39 #if !defined(__CINT__) || defined(__MAKECINT__)
40 #include "Riostream.h"
45 #include "TGraphAsymmErrors.h"
50 void EfficiencyIntegral(
const char* prefix, TH1* pass, TH1* total,
double& eff,
double& error,
bool includeOverflow =
false)
61 TH1D passhist(
"temppasshist",
"", 1, 0, 1);
62 TH1D totalhist(
"temptotalhist",
"", 1, 0, 1);
65 passhist.SetBinContent(1, pass->Integral(0, pass->GetNbinsX()+1));
66 totalhist.SetBinContent(1, total->Integral(0, total->GetNbinsX()+1));
70 passhist.SetBinContent(1, pass->Integral(1, pass->GetNbinsX()));
71 totalhist.SetBinContent(1, total->Integral(1, total->GetNbinsX()));
73 TGraphAsymmErrors* effgraph =
new TGraphAsymmErrors(&passhist, &totalhist);
74 eff = effgraph->GetY()[0];
75 double effhigh = effgraph->GetEYhigh()[0];
76 double efflow = effgraph->GetEYlow()[0];
77 error = effhigh > efflow ? effhigh : efflow;
78 cout << prefix << eff <<
" + " << effhigh <<
" - " << efflow << endl;
82 void PlotEfficiency(
const char* histfilename =
"hists.root",
bool includeOverflow =
true)
98 TFile
file(histfilename);
100 TList* histolist = NULL;
101 TIter next(file.GetListOfKeys());
102 for (TObject* key = next(); key != NULL; key = next())
104 TList*
list =
dynamic_cast<TList*
>( file.Get(key->GetName()) );
112 if (histolist == NULL)
114 cout <<
"ERROR: Could not find the histogram list in file '" << histfilename <<
"'" << endl;
118 TH2* findableTracksHist =
dynamic_cast<TH2*
>( histolist->FindObject(
"findableTracksHist") );
119 TH2* foundTracksHistMC =
dynamic_cast<TH2*
>( histolist->FindObject(
"foundTracksHistMC") );
120 TH2* fakeTracksHist =
dynamic_cast<TH2*
>( histolist->FindObject(
"fakeTracksHist") );
122 if (findableTracksHist == NULL)
124 cout <<
"ERROR: Could not find the histogram findableTracksHist in TList '" << histolist->GetName() <<
"'" << endl;
127 if (foundTracksHistMC == NULL)
129 cout <<
"ERROR: Could not find the histogram foundTracksHistMC in TList '" << histolist->GetName() <<
"'" << endl;
132 if (fakeTracksHist == NULL)
134 cout <<
"ERROR: Could not find the histogram fakeTracksHist in TList '" << histolist->GetName() <<
"'" << endl;
138 TH1* projeffx = foundTracksHistMC->ProjectionX();
139 TH1* projfindx = findableTracksHist->ProjectionX();
140 TGraphAsymmErrors* effpt =
new TGraphAsymmErrors(projeffx, projfindx);
142 effpt->GetHistogram()->SetTitle(
"Efficiency of track reconstruction.");
143 effpt->GetHistogram()->SetXTitle(projeffx->GetXaxis()->GetTitle());
144 effpt->GetHistogram()->SetYTitle(
"#epsilon");
145 effpt->GetYaxis()->SetRangeUser(0, 1.1);
148 TH1* projfakex = fakeTracksHist->ProjectionX();
149 TGraphAsymmErrors* fakept =
new TGraphAsymmErrors(projfakex, projfindx);
151 fakept->GetHistogram()->SetTitle(
"Fake reconstructed tracks ratio.");
152 fakept->GetHistogram()->SetXTitle(projfakex->GetXaxis()->GetTitle());
153 fakept->GetHistogram()->SetYTitle(
"fake tracks / findable tracks");
156 TH1* projeffy = foundTracksHistMC->ProjectionY();
157 TH1* projfindy = findableTracksHist->ProjectionY();
158 TGraphAsymmErrors* effy =
new TGraphAsymmErrors(projeffy, projfindy);
160 effy->GetHistogram()->SetTitle(
"Efficiency of track reconstruction.");
161 effy->GetHistogram()->SetXTitle(projeffy->GetXaxis()->GetTitle());
162 effy->GetHistogram()->SetYTitle(
"#epsilon");
163 effy->GetYaxis()->SetRangeUser(0, 1.1);
166 TH1* projfakey = fakeTracksHist->ProjectionY();
167 TGraphAsymmErrors* fakey =
new TGraphAsymmErrors(projfakey, projfindy);
169 fakey->GetHistogram()->SetTitle(
"Fake reconstructed tracks ratio.");
170 fakey->GetHistogram()->SetXTitle(projfakey->GetXaxis()->GetTitle());
171 fakey->GetHistogram()->SetYTitle(
"fake tracks / findable tracks");
175 cout <<
"findable tracks = " << projfindx->Integral(0, projfindx->GetNbinsX()+1) << endl;
176 cout <<
"found tracks = " << projeffx->Integral(0, projeffx->GetNbinsX()+1) << endl;
177 cout <<
"fake tracks = " << projfakex->Integral(0, projfakex->GetNbinsX()+1) << endl;
181 cout <<
"findable tracks = " << projfindx->Integral(0, projfindx->GetNbinsX()+1) << endl;
182 cout <<
"found tracks = " << projeffx->Integral(0, projeffx->GetNbinsX()+1) << endl;
183 cout <<
"fake tracks = " << projfakex->Integral(0, projfakex->GetNbinsX()+1) << endl;
185 double eff, fake, deff, dfake;
186 EfficiencyIntegral(
"Total efficiency = ", projeffx, projfindx, eff, deff, includeOverflow);
187 EfficiencyIntegral(
"Total fake ratio = ", projfakex, projfindx, fake, dfake, includeOverflow);
188 cout <<
"Sum = " << eff + fake <<
" +/- " << sqrt(deff*deff + dfake*dfake) << endl;
void EfficiencyIntegral(const char *prefix, TH1 *pass, TH1 *total, double &eff, double &error, bool includeOverflow=false)
void PlotEfficiency(const char *histfilename="hists.root", bool includeOverflow=true)