BayesianAnalysisToolkit  0.9.3
Private Attributes | List of all members
BCMTFChannel Class Reference

A class describing a physics channel. More...

#include <BCMTFChannel.h>

Collaboration diagram for BCMTFChannel:
Collaboration graph
[legend]

Public Member Functions

Constructors and destructors
 BCMTFChannel (const char *name)
 
 ~BCMTFChannel ()
 
Member functions (get)
std::string GetName ()
 
BCMTFTemplateGetData ()
 
BCMTFTemplateGetTemplate (int index)
 
BCMTFSystematicVariationGetSystematicVariation (int index)
 
bool GetFlagChannelActive ()
 
TH2D * GetHistUncertaintyBandExpectation ()
 
TH2D * GetHistUncertaintyBandPoisson ()
 
double GetRangeYMin ()
 
double GetRangeYMax ()
 
Member functions (set)
void SetName (const char *name)
 
void SetData (BCMTFTemplate *bctemplate)
 
void SetHistUncertaintyBandExpectation (TH2D *hist)
 
void SetHistUncertaintyBandPoisson (TH2D *hist)
 
void SetFlagChannelActive (bool flag)
 
void SetRangeY (double min, double max)
 
Member functions (miscellaneous methods)
void AddTemplate (BCMTFTemplate *bctemplate)
 
void AddSystematicVariation (BCMTFSystematicVariation *variation)
 
void CalculateHistUncertaintyBandPoisson ()
 
TH1D * CalculateUncertaintyBandPoisson (double minimum, double maximumm, int color)
 
Member functions (output methods)
void PrintTemplates (std::string filename)
 
void PrintTemplate (int index, const char *filename)
 
void PrintHistUncertaintyBandExpectation (const char *filename)
 
void PrintHistUncertaintyBandPoisson (const char *filename, const char *options="COLZ")
 
void PrintHistCumulativeUncertaintyBandPoisson (const char *filename)
 
void PrintUncertaintyBandPoisson (const char *filename, double minimum, double maximum, int color)
 

Private Attributes

std::string fName
 
BCMTFTemplatefData
 
double fRangeYMin
 
double fRangeYMax
 
std::vector< BCMTFTemplate * > fTemplateContainer
 
std::vector
< BCMTFSystematicVariation * > 
fSystematicVariationContainer
 
bool fFlagChannelActive
 
TH2D * fHistUncertaintyBandExpectation
 
TH2D * fHistUncertaintyBandPoisson
 

Detailed Description

A class describing a physics channel.

Author
Daniel Kollar
Kevin Kröninger
Version
1.1
Date
06.2012 This class describes a physics channel.

Definition at line 33 of file BCMTFChannel.h.

Constructor & Destructor Documentation

BCMTFChannel::BCMTFChannel ( const char *  name)

The default constructor.

Parameters
nameThe name of the channel.

Definition at line 25 of file BCMTFChannel.cxx.

26  : fData(0)
27  , fFlagChannelActive(true)
30 {
31  fName = name;
32 }
BCMTFChannel::~BCMTFChannel ( )

The default destructor.

Definition at line 35 of file BCMTFChannel.cxx.

36 {
37  if (fData)
38  delete fData;
39 
40  for (unsigned int i = 0; i < fTemplateContainer.size(); ++i)
41  delete (fTemplateContainer.at(i));
42 
43  for (unsigned int i = 0; i < fSystematicVariationContainer.size(); ++i)
44  delete (fSystematicVariationContainer.at(i));
45 
46  /*
47  if (fHistUncertaintyBandExpectation)
48  delete fHistUncertaintyBandExpectation;
49 
50  if (fHistUncertaintyBandPoisson)
51  delete fHistUncertaintyBandPoisson;
52  */
53 }

Member Function Documentation

void BCMTFChannel::AddSystematicVariation ( BCMTFSystematicVariation variation)
inline

Add a systematic variation.

Parameters
variationThe variation.

Definition at line 162 of file BCMTFChannel.h.

163  { fSystematicVariationContainer.push_back(variation); };
void BCMTFChannel::AddTemplate ( BCMTFTemplate bctemplate)
inline

Add a template.

Parameters
bctemplateThe template.

Definition at line 156 of file BCMTFChannel.h.

