ATLAS Offline Software
Loading...
Searching...
No Matches
APWeightHist Class Reference

Extended histogramming class. More...

#include <APWeightHist.h>

Inheritance diagram for APWeightHist:
Collaboration diagram for APWeightHist:

Public Member Functions

 APWeightHist (const char *name, const char *title, const int n_bins, const float x_min, const float x_max)
 Constructor which takes histo title, amount of bins and the range and optionally the preicision to use for the calculation of the uncertainty.
 APWeightHist ()
 Default constructor.
 ~APWeightHist ()
 Default destructor.
int Fill (const double value, APWeightEntry *weight)
 < Overloads TH1D's Fill method.
TGraphAsymmErrors * GetGraphStatUncert (bool autocompute=true)
 Extracts the histogram with statistical uncertainties.
TGraphErrors * GetGraphSystUncert (bool simple=true, bool autocompute=true)
 Extracts the histogram with systematic uncertainties.
void ComputeGraph (const int prec=250)
 Computes the resulting graph from all added ntuples and calculates the uncertainties for all bins.
TH1D * GetBinPDF (unsigned int bin, bool autocompute=true)
 ClassDef (APWeightHist, 1)
 ClassDef for ROOTCINT dictionary.

Private Attributes

double m_computed_entries
 Flag to store information about the status of the computation.
std::vector< std::vector< APWeightEntry * > > m_binned_weights
 Holds all filled weights weights as pointers.
std::vector< TH1D * > m_bin_dists
 Holds the PDFs for the individual bins.
std::vector< double > m_SumSys2
 Holds the variances of systematic uncertainties for the individual bins.
TGraphAsymmErrors * m_graph_stat
 Holds the histogram with statistical uncertainties.
TGraphErrors * m_graph_syst
 Holds the histogram with systematic uncertainties.

Detailed Description

Extended histogramming class.

Extended histogramming class (inheriting from TH1D) which allows propagation of uncertainties on the actual weights used for filling.

Author
fabia.nosp@m.n.Ko.nosp@m.hn@ce.nosp@m.rn.c.nosp@m.h

Definition at line 26 of file APWeightHist.h.

Constructor & Destructor Documentation

◆ APWeightHist() [1/2]

APWeightHist::APWeightHist ( const char * name,
const char * title,
const int n_bins,
const float x_min,
const float x_max )

Constructor which takes histo title, amount of bins and the range and optionally the preicision to use for the calculation of the uncertainty.

Definition at line 18 of file APWeightHist.cxx.

19 : TH1D(name, title, n_bins, x_min, x_max)
20 //m_prec(0)
21{
22 m_graph_stat = new TGraphAsymmErrors();
23 m_graph_stat->GetXaxis()->SetTitle(GetXaxis()->GetTitle());
24 m_graph_stat->GetYaxis()->SetTitle(GetYaxis()->GetTitle());
25 m_graph_syst = new TGraphErrors();
26 m_graph_syst->GetXaxis()->SetTitle(GetXaxis()->GetTitle());
27 m_graph_syst->GetYaxis()->SetTitle(GetYaxis()->GetTitle());
28 m_binned_weights = vector< vector< APWeightEntry* > >(n_bins);
29 Sumw2();
30 m_SumSys2 = vector< double >(n_bins, 0.);
32}
std::vector< std::vector< APWeightEntry * > > m_binned_weights
Holds all filled weights weights as pointers.
TGraphAsymmErrors * m_graph_stat
Holds the histogram with statistical uncertainties.
std::vector< double > m_SumSys2
Holds the variances of systematic uncertainties for the individual bins.
TGraphErrors * m_graph_syst
Holds the histogram with systematic uncertainties.
double m_computed_entries
Flag to store information about the status of the computation.

◆ APWeightHist() [2/2]

APWeightHist::APWeightHist ( )

Default constructor.

Definition at line 34 of file APWeightHist.cxx.

35 : m_graph_stat(0),
37 //m_prec(0)
38{
40}

◆ ~APWeightHist()

APWeightHist::~APWeightHist ( )

Default destructor.

Definition at line 42 of file APWeightHist.cxx.

42 {
43
44}

Member Function Documentation

◆ ClassDef()

APWeightHist::ClassDef ( APWeightHist ,
1  )

ClassDef for ROOTCINT dictionary.

◆ ComputeGraph()

void APWeightHist::ComputeGraph ( const int prec = 250)

Computes the resulting graph from all added ntuples and calculates the uncertainties for all bins.

Definition at line 69 of file APWeightHist.cxx.

