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

Class to store 3D parameterized weight maps. More...

#include <APReweight3D.h>

Inheritance diagram for APReweight3D:
Collaboration diagram for APReweight3D:

Public Member Functions

 APReweight3D ()
 Default constructor.
 APReweight3D (TH3 *denominator_in, TH3 *numerator_in, bool isTrig=false)
 Constructor for histograms (numerator/denominator) to read in.
virtual ~APReweight3D ()
 Default destructor.
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.g.
APWeightEntryGetBinWeight (unsigned int bin_x, unsigned int bin_y, unsigned int bin_z) const
 Get Weight entry for a given triplet of bin numbers.
APWeightEntryGetWeight (double value_x, double value_y, double value_z) const
 Get Weight entry for a given triplet of values.
double GetSampleScale () const
 Get scale factor that was calculated from sample sizes upon instantiation.
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.
unsigned int GetBinY (double value_y) const
 Get bin number in Y that corresponds to a given value.
unsigned int GetBinZ (double value_z) const
 Get bin number in Z that corresponds to a given value.
const TH3D * GetDenominatorHist () const
 Get original denominator histogram.
const TH3D * GetNumeratorHist () const
 Get original numerator histogram.
void SetSystUncert (double rel_uncert)
 Set the global relative (!) systematic uncertainty of all efficiencies/weights.
void SetQuietMode (bool isQuiet=true)
 Sets the flag to turn off messages.
unsigned int GetID () const
 Returns the unique ID for assignment of APWeightEntries to source.

Public Attributes

ClassDef(APReweight3D, 1) private TH3D * m_numerator_hist
 < Holds the original denominator histogram.
std::vector< std::vector< std::vector< APWeightEntry * > > > m_weights
 Holds all weight entries.
unsigned int m_n_bins_x
 Holds the amount of bins in X.
unsigned int m_n_bins_y
 Holds the amount of bins in Y.
unsigned int m_n_bins_z
 Holds the amount of bins in Z.
TAxis * m_axis_x
 Holds the X axis of the APReweight3D instance (from input histograms).
TAxis * m_axis_y
 Holds the Y axis of the APReweight3D instance (from input histograms).
TAxis * m_axis_z
 Holds the Z axis of the APReweight3D instance (from input histograms).
double m_scale
 Holds the scale factor that was calculated from sample sizes upon instantiation.
bool m_isTrig
 Flag to determine if the class holds trigger efficiencies or "simple" MC weights.
bool m_isQuiet
 Flag to turn off messages.
double m_syst_uncert_global
 Holds the global relative (!) systematic uncertainty of all efficiencies/weights.
APWeightEntrym_empty_weight
 Dummy weight (equals 0.) to return if value out of range is provided.

Static Public Attributes

static ClassDef(APReweightBase, 1) protected std::atomic< unsigned int > s_NID = 0
 < Holds the unique ID for assignment of APWeightEntries to source.

Detailed Description

Class to store 3D parameterized weight maps.

Stores a 3D parameterization of APWeightEntries from numerator and denominator histograms or from an efficiency histogram and uncertainties.

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

Definition at line 29 of file APReweight3D.h.

Constructor & Destructor Documentation

◆ APReweight3D() [1/2]

APReweight3D::APReweight3D ( )

Default constructor.

Definition at line 15 of file APReweight3D.cxx.

15 :
17 m_denominator_hist(0),
19 m_n_bins_x(0),
20 m_n_bins_y(0),
21 m_n_bins_z(0),
22 m_axis_x(0),
23 m_axis_y(0),
24 m_axis_z(0)
25{
26 m_isQuiet = false;
27}
unsigned int m_n_bins_y
Holds the amount of bins in Y.
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).
unsigned int m_n_bins_x
Holds the amount of bins in X.
TAxis * m_axis_x
Holds the X axis of the APReweight3D instance (from input histograms).
unsigned int m_n_bins_z
Holds the amount of bins in Z.
TAxis * m_axis_y
Holds the Y axis of the APReweight3D instance (from input histograms).
APReweightBase()
Default constructor.
bool m_isQuiet
Flag to turn off messages.

◆ APReweight3D() [2/2]

APReweight3D::APReweight3D ( TH3 * denominator_in,
TH3 * numerator_in,
bool isTrig = false )

Constructor for histograms (numerator/denominator) to read in.

Definition at line 29 of file APReweight3D.cxx.