157  { fTemplateContainer.push_back(bctemplate); };
void BCMTFChannel::CalculateHistUncertaintyBandPoisson ( )

Calculate histogram for uncertainty band calculation.

Definition at line 222 of file BCMTFChannel.cxx.

223 {
224  // calculate histogram
225  int nbinsy_exp = fHistUncertaintyBandExpectation->GetNbinsY();
226  int nbinsx_poisson = fHistUncertaintyBandPoisson->GetNbinsX();
227  int nbinsy_poisson = fHistUncertaintyBandPoisson->GetNbinsY();
228 
229  // loop over x-axis of observation
230  for (int ix = 1; ix <= nbinsx_poisson; ++ix) {
231  double sum_w = 0;
232  // loop over y-axis of expectation and calculate sum of weights
233  for (int iy = 1; iy <= nbinsy_exp; ++iy) {
234  double w = fHistUncertaintyBandExpectation->GetBinContent(ix, iy);
235  sum_w += w;
236  }
237  // loop over y-axis of expectation
238  for (int iy = 1; iy <= nbinsy_exp; ++iy) {
239  double w = fHistUncertaintyBandExpectation->GetBinContent(ix, iy)/sum_w;
240  double expectation = fHistUncertaintyBandExpectation->GetYaxis()->GetBinCenter(iy);
241  // loop over y-axis of observation
242  for (int jbin = 1; jbin <= nbinsy_poisson; ++jbin) {
243  double p = TMath::Poisson(double(jbin-1), expectation);
244  double bincontent = 0;
245  if (iy>1)
246  bincontent=fHistUncertaintyBandPoisson->GetBinContent(ix, jbin);
247  fHistUncertaintyBandPoisson->SetBinContent(ix, jbin, bincontent+p*w);
248  }
249  }
250  }
251 
252 }
TH1D * BCMTFChannel::CalculateUncertaintyBandPoisson ( double  minimum,
double  maximumm,
int  color 
)

Calculate histogram for uncertainty band calculation and return a TH1D.

Parameters
minimumThe minimum value on the expectation.
maximumThe maximum value on the expectation.
colorThe color scheme.
Returns
A TH1D histogram.

Definition at line 255 of file BCMTFChannel.cxx.

256 {
257  TH1D* hist = new TH1D(*(fData->GetHistogram()));
258  hist->SetMarkerSize(0);
259  hist->SetFillColor(color);
260  hist->SetFillStyle(1001);
261 
262  int nbinsx_poisson = fHistUncertaintyBandPoisson->GetNbinsX();
263  int nbinsy_poisson = fHistUncertaintyBandPoisson->GetNbinsY();
264 
265  // loop over x-axis of observation
266  for (int ix = 1; ix <= nbinsx_poisson; ++ix) {
267  double sum_p = 0; // sum of all probabilities inside the interval
268  int limit_min = 0;
269  int limit_max = nbinsx_poisson-1;
270 
271  // loop over y-axis of observation
272  for (int jbin = 1; jbin <= nbinsy_poisson; ++jbin) {
273  double p = fHistUncertaintyBandPoisson->GetBinContent(ix, jbin);
274  sum_p+=p;
275  if (sum_p < minimum)
276  limit_min=jbin;
277  if (sum_p > maximum && (sum_p - p) < maximum )
278  limit_max=jbin-1;
279  }
280  // hist->SetBinContent(ix, 0.5*double(limit_min+limit_max));
281  // hist->SetBinError(ix, 0.5*double(limit_max-limit_min));
282  double ylimit_min = fHistUncertaintyBandPoisson->GetYaxis()->GetBinCenter(limit_min);
283  double ylimit_max = fHistUncertaintyBandPoisson->GetYaxis()->GetBinCenter(limit_max);
284  hist->SetBinContent(ix, 0.5*double(ylimit_min+ylimit_max));
285  hist->SetBinError(ix, 0.5*double(ylimit_max-ylimit_min));
286  }
287 
288  return hist;
289 }
BCMTFTemplate* BCMTFChannel::GetData ( )
inline
Returns
The data.

Definition at line 61 of file BCMTFChannel.h.

62  { return fData; };
bool BCMTFChannel::GetFlagChannelActive ( )
inline
Returns
Flag defining if the channel is active or not.

Definition at line 80 of file BCMTFChannel.h.

