5#define APReweightND_cxx
32 m_scale = (double)denominator_in->GetEntries() / (double)numerator_in->GetEntries();
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;
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;
48 for(
unsigned int j = 0; j < m_n_dim; ++j ) {
49 if( coords[j] !=
m_numerator_hist->GetAxis(j)->GetNbins() ) checkComplete =
false;
51 if( checkComplete )
break;
53 int completeDimension = -1;
54 for(
unsigned int j = 0; j < m_n_dim; ++j ) {
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;
60 if( isComplete ) completeDimension = j;
64 if( completeDimension != -1 ) {
65 for(
int j = 0; j <= completeDimension; ++j ) coords[j] = 1;
66 coords[completeDimension+1] += 1;
78 if (err_high_in == 0) err_high_in = err_low_in;
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(
"") );
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() );
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())));
95 temp_entry->
SetID(m_ID);
104 for (vector<TAxis*>::reverse_iterator it=
m_axes.rbegin(); it !=
m_axes.rend(); ++it) {
115 vector<int> temp_vec(&
bin[0],&
bin[m_n_dim]);
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();
123 temp_weight->
SetID(m_ID);
127 return (*temp_it).second;
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;
136 temp_bin.push_back((
m_axes[i])->FindFixBin(value[i]));
154 unsigned int ret = 0;
155 for (
unsigned int i = 0; i < m_n_dim; ++i) ret += (
m_axes[i])->GetNbins();
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.
APReweightBase()
Default constructor.
bool m_isQuiet
Flag to turn off messages.
void SetQuietMode(bool isQuiet=true)
Sets the flag to turn off messages.
const THnSparse * GetDenominatorHist() const
Get original denominator histogram.
std::vector< TAxis * > m_axes
Holds all axes of the APReweightND instance (from input histograms).
std::map< std::vector< int >, APWeightEntry * > m_weights
Holds all weight entries.
APWeightEntry * GetBinWeight(const int bin[])
Get Weight entry for a given n-tuple of bin numbers.
double GetSampleScale() const
Get scale factor that was calculated from sample sizes upon instantiation.
unsigned int NBins() const
Get amount of bins.
void SetSystUncert(double rel_uncert)
Set the global relative (!) systematic uncertainty of all efficiencies/weights.
THnSparse * m_numerator_hist
Holds the original numerator histogram.
virtual ~APReweightND()
Default destructor.
APReweightND()
Default constructor.
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....
ClassDef(APReweightND, 1) private THnSparse * m_denominator_hist
< Holds the amount of dimensions.
APWeightEntry * GetWeight(double value[])
Get Weight entry for a given n-tuple of values.
const THnSparse * GetNumeratorHist() const
Get original numerator histogram.
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)
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="")