OscFit::Histogram Class Reference

#include <Histogram.h>

List of all members.

Public Member Functions

 Histogram (Binning *theBinning)
virtual ~Histogram ()
void Fill (Double_t a, Double_t b=1.0, Double_t c=1.0)
void Fill2D (Double_t x, Double_t y, Double_t w=1.0)
void Add (Histogram *hist, Double_t w=1.0)
Int_t GetNbins ()
Double_t GetBinContent (Int_t ibin)
void SetBinContent (Int_t ibin, Double_t x)
Double_t GetBinCenter (Int_t i)
Double_t SumBinContents ()
Double_t GetTotalContent ()
void PrintContents ()
void Scale (Double_t scale)
void Reset ()
TH1D * MakeTH1D (const char *histName)
TH2D * MakeTH2D (const char *histName)
 Histogram (TH1D *hist, Bin_t bin)
 Histogram (Bin_t bin)
 Histogram (Int_t numBins, Double_t *binEdges)
virtual ~Histogram ()
TH1D * MakeTH1D (const char *histname)
void Fill (Double_t x, Double_t w=1.0)
void SetBinType (Bin_t binType)
Bin_t GetBinType ()
Double_t GetOverflow ()
Double_t GetTotalContent ()
Int_t GetNumBins ()
Double_t GetBinContent (Int_t ibin)
void SetBinContent (Int_t ibin, Double_t obs)
void PrintContents ()
void Reset ()
void Add (Histogram *hist, Double_t w=1.0)

Private Member Functions

void BuildBinningScheme (Bin_t bin)
void BuildBinningScheme0 ()
void BuildBinningScheme1 ()
void BuildBinningScheme2 ()
void BuildBinningScheme3 ()
void DeleteBinningScheme ()

Private Attributes

Double_t * fX
BinningfBinning
Double_t fTotalContent
Int_t fNumBins
Double_t * fBinContents
Double_t * fBinEdges
Bin_t fBinType
Double_t fOverflow

Detailed Description

Definition at line 10 of file Histogram.h.


Constructor & Destructor Documentation

Histogram::Histogram ( Binning theBinning  ) 

Definition at line 10 of file Histogram.cxx.

00011 {
00012   assert(theBinning);
00013 
00014   fBinning = theBinning;
00015  
00016   fX = new Double_t[fBinning->GetNbins()];
00017 
00018   Reset();
00019 }

Histogram::~Histogram (  )  [virtual]

Definition at line 21 of file Histogram.cxx.

References fX.

00022 {
00023   delete [] fX;
00024 } 

Histogram::Histogram ( TH1D *  hist,
Bin_t  bin 
)

Definition at line 10 of file twoflavours/Histogram.cxx.

00011 {
00012   fBinType = bin;
00013 
00014   fNumBins = hist->GetXaxis()->GetNbins();
00015   fBinEdges = new Double_t[fNumBins+1];
00016   fBinContents = new Double_t[fNumBins];
00017 
00018   fTotalContent = 0.0;  
00019 
00020   for( Int_t ibin=0; ibin<fNumBins+1; ibin++ ){
00021     fBinEdges[ibin] = hist->GetXaxis()->GetBinLowEdge(ibin+1);
00022   }
00023 
00024   for( Int_t ibin=0; ibin<fNumBins; ibin++ ){
00025     fBinContents[ibin] = hist->GetBinContent(ibin+1);
00026     fTotalContent += fBinContents[ibin];
00027   }
00028 
00029   fOverflow = hist->GetBinContent(fNumBins+1);
00030   fTotalContent += fOverflow;
00031 }

Histogram::Histogram ( Bin_t  bin  ) 

Definition at line 33 of file twoflavours/Histogram.cxx.

References BuildBinningScheme(), fBinContents, fBinEdges, fBinType, fNumBins, fOverflow, and fTotalContent.

00034 {
00035   fBinType = bin;
00036 
00037   fNumBins = 0;
00038   fBinEdges = 0;
00039   fBinContents = 0;
00040   
00041   fTotalContent = 0.0;
00042   fOverflow = 0.0;
00043 
00044   BuildBinningScheme(fBinType);
00045 }

Histogram::Histogram ( Int_t  numBins,
Double_t *  binEdges 
)

Definition at line 47 of file twoflavours/Histogram.cxx.

