17 m_denominator_hist(0),
25APReweight::APReweight(TTree* denominator,
const std::string& denominator_branch, TTree* numerator,
const std::string& numerator_branch,
unsigned int n_bins,
double x_min,
double x_max,
bool isTrig) :
APReweightBase() {
27 m_denominator_hist =
new TH1D(
"",
"denominator_hist", n_bins, x_min, x_max);
29 m_axis = (TAxis*) m_denominator_hist->GetXaxis()->Clone(
"");
30 m_n_bins = m_denominator_hist->GetNbinsX();
33 vector<double> *denominator_vec = 0, *numerator_vec = 0;
34 TBranch *b_denominator_vec, *b_numerator_vec;
35 denominator->SetBranchAddress(denominator_branch.c_str(), &denominator_vec, &b_denominator_vec);
36 numerator->SetBranchAddress(numerator_branch.c_str(), &numerator_vec, &b_numerator_vec);
37 unsigned long nentries_denominator = denominator->GetEntries(), nentries_numerator = numerator->GetEntries(), counter = 0;
38 while (counter < nentries_denominator) {
39 denominator->GetEntry(counter);
40 for (
unsigned int i = 0,
I = denominator_vec->size(); i <
I; ++i) m_denominator_hist->Fill((*denominator_vec)[i]);
44 while (counter < nentries_numerator) {
45 numerator->GetEntry(counter);
46 for (
unsigned int i = 0,
I = numerator_vec->size(); i <
I; ++i)
m_numerator_hist->Fill((*numerator_vec)[i]);
51 denominator->ResetBranchAddress(b_denominator_vec);
52 numerator->ResetBranchAddress(b_numerator_vec);
53 delete b_denominator_vec;
54 delete b_numerator_vec;
55 denominator_vec->clear();
56 delete denominator_vec;
57 numerator_vec->clear();
60 m_scale = (double) nentries_denominator / (
double) nentries_numerator;
63 for (
unsigned int i = 0; i <
m_n_bins; ++i) {
66 temp_entry->
SetID(m_ID);
73 m_denominator_hist =
new TH1D(
"",
"denominator_hist", n_bins, x_min, x_max);
75 m_axis = (TAxis*) m_denominator_hist->GetXaxis()->Clone(
"");
76 m_n_bins = m_denominator_hist->GetNbinsX();
79 for (
unsigned long i = 0,
I = denominator.size(); i <
I; ++i) m_denominator_hist->Fill(denominator[i]);
80 for (
unsigned long i = 0,
I = numerator.size(); i <
I; ++i)
m_numerator_hist->Fill(numerator[i]);
82 m_scale = (double) denominator.size() / (double) numerator.size();
85 for (
unsigned int i = 0; i <
m_n_bins; ++i) {
88 temp_entry->
SetID(m_ID);
95 m_denominator_hist = (TH1D*) denominator_in->Clone(
"");
97 m_axis = (TAxis*) m_denominator_hist->GetXaxis()->Clone(
"");
98 m_n_bins = m_denominator_hist->GetNbinsX();
99 m_scale = (double) denominator_in->GetEntries() / (double) numerator_in->GetEntries();
102 for (
unsigned int i = 0; i <
m_n_bins; ++i) {
105 temp_entry->
SetID(m_ID);
111 if(
m_numerator_hist->GetBinContent(i) > m_denominator_hist->GetBinContent(i) ) {
112 std::cout <<
"WARNING in APReweight::~APReweight(TH1* denominator_in, TH1* numerator_in, bool isTrig) : Using histograms " <<
m_numerator_hist->GetName() <<
" and " << m_denominator_hist->GetName() <<
" the efficiency is larger than 1 for bin " << i <<
"! This is inconsistent and can lead to unwanted behaviour (weights > 1, variance < 0 )! Please check your input histograms. In order to avoid negative variances, the efficiency in this bin will be set to 0. " << std::endl;
121 if (err_high_in == 0) err_high_in = err_low_in;
123 m_denominator_hist =
new TH1D(
"",
"", 1, 0., 1.);
125 m_axis = (TAxis*) efficiency_in->GetXaxis()->Clone(
"");
126 m_n_bins = efficiency_in->GetNbinsX();
129 for (
unsigned int i = 0; i <
m_n_bins; ++i) {
131 temp_entry->
ReadEfficiency(efficiency_in->GetBinContent(i + 1), err_low_in->GetBinContent(i + 1), err_high_in->GetBinContent(i + 1));
133 temp_entry->
SetID(m_ID);
139 delete m_denominator_hist;
143 for (vector<APWeightEntry*>::reverse_iterator it =
m_weights.rbegin(); it !=
m_weights.rend(); ++it) {
159 return m_denominator_hist;
175 for (
unsigned int i = 1; i <=
m_n_bins; ++i) {
176 if (value >=
m_axis->GetBinLowEdge(i) && value <= m_axis->GetBinUpEdge(i)) {
180 if (!
m_isQuiet) cout <<
"WARNING in APReweight::GetBin: Value out of range! Returning 0." << endl;
185 for (
unsigned int i = 1; i <=
m_n_bins; ++i) {
double m_scale
Holds the scale factor that was calculated from sample sizes upon instantiation.
APWeightEntry * m_empty_weight
Dummy weight (equals 0.) to return if value out of range is provided.
bool m_isTrig
Flag to determine if the class holds trigger efficiencies or "simple" MC weights.
APReweightBase()
Default constructor.
bool m_isQuiet
Flag to turn off messages.
const TH1D * GetDenominatorHist() const
Get original denominator histogram.
APReweight()
Default constructor.
virtual ~APReweight()
Default destructor.
void SetQuietMode(bool isQuiet=true)
Sets the flag to turn off messages.
unsigned int m_n_bins
Holds the amount of bins.
void ReadEfficiency(TH1 *efficiency_in, TH1 *err_low_in, TH1 *err_high_in=0)
Read efficiencies and upper/lower uncertainty (if numerator/denominator not applicable (e....
ClassDef(APReweight, 1) private TH1D * m_numerator_hist
< Holds the original denominator histogram.
double GetSampleScale() const
Get scale factor that was calculated from sample sizes upon instantiation.
APWeightEntry * GetWeight(double value) const
Get Weight entry for a given value.
APWeightEntry * GetBinWeight(unsigned int bin) const
Get Weight entry for a given bin number.
std::vector< APWeightEntry * > m_weights
Holds all weight entries.
unsigned int NBins() const
Get amount of bins.
const TH1D * GetNumeratorHist() const
Get original numerator histogram.
unsigned int GetBin(double value) const
Get bin number that corresponds to a given value.
TAxis * m_axis
Holds the axis of the APReweight instance (from input histograms).
void SetSystUncert(double rel_uncert)
Set the global relative (!) systematic uncertainty of all efficiencies/weights.
Class to store a single weight entry (one bin).
void SetID(unsigned int id)
Set the internal ID (used by APReweight/APReweight2D/APReweight3D/APReweightND).
void ReadEfficiency(double efficiency, double err_low, double err_high)
Read efficiencies and upper/lower uncertainty (if numerator/denominator not applicable (e....
void SetSystUncert(double rel_uncert)
Set the relative (!) systematic uncertainty for the efficiency/weight.
void SetCoordinates(const std::vector< int > &coords, const std::vector< int > &n_dim_origin)