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

Class to store n-dimensionally parameterized weight maps. More...

#include <APReweightND.h>

Inheritance diagram for APReweightND:
Collaboration diagram for APReweightND:

Public Member Functions

 APReweightND ()
 Default constructor.
 APReweightND (THnSparse *denominator_in, THnSparse *numerator_in, bool isTrig=false)
 Constructor for histograms (numerator/denominator) to read in.
virtual ~APReweightND ()
 Default destructor.
void ReadEfficiency (THnSparse *efficiency_in, THnSparse *err_low_in, THnSparse *err_high_in=0)
 Read efficiencies and upper/lower uncertainty (if numerator/denominator not applicable (e.g.
APWeightEntryGetBinWeight (const int bin[])
 Get Weight entry for a given n-tuple of bin numbers.
APWeightEntryGetWeight (double value[])
 Get Weight entry for a given n-tuple of values.
double GetSampleScale () const
 Get scale factor that was calculated from sample sizes upon instantiation.
unsigned int NBins () const
 Get amount of bins.
const THnSparse * GetDenominatorHist () const
 Get original denominator histogram.
const THnSparse * 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(APReweightND, 1) private THnSparse * m_denominator_hist
 < Holds the amount of dimensions.
THnSparse * m_numerator_hist
 Holds the original numerator histogram.
std::map< std::vector< int >, APWeightEntry * > m_weights
 Holds all weight entries.
std::vector< TAxis * > m_axes
 Holds all axes of the APReweightND 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 n-dimensionally parameterized weight maps.

Stores a n-dimensional 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 APReweightND.h.

Constructor & Destructor Documentation

◆ APReweightND() [1/2]

APReweightND::APReweightND ( )

Default constructor.

Definition at line 17 of file APReweightND.cxx.

19 m_n_dim(0),
22{
23 m_isQuiet = false;
24}
APReweightBase()
Default constructor.
bool m_isQuiet
Flag to turn off messages.
THnSparse * m_numerator_hist
Holds the original numerator histogram.
ClassDef(APReweightND, 1) private THnSparse * m_denominator_hist
< Holds the amount of dimensions.

◆ APReweightND() [2/2]

APReweightND::APReweightND ( THnSparse * denominator_in,
THnSparse * numerator_in,
bool isTrig = false )

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

Definition at line 26 of file APReweightND.cxx.

26 : APReweightBase() {
27 m_empty_weight = new APWeightEntry(0,0,1.);
28 m_denominator_hist = (THnSparse*)denominator_in->Clone("");
29 m_numerator_hist = (THnSparse*)numerator_in->Clone("");
30 m_n_dim = m_denominator_hist->GetNdimensions();
31 for (unsigned int i = 0; i < m_n_dim; ++i) m_axes.push_back( (TAxis*)m_denominator_hist->GetAxis(i)->Clone("") );
32 m_scale = (double)denominator_in->GetEntries() / (double)numerator_in->GetEntries();
33 m_isTrig = isTrig;
34 m_isQuiet = false;
36
37 if( m_isTrig ) {
38 std::vector<int> coords(m_n_dim);
39 for( unsigned int i = 0; i < m_n_dim; ++i ) coords[i] = 1;
40 bool checkComplete = false;
41 while( 1 ) {
42 if( m_numerator_hist->GetBinContent(coords.data()) > m_denominator_hist->GetBinContent(coords.data()) ) {
43 std::cout << "WARNING in APReweightND::~APReweightND(THnSparse* denominator_in, THnSparse* numerator_in, bool isTrig) : Using histograms " << m_numerator_hist->GetName() << " and " << m_denominator_hist->GetName() << " the efficiency is larger than 1 for coordinates [ "; for( unsigned int j = 0; j < m_n_dim; ++j ) { std::cout << coords[j] << " "; } std::cout << " ]! This is inconsisten 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;
44 m_numerator_hist->SetBinContent(coords.data(), 0);
45 }
46
47 checkComplete = true;
48 for( unsigned int j = 0; j < m_n_dim; ++j ) {
49 if( coords[j] != m_numerator_hist->GetAxis(j)->GetNbins() ) checkComplete = false;
50 }
51 if( checkComplete ) break;
52
53 int completeDimension = -1;
54 for( unsigned int j = 0; j < m_n_dim; ++j ) {
55 if( coords[j] == m_numerator_hist->GetAxis(j)->GetNbins() ) {
56 bool isComplete = true;
57 for( int k = (int)j-1; k >= 0; --k ) {
58 if( coords[k] != m_numerator_hist->GetAxis(k)->GetNbins() ) isComplete = false;
59 }
60 if( isComplete ) completeDimension = j;
61 }
62 }
63
64 if( completeDimension != -1 ) {
65 for( int j = 0; j <= completeDimension; ++j ) coords[j] = 1;
66 coords[completeDimension+1] += 1;
67 }
68 else {
69 coords[0] += 1;
70 }
71
72 }
73 }
74
75}
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.
double m_syst_uncert_global
Holds the global relative (!) systematic uncertainty of all efficiencies/weights.
std::vector< TAxis * > m_axes
Holds all axes of the APReweightND instance (from input histograms).

◆ ~APReweightND()

APReweightND::~APReweightND ( )
virtual

Default destructor.

Definition at line 100 of file APReweightND.cxx.

100 {
101 delete m_denominator_hist;
102 delete m_numerator_hist;
103 delete m_empty_weight;
104 for (vector<TAxis*>::reverse_iterator it=m_axes.rbegin(); it != m_axes.rend(); ++it) {
105 delete *it;
106 }
107 for (map< vector<int>, APWeightEntry* >::reverse_iterator it=m_weights.rbegin(); it != m_weights.rend(); ++it) {
108 delete it->second;
109 }
110 m_weights.clear();
111 m_axes.clear();
112}
std::map< std::vector< int >, APWeightEntry * > m_weights
Holds all weight entries.

Member Function Documentation

◆ GetBinWeight()

APWeightEntry * APReweightND::GetBinWeight ( const int bin[])

Get Weight entry for a given n-tuple of bin numbers.

Definition at line 114 of file APReweightND.cxx.

114 {
115 vector<int> temp_vec(&bin[0],&bin[m_n_dim]);
116 map< vector<int> , APWeightEntry* >::iterator temp_it = m_weights.find(temp_vec);
117 if ( temp_it == m_weights.end() ) {
118 APWeightEntry* temp_weight = new APWeightEntry((unsigned int)m_denominator_hist->GetBinContent(m_denominator_hist->GetBin(bin)),(unsigned int)m_numerator_hist->GetBinContent(m_numerator_hist->GetBin(bin)),m_scale, m_isTrig);
119 vector<int> temp_vec_axes(m_n_dim,0);
120 for (unsigned int i = 0; i < m_n_dim; ++i) temp_vec_axes[i] = m_denominator_hist->GetAxis(i)->GetNbins();
121 temp_weight->SetCoordinates(temp_vec,temp_vec_axes);
123 temp_weight->SetID(m_ID);
124 m_weights[temp_vec] = temp_weight;
125 return temp_weight;
126 }
127 return (*temp_it).second;
128}
void SetID(unsigned int id)
Set the internal ID (used by APReweight/APReweight2D/APReweight3D/APReweightND).
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)

◆ GetDenominatorHist()

const THnSparse * APReweightND::GetDenominatorHist ( ) const

Get original denominator histogram.

Definition at line 141 of file APReweightND.cxx.

141 {
142 return m_denominator_hist;
143}

◆ 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 THnSparse * APReweightND::GetNumeratorHist ( ) const

Get original numerator histogram.

Definition at line 145 of file APReweightND.cxx.

145 {
146 return m_numerator_hist;
147}

◆ GetSampleScale()

double APReweightND::GetSampleScale ( ) const

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

Definition at line 149 of file APReweightND.cxx.

149 {
150 return m_scale;
151}

◆ GetWeight()

APWeightEntry * APReweightND::GetWeight ( double value[])

Get Weight entry for a given n-tuple of values.

Definition at line 130 of file APReweightND.cxx.

130 {
131 vector<int> temp_bin;
132 for (unsigned int i = 0; i < m_n_dim; ++i) {
133 if ( value[i] < (m_axes[i])->GetXmin() || value[i] > (m_axes[i])->GetXmax() ) {
134 if (!m_isQuiet) cout << "WARNING in APReweightND::GetBin: Value out of range! Dim: " << i << ", value: " << value[i] << ", return value: " << (m_axes[i])->FindFixBin(value[i]) << endl;
135 }
136 temp_bin.push_back((m_axes[i])->FindFixBin(value[i]));
137 }
138 return GetBinWeight(&temp_bin[0]);
139}
APWeightEntry * GetBinWeight(const int bin[])
Get Weight entry for a given n-tuple of bin numbers.

◆ NBins()

unsigned int APReweightND::NBins ( ) const

Get amount of bins.

Definition at line 153 of file APReweightND.cxx.

153 {
154 unsigned int ret = 0;
155 for (unsigned int i = 0; i < m_n_dim; ++i) ret += (m_axes[i])->GetNbins();
156 return ret;
157}

◆ ReadEfficiency()

void APReweightND::ReadEfficiency ( THnSparse * efficiency_in,
THnSparse * err_low_in,
THnSparse * err_high_in = 0 )

Read efficiencies and upper/lower uncertainty (if numerator/denominator not applicable (e.g.

Bootstrap)).

Definition at line 77 of file APReweightND.cxx.

77 {
78 if (err_high_in == 0) err_high_in = err_low_in;
79 m_empty_weight = new APWeightEntry(0,0,1.);
80 m_denominator_hist = new THnSparseD();
81 m_numerator_hist = new THnSparseD();
82 m_n_dim = efficiency_in->GetNdimensions();
83 for (unsigned int i = 0; i < m_n_dim; ++i) m_axes.push_back( (TAxis*)efficiency_in->GetAxis(i)->Clone("") );
84 m_scale = 1.0;
85 m_isTrig = true;
87 vector<int> temp_vec_axes(m_n_dim,0);
88 for (unsigned int j = 0; j < m_n_dim; ++j) temp_vec_axes[j] = efficiency_in->GetAxis(j)->GetNbins();
89 for (int i = 0, I = efficiency_in->GetNbins(); i < I; ++i) {
90 std::vector<int> coords (m_n_dim);
91 double efficiency = efficiency_in->GetBinContent( i,coords.data() );
92 APWeightEntry *temp_entry = new APWeightEntry();
93 temp_entry->ReadEfficiency(efficiency,err_low_in->GetBinContent(err_low_in->GetBin(coords.data())),err_high_in->GetBinContent(err_high_in->GetBin(coords.data())));
94 temp_entry->SetCoordinates(coords,temp_vec_axes);
95 temp_entry->SetID(m_ID);
96 m_weights[coords] = temp_entry;
97 }
98}
#define I(x, y, z)
Definition MD5.cxx:116
void ReadEfficiency(double efficiency, double err_low, double err_high)
Read efficiencies and upper/lower uncertainty (if numerator/denominator not applicable (e....
void efficiency(std::vector< double > &bins, std::vector< double > &values, const std::vector< std::string > &files, const std::string &histname, const std::string &tplotname, const std::string &label="")

◆ SetQuietMode()

void APReweightND::SetQuietMode ( bool isQuiet = true)

Sets the flag to turn off messages.

Definition at line 166 of file APReweightND.cxx.

166 {
167 m_isQuiet = isQuiet;
168}

◆ SetSystUncert()

void APReweightND::SetSystUncert ( double rel_uncert)

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

Definition at line 159 of file APReweightND.cxx.

159 {
160 m_syst_uncert_global = rel_uncert;
161 for ( map< vector<int> , APWeightEntry* >::const_iterator temp_it = m_weights.begin(); temp_it != m_weights.end(); ++temp_it ) {
162 ((*temp_it).second)->SetSystUncert(rel_uncert);
163 }
164}
void SetSystUncert(double rel_uncert)
Set the global relative (!) systematic uncertainty of all efficiencies/weights.

Member Data Documentation

◆ m_axes

std::vector< TAxis* > APReweightND::m_axes

Holds all axes of the APReweightND instance (from input histograms).

Definition at line 57 of file APReweightND.h.

◆ m_denominator_hist

ClassDef (APReweightND, 1) private THnSparse* APReweightND::m_denominator_hist

< Holds the amount of dimensions.

Holds the original denominator histogram.

Definition at line 54 of file APReweightND.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_numerator_hist

THnSparse* APReweightND::m_numerator_hist

Holds the original numerator histogram.

Definition at line 55 of file APReweightND.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::map< std::vector<int> , APWeightEntry* > APReweightND::m_weights

Holds all weight entries.

Definition at line 56 of file APReweightND.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: