ATLAS Offline Software
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
APReweight2D Class Reference

#include <APReweight2D.h>

Inheritance diagram for APReweight2D:
Collaboration diagram for APReweight2D:

Public Member Functions

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

Public Attributes

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

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. More...
 

Detailed Description

Class to store 2D parameterized weight maps

Stores a 2D 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 APReweight2D.h.

Constructor & Destructor Documentation

◆ APReweight2D() [1/2]

APReweight2D::APReweight2D ( )

Default constructor.

Definition at line 15 of file APReweight2D.cxx.

15  :
17  m_denominator_hist(0),
19  m_n_bins_x(0),
20  m_n_bins_y(0),
21  m_axis_x(0),
22  m_axis_y(0)
23 {
24  m_isQuiet = false;
25 }

◆ APReweight2D() [2/2]

APReweight2D::APReweight2D ( TH2 *  denominator_in,
TH2 *  numerator_in,
bool  isTrig = false 
)

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

Definition at line 27 of file APReweight2D.cxx.

27  : APReweightBase() {
28  m_empty_weight = new APWeightEntry(0, 0, 1.);
29  m_denominator_hist = (TH2D*) denominator_in->Clone("");
30  m_numerator_hist = (TH2D*) numerator_in->Clone("");
31  m_axis_x = (TAxis*) m_denominator_hist->GetXaxis()->Clone("");
32  m_axis_y = (TAxis*) m_denominator_hist->GetYaxis()->Clone("");
33  m_n_bins_x = m_denominator_hist->GetNbinsX();
34  m_n_bins_y = m_denominator_hist->GetNbinsY();
35  m_scale = (double) denominator_in->GetEntries() / (double) numerator_in->GetEntries();
36  m_isTrig = isTrig;
37  m_isQuiet = false;
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) {
41  APWeightEntry* temp_entry = new APWeightEntry((unsigned int) m_denominator_hist->GetBinContent(i + 1, j + 1), (unsigned int) m_numerator_hist->GetBinContent(i + 1, j + 1), m_scale, m_isTrig);
42  vector<int> temp_vec(2,0);
43  vector<int> temp_vec_axes(2,0);
44  temp_vec[0] = i+1;
45  temp_vec[1] = j+1;
46  temp_vec_axes[0] = m_n_bins_x;
47  temp_vec_axes[1] = m_n_bins_y;
48  temp_entry->SetCoordinates(temp_vec,temp_vec_axes);
49  temp_entry->SetID(m_ID);
50  m_weights[i].push_back(temp_entry);
51  }
52  }
53 
54  if( m_isTrig ) {
55  for( int i = 1; i < m_numerator_hist->GetNbinsX()*m_numerator_hist->GetNbinsY(); ++i ) {
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;
58  m_numerator_hist->SetBinContent(i,0);
59  }
60  }
61  }
62 
63 
64 }

◆ ~APReweight2D()

APReweight2D::~APReweight2D ( )
virtual

Default destructor.

Definition at line 95 of file APReweight2D.cxx.

95  {
96  delete m_denominator_hist;
97  delete m_numerator_hist;
98  delete m_axis_x;
99  delete m_axis_y;
100  delete m_empty_weight;
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) {
103  delete *it;
104  }
105  }
106  m_weights.clear();
107 }

Member Function Documentation

◆ GetBinWeight()

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

Get Weight entry for a given pair of bin numbers.

Definition at line 109 of file APReweight2D.cxx.

109  {
110  if (bin_x == 0 || bin_y == 0) return m_empty_weight;
111  return m_weights[bin_x - 1][bin_y - 1];
112 }

◆ GetBinX()

unsigned int APReweight2D::GetBinX ( double  value_x) const

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

Definition at line 134 of file APReweight2D.cxx.

134  {
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)) {
137  return i;
138  }
139  }
140  if (!m_isQuiet) cout << "WARNING in APReweight2D::GetBinX: Value out of range! Returning 0." << endl;
141  return 0;
142 }

◆ GetBinY()

unsigned int APReweight2D::GetBinY ( double  value_y) const

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

Definition at line 144 of file APReweight2D.cxx.

144  {
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)) {
147  return i;
148  }
149  }
150  if (!m_isQuiet) cout << "WARNING in APReweight2D::GetBinY: Value out of range! Returning 0." << endl;
151  return 0;
152 }

◆ GetDenominatorHist()

const TH2D * APReweight2D::GetDenominatorHist ( ) const

Get original denominator histogram.

Definition at line 118 of file APReweight2D.cxx.

118  {
119  return m_denominator_hist;
120 }

◆ 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 TH2D * APReweight2D::GetNumeratorHist ( ) const

Get original numerator histogram.

Definition at line 122 of file APReweight2D.cxx.

122  {
123  return m_numerator_hist;
124 }

◆ GetSampleScale()

double APReweight2D::GetSampleScale ( ) const

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

Definition at line 126 of file APReweight2D.cxx.

126  {
127  return m_scale;
128 }

◆ GetWeight()

APWeightEntry * APReweight2D::GetWeight ( double  value_x,
double  value_y 
) const

Get Weight entry for a given pair of values.

Definition at line 114 of file APReweight2D.cxx.

114  {
115  return GetBinWeight(GetBinX(value_x), GetBinY(value_y));
116 }

◆ NBins()

unsigned int APReweight2D::NBins ( ) const

Get amount of bins.

Definition at line 130 of file APReweight2D.cxx.

130  {
131  return m_n_bins_x*m_n_bins_y;
132 }

◆ ReadEfficiency()

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

Bootstrap)).

Definition at line 66 of file APReweight2D.cxx.