69 {
70 for (int i = 0, I = m_graph_stat->GetN(); i < I; ++i) m_graph_stat->RemovePoint(i);
71 for (int i = 0, I = m_graph_syst->GetN(); i < I; ++i) m_graph_syst->RemovePoint(i);
72 vector< TH1D* > original_dists = vector< TH1D* >(fXaxis.GetNbins());
73 m_bin_dists = vector< TH1D* >(fXaxis.GetNbins());
74 int point_count = 0;
75 for (int j = 0; j < fXaxis.GetNbins(); ++j) {
76 //Create Poisson distributions for original histogram.
77 double unweighted_content = (double) (m_binned_weights[j]).size();
78 double sig_low_o = (max((double) 0.0, (unweighted_content - 5 * sqrt(unweighted_content))));
79 double sig_high_o = (unweighted_content + 5 * sqrt(unweighted_content));
80 double step = (sig_high_o - sig_low_o) * 1e-3;
81
82 original_dists[j] = new TH1D("", "", 1000, sig_low_o, sig_high_o);
83
84 int bin_no = 1;
85 double curr_fact = ln_factorialApp((m_binned_weights[j]).size());
86 for (double lambda = sig_low_o; lambda < sig_high_o; lambda += step) {
87 double value = exp(-lambda + unweighted_content * log(lambda) - curr_fact);
88 if (value != value) value = 0.;
89 (original_dists[j])->SetBinContent(bin_no, value);
90 ++bin_no;
91 }
92 (original_dists[j])->Scale(1. / (original_dists[j])->GetSum());
93 const double old_mode = (original_dists[j])->GetBinCenter((original_dists[j])->GetMaximumBin());
94 const double inv_old_mode = 1. / old_mode;
95
96 //Create different final sum of weights for this bin
97 vector< double > bin_sumw(prec, 0.);
98 double max_value = 1.e-100;
99 double min_value = 1.e100;
100
101 for (vector<double>::iterator it_hist = bin_sumw.begin(), it_histE = bin_sumw.end(); it_hist != it_histE; ++it_hist) {
102 for (vector<APWeightEntry*>::iterator it_func = (m_binned_weights[j]).begin(), it_funcE = (m_binned_weights[j]).end(); it_func != it_funcE; ++it_func) {
103 *it_hist += (*it_func)->GetRandom();
104 }
105 double cur_val = *it_hist;
106 if (cur_val < min_value) {
107 min_value = cur_val;
108 } else if (cur_val > max_value) {
109 max_value = cur_val;
110 }
111 }
112
113 //Create final distribution for this bin
114 TH1D* scaled_hist_l = (TH1D*) (original_dists[j])->Clone("");
115 TH1D* scaled_hist_h = (TH1D*) (original_dists[j])->Clone("");
116 double scale = min_value * inv_old_mode;
117 scaled_hist_l->GetXaxis()->SetLimits(scale * sig_low_o, scale * sig_high_o);
118 scale = max_value * inv_old_mode;
119 scaled_hist_h->GetXaxis()->SetLimits(scale * sig_low_o, scale * sig_high_o);
120
121 double quant[1];
122 double prob[1] = {0.001};
123
124 scaled_hist_l->GetQuantiles(1, quant, prob);
125 double sig_low = quant[0];
126 prob[0] = 0.999;
127 scaled_hist_h->GetQuantiles(1, quant, prob);
128 double sig_high = quant[0];
129
130 m_bin_dists[j] = new TH1D("", "", 1000, sig_low, sig_high);
131
132 //fill final distribution for this bin with scaled/weighted Poisson distributions
133 if (unweighted_content > 0.) {
134 for (int k = 0; k < prec; ++k) {
135 double new_val = bin_sumw[k];
136 TH1D* scaled_hist = (TH1D*) (original_dists[j])->Clone("");
137 double temp_scale = new_val * inv_old_mode;
138 scaled_hist->GetXaxis()->SetLimits(temp_scale * sig_low_o, temp_scale * sig_high_o);
139 for (int l = 1; l < 1001; ++l) {
140 (m_bin_dists[j])->AddBinContent(l, scaled_hist->GetBinContent(scaled_hist->FindBin((m_bin_dists[j])->GetBinCenter(l))));
141 }
142 delete scaled_hist;
143 }
144 double local_value = sig_low + (m_bin_dists[j])->GetMaximumBin() * ((sig_high - sig_low) * 1e-3);
145 m_graph_stat->SetPoint(point_count, (GetXaxis()->GetXmin() + j * GetBinWidth(j + 1) + GetBinWidth(j + 1) / 2), local_value);
146 m_graph_syst->SetPoint(point_count, (GetXaxis()->GetXmin() + j * GetBinWidth(j + 1) + GetBinWidth(j + 1) / 2), local_value);
147 double quantile[ 2 ];
148 double conf[ 2 ] = {0.1585, 0.8415};
149 (m_bin_dists[j])->GetQuantiles(2, quantile, conf);
150 m_graph_stat->SetPointError(point_count, GetBinWidth(j + 1) / 2, GetBinWidth(j + 1) / 2, local_value - quantile[0], quantile[1] - local_value);
151 m_graph_syst->SetPointError(point_count, GetBinWidth(j + 1) / 2, local_value * (sqrt(m_SumSys2[j]) / GetBinContent(j + 1)));
152 ++point_count;
153 }
154 }
155 m_computed_entries = fEntries;
156}
static int quant(double min, double max, unsigned nSteps, double val)
#define I(x, y, z)
Definition MD5.cxx:116
double ln_factorialApp(unsigned int value)
Logarithmic factorial (approximative).
Definition MathTools.cxx:18
#define max(a, b)
Definition cfImp.cxx:41
std::vector< TH1D * > m_bin_dists
Holds the PDFs for the individual bins.
void Scale(TH1 *h, double d=1)
l
Printing final latex table to .tex output file.
float j(const xAOD::IParticle &, const xAOD::TrackMeasurementValidation &hit, const Eigen::Matrix3d &jab_inv)

