Plot::Hist Class Reference

#include <Plot.h>

List of all members.

Public Member Functions

 Hist (const std::string fpath, const std::string block="block")
virtual ~Hist ()
bool Set (const std::string fpath, const std::string block="block")
TH1 * Get (const std::string hpath)
void SetProtons (double protons)
TGraphAsymmErrors * SetLH (const std::string lpath, const std::string hpath)
TH1 * operator-> () const
TH1 * GetHist (std::string option="") const
double GetEntries (std::string option="") const
double GetProtons () const
const DataBlockGetBlock () const
const std::map< int, std::pair
< Plot::Band, Plot::Band > > & 
GetErrorBand () const
void Rebin (int rebin, std::string option="")
void Rebin (TH1 *h, std::string option="")
void NormalizeOnWidth (std::string option="")
TH1 * Scale (const Hist &other, std::string option)
TCanvas * Draw (std::string option, std::string cname="")
void SetErrorStyle (int color=-1, int style=1001)
TPaveStats * MoveStat (float x, float y, float w, float h, std::string option="")
TH1 * GetRatio (const Hist &other, std::string option="", double min_=1.0, double max_=0.0, double factor=0.05) const

Private Member Functions

TGraphAsymmErrors * ComputeError ()
std::pair< TH1 *, DataBlockRead (const std::string &hpath)
TH1 * CreateRatio (TH1 *hC, TH1 *hO, const std::string &option, double nmin) const
double * Create (int size)
void ClearError ()

Private Attributes

std::string fBlokPath
std::string fFilePath
std::string fHistPath
std::string fHistPathL
std::string fHistPathH
TH1 * fHist
TH1 * fHistL
TH1 * fHistH
DataBlock fBlock
int fErrorColor
int fErrorStyle
TGraphAsymmErrors * fAGraph
std::map< int, std::pair< Band,
Band > > 
fError
std::map< int, TBox * > fBox
std::vector< double * > fArray

Detailed Description

Definition at line 85 of file Plot.h.


Constructor & Destructor Documentation

Plot::Hist::Hist ( const std::string  fpath,
const std::string  block = "block" 
) [explicit]
Plot::Hist::~Hist (  )  [virtual]

Definition at line 373 of file Plot.cxx.

References ClearError(), fHist, fHistH, and fHistL.

00374 {
00375    if(fHist)  delete fHist;
00376    if(fHistL) delete fHistL;
00377    if(fHistH) delete fHistH;   
00378 
00379    ClearError();
00380 }


Member Function Documentation

void Plot::Hist::ClearError (  )  [private]

Definition at line 1312 of file Plot.cxx.

References MuELoss::a, fAGraph, fArray, fBox, fError, it, and Munits::second.

Referenced by ComputeError(), and ~Hist().

01313 {
01314    if(fAGraph)
01315    {
01316       delete fAGraph;
01317       fAGraph = 0;
01318    }
01319 
01320    for(vector<double *>::iterator it = fArray.begin(); it != fArray.end(); ++it)
01321    {
01322       double *a = *it;
01323       if(a)
01324       {
01325          delete [] a;
01326       }
01327    }  
01328 
01329    for(map<int, TBox *>::iterator it = fBox.begin(); it != fBox.end(); ++it)
01330    {
01331       TBox *box = it -> second;
01332       if(box) delete box;
01333    }
01334 
01335    fArray.clear();
01336    fError.clear();
01337    fBox.clear();
01338 }

TGraphAsymmErrors * Plot::Hist::ComputeError (  )  [private]

Definition at line 450 of file Plot.cxx.

References ClearError(), Create(), fAGraph, fBox, fError, fHist, fHistH, fHistL, Plot::Band::High(), and Plot::Band::Low().