81  { return fFlagChannelActive; };
TH2D* BCMTFChannel::GetHistUncertaintyBandExpectation ( )
inline

Return a histogram ued for the calculation of the error band of the expectation.

Returns
The histogram.

Definition at line 87 of file BCMTFChannel.h.

TH2D* BCMTFChannel::GetHistUncertaintyBandPoisson ( )
inline

Return a histogram used for the calculation of the Poisson fluctuations.

Returns
The histogram.

Definition at line 93 of file BCMTFChannel.h.

94  { return fHistUncertaintyBandPoisson; };
std::string BCMTFChannel::GetName ( )
inline
Returns
The name of the channel.

Definition at line 56 of file BCMTFChannel.h.

57  { return fName; };
double BCMTFChannel::GetRangeYMax ( )
inline
Returns
The maximal y-range for printing.

Definition at line 103 of file BCMTFChannel.h.

104  { return fRangeYMax; };
double BCMTFChannel::GetRangeYMin ( )
inline
Returns
The minimal y-range for printing.

Definition at line 98 of file BCMTFChannel.h.

99  { return fRangeYMin; };
BCMTFSystematicVariation* BCMTFChannel::GetSystematicVariation ( int  index)
inline

Return a systematic variation

Parameters
indexThe systematic index.
Returns
The systematic variation.

Definition at line 75 of file BCMTFChannel.h.

76  { return fSystematicVariationContainer.at(index); };
BCMTFTemplate* BCMTFChannel::GetTemplate ( int  index)
inline

Return a template

Parameters
indexThe template index.
Returns
The template.

Definition at line 68 of file BCMTFChannel.h.

69  { return fTemplateContainer.at(index); };
void BCMTFChannel::PrintHistCumulativeUncertaintyBandPoisson ( const char *  filename)

Print cumulative histogram for uncertainty band calculation.

Parameters
filenameThe name of the file.

Definition at line 292 of file BCMTFChannel.cxx.

293 {
294  // create new canvas
295  TCanvas * c1 = new TCanvas();
296  c1->cd();
297 
298  // calculate error band
300 
301  TH2D hist(*fHistUncertaintyBandPoisson);
302 
303  int nbinsx_poisson = hist.GetNbinsX();
304  int nbinsy_poisson = hist.GetNbinsY();
305 
306  // loop over x-axis of observation
307  for (int ix = 1; ix <= nbinsx_poisson; ++ix) {
308  double sum_p = 0; // sum of all probabilities inside the interval
309 
310  // loop over y-axis of observation
311  for (int jbin = 1; jbin <= nbinsy_poisson; ++jbin) {
312  double p = hist.GetBinContent(ix, jbin);
313  sum_p+=p;
314  hist.SetBinContent(ix, jbin, sum_p);
315  }
316  }
317 
318  // draw histogram
319  hist.Draw("COLZ");
320  c1->Draw();
321 
322  // print
323  c1->Print(filename);
324 
325  // free memory
326  delete c1;
327 }
void BCMTFChannel::PrintHistUncertaintyBandExpectation ( const char *  filename)

Print histogram for uncertainty band calculation.

Parameters
filenameThe name of the file.

Definition at line 204 of file BCMTFChannel.cxx.

205 {
206  // create new canvas
207  TCanvas * c1 = new TCanvas();
208  c1->cd();
209 
210  // draw histogram
211  fHistUncertaintyBandExpectation->Draw("COLZ");
212  c1->Draw();
213 
214  // print
215  c1->Print(filename);
216 
217  // free memory
218  delete c1;
219 }
void BCMTFChannel::PrintHistUncertaintyBandPoisson ( const char *  filename,
const char *  options = "COLZ" 
)

Print histogram for uncertainty band calculation.

Parameters
filenameThe name of the file.

Definition at line 330 of file BCMTFChannel.cxx.

331 {
332  // create new canvas
333  TCanvas * c1 = new TCanvas();
334  c1->cd();
335 
336  // calculate error band
338 
339  // draw histogram
340  fHistUncertaintyBandPoisson->Draw(options);
341  c1->Draw();
342 
343  // print
344  c1->Print(filename);
345 
346  // free memory
347  delete c1;
348 }
void BCMTFChannel::PrintTemplate ( int  index,
const char *  filename 
)

Print a particular template with systematics.

Parameters
indexThe template index.
filenameThe name of the file.

