5#define APReweight2D_cxx
17 m_denominator_hist(0),
29 m_denominator_hist = (TH2D*) denominator_in->Clone(
"");
31 m_axis_x = (TAxis*) m_denominator_hist->GetXaxis()->Clone(
"");
32 m_axis_y = (TAxis*) m_denominator_hist->GetYaxis()->Clone(
"");
35 m_scale = (double) denominator_in->GetEntries() / (double) numerator_in->GetEntries();
38 for (
unsigned int i = 0; i <
m_n_bins_x; ++i) {
39 m_weights.push_back(vector<APWeightEntry*>());
40 for (
unsigned int j = 0; j <
m_n_bins_y; ++j) {
42 vector<int> temp_vec(2,0);
43 vector<int> temp_vec_axes(2,0);
49 temp_entry->
SetID(m_ID);
56 if(
m_numerator_hist->GetBinContent(i) > m_denominator_hist->GetBinContent(i) ) {
57 std::cout <<
"WARNING in APReweight2D::~APReweight2D(TH2* denominator_in, TH2* 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;
67 if (err_high_in == 0) err_high_in = err_low_in;
69 m_denominator_hist =
new TH2D(
"",
"", 1, 0., 1., 1, 0., 1.);
71 m_axis_x = (TAxis*) efficiency_in->GetXaxis()->Clone(
"");
72 m_axis_y = (TAxis*) efficiency_in->GetYaxis()->Clone(
"");
77 for (
unsigned int i = 0; i <
m_n_bins_x; ++i) {
78 m_weights.push_back(vector<APWeightEntry*>());
79 for (
unsigned int j = 0; j <
m_n_bins_y; ++j) {
81 temp_entry->
ReadEfficiency(efficiency_in->GetBinContent(i + 1, j + 1), err_low_in->GetBinContent(i + 1, j + 1), err_high_in->GetBinContent(i + 1, j + 1));
82 vector<int> temp_vec(2,0);
83 vector<int> temp_vec_axes(2,0);
89 temp_entry->
SetID(m_ID);
96 delete m_denominator_hist;
101 for (
unsigned int i = 0; i <
m_n_bins_x; ++i) {
102 for (vector<APWeightEntry*>::reverse_iterator it =
m_weights[i].rbegin(); it !=
m_weights[i].rend(); ++it) {
119 return m_denominator_hist;
135 for (
unsigned int i = 1; i <=
m_n_bins_x; ++i) {
136 if (value >=
m_axis_x->GetBinLowEdge(i) && value < m_axis_x->GetBinUpEdge(i)) {
140 if (!
m_isQuiet) cout <<
"WARNING in APReweight2D::GetBinX: Value out of range! Returning 0." << endl;
145 for (
unsigned int i = 1; i <=
m_n_bins_y; ++i) {
146 if (value >=
m_axis_y->GetBinLowEdge(i) && value < m_axis_y->GetBinUpEdge(i)) {
150 if (!
m_isQuiet) cout <<
"WARNING in APReweight2D::GetBinY: Value out of range! Returning 0." << endl;
155 for (
unsigned int i = 0; i <
m_n_bins_x; ++i) {
156 for (
unsigned int j = 0; j <
m_n_bins_y; ++j) {
APWeightEntry * GetWeight(double value_x, double value_y) const
Get Weight entry for a given pair of values.
virtual ~APReweight2D()
Default destructor.
const TH2D * GetDenominatorHist() const
Get original denominator histogram.
unsigned int m_n_bins_y
Holds the amount of bins in Y.
unsigned int GetBinY(double value_y) const
Get bin number in Y that corresponds to a given value.
double GetSampleScale() const
Get scale factor that was calculated from sample sizes upon instantiation.
void SetSystUncert(double rel_uncert)
Set the global relative (!) systematic uncertainty of all efficiencies/weights.
unsigned int m_n_bins_x
Holds the amount of bins in X.
TAxis * m_axis_x
Holds the X axis of the APReweight2D instance (from input histograms).
TAxis * m_axis_y
Holds the Y axis of the APReweight2D instance (from input histograms).
ClassDef(APReweight2D, 1) private TH2D * m_numerator_hist
< Holds the original denominator histogram.
APReweight2D()
Default constructor.
const TH2D * GetNumeratorHist() const
Get original numerator histogram.
std::vector< std::vector< APWeightEntry * > > m_weights
Holds all weight entries.
void SetQuietMode(bool isQuiet=true)
Sets the flag to turn off messages.
unsigned int NBins() const
Get amount of bins.
unsigned int GetBinX(double value_x) const
Get bin number in X that corresponds to a given value.
void ReadEfficiency(TH2 *efficiency_in, TH2 *err_low_in, TH2 *err_high_in=0)
Read efficiencies and upper/lower uncertainty (if numerator/denominator not applicable (e....
APWeightEntry * GetBinWeight(unsigned int bin_x, unsigned int bin_y) const
Get Weight entry for a given pair of bin numbers.
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.
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)