References fBinContents, fBinEdges, fBinType, fNumBins, fOverflow, fTotalContent, and OscFit::kNoBin.

00048 {
00049   fBinType = OscFit::kNoBin;
00050 
00051   fNumBins  = numBins;
00052   fBinEdges = new Double_t[fNumBins+1];
00053   fBinContents = new Double_t[fNumBins];
00054 
00055   fTotalContent = 0.0;
00056   fOverflow = 0.0;
00057 
00058   for( Int_t ibin=0; ibin<fNumBins+1; ibin++ ){
00059     fBinEdges[ibin] = binEdges[ibin];
00060   }
00061 
00062   for( Int_t ibin=0; ibin<fNumBins; ibin++ ){
00063     fBinContents[ibin] = 0.0;
00064   }
00065 }

virtual OscFit::Histogram::~Histogram (  )  [virtual]

Member Function Documentation

void OscFit::Histogram::Add ( Histogram hist,
Double_t  w = 1.0 
)
void Histogram::Add ( Histogram hist,
Double_t  w = 1.0 
)

Definition at line 45 of file Histogram.cxx.

References fTotalContent, fX, GetBinContent(), GetNbins(), and GetTotalContent().

Referenced by OscFit::Template::Add(), OscFit::TemplateCalculator::CombineResBins(), OscFit::Template::ConditionalAdd(), OscFit::Template::Fill(), and OscFit::Template::SpecialAdd().

00046 {
00047   if( hist==0 ) return;
00048 
00049   assert( hist->GetNbins()==GetNbins() );
00050 
00051   for( Int_t ibin=0; ibin<hist->GetNbins(); ibin++ ){
00052 
00053     fX[ibin] += w*hist->GetBinContent(ibin);  
00054   }
00055 
00056   fTotalContent += w*hist->GetTotalContent();
00057 
00058   return;
00059 }

void Histogram::BuildBinningScheme ( Bin_t  bin  )  [private]

Definition at line 73 of file twoflavours/Histogram.cxx.

References BuildBinningScheme0(), BuildBinningScheme2(), BuildBinningScheme3(), OscFit::kNoBin, OscFit::kOppositeSign, OscFit::kRAF, OscFit::kResBin0, OscFit::kResBin1, OscFit::kResBin2, OscFit::kResBin3, and OscFit::kResBin4.

Referenced by Histogram().

00074 {
00075   switch( bin ){ 
00076     case kNoBin:         return BuildBinningScheme0();
00077     case kResBin0:       return BuildBinningScheme2();
00078     case kResBin1:       return BuildBinningScheme2();
00079     case kResBin2:       return BuildBinningScheme2();
00080     case kResBin3:       return BuildBinningScheme2();
00081     case kResBin4:       return BuildBinningScheme2();
00082     case kOppositeSign:  return BuildBinningScheme2();
00083     case kRAF:           return BuildBinningScheme3();
00084     default:             return BuildBinningScheme0();
00085   }
00086 }

void Histogram::BuildBinningScheme0 (  )  [private]

Definition at line 95 of file twoflavours/Histogram.cxx.

References DeleteBinningScheme(), fBinContents, fBinEdges, fNumBins, fOverflow, and fTotalContent.

Referenced by BuildBinningScheme().

00096 {
00097   DeleteBinningScheme();
00098 
00099   fNumBins = 1;
00100   fBinEdges = new Double_t[2];
00101   fBinContents = new Double_t[1];
00102 
00103   fBinEdges[0] = 0.0;
00104   fBinEdges[1] = 1.0e6;
00105 
00106   fBinContents[0] = 0.0;
00107 
00108   fTotalContent = 0.0;
00109   fOverflow = 0.0;
00110 }

void Histogram::BuildBinningScheme1 (  )  [private]

Definition at line 112 of file twoflavours/Histogram.cxx.

References DeleteBinningScheme(), fBinContents, fBinEdges, fNumBins, fOverflow, and fTotalContent.

00113 {
00114   DeleteBinningScheme();
00115 
00116   fNumBins = 800;
00117   fBinEdges = new Double_t[801];
00118   fBinContents = new Double_t[800];
00119 
00120   for( Int_t ibin=0; ibin<fNumBins+1; ibin++ ){
00121     fBinEdges[ibin] = ((Double_t)ibin)*0.250;
00122   }
00123 
00124   for( Int_t ibin=0; ibin<fNumBins; ibin++ ){
00125     fBinContents[ibin] = 0.0;
00126   }
00127 
00128   fTotalContent = 0.0;
00129   fOverflow = 0.0;
00130 }

