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

#include <APReweight.h>

Inheritance diagram for APReweight:
Collaboration diagram for APReweight:

Public Member Functions

 APReweight ()
 Default constructor. More...
 
 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=false)
 Constructor for whole branches (numerator/denominator) to read in. More...
 
 APReweight (std::vector< double > denominator, std::vector< double > numerator, unsigned int n_bins, double x_min, double x_max, bool isTrig=false)
 Constructor for vectors (numerator/denominator) to read in. More...
 
 APReweight (TH1 *denominator_in, TH1 *numerator_in, bool isTrig=false)
 Constructor for histograms (numerator/denominator) to read in. More...
 
virtual ~APReweight ()
 Default destructor. More...
 
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.g. More...
 
APWeightEntryGetBinWeight (unsigned int bin) const
 Get Weight entry for a given bin number. More...
 
APWeightEntryGetWeight (double value) const
 Get Weight entry for a given value. 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 GetBin (double value) const
 Get bin number that corresponds to a given value. More...
 
const TH1D * GetDenominatorHist () const
 Get original denominator histogram. More...
 
const TH1D * 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(APReweight, 1) private TH1D * m_numerator_hist
 < Holds the original denominator histogram. More...
 
std::vector< APWeightEntry * > m_weights
 Holds all weight entries. More...
 
unsigned int m_n_bins
 Holds the amount of bins. More...
 
TAxis * m_axis
 Holds the axis of the APReweight 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 1D parameterized weight maps

Stores a 1D 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 30 of file APReweight.h.

Constructor & Destructor Documentation

◆ APReweight() [1/4]

APReweight::APReweight ( )

Default constructor.

Definition at line 15 of file APReweight.cxx.

15  :
17  m_denominator_hist(0),
19  m_n_bins(0),
20  m_axis(0)
21 {
22  m_isQuiet = false;
23 }

◆ APReweight() [2/4]

APReweight::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 = false 
)

Constructor for whole branches (numerator/denominator) to read in.

Definition at line 25 of file APReweight.cxx.

25  : APReweightBase() {
26  m_empty_weight = new APWeightEntry(0, 0, 1.);
27  m_denominator_hist = new TH1D("", "denominator_hist", n_bins, x_min, x_max);
28  m_numerator_hist = new TH1D("", "numerator_hist", n_bins, x_min, x_max);
29  m_axis = (TAxis*) m_denominator_hist->GetXaxis()->Clone("");
30  m_n_bins = m_denominator_hist->GetNbinsX();
31 
32  //Readout from Trees and fill histograms
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]);
41  ++counter;
42  }
43  counter = 0;
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]);
47  ++counter;
48  }
49 
50  //Cleanup
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();
58  delete numerator_vec;
59 
60  m_scale = (double) nentries_denominator / (double) nentries_numerator;
61  m_isTrig = isTrig;
62  m_isQuiet = false;
63  for (unsigned int i = 0; i < m_n_bins; ++i) {
64  APWeightEntry* temp_entry = new APWeightEntry((unsigned int) m_denominator_hist->GetBinContent(i + 1), (unsigned int) m_numerator_hist->GetBinContent(i + 1), m_scale, m_isTrig);
65  temp_entry->SetCoordinates(vector<int>(1,i+1),vector<int>(1,m_n_bins));
66  temp_entry->SetID(m_ID);
67  m_weights.push_back(temp_entry);
68  }
69 }

◆ APReweight() [3/4]

APReweight::APReweight ( std::vector< double >  denominator,
std::vector< double >  numerator,
unsigned int  n_bins,
double  x_min,
double  x_max,
bool  isTrig = false 
)

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

Definition at line 71 of file APReweight.cxx.

