13 #include "TEfficiency.h"
15 #include "TGraphAsymmErrors.h"
22 TChain *all =
new TChain(treename.c_str());
24 for (
int i = 0;
i < filecount; ++
i)
29 temp = name+
string(s.str())+extension;
30 all->Add(temp.c_str());
35 void makephotonM(TChain* ttree,TChain* back, TFile* out_file){
41 std::vector<TH1F*> plots;
42 ttree->SetBranchAddress(
"photon_m", &photon_m );
43 back->SetBranchAddress(
"photon_m", &back_m );
44 back->SetBranchAddress(
"vtx_radius", &back_Vtx );
45 back->SetBranchAddress(
"track_pT", &back_pt );
47 plots.push_back(
new TH1F(
"m^{#gamma}_{reco}",
"",60,0,.18));
48 plots.push_back(
new TH1F(
"m^{bkgd}_{reco}_wide",
"",60,0,1));
51 for (
int i = 0;
i < plots.size(); ++
i)
55 for (
int event = 0;
event < ttree->GetEntries(); ++
event)
57 ttree->GetEvent(
event);
58 plots[0]->Fill(photon_m);
61 for (
int event = 0;
event < back->GetEntries(); ++
event)
63 back->GetEvent(
event);
64 if(back_Vtx<21.&&back_pt>2.5)
65 plots[1]->Fill(back_m);
69 for (
int i = 0;
i < plots.size(); ++
i)
71 plots[
i]->Scale(1./ttree->GetEntries(),
"width");
74 ttree->ResetBranchAddresses();
77 void makeVtxR(TChain* ttree, TTree* vtxTree,TFile* out_file){
82 ttree->SetBranchAddress(
"vtx_radius",&vtxr);
83 ttree->SetBranchAddress(
"tvtx_radius",&tvtxr);
84 vtxTree->SetBranchAddress(
"vtx_x",&vtxX);
85 vtxTree->SetBranchAddress(
"vtx_y",&vtxY);
87 std::vector<TH1F*> plots;
88 plots.push_back(
new TH1F(
"vtx_reco",
"",30,0,40));
89 plots.push_back(
new TH1F(
"vtx_corrected",
"",30,0,40));
90 plots.push_back(
new TH1F(
"vtx_truth",
"",30,0,40));
97 for (
int event = 0;
event < ttree->GetEntries(); ++
event)
99 ttree->GetEvent(
event);
100 plots[1]->Fill(vtxr);
101 plots[2]->Fill(tvtxr);
102 calc+=TMath::Abs(vtxr-tvtxr);
104 calc/=ttree->GetEntries();
105 for (
int i = 0;
i < vtxTree->GetEntries(); ++
i)
107 vtxTree->GetEvent(
i);
108 plots[0]->Fill(sqrt(vtxX*vtxX+vtxY*vtxY));
110 for (
int i = 0;
i < 3; ++
i)
112 plots[
i]->Scale(1./plots[2]->GetEntries(),
"width");
115 std::cout<<
"mean deviation="<<calc<<std::endl;
121 ttree->SetBranchAddress(
"vtx_radius",&r);
122 ttree->SetBranchAddress(
"tvtx_radius",&tr);
123 TH1F *vtxeffPlot =
new TH1F(
"#frac{#Deltar_{vtx}_^{#it{reco}}}{r_{vtx}^{#it{truth}}}",
"",40,-2,2);
124 TH2F *vtxefffuncPlot =
new TH2F(
"vtx_resolution_to_truthvtx",
"",20,0,21,40,-1.5,1.5);
126 vtxefffuncPlot->Sumw2();
127 for (
int event = 0;
event < ttree->GetEntries(); ++
event)
129 ttree->GetEvent(
event);
131 vtxeffPlot->Fill((r-tr)/tr);
132 vtxefffuncPlot->Fill(tr,(r-tr)/tr);
134 vtxeffPlot->Scale(1./ttree->GetEntries(),
"width");
135 vtxefffuncPlot->Scale(1./ttree->GetEntries(),
"width");
137 ttree->ResetBranchAddresses();
144 ttree->SetBranchAddress(
"vtx_radius",&r);
145 ttree->SetBranchAddress(
"tvtx_radius",&tr);
146 ttree->SetBranchAddress(
"track_pT",&pT);
148 TH1F *recoR=
new TH1F(
"vtxrecoR",
"",30,0,40);
149 TH1F *truthR=
new TH1F(
"vtxtruthR",
"",30,0,40);
152 for (
int event = 0;
event < ttree->GetEntries(); ++
event)
154 ttree->GetEvent(
event);
155 if(r>0) recoR->Fill(tr);
158 vtxEff =
new TEfficiency(*recoR,*truthR);
159 vtxEff->SetName(
"vtxEff");
162 ttree->ResetBranchAddresses();
168 ttree->SetBranchAddress(
"photon_pT",&pT);
169 ttree->SetBranchAddress(
"tphoton_pT",&tpT);
170 TH1F *pTRes =
new TH1F(
"#frac{#it{p}^{T}_{reco}}{#it{p}_{#it{truth}}^{T}}",
"",40,0,2.5);
172 for (
int event = 0;
event < ttree->GetEntries(); ++
event)
174 ttree->GetEvent(
event);
175 if(pT>0)pTRes->Fill(pT/tpT);
177 pTRes->Scale(1./pTRes->Integral());
178 ttree->ResetBranchAddresses();
182 TEfficiency*
makepTDist(TChain* ttree,TTree* allTree,TFile* out_file){
186 ttree->SetBranchAddress(
"photon_pT",&pT);
187 ttree->SetBranchAddress(
"tphoton_pT",&tpT);
189 vector<float> *allpT=NULL;
190 allTree->SetBranchAddress(
"photon_pT",&allpT);
192 TH1F *pTeffPlot =
new TH1F(
"#frac{#it{p}^{T}}{#it{p}_{#it{truth}}^{T}}",
"",40,-2,2);
193 TH2F *pTefffuncPlot =
new TH2F(
"pT_resolution_to_truthpt",
"",40,1,35,40,-1.5,1.5);
194 TH1F *converted_pTspec =
new TH1F(
"converted_photon_truth_pT",
"",25,5,30);
195 TH1F *all_pTspec =
new TH1F(
"all_photon_truth_pT",
"",25,5,30);
198 converted_pTspec->Sumw2();
200 pTefffuncPlot->Sumw2();
201 for (
int event = 0;
event < ttree->GetEntries(); ++
event)
203 ttree->GetEvent(
event);
204 if(pT>0)pTeffPlot->Fill(pT/tpT);
205 converted_pTspec->Fill(tpT);
206 if(pT>0)pTefffuncPlot->Fill(tpT,pT/tpT);
209 for (
int event = 0;
event < allTree->GetEntries(); ++
event)
211 allTree->GetEvent(
event);
212 for(
auto i : *allpT){
216 TEfficiency* uni_rate =
new TEfficiency(*converted_pTspec,*all_pTspec);
217 pTeffPlot->Scale(1./ttree->GetEntries(),
"width");
218 pTefffuncPlot->Scale(1./ttree->GetEntries());
219 TProfile* resProfile = pTefffuncPlot->ProfileX(
"func_prof",5,30);
223 ttree->ResetBranchAddresses();
229 signalTree->SetBranchAddress(
"track_deta",&detas);
230 background->SetBranchAddress(
"track_deta",&detab);
231 TH1F *detaS_plot =
new TH1F(
"detaS",
"",3000,-.001,1);
232 TH1F *detaB_plot =
new TH1F(
"detaB",
"",3000,-.001,1);
236 for (
int i = 0;
i < signalTree->GetEntries(); ++
i)
238 signalTree->GetEvent(
i);
239 detaS_plot->Fill(detas);
241 cout<<
"background has "<<background->GetEntries()<<
" entries"<<endl;
242 for (
int i = 0;
i < background->GetEntries(); ++
i)
244 background->GetEvent(
i);
245 detaB_plot->Fill(detab);
247 detaB_plot->Scale(1/detaB_plot->Integral());
248 detaS_plot->Scale(1/detaS_plot->Integral());
251 signalTree->ResetBranchAddresses();
252 background->ResetBranchAddresses();
263 ttree->SetBranchAddress(
"cluster_dphi",&dphi);
264 ttree->SetBranchAddress(
"cluster_prob",&prob);
265 ttree->SetBranchAddress(
"track_layer",&layer);
266 ttree->SetBranchAddress(
"track_dlayer",&dlayer);
267 ttree->SetBranchAddress(
"track_pT",&track_pT);
268 ttree->SetBranchAddress(
"track_deta",&deta);
269 ttree->SetBranchAddress(
"vtx_radius",&radius);
271 TH1F *layerDist =
new TH1F(
"layer",
"",16,-.5,15.5);
272 TH1F *probDist =
new TH1F(
"clust_prob",
"",30,-.5,1.);
273 TH1F *deta_plot =
new TH1F(
"deta",
"",30,-.001,.01);
274 TH1F *dlayer_plot =
new TH1F(
"dlayer",
"",11,-.5,10.5);
275 TH1F *r_plot =
new TH1F(
"signal_vtx_radius_dist",
"",26,-.5,25.5);
279 dlayer_plot->Sumw2();
281 unsigned badLayCount=0;
282 unsigned badClusCount=0;
283 unsigned bigDetaCount=0;
284 unsigned shortRadiusCount=0;
286 for (
int event = 0;
event < ttree->GetEntries(); ++
event)
288 ttree->GetEvent(
event);
289 if(layer==0)badLayCount++;
290 if(dphi<0&&track_pT>.6){
293 if(track_pT>.6&&dphi>=0){
294 layerDist->Fill(layer);
295 probDist->Fill(prob);
296 deta_plot->Fill(deta);
297 dlayer_plot->Fill(TMath::Abs(dlayer));
298 if(deta>.0082||TMath::Abs(dlayer)>9)bigDetaCount++;
300 r_plot->Fill(radius);
301 if(radius<1.84) shortRadiusCount++;
306 layerDist->Scale(1./ttree->GetEntries());
307 deta_plot->Scale(1./ttree->GetEntries());
308 dlayer_plot->Scale(1./ttree->GetEntries());
309 r_plot->Scale(1./ttree->GetEntries());
310 cout<<
"Signal rejection through layer cut= "<<(float)badLayCount/ttree->GetEntries()<<endl;
311 cout<<
"error= "<<sqrt((
float)badLayCount)/ttree->GetEntries()<<endl;
312 cout<<
"Signal rejection through clus cut= "<<(float)badClusCount/ttree->GetEntries()<<endl;
313 cout<<
"error= "<<sqrt((
float)badClusCount)/ttree->GetEntries()<<endl;
314 cout<<
"Signal rejection through deta cut= "<<(float)bigDetaCount/ttree->GetEntries()<<endl;
315 cout<<
"error= "<<sqrt((
float)bigDetaCount)/ttree->GetEntries()<<endl;
316 cout<<
"Signal rejection through radius cut= "<<(float)shortRadiusCount/ttree->GetEntries()<<endl;
317 cout<<
"error= "<<sqrt((
float)shortRadiusCount)/ttree->GetEntries()<<endl;
325 ttree->SetBranchAddress(
"refitdiffx",&diffx);
326 ttree->SetBranchAddress(
"refitdiffy",&diffy);
327 ttree->SetBranchAddress(
"refitdiffz",&diffz);
328 TH1F *diffplotx=
new TH1F(
"x_{0}-x_{refit}",
"",40,-10,10);
329 TH1F *diffploty=
new TH1F(
"y_{0}-y_{refit}",
"",40,-10,10);
330 TH1F *diffplotz=
new TH1F(
"z_{0}-z_{refit}",
"",40,-10,10);
336 for (
int event = 0;
event < ttree->GetEntries(); ++
event)
338 ttree->GetEvent(
event);
339 diffplotx->Fill(diffx);
340 diffploty->Fill(diffy);
341 diffplotz->Fill(diffz);
344 diffplotx->Scale(1./ttree->GetEntries(),
"width");
345 diffploty->Scale(1./ttree->GetEntries(),
"width");
346 diffplotz->Scale(1./ttree->GetEntries(),
"width");
349 ttree->ResetBranchAddresses();
354 caloFile.open(filename.c_str());
357 vector<double> xData, yData;
362 while(caloFile >>x>>s>>y){
366 double *xArray, *yArray;
369 TGraph *pTResCaloGraph =
new TGraph(xData.size(),xArray,yArray);
370 pTResCaloGraph->SetNameTitle(
"calopTRes",
"calopTRes");
371 pTResCaloGraph->Sort();
372 pTResCaloGraph->Write();
377 vector<float>* tpT= NULL;
378 ttree->SetBranchAddress(
"photon_pT",&tpT);
382 title+=
"_photon_truth_pT";
384 else title=
"photon_truth_pT";
385 TH1F *tpTspec =
new TH1F(title.c_str(),
"",20,5,25);
387 cout<<
"pythia tree with: "<<ttree->GetEntries()<<
" entries"<<endl;
388 for (
int event = 0;
event < ttree->GetEntries(); ++
event)
390 ttree->GetEvent(
event);
392 if(
i>5)tpTspec->Fill(
i);
396 ttree->ResetBranchAddresses();
402 string rname = h.GetName();
404 TH1F
r = TH1F(rname.c_str(),h.GetTitle(),h.GetNbinsX()-1,h.GetBinLowEdge(2),h.GetBinLowEdge(h.GetNbinsX()+1));
406 for(
unsigned i=1;
i<r.GetNbinsX();++
i){
407 r.SetBinContent(
i,h.GetBinContent(
i+1));
408 r.SetBinError(
i,h.GetBinError(
i+1));
418 cout<<
"AD:"<<ad<<endl;
420 if(ad<.2) r= 1-TMath::Exp(-13.436+101.14*ad-223.74*ad*ad);
421 else if (ad<.34) r= 1-TMath::Exp(-8.31+42.79*ad-59.938*ad*ad);
422 else if (ad<.6) r= 1-TMath::Exp(.917-4.279*ad-1.38*ad*ad);
423 else r= 1-TMath::Exp(1.29-5.709*ad+.0186*ad*ad);
429 hard.Scale(1/hard.Integral());
430 soft.Scale(1/soft.Integral());
431 return soft.Chi2Test(&hard,
"WW CHI2/NDF");
435 unsigned bins = soft.GetNbinsX();
436 while(
ADtoP(hard.AndersonDarlingTest(&soft))>.05&&bins>2){
437 cout<<
"Hard/Soft p="<<
ADtoP(hard.AndersonDarlingTest(&soft))<<
" n bins="<<hard.GetNbinsX()<<endl;
438 cout<<
"chi2 p="<<
smartChi2(hard,soft)<<
" n bins="<<hard.GetNbinsX()<<endl;
443 TH1F* temp = (TH1F*) hard.Clone(
"hard_chopped");
448 TH1F* conversion_rate = (TH1F*) pythia->Clone(
"rate");
449 TH1* uni_rate = (TH1F*)rate->GetPassedHistogram()->Clone(
"uni_rate");
450 uni_rate->Divide(rate->GetTotalHistogram());
451 conversion_rate->Multiply(uni_rate);
452 conversion_rate->Scale(1/pythia->Integral());
457 cout<<soft->Integral(matchBin,soft->GetNbinsX())<<endl;
458 cout<<hard->Integral(matchBin,soft->GetNbinsX())<<endl;
459 return soft->Integral(matchBin,soft->GetNbinsX())/hard->Integral(matchBin,hard->GetNbinsX());
463 TH1F* combined =
new TH1F(
"combinedpythia",
"",soft->GetNbinsX(),soft->GetBinLowEdge(1),hard->GetBinLowEdge(hard->GetNbinsX()+1));
464 unsigned matchBin = 11;
465 for (
int i = 1;
i < matchBin; ++
i)
467 combined->SetBinContent(
i,soft->GetBinContent(
i));
468 combined->SetBinError(
i,soft->GetBinError(
i));
471 for (
int i = matchBin;
i < combined->GetNbinsX()+1; ++
i)
473 combined->SetBinContent(
i,hard->GetBinContent(
i));
474 combined->SetBinError(
i,hard->GetBinError(
i));
482 TFile *out_file =
new TFile(
"effplots2.root",
"UPDATE");
483 string treePath =
"/sphenix/user/vassalli/gammasample/embeded/truthconversionembededanalysis";
484 string treeExtension =
".root";
485 unsigned int nFiles=1000;
495 TChain *ttree =
handleFile(treePath,treeExtension,
"cutTreeSignal",nFiles);
496 TChain *pairBackTree =
handleFile(treePath,treeExtension,
"pairBackTree",nFiles);
497 TChain *vtxBackTree =
handleFile(treePath,treeExtension,
"vtxBackTree",nFiles);
498 TChain *vertexingTree =
handleFile(treePath,treeExtension,
"vtxingTree",nFiles);
512 makeVtxR(ttree,vertexingTree,out_file);