4 #include <TDirectory.h>
6 namespace GetResolutionsNS {
12 TH1I *
Get1DHistogram(
const char * plugin,
const char * directoryName,
const char * name,
bool print =
true){
14 TString fullName = TString(plugin) +
"/" + TString(directoryName) +
"/" + TString(name);
15 thisFile->GetObject(fullName, histogram);
17 if (print) cout <<
"Unable to find histogram " << fullName.Data() << endl;
23 TH2I *
Get2DHistogram(
const char * plugin,
const char * directoryName,
const char * name){
25 TString fullName = TString(plugin) +
"/" + TString(directoryName) +
"/" + TString(name);
26 thisFile->GetObject(fullName, histogram);
28 cout <<
"Unable to find histogram " << fullName.Data() << endl;
37 TString fullName = TString(plugin) +
"/" + TString(directoryName) +
"/" + TString(name);
38 thisFile->GetObject(fullName, histogram);
40 cout <<
"Unable to find histogram " << fullName.Data() << endl;
59 void GetResolutionHistograms(TH2 *
hist2d, TH1D *rmshist, TH1D *fithist, TH1D *meanhist, TH1D *fitmeanhist,
int minhits, TString tag,
bool print);
64 std::vector<std::string> histname_plot,
65 std::vector<std::string> histdir_plot,
std::string plot_type,
66 std::vector<std::string> legend_plot,
bool logx=1) {
68 sprintf(canvasname,
"canvas_%s_%s",plot_label.c_str(),plot_type.c_str());
69 TCanvas *canvas_showers_sigma =
new TCanvas(canvasname,canvasname);
74 char fullhistname[255], plotfilename[255];
75 TLegend *leg_showers_sigma =
new TLegend(0.75,0.75,0.99,0.99);
76 for (
int i=0; i<histname_plot.size(); i++) {
77 sprintf(fullhistname,
"%s_%s_%s",histdir_plot[i].c_str(),histname_plot[i].c_str(),plot_type.c_str());
78 TH1D* histpointer = (TH1D*)gDirectory->Get(fullhistname);
79 if (histpointer==NULL) {
80 printf(
" no %s\n",fullhistname);
83 histpointer->SetTitle(plot_title.c_str());
86 else histpointer->Draw(
"same");
87 if (logx) histpointer->SetAxisRange(0.02,5);
88 leg_showers_sigma->AddEntry(histpointer,legend_plot[i].c_str(),
"ep");
91 leg_showers_sigma->Draw();
92 sprintf(plotfilename,
"plots/results/%s_%s_%s.png",plot_label.c_str(),plot_type.c_str(),tag.Data());
93 canvas_showers_sigma->Print(plotfilename);
99 printf(
"GetResolutions\n");
105 if ( GetResolutionsNS::thisFile == NULL) {
106 cout <<
"Unable to open file " <<
filename.Data() <<
"...Exiting" << endl;
109 cout <<
"Opened file " <<
filename.Data() <<
"...good" << endl;
113 char outfilename[255];
114 sprintf(outfilename,
"Resolutions_Results_%s.root",tag.Data());
115 printf(
"Opening for output %s\n",outfilename);
116 TFile *outputFile = TFile::Open(outfilename,
"RECREATE");
118 outputFile->mkdir(
"ResultOverview");
121 gStyle->SetOptStat(2220);
122 gStyle->SetOptFit(1);
128 std::vector<std::string> histname;
129 std::vector<std::string> histdir;
130 std::vector<int> minhits;
133 histdir.push_back(
"Showers");
134 histname.push_back(
"PionShowers_q-");
135 minhits.push_back(1000);
136 histdir.push_back(
"Showers");
137 histname.push_back(
"AllShowers_q0");
138 minhits.push_back(1000);
140 histdir.push_back(
"Points_deltaTVsEnergy");
141 histname.push_back(
"AllPoints_q-");
142 minhits.push_back(1000);
143 histdir.push_back(
"Points_deltaTVsEnergy");
144 histname.push_back(
"Layer1_q-");
145 minhits.push_back(1000);
146 histdir.push_back(
"Points_deltaTVsEnergy");
147 histname.push_back(
"Layer2_q-");
148 minhits.push_back(1000);
149 histdir.push_back(
"Points_deltaTVsEnergy");
150 histname.push_back(
"Layer3_q-");
151 minhits.push_back(1000);
152 histdir.push_back(
"Points_deltaTVsEnergy");
153 histname.push_back(
"Layer4_q-");
154 minhits.push_back(1000);
155 histdir.push_back(
"Points_deltaTVsEnergy");
156 histname.push_back(
"AllPoints_q0");
157 minhits.push_back(1000);
158 histdir.push_back(
"Points_deltaTVsEnergy");
159 histname.push_back(
"Layer1_q0");
160 minhits.push_back(1000);
161 histdir.push_back(
"Points_deltaTVsEnergy");
162 histname.push_back(
"Layer2_q0");
163 minhits.push_back(1000);
164 histdir.push_back(
"Points_deltaTVsEnergy");
165 histname.push_back(
"Layer3_q0");
166 minhits.push_back(1000);
167 histdir.push_back(
"Points_deltaTVsEnergy");
168 histname.push_back(
"Layer4_q0");
169 minhits.push_back(1000);
170 histdir.push_back(
"Points_deltaTVsShowerEnergy");
171 histname.push_back(
"AllPoints_q-");
172 minhits.push_back(1000);
173 histdir.push_back(
"Points_deltaTVsShowerEnergy");
174 histname.push_back(
"Layer1_q-");
175 minhits.push_back(1000);
176 histdir.push_back(
"Points_deltaTVsShowerEnergy");
177 histname.push_back(
"Layer2_q-");
178 minhits.push_back(1000);
179 histdir.push_back(
"Points_deltaTVsShowerEnergy");
180 histname.push_back(
"Layer3_q-");
181 minhits.push_back(1000);
182 histdir.push_back(
"Points_deltaTVsShowerEnergy");
183 histname.push_back(
"Layer4_q-");
184 minhits.push_back(1000);
185 histdir.push_back(
"Showers");
186 histname.push_back(
"PionShowersVsP_q-");
187 minhits.push_back(1000);
188 histdir.push_back(
"Showers");
189 histname.push_back(
"PionShowersVsZ_q-");
190 minhits.push_back(1000);
191 histdir.push_back(
"Showers");
192 histname.push_back(
"AllShowersVsZ_q0");
193 minhits.push_back(1000);
230 histdir.push_back(
"Target Time");
231 histname.push_back(
"deltaTVsCell_q-");
232 minhits.push_back(10);
233 histdir.push_back(
"Target Time");
234 histname.push_back(
"deltaTVsCell_q-_Eweight");
235 minhits.push_back(10);
236 histdir.push_back(
"Target Time");
237 histname.push_back(
"deltaTVsCell_q0");
238 minhits.push_back(10);
239 histdir.push_back(
"Target Time");
240 histname.push_back(
"deltaTVsCell_q0_Eweight");
241 minhits.push_back(10);
244 std::vector<TH2*> TimeVsEnergy;
245 std::vector<TH1D*> TimeSigma;
246 std::vector<TH1D*> TimeRMS;
247 std::vector<TH1D*> TimeMean;
248 std::vector<TH1D*> TimeFitMean;
253 TCanvas *canvas_resolutions =
new TCanvas(
"canvas_resolutions",
"canvas_resolutions",1200,800);
254 canvas_resolutions->Divide(xpads,ypads,0.001,0.001);
255 TCanvas *canvas_means =
new TCanvas(
"canvas_means",
"canvas_means",1200,800);
256 canvas_means->Divide(xpads,ypads,0.001,0.001);
257 for (
int i=0; i<histname.size(); i++) {
259 if (locTimeVsEnergy != NULL) {
260 TimeVsEnergy.push_back(locTimeVsEnergy);
262 printf(
"Looking for a weighted histogram\n");
264 if (locTimeVsEnergy != NULL) {
266 TimeVsEnergy.push_back(locTimeVsEnergy);
270 if (TimeVsEnergy[i] == NULL) {
271 TimeSigma.push_back(NULL);
272 TimeRMS.push_back(NULL);
273 TimeMean.push_back(NULL);
274 TimeFitMean.push_back(NULL);
279 TAxis * xaxis = TimeVsEnergy[i]->GetXaxis();
280 int nBinsX = TimeVsEnergy[i]->GetNbinsX();
281 char fullhistname[255];
282 sprintf(fullhistname,
"%s_%s_sigma",histdir[i].c_str(),histname[i].c_str());
284 TH1D* locTimeSigma = TimeVsEnergy[i]->ProjectionX(fullhistname);
285 TH1D* locTimeRMS = TimeVsEnergy[i]->ProjectionX(Form(
"%s_%s_RMS",histdir[i].c_str(),histname[i].c_str()));
286 TH1D* locTimeMean = TimeVsEnergy[i]->ProjectionX(Form(
"%s_%s_mean",histdir[i].c_str(),histname[i].c_str()));
287 TH1D* locTimeFitMean = TimeVsEnergy[i]->ProjectionX(Form(
"%s_%s_fitmean",histdir[i].c_str(),histname[i].c_str()));
288 TimeSigma.push_back(locTimeSigma);
289 TimeRMS.push_back(locTimeRMS);
290 TimeMean.push_back(locTimeMean);
291 TimeFitMean.push_back(locTimeFitMean);
303 TimeSigma[i]->GetYaxis()->SetTitle(
"#sigmat [ns]");
305 TimeRMS[i]->GetYaxis()->SetTitle(
"#sigmat [ns]");
307 TimeMean[i]->GetYaxis()->SetTitle(
"#deltat [ns]");
309 TimeFitMean[i]->GetYaxis()->SetTitle(
"#deltat [ns]");
311 TString newtag = tag +
"_" + histname[i].c_str();
313 GetResolutionHistograms(TimeVsEnergy[i],TimeRMS[i],TimeSigma[i],TimeMean[i],TimeFitMean[i],minhits[i],newtag.Data(),0);
314 canvas_resolutions->cd(i+1);
316 TimeSigma[i]->Draw(
"same");
317 canvas_means->cd(i+1);
318 TimeFitMean[i]->Draw();
322 char plotfilename[255];
324 sprintf(plotfilename,
"plots/results/resolution_pad_%s.png",tag.Data());
325 canvas_resolutions->Print(plotfilename);
326 sprintf(plotfilename,
"plots/results/means_pad_%s.png",tag.Data());
327 canvas_means->Print(plotfilename);
348 gStyle->SetOptStat(0);
349 gStyle->SetOptFit(0);
350 char title[255], fullhistname[255];
353 std::vector<std::string> histname_plot;
354 std::vector<std::string> histdir_plot;
355 std::vector<std::string> legend_plot;
357 histdir_plot.push_back(
"Showers");
358 histname_plot.push_back(
"PionShowers_q-");
359 legend_plot.push_back(
"Charged showers");
360 histdir_plot.push_back(
"Showers");
361 histname_plot.push_back(
"AllShowers_q0");
362 legend_plot.push_back(
"Neutral showers");
363 title_plot =
"BCAL Shower time resolution";
364 makeplot(title_plot,tag,
"shower",histname_plot,histdir_plot,
"sigma",legend_plot);
365 title_plot =
"BCAL Shower time offset";
366 makeplot(title_plot,tag,
"shower",histname_plot,histdir_plot,
"fitmean",legend_plot);
367 histdir_plot.clear();
368 histname_plot.clear();
372 histdir_plot.push_back(
"Points_deltaTVsEnergy");
373 histname_plot.push_back(
"AllPoints_q-");
374 legend_plot.push_back(
"All points");
375 histdir_plot.push_back(
"Points_deltaTVsEnergy");
376 histname_plot.push_back(
"Layer1_q-");
377 legend_plot.push_back(
"layer 1");
378 histdir_plot.push_back(
"Points_deltaTVsEnergy");
379 histname_plot.push_back(
"Layer2_q-");
380 legend_plot.push_back(
"layer 2");
381 histdir_plot.push_back(
"Points_deltaTVsEnergy");
382 histname_plot.push_back(
"Layer3_q-");
383 legend_plot.push_back(
"layer 3");
384 histdir_plot.push_back(
"Points_deltaTVsEnergy");
385 histname_plot.push_back(
"Layer4_q-");
386 legend_plot.push_back(
"layer 4");
387 title_plot =
"Charged points time resolution";
388 makeplot(title_plot,tag,
"charged_points",histname_plot,histdir_plot,
"sigma",legend_plot);
389 title_plot =
"Charged points time offset";
390 makeplot(title_plot,tag,
"charged_points",histname_plot,histdir_plot,
"fitmean",legend_plot);
391 histdir_plot.clear();
392 histname_plot.clear();
396 histdir_plot.push_back(
"Points_deltaTVsEnergy");
397 histname_plot.push_back(
"AllPoints_q0");
398 legend_plot.push_back(
"All points");
399 histdir_plot.push_back(
"Points_deltaTVsEnergy");
400 histname_plot.push_back(
"Layer1_q0");
401 legend_plot.push_back(
"Layer 1");
402 histdir_plot.push_back(
"Points_deltaTVsEnergy");
403 histname_plot.push_back(
"Layer2_q0");
404 legend_plot.push_back(
"Layer 2");
405 histdir_plot.push_back(
"Points_deltaTVsEnergy");
406 histname_plot.push_back(
"Layer3_q0");
407 legend_plot.push_back(
"Layer 3");
408 histdir_plot.push_back(
"Points_deltaTVsEnergy");
409 histname_plot.push_back(
"Layer4_q0");
410 legend_plot.push_back(
"Layer 4");
411 title_plot =
"Neutral points time resolution";
412 makeplot(title_plot,tag,
"neutral_points",histname_plot,histdir_plot,
"sigma",legend_plot);
413 title_plot =
"Neutral points time offset";
414 makeplot(title_plot,tag,
"neutral_points",histname_plot,histdir_plot,
"fitmean",legend_plot);
415 histdir_plot.clear();
416 histname_plot.clear();
419 histdir_plot.push_back(
"Showers");
420 histname_plot.push_back(
"AllShowersVsZ_q0");
421 legend_plot.push_back(
"Neutral showers");
422 histdir_plot.push_back(
"Showers");
423 histname_plot.push_back(
"PionShowersVsZ_q-");
424 legend_plot.push_back(
"Charged showers");
425 title_plot =
"Shower time resolution";
426 makeplot(title_plot,tag,
"shower_vsZ",histname_plot,histdir_plot,
"sigma",legend_plot,0);
427 title_plot =
"Shower time offset";
428 makeplot(title_plot,tag,
"shower_vsZ",histname_plot,histdir_plot,
"fitmean",legend_plot,0);
429 histdir_plot.clear();
430 histname_plot.clear();
433 histdir_plot.push_back(
"Showers");
434 histname_plot.push_back(
"PionShowersVsP_q-");
435 legend_plot.push_back(
"Charged showers");
436 title_plot =
"Shower time resolution";
437 makeplot(title_plot,tag,
"shower_vsP",histname_plot,histdir_plot,
"sigma",legend_plot);
438 title_plot =
"Shower time offset";
439 makeplot(title_plot,tag,
"shower_vsP",histname_plot,histdir_plot,
"fitmean",legend_plot);
440 histdir_plot.clear();
441 histname_plot.clear();
446 GetResolutionsNS::thisFile->Close();
456 TString tag,
bool print) {
458 TAxis * xaxis = hist2d->GetXaxis();
459 TAxis * yaxis = hist2d->GetYaxis();
460 int nBinsX = hist2d->GetNbinsX();
461 int nBinsY = hist2d->GetNbinsY();
463 printf(
"bins (%i,%i) %s %s\n",nBinsX,nBinsY,hist2d->GetName(),hist2d->GetTitle());
465 TH1D *mulitbin_projY = hist2d->ProjectionY(
"mulitbin_projY", 1, 1);
466 mulitbin_projY->Reset();
467 TH1D *xmean = hist2d->ProjectionX(
"xmean");
471 fitsigmahist->Reset();
473 fitmeanhist->Reset();
475 TCanvas *canvas_fit =
new TCanvas(
"canvas_fit",
"canvas_fit");
478 for (
int i = 1 ; i <= nBinsX; i++){
479 TH1D *singlebin_projY = hist2d->ProjectionY(
"temp", i, i);
480 mulitbin_projY->Add(singlebin_projY);
481 float center = yaxis->GetBinCenter(mulitbin_projY->GetMaximumBin());
484 float mintime = center-width;
485 float maxtime = center+width;
488 sprintf(title,
"E=%.3f GeV (%s)",xaxis->GetBinCenter(i),tag.Data());
489 mulitbin_projY->SetTitle(title);
491 int entries_multi = mulitbin_projY->GetEntries();
492 float int_multi = mulitbin_projY->Integral(yaxis->FindBin(mintime),yaxis->FindBin(maxtime));
493 float int_single = singlebin_projY->Integral(yaxis->FindBin(mintime),yaxis->FindBin(maxtime));
494 xmean->SetBinContent(i,int_single);
495 float weightedmean = xmean->GetMean();
497 int bin = xmean->FindBin(weightedmean);
499 if (entries_multi<minhits || (i==nBinsX && entries_multi<(minhits/4.))) {
505 mulitbin_projY->SetAxisRange(-5,5);
506 double mean = mulitbin_projY->GetMean();
507 double meanerr = mulitbin_projY->GetMeanError();
508 double RMS = mulitbin_projY->GetRMS();
509 double RMSerr = mulitbin_projY->GetRMSError();
510 rmshist->SetBinContent(bin,RMS);
511 rmshist->SetBinError(bin,RMSerr);
512 meanhist->SetBinContent(bin,mean);
513 meanhist->SetBinError(bin,meanerr);
515 mulitbin_projY->SetAxisRange(mintime,maxtime);
516 TF1 *f_gaus =
new TF1(
"f_gaus",
"gaus",mintime,maxtime);
517 f_gaus->SetLineColor(kRed);
518 f_gaus->SetLineWidth(1);
520 mulitbin_projY->Fit(f_gaus,
"RQ");
521 double fitmean = f_gaus->GetParameter(1);
522 double fitmeanerr = f_gaus->GetParError(1);
523 double sigma = f_gaus->GetParameter(2);
524 double sigmaerr = f_gaus->GetParError(2);
527 fitsigmahist->SetBinContent(bin,sigma);
528 fitsigmahist->SetBinError(bin,sigmaerr);
529 fitmeanhist->SetBinContent(bin,fitmean);
530 fitmeanhist->SetBinError(bin,fitmeanerr);
533 gStyle->SetPadRightMargin(0.20);
534 gStyle->SetStatW(0.20);
535 mulitbin_projY->SetAxisRange(-10,10);
536 sprintf(plotname,
"plots/resolutions/fit_%s_%i.png",tag.Data(),i);
537 canvas_fit->Print(plotname);
539 mulitbin_projY->Reset();
550 if (color > 4) color++;
551 if (color > 9) color = 791-9+number;
558 hist->SetMarkerStyle(markerstyle);
559 hist->SetMarkerSize(0.8);
560 hist->SetMarkerColor(color);
561 hist->SetLineColor(color);
562 hist->SetLineWidth(2);
void GetResolutions(int run=2931, TString filename="hd_root.root", TString tag="default", bool summary=1)
void GetResolutionHistograms(TH2 *hist2d, TH1D *rmshist, TH1D *fithist, TH1D *meanhist, TH1D *fitmeanhist, int minhits, TString tag, bool print)
sprintf(text,"Post KinFit Cut")
TH2D * Get2DWeightedHistogram(const char *plugin, const char *directoryName, const char *name)
void FormatHist(TH1 *hist, int color, int markerstyle)
TH2I * Get2DHistogram(const char *plugin, const char *directoryName, const char *name)
Double_t sigma[NCHANNELS]
void GetXYfromSize(int size, int &x, int &y)
TH1I * Get1DHistogram(const char *plugin, const char *directoryName, const char *name, bool print=true)
void makeplot(std::string plot_title, TString tag, std::string plot_label, std::vector< std::string > histname_plot, std::vector< std::string > histdir_plot, std::string plot_type, std::vector< std::string > legend_plot, bool logx=1)
printf("string=%s", string)