5 TEfficiency* CalcEfficHadrons(const char* fileName, Bool_t makeDraw=kFALSE)
8 TFile *file = new TFile(fileName);
10 // ********************************************
11 // parameters to check before running the macro
12 // ********************************************
14 const Int_t NHISTS = 4; // Check the number of histograms for different particle species
15 const Int_t NOUTPUTS = 3;
16 const Int_t NHISTOUT[NOUTPUTS] = {1,1,1};
17 const Int_t IHISTOUT[NOUTPUTS][NHISTS] = {{0,-1,-1,-1},{1,-1,-1,-1},{2,-1,-1,-1}};
18 const Float_t CUT_RES = 0.02;
20 Int_t style[NOUTPUTS] = {20,21,22};
21 Int_t color[NOUTPUTS] = {1,2,4};
23 const Int_t fgNumOfPtBins = 111; // Check the number of eta bins in the histograms
24 const Int_t fgNumOfEtaBins = 16; // Check the number of E bins in the histograms
25 const Int_t fgNumOfRBins = 45;
27 Double_t fgPtAxis[117]= {0.0,0.01,0.02,0.03,0.04, 0.05, 0.06,0.07,0.08,0.09, 0.10,0.11, .12,0.13, .14,0.15, .16,0.17, .18,0.19,
28 0.2, .22, .24, .26, .28, 0.30, 0.32, .34, .36, .38, 0.40, .42, .44, .46, .48,
29 0.5, .52, .54, .56, .58, 0.60, 0.62, .64, .66, .68, 0.70, .72, .74, .76, .78,
30 .80, .82, .84, .86, .88, 0.90, 0.92, .94, .96, .98, 1.00,1.05, 1.1,1.15, 1.2,
31 1.25, 1.3,1.35,1.40,1.45, 1.50, 1.55, 1.6,1.65, 1.7, 1.75, 1.8,1.85, 1.9,1.95,
32 2.0, 2.2, 2.4, 2.6, 2.8, 3.00, 3.20, 3.4, 3.6, 3.8, 4.00, 4.2, 4.4, 4.6, 4.8,
33 5.0, 5.5, 6.0, 6.5, 7.0, 7.50, 8.00, 8.5, 9.0, 9.5, 10.0,12.0,14.0,16.0,18.0,
34 20.0,25.0,30.0,35.0,40.0, 45.0, 50.0};
36 // declare histograms and graphs
37 TH2F *histNum[NHISTS];
38 TH2F *histDen[NHISTS];
39 TGraphErrors *graph[NOUTPUTS];
41 TEfficiency *effic[NOUTPUTS];
44 // retrieve the input list of histogram. Check the TList name in the input file.
45 TList *list = (TList*) file->Get("out1");
47 // retrieve the histograms in the list. Check the name of the histograms
48 histNum[0] = (TH2F*)list->FindObject("fHistPionRec_ResPt_EmcalMC");
49 histNum[1] = (TH2F*)list->FindObject("fHistKaonRec_ResPt_EmcalMC");
50 histNum[2] = (TH2F*)list->FindObject("fHistProtonRec_ResPt_EmcalMC");
51 histNum[3] = (TH2F*)list->FindObject("fHistMuonRec_ResPt_EmcalMC");
53 // retrieve the histograms in the list. Check the name of the histograms
54 histDen[0] = (TH2F*)list->FindObject("fHistPionAcc_EtaPt_EmcalMC");
55 histDen[1] = (TH2F*)list->FindObject("fHistKaonAcc_EtaPt_EmcalMC");
56 histDen[2] = (TH2F*)list->FindObject("fHistProtonAcc_EtaPt_EmcalMC");
57 histDen[3] = (TH2F*)list->FindObject("fHistMuonAcc_EtaPt_EmcalMC");
59 // ********************************************
61 Float_t x[fgNumOfPtBins]={0}, ex[fgNumOfPtBins]={0};
62 Float_t y[fgNumOfPtBins]={0}, ey[fgNumOfPtBins]={0};
67 // loop over different desired outputs
68 for (int iOut=0; iOut<NOUTPUTS; iOut++)
70 sprintf(efficName,"effic_%d",iOut);
71 effic[iOut] = new TEfficiency(efficName,efficName,fgNumOfPtBins,fgPtAxis);
74 for (int ix=0; ix<fgNumOfPtBins; ix++)
76 // initialize ET variables for a new particle species
77 x[ix]=histNum[0]->GetXaxis()->GetBinCenter(ix+1);
85 for (int iy=0; iy<fgNumOfEtaBins; iy++)
87 for (int iHist=0; iHist<NHISTOUT[iOut]; iHist++)
89 den += histDen[IHISTOUT[iOut][iHist]]->GetBinContent(ix+1,iy+1); // sum over all E bins in order to get total ET
93 // loop over residual bins
94 for (int iHist=0; iHist<NHISTOUT[iOut]; iHist++)
96 projYNum = histNum[IHISTOUT[iOut][iHist]]->ProjectionY();
97 for (int iy=0; iy<fgNumOfRBins; iy++)
99 Res = projYNum->GetBinCenter(iy+1);
101 num += histNum[IHISTOUT[iOut][iHist]]->GetBinContent(ix+1,iy+1); // sum over all E bins in order to get total ET
105 if ((num>0) && (den>0))
107 effic[iOut]->SetTotalEvents(ix,den);
108 effic[iOut]->SetPassedEvents(ix,num);
110 ey[ix] = y[ix]*sqrt(1/num+1/den);
111 //ey[ix] = ((num+1)*(num+2))/((den+2)*(den+3))-((num+1)*(num+1))/((den+2)*(den+2));
119 } // end of loop over E bins
121 graph[iOut] = new TGraphErrors(fgNumOfPtBins,x,y,ex,ey); // graphic of ET(>E_cut)/ET(total) for a given particle species and E cut
123 } // end of loop over different outputs
130 gStyle->SetOptTitle(0);
131 gStyle->SetOptStat(0);
132 gStyle->SetOptFit(0);
134 TCanvas *c = new TCanvas("c","c",500,400);
135 //c->SetTopMargin(0.04);
136 //c->SetRightMargin(0.04);
137 //c->SetLeftMargin(0.181452);
138 //c->SetBottomMargin(0.134409);
142 c->SetFrameFillColor(0);
143 c->SetFrameBorderMode(0);
146 for (int i=0; i<NOUTPUTS; i++)
148 graph[i]->SetMarkerStyle(style[i]);
149 graph[i]->SetMarkerColor(color[i]);
150 graph[i]->SetLineColor(color[i]);
151 graph[i]->SetFillColor(0);
154 graph[i]->GetXaxis()->SetTitle("E (GeV)");
155 graph[i]->GetYaxis()->SetTitle("effic");
156 graph[i]->SetMaximum(1.0);
157 graph[i]->SetMinimum(0.0);
158 graph[i]->Draw("AP");
164 for (int i=0; i<NOUTPUTS; i++)
166 effic[i]->SetMarkerStyle(style[i]);
167 effic[i]->SetMarkerColor(color[i]);
168 effic[i]->SetLineColor(color[i]);
169 effic[i]->SetFillColor(0);
170 effic[i]->SetTitle("efficiency; p_{T} (GeV/c); #epsilon");
176 effic[i]->Draw("Psame");
179 TLegend *leg = new TLegend(0.65,0.2,0.95,0.5);
180 leg->AddEntry(effic[0],"pions");
181 leg->AddEntry(effic[1],"kaons");
182 leg->AddEntry(effic[2],"protons");
183 //leg->AddEntry(effic[3],"muons");
184 leg->SetFillStyle(0);
185 leg->SetFillColor(0);
186 leg->SetBorderSize(0);
187 leg->SetTextSize(0.03);