19 #include "BCMTFTemplate.h" 20 #include "BCMTFSystematicVariation.h" 22 #include "BCMTFChannel.h" 27 , fFlagChannelActive(true)
28 , fHistUncertaintyBandExpectation(0)
29 , fHistUncertaintyBandPoisson(0)
39 for (
unsigned int i = 0; i < fTemplateContainer.size(); ++i)
40 delete (fTemplateContainer.at(i));
42 for (
unsigned int i = 0; i < fSystematicVariationContainer.size(); ++i)
43 delete (fSystematicVariationContainer.at(i));
45 delete fHistUncertaintyBandExpectation;
46 delete fHistUncertaintyBandPoisson;
52 if (fHistUncertaintyBandExpectation) {
53 delete fHistUncertaintyBandExpectation;
55 fHistUncertaintyBandExpectation = hist;
61 std::string newFilename(filename);
63 if ( (newFilename.find_last_of(
".") != std::string::npos) &&
64 (newFilename.substr(newFilename.find_last_of(
".") + 1) ==
"pdf") ) {
67 }
else if ( (newFilename.find_last_of(
".") != std::string::npos) &&
68 (newFilename.substr(newFilename.find_last_of(
".") + 1) ==
"ps") ) {
72 newFilename +=
".pdf";
76 TCanvas* c1 =
new TCanvas();
80 int ntemplates = int(fTemplateContainer.size());
86 for (
int i = 0; i < ntemplates; ++i) {
90 if (first_hist < 0 && temphist)
98 if ( first_hist < 0 ) {
106 for (
int i = 0; i < ntemplates; ++i) {
111 TLatex* l =
new TLatex();
116 l->DrawTextNDC(0.2, 0.9, (fName +
"-" +
GetTemplate(i)->GetProcessName()).data());
120 if (i == first_hist && (first_hist != last_hist))
121 c1->Print((newFilename +
"(").data());
122 else if (i == last_hist && (first_hist != last_hist))
123 c1->Print((newFilename +
")").data());
126 c1->Print(newFilename.data());
141 TCanvas* c1 =
new TCanvas();
145 unsigned int nsystematics = fSystematicVariationContainer.size();
151 if (nsystematics == 0)
152 c1->Print(filename.data());
154 c1->Print( (filename +
"(").data() );
157 for (
unsigned int isystematic = 0; isystematic < nsystematics; ++isystematic) {
166 TH1D hist = TH1D(*
GetTemplate(index)->GetHistogram());
168 TH1D hist_down(hist);
171 hist.SetFillStyle(0);
172 hist_up.SetFillStyle(0);
173 hist_up.SetLineStyle(2);
174 hist_down.SetFillStyle(0);
175 hist_down.SetLineStyle(3);
181 hist.Scale(efficiency / hist.Integral());
184 for (
int i = 1; i <= hist.GetNbinsX(); ++i) {
185 hist.SetBinContent(i,
GetTemplate(index)->GetHistogram()->GetBinContent(i));
191 hist_up.Draw(
"HIST");
192 hist.Draw(
"HISTSAME");
193 hist_down.Draw(
"HISTSAME");
195 if (isystematic < nsystematics - 1)
196 c1->Print(filename.data());
198 c1->Print( (filename +
")").data() );
209 TCanvas* c1 =
new TCanvas();
213 fHistUncertaintyBandExpectation->Draw(
"COLZ");
217 c1->Print(filename.data());
227 int nbinsy_exp = fHistUncertaintyBandExpectation->GetNbinsY();
228 int nbinsx_poisson = fHistUncertaintyBandPoisson->GetNbinsX();
229 int nbinsy_poisson = fHistUncertaintyBandPoisson->GetNbinsY();
232 for (
int ix = 1; ix <= nbinsx_poisson; ++ix) {
235 for (
int iy = 1; iy <= nbinsy_exp; ++iy) {
236 double w = fHistUncertaintyBandExpectation->GetBinContent(ix, iy);
240 for (
int iy = 1; iy <= nbinsy_exp; ++iy) {
241 double w = fHistUncertaintyBandExpectation->GetBinContent(ix, iy) / sum_w;
242 double expectation = fHistUncertaintyBandExpectation->GetYaxis()->GetBinCenter(iy);
244 for (
int jbin = 1; jbin <= nbinsy_poisson; ++jbin) {
245 double p = TMath::Poisson(
double(jbin - 1), expectation);
246 double bincontent = 0;
248 bincontent = fHistUncertaintyBandPoisson->GetBinContent(ix, jbin);
249 fHistUncertaintyBandPoisson->SetBinContent(ix, jbin, bincontent + p * w);
264 hist->SetMarkerSize(0);
265 hist->SetFillColor(color);
266 hist->SetFillStyle(1001);
268 int nbinsx_poisson = fHistUncertaintyBandPoisson->GetNbinsX();
269 int nbinsy_poisson = fHistUncertaintyBandPoisson->GetNbinsY();
272 for (
int ix = 1; ix <= nbinsx_poisson; ++ix) {
275 int limit_max = nbinsx_poisson - 1;
278 for (
int jbin = 1; jbin <= nbinsy_poisson; ++jbin) {
279 double p = fHistUncertaintyBandPoisson->GetBinContent(ix, jbin);
283 if (sum_p > maximum && (sum_p - p) < maximum )
284 limit_max = jbin - 1;
288 double ylimit_min = fHistUncertaintyBandPoisson->GetYaxis()->GetBinCenter(limit_min);
289 double ylimit_max = fHistUncertaintyBandPoisson->GetYaxis()->GetBinCenter(limit_max);
290 hist->SetBinContent(ix, 0.5 *
double(ylimit_min + ylimit_max));
291 hist->SetBinError(ix, 0.5 *
double(ylimit_max - ylimit_min));
301 TCanvas* c1 =
new TCanvas();
307 TH2D hist(*fHistUncertaintyBandPoisson);
309 int nbinsx_poisson = hist.GetNbinsX();
310 int nbinsy_poisson = hist.GetNbinsY();
313 for (
int ix = 1; ix <= nbinsx_poisson; ++ix) {
317 for (
int jbin = 1; jbin <= nbinsy_poisson; ++jbin) {
318 double p = hist.GetBinContent(ix, jbin);
320 hist.SetBinContent(ix, jbin, sum_p);
329 c1->Print(filename.data());
339 TCanvas* c1 =
new TCanvas();
346 fHistUncertaintyBandPoisson->Draw(options.c_str());
350 c1->Print(filename.data());
360 TCanvas* c1 =
new TCanvas();
371 c1->Print(filename.data());
void PrintHistUncertaintyBandExpectation(const std::string &filename)
Print histogram for uncertainty band calculation.
void SetHistUncertaintyBandExpectation(TH2D *hist)
Set a histogram ued for the calculation of the error band of the expectation.
void PrintTemplate(int index, const std::string &filename)
Print a particular template with systematics.
A guard object to prevent ROOT from taking over ownership of TNamed objects.
void PrintHistCumulativeUncertaintyBandPoisson(const std::string &filename)
Print cumulative histogram for uncertainty band calculation.
BCMTFTemplate * GetTemplate(int index)
Return a template.
void PrintHistUncertaintyBandPoisson(const std::string &filename, const std::string &options="COLZ")
Print histogram for uncertainty band calculation.
BCMTFSystematicVariation * GetSystematicVariation(int index)
Return a systematic variation.
void PrintUncertaintyBandPoisson(const std::string &filename, double minimum, double maximum, int color)
Print uncertainty band.
void SetName(const std::string &name)
Set the name of the channel.
TH1D * GetHistogramUp(int index)
Returns the histogram correponding to the up-scale variation of the systematic.
BCMTFChannel(const std::string &name)
The default constructor.
void CalculateHistUncertaintyBandPoisson()
Calculate histogram for uncertainty band calculation.
TH1D * GetHistogramDown(int index)
Returns the histogram correponding to the down-scale variation of the systematic. ...
~BCMTFChannel()
The default destructor.
TH1D * CalculateUncertaintyBandPoisson(double minimum, double maximum, int color)
Calculate histogram for uncertainty band calculation and return a TH1D.
void PrintTemplates(const std::string &filename)
Print the templates in this channel.