Definition at line 136 of file BCMTFChannel.cxx.

137 {
138  // create new canvas
139  TCanvas * c1 = new TCanvas();
140  c1->cd();
141 
142  // get number of systematics
143  unsigned int nsystematics = fSystematicVariationContainer.size();
144 
145  // draw template
146  GetTemplate(index)->GetHistogram()->Draw();
147 
148  // print to file
149  if (nsystematics == 0)
150  c1->Print(filename);
151  else
152  c1->Print( (std::string(filename)+std::string("(")).c_str() );
153 
154  // loop over systematics
155  for (unsigned int isystematic = 0; isystematic < nsystematics; ++isystematic) {
156  c1->cd();
157 
158  // check that histogram exists
159  if (!GetSystematicVariation(isystematic)->GetHistogramUp(index) ||
160  !GetSystematicVariation(isystematic)->GetHistogramDown(index))
161  continue;
162 
163  // get histogram
164  TH1D hist = TH1D(*GetTemplate(index)->GetHistogram());
165  TH1D hist_up(hist);
166  TH1D hist_down(hist);
167 
168  // set style
169  hist.SetFillStyle(0);
170  hist_up.SetFillStyle(0);
171  hist_up.SetLineStyle(2);
172  hist_down.SetFillStyle(0);
173  hist_down.SetLineStyle(3);
174 
175  // get efficiency
176  double efficiency = GetTemplate(index)->GetEfficiency();
177 
178  // scale histogram
179  hist.Scale(efficiency/ hist.Integral());
180 
181  // loop over all bins
182  for (int i = 1; i <= hist.GetNbinsX(); ++i) {
183  hist.SetBinContent(i, GetTemplate(index)->GetHistogram()->GetBinContent(i));
184  hist_up.SetBinContent(i, hist.GetBinContent(i) * (1.0 + GetSystematicVariation(isystematic)->GetHistogramUp(index)->GetBinContent(i)));
185  hist_down.SetBinContent(i, hist.GetBinContent(i) * (1.0 - GetSystematicVariation(isystematic)->GetHistogramDown(index)->GetBinContent(i)));
186  }
187 
188  // draw histogram
189  hist_up.Draw("HIST");
190  hist.Draw("HISTSAME");
191  hist_down.Draw("HISTSAME");
192 
193  if (isystematic < nsystematics-1)
194  c1->Print(filename);
195  else
196  c1->Print( (std::string(filename)+std::string(")")).c_str() );
197  }
198 
199  // free memory
200  delete c1;
201 }
void BCMTFChannel::PrintTemplates ( std::string  filename)

Print the templates in this channel.

Parameters
filenameThe name of the file.

Definition at line 56 of file BCMTFChannel.cxx.

57 {
58  // check if file extension is pdf
59  if ( (filename.find_last_of(".") != std::string::npos) &&
60  (filename.substr(filename.find_last_of(".")+1) == "pdf") ) {
61  ; // it's a PDF file
62 
63  }
64  else if ( (filename.find_last_of(".") != std::string::npos) &&
65  (filename.substr(filename.find_last_of(".")+1) == "ps") ) {
66  ; // it's a PS file
67  }
68  else {
69  ; // make it a PDF file
70  filename += ".pdf";
71  }
72 
73  // create new canvas
74  TCanvas * c1 = new TCanvas();
75  c1->cd();
76 
77  // get number of templates
78  int ntemplates = int(fTemplateContainer.size());
79 
80  int first_hist = -1;
81  int last_hist = 0;
82 
83  // calculate first and last existing histogram
84  for (int i = 0; i < ntemplates; ++i) {
85  // get histogram
86  TH1D * temphist = GetTemplate(i)->GetHistogram();
87 
88  if (first_hist < 0 && temphist)
89  first_hist = i;
90 
91  if (temphist)
92  last_hist = i;
93  }
94 
95  // Don't print if there are no histograms
96  if ( first_hist < 0 ) {
97  // free memory
98  delete c1;
99 
100  return;
101  }
102 
103  // loop over templates
104  for (int i = 0; i < ntemplates; ++i) {
105 
106  // get histogram
107  TH1D * temphist = GetTemplate(i)->GetHistogram();
108 
109  TLatex* l = new TLatex();
110 
111  // draw
112  if (temphist) {
113  temphist->Draw();
114  l->DrawTextNDC(0.2, 0.9, Form("%s - %s", fName.c_str(), GetTemplate(i)->GetProcessName().c_str()));
115  }
116 
117  // print
118  if (i == first_hist && (first_hist != last_hist))
119  c1->Print(std::string( filename + "(").c_str());
120  else if (i == last_hist && (first_hist != last_hist))
121  c1->Print(std::string( filename + ")").c_str());
122  else {
123  if (temphist)
124  c1->Print(filename.c_str());
125  }
126 
127  // free memory
128  delete l;
129  }
130 
131  // free memory
132  delete c1;
133 }
void BCMTFChannel::PrintUncertaintyBandPoisson ( const char *  filename,
double  minimum,
double  maximum,
int  color 
)