29 : APReweightBase() {
30 m_empty_weight = new APWeightEntry(0, 0, 1.);
31 m_denominator_hist = (TH3D*) denominator_in->Clone("");
32 m_numerator_hist = (TH3D*) numerator_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("");
36 m_n_bins_x = m_denominator_hist->GetNbinsX();
37 m_n_bins_y = m_denominator_hist->GetNbinsY();
38 m_n_bins_z = m_denominator_hist->GetNbinsZ();
39 m_scale = (double) denominator_in->GetEntries() / (double) numerator_in->GetEntries();
40 m_isTrig = isTrig;
41 m_isQuiet = false;
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) {
47 APWeightEntry* temp_entry = new APWeightEntry((unsigned int) m_denominator_hist->GetBinContent(i + 1, j + 1, k + 1), (unsigned int) m_numerator_hist->GetBinContent(i + 1, j + 1, k + 1), m_scale, m_isTrig);
48 vector<int> temp_vec(3,0);
49 vector<int> temp_vec_axes(3,0);
50 temp_vec[0] = i+1;
51 temp_vec[1] = j+1;
52 temp_vec[2] = k+1;
53 temp_vec_axes[0] = m_n_bins_x;
54 temp_vec_axes[1] = m_n_bins_y;
55 temp_vec_axes[2] = m_n_bins_z;
56 temp_entry->SetCoordinates(temp_vec,temp_vec_axes);
57 temp_entry->SetID(m_ID);
58 m_weights[i][j].push_back(temp_entry);
59 }
60 }
61 }
62
63 if( m_isTrig ) {
64 for( int i = 1; i < m_numerator_hist->GetNbinsX()*m_numerator_hist->GetNbinsY()*m_numerator_hist->GetNbinsZ(); ++i ) {
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;
67 m_numerator_hist->SetBinContent(i,0);
68 }
69 }
70 }
71
72
73}
std::vector< std::vector< std::vector< APWeightEntry * > > > m_weights
Holds all weight entries.
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.
void SetID(unsigned int id)
Set the internal ID (used by APReweight/APReweight2D/APReweight3D/APReweightND).
void SetCoordinates(const std::vector< int > &coords, const std::vector< int > &n_dim_origin)

◆ ~APReweight3D()

APReweight3D::~APReweight3D ( )
virtual

Default destructor.

Definition at line 111 of file APReweight3D.cxx.

111 {
112 delete m_denominator_hist;
113 delete m_numerator_hist;
114 delete m_empty_weight;
115 delete m_axis_x;
116 delete m_axis_y;
117 delete m_axis_z;
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) {
121 delete *it;
122 }
123 }
124 }
125 m_weights.clear();
126}

Member Function Documentation

◆ GetBinWeight()

APWeightEntry * APReweight3D::GetBinWeight ( unsigned int bin_x,
unsigned int bin_y,
unsigned int bin_z ) const

Get Weight entry for a given triplet of bin numbers.

Definition at line 128 of file APReweight3D.cxx.

128 {
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];
131}

◆ GetBinX()

unsigned int APReweight3D::GetBinX ( double value_x) const

Get bin number in X that corresponds to a given value.

Definition at line 153 of file APReweight3D.cxx.

153 {
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)) {
156 return i;
157 }
158 }
159 if (!m_isQuiet) cout << "WARNING in APReweight3D::GetBinX: Value out of range! Returning 0." << endl;
160 return 0;
161}

◆ GetBinY()

unsigned int APReweight3D::GetBinY ( double value_y) const

Get bin number in Y that corresponds to a given value.

Definition at line 163 of file APReweight3D.cxx.

163 {
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)) {
166 return i;
167 }
168 }
169 if (!m_isQuiet) cout << "WARNING in APReweight3D::GetBinY: Value out of range! Returning 0." << endl;
170 return 0;
171}

◆ GetBinZ()

unsigned int APReweight3D::GetBinZ ( double value_z) const

Get bin number in Z that corresponds to a given value.

Definition at line 173 of file APReweight3D.cxx.

173 {
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)) {
176 return i;
177 }
178 }
179 if (!m_isQuiet) cout << "WARNING in APReweight3D::GetBinZ: Value out of range! Returning 0." << endl;
180 return 0;
181}

◆ GetDenominatorHist()

const TH3D * APReweight3D::GetDenominatorHist ( ) const

Get original denominator histogram.

Definition at line 137 of file APReweight3D.cxx.

137 {
138 return m_denominator_hist;
139}

◆ GetID()

unsigned int APReweightBase::GetID ( ) const
inherited

Returns the unique ID for assignment of APWeightEntries to source.

Definition at line 23 of file APReweightBase.cxx.

23 {
24 return m_ID;
25}

◆ GetNumeratorHist()

const TH3D * APReweight3D::GetNumeratorHist ( ) const

Get original numerator histogram.

Definition at line 141 of file APReweight3D.cxx.

141 {
142 return m_numerator_hist;
143}

◆ GetSampleScale()

double APReweight3D::GetSampleScale ( ) const

Get scale factor that was calculated from sample sizes upon instantiation.

Definition at line 145 of file APReweight3D.cxx.

145 {
146 return m_scale;
147}

◆ GetWeight()

APWeightEntry * APReweight3D::GetWeight ( double value_x,
double value_y,
double value_z ) const

Get Weight entry for a given triplet of values.

Definition at line 133 of file APReweight3D.cxx.

133 {
134 return GetBinWeight(GetBinX(value_x), GetBinY(value_y), GetBinZ(value_z));
135}
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.
unsigned int GetBinZ(double value_z) const
Get bin number in Z that corresponds to a given value.
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.

