5#define APReweight3D_cxx
17 m_denominator_hist(0),
31 m_denominator_hist = (TH3D*) denominator_in->Clone(
"");
33 m_axis_x = (TAxis*) m_denominator_hist->GetXaxis()->Clone(
"");
34 m_axis_y = (TAxis*) m_denominator_hist->GetYaxis()->Clone(
"");
35 m_axis_z = (TAxis*) m_denominator_hist->GetZaxis()->Clone(
"");
39 m_scale = (double) denominator_in->GetEntries() / (double) numerator_in->GetEntries();
42 for (
unsigned int i = 0; i <
m_n_bins_x; ++i) {
43 m_weights.push_back(vector< vector<APWeightEntry*> >());
44 for (
unsigned int j = 0; j <
m_n_bins_y; ++j) {
45 m_weights[i].push_back(vector<APWeightEntry*>());
46 for (
unsigned int k = 0; k <
m_n_bins_z; ++k) {
48 vector<int> temp_vec(3,0);
49 vector<int> temp_vec_axes(3,0);
57 temp_entry->
SetID(m_ID);
65 if(
m_numerator_hist->GetBinContent(i) > m_denominator_hist->GetBinContent(i) ) {
66 std::cout <<
"WARNING in APReweight3D::~APReweight3D(TH3* denominator_in, TH3* 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;
76 if (err_high_in == 0) err_high_in = err_low_in;
78 m_denominator_hist =
new TH3D(
"",
"", 1, 0., 1., 1, 0., 1., 1, 0., 1.);
79 m_numerator_hist =
new TH3D(
"",
"", 1, 0., 1., 1, 0., 1., 1, 0., 1.);
80 m_axis_x = (TAxis*) efficiency_in->GetXaxis()->Clone(
"");
81 m_axis_y = (TAxis*) efficiency_in->GetYaxis()->Clone(
"");
82 m_axis_z = (TAxis*) efficiency_in->GetZaxis()->Clone(
"");
88 for (
unsigned int i = 0; i <
m_n_bins_x; ++i) {
89 m_weights.push_back(vector< vector<APWeightEntry*> >());
90 for (
unsigned int j = 0; j <
m_n_bins_y; ++j) {
91 m_weights[i].push_back(vector<APWeightEntry*>());
92 for (
unsigned int k = 0; k <
m_n_bins_z; ++k) {
94 temp_entry->
ReadEfficiency(efficiency_in->GetBinContent(i + 1, j + 1, k + 1), err_low_in->GetBinContent(i + 1, j + 1, k + 1), err_high_in->GetBinContent(i + 1, j + 1, k + 1));
95 vector<int> temp_vec(3,0);
96 vector<int> temp_vec_axes(3,0);
104 temp_entry->
SetID(m_ID);
112 delete m_denominator_hist;
118 for (
unsigned int i = 0; i <
m_n_bins_x; ++i) {
119 for (
unsigned int j = 0; j <
m_n_bins_y; ++j) {
120 for (vector<APWeightEntry*>::reverse_iterator it =
m_weights[i][j].rbegin(); it !=
m_weights[i][j].rend(); ++it) {
129 if (bin_x == 0 || bin_y == 0 || bin_z == 0)
return m_empty_weight;
130 return m_weights[bin_x - 1][bin_y - 1][bin_z - 1];
138 return m_denominator_hist;
154 for (
unsigned int i = 1; i <=
m_n_bins_x; ++i) {
155 if (value >=
m_axis_x->GetBinLowEdge(i) && value < m_axis_x->GetBinUpEdge(i)) {
159 if (!
m_isQuiet) cout <<
"WARNING in APReweight3D::GetBinX: Value out of range! Returning 0." << endl;
164 for (
unsigned int i = 1; i <=
m_n_bins_y; ++i) {
165 if (value >=
m_axis_y->GetBinLowEdge(i) && value < m_axis_y->GetBinUpEdge(i)) {
169 if (!
m_isQuiet) cout <<
"WARNING in APReweight3D::GetBinY: Value out of range! Returning 0." << endl;
174 for (
unsigned int i = 1; i <=
m_n_bins_z; ++i) {
175 if (value >=
m_axis_z->GetBinLowEdge(i) && value < m_axis_z->GetBinUpEdge(i)) {
179 if (!
m_isQuiet) cout <<
"WARNING in APReweight3D::GetBinZ: Value out of range! Returning 0." << endl;
184 for (
unsigned int i = 0; i <
m_n_bins_x; ++i) {
185 for (
unsigned int j = 0; j <
m_n_bins_y; ++j) {
186 for (
unsigned int k = 0; k <
m_n_bins_z; ++k) {
unsigned int m_n_bins_y
Holds the amount of bins in Y.
virtual ~APReweight3D()
Default destructor.
APWeightEntry * GetBinWeight(unsigned int bin_x, unsigned int bin_y, unsigned int bin_z) const
Get Weight entry for a given triplet of bin numbers.
void ReadEfficiency(TH3 *efficiency_in, TH3 *err_low_in, TH3 *err_high_in=0)
Read efficiencies and upper/lower uncertainty (if numerator/denominator not applicable (e....
ClassDef(APReweight3D, 1) private TH3D * m_numerator_hist
< Holds the original denominator histogram.
TAxis * m_axis_z
Holds the Z axis of the APReweight3D instance (from input histograms).
std::vector< std::vector< std::vector< APWeightEntry * > > > m_weights
Holds all weight entries.
double GetSampleScale() const
Get scale factor that was calculated from sample sizes upon instantiation.
unsigned int m_n_bins_x
Holds the amount of bins in X.
unsigned int GetBinZ(double value_z) const
Get bin number in Z that corresponds to a given value.
const TH3D * GetNumeratorHist() const
Get original numerator histogram.
TAxis * m_axis_x
Holds the X axis of the APReweight3D instance (from input histograms).
unsigned int NBins() const
Get amount of bins.
APReweight3D()
Default constructor.
unsigned int m_n_bins_z
Holds the amount of bins in Z.
unsigned int GetBinY(double value_y) const
Get bin number in Y that corresponds to a given value.
unsigned int GetBinX(double value_x) const
Get bin number in X that corresponds to a given value.
APWeightEntry * GetWeight(double value_x, double value_y, double value_z) const
Get Weight entry for a given triplet of values.
void SetQuietMode(bool isQuiet=true)
Sets the flag to turn off messages.
void SetSystUncert(double rel_uncert)
Set the global relative (!) systematic uncertainty of all efficiencies/weights.
const TH3D * GetDenominatorHist() const
Get original denominator histogram.
TAxis * m_axis_y
Holds the Y axis of the APReweight3D instance (from input histograms).
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)