void Histogram::BuildBinningScheme2 (  )  [private]

Definition at line 132 of file twoflavours/Histogram.cxx.

References DeleteBinningScheme(), fBinContents, fBinEdges, fNumBins, fOverflow, and fTotalContent.

Referenced by BuildBinningScheme().

00133 {
00134   DeleteBinningScheme();
00135 
00136   fNumBins = 100;
00137   fBinEdges = new Double_t[101];
00138   fBinContents = new Double_t[100];
00139 
00140   // Binning Scheme
00141   // ==============
00142   // 0.5  GeV bins, up to 0.5 GeV
00143   // 0.25 GeV bins, up to 20  GeV
00144   // 1.0  GeV bins, up to 30  GeV
00145   // 2.0  GeV bins, up to 50  GeV
00146   // 150  GeV bin,  up to 200 GeV
00147 
00148   fBinEdges[0]  =  0.0;
00149   fBinEdges[1]  =  0.5;
00150 
00151   fBinEdges[2]  =  0.75;
00152   fBinEdges[3]  =  1.00;
00153   fBinEdges[4]  =  1.25;
00154   fBinEdges[5]  =  1.50;
00155   fBinEdges[6]  =  1.75;
00156   fBinEdges[7]  =  2.00;
00157   fBinEdges[8]  =  2.25;
00158   fBinEdges[9]  =  2.50;
00159   fBinEdges[10] =  2.75;
00160   fBinEdges[11] =  3.00;
00161   fBinEdges[12] =  3.25;
00162   fBinEdges[13] =  3.50;
00163   fBinEdges[14] =  3.75;
00164   fBinEdges[15] =  4.00;
00165   fBinEdges[16] =  4.25;
00166   fBinEdges[17] =  4.50;
00167   fBinEdges[18] =  4.75;
00168   fBinEdges[19] =  5.00;
00169   fBinEdges[20] =  5.25;
00170   fBinEdges[21] =  5.50;
00171   fBinEdges[22] =  5.75;
00172   fBinEdges[23] =  6.00;
00173   fBinEdges[24] =  6.25;
00174   fBinEdges[25] =  6.50;
00175   fBinEdges[26] =  6.75;
00176   fBinEdges[27] =  7.00;
00177   fBinEdges[28] =  7.25;
00178   fBinEdges[29] =  7.50;
00179   fBinEdges[30] =  7.75;
00180   fBinEdges[31] =  8.00;
00181   fBinEdges[32] =  8.25;
00182   fBinEdges[33] =  8.50;
00183   fBinEdges[34] =  8.75;
00184   fBinEdges[35] =  9.00;
00185   fBinEdges[36] =  9.25;
00186   fBinEdges[37] =  9.50;
00187   fBinEdges[38] =  9.75;
00188   fBinEdges[39] = 10.00;
00189   fBinEdges[40] = 10.25;
00190   fBinEdges[41] = 10.50;
00191   fBinEdges[42] = 10.75;
00192   fBinEdges[43] = 11.00;
00193   fBinEdges[44] = 11.25;
00194   fBinEdges[45] = 11.50;
00195   fBinEdges[46] = 11.75;
00196   fBinEdges[47] = 12.00;
00197   fBinEdges[48] = 12.25;
00198   fBinEdges[49] = 12.50;
00199   fBinEdges[50] = 12.75;
00200   fBinEdges[51] = 13.00;
00201   fBinEdges[52] = 13.25;
00202   fBinEdges[53] = 13.50;
00203   fBinEdges[54] = 13.75;
00204   fBinEdges[55] = 14.00;
00205   fBinEdges[56] = 14.25;
00206   fBinEdges[57] = 14.50;
00207   fBinEdges[58] = 14.75;
00208   fBinEdges[59] = 15.00;
00209   fBinEdges[60] = 15.25;
00210   fBinEdges[61] = 15.50;
00211   fBinEdges[62] = 15.75;
00212   fBinEdges[63] = 16.00;
00213   fBinEdges[64] = 16.25;
00214   fBinEdges[65] = 16.50;
00215   fBinEdges[66] = 16.75;
00216   fBinEdges[67] = 17.00;
00217   fBinEdges[68] = 17.25;
00218   fBinEdges[69] = 17.50;
00219   fBinEdges[70] = 17.75;
00220   fBinEdges[71] = 18.00;
00221   fBinEdges[72] = 18.25;
00222   fBinEdges[73] = 18.50;
00223   fBinEdges[74] = 18.75;
00224   fBinEdges[75] = 19.00;
00225   fBinEdges[76] = 19.25;
00226   fBinEdges[77] = 19.50;
00227   fBinEdges[78] = 19.75;
00228   fBinEdges[79] = 20.00;
00229 
00230   fBinEdges[80] = 21.0;
00231   fBinEdges[81] = 22.0;
00232   fBinEdges[82] = 23.0;
00233   fBinEdges[83] = 24.0;
00234   fBinEdges[84] = 25.0;
00235   fBinEdges[85] = 26.0;
00236   fBinEdges[86] = 27.0;
00237   fBinEdges[87] = 28.0;
00238   fBinEdges[88] = 29.0;
00239   fBinEdges[89] = 30.0;
00240 
00241   fBinEdges[90] = 32.0;
00242   fBinEdges[91] = 34.0;
00243   fBinEdges[92] = 36.0;
00244   fBinEdges[93] = 38.0;
00245   fBinEdges[94] = 40.0;
00246   fBinEdges[95] = 42.0;
00247   fBinEdges[96] = 44.0;
00248   fBinEdges[97] = 46.0;
00249   fBinEdges[98] = 48.0;
00250   fBinEdges[99] = 50.0;
00251 
00252   fBinEdges[100] = 200.0;
00253 
00254   for( Int_t ibin=0; ibin<fNumBins; ibin++ ){
00255     fBinContents[ibin] = 0.0;
00256   }
00257 
00258   fTotalContent = 0.0;
00259   fOverflow = 0.0;
00260 }