00451 {   
00452    TH1 *hC = fHist;
00453    TH1 *hL = fHistL;
00454    TH1 *hH = fHistH;
00455 
00456    if(!hC || !hL || !hH)
00457    {
00458       return 0;
00459    }
00460 
00461    ClearError();
00462 
00463    const int nbin = hC -> GetNbinsX();
00464 
00465    if(hL -> GetNbinsX() != nbin || hH -> GetNbinsX() != nbin)
00466    {
00467       cerr << "Error::Compute - mismatched number of bins" << endl;
00468       return 0;
00469    }
00470 
00471    int npoint = 0;
00472    for(int ibin = 1; ibin <= nbin; ++ibin)
00473    {
00474       if(hC -> GetBinContent(ibin) > 0)
00475       {
00476          ++npoint;
00477       }
00478    }
00479 
00480    double* x   = Create(npoint);
00481    double* y   = Create(npoint);
00482    double* exl = Create(npoint);
00483    double* exh = Create(npoint);
00484    double* eyl = Create(npoint); 
00485    double* eyh = Create(npoint);
00486 
00487    npoint = 0;
00488    for(int ibin = 1; ibin <= nbin; ++ibin)
00489    {      
00490       if(!(hC -> GetBinContent(ibin) > 0))
00491       {
00492          continue;
00493       }
00494 
00495       const double xc = hC -> GetXaxis() -> GetBinCenter(ibin);
00496       const double xl = hC -> GetXaxis() -> GetBinLowEdge(ibin);
00497       const double xh = hC -> GetXaxis() -> GetBinUpEdge(ibin);
00498 
00499       const double yc = hC -> GetBinContent(ibin);
00500       const double yl = hL -> GetBinContent(ibin);
00501       const double yh = hH -> GetBinContent(ibin);
00502 
00503       if(yl > yh)
00504       {
00505          cerr << "Error::Compute -  low value " << yl << " larger than high value " << yh<< endl;
00506          continue;
00507       }
00508 
00509       if(yc < yl || yh < yc)
00510       {
00511          cerr << "Error::Compute -  low and/or high error have wrong limit" << yh << endl;
00512          continue;
00513       }
00514 
00515       const double error_stat = std::sqrt(yc);
00516       const double error_low  = error_stat + yc - yl;
00517       const double error_high = error_stat + yh - yc;
00518 
00519       //cout << "yc - yl = " << yc << " - " << yl << " = " << yc - yl << endl;
00520       //cout << "yh - yc = " << yh << " - " << yc << " = " << yh - yc << endl;
00521 
00522       x[npoint] = xc;
00523       y[npoint] = yc;
00524 
00525       exl[npoint] = xc - xl;
00526       exh[npoint] = xh - xc;
00527 
00528       eyl[npoint] = error_low;
00529       eyh[npoint] = error_high;
00530 
00531       ++npoint;
00532 
00533       const Band xb(ibin, xc, xl, xh);
00534       const Band yb(ibin, yc, yl - error_stat, yh + error_stat);
00535       
00536       const pair<Band, Band> np(xb, yb);
00537 
00538       if(!fError.insert(map<int, pair<Band, Band> >::value_type(ibin, np)).second)
00539       {
00540          cerr << "Error::Compute - bin " << ibin << " already exists" << endl;
00541       }
00542 
00543       TBox *box = new TBox(xb.Low(), yb.Low(), xb.High(), yb.High());
00544 
00545       if(!fBox.insert(map<int, TBox *>::value_type(ibin, box)).second)
00546       {
00547          cerr << "Error::Compute - bin " << ibin << " already exists" << endl;
00548       }
00549       
00550       
00551       if(error_low > error_high)
00552       {
00553          hC -> SetBinError(ibin, error_low);
00554       }
00555       else
00556       {
00557          hC -> SetBinError(ibin, error_high);
00558       }
00559    }
00560 
00561    fAGraph = new TGraphAsymmErrors(npoint, x, y, exl, exh, eyl, eyh);
00562 
00563    return fAGraph;
00564 }

double * Plot::Hist::Create ( int  size  )  [private]

Definition at line 1291 of file Plot.cxx.

References MuELoss::a, and fArray.

Referenced by ComputeError().

01292 {
01293    if(size < 1)
01294    {
01295       cerr << "Error::Create - can not create zero size array" << endl;
01296       return 0;
01297    }
01298 
01299    double *a = new double[size];
01300 
01301    for(int i = 0; i < size; ++i)
01302    {
01303       a[i] = 0.0;
01304    }
01305 
01306    fArray.push_back(a);
01307    
01308    return a;
01309 }

TH1* Plot::Hist::CreateRatio ( TH1 *  hC,
TH1 *  hO,
const std::string &  option,
double  nmin 
) const [private]
TCanvas* Plot::Hist::Draw ( std::string  option,
std::string  cname = "" 
)
TH1* Plot::Hist::Get ( const std::string  hpath  ) 
const DataBlock & Plot::Hist::GetBlock (  )  const

Definition at line 624 of file Plot.cxx.

References fBlock.

00625 {
00626    return fBlock;
00627 }

double Plot::Hist::GetEntries ( std::string  option = ""  )  const
const map< int, pair< Plot::Band, Plot::Band > > & Plot::Hist::GetErrorBand (  )  const

Definition at line 630 of file Plot.cxx.

References fError.

00631 {
00632    return fError;
00633 }

TH1* Plot::Hist::GetHist ( std::string  option = ""  )  const
double Plot::Hist::GetProtons (  )  const

Definition at line 618 of file Plot.cxx.

References fBlock, and DataBlock::GetProtonsOut().

00619 {
00620    return fBlock.GetProtonsOut();
00621 }

TH1* Plot::Hist::GetRatio ( const Hist other,
std::string  option = "",
double  min_ = 1.0,
double  max_ = 0.0,
double  factor = 0.05 
) const
TPaveStats* Plot::Hist::MoveStat ( float  x,
float  y,
float  w,
float  h,
std::string  option = "" 
)
void Plot::Hist::NormalizeOnWidth ( std::string  option = ""  ) 

Definition at line 777 of file Plot.cxx.

