Private Attributes

BCMTFChannel Class Reference

A class describing a physics channel. More...

#include <BCMTFChannel.h>

Collaboration diagram for BCMTFChannel:
Collaboration graph
[legend]

List of all members.

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 (const char *filename)
void PrintTemplate (int index, const char *filename)
void PrintHistUncertaintyBandExpectation (const char *filename)
void PrintHistUncertaintyBandPoisson (const char *filename)
void PrintHistCumulativeUncertaintyBandPoisson (const char *filename)

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 32 of file BCMTFChannel.h.


Constructor & Destructor Documentation

BCMTFChannel::BCMTFChannel ( const char *  name  ) 

The default constructor.

Parameters:
name The name of the channel.

Definition at line 23 of file BCMTFChannel.cxx.

BCMTFChannel::~BCMTFChannel (  ) 

The default destructor.

Definition at line 33 of file BCMTFChannel.cxx.

{
   if (fData)
      delete fData;

   for (unsigned int i = 0; i < fTemplateContainer.size(); ++i)
      delete (fTemplateContainer.at(i));

   for (unsigned int i = 0; i < fSystematicVariationContainer.size(); ++i)
      delete (fSystematicVariationContainer.at(i));

    /*
    if (fHistUncertaintyBandExpectation)
       delete fHistUncertaintyBandExpectation;

    if (fHistUncertaintyBandPoisson)
       delete fHistUncertaintyBandPoisson;
    */
}


Member Function Documentation

void BCMTFChannel::AddSystematicVariation ( BCMTFSystematicVariation variation  )  [inline]

Add a systematic variation.

Parameters:
variation The variation.

Definition at line 161 of file BCMTFChannel.h.

         { fSystematicVariationContainer.push_back(variation); };

void BCMTFChannel::AddTemplate ( BCMTFTemplate bctemplate  )  [inline]

Add a template.

Parameters:
bctemplate The template.

Definition at line 155 of file BCMTFChannel.h.

         { fTemplateContainer.push_back(bctemplate); };

void BCMTFChannel::CalculateHistUncertaintyBandPoisson (  ) 

Calculate histogram for uncertainty band calculation.

Definition at line 205 of file BCMTFChannel.cxx.

{
   // calculate histogram
   int nbinsy_exp = fHistUncertaintyBandExpectation->GetNbinsY();
   int nbinsx_poisson = fHistUncertaintyBandPoisson->GetNbinsX();
   int nbinsy_poisson = fHistUncertaintyBandPoisson->GetNbinsY();
   
   // loop over x-axis of observation
   for (int ix = 1; ix <= nbinsx_poisson; ++ix) {
      double sum_w = 0;
      // loop over y-axis of expectation and calculate sum of weights
      for (int iy = 1; iy <= nbinsy_exp; ++iy) {
         double w = fHistUncertaintyBandExpectation->GetBinContent(ix, iy);
         sum_w += w;
      }
      // loop over y-axis of expectation
      for (int iy = 1; iy <= nbinsy_exp; ++iy) {
         double w = fHistUncertaintyBandExpectation->GetBinContent(ix, iy)/sum_w;
         double expectation = fHistUncertaintyBandExpectation->GetYaxis()->GetBinCenter(iy);
         // loop over y-axis of observation
         for (int jbin = 1; jbin <= nbinsy_poisson; ++jbin) {
            double p = TMath::Poisson(double(jbin-1), expectation);
            double bincontent = 0;
            if (iy>1)
               bincontent=fHistUncertaintyBandPoisson->GetBinContent(ix, jbin);
            fHistUncertaintyBandPoisson->SetBinContent(ix, jbin, bincontent+p*w);
         }
      }
   }
   
}

TH1D * BCMTFChannel::CalculateUncertaintyBandPoisson ( double  minimum,
double  maximumm,
int  color 
)

Calculate histogram for uncertainty band calculation and return a TH1D.