void Histogram::BuildBinningScheme3 (  )  [private]

Definition at line 262 of file twoflavours/Histogram.cxx.

References DeleteBinningScheme(), fBinContents, fBinEdges, fNumBins, fOverflow, and fTotalContent.

Referenced by BuildBinningScheme().

00263 {
00264   DeleteBinningScheme();
00265 
00266   fNumBins = 123;
00267   fBinEdges = new Double_t[124];
00268   fBinContents = new Double_t[123];
00269 
00270   for( Int_t ibin=0; ibin<fNumBins+1; ibin++ ){
00271     fBinEdges[ibin] = (Double_t)ibin;
00272   }
00273 
00274   for( Int_t ibin=0; ibin<fNumBins; ibin++ ){
00275     fBinContents[ibin] = 0.0;
00276   }
00277 
00278   fTotalContent = 0.0;
00279   fOverflow = 0.0;
00280 }

void Histogram::DeleteBinningScheme (  )  [private]

Definition at line 88 of file twoflavours/Histogram.cxx.

References fBinContents, fBinEdges, and fNumBins.

Referenced by BuildBinningScheme0(), BuildBinningScheme1(), BuildBinningScheme2(), and BuildBinningScheme3().

00089 {
00090   fNumBins = 0;
00091   if( fBinEdges ) delete [] fBinEdges;
00092   if( fBinContents ) delete [] fBinContents;
00093 }

void Histogram::Fill ( Double_t  x,
Double_t  w = 1.0 
)

Definition at line 328 of file twoflavours/Histogram.cxx.

References fBinContents, fBinEdges, fOverflow, and fTotalContent.

00329 {
00330   for( Int_t ibin=0; ibin<fNumBins; ibin++ ){
00331     if( x>=fBinEdges[ibin] && x<fBinEdges[ibin+1] ){
00332       fBinContents[ibin] += w; 
00333       fTotalContent      += w;
00334       return;
00335     }
00336   }
00337 
00338   if( x>fBinEdges[fNumBins] ){
00339     fOverflow     += w; 
00340     fTotalContent += w;
00341     return;
00342   }
00343 
00344   return;
00345 }

void Histogram::Fill ( Double_t  a,
Double_t  b = 1.0,
Double_t  c = 1.0 
)

Definition at line 26 of file Histogram.cxx.

