]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG4/totEt/macros/hadEt/CorrEfficiency.C
Updating macros for hadronic et. Implements centrality dependence of efficiency.
[u/mrichter/AliRoot.git] / PWG4 / totEt / macros / hadEt / CorrEfficiency.C
1 //Christine Nattrass, University of Tennessee at Knoxville
2 //This macro is for calculating the single track efficiency for the hadronic transverse energy measurement
3 //Uses the output of AliAnalysisTaskHadEt
4 //This is not actually what gets used in the correction class AliAnalysisHadEtCorrections - that is done in the macro GetCorrections.C - but this is useful for making plots and playing around with different options
5
6 //this function calculates the efficiency propagating errors properly
7 TH1D* bayneseffdiv(TH1D* numerator, TH1D* denominator,Char_t* name) 
8 {
9     if(!numerator){
10       cerr<<"Error:  numerator does not exist!"<<endl;
11       return NULL;
12     }
13     if(!denominator){
14       cerr<<"Error:  denominator does not exist!"<<endl;
15       return NULL;
16     }
17     TH1D* result = (TH1D*)numerator->Clone(name);
18     Int_t nbins = numerator->GetNbinsX();
19     for (Int_t ibin=0; ibin<= nbins+1; ++ibin) {
20       Double_t numeratorVal = numerator->GetBinContent(ibin);
21       Double_t denominatorVal = denominator->GetBinContent(ibin);
22       // Check if the errors are right or the thing is scaled
23       Double_t numeratorValErr = numerator->GetBinError(ibin);
24       if (!(numeratorValErr==0. || numeratorVal ==0.) ) {
25         Double_t rescale = numeratorValErr*numeratorValErr/numeratorVal;
26         numeratorVal /= rescale;
27       }
28       Double_t denominatorValErr = denominator->GetBinError(ibin);
29       if (!(denominatorValErr==0. || denominatorVal==0. )) {
30         Double_t rescale = denominatorValErr*denominatorValErr/denominatorVal;
31         denominatorVal /= rescale;
32       }
33       Double_t quotient = 0.;
34       if (denominatorVal!=0.) {
35         quotient = numeratorVal/denominatorVal;
36       }
37       Double_t quotientErr=0;
38       quotientErr = TMath::Sqrt(
39                                 (numeratorVal+1.0)/(denominatorVal+2.0)*
40                                 ((numeratorVal+2.0)/(denominatorVal+3.0)-(numeratorVal+1.0)/(denominatorVal+2.0)));
41       result->SetBinContent(ibin,quotient);
42       result->SetBinError(ibin,quotientErr);
43       //cout<<"Setting bin "<<ibin<<" to "<<quotient<<" "<<numeratorVal<<"/"<<denominatorVal<<endl;
44     }
45     return result;
46 }
47
48
49 //This is a somewhat messy function that gets the efficiency for different particles
50 TH1D *GetHisto(float cut = 0.12, char *name, int mycase, bool eta, int color, int marker,bool TPC, bool ITS, bool PbPb, int cb, int cblast){
51   //TFile *file = new TFile("Et.ESD.new.sim.merged.root");
52   TFile *file = new TFile("rootFiles/LHC11a4_bis/Et.ESD.new.sim.LHC11a4_bis.root");
53   //TFile *file = new TFile("rootFiles/LHC10d7/Et.ESD.new.sim.LHC10d7.root");
54   TList *list = file->FindObject("out2");
55   char *myname = "ITS";
56   if(TPC&&!ITS) myname = "TPC";
57   if(TPC&&ITS) myname = "TPCITS";
58   cout<<"Using tracks from "<<myname<<" for efficiency"<<endl;
59   TH2F *numeratorParent; 
60   switch(mycase){
61   case 0:
62     if(cblast != -1){//add more centrality bins
63       for(int i=cb;i<=cblast;i++){
64         if(i==cb) numeratorParent = (TH2F*)((TH2F*) out2->FindObject(Form("EtNReconstructed%s%sCB%i",myname,"PiPlus",i)))->Clone("RecoHadron");
65         else{numeratorParent->Add((TH2F*) out2->FindObject(Form("EtNReconstructed%s%sCB%i",myname,"PiPlus",i)));}
66         numeratorParent->Add((TH2F*) out2->FindObject(Form("EtNReconstructed%s%sCB%i",myname,"PiMinus",i)));
67         numeratorParent->Add((TH2F*) out2->FindObject(Form("EtNReconstructed%s%sCB%i",myname,"KMinus",i)));
68         numeratorParent->Add((TH2F*) out2->FindObject(Form("EtNReconstructed%s%sCB%i",myname,"KPlus",i)));
69         numeratorParent->Add((TH2F*) out2->FindObject(Form("EtNReconstructed%s%sCB%i",myname,"Proton",i)));
70         numeratorParent->Add((TH2F*) out2->FindObject(Form("EtNReconstructed%s%sCB%i",myname,"AntiProton",i)));
71       }
72     }
73     else{
74       numeratorParent = (TH2F*)((TH2F*) out2->FindObject(Form("EtNReconstructed%s%s",myname,"PiPlus")))->Clone("RecoHadron");
75       numeratorParent->Add((TH2F*) out2->FindObject(Form("EtNReconstructed%s%s",myname,"PiMinus")));
76       numeratorParent->Add((TH2F*) out2->FindObject(Form("EtNReconstructed%s%s",myname,"KMinus")));
77       numeratorParent->Add((TH2F*) out2->FindObject(Form("EtNReconstructed%s%s",myname,"KPlus")));
78       numeratorParent->Add((TH2F*) out2->FindObject(Form("EtNReconstructed%s%s",myname,"Proton")));
79       numeratorParent->Add((TH2F*) out2->FindObject(Form("EtNReconstructed%s%s",myname,"AntiProton")));
80     }
81     break;
82   case 1://pion
83     if(cblast != -1){//add more centrality bins
84       for(int i=cb;i<=cblast;i++){
85         if(i==cb) numeratorParent = (TH2F*)((TH2F*) out2->FindObject(Form("EtNReconstructed%s%sCB%i",myname,"PiPlus",i)))->Clone("RecoPion");
86         else{numeratorParent->Add((TH2F*) out2->FindObject(Form("EtNReconstructed%s%sCB%i",myname,"PiPlus",i)));}
87         numeratorParent->Add((TH2F*) out2->FindObject(Form("EtNReconstructed%s%sCB%i",myname,"PiMinus",i)));
88       }
89     }
90     else{
91       numeratorParent = (TH2F*)((TH2F*) out2->FindObject(Form("EtNReconstructed%s%s",myname,"PiPlus")))->Clone("RecoPion");
92       numeratorParent->Add((TH2F*) out2->FindObject(Form("EtNReconstructed%s%s",myname,"PiMinus")));
93     }
94     break;
95   case 2://kaon
96     if(cblast != -1){//add more centrality bins
97       for(int i=cb;i<=cblast;i++){
98         if(i==cb) numeratorParent = (TH2F*)((TH2F*) out2->FindObject(Form("EtNReconstructed%s%sCB%i",myname,"KPlus",i)))->Clone("RecoKaon");
99         else{numeratorParent->Add((TH2F*) out2->FindObject(Form("EtNReconstructed%s%sCB%i",myname,"KPlus",i)));}
100         numeratorParent->Add((TH2F*) out2->FindObject(Form("EtNReconstructed%s%sCB%i",myname,"KMinus",i)));
101       }
102     }
103     else{
104       cout<<"I am kaoning here !"<<endl;
105       numeratorParent = (TH2F*)((TH2F*) out2->FindObject(Form("EtNReconstructed%s%s",myname,"KPlus")))->Clone("RecoKaon");
106       numeratorParent->Add((TH2F*) out2->FindObject(Form("EtNReconstructed%s%s",myname,"KMinus")));
107       cout<<"Numerator "<<numeratorParent->GetEntries()<<endl;
108     }
109     break;
110   case 3://proton
111     if(cblast != -1){//add more centrality bins
112       for(int i=cb;i<=cblast;i++){
113         if(i==cb) numeratorParent = (TH2F*)((TH2F*) out2->FindObject(Form("EtNReconstructed%s%sCB%i",myname,"Proton",i)))->Clone("RecoProton");
114         else{numeratorParent->Add((TH2F*) out2->FindObject(Form("EtNReconstructed%s%sCB%i",myname,"Proton",i)));}
115         numeratorParent->Add((TH2F*) out2->FindObject(Form("EtNReconstructed%s%sCB%i",myname,"AntiProton",i)));
116       }
117     }
118     else{
119       cout<<"I am protoning here !"<<endl;
120       numeratorParent = (TH2F*)((TH2F*) out2->FindObject(Form("EtNReconstructed%s%s",myname,"Proton")))->Clone("RecoProton");
121       numeratorParent->Add((TH2F*) out2->FindObject(Form("EtNReconstructed%s%s",myname,"AntiProton")));
122       cout<<"Numerator "<<numeratorParent->GetEntries()<<endl;
123     }
124     break;
125   case 4://electron
126     numeratorParent = (TH2F*)((TH2F*) out2->FindObject(Form("EtNReconstructed%s%s%s",myname,"EPlus",cbname)))->Clone("RecoElectron");
127     numeratorParent->Add((TH2F*) out2->FindObject(Form("EtNReconstructed%s%s%s",myname,"EMinus",cbname)));
128     break;
129   }
130   TH2F *denominatorParent; 
131   switch(mycase){
132   case 0:
133     if(cblast != -1){//add more centrality bins
134       denominatorParent = (TH2F*)((TH2F*) out2->FindObject(Form("EtNSimulatedChargedHadronCB%i",cb)))->Clone("RecoHadron");
135       for(int i=cb+1;i<=cblast;i++){
136         denominatorParent->Add((TH2F*) out2->FindObject(Form("EtNSimulatedChargedHadronCB%i",i)));
137       }
138     }
139     else{
140       denominatorParent = (TH2F*)((TH2F*) out2->FindObject("EtNSimulatedChargedHadron"))->Clone("RecoHadron");
141     }
142     break;
143   case 1://pion
144     if(cblast != -1){//add more centrality bins
145       denominatorParent = (TH2F*)((TH2F*) out2->FindObject(Form("EtNSimulatedPiPlusCB%i",cb)))->Clone("RecoPion");
146       denominatorParent->Add((TH2F*) out2->FindObject(Form("EtNSimulatedPiMinusCB%i",cb)));
147       for(int i=cb+1;i<=cblast;i++){
148         denominatorParent->Add((TH2F*) out2->FindObject(Form("EtNSimulatedPiPlusCB%i",i)));
149         denominatorParent->Add((TH2F*) out2->FindObject(Form("EtNSimulatedPiMinusCB%i",i)));
150       }
151     }
152     else{
153       denominatorParent = (TH2F*)((TH2F*) out2->FindObject("EtNSimulatedPiPlus"))->Clone("RecoPion");
154       denominatorParent->Add((TH2F*) out2->FindObject("EtNSimulatedPiMinus"));
155     }
156     break;
157   case 2://kaon
158     if(cblast != -1){//add more centrality bins
159       denominatorParent = (TH2F*)((TH2F*) out2->FindObject(Form("EtNSimulatedKPlusCB%i",cb)))->Clone("RecoKaon");
160       denominatorParent->Add((TH2F*) out2->FindObject(Form("EtNSimulatedKMinusCB%i",cb)));
161       for(int i=cb+1;i<=cblast;i++){
162         denominatorParent->Add((TH2F*) out2->FindObject(Form("EtNSimulatedKPlusCB%i",i)));
163         denominatorParent->Add((TH2F*) out2->FindObject(Form("EtNSimulatedKMinusCB%i",i)));
164       }
165     }
166     else{
167       cout<<"I am here kaoning"<<endl;
168       denominatorParent = (TH2F*)((TH2F*) out2->FindObject("EtNSimulatedKPlus"))->Clone("RecoKaon");
169       denominatorParent->Add((TH2F*) out2->FindObject("EtNSimulatedKMinus"));
170       cout<<"Denominator "<<denominatorParent->GetEntries()<<endl;
171     }
172     break;
173   case 3://proton
174     if(cblast != -1){//add more centrality bins
175       for(int i=cb;i<=cblast;i++){
176         if(cb==i)denominatorParent = (TH2F*)((TH2F*) out2->FindObject(Form("EtNSimulatedProtonCB%i",i)))->Clone("RecoProton");
177         else{denominatorParent->Add((TH2F*) out2->FindObject(Form("EtNSimulatedProtonCB%i",i)));}
178         denominatorParent->Add((TH2F*) out2->FindObject(Form("EtNSimulatedAntiProtonCB%i",i)));
179       }
180     }
181     else{
182       cout<<"I am here protoning"<<endl;
183       denominatorParent = (TH2F*)((TH2F*) out2->FindObject("EtNSimulatedProton"))->Clone("RecoProton");
184       denominatorParent->Add((TH2F*) out2->FindObject("EtNSimulatedAntiProton"));
185       cout<<"Denominator "<<denominatorParent->GetEntries()<<endl;
186     }
187     break;
188   case 4://electron
189     denominatorParent = (TH2F*)((TH2F*) out2->FindObject("EtNSimulatedEPlus"))->Clone("RecoElectron");
190     denominatorParent->Add((TH2F*) out2->FindObject("EtNSimulatedEMinus"));
191     break;
192   }
193       cout<<"Numerator "<<numeratorParent->GetEntries()<<endl;
194       cout<<"Denominator "<<denominatorParent->GetEntries()<<endl;
195   numeratorParent->Sumw2();
196   denominatorParent->Sumw2();
197   TH1D *denominator;
198   TH1D *numerator;
199   if(eta){
200     int lowbin = numeratorParent->GetYaxis()->FindBin(-cut+.001);//make sure we don't accv0entally get the wrong bin
201     int highbin = numeratorParent->GetYaxis()->FindBin(cut-.001);
202     cout<<"Projecting from "<<numeratorParent->GetYaxis()->GetBinLowEdge(lowbin)<<" to "<<numeratorParent->GetYaxis()->GetBinLowEdge(highbin+1)<<endl;
203     denominator = denominatorParent->ProjectionX(Form("garbage%s",name),lowbin,highbin);
204     numerator = numeratorParent->ProjectionX(name,lowbin,highbin);
205   }
206   else{
207     int lowbin = denominatorParent->GetXaxis()->FindBin(cut);//make sure we don't accidentally get the wrong bin
208     int highbin = denominatorParent->GetXaxis()->GetNbins();
209     cout<<"Here Projecting from "<<denominatorParent->GetXaxis()->GetBinLowEdge(lowbin)<<" to "<<denominatorParent->GetXaxis()->GetBinLowEdge(highbin+1)<<endl;
210     numerator = numeratorParent->ProjectionY(name,lowbin,highbin);
211     denominator = denominatorParent->ProjectionY(Form("denominator%s",name),lowbin,highbin);
212   }
213   delete numeratorParent;
214   delete denominatorParent;
215   //numerator->Divide(denominator);
216   TH1D *result = bayneseffdiv((TH1D*) numerator,(TH1D*)denominator,name);
217   //result->Rebin(2);
218   //result->Scale(0.5);
219   result->SetYTitle("Efficiency");
220   result->GetYaxis()->SetTitleOffset(0.8);
221   result->GetXaxis()->SetTitleOffset(0.8);
222   result->GetYaxis()->SetLabelSize(0.05);
223   result->GetXaxis()->SetLabelSize(0.05);
224   result->GetYaxis()->SetTitleSize(0.05);
225   result->GetXaxis()->SetTitleSize(0.05);
226   result->SetMarkerColor(color);
227   result->SetLineColor(color);
228   result->SetMarkerStyle(marker);
229   //result->Draw("e");
230   return result;
231
232 }
233
234
235 //this is a method that makes pretty plots
236 void CorrEfficiency(char *shortprodname= "LHC11a4_bis", char *prodname = "LHC11a4_bis HIJING 2.76 TeV Pb+Pb", bool TPC = true,bool ITS = true, bool eta = true, bool PbPb = true, int cb = 0, int cblast = -1){
237
238   gStyle->SetOptTitle(0);
239   gStyle->SetOptStat(0);
240   gStyle->SetOptFit(0);
241   TCanvas *c = new TCanvas("c","c",600,400);
242   c->SetTopMargin(0.02);
243   c->SetRightMargin(0.02);
244   c->SetBorderSize(0);
245   c->SetFillColor(0);
246   c->SetFillColor(0);
247   c->SetBorderMode(0);
248   c->SetFrameFillColor(0);
249   c->SetFrameBorderMode(0);
250   //c->SetLogx();
251
252   int colortotal = 1;
253   int colorpi = 2;
254   int colork = 3;
255   int colorp = 4;
256   int phosmarker = 20;
257   int emcalmarker = 24;
258   float ptcut1 = 0.05;
259   float ptcut2 = 0.1;
260   float phoscut = 0.12;
261   float emcalcut = 0.7;
262   if(!eta){
263     phoscut = 0.1;
264     emcalcut = 0.15;
265   }
266   TH1D *PHOStotal = GetHisto(phoscut,"PHOStotal",0,eta,colortotal,phosmarker,TPC,ITS,PbPb,cb,cblast);
267   TH1D *PHOSpi = GetHisto(phoscut,"PHOSpi",1,eta,colorpi,phosmarker,TPC,ITS,PbPb,cb,cblast);
268   TH1D *PHOSp = GetHisto(phoscut,"PHOSp",3,eta,colork,phosmarker,TPC,ITS,PbPb,cb,cblast);
269   TH1D *PHOSk = GetHisto(phoscut,"PHOSk",2,eta,colorp,phosmarker,TPC,ITS,PbPb,cb,cblast);
270   if(eta) PHOStotal->GetXaxis()->SetRange(PHOStotal->GetXaxis()->FindBin(0.05),PHOStotal->GetXaxis()->FindBin(1.0));
271 //if(ITS&&!TPC){PHOStotal->GetXaxis()->SetRange(PHOStotal->GetXaxis()->FindBin(0.05),PHOStotal->GetXaxis()->FindBin(1.0));}
272 //else{PHOStotal->GetXaxis()->SetRange(PHOStotal->GetXaxis()->FindBin(0.0),PHOStotal->GetXaxis()->FindBin(3.0));}
273   PHOStotal->SetMinimum(0.0);
274   PHOStotal->SetMaximum(1.0);
275   //parameters[centbin][0]*exp(-pow(parameters[centbin][1]/pt,parameters[centbin][2]))
276   TF1 *func = new TF1("func","[0]*exp(-pow([1]/x,[2]))");
277   func->SetParameter(0,.9);
278   func->SetParameter(1,.05);
279   func->SetParLimits(1,1e-3,1);
280   func->SetParameter(2,.1);
281   //PHOStotal->Fit(func);
282   PHOStotal->Draw();
283   PHOSpi->Draw("same");
284   PHOSp->Draw("same");
285   PHOSk->Draw("same");
286   cout<<"Hadrons"<<endl;
287   TH1D *EMCALtotal = GetHisto(emcalcut,"EMCALtotal",0,eta,colortotal,emcalmarker,TPC,ITS,PbPb,cb,cblast);
288   cout<<endl<<endl<<"=================================PIONS================================="<<endl;
289   TH1D *EMCALpi = GetHisto(emcalcut,"EMCALpi",1,eta,colorpi,emcalmarker,TPC,ITS,PbPb,cb,cblast);
290   cout<<endl<<endl<<"=================================PROTONS================================="<<endl;
291   TH1D *EMCALp = GetHisto(emcalcut,"EMCALp",3,eta,colork,emcalmarker,TPC,ITS,PbPb,cb,cblast);
292   cout<<endl<<endl<<"=================================KAONS================================="<<endl;
293   TH1D *EMCALk = GetHisto(emcalcut,"EMCALk",2,eta,colorp,emcalmarker,TPC,ITS,PbPb,cb,cblast);
294   EMCALtotal->Draw("same");
295   EMCALpi->Draw("same");
296   EMCALp->Draw("same");
297   EMCALk->Draw("same");
298
299
300   TLegend *leg = new  TLegend(0.22651,0.247312,0.370805,0.438172);
301   leg->AddEntry(PHOStotal,"#pi,K,p");
302   leg->AddEntry(PHOSpi,"#pi^{#pm}");
303   leg->AddEntry(PHOSk,"K^{#pm}");
304   leg->AddEntry(PHOSp,"p,#bar{p}");
305   leg->SetFillStyle(0);
306   leg->SetFillColor(0);
307   leg->SetBorderSize(0);
308   leg->SetTextSize(0.06);
309  leg->Draw();
310
311   TLine *line = new TLine(0.150,0.0,0.150,1.0);
312   if(eta)line->Draw();
313   line->SetLineWidth(3.0);
314   //line->SetLineColor(TColor::kYellow);
315   line->SetLineStyle(2);
316   TLatex *tex = new TLatex(0.398954,0.0513196,prodname);
317   tex->SetTextSize(0.0537634);
318   tex->Draw();
319   TLatex *tex3 = new TLatex(1.16186,0.28348,"Closed symbols |#eta|<0.12 (PHOS)");
320   tex3->SetTextSize(0.0537634);
321   tex3->Draw();
322   TLatex *tex4 = new TLatex(1.16186,0.213221,"Open symbols |#eta|<0.70 (EMCal)");
323   tex4->SetTextSize(0.0537634);
324   tex4->Draw();
325   TLatex *tex2 = new TLatex(0.164016,0.860826,"TPC cut-off 150 MeV/c");
326   tex2->SetTextSize(0.0537634);
327   if(eta) tex2->Draw();
328
329
330   TLine *line2 = new TLine(0.10,0.0,0.10,1.0);
331   line2->SetLineWidth(3.0);
332   TLatex *tex5 = new TLatex(0.10817,0.924976,"ITS cut-off 100 MeV/c");
333   tex5->SetTextSize(0.0537634);
334   line2->SetLineStyle(2);
335   tex5->SetTextColor(4);
336   line2->SetLineColor(4);
337   if(!TPC && eta){
338     line2->Draw();
339     tex5->Draw();
340   }
341   if(!TPC){
342     c->SaveAs("pics/CorrEfficiency.eps");
343     c->SaveAs("pics/CorrEfficiency.png");
344   }
345   else{
346     c->SaveAs("pics/CorrEfficiencyTPCITS.eps");
347     c->SaveAs("pics/CorrEfficiencyTPCITS.png");
348   }
349
350   if(PbPb){//make one more plot
351     //pions - no real centrality dependence
352     //three centrality bins for efficiency 0-25%, 25-50%, 50-90%
353     //use same for unidentified hadrons
354     //kaons & protons - centrality dependence is more significant but I don't think I can do better on the binning
355     int pid = 0;//h=0,pi=1,p=3,k=2
356   TCanvas *c2 = new TCanvas("c2","c2",600,400);
357   c2->SetTopMargin(0.02);
358   c2->SetRightMargin(0.02);
359   c2->SetBorderSize(0);
360   c2->SetFillColor(0);
361   c2->SetFillColor(0);
362   c2->SetBorderMode(0);
363   c2->SetFrameFillColor(0);
364   c2->SetFrameBorderMode(0);
365   cout<<endl<<endl;
366
367   TH1D *cb0 = GetHisto(phoscut,"cb0",pid,eta,1,20,TPC,ITS,PbPb,0,4);
368   TH1D *cb4 = GetHisto(phoscut,"cb5",pid,eta,4,20,TPC,ITS,PbPb,5,9);
369   //TH1D *cb9 = GetHisto(phoscut,"cb9",pid,eta,TColor::kGreen+4,20,TPC,ITS,PbPb,10,14);
370   TH1D *cb14 = GetHisto(phoscut,"cb14",pid,eta,2,20,TPC,ITS,PbPb,10,18);
371   cb0->GetXaxis()->SetRange(cb0->GetXaxis()->FindBin(0.05),cb0->GetXaxis()->FindBin(1.0));
372   cb0->SetMaximum(1.0);
373   cb0->Draw();
374   cb4->Draw("same");
375   // cb9->Draw("same");
376   cb14->Draw("same");
377   TLegend *leg = new TLegend(0.124161,0.747312,0.318792,0.959677);//(left,bottom,right,top)
378    leg->SetTextSize(0.0537634);
379    leg->SetBorderSize(0);
380    leg->SetLineColor(0);
381    leg->SetLineStyle(0);
382    leg->SetLineWidth(0);
383    leg->SetFillColor(0);
384    leg->SetFillStyle(0);
385    leg->AddEntry(cb0,"0-25%");
386    leg->AddEntry(cb4,"25-50%");
387    //leg->AddEntry(cb9,"45-50%");
388    leg->AddEntry(cb14,"50-90%");
389    leg->Draw();
390    c2->SaveAs(Form("pics/CorrEfficiency%i.png",pid));
391   }
392 }