Parameters:
minimum The minimum value on the expectation.
maximum The maximum value on the expectation.
color The color scheme.
Returns:
A TH1D histogram.

Definition at line 238 of file BCMTFChannel.cxx.

{
   TH1D* hist = new TH1D(*(fData->GetHistogram()));
   hist->SetMarkerSize(0);
   hist->SetFillColor(color);
   hist->SetFillStyle(1001);

   int nbinsx_poisson = fHistUncertaintyBandPoisson->GetNbinsX();
   int nbinsy_poisson = fHistUncertaintyBandPoisson->GetNbinsY();

   // loop over x-axis of observation
   for (int ix = 1; ix <= nbinsx_poisson; ++ix) {
      double sum_p = 0;  // sum of all probabilities inside the interval
      int limit_min = 0;
      int limit_max = nbinsx_poisson-1;
      
      // loop over y-axis of observation
      for (int jbin = 1; jbin <= nbinsy_poisson; ++jbin) {
         double p = fHistUncertaintyBandPoisson->GetBinContent(ix, jbin);
         sum_p+=p;
         if (sum_p < minimum)
            limit_min=jbin;
         if (sum_p > maximum && (sum_p - p) < maximum ) 
            limit_max=jbin-1;
      }
      hist->SetBinContent(ix, 0.5*double(limit_min+limit_max));
      hist->SetBinError(ix, 0.5*double(limit_max-limit_min));
   }

   return hist;
}

BCMTFTemplate* BCMTFChannel::GetData (  )  [inline]
Returns:
The data.

Definition at line 60 of file BCMTFChannel.h.

         { return fData; };

bool BCMTFChannel::GetFlagChannelActive (  )  [inline]
Returns:
Flag defining if the channel is active or not.