71  : APReweightBase() {
72  m_empty_weight = new APWeightEntry(0, 0, 1.);
73  m_denominator_hist = new TH1D("", "denominator_hist", n_bins, x_min, x_max);
74  m_numerator_hist = new TH1D("", "numerator_hist", n_bins, x_min, x_max);
75  m_axis = (TAxis*) m_denominator_hist->GetXaxis()->Clone("");
76  m_n_bins = m_denominator_hist->GetNbinsX();
77 
78  //Readout from vectors and fill histograms
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]);
81 
82  m_scale = (double) denominator.size() / (double) numerator.size();
83  m_isTrig = isTrig;
84  m_isQuiet = false;
85  for (unsigned int i = 0; i < m_n_bins; ++i) {
86  APWeightEntry* temp_entry = new APWeightEntry((unsigned int) m_denominator_hist->GetBinContent(i + 1), (unsigned int) m_numerator_hist->GetBinContent(i + 1), m_scale, m_isTrig);
87  temp_entry->SetCoordinates(vector<int>(1,i+1),vector<int>(1,m_n_bins));
88  temp_entry->SetID(m_ID);
89  m_weights.push_back(temp_entry);
90  }
91 }

◆ APReweight() [4/4]

APReweight::APReweight ( TH1 *  denominator_in,
TH1 *  numerator_in,
bool  isTrig = false 
)

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

Definition at line 93 of file APReweight.cxx.

93  : APReweightBase() {
94  m_empty_weight = new APWeightEntry(0, 0, 1.);
95  m_denominator_hist = (TH1D*) denominator_in->Clone("");
96  m_numerator_hist = (TH1D*) numerator_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();
100  m_isTrig = isTrig;
101  m_isQuiet = false;
102  for (unsigned int i = 0; i < m_n_bins; ++i) {
103  APWeightEntry* temp_entry = new APWeightEntry((unsigned int) m_denominator_hist->GetBinContent(i + 1), (unsigned int) m_numerator_hist->GetBinContent(i + 1), m_scale, m_isTrig);
104  temp_entry->SetCoordinates(vector<int>(1,i+1),vector<int>(1,m_n_bins));
105  temp_entry->SetID(m_ID);
106  m_weights.push_back(temp_entry);
107  }
108 
109  if( m_isTrig ) {
110  for( int i = 1; i < m_numerator_hist->GetNbinsX(); ++i ) {
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;
113  m_numerator_hist->SetBinContent(i,0);
114  }
115  }
116  }
117 
118 }

◆ ~APReweight()

APReweight::~APReweight ( )
virtual

Default destructor.

Definition at line 138 of file APReweight.cxx.

138  {
139  delete m_denominator_hist;
140  delete m_numerator_hist;
141  delete m_empty_weight;
142  delete m_axis;
143  for (vector<APWeightEntry*>::reverse_iterator it = m_weights.rbegin(); it != m_weights.rend(); ++it) {
144  delete *it;
145  }
146  m_weights.clear();
147 }

Member Function Documentation

◆ GetBin()

unsigned int APReweight::GetBin ( double  value) const

Get bin number that corresponds to a given value.

Definition at line 174 of file APReweight.cxx.

174  {
175  for (unsigned int i = 1; i <= m_n_bins; ++i) {
176  if (value >= m_axis->GetBinLowEdge(i) && value <= m_axis->GetBinUpEdge(i)) {
177  return i;
178  }
179  }
180  if (!m_isQuiet) cout << "WARNING in APReweight::GetBin: Value out of range! Returning 0." << endl;
181  return 0;
182 }

◆ GetBinWeight()

APWeightEntry * APReweight::GetBinWeight ( unsigned int  bin) const

Get Weight entry for a given bin number.

Definition at line 149 of file APReweight.cxx.

149  {
150  if (bin == 0) return m_empty_weight;
151  return m_weights[bin - 1];
152 }

◆ GetDenominatorHist()

const TH1D * APReweight::GetDenominatorHist ( ) const

Get original denominator histogram.

Definition at line 158 of file APReweight.cxx.

158  {
159  return m_denominator_hist;
160 }

◆ 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 TH1D * APReweight::GetNumeratorHist ( ) const

Get original numerator histogram.

Definition at line 162 of file APReweight.cxx.

162  {
163  return m_numerator_hist;
164 }

◆ GetSampleScale()

double APReweight::GetSampleScale ( ) const

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

Definition at line 166 of file APReweight.cxx.

166  {
167  return m_scale;
168 }

◆ GetWeight()

APWeightEntry * APReweight::GetWeight ( double  value) const

Get Weight entry for a given value.

Definition at line 154 of file APReweight.cxx.