Print uncertainty band.

Parameters
filenameThe name of the file.

Definition at line 351 of file BCMTFChannel.cxx.

352 {
353  // create new canvas
354  TCanvas * c1 = new TCanvas();
355  c1->cd();
356 
357  // calculate error band
358  TH1D* hist=CalculateUncertaintyBandPoisson(minimum, maximum, color);
359 
360  // draw histogram
361  hist->Draw("E2");
362  c1->Draw();
363 
364  // print
365  c1->Print(filename);
366 
367  // free memory
368  delete c1;
369 }
void BCMTFChannel::SetData ( BCMTFTemplate bctemplate)
inline

Set the data set.

Parameters
bctemplateThe data set.

Definition at line 119 of file BCMTFChannel.h.

120  { fData = bctemplate; };
void BCMTFChannel::SetFlagChannelActive ( bool  flag)
inline

Set flag to define if the channel is active or not.

Parameters
flagThe flag.

Definition at line 138 of file BCMTFChannel.h.

139  { fFlagChannelActive = flag; };
void BCMTFChannel::SetHistUncertaintyBandExpectation ( TH2D *  hist)
inline

Set a histogram ued for the calculation of the error band of the expectation.

Parameters
histThe histogram.

Definition at line 126 of file BCMTFChannel.h.

126  {
void BCMTFChannel::SetHistUncertaintyBandPoisson ( TH2D *  hist)
inline

Set a histogram used for the calculation of the Poisson fluctuations.

Parameters
Thehistogram.

Definition at line 132 of file BCMTFChannel.h.

132  {
void BCMTFChannel::SetName ( const char *  name)
inline

Set the name of the channel.

Parameters
nameThe name of the channel.

Definition at line 113 of file BCMTFChannel.h.

114  { fName = name; };
void BCMTFChannel::SetRangeY ( double  min,
double  max 
)
inline

Set the y-ranges for printing.

Parameters
minThe minimum range.
maxThe maximum range.

Definition at line 145 of file BCMTFChannel.h.

145  {
146  fRangeYMin = min; fRangeYMax = max; };

Member Data Documentation

BCMTFTemplate* BCMTFChannel::fData
private

The data set.

Definition at line 224 of file BCMTFChannel.h.

bool BCMTFChannel::fFlagChannelActive
private

Flag defining if the channel is active or not.

Definition at line 244 of file BCMTFChannel.h.

TH2D* BCMTFChannel::fHistUncertaintyBandExpectation
private

A histogram for the calculation of uncertainty bands.

Definition at line 248 of file BCMTFChannel.h.

TH2D* BCMTFChannel::fHistUncertaintyBandPoisson
private

A histogram for the calculation of uncertainty bands.

Definition at line 252 of file BCMTFChannel.h.

std::string BCMTFChannel::fName
private

The name of the channel.

Definition at line 220 of file BCMTFChannel.h.

double BCMTFChannel::fRangeYMax
private

The maximal y-range for printing.

Definition at line 232 of file BCMTFChannel.h.

double BCMTFChannel::fRangeYMin
private

The minimal y-range for printing.

Definition at line 228 of file BCMTFChannel.h.

std::vector<BCMTFSystematicVariation *> BCMTFChannel::fSystematicVariationContainer
private

A container of systematics.

Definition at line 240 of file BCMTFChannel.h.

std::vector<BCMTFTemplate *> BCMTFChannel::fTemplateContainer
private

A container of templates.

Definition at line 236 of file BCMTFChannel.h.


The documentation for this class was generated from the following files: