ROOT logo
///==========================================================================
///
///    macro to plot centrality bin values 
///==========================================================================
///
#include <cstdlib>

const Int_t nbins;

double centPercent[]={5.,10.,20.,40.,60.,80.,99.9999999}; 
//double centPercent[]={10.,20.,40.,60.,80.,99.9999999}; 


nbins = sizeof(centPercent)/sizeof(double);

TArrayI* binUp = new TArrayI(nbins);
TArrayF* Multbin = new TArrayF(nbins);

void plotGlauberCenVarsZPA()    
{
 TGraphErrors *gNpart=new TGraphErrors(0);
 gNpart->SetName("gNpart"); 
 TGraphErrors *gNcoll=new TGraphErrors(0);
 gNcoll->SetName("gNcoll"); 
 TGraphErrors *gtAA=new TGraphErrors(0);
 gtAA->SetName("gtAA"); 


  TFile *f=new TFile("ZPA_ntuple_188359.root");
  
  TNtuple *nt=(TNtuple*)f->Get("gnt");
  
  Float_t B;
  Float_t Npart;
  Float_t Ncoll;
  Float_t tAA;
  Float_t ntot;
  
  nt->SetBranchAddress("B",&B);
  nt->SetBranchAddress("Npart",&Npart);
  nt->SetBranchAddress("Ncoll",&Ncoll);
  nt->SetBranchAddress("tAA",&tAA);
  nt->SetBranchAddress("ntot",&ntot);


  Int_t totev=nt->GetEntries();
 
 
  TH1F*hB=new TH1F("hB","hB",28000,0.,14.);
  TH1F*hNpart=new TH1F("hNpart","hNpart",420,-0.5,419.5);
  TH1F*hNcoll=new TH1F("hNcoll","hNcoll",3500,0,35);
  TH1F*htAA=new TH1F("htAA","htAA",100000,-0.5,39.5);
  TH1F*hntot=new TH1F("hntot","hntot",100000,-0.5,39.5);
 
  
  for (Int_t iEvent = 0; iEvent < totev; iEvent++) {
    nt->GetEvent(iEvent); 
    
    Float_t nu = (Float_t) ntot; 
    nu = gRandom->Gaus(nu,0.5); 

    if(nu>0) {
  
    hNpart->Fill(Npart);
    hNcoll->Fill(Ncoll);
    hB->Fill(B);
    htAA->Fill(tAA);
    hntot->Fill(nu);
    }
  } 

   new TCanvas();
   hNcoll->Draw();

   //---------------------------------------------------
   getCentrality(hntot);
   //---------------------------------------------------


 TH1F* hnpartcutb[nbins];
 char histtitp[100];
 for (Int_t i=0; i<binUp->GetSize(); i++) {
   sprintf(histtitp,"npartcutb%d",i);
   hnpartcutb[i] = new TH1F(histtitp,histtitp,10000,-0.5,9999.5);
   hnpartcutb[i]->SetLineWidth(1);
   hnpartcutb[i]->SetStats(1);

 }

 TH1F* hncollcutb[nbins];
 char histtitc[100];
 for (Int_t i=0; i<binUp->GetSize(); i++) {
   sprintf(histtitc,"ncollcutb%d",i);
   hncollcutb[i] = new TH1F(histtitc,histtitc,10000,-0.5,9999.5);
   hncollcutb[i]->SetLineWidth(1);
   hncollcutb[i]->SetStats(1);

 }

 TH1F* htaacutb[nbins];
 char histtitt[100];
 for (Int_t i=0; i<binUp->GetSize(); i++) {
   sprintf(histtitt,"taacutb%d",i);
   htaacutb[i] = new TH1F(histtitt,histtitt,100000,-0.5,39.5);
   htaacutb[i]->SetLineWidth(1);
   htaacutb[i]->SetStats(1);

 }

 TH1F* hbcutb[nbins];
 char histtitt[100];
 for (Int_t i=0; i<binUp->GetSize(); i++) {
   sprintf(histtitt,"bcutb%d",i);
   hbcutb[i] = new TH1F(histtitt,histtitt,100000,-0.5,39.5);
   hbcutb[i]->SetLineWidth(1);
   hbcutb[i]->SetStats(1);

 }



 for (Int_t iEvent = 0; iEvent < totev; iEvent++) {
   nt->GetEvent(iEvent);
   for (int ibin=0; ibin<nbins; ibin++) {
     //     if (B<Multbin->At(ibin)) {

     Float_t nu = (Float_t) Ncoll; 
     nu = nu+1.*gRandom->Rndm();
  
     if (nu>Multbin->At(ibin)) {
       hnpartcutb[ibin]->Fill(Npart); 
       hncollcutb[ibin]->Fill(Ncoll); 
       htaacutb[ibin]->Fill(tAA); 
       hbcutb[ibin]->Fill(B); 
       break;
     } 
   } 
 } 
 

   


 // superimpose cut histograms
// new TCanvas();
// hnpartcutb[0]->Draw("");
 for (Int_t icentr=0; icentr<nbins;icentr++) {
   hnpartcutb[icentr]->SetLineColor(icentr);
   hnpartcutb[icentr]->Draw("same");
 } 

 for (Int_t icentr=0; icentr<nbins;icentr++) {
   new TCanvas();
   hnpartcutb[icentr]->SetLineColor(icentr);
   hnpartcutb[icentr]->SetStats(1); 
   hnpartcutb[icentr]->Draw("");
   gNpart->SetPoint(icentr,Float_t(icentr),hnpartcutb[icentr]->GetMean());
   gNpart->SetPointError(icentr,0,hnpartcutb[icentr]->GetRMS());
 }
 cout << endl;

 for (Int_t icentr=0; icentr<nbins;icentr++) {
   new TCanvas();
   hncollcutb[icentr]->SetLineColor(icentr);
   hncollcutb[icentr]->SetStats(1); 
   hncollcutb[icentr]->Draw("");
   gNcoll->SetPoint(icentr,Float_t(icentr),hncollcutb[icentr]->GetMean());
   gNcoll->SetPointError(icentr,0,hncollcutb[icentr]->GetRMS());
 }
 cout << endl;

 for (Int_t icentr=0; icentr<nbins;icentr++) {
   new TCanvas();
   htaacutb[icentr]->SetLineColor(icentr);
   htaacutb[icentr]->SetStats(1); 
   htaacutb[icentr]->Draw("");
   gtAA->SetPoint(icentr,Float_t(icentr),htaacutb[icentr]->GetMean());
   gtAA->SetPointError(icentr,0,htaacutb[icentr]->GetRMS());
 }

 for (Int_t icentr=0; icentr<nbins;icentr++) 
   cout<<icentr<<" | "<<setprecision(3)<<centPercent[icentr]<<" | "
       <<Multbin->At(icentr-1)<<" | "<<Multbin->At(icentr)<<" | "
       <<hnpartcutb[icentr]->GetMean()<<" | " <<hnpartcutb[icentr]->GetRMS()<< " | " 
       <<hncollcutb[icentr]->GetMean()<<" | " <<hncollcutb[icentr]->GetRMS()<< " | " 
       <<hbcutb[icentr]->GetMean()    <<" | " <<hbcutb[icentr]->GetRMS()    << " | "
       <<htaacutb[icentr]->GetMean()  <<" | " <<htaacutb[icentr]->GetRMS()  << " | "<<endl;


 //TString suffixhisto=Form("/home/atoia/GlauberNtuple/62/GlauberMC_PbPb_histoB_sigma%d_mind%d_r%d_a%d_%d.root",mysignn,mymind,myr,mya,nbins);
 //TString suffixhisto=Form("/home/atoia/GlauberNtuple/GlauberMC_PbPb_histoB_sigma%d_mind%d_r%d_a%d_%d.root",mysignn,mymind,myr,mya,nbins);
 //const Char_t* filehistoname=suffixhisto.Data();
 //TFile*filefinal=new TFile(filehistoname,"recreate");
 // --FOR TEST --
 //TFile*filefinal=new TFile("GlauberInfo.root","recreate");
 
 // gNpart->Write();
 // gNcoll->Write();
 // gtAA->Write();
 
 // hNpart->Write();
 // hNcoll->Write();
 // hB    ->Write();
 // htAA  ->Write();
  
 // for (int i=0; i<nbins; i++) {
 //   hnpartcutb[i]->Write();
 //   hncollcutb[i]->Write();
 //   htaacutb[i]  ->Write();
 // }
 
}