References fBinning, Fill2D(), and OscFit::Binning::GetNbinsY().

Referenced by OscFit::Template::Fill(), and OscFit::Template::LoopFill().

00027 {
00028   if( fBinning->GetNbinsY()<=1 ) Fill2D( a, 0, b );
00029   else                           Fill2D( a, b, c );
00030 }

void Histogram::Fill2D ( Double_t  x,
Double_t  y,
Double_t  w = 1.0 
)

Definition at line 32 of file Histogram.cxx.

References fBinning, OscFit::Binning::FindBin(), fTotalContent, fX, and GetNbins().

Referenced by Fill().

00033 {
00034   Int_t ibin = fBinning->FindBin(x,y);
00035 
00036   if( ibin>=0 
00037    && ibin<GetNbins() ){
00038     fX[ibin]      += w;  
00039     fTotalContent += w;
00040   }
00041 
00042   return;
00043 }

Double_t OscFit::Histogram::GetBinCenter ( Int_t  i  )  [inline]

Definition at line 26 of file Histogram.h.

References fBinning, and OscFit::Binning::fXedges.

Referenced by OscFit::Template::LoopFill().

00026                                    {
00027       return 0.5*(fBinning->fXedges[i]+fBinning->fXedges[i+1]);
00028     }

Double_t OscFit::Histogram::GetBinContent ( Int_t  ibin  ) 
Double_t Histogram::GetBinContent ( Int_t  ibin  ) 

Definition at line 77 of file Histogram.cxx.

References fX, and GetNbins().

Referenced by Add(), OscFit::TemplateCalculator::BuildExpt(), OscFit::Fitter::GetLnL(), OscFit::Fitter::GetLnLNoRes(), OscFit::Template::LoopFill(), and SumBinContents().

00078 {
00079   if( ibin>=0 && ibin<GetNbins() ) return fX[ibin];
00080   else                             return 0.0;
00081 }

Bin_t OscFit::Histogram::GetBinType (  )  [inline]

Definition at line 23 of file twoflavours/Histogram.h.

References fBinType.

00023 { return fBinType; }

Int_t Histogram::GetNbins (  ) 
Int_t OscFit::Histogram::GetNumBins (  )  [inline]

Definition at line 26 of file twoflavours/Histogram.h.

References fNumBins.

Referenced by OscFit::Fitter::GetLnL(), and OscFit::Fitter::GetLnLNoRes().

00026 { return fNumBins; } 

Double_t OscFit::Histogram::GetOverflow (  )  [inline]

Definition at line 24 of file twoflavours/Histogram.h.

References fOverflow.

00024 { return fOverflow; }

Double_t OscFit::Histogram::GetTotalContent (  )  [inline]

Definition at line 25 of file twoflavours/Histogram.h.

References fTotalContent.

00025 { return fTotalContent; }

Double_t OscFit::Histogram::GetTotalContent (  )  [inline]
TH1D* OscFit::Histogram::MakeTH1D ( const char *  histname  ) 
TH1D * Histogram::MakeTH1D ( const char *  histName  ) 

Definition at line 107 of file Histogram.cxx.

References fBinning, fX, OscFit::Binning::GetBinNumber(), GetNbins(), OscFit::Binning::GetNbinsX(), and OscFit::Binning::MakeTH1D().

Referenced by OscFit::TemplateWriter::AddToFile(), OscFit::Template::MakeTH1D(), OscFit::Template::WriteHistograms(), and OscFit::TemplateIO::WriteToFile().

00108 {
00109   TH1D* hNew = fBinning->MakeTH1D(histName);
00110 
00111   if( hNew ){
00112     for( Int_t nx=0; nx<fBinning->GetNbinsX(); nx++ ){
00113       Int_t ibin = fBinning->GetBinNumber(nx);
00114 
00115       assert( ibin>=0 && ibin<GetNbins() ); // check for overflows
00116 
00117       hNew->SetBinContent(nx+1,fX[ibin]);
00118     }
00119   }
00120 
00121   return hNew;
00122 }

TH2D * Histogram::MakeTH2D ( const char *  histName  ) 

Definition at line 124 of file Histogram.cxx.

References fBinning, fX, OscFit::Binning::GetBinNumber(), GetNbins(), OscFit::Binning::GetNbinsX(), OscFit::Binning::GetNbinsY(), and OscFit::Binning::MakeTH2D().

