10 _binContents(nBins+1,0.0),
17 WELCOME_LOG <<
"Good day from the HistogramBase() Constructor";
25 _sumW2 = std::vector<double>(nBins+1,0.0);
40 _sumW2 .reserve(nElements+1);
61 for (
int i = 1; i < other.
_nBins; i++){
67 _sumW2 .push_back( overflowSumW2 );
79 TTree tree(
"HistogramBase",
"HistogramBase");
82 double binContent = 0.0;
85 tree.Branch(
"binNumber" , &binNumber );
86 tree.Branch(
"binContent", &binContent);
87 tree.Branch(
"sumW2" , &sumW2 );
89 for(
unsigned int bin = 0; bin <
_binContents.size(); bin++ ){
104 TFile file(filename,
"RECREATE");
117 TFile file(filename,
"READ");
118 TTree* tree = (TTree*)file.Get(
"HistogramBase");
121 double binContent = 0.0;
124 int nEntries = tree->GetEntries();
126 tree->SetBranchAddress(
"binNumber" , &binNumber );
127 tree->SetBranchAddress(
"binContent", &binContent);
128 tree->SetBranchAddress(
"sumW2" , &sumW2 );
133 for(
int ent = 0; ent < nEntries; ent++){
136 VERBOSE_LOG <<
"Bin = " << binNumber <<
" Content = " << binContent <<
" SumW2 = " << sumW2;
139 _sumW2 .at((
int)binNumber) = sumW2;
149 GOODBYE_LOG <<
"Goodbye from the HistogramBase() Constructor";
158 _sumW2[binNum] += weight*weight;
168 if(bin >
_nBins || bin < 0) {
169 ERROR_LOG <<
"Bin " << bin <<
" does not exist! Adding to underflow/overflow bin " <<
_nBins;
180 for (
int i = 0; i <
_nBins; i++){
191 for (
int i = 0; i <
_nBins; i++){
202 for (
int i = 0; i <
_nBins; i++){
213 for (
int i = 0; i <
_nBins; i++){
224 ERROR_LOG <<
"Trying to divide histograms with different numbers of bins. Doing nothing.";
232 double var1 =
_sumW2.at(i);
233 double var2 = other.
_sumW2.at(i);
234 double frac1sq = var1/(binCont1*binCont1);
235 double frac2sq = var2/(binCont2*binCont2);
237 double content = binCont1 / binCont2;
238 double var = content*content*(frac1sq + frac2sq);
240 if (binCont2 == 0.0) content = 0.0;
257 ERROR_LOG <<
"Trying to divide histograms with different numbers of bins. Doing nothing.";
265 double var1 =
_sumW2.at(i);
266 double var2 = other.
_sumW2.at(i);
267 double frac1sq = var1/(binCont1*binCont1);
268 double frac2sq = var2/(binCont2*binCont2);
270 double content = binCont1 * binCont2;
271 double var = content*content*(frac1sq + frac2sq);
289 ERROR_LOG <<
"Trying to divide histograms with different numbers of bins. Doing nothing.";
297 double var1 =
_sumW2.at(i);
298 double var2 = other.
_sumW2.at(i);
300 double content = binCont1 + binCont2;
301 double var = var1 + var2;
319 ERROR_LOG <<
"Trying to divide histograms with different numbers of bins. Doing nothing.";
327 double var1 =
_sumW2.at(i);
328 double var2 = other.
_sumW2.at(i);
330 double content = binCont1 - binCont2;
331 double var = var1 + var2;
349 ERROR_LOG <<
"Trying to divide histograms with different numbers of bins. Doing nothing.";
353 for(
int i = 0; i <
getNBins(); i++){
357 double var1 =
_sumW2.at(i);
358 double var2 = other.
_sumW2.at(i);
360 double content = binCont1 - binCont2;
361 double var = var1 + var2;
379 ERROR_LOG <<
"Trying to divide histograms with different numbers of bins. Doing nothing.";
383 for(
int i = 0; i <
getNBins(); i++){
387 double var1 = other1.
_sumW2.at(i);
388 double var2 = other2.
_sumW2.at(i);
390 double content = binCont1 - binCont2;
391 double var = var1 + var2;
407 ERROR_LOG <<
"Trying to divide histograms with different numbers of bins. Doing nothing.";
411 for(
int i = 0; i <
getNBins(); i++){
415 double var1 =
_sumW2.at(i);
416 double var2 = other.
_sumW2.at(i);
418 double content = (binCont1 - binCont2)/(binCont1 + binCont2);
420 double dzdx = (2.0*binCont2)/((binCont1 + binCont2)*(binCont1 + binCont2));
421 double dzdy = (2.0*binCont1)/((binCont1 + binCont2)*(binCont1 + binCont2));
422 double varsq = dzdx*dzdx*var1*var1 + dzdy*dzdy*var2*var2;
438 ERROR_LOG <<
"Trying to divide histograms with different numbers of bins. Doing nothing.";
442 for(
int i = 0; i <
getNBins(); i++){
446 double var1 = other1.
_sumW2.at(i);
447 double var2 = other2.
_sumW2.at(i);
449 double content = (binCont1 - binCont2)/(binCont1 + binCont2);
451 double dzdx = (2.0*binCont2)/((binCont1 + binCont2)*(binCont1 + binCont2));
452 double dzdy = (2.0*binCont1)/((binCont1 + binCont2)*(binCont1 + binCont2));
453 double varsq = dzdx*dzdx*var1*var1 + dzdy*dzdy*var2*var2;
474 TRandom3 random(seed);
476 for(
int i = 0; i <
getNBins(); i++){
479 double sigma = sqrt(
_sumW2.at(i));
481 double newContent = random.Gaus(mean, sigma);
482 if (newContent < 0.0) newContent = 0.0;
497 return TMath::Prob(
chi2, ndof);
506 double pval =
pvalue(other, ndof);
507 double sigma = TMath::NormQuantile( pval/2.0 );
519 for(
int i = 0; i <
getNBins(); i++){
523 double var1 =
_sumW2.at(i);
524 double var2 = other.
_sumW2.at(i);
526 double content = binCont1 - binCont2;
527 double var = var1 + var2;
529 double thisTerm = (content * content) / var;
544 TH1D
pulls (
"pulls",
"pulls", nBins, -pmLimits, pmLimits);
545 pulls.GetXaxis()->SetTitle(
"pull");
546 pulls.GetYaxis()->SetTitle(
"frequency");
547 for(
int i = 0; i <
getNBins(); i++){
551 double var1 =
_sumW2.at(i);
552 double var2 = other.
_sumW2.at(i);
554 double content = binCont1 - binCont2;
555 double var = var1 + var2;
557 double pull = (content) / sqrt(var);
571 for(
int i = 0; i <
getNBins() ; i++){
581 for(
int i = 0; i <
getNBins() ; i++){
592 double divisor2 = divisor*divisor;
594 for(
int i = 0; i <
getNBins(); i++){
649 for(
int i = 0; i <
_nBins; i++){
661 for(
int i = 0; i <
_nBins; i++){
void loadBase(TString filename)
double chi2(const HistogramBase &other) const
double getMaxDensity() const
double getBinError(int bin) const
virtual void merge(const HistogramBase &other)
std::vector< double > _binContents
void asymmetry(const HistogramBase &other)
void setBinError(int bin, double val)
std::vector< double > _sumW2
void add(const double &x, const double &weight=1.0)
virtual double getBinVolume(int bin) const
const double & getMin() const
double getBinContent(int bin) const
void setBinContent(int bin, double val)
void fillBase(int binNum, double weight)
void makeFrequencyDensity()
double chi2sig(const HistogramBase &other, int ndof=-1) const
double getFrequencyDensity(int bin) const
void resetBinContents(int nBins)
void multiply(const HistogramBase &other)
virtual void plot(TString plotDirectory, TString plotOptions="", TPad *pad=0, double scaleFactor=1.0)
void drawPullHistogram(const HistogramBase &other, TString name, int nBins=50, double pmLimits=3.5) const
void reserveCapacity(int nElements)
void minus(const HistogramBase &other)
void randomiseWithinErrors(int seed)
void divide(const HistogramBase &other)
int checkBinNumber(int bin) const
void normalise(double area=1.0)
const double & getMax() const
void pulls(const HistogramBase &other)
double pvalue(const HistogramBase &other, int ndof=-1) const
double integralError() const
double getMinDensity() const
void add(const HistogramBase &other)