void getCentrality(TH1 *histNch, Float_t ff=1.0)
// histNch - histo of multiplicity distribution (better with binsize=1)x
// ff fraction of accepted events. All losses are assumed to occur in most
// peripheral bin
{

 //double sum= histNch->GetEntries() - histNch->GetBinContent(1);
 double sum= histNch->Integral(); 
 int nbinsx=histNch->GetNbinsX();
 double frac=0.;
 int ic=0;
 //for (int ib=1;ib<=nbinsx;ib++){
 for (int ib=nbinsx;ib>0;ib--){
   frac += histNch->GetBinContent(ib)/sum*100.*ff;
   if(frac > centPercent[ic]){
     binUp->SetAt(ib,ic);
     Multbin->SetAt(histNch->GetBinCenter(ib),ic);
     cout<<" centrality="<<centPercent[ic]<<"   ncoll <="<< histNch->GetBinCenter(ib) <<endl;
     //cout<<" centrality="<<centPercent[ic]<<" impact parameter <="<< histNch->GetBinCenter(ib) <<endl;
     ic++;
   }
   if(ic==nbins) break;
 }
 
 printf(" \n float binUp[%i] = {",nbins);  
 // cout <<" \n float multCent[nbins] = {";

 for (int ic=nbins-1; ic>-1; ic--){
   cout<< binUp->At(ic);
   if (ic!=0) cout<<", ";
 }
 cout<<"};\n"<<endl;


 printf(" \n float multCent[%i] = {",nbins);  
 // cout <<" \n float multCent[nbins] = {";

 for (int ic=nbins-1; ic>-1; ic--){
   cout<< histNch->GetBinCenter(binUp->At(ic));
   if (ic!=0) cout<<", ";
 }
 cout<<"};\n"<<endl;
}
 plotGlauberCenVarsZPA.C:1
 plotGlauberCenVarsZPA.C:2
 plotGlauberCenVarsZPA.C:3
 plotGlauberCenVarsZPA.C:4
 plotGlauberCenVarsZPA.C:5
 plotGlauberCenVarsZPA.C:6
 plotGlauberCenVarsZPA.C:7
 plotGlauberCenVarsZPA.C:8
 plotGlauberCenVarsZPA.C:9
 plotGlauberCenVarsZPA.C:10
 plotGlauberCenVarsZPA.C:11
 plotGlauberCenVarsZPA.C:12
 plotGlauberCenVarsZPA.C:13
 plotGlauberCenVarsZPA.C:14
 plotGlauberCenVarsZPA.C:15
 plotGlauberCenVarsZPA.C:16
 plotGlauberCenVarsZPA.C:17
 plotGlauberCenVarsZPA.C:18
 plotGlauberCenVarsZPA.C:19
 plotGlauberCenVarsZPA.C:20
 plotGlauberCenVarsZPA.C:21
 plotGlauberCenVarsZPA.C:22
 plotGlauberCenVarsZPA.C:23
 plotGlauberCenVarsZPA.C:24
 plotGlauberCenVarsZPA.C:25
 plotGlauberCenVarsZPA.C:26
 plotGlauberCenVarsZPA.C:27
 plotGlauberCenVarsZPA.C:28
 plotGlauberCenVarsZPA.C:29
 plotGlauberCenVarsZPA.C:30
 plotGlauberCenVarsZPA.C:31
 plotGlauberCenVarsZPA.C:32
 plotGlauberCenVarsZPA.C:33
 plotGlauberCenVarsZPA.C:34
 plotGlauberCenVarsZPA.C:35
 plotGlauberCenVarsZPA.C:36
 plotGlauberCenVarsZPA.C:37
 plotGlauberCenVarsZPA.C:38
 plotGlauberCenVarsZPA.C:39
 plotGlauberCenVarsZPA.C:40
 plotGlauberCenVarsZPA.C:41
 plotGlauberCenVarsZPA.C:42
 plotGlauberCenVarsZPA.C:43
 plotGlauberCenVarsZPA.C:44
 plotGlauberCenVarsZPA.C:45
 plotGlauberCenVarsZPA.C:46
 plotGlauberCenVarsZPA.C:47
 plotGlauberCenVarsZPA.C:48
 plotGlauberCenVarsZPA.C:49
 plotGlauberCenVarsZPA.C:50
 plotGlauberCenVarsZPA.C:51
 plotGlauberCenVarsZPA.C:52
 plotGlauberCenVarsZPA.C:53
 plotGlauberCenVarsZPA.C:54
 plotGlauberCenVarsZPA.C:55
 plotGlauberCenVarsZPA.C:56
 plotGlauberCenVarsZPA.C:57
 plotGlauberCenVarsZPA.C:58
 plotGlauberCenVarsZPA.C:59
 plotGlauberCenVarsZPA.C:60
 plotGlauberCenVarsZPA.C:61
 plotGlauberCenVarsZPA.C:62
 plotGlauberCenVarsZPA.C:63
 plotGlauberCenVarsZPA.C:64
 plotGlauberCenVarsZPA.C:65
 plotGlauberCenVarsZPA.C:66
 plotGlauberCenVarsZPA.C:67
 plotGlauberCenVarsZPA.C:68
 plotGlauberCenVarsZPA.C:69
 plotGlauberCenVarsZPA.C:70
 plotGlauberCenVarsZPA.C:71
 plotGlauberCenVarsZPA.C:72
 plotGlauberCenVarsZPA.C:73
 plotGlauberCenVarsZPA.C:74
 plotGlauberCenVarsZPA.C:75
 plotGlauberCenVarsZPA.C:76
 plotGlauberCenVarsZPA.C:77
 plotGlauberCenVarsZPA.C:78
 plotGlauberCenVarsZPA.C:79
 plotGlauberCenVarsZPA.C:80
 plotGlauberCenVarsZPA.C:81
 plotGlauberCenVarsZPA.C:82
 plotGlauberCenVarsZPA.C:83
 plotGlauberCenVarsZPA.C:84
 plotGlauberCenVarsZPA.C:85
 plotGlauberCenVarsZPA.C:86
 plotGlauberCenVarsZPA.C:87
 plotGlauberCenVarsZPA.C:88
 plotGlauberCenVarsZPA.C:89
 plotGlauberCenVarsZPA.C:90
 plotGlauberCenVarsZPA.C:91
 plotGlauberCenVarsZPA.C:92
 plotGlauberCenVarsZPA.C:93
 plotGlauberCenVarsZPA.C:94
 plotGlauberCenVarsZPA.C:95
 plotGlauberCenVarsZPA.C:96
 plotGlauberCenVarsZPA.C:97
 plotGlauberCenVarsZPA.C:98
 plotGlauberCenVarsZPA.C:99
 plotGlauberCenVarsZPA.C:100
 plotGlauberCenVarsZPA.C:101
 plotGlauberCenVarsZPA.C:102
 plotGlauberCenVarsZPA.C:103
 plotGlauberCenVarsZPA.C:104
 plotGlauberCenVarsZPA.C:105
 plotGlauberCenVarsZPA.C:106
 plotGlauberCenVarsZPA.C:107
 plotGlauberCenVarsZPA.C:108
 plotGlauberCenVarsZPA.C:109
 plotGlauberCenVarsZPA.C:110
 plotGlauberCenVarsZPA.C:111
 plotGlauberCenVarsZPA.C:112
 plotGlauberCenVarsZPA.C:113
 plotGlauberCenVarsZPA.C:114
 plotGlauberCenVarsZPA.C:115
 plotGlauberCenVarsZPA.C:116
 plotGlauberCenVarsZPA.C:117
 plotGlauberCenVarsZPA.C:118
 plotGlauberCenVarsZPA.C:119
 plotGlauberCenVarsZPA.C:120
 plotGlauberCenVarsZPA.C:121
 plotGlauberCenVarsZPA.C:122
 plotGlauberCenVarsZPA.C:123
 plotGlauberCenVarsZPA.C:124
 plotGlauberCenVarsZPA.C:125
 plotGlauberCenVarsZPA.C:126
 plotGlauberCenVarsZPA.C:127
 plotGlauberCenVarsZPA.C:128
 plotGlauberCenVarsZPA.C:129
 plotGlauberCenVarsZPA.C:130
 plotGlauberCenVarsZPA.C:131
 plotGlauberCenVarsZPA.C:132
 plotGlauberCenVarsZPA.C:133
 plotGlauberCenVarsZPA.C:134
 plotGlauberCenVarsZPA.C:135
 plotGlauberCenVarsZPA.C:136
 plotGlauberCenVarsZPA.C:137
 plotGlauberCenVarsZPA.C:138
 plotGlauberCenVarsZPA.C:139
 plotGlauberCenVarsZPA.C:140
 plotGlauberCenVarsZPA.C:141
 plotGlauberCenVarsZPA.C:142
 plotGlauberCenVarsZPA.C:143
 plotGlauberCenVarsZPA.C:144
 plotGlauberCenVarsZPA.C:145
 plotGlauberCenVarsZPA.C:146
 plotGlauberCenVarsZPA.C:147
 plotGlauberCenVarsZPA.C:148
 plotGlauberCenVarsZPA.C:149
 plotGlauberCenVarsZPA.C:150
 plotGlauberCenVarsZPA.C:151
 plotGlauberCenVarsZPA.C:152
 plotGlauberCenVarsZPA.C:153
 plotGlauberCenVarsZPA.C:154
 plotGlauberCenVarsZPA.C:155
 plotGlauberCenVarsZPA.C:156
 plotGlauberCenVarsZPA.C:157
 plotGlauberCenVarsZPA.C:158
 plotGlauberCenVarsZPA.C:159
 plotGlauberCenVarsZPA.C:160
 plotGlauberCenVarsZPA.C:161
 plotGlauberCenVarsZPA.C:162
 plotGlauberCenVarsZPA.C:163
 plotGlauberCenVarsZPA.C:164
 plotGlauberCenVarsZPA.C:165
 plotGlauberCenVarsZPA.C:166
 plotGlauberCenVarsZPA.C:167
 plotGlauberCenVarsZPA.C:168
 plotGlauberCenVarsZPA.C:169
 plotGlauberCenVarsZPA.C:170
 plotGlauberCenVarsZPA.C:171
 plotGlauberCenVarsZPA.C:172
 plotGlauberCenVarsZPA.C:173
 plotGlauberCenVarsZPA.C:174
 plotGlauberCenVarsZPA.C:175
 plotGlauberCenVarsZPA.C:176
 plotGlauberCenVarsZPA.C:177
 plotGlauberCenVarsZPA.C:178
 plotGlauberCenVarsZPA.C:179
 plotGlauberCenVarsZPA.C:180
 plotGlauberCenVarsZPA.C:181
 plotGlauberCenVarsZPA.C:182
 plotGlauberCenVarsZPA.C:183
 plotGlauberCenVarsZPA.C:184
 plotGlauberCenVarsZPA.C:185
 plotGlauberCenVarsZPA.C:186
 plotGlauberCenVarsZPA.C:187
 plotGlauberCenVarsZPA.C:188
 plotGlauberCenVarsZPA.C:189
 plotGlauberCenVarsZPA.C:190
 plotGlauberCenVarsZPA.C:191
 plotGlauberCenVarsZPA.C:192
 plotGlauberCenVarsZPA.C:193
 plotGlauberCenVarsZPA.C:194
 plotGlauberCenVarsZPA.C:195
 plotGlauberCenVarsZPA.C:196
 plotGlauberCenVarsZPA.C:197
 plotGlauberCenVarsZPA.C:198
 plotGlauberCenVarsZPA.C:199
 plotGlauberCenVarsZPA.C:200
 plotGlauberCenVarsZPA.C:201
 plotGlauberCenVarsZPA.C:202
 plotGlauberCenVarsZPA.C:203
 plotGlauberCenVarsZPA.C:204
 plotGlauberCenVarsZPA.C:205
 plotGlauberCenVarsZPA.C:206
 plotGlauberCenVarsZPA.C:207
 plotGlauberCenVarsZPA.C:208
 plotGlauberCenVarsZPA.C:209
 plotGlauberCenVarsZPA.C:210
 plotGlauberCenVarsZPA.C:211
 plotGlauberCenVarsZPA.C:212
 plotGlauberCenVarsZPA.C:213
 plotGlauberCenVarsZPA.C:214
 plotGlauberCenVarsZPA.C:215
 plotGlauberCenVarsZPA.C:216
 plotGlauberCenVarsZPA.C:217
 plotGlauberCenVarsZPA.C:218
 plotGlauberCenVarsZPA.C:219
 plotGlauberCenVarsZPA.C:220
 plotGlauberCenVarsZPA.C:221
 plotGlauberCenVarsZPA.C:222
 plotGlauberCenVarsZPA.C:223
 plotGlauberCenVarsZPA.C:224
 plotGlauberCenVarsZPA.C:225
 plotGlauberCenVarsZPA.C:226
 plotGlauberCenVarsZPA.C:227
 plotGlauberCenVarsZPA.C:228
 plotGlauberCenVarsZPA.C:229
 plotGlauberCenVarsZPA.C:230
 plotGlauberCenVarsZPA.C:231
 plotGlauberCenVarsZPA.C:232
 plotGlauberCenVarsZPA.C:233
 plotGlauberCenVarsZPA.C:234
 plotGlauberCenVarsZPA.C:235
 plotGlauberCenVarsZPA.C:236
 plotGlauberCenVarsZPA.C:237
 plotGlauberCenVarsZPA.C:238
 plotGlauberCenVarsZPA.C:239
 plotGlauberCenVarsZPA.C:240
 plotGlauberCenVarsZPA.C:241
 plotGlauberCenVarsZPA.C:242
 plotGlauberCenVarsZPA.C:243
 plotGlauberCenVarsZPA.C:244
 plotGlauberCenVarsZPA.C:245
 plotGlauberCenVarsZPA.C:246
 plotGlauberCenVarsZPA.C:247
 plotGlauberCenVarsZPA.C:248
 plotGlauberCenVarsZPA.C:249
 plotGlauberCenVarsZPA.C:250
 plotGlauberCenVarsZPA.C:251
 plotGlauberCenVarsZPA.C:252
 plotGlauberCenVarsZPA.C:253
 plotGlauberCenVarsZPA.C:254
 plotGlauberCenVarsZPA.C:255
 plotGlauberCenVarsZPA.C:256
 plotGlauberCenVarsZPA.C:257
 plotGlauberCenVarsZPA.C:258