154  {
155  return GetBinWeight(GetBin(value));
156 }

◆ NBins()

unsigned int APReweight::NBins ( ) const

Get amount of bins.

Definition at line 170 of file APReweight.cxx.

170  {
171  return m_n_bins;
172 }

◆ ReadEfficiency()

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

Bootstrap)).

Definition at line 120 of file APReweight.cxx.

120  {
121  if (err_high_in == 0) err_high_in = err_low_in;
122  m_empty_weight = new APWeightEntry(0, 0, 1.);
123  m_denominator_hist = new TH1D("", "", 1, 0., 1.);
124  m_numerator_hist = new TH1D("", "", 1, 0., 1.);
125  m_axis = (TAxis*) efficiency_in->GetXaxis()->Clone("");
126  m_n_bins = efficiency_in->GetNbinsX();
127  m_scale = 1.0;
128  m_isTrig = true;
129  for (unsigned int i = 0; i < m_n_bins; ++i) {
130  APWeightEntry *temp_entry = new APWeightEntry();
131  temp_entry->ReadEfficiency(efficiency_in->GetBinContent(i + 1), err_low_in->GetBinContent(i + 1), err_high_in->GetBinContent(i + 1));
132  temp_entry->SetCoordinates(vector<int>(1,i+1),vector<int>(1,m_n_bins));
133  temp_entry->SetID(m_ID);
134  m_weights.push_back(temp_entry);
135  }
136 }

◆ SetQuietMode()

void APReweight::SetQuietMode ( bool  isQuiet = true)

Sets the flag to turn off messages.

Definition at line 190 of file APReweight.cxx.

190  {
191  m_isQuiet = isQuiet;
192 }

◆ SetSystUncert()

void APReweight::SetSystUncert ( double  rel_uncert)

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

Definition at line 184 of file APReweight.cxx.

184  {
185  for (unsigned int i = 1; i <= m_n_bins; ++i) {
186  GetBinWeight(i)->SetSystUncert(rel_uncert);
187  }
188 }

Member Data Documentation

◆ m_axis

TAxis* APReweight::m_axis

Holds the axis of the APReweight instance (from input histograms).

Definition at line 61 of file APReweight.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

unsigned int APReweight::m_n_bins

Holds the amount of bins.

Definition at line 60 of file APReweight.h.

◆ m_numerator_hist

ClassDef (APReweight, 1) private TH1D* APReweight::m_numerator_hist

< Holds the original denominator histogram.

Holds the original numerator histogram.

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

Holds all weight entries.

Definition at line 59 of file APReweight.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:
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
skel.it
it
Definition: skel.GENtoEVGEN.py:396
bin
Definition: BinsDiffFromStripMedian.h:43
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
APReweight::m_n_bins
unsigned int m_n_bins
Holds the amount of bins.
Definition: APReweight.h:60
APReweightBase::m_isQuiet
bool m_isQuiet
Flag to turn off messages.
Definition: APReweightBase.h:38
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
APWeightEntry::SetID
void SetID(unsigned int id)
Set the internal ID (used by APReweight/APReweight2D/APReweight3D/APReweightND).
Definition: APWeightEntry.cxx:273
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
ReadTripsProbsFromCool.denominator
denominator
Definition: ReadTripsProbsFromCool.py:96
APReweight::m_axis
TAxis * m_axis
Holds the axis of the APReweight instance (from input histograms).
Definition: APReweight.h:61
APReweight::m_numerator_hist
ClassDef(APReweight, 1) private TH1D * m_numerator_hist
< Holds the original denominator histogram.
Definition: APReweight.h:54
I
#define I(x, y, z)
Definition: MD5.cxx:116
APReweight::GetBinWeight
APWeightEntry * GetBinWeight(unsigned int bin) const
Get Weight entry for a given bin number.
Definition: APReweight.cxx:149
test_pyathena.counter
counter
Definition: test_pyathena.py:15
APReweight::m_weights
std::vector< APWeightEntry * > m_weights
Holds all weight entries.
Definition: APReweight.h:59
APReweight::GetBin
unsigned int GetBin(double value) const
Get bin number that corresponds to a given value.
Definition: APReweight.cxx:174