◆ Fill()

int APWeightHist::Fill ( const double value,
APWeightEntry * weight )

< Overloads TH1D's Fill method.

Adds a weighted value to the calculation.

Definition at line 46 of file APWeightHist.cxx.

46 {
47 // if (fBuffer) return BufferFill(value,w);
48 double w = weight->GetExpectancy();
49 int bin = fXaxis.FindBin(value);
50 fEntries++;
51 AddBinContent(bin, w);
52 if (fSumw2.fN) fSumw2.fArray[bin] += w * w;
53 if (bin == 0 || bin > fXaxis.GetNbins()) {
54 if (!GetStatOverflowsBehaviour()) return -1;
55 }
56 Double_t z = (w > 0 ? w : -w);
57 fTsumw += z;
58 fTsumw2 += z*z;
59 fTsumwx += z*value;
60 fTsumwx2 += z * value*value;
61 if (bin > 0) {
62 m_binned_weights[bin - 1].push_back(weight);
63 m_SumSys2[bin - 1] += weight->GetSysUncert2();
64 }
65 fSumw2.fArray[bin] += weight->GetVariance() + z*z;
66 return bin;
67}
#define z

◆ GetBinPDF()

TH1D * APWeightHist::GetBinPDF ( unsigned int bin,
bool autocompute = true )

Definition at line 180 of file APWeightHist.cxx.

180 {
181 if (autocompute && fEntries > m_computed_entries) ComputeGraph();
182 return m_bin_dists[bin - 1];
183}
void ComputeGraph(const int prec=250)
Computes the resulting graph from all added ntuples and calculates the uncertainties for all bins.

◆ GetGraphStatUncert()

TGraphAsymmErrors * APWeightHist::GetGraphStatUncert ( bool autocompute = true)

Extracts the histogram with statistical uncertainties.

Definition at line 158 of file APWeightHist.cxx.

158 {
159 if (autocompute && fEntries > m_computed_entries) ComputeGraph();
160 return m_graph_stat;
161}

◆ GetGraphSystUncert()

TGraphErrors * APWeightHist::GetGraphSystUncert ( bool simple = true,
bool autocompute = true )

Extracts the histogram with systematic uncertainties.

Definition at line 163 of file APWeightHist.cxx.

163 {
164 if (simple) {
165 for (int i = 0, I = m_graph_syst->GetN(); i < I; ++i) m_graph_syst->RemovePoint(i);
166 int point_count = 0;
167 for (int j = 0; j < fXaxis.GetNbins(); ++j) {
168 if ((m_binned_weights[j]).size() > 0) {
169 m_graph_syst->SetPoint(point_count, (GetXaxis()->GetXmin() + j * GetBinWidth(j + 1) + GetBinWidth(j + 1) / 2), GetBinContent(j + 1));
170 m_graph_syst->SetPointError(point_count, GetBinWidth(j + 1) / 2, sqrt(m_SumSys2[j]));
171 ++point_count;
172 }
173 }
174 return m_graph_syst;
175 }
176 if (autocompute && fEntries > m_computed_entries) ComputeGraph();
177 return m_graph_syst;
178}

Member Data Documentation

◆ m_bin_dists

std::vector< TH1D* > APWeightHist::m_bin_dists
private

Holds the PDFs for the individual bins.

Definition at line 44 of file APWeightHist.h.

◆ m_binned_weights

std::vector< std::vector< APWeightEntry* > > APWeightHist::m_binned_weights
private

Holds all filled weights weights as pointers.

Definition at line 43 of file APWeightHist.h.

◆ m_computed_entries

double APWeightHist::m_computed_entries
private

Flag to store information about the status of the computation.

Definition at line 42 of file APWeightHist.h.

◆ m_graph_stat

TGraphAsymmErrors* APWeightHist::m_graph_stat
private

Holds the histogram with statistical uncertainties.

Definition at line 46 of file APWeightHist.h.

◆ m_graph_syst

TGraphErrors* APWeightHist::m_graph_syst
private

Holds the histogram with systematic uncertainties.

Definition at line 47 of file APWeightHist.h.

◆ m_SumSys2

std::vector< double > APWeightHist::m_SumSys2
private

Holds the variances of systematic uncertainties for the individual bins.

Definition at line 45 of file APWeightHist.h.


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