References fHistH, and fHistL.

00778 {
00779    if(!fHist)
00780    {
00781       return;
00782    }
00783 
00784    bool do_error = true;
00785    if(option.find("no_error") != string::npos)
00786    {
00787       do_error = false;
00788    }
00789 
00790    for(int ibin = 1; ibin <= fHist -> GetNbinsX(); ++ibin)
00791    {
00792       const double value = fHist -> GetBinContent(ibin);
00793       const double error = fHist -> GetBinError(ibin);
00794       const double width = fHist -> GetBinWidth(ibin);
00795       
00796       if(!(width > 0.0)) continue;
00797 
00798       fHist -> SetBinContent(ibin, value/width);
00799       if(do_error) fHist -> SetBinError(ibin, error/width);
00800       
00801       if(fHistL)
00802       {
00803          const double valueL = fHistL -> GetBinContent(ibin);
00804          const double errorL = fHistL -> GetBinError(ibin);
00805 
00806          fHistL -> SetBinContent(ibin, valueL/width);
00807          if(do_error) fHistL -> SetBinError(ibin, errorL/width);
00808       }
00809 
00810       if(fHistH)
00811       {
00812          const double valueH = fHistH -> GetBinContent(ibin);
00813          const double errorH = fHistH -> GetBinError(ibin);
00814 
00815          fHistH -> SetBinContent(ibin, valueH/width);
00816          if(do_error) fHistH -> SetBinError(ibin, errorH/width);
00817       }
00818    }
00819 }

TH1 * Plot::Hist::operator-> (  )  const

Definition at line 567 of file Plot.cxx.

References fHist.

00568 {
00569    return fHist;
00570 }

std::pair<TH1 *, DataBlock> Plot::Hist::Read ( const std::string &  hpath  )  [private]
void Plot::Hist::Rebin ( TH1 *  h,
std::string  option = "" 
)
void Plot::Hist::Rebin ( int  rebin,
std::string  option = "" 
)
TH1* Plot::Hist::Scale ( const Hist other,
std::string  option 
)
bool Plot::Hist::Set ( const std::string  fpath,
const std::string  block = "block" 
)
void Plot::Hist::SetErrorStyle ( int  color = -1,
int  style = 1001 
)

Definition at line 941 of file Plot.cxx.

References fErrorColor, and fErrorStyle.

00942 {
00943    fErrorColor = color;
00944    fErrorStyle = style;
00945 }

TGraphAsymmErrors* Plot::Hist::SetLH ( const std::string  lpath,
const std::string  hpath 
)
void Plot::Hist::SetProtons ( double  protons  ) 

Definition at line 404 of file Plot.cxx.

References fBlock, and DataBlock::SetProtons().

00405 {
00406    if(protons > 0.0)
00407    {
00408       fBlock.SetProtons(protons);
00409    }
00410 }


Member Data Documentation

TGraphAsymmErrors* Plot::Hist::fAGraph [private]

Definition at line 156 of file Plot.h.

Referenced by ClearError(), and ComputeError().

std::vector<double *> Plot::Hist::fArray [private]

Definition at line 160 of file Plot.h.

Referenced by ClearError(), and Create().

Definition at line 151 of file Plot.h.

Referenced by GetBlock(), GetProtons(), and SetProtons().

std::string Plot::Hist::fBlokPath [private]

Definition at line 141 of file Plot.h.

std::map<int, TBox *> Plot::Hist::fBox [private]

Definition at line 159 of file Plot.h.

Referenced by ClearError(), and ComputeError().

std::map<int, std::pair<Band, Band> > Plot::Hist::fError [private]

Definition at line 158 of file Plot.h.

Referenced by ClearError(), ComputeError(), and GetErrorBand().

int Plot::Hist::fErrorColor [private]

Definition at line 153 of file Plot.h.

Referenced by SetErrorStyle().

int Plot::Hist::fErrorStyle [private]

Definition at line 154 of file Plot.h.

Referenced by SetErrorStyle().

std::string Plot::Hist::fFilePath [private]

Definition at line 142 of file Plot.h.

TH1* Plot::Hist::fHist [private]

Definition at line 147 of file Plot.h.

Referenced by ComputeError(), operator->(), and ~Hist().

TH1* Plot::Hist::fHistH [private]

Definition at line 149 of file Plot.h.

Referenced by ComputeError(), NormalizeOnWidth(), and ~Hist().

TH1* Plot::Hist::fHistL [private]

Definition at line 148 of file Plot.h.

Referenced by ComputeError(), NormalizeOnWidth(), and ~Hist().

std::string Plot::Hist::fHistPath [private]

Definition at line 143 of file Plot.h.

std::string Plot::Hist::fHistPathH [private]

Definition at line 145 of file Plot.h.

std::string Plot::Hist::fHistPathL [private]

Definition at line 144 of file Plot.h.


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

Generated on 24 Apr 2018 for loon by  doxygen 1.6.1