StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
GetCentrality.C
1 // ROOT headers
2 #include "TMath.h"
3 #include "TRandom3.h"
4 #include "TCanvas.h"
5 #include "TF1.h"
6 #include "TH1D.h"
7 #include "TH1D.h"
8 #include "TGraph.h"
9 #include "TAxis.h"
10 #include "TGraph2D.h"
11 #include "TGraphErrors.h"
12 #include "TH1F.h"
13 #include "TH1F.h"
14 #include "TFile.h"
15 #include "TNtuple.h"
16 
17 // C++ headers
18 #include <iostream>
19 #include <numeric>
20 #include <sstream>
21 #include <chrono>
22 
23 //_________________
24 void getcentralitybins() {
25  TFile *f0 = new TFile("Case3/Zr/Ratio_npp2.386_k3.889_x0.123_eff0.024.root");
26  TH1D *sim = (TH1D *)f0->Get("hRefMultSim");
27  TH1D *data = (TH1D *)f0->Get("hRefMult");
28 
29  int centralitybin[16][2];
30  double integral = sim->Integral();
31  for(int cent=0; cent<16; cent++){
32  double distance = 1000.0;
33  double fraction = 0.05*((double)cent+1.0);
34  //For the most central bins, integrate the data
35  if(cent<4){
36  for(int i=0; i<data->GetNbinsX(); i++){
37  double thisfraction = (data->Integral(i,500))/(integral);
38  double thisdistance = TMath::Abs(thisfraction - fraction);
39  if(thisdistance>distance){
40  if(cent==0){centralitybin[0][0]=500; centralitybin[0][1]=i-1;centralitybin[1][0]=i-2;}
41  else{centralitybin[cent][1]=i-1;centralitybin[cent+1][0]=i-2;}
42  break;
43  }
44  else{distance=thisdistance;}
45  }
46  }
47  //For more peripheral bins, integrate the simulated distribution
48  else{
49  int newmaxbin = centralitybin[3][1]-1;
50  double zeroToTwentyIntegral = data->Integral(newmaxbin+1,500);
51  for(int i=0; i<newmaxbin; i++){
52  double thisfraction=(sim->Integral(i,newmaxbin)+zeroToTwentyIntegral)/(integral);
53  double thisdistance = TMath::Abs(thisfraction - fraction);
54  if(thisdistance>distance){
55  if(cent==15){centralitybin[15][1]=i-2;}
56  else{centralitybin[cent][1]=i-1;centralitybin[cent+1][0]=i-2;}
57  break;
58  }
59  else{distance=thisdistance;}
60  }
61  }
62  }
63 
64  std::cout<<"******* 16 Bins *******"<<std::endl;
65  std::cout<<"High bins"<<std::endl;
66  for(int i=0; i<16; i++){
67  std::cout<<centralitybin[i][0]<<std::endl;
68  }
69  std::cout<<"Low bins"<<std::endl;
70  for(int i=0; i<16; i++){
71  std::cout<<centralitybin[i][1]<<std::endl;
72  }
73  std::cout<<"******* 9 Bins *******"<<std::endl;
74  std::cout<<"High bins"<<std::endl;
75  for(int i=0; i<9; i++){
76  if(i==0 || i==1){std::cout<<centralitybin[i][0]<<std::endl;}
77  else{std::cout<<centralitybin[2*i-1][0]<<std::endl;}
78  }
79  std::cout<<"Low bins"<<std::endl;
80  for(int i=0; i<9; i++){
81  if(i==0 || i==1){std::cout<<centralitybin[i][1]<<std::endl;}
82  else{std::cout<<centralitybin[2*i-1][1]<<std::endl;}
83  }
84 }