Definition at line 79 of file BCMTFChannel.h.

         { 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 86 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 92 of file BCMTFChannel.h.

std::string BCMTFChannel::GetName (  )  [inline]
Returns:
The name of the channel.

Definition at line 55 of file BCMTFChannel.h.

         { return fName; };

double BCMTFChannel::GetRangeYMax (  )  [inline]
Returns:
The maximal y-range for printing.

Definition at line 102 of file BCMTFChannel.h.

         { return fRangeYMax; }; 

double BCMTFChannel::GetRangeYMin (  )  [inline]
Returns:
The minimal y-range for printing.

Definition at line 97 of file BCMTFChannel.h.

         { return fRangeYMin; }; 

BCMTFSystematicVariation* BCMTFChannel::GetSystematicVariation ( int  index  )  [inline]

Return a systematic variation

Parameters:
index The systematic index.
Returns:
The systematic variation.

Definition at line 74 of file BCMTFChannel.h.

         { return fSystematicVariationContainer.at(index); };

BCMTFTemplate* BCMTFChannel::GetTemplate ( int  index  )  [inline]

Return a template

Parameters:
index The template index.
Returns:
The template.

Definition at line 67 of file BCMTFChannel.h.

         { return fTemplateContainer.at(index); };

void BCMTFChannel::PrintHistCumulativeUncertaintyBandPoisson ( const char *  filename  ) 

Print cumulative histogram for uncertainty band calculation.

Parameters:
filename The name of the file.

Definition at line 271 of file BCMTFChannel.cxx.

{
   // create new canvas
   TCanvas * c1 = new TCanvas();
   c1->cd();

    // calculate error band
    this->CalculateHistUncertaintyBandPoisson();

    TH2D hist(*fHistUncertaintyBandPoisson);

   int nbinsx_poisson = hist.GetNbinsX();
   int nbinsy_poisson = hist.GetNbinsY();

   // loop over x-axis of observation
   for (int ix = 1; ix <= nbinsx_poisson; ++ix) {
      double sum_p = 0;  // sum of all probabilities inside the interval
      
      // loop over y-axis of observation
      for (int jbin = 1; jbin <= nbinsy_poisson; ++jbin) {
         double p = hist.GetBinContent(ix, jbin);
         sum_p+=p;
         hist.SetBinContent(ix, jbin, sum_p);
      }
   }

    // draw histogram
    hist.Draw("COLZ");
    c1->Draw();

    // print
    c1->Print(filename);

    // free memory
    delete c1;
}

void BCMTFChannel::PrintHistUncertaintyBandExpectation ( const char *  filename  ) 

Print histogram for uncertainty band calculation.

Parameters:
filename The name of the file.

Definition at line 187 of file BCMTFChannel.cxx.

{
   // create new canvas
   TCanvas * c1 = new TCanvas();
   c1->cd();
    
    // draw histogram
    fHistUncertaintyBandExpectation->Draw("COLZ");
    c1->Draw();

    // print
    c1->Print(filename);

    // free memory
    delete c1;
}

void BCMTFChannel::PrintHistUncertaintyBandPoisson ( const char *  filename  ) 

Print histogram for uncertainty band calculation.

Parameters:
filename The name of the file.

Definition at line 309 of file BCMTFChannel.cxx.

{
   // create new canvas
   TCanvas * c1 = new TCanvas();
   c1->cd();

    // calculate error band
    this->CalculateHistUncertaintyBandPoisson();

    // draw histogram
    fHistUncertaintyBandPoisson->Draw("COLZ");
    c1->Draw();

    // print
    c1->Print(filename);

    // free memory
    delete c1;
}

void BCMTFChannel::PrintTemplate ( int  index,
const char *  filename 
)

Print a particular template with systematics.

Parameters:
index The template index.
filename The name of the file.

Definition at line 119 of file BCMTFChannel.cxx.

{
   // create new canvas
   TCanvas * c1 = new TCanvas();
   c1->cd();

   // get number of systematics
   unsigned int nsystematics = fSystematicVariationContainer.size();

   // draw template
   GetTemplate(index)->GetHistogram()->Draw();

   // print to file
   if (nsystematics == 0)
      c1->Print(filename);
   else
      c1->Print( (std::string(filename)+std::string("(")).c_str() );

   // loop over systematics
   for (unsigned int isystematic = 0; isystematic < nsystematics; ++isystematic) {
      c1->cd();

      // check that histogram exists
      if (!GetSystematicVariation(isystematic)->GetHistogramUp(index) ||
            !GetSystematicVariation(isystematic)->GetHistogramDown(index))
         continue;

      // get histogram
      TH1D hist = TH1D(*GetTemplate(index)->GetHistogram());
      TH1D hist_up(hist);
      TH1D hist_down(hist);

      // set style
      hist.SetFillStyle(0);
      hist_up.SetFillStyle(0);
      hist_up.SetLineStyle(2);
      hist_down.SetFillStyle(0);
      hist_down.SetLineStyle(3);

      // get efficiency
      double efficiency = GetTemplate(index)->GetEfficiency();

      // scale histogram
      hist.Scale(efficiency/ hist.Integral());

      // loop over all bins
      for (int i = 1; i <= hist.GetNbinsX(); ++i) {
         hist.SetBinContent(i, GetTemplate(index)->GetHistogram()->GetBinContent(i));
         hist_up.SetBinContent(i, hist.GetBinContent(i) * (1.0 + GetSystematicVariation(isystematic)->GetHistogramUp(index)->GetBinContent(i)));
         hist_down.SetBinContent(i, hist.GetBinContent(i) * (1.0 - GetSystematicVariation(isystematic)->GetHistogramDown(index)->GetBinContent(i)));
      }

      // draw histogram
      hist_up.Draw("HIST");
      hist.Draw("HISTSAME");
      hist_down.Draw("HISTSAME");

      if (isystematic < nsystematics-1)
         c1->Print(filename);
      else
         c1->Print( (std::string(filename)+std::string(")")).c_str() );
   }

   // free memory
   delete c1;
}

void BCMTFChannel::PrintTemplates ( const char *  filename  ) 

Print the templates in this channel.

Parameters:
filename The name of the file.

Definition at line 54 of file BCMTFChannel.cxx.

{
   // create new canvas
   TCanvas * c1 = new TCanvas();
   c1->Divide(2, 2);

   std::string f(filename);

   // get number of templates
   unsigned int ntemplates = fTemplateContainer.size();

   // calculate number of pages
   unsigned int npages =  ntemplates / 4;
   if (ntemplates % 4 > 0)
      npages++;

   // loop over pages
   for (unsigned int i = 0; i < npages; ++i) {
      // loop over pads
      for (unsigned int j = 0; j < 4; ++j) {
         // calculate template index
         unsigned int templateindex = 4 * i + j;

         if (templateindex < ntemplates && GetTemplate(templateindex)->GetHistogram()) {
            // cd into pad
            c1->cd(j+1);

            // get histogram
            TH1D * hist = new TH1D( *( (TH1D *) GetTemplate(templateindex)->GetHistogram()->Clone() ) );

            // get efficiency
            double efficiency = GetTemplate(templateindex)->GetEfficiency();

            // scale histogram
            hist->Scale(efficiency/hist->Integral());

            // draw histogram
            hist->Draw("HIST");
         }
         else {
            // clear pad
            c1->cd(j+1)->Clear();
         }
      }

      if (npages == 1)
         c1->Print(f.c_str());
      else if (i == 0) {
         c1->Print( (f+std::string("[")).c_str() );
         c1->Print(f.c_str());
      }
      else if (i < npages-1) {
         c1->Print(f.c_str());
      }
      else {
         c1->Print(f.c_str());
         c1->Print( (f+std::string("]")).c_str() );
      }
   }

   // free memory
   delete c1;
}

void BCMTFChannel::SetData ( BCMTFTemplate bctemplate  )  [inline]

Set the data set.

Parameters:
bctemplate The data set.

Definition at line 118 of file BCMTFChannel.h.

         { fData = bctemplate; };

void BCMTFChannel::SetFlagChannelActive ( bool  flag  )  [inline]

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

Parameters:
flag The flag.

Definition at line 137 of file BCMTFChannel.h.

         { fFlagChannelActive = flag; };

void BCMTFChannel::SetHistUncertaintyBandExpectation ( TH2D *  hist  )  [inline]

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

Parameters:
hist The histogram.

Definition at line 125 of file BCMTFChannel.h.

void BCMTFChannel::SetHistUncertaintyBandPoisson ( TH2D *  hist  )  [inline]

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

Parameters:
The histogram.

Definition at line 131 of file BCMTFChannel.h.

void BCMTFChannel::SetName ( const char *  name  )  [inline]

Set the name of the channel.

Parameters:
name The name of the channel.

Definition at line 112 of file BCMTFChannel.h.

         { fName = name; };

void BCMTFChannel::SetRangeY ( double  min,
double  max 
) [inline]

Set the y-ranges for printing.

Parameters:
min The minimum range.
max The maximum range.

Definition at line 144 of file BCMTFChannel.h.

                                                {
            fRangeYMin = min; fRangeYMax = max; };


Member Data Documentation

The data set.

Definition at line 218 of file BCMTFChannel.h.

Flag defining if the channel is active or not.

Definition at line 238 of file BCMTFChannel.h.

A histogram for the calculation of uncertainty bands.

Definition at line 242 of file BCMTFChannel.h.

A histogram for the calculation of uncertainty bands.

Definition at line 246 of file BCMTFChannel.h.

std::string BCMTFChannel::fName [private]

The name of the channel.

Definition at line 214 of file BCMTFChannel.h.

double BCMTFChannel::fRangeYMax [private]

The maximal y-range for printing.

Definition at line 226 of file BCMTFChannel.h.

double BCMTFChannel::fRangeYMin [private]

The minimal y-range for printing.

Definition at line 222 of file BCMTFChannel.h.

A container of systematics.

Definition at line 234 of file BCMTFChannel.h.

A container of templates.

Definition at line 230 of file BCMTFChannel.h.


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