66  {
67  if (err_high_in == 0) err_high_in = err_low_in;
68  m_empty_weight = new APWeightEntry(0, 0, 1.);
69  m_denominator_hist = new TH2D("", "", 1, 0., 1., 1, 0., 1.);
70  m_numerator_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("");
73  m_n_bins_x = efficiency_in->GetNbinsX();
74  m_n_bins_y = efficiency_in->GetNbinsY();
75  m_scale = 1.0;
76  m_isTrig = true;
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) {
80  APWeightEntry *temp_entry = new APWeightEntry();
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);
84  temp_vec[0] = i+1;
85  temp_vec[1] = j+1;
86  temp_vec_axes[0] = m_n_bins_x;
87  temp_vec_axes[1] = m_n_bins_y;
88  temp_entry->SetCoordinates(temp_vec,temp_vec_axes);
89  temp_entry->SetID(m_ID);
90  m_weights[i].push_back(temp_entry);
91  }
92  }
93 }

◆ SetQuietMode()

void APReweight2D::SetQuietMode ( bool  isQuiet = true)

Sets the flag to turn off messages.

Definition at line 162 of file APReweight2D.cxx.

162  {
163  m_isQuiet = isQuiet;
164 }

◆ SetSystUncert()

void APReweight2D::SetSystUncert ( double  rel_uncert)

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

Definition at line 154 of file APReweight2D.cxx.

154  {
155  for (unsigned int i = 0; i < m_n_bins_x; ++i) {
156  for (unsigned int j = 0; j < m_n_bins_y; ++j) {
157  GetBinWeight(i,j)->SetSystUncert(rel_uncert);
158  }
159  }
160 }

Member Data Documentation

◆ m_axis_x

TAxis* APReweight2D::m_axis_x

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

Definition at line 60 of file APReweight2D.h.

◆ m_axis_y

TAxis* APReweight2D::m_axis_y

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

Definition at line 61 of file APReweight2D.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 APReweight2D::m_n_bins_x

Holds the amount of bins in X.

Definition at line 58 of file APReweight2D.h.

◆ m_n_bins_y

unsigned int APReweight2D::m_n_bins_y

Holds the amount of bins in Y.

Definition at line 59 of file APReweight2D.h.

◆ m_numerator_hist

ClassDef (APReweight2D,1) private TH2D* APReweight2D::m_numerator_hist

< Holds the original denominator histogram.

Holds the original numerator histogram.

Definition at line 56 of file APReweight2D.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< APWeightEntry* > > APReweight2D::m_weights

Holds all weight entries.

Definition at line 57 of file APReweight2D.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:
APReweight2D::GetBinWeight
APWeightEntry * GetBinWeight(unsigned int bin_x, unsigned int bin_y) const
Get Weight entry for a given pair of bin numbers.
Definition: APReweight2D.cxx:109
APWeightEntry
Definition: APWeightEntry.h:25
APWeightEntry::SetCoordinates
void SetCoordinates(const std::vector< int > &coords, const std::vector< int > &n_dim_origin)
Definition: APWeightEntry.cxx:180
APReweightBase::m_empty_weight
APWeightEntry * m_empty_weight
Dummy weight (equals 0.) to return if value out of range is provided.
Definition: APReweightBase.h:40
APReweight2D::GetBinX
unsigned int GetBinX(double value_x) const
Get bin number in X that corresponds to a given value.
Definition: APReweight2D.cxx:134
skel.it
it
Definition: skel.GENtoEVGEN.py:396
APReweightBase::m_scale
double m_scale
Holds the scale factor that was calculated from sample sizes upon instantiation.
Definition: APReweightBase.h:36
athena.value
value
Definition: athena.py:124
APReweightBase::m_isQuiet
bool m_isQuiet
Flag to turn off messages.
Definition: APReweightBase.h:38
APReweight2D::m_axis_y
TAxis * m_axis_y
Holds the Y axis of the APReweight2D instance (from input histograms).
Definition: APReweight2D.h:61
APReweightBase::APReweightBase
APReweightBase()
Default constructor.
Definition: APReweightBase.cxx:10
APWeightEntry::ReadEfficiency
void ReadEfficiency(double efficiency, double err_low, double err_high)
Read efficiencies and upper/lower uncertainty (if numerator/denominator not applicable (e....
Definition: APWeightEntry.cxx:168
lumiFormat.i
int i
Definition: lumiFormat.py:85
APReweightBase::m_isTrig
bool m_isTrig
Flag to determine if the class holds trigger efficiencies or "simple" MC weights.
Definition: APReweightBase.h:37
APReweight2D::m_axis_x
TAxis * m_axis_x
Holds the X axis of the APReweight2D instance (from input histograms).
Definition: APReweight2D.h:60
APWeightEntry::SetID
void SetID(unsigned int id)
Set the internal ID (used by APReweight/APReweight2D/APReweight3D/APReweightND).
Definition: APWeightEntry.cxx:273
APReweight2D::m_n_bins_x
unsigned int m_n_bins_x
Holds the amount of bins in X.
Definition: APReweight2D.h:58
APWeightEntry::SetSystUncert
void SetSystUncert(double rel_uncert)
Set the relative (!) systematic uncertainty for the efficiency/weight.
Definition: APWeightEntry.cxx:268
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
APReweight2D::GetBinY
unsigned int GetBinY(double value_y) const
Get bin number in Y that corresponds to a given value.
Definition: APReweight2D.cxx:144
APReweight2D::m_n_bins_y
unsigned int m_n_bins_y
Holds the amount of bins in Y.
Definition: APReweight2D.h:59
APReweight2D::m_weights
std::vector< std::vector< APWeightEntry * > > m_weights
Holds all weight entries.
Definition: APReweight2D.h:57
APReweight2D::m_numerator_hist
ClassDef(APReweight2D, 1) private TH2D * m_numerator_hist
< Holds the original denominator histogram.
Definition: APReweight2D.h:52