◆ NBins()

unsigned int APReweight3D::NBins ( ) const

Get amount of bins.

Definition at line 149 of file APReweight3D.cxx.

149 {
151}

◆ ReadEfficiency()

void APReweight3D::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.g.

Bootstrap)).

Definition at line 75 of file APReweight3D.cxx.

75 {
76 if (err_high_in == 0) err_high_in = err_low_in;
77 m_empty_weight = new APWeightEntry(0, 0, 1.);
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("");
83 m_n_bins_x = efficiency_in->GetNbinsX();
84 m_n_bins_y = efficiency_in->GetNbinsY();
85 m_n_bins_z = efficiency_in->GetNbinsZ();
86 m_scale = 1.0;
87 m_isTrig = true;
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) {
93 APWeightEntry *temp_entry = new APWeightEntry();
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);
97 temp_vec[0] = i+1;
98 temp_vec[1] = j+1;
99 temp_vec[2] = k+1;
100 temp_vec_axes[0] = m_n_bins_x;
101 temp_vec_axes[1] = m_n_bins_y;
102 temp_vec_axes[2] = m_n_bins_z;
103 temp_entry->SetCoordinates(temp_vec,temp_vec_axes);
104 temp_entry->SetID(m_ID);
105 m_weights[i][j].push_back(temp_entry);
106 }
107 }
108 }
109}
void ReadEfficiency(double efficiency, double err_low, double err_high)
Read efficiencies and upper/lower uncertainty (if numerator/denominator not applicable (e....

◆ SetQuietMode()

void APReweight3D::SetQuietMode ( bool isQuiet = true)

Sets the flag to turn off messages.

Definition at line 193 of file APReweight3D.cxx.

193 {
194 m_isQuiet = isQuiet;
195}

◆ SetSystUncert()

void APReweight3D::SetSystUncert ( double rel_uncert)

Set the global relative (!) systematic uncertainty of all efficiencies/weights.

Definition at line 183 of file APReweight3D.cxx.

183 {
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) {
187 GetBinWeight(i, j, k)->SetSystUncert(rel_uncert);
188 }
189 }
190 }
191}
void SetSystUncert(double rel_uncert)
Set the relative (!) systematic uncertainty for the efficiency/weight.

Member Data Documentation

◆ m_axis_x

TAxis* APReweight3D::m_axis_x

Holds the X axis of the APReweight3D instance (from input histograms).

Definition at line 62 of file APReweight3D.h.

◆ m_axis_y

TAxis* APReweight3D::m_axis_y

Holds the Y axis of the APReweight3D instance (from input histograms).

Definition at line 63 of file APReweight3D.h.

◆ m_axis_z

TAxis* APReweight3D::m_axis_z

Holds the Z axis of the APReweight3D instance (from input histograms).

Definition at line 64 of file APReweight3D.h.

◆ m_empty_weight

APWeightEntry* APReweightBase::m_empty_weight
inherited

Dummy weight (equals 0.) to return if value out of range is provided.

Definition at line 40 of file APReweightBase.h.

◆ m_isQuiet

bool APReweightBase::m_isQuiet
inherited

Flag to turn off messages.

Definition at line 38 of file APReweightBase.h.

◆ m_isTrig

bool APReweightBase::m_isTrig
inherited

Flag to determine if the class holds trigger efficiencies or "simple" MC weights.

Definition at line 37 of file APReweightBase.h.

◆ m_n_bins_x

unsigned int APReweight3D::m_n_bins_x

Holds the amount of bins in X.

Definition at line 59 of file APReweight3D.h.

◆ m_n_bins_y

unsigned int APReweight3D::m_n_bins_y

Holds the amount of bins in Y.

Definition at line 60 of file APReweight3D.h.

◆ m_n_bins_z

unsigned int APReweight3D::m_n_bins_z

Holds the amount of bins in Z.

Definition at line 61 of file APReweight3D.h.

◆ m_numerator_hist

ClassDef (APReweight3D,1) private TH3D* APReweight3D::m_numerator_hist

< Holds the original denominator histogram.

Holds the original numerator histogram.

Definition at line 57 of file APReweight3D.h.

◆ m_scale

double APReweightBase::m_scale
inherited

Holds the scale factor that was calculated from sample sizes upon instantiation.

Definition at line 36 of file APReweightBase.h.

◆ m_syst_uncert_global

double APReweightBase::m_syst_uncert_global
inherited

Holds the global relative (!) systematic uncertainty of all efficiencies/weights.

Definition at line 39 of file APReweightBase.h.

◆ m_weights

std::vector< std::vector< std::vector< APWeightEntry* > > > APReweight3D::m_weights

Holds all weight entries.

Definition at line 58 of file APReweight3D.h.

◆ s_NID

std::atomic< unsigned int > APReweightBase::s_NID = 0
staticinherited

< Holds the unique ID for assignment of APWeightEntries to source.

Holds the overall number of assigned IDs.

Definition at line 35 of file APReweightBase.h.


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