Referenced by OscFit::TemplateIO::WriteToFile().

00125 {
00126   TH2D* hNew = fBinning->MakeTH2D(histName);
00127 
00128   if( hNew ){
00129     for( Int_t nx=0; nx<fBinning->GetNbinsX(); nx++ ){
00130       for( Int_t ny=0; ny<fBinning->GetNbinsY(); ny++ ){
00131         Int_t ibin = fBinning->GetBinNumber(nx,ny);
00132 
00133         assert( ibin>=0 && ibin<GetNbins() ); // check for overflows
00134 
00135         hNew->SetBinContent(nx+1,ny+1,fX[ibin]);
00136       }
00137     }
00138   }
00139 
00140   return hNew;
00141 }

void OscFit::Histogram::PrintContents (  ) 
void Histogram::PrintContents (  ) 

Definition at line 143 of file Histogram.cxx.

References fX, GetNbins(), GetTotalContent(), and SumBinContents().

00144 {
00145   std::cout << " *** Histogram::PrintContents() *** " << std::endl;
00146 
00147   for( Int_t ibin=0; ibin<GetNbins(); ibin++ ){
00148     std::cout << " [" << ibin << "]\t" << fX[ibin] << std::endl;
00149   }
00150 
00151   std::cout << "  Total: " << GetTotalContent() << " (Check: " << SumBinContents() << ")" << std::endl;
00152 
00153   return;
00154 }

void OscFit::Histogram::Reset (  ) 
void Histogram::Reset (  ) 

Definition at line 98 of file Histogram.cxx.

References fTotalContent, fX, and GetNbins().

Referenced by OscFit::Template::Reset().

00099 {
00100   for( Int_t ibin=0; ibin<GetNbins(); ibin++ ){
00101     fX[ibin] = 0.0;
00102   } 
00103 
00104   fTotalContent = 0.0;
00105 }

void Histogram::Scale ( Double_t  scale  ) 

Definition at line 89 of file Histogram.cxx.

References fTotalContent, fX, and GetNbins().

Referenced by OscFit::Template::Scale().

00090 {
00091   for( Int_t ibin=0; ibin<GetNbins(); ibin++ ){
00092     fX[ibin] *= scale;
00093   } 
00094 
00095   fTotalContent *= scale;
00096 }

void OscFit::Histogram::SetBinContent ( Int_t  ibin,
Double_t  obs 
)
void Histogram::SetBinContent ( Int_t  ibin,
Double_t  x 
)

Definition at line 83 of file Histogram.cxx.

References fTotalContent, fX, and GetNbins().

Referenced by OscFit::TemplateCalculator::BuildExpt().

00084 {
00085   if( ibin>=0 && ibin<GetNbins() ) { fTotalContent += x-fX[ibin];  fX[ibin] = x;  }
00086   return;
00087 }

void Histogram::SetBinType ( Bin_t  binType  ) 

Definition at line 367 of file twoflavours/Histogram.cxx.

References fBinType.

Referenced by OscFit::Template::BuildHistograms().

00368 {
00369   fBinType = binType;
00370 }

Double_t Histogram::SumBinContents (  ) 

Definition at line 66 of file Histogram.cxx.

References GetBinContent(), GetNbins(), and total().

Referenced by PrintContents().

00067 {
00068   Double_t total = 0.0;
00069 
00070   for( Int_t ibin=0; ibin<GetNbins(); ibin++ ){
00071     total += GetBinContent( ibin );
00072   }
00073 
00074   return total;
00075 }


Member Data Documentation

Double_t* OscFit::Histogram::fBinContents [private]
Double_t* OscFit::Histogram::fBinEdges [private]

Definition at line 49 of file Histogram.h.

Referenced by Fill(), Fill2D(), GetBinCenter(), GetNbins(), MakeTH1D(), and MakeTH2D().

Definition at line 52 of file twoflavours/Histogram.h.

Referenced by GetBinType(), Histogram(), and SetBinType().

Int_t OscFit::Histogram::fNumBins [private]
Double_t OscFit::Histogram::fOverflow [private]
Double_t* OscFit::Histogram::fX [private]

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

Generated on 21 Jun 2018 for loon by  doxygen 1.6.1