2 ofstream spreadsheet(
"./effic.csv");
4 void plCalcEffic(
int charge = 2){
5 system(
"mkdir -p plots/");
11 else plCalcEfficX(charge);
15 void plCalcEfficX(
int charge = 0,
char* iPath=
"/star/u/stevens4/wAnalysis/efficXsec/outEmb/gainUp2/"){
18 if(charge==0) sign=
"+";
19 else if(charge==1) sign=
"-";
22 if(charge == 1) core0=
"Wminus";
23 else if(charge == 0) core0=
"Wplus";
25 ofstream latex(Form(
"./%s.txt",core0));
29 gStyle->SetPalette(1);
32 TString fullInpName=iPath; fullInpName+=core0;
33 fullInpName+=
".wana.hist.root";
34 fd=
new TFile(fullInpName);
36 printf(
"ERROR: input histo file not found, quit\n",fullInpName.Data());
39 printf(
"Opened: %s\n",fullInpName.Data());
51 float etplot[5]={1.0,1.0,1.0,1.0,1.0};
52 float etplotErr[5]={1.0,1.0,1.0,1.0,0.0};
53 float zdcplot[5]={2.0,2.0,2.0,2.0,2.0};
54 float zdcplotErr[5]={1.0,1.0,1.0,1.0,0.0};
57 TH1F *hTrigET=doEfficiency(fd,
"MCeleETall",
"MCeleETtrig",Form(
"W%s trigger efficiency",sign),etrebin,etplot[0],etplotErr[0]);
58 TH1F *hTrigEta=doEfficiency(fd,
"MCeleEtaAll",
"MCeleEtaTrig",Form(
"W%s trigger efficiency",sign),etaRebin,0);
59 TH1F *hTrigDetEta=doEfficiency(fd,
"MCeleDetEtaAll",
"MCeleDetEtaTrig",Form(
"W%s trigger efficiency",sign),etaRebin,0);
60 TH1F *hTrigZvert=doEfficiency(fd,
"MCeleZvertAll",
"MCeleZvertTrig",Form(
"W%s trigger efficiency",sign),zRebin,0);
61 TH1F *hTrigPhi=doEfficiency(fd,
"MCelePhiModulePairAll",
"MCelePhiModulePairTrig",Form(
"W%s trigger efficiency",sign),phiModuleRebin,0);
62 TH1F *hTrigZDC=doEfficiency(fd,
"MCeleZdcAll",
"MCeleZdcTrig",Form(
"W%s trigger efficiency",sign),zdcRebin,zdcplot[0],zdcplotErr[0]);
64 TH1F *hVertET=doEfficiency(fd,
"MCeleETtrig",
"MCeleETvert",Form(
"W%s vertex efficiency",sign),etrebin,etplot[1],etplotErr[1]);
65 TH1F *hVertEta=doEfficiency(fd,
"MCeleEtaTrig",
"MCeleEtaVert",Form(
"W%s vertex efficiency",sign),etaRebin,0);
66 TH1F *hVertZvert=doEfficiency(fd,
"MCeleZvertTrig",
"MCeleZvertVert",Form(
"W%s vertex efficiency",sign),zRebin,0);
67 TH1F *hVertPhi=doEfficiency(fd,
"MCelePhiTrig",
"MCelePhiVert",Form(
"W%s vertex efficiency",sign),phiRebin,0);
68 TH1F *hVertZDC=doEfficiency(fd,
"MCeleZdcTrig",
"MCeleZdcVert",Form(
"W%s vertex efficiency",sign),zdcRebin,zdcplot[1],zdcplotErr[1]);
70 TH1F *hTrackET=doEfficiency(fd,
"MCeleETvert",
"MCeleETTrack",Form(
"W%s tracking efficiency",sign),etrebin,etplot[2],etplotErr[2]);
71 TH1F *hTrackEta=doEfficiency(fd,
"MCeleEtaVert",
"MCeleEtaTrack",Form(
"W%s tracking efficiency",sign),etaRebin,0);
72 TH1F *hTrackZvert=doEfficiency(fd,
"MCeleZvertVert",
"MCeleZvertTrack",Form(
"W%s tracking efficiency",sign),zRebin,0);
73 TH1F *hTrackPhi=doEfficiency(fd,
"MCelePhiVert",
"MCelePhiTrack",Form(
"W%s tracking efficiency",sign),phiRebin,0);
74 TH1F *hTrackZDC=doEfficiency(fd,
"MCeleZdcVert",
"MCeleZdcTrack",Form(
"W%s tracking efficiency",sign),zdcRebin,zdcplot[2],zdcplotErr[2]);
76 TH1F *hRecoET=doEfficiency(fd,
"MCeleETTrack",
"MCeleETreco",Form(
"W%s algo efficiency",sign),etrebin,etplot[3],etplotErr[3]);
77 TH1F *hRecoEta=doEfficiency(fd,
"MCeleEtaTrack",
"MCeleEtaReco",Form(
"W%s algo efficiency",sign),etaRebin,0);
78 TH1F *hRecoZvert=doEfficiency(fd,
"MCeleZvertTrack",
"MCeleZvertReco",Form(
"W%s algo efficiency",sign),zRebin,0);
79 TH1F *hRecoPhi=doEfficiency(fd,
"MCelePhiTrack",
"MCelePhiReco",Form(
"W%s algo efficiency",sign),phiRebin,0);
80 TH1F *hRecoZDC=doEfficiency(fd,
"MCeleZdcTrack",
"MCeleZdcReco",Form(
"W%s algo efficiency",sign),zdcRebin,zdcplot[3],zdcplotErr[3]);
83 TH1F *hTotET=doEfficiency(fd,
"MCeleETall",
"MCeleETreco",Form(
"W%s total efficiency",sign),etrebin,etplot[4],etplotErr[4]);
84 TH1F *hTotZDC=doEfficiency(fd,
"MCeleZdcAll",
"MCeleZdcReco",Form(
"W%s total efficiency",sign),zdcRebin,zdcplot[4],zdcplotErr[4]);
85 float totEffic=etplot[0]*etplot[1]*etplot[2]*etplot[3];
87 cout<<
"Total Efficiency = "<<etplot[4]<<
" $\\pm$ "<<etplotErr[4]<<endl;
90 spreadsheet<<
"W"<<sign<<
" Total Efficiency"<<endl;
91 for(
int j=0; j<6; j++){
92 spreadsheet<<25+j*4<<
","<<29+j*4<<
","<<Form(
"%.4f",hTotET->GetBinContent(7+j))<<
","<<Form(
"%.4f",hTotET->GetBinError(7+j))<<endl;
96 int etAxisMin=0;
int etAxisMax=70;
99 cA=
new TCanvas(Form(
"W%s algo effic",sign),
"algo effic",800,600);
103 hRecoET->SetAxisRange(etAxisMin,etAxisMax);
111 cA->Print(Form(
"plots/W%salgoEffic.eps",sign));
112 cA->Print(Form(
"plots/W%salgoEffic.png",sign));
115 spreadsheet<<
"W"<<sign<<
" Algo Efficiency"<<endl;
116 latex<<
"W"<<sign<<
" Algo Efficiency"<<endl;
117 for(
int j=0; j<6; j++){
119 if(j<6) latex<<25+j*4<<
"$<E_T<$"<<29+j*4<<
" & "<<Form(
"%.4f",hRecoET->GetBinContent(7+j))<<
" $\\pm$ "<<Form(
"%.4f",hRecoET->GetBinError(7+j))<<
" $\\pm$ & \\\\"<<endl;
122 spreadsheet<<25+j*4<<
","<<29+j*4<<
","<<Form(
"%.4f",hRecoET->GetBinContent(7+j))<<
","<<Form(
"%.4f",hRecoET->GetBinError(7+j))<<endl;
126 cT=
new TCanvas(Form(
"W%s track effic",sign),
"track effic",800,600);
130 hTrackET->SetAxisRange(etAxisMin,etAxisMax);
135 hTrackZDC->SetMinimum(0.6);
139 cT->Print(Form(
"plots/W%strackEffic.eps",sign));
140 cT->Print(Form(
"plots/W%strackEffic.png",sign));
144 cV=
new TCanvas(Form(
"W%s vertex effic",sign),
"vertex effic",800,600);
148 hVertET->SetAxisRange(etAxisMin,etAxisMax);
154 hVertZDC->SetMinimum(0.6);
156 cV->Print(Form(
"plots/W%svertEffic.eps",sign));
157 cV->Print(Form(
"plots/W%svertEffic.png",sign));
161 c2D=
new TCanvas(Form(
"W%s trigger effic ET bins",sign),
"trigger effic ET bins",700,500);
162 j1=(TH2F*)fd->Get(
"MCeleEta_ptPreTrig");
165 spreadsheet<<
"W"<<sign<<
" Trigger Efficiency"<<endl;
166 latex<<
"W"<<sign<<
" Trigger Efficiency"<<endl;
167 for(
int j=0; j<6; j++){
168 h25[j] = j1->ProjectionX(Form(
"pt%d_%d",25+j*4,29+j*4),26+j*4,29+j*4);
169 h25[j]->SetTitle(Form(
"Lepton detector #eta (from Geant): PT=[%d,%d]",25+j*4,29+j*4));
173 float accepted = h25[j]->Integral(26,125);
174 float total = h25[j]->Integral();
178 if(j<6) latex<<25+j*4<<
"$<E_T<$"<<29+j*4<<
" & "<<Form(
"%.4f",hTrigET->GetBinContent(7+j))<<
" $\\pm$ "<<Form(
"%.4f",hTrigET->GetBinError(7+j))<<
" $\\pm$ & & "<<Form(
"%.4f",accepted/total)<<
" & \\\\"<<endl;
179 spreadsheet<<25+j*4<<
","<<29+j*4<<
","<<Form(
"%.4f",hTrigET->GetBinContent(7+j))<<
","<<Form(
"%.4f",hTrigET->GetBinError(7+j))<<endl;
183 Lx=h25[j]->GetListOfFunctions();
184 int max=h25[j]->GetMaximum();
185 ln1=
new TLine(-1,0,-1,max);
186 ln2=
new TLine(1,0,1,max);
187 ln1->SetLineWidth(2); ln2->SetLineWidth(2);
188 ln1->SetLineColor(kRed); ln1->SetLineStyle(2);
189 ln2->SetLineColor(kRed); ln2->SetLineStyle(2);
190 Lx->Add(ln1); Lx->Add(ln2);
196 c2D->Print(Form(
"plots/W%strigEfficNonConst.eps",sign));
197 c2D->Print(Form(
"plots/W%strigEfficNonConst.png",sign));
200 c=
new TCanvas(Form(
"W%s trigger effic",sign),
"trigger effic",800,600);
204 hTrigET->SetAxisRange(etAxisMin,etAxisMax);
211 c->Print(Form(
"plots/W%strigEffic.eps",sign));
212 c->Print(Form(
"plots/W%strigEffic.png",sign));
216 TH2F * g0=(TH2F * )fd->Get(
"muBdist1"); assert(g0);
217 TH2F * g1=(TH2F * )fd->Get(
"muBclET24R_ET"); assert(g1);
218 TH2F * g2=(TH2F * )fd->Get(
"muBclEjetE2D_ET"); assert(g2);
219 TH2F * g3=(TH2F * )fd->Get(
"musPtBalance_clust"); assert(g3);
220 cAlgo2=
new TCanvas(Form(
"W%s algo effic 2 ",sign),
"algo effic 2",800,600);
224 g0->GetXaxis()->SetRange(0,70);
227 g1->GetXaxis()->SetRange(0,70);
230 g2->GetXaxis()->SetRange(0,70);
233 g3->GetXaxis()->SetRange(0,70);
234 cAlgo2->Print(Form(
"plots/W%salgoEffic2.eps",sign));
235 cAlgo2->Print(Form(
"plots/W%salgoEffic2.png",sign));
245 TH1F* doEfficiency(TFile *fd,
char* name0,
char* name1,
char *tit,
int reb=1,
float &etplot,
float &etplotErr=0){
247 TH1F * h0=(TH1F * )fd->Get(name0); assert(h0);
248 TH1F * h1=(TH1F * )fd->Get(name1); assert(h1);
250 ha=(TH1F*) h0->Clone(); assert(ha);
251 hb=(TH1F*) h1->Clone(); assert(hb);
256 hc=(TH1F*) hb->Clone(); assert(hc);
260 float num=0;
float den=0;
261 float matchErr2=0;
float thrownErr2=0;
262 int nb=hb->GetNbinsX();
265 startBin=hb->GetXaxis()->FindBin(25.);
268 endBin=hb->GetXaxis()->FindBin(100.0);
271 endBin=hb->GetXaxis()->FindBin(200000.);
272 startBin=hb->GetXaxis()->FindBin(0.);
277 assert(nb==ha->GetNbinsX());
278 for(
int i=1; i<=nb; i++) {
279 float n0=ha->GetBinContent(i);
280 float n1=hb->GetBinContent(i);
281 float e0=ha->GetBinError(i);
282 float e1=hb->GetBinError(i);
284 float eff=(float) n1/n0;
297 else errEff=sqrt(e1*e1*(n0-n1)*(n0-n1)+(e0-e1)*(e0-e1)*n1*n1)/n0/n0;
300 hc->SetBinContent(i,eff);
301 hc->SetBinError(i,errEff);
302 if(i>=startBin && i<=endBin){
315 if(etplotErr>0.0) cout<<name1<<
"="<< num/den <<
" $\\pm$ "<< sqrt(matchErr2*(den-num)*(den-num) + (thrownErr2-matchErr2)*num*num)/den/den <<endl;
317 etplotErr=sqrt(matchErr2*(den-num)*(den-num) + (thrownErr2-matchErr2)*num*num)/den/den;
324 etplotErr=sqrt(matchErr2*(den-num)*(den-num) + (thrownErr2-matchErr2)*num*num)/den/den;