Browse Source

Added binary for centrality calculations

PeterParfenov 2 years ago
parent
commit
1e49af1e70
5 changed files with 111 additions and 4 deletions
  1. 3 0
      CMakeLists.txt
  2. 1 1
      Centrality/CMakeLists.txt
  3. 34 2
      Centrality/CentralityCalculator.cxx
  4. 8 1
      Centrality/CentralityCalculator.h
  5. 65 0
      calcCent.cpp

+ 3 - 0
CMakeLists.txt

@@ -31,3 +31,6 @@ set(CMAKE_BUILD_TYPE Debug)
 set(CMAKE_C_FLAGS "-O2")
 
 add_subdirectory(Centrality)
+
+add_executable(calcCent calcCent.cpp)
+target_link_libraries(calcCent Centrality)

+ 1 - 1
Centrality/CMakeLists.txt

@@ -4,7 +4,7 @@ set(Centrality_h_files
 
 set(Centrality_cxx_files
 	MultReader.cxx
-	CentralityCalculator.cxx)
+	CentralityCalculator.cxx ../calcCent.cpp)
 
 #---Generate dictionary
 ROOT_GENERATE_DICTIONARY(G__Centrality

+ 34 - 2
Centrality/CentralityCalculator.cxx

@@ -1,5 +1,9 @@
 #include "CentralityCalculator.h"
 
+#include <TLine.h>
+#include <TCanvas.h>
+#include <TLatex.h>
+
 ClassImp(CentralityCalculator);
 
 CentralityCalculator::CentralityCalculator()
@@ -30,7 +34,7 @@ Int_t CentralityCalculator::Integrate(Int_t max_bin, Float_t sum)
 	return max_bin;
 }
 
-Int_t CentralityCalculator::GetCentrality(Int_t multiplicity)
+Int_t CentralityCalculator::GetCent(Int_t multiplicity)
 {
   int centrality_bin = -1;
   for (int multiplicityBin = 0; multiplicityBin < NmultiplicityBins; ++multiplicityBin)
@@ -69,6 +73,12 @@ Int_t CentralityCalculator::GetCentrality(Int_t multiplicity)
   return centrality_bin;
 }
 
+Int_t CentralityCalculator::GetCentrality(Int_t multiplicity)
+{
+  Int_t cent = 99 - GetCent(multiplicity);
+  return cent;
+}
+
 void CentralityCalculator::Calc()
 {
   Double_t one_tenth = fHmult->Integral("WIDTH") / NmultiplicityBins; //the fraction of events equal to on centrality bin
@@ -84,5 +94,27 @@ void CentralityCalculator::Calc()
 	multiplicity_bins[NmultiplicityBins] = fHmult->GetBinLowEdge(n_mult_bins) + fHmult->GetBinWidth(1);
 	
 	for (int i = 0; i <= NmultiplicityBins; ++i) std::cout << "multiplicity bin = " << i << ": " << multiplicity_bins[i] << std::endl;
-
 }
+
+void CentralityCalculator::DrawHistogram(TString outName)
+{
+  TH1F* hist = (TH1F*) fHmult->Clone();
+  TLine line;
+
+  TCanvas *canv = new TCanvas(Form("%s","canvas"),Form("%s","canvas"),900,650);
+  canv->cd();
+  canv->SetLogy();
+
+  hist->Draw();
+
+  line.SetLineColor(1);
+  line.SetLineWidth(2);
+  for (int i=0; i<(Int_t)(NmultiplicityBins/10);i++)
+  {
+    line.DrawLine(multiplicity_bins[i*10+1],0.,multiplicity_bins[i*10+1],hist->GetBinContent(hist->FindBin(multiplicity_bins[i*10+1])));
+  }
+  TLatex tex;
+  tex.DrawLatexNDC(0.35,0.85,Form("Au+Au, %s, #sqrt{s_{NN}}=%3.1f GeV",fModel.Data(),fEnergy));
+
+  canv->SaveAs(Form("%s",outName.Data()));
+}

+ 8 - 1
Centrality/CentralityCalculator.h

@@ -14,14 +14,21 @@ private:
   static const Int_t NmultiplicityBins = 100;
   Double_t multiplicity_bins[NmultiplicityBins+1];
   TRandom3 *RNG;
+  TString  fModel;
+  Double_t fEnergy;
+  Int_t GetCent(Int_t multiplicity);
+  Int_t Integrate(Int_t max_bin, Float_t sum);
+
 public:
   CentralityCalculator();
   virtual ~CentralityCalculator();
 
   void  SetHistogram(TH1F *const& _h) { fHmult = _h; }
-  Int_t Integrate(Int_t max_bin, Float_t sum);
+  void  SetModel(TString _s) { fModel = _s; }
+  void  SetEnergy(Double_t _a) { fEnergy = _a; }
   Int_t GetCentrality(Int_t multiplicity);
   void  Calc();
+  void  DrawHistogram(TString outName);
 
   ClassDef(CentralityCalculator,0);
 };

+ 65 - 0
calcCent.cpp

@@ -0,0 +1,65 @@
+//
+// Created by peter on 8/27/19.
+//
+
+#include <iostream>
+#include <TStopwatch.h>
+#include <TFile.h>
+#include <TH1F.h>
+
+#include "CentralityCalculator.h"
+
+int main(int argc, char** argv)
+{
+  TString inFileName, CanvasName;
+  if (argc < 5)
+  {
+    std::cerr << "./calcCent -i INPUTFILE -canv CANVASNAME" << std::endl;
+    return 10;
+  }
+  for (int i = 1; i < argc; i++)
+  {
+    if (std::string(argv[i]) != "-i" &&
+        std::string(argv[i]) != "-canv")
+    {
+      std::cerr << "\ncalcCent: Unknown parameter: " << argv[i] << std::endl;
+      return 11;
+    } else {
+      if (std::string(argv[i]) == "-i" && i != argc - 1)
+      {
+        inFileName = argv[++i];
+      }
+      if (std::string(argv[i]) == "-i" && i == argc - 1)
+      {
+        std::cerr << "\ncalcCent: Input file name was not specified!" << std::endl;
+        return 20;
+      }
+
+      if (std::string(argv[i]) == "-canv" && i != argc - 1)
+      {
+        CanvasName = argv[++i];
+      }
+      if (std::string(argv[i]) == "-canv" && i == argc - 1)
+      {
+        std::cerr << "\ncalcCent: Input file name was not specified!" << std::endl;
+        return 20;
+      }
+    }
+  }
+  TStopwatch timer;
+  timer.Start();
+
+  TFile *fi = new TFile(inFileName.Data(),"read");
+  TH1F *hist = (TH1F*) fi->Get("hMult");
+  CentralityCalculator *cent = new CentralityCalculator();
+  cent->SetEnergy(200.);
+  cent->SetModel("PHSD");
+  cent->SetHistogram(hist);
+  cent->Calc();
+  cent->DrawHistogram(CanvasName);
+
+  timer.Stop();
+  timer.Print();
+
+  return 0;
+}