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

#include <APWeightSum.h>

Inheritance diagram for APWeightSum:
Collaboration diagram for APWeightSum:

Public Member Functions

 APWeightSum ()
 Default constructor. More...
 
virtual ~APWeightSum ()
 Default destructor. More...
 
void AddWeightToEvt (APWeightEntry *weight)
 Adds a weight to the sum of weights. More...
 
void FinishEvt (double ext_weight=1.0)
 Finishes the current event and calculates the event weight. More...
 
void AddEvt (APEvtWeight *evt_weight, double ext_weight=1.0)
 Adds an event with an externally calculated EvtWeight object. More...
 
double GetSumW () const
 Returns the sum of weights. More...
 
double GetSumW2 () const
 Returns sum of (weights^2). More...
 
double GetSumWExternal () const
 Returns the sum of weights without taking into account the trigger weighting (external weights only) to allow switching trigger weighting on/off. More...
 
double GetStdDev ()
 Returns the standard deviation. More...
 
double GetVariance ()
 Returns the variance. More...
 
double GetVarianceNoCorr ()
 Returns the variance, assuming no correlations. More...
 
double GetVarianceFullCorr ()
 Returns the variance, assuming full correlation amongst objects. More...
 
double GetSysUncert () const
 Returns the systematic uncertainty (from systematics assigned to weights). More...
 
unsigned long GetKUnweighted () const
 Returns the unweighted sum of entries. More...
 
THnSparse * GetUncertHistogram (APReweightBase *weighter)
 Returns THnSparse holding the uncertainties for given APReweightBase instance. More...
 
const std::vector< THnSparse * > & GetAllUncertHistograms ()
 Returns vector of THnSparses holding the uncertainties for all APReweight IDs. More...
 

Public Attributes

ClassDef(APWeightSum, 1) protected std::vector< APWeightEntry * > m_current_evt_weights
 < Calculates the final uncertainties including correlations. More...
 
std::vector< THnSparse * > m_linear_uncert
 Holds all histograms for uncertainties. More...
 
unsigned long int m_k_evt_orig
 Holds the original amount of unweighted counts ("sum of 1's"). More...
 
double m_k_evt_weight
 Holds the sum of weights. More...
 
double m_k_evt_weight2
 Holds the sum of squared weights. More...
 
double m_k_evt_weight_external
 Holds the sum of external weights (no trigger weighting). More...
 
double m_variance
 Holds the variance. More...
 
double m_variance_nocorr
 Holds the variance, assuming no correlations. More...
 
double m_variance_fullcorr
 Holds the variance, assuming full correlation amongst objects. More...
 
double m_variance_sys
 Holds the systematic variance (from systematics assigned to weights). More...
 
bool m_isComputed
 

Detailed Description

Class to calculate the sum of weights ("weighted counter")

Calculates the sum of weights taking into account the underlying asymmetric probability distribution. This is done by modelling the pdf and then extracting the corresponding quantiles.

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

Definition at line 29 of file APWeightSum.h.

Constructor & Destructor Documentation

◆ APWeightSum()

APWeightSum::APWeightSum ( )

Default constructor.

Definition at line 17 of file APWeightSum.cxx.

17  {
18  m_k_evt_orig = 0;
19  m_k_evt_weight = 0.;
20  m_k_evt_weight2 = 0.;
22  m_variance = 0.;
23  m_variance_nocorr = 0.;
25  m_variance_sys = 0.;
26 
27  m_isComputed = false;
28 }

◆ ~APWeightSum()

APWeightSum::~APWeightSum ( )
virtual

Default destructor.

Definition at line 30 of file APWeightSum.cxx.

30  {
31  for (vector<THnSparse*>::reverse_iterator it = m_linear_uncert.rbegin(); it != m_linear_uncert.rend(); ++it) delete *it;
32  m_linear_uncert.clear();
33 }

Member Function Documentation

◆ AddEvt()

void APWeightSum::AddEvt ( APEvtWeight evt_weight,
double  ext_weight = 1.0 
)

Adds an event with an externally calculated EvtWeight object.

Takes an optional external weight factor (e.g. mc weight).

Definition at line 100 of file APWeightSum.cxx.

100  {
101  ++m_k_evt_orig;
102  m_k_evt_weight += ext_weight * evt_weight->GetWeight();
104  m_k_evt_weight_external += ext_weight;
105 
106  vector<APWeightEntry*> temp_vec_mu = evt_weight->GetWeightObjects(APEvtWeight::kMuon);
107  vector<APWeightEntry*> temp_vec_dimu = evt_weight->GetWeightObjects(APEvtWeight::kDiMuon);
108  vector<APWeightEntry*> temp_vec_mumo = evt_weight->GetWeightObjects(APEvtWeight::kMuonMO);
109  vector<APWeightEntry*> temp_vec_tau = evt_weight->GetWeightObjects(APEvtWeight::kTau);
110  vector<APWeightEntry*> temp_vec_ditau = evt_weight->GetWeightObjects(APEvtWeight::kDiTau);
111  vector<APWeightEntry*> temp_vec_taumo = evt_weight->GetWeightObjects(APEvtWeight::kTauMO);
112  vector<APWeightEntry*> temp_vec_el = evt_weight->GetWeightObjects(APEvtWeight::kElectron);
113  vector<APWeightEntry*> temp_vec_diel = evt_weight->GetWeightObjects(APEvtWeight::kDiElectron);
114  vector<APWeightEntry*> temp_vec_elmo = evt_weight->GetWeightObjects(APEvtWeight::kElectronMO);
115  vector<APWeightEntry*> temp_vec_jet = evt_weight->GetWeightObjects(APEvtWeight::kJet);
116  vector<APWeightEntry*> temp_vec_dijet = evt_weight->GetWeightObjects(APEvtWeight::kDiJet);
117  vector<APWeightEntry*> temp_vec_jetmo = evt_weight->GetWeightObjects(APEvtWeight::kJetMO);
118 
119  vector< vector<APWeightEntry*> > temp_vec_all;
120 
121  temp_vec_all.push_back(temp_vec_mu);
122  temp_vec_all.push_back(temp_vec_tau);
123  temp_vec_all.push_back(temp_vec_el);
124  temp_vec_all.push_back(temp_vec_jet);
125  temp_vec_all.push_back(temp_vec_mumo);
126  temp_vec_all.push_back(temp_vec_taumo);
127  temp_vec_all.push_back(temp_vec_elmo);
128  temp_vec_all.push_back(temp_vec_jetmo);
129  temp_vec_all.push_back(temp_vec_dimu);
130  temp_vec_all.push_back(temp_vec_ditau);
131  temp_vec_all.push_back(temp_vec_diel);
132  temp_vec_all.push_back(temp_vec_dijet);
133 
134  /* check if histogram for error propagation is already there; if not, create it */
135  for( unsigned int iAll = 0, IAll = temp_vec_all.size(); iAll < IAll; ++iAll ) {
136  for( unsigned int i = 0, I = temp_vec_all[iAll].size(); i < I; ++i ) {
137  unsigned int ID = temp_vec_all[iAll][i]->GetID();
138  if( m_linear_uncert.size() < ID+1 ) m_linear_uncert.resize(ID+1, 0);
139  if( m_linear_uncert[ID] == 0 ) {
140  vector<int> original_dimensions = temp_vec_all[iAll][i]->GetOriginalDimensions();
141  int *bins = new int[original_dimensions.size()];
142  double *xmin = new double[original_dimensions.size()];
143  double *xmax = new double[original_dimensions.size()];
144  for( unsigned int j = 0, J = original_dimensions.size(); j < J; ++j ) {
145  bins[j] = original_dimensions[j];
146  xmin[j] = 0.;
147  xmax[j] = 10.;
148  }
149  m_linear_uncert[ID] = new THnSparseD("","",original_dimensions.size(), bins, xmin, xmax);
150  }
151  }
152  }
153  /* calculate weight and derivatives */
154  /* these are the simple weights: kMuon, kTau, kElectron and kJet: single object trigger, OR of all elements */
155  if(evt_weight->GetType() <= APEvtWeight::kJet) {
156  vector<APWeightEntry*> temp_vec_rel;
157  if(evt_weight->GetType() == APEvtWeight::kMuon) temp_vec_rel = temp_vec_mu;
158  else if(evt_weight->GetType() == APEvtWeight::kTau) temp_vec_rel = temp_vec_tau;
159  else if(evt_weight->GetType() == APEvtWeight::kElectron) temp_vec_rel = temp_vec_el;
160  else if(evt_weight->GetType() == APEvtWeight::kJet) temp_vec_rel = temp_vec_jet;
161 
162  for (unsigned int i = 0, I = temp_vec_rel.size(); i < I; ++i ) {
163  vector<int> coord = temp_vec_rel[i]->GetCoords();
164  double weight_uncert = sqrt(temp_vec_rel[i]->GetVariance());
165  for (unsigned int j = 0; j < I; ++j ) {
166  if (j == i) continue;
167  weight_uncert *= (1.0 - temp_vec_rel[j]->GetExpectancy());
168  }
169  m_linear_uncert[temp_vec_rel[i]->GetID()]->SetBinContent(&coord.front(), m_linear_uncert[temp_vec_rel[i]->GetID()]->GetBinContent(&coord.front())+weight_uncert);
170  m_variance_nocorr += weight_uncert*weight_uncert;
171  }
172  }
173 
174  /* these are the DiMuon, DiTau, DiElectron and DiJet weights */
175  else if (evt_weight->GetType() >= APEvtWeight::kDiMuon && evt_weight->GetType() <= APEvtWeight::kDiJet) {
176  vector<APWeightEntry*> temp_vec_rel;
177  if(evt_weight->GetType() == APEvtWeight::kDiMuon) temp_vec_rel = temp_vec_dimu;
178  else if(evt_weight->GetType() == APEvtWeight::kDiTau) temp_vec_rel = temp_vec_ditau;
179  else if(evt_weight->GetType() == APEvtWeight::kDiElectron) temp_vec_rel = temp_vec_diel;
180  else if(evt_weight->GetType() == APEvtWeight::kDiJet) temp_vec_rel = temp_vec_dijet;
181 
182  bool isAsymTrig = false;
183  vector<unsigned int> temp_vec_IDs;
184  temp_vec_IDs.push_back(temp_vec_rel[0]->GetID() );
185  for( unsigned int i = 1, I = temp_vec_rel.size(); i < I; ++i ) {
186  bool knownID = false;
187  for( unsigned int j = 0, J = temp_vec_IDs.size(); j < J; ++j ) {
188  if( temp_vec_rel[i]->GetID() == temp_vec_IDs[j] ) { knownID = true; break; }
189  }
190  if( !knownID ) temp_vec_IDs.push_back( temp_vec_rel[i]->GetID() );
191  }
192  if( temp_vec_IDs.size() != 1 ) isAsymTrig = true;
193 
194  /* this is for symmetric dilepton triggers */
195  if( !isAsymTrig ) {
196  for (unsigned int i = 0, I = temp_vec_rel.size(); i < I; ++i ) {
197  vector<int> coord = temp_vec_rel[i]->GetCoords();
198  double weight_uncert = sqrt(temp_vec_rel[i]->GetVariance());
199  double weight_derivative = 0.;
200  for (unsigned int j = 0; j < I; ++j ) {
201  if (j == i) continue;
202  double weight_derivative_temp = temp_vec_rel[j]->GetExpectancy();
203  for (unsigned int k = 0; k < I; ++k ) {
204  if( k == j || k == i ) continue;
205  weight_derivative_temp *= (1.0 - temp_vec_rel[k]->GetExpectancy());
206  }
207  weight_derivative += weight_derivative_temp;
208  }
209  weight_uncert *= weight_derivative;
210  m_linear_uncert[temp_vec_rel[i]->GetID()]->SetBinContent(&coord.front(), m_linear_uncert[temp_vec_rel[i]->GetID()]->GetBinContent(&coord.front())+weight_uncert);
211  m_variance_nocorr += weight_uncert*weight_uncert;
212  }
213  }
214 
215  /* this is for asymmetric triggers */
216  else {
217  /* at first the first leg of the trigger */
218  for( unsigned int k = 0, K = temp_vec_rel.size(); k < K; k += 4 ) {
219  vector<int> coord = temp_vec_rel[k]->GetCoords();
220  double variance_k = 0.;
221  double variance_temp = 1.;
222  for( unsigned int i = 0, I = temp_vec_rel.size(); i < I; i += 4 ) {
223  if( i == k ) continue;
224  variance_temp *= (1. - temp_vec_rel[i]->GetExpectancy());
225  }
226  variance_k += variance_temp;
227  variance_temp = -1.;
228  for( unsigned int i = 0, I = temp_vec_rel.size(); i < I; i += 4 ) {
229  variance_temp *= (1.0 - temp_vec_rel[i+2]->GetExpectancy());
230  if( i == k ) continue;
231  variance_temp *= (1.0 - temp_vec_rel[i]->GetExpectancy());
232  }
233  variance_k += variance_temp;
234  variance_temp = -temp_vec_rel[k+3]->GetExpectancy();
235  for( unsigned int i = 0, I = temp_vec_rel.size(); i < I; i += 4 ) {
236  if( i == k ) continue;
237  variance_temp *= (1.0 - temp_vec_rel[i]->GetExpectancy())*(1.0 - temp_vec_rel[i+2]->GetExpectancy());
238  }
239  variance_k += variance_temp;
240  variance_temp = 0.;
241  for( unsigned int j = 0, J = temp_vec_rel.size(); j < J; j+= 4 ) {
242  if( j == k ) continue;
243  double variance_ijk_temp = temp_vec_rel[j]->GetExpectancy()*temp_vec_rel[j+3]->GetExpectancy();
244  for( unsigned int i = 0, I = temp_vec_rel.size(); i < I; i += 4 ) {
245  if( i == j ) continue;
246  variance_ijk_temp *= (1.0 - temp_vec_rel[i+2]->GetExpectancy());
247  if( i == k ) continue;
248  variance_ijk_temp *= (1.0 - temp_vec_rel[i]->GetExpectancy());
249  }
250  variance_temp += variance_ijk_temp;
251  }
252  variance_k += variance_temp;
253  variance_k *= variance_k*temp_vec_rel[k]->GetVariance();
254  m_linear_uncert[temp_vec_rel[k]->GetID()]->SetBinContent(&coord.front(), m_linear_uncert[temp_vec_rel[k]->GetID()]->GetBinContent(&coord.front())+sqrt(variance_k));
255  m_variance_nocorr += variance_k;
256  }
257 
258  /* second leg */
259  for( unsigned int k = 0, K = temp_vec_rel.size(); k < K; k += 4 ) {
260  vector<int> coord = temp_vec_rel[k+1]->GetCoords();
261  double variance_temp = 1.;
262  for( unsigned int i = 0, I = temp_vec_rel.size(); i < I; i += 4 ) {
263  if( i == k ) continue;
264  variance_temp *= (1. - temp_vec_rel[i+1]->GetExpectancy());
265  }
266  variance_temp *= variance_temp*temp_vec_rel[k+1]->GetVariance();
267  m_linear_uncert[temp_vec_rel[k+1]->GetID()]->SetBinContent(&coord.front(), m_linear_uncert[temp_vec_rel[k+1]->GetID()]->GetBinContent(&coord.front())+sqrt(variance_temp));
268  m_variance_nocorr += variance_temp;
269  }
270 
271  /* second leg | condition leg 1 failed */
272  for( unsigned int k = 0, K = temp_vec_rel.size(); k < K; k += 4 ) {
273  vector<int> coord = temp_vec_rel[k+2]->GetCoords();
274  double variance_k = 0.;
275  double variance_temp = 1.;
276  for( unsigned int i = 0, I = temp_vec_rel.size(); i < I; i += 4 ) {
277  variance_temp *= (1. - temp_vec_rel[i]->GetExpectancy());
278  if( i == k ) continue;
279  variance_temp *= (1. - temp_vec_rel[i+2]->GetExpectancy());
280  }
281  variance_k += variance_temp;
282  variance_temp = 0.;
283  for( unsigned int j = 0, J = temp_vec_rel.size(); j < J; j+= 4 ) {
284  double variance_ijk_temp = temp_vec_rel[j]->GetExpectancy()*temp_vec_rel[j+3]->GetExpectancy();
285  for( unsigned int i = 0, I = temp_vec_rel.size(); i < I; i += 4 ) {
286  if( j == i ) continue;
287  variance_ijk_temp *= (1.0 - temp_vec_rel[i]->GetExpectancy());
288  if( i == k ) continue;
289  variance_ijk_temp *= (1.0 - temp_vec_rel[i+2]->GetExpectancy());
290  }
291  variance_temp += variance_ijk_temp;
292  }
293  variance_k += variance_temp;
294  variance_k *= variance_k*temp_vec_rel[k+2]->GetVariance();
295  m_linear_uncert[temp_vec_rel[k+2]->GetID()]->SetBinContent(&coord.front(), m_linear_uncert[temp_vec_rel[k+2]->GetID()]->GetBinContent(&coord.front())+sqrt(variance_k));
296  m_variance_nocorr += variance_k;
297  }
298 
299  /* second leg | condition leg 1 passed */
300  for( unsigned int k = 0, K = temp_vec_rel.size(); k < K; k += 4 ) {
301  vector<int> coord = temp_vec_rel[k+3]->GetCoords();
302  double variance_k = - temp_vec_rel[k]->GetExpectancy();
303  for( unsigned int i = 0, I = temp_vec_rel.size(); i < I; i += 4 ) {
304  if( i == k ) continue;
305  variance_k *= (1.0 - temp_vec_rel[i]->GetExpectancy())*(1.0 - temp_vec_rel[i+3]->GetExpectancy());
306  }
307  variance_k *= variance_k*temp_vec_rel[k+3]->GetVariance();
308  m_linear_uncert[temp_vec_rel[k+3]->GetID()]->SetBinContent(&coord.front(), m_linear_uncert[temp_vec_rel[k+3]->GetID()]->GetBinContent(&coord.front())+sqrt(variance_k));
309  m_variance_nocorr += variance_k;
310  }
311  }
312 
313  }
314 
315  /* these are the weights for ANDed triggers. Shouldn't be used but for examples. This will treat everything as ANDed. */
316  else if (evt_weight->GetType() == APEvtWeight::kANDed ) {
317  for (unsigned int iAll = 0, IAll = temp_vec_all.size(); iAll < IAll; ++iAll ) {
318  for (unsigned int i = 0, I = temp_vec_all[iAll].size(); i < I; ++i ) {
319  vector<int> coord = temp_vec_all[iAll][i]->GetCoords();
320  double weight_uncert = sqrt(temp_vec_all[iAll][i]->GetVariance());
321  weight_uncert *= (temp_vec_all[iAll][i]->GetExpectancy() <= numeric_limits<double>::epsilon() ) ? 0. : evt_weight->GetWeight()/temp_vec_all[iAll][i]->GetExpectancy();
322  m_linear_uncert[temp_vec_all[iAll][i]->GetID()]->SetBinContent(&coord.front(), m_linear_uncert[temp_vec_all[iAll][i]->GetID()]->GetBinContent(&coord.front())+weight_uncert);
323  m_variance_nocorr += weight_uncert*weight_uncert;
324  }
325  }
326  }
327 
328  /* these are weights for ORed triggers, for instance dimuon OR single muon */
329  /* treat everything as ORed: calculate weight for each type, then combine weights */
330  /* objects of same type are ORed: kMuon, kTau, kElectron, kJet, kMuonMO, kTauMO, kElectronMO, kJetMo */
331  /* objects of different type are handled differently */
332  /* if type is kMOANDed, everything is ANDed.*/
333  /* if type is kMOORed, kMuonMO, kTauMO, kElectronMO, kJetMO are ANDed; all others are ORed with each other! */
334  else if (evt_weight->GetType() >= APEvtWeight::kORed ) {
335 
336  vector<double> temp_weight_rel(12,1.);
337 
338  /* calculate single object trigger weights: OR of all objects of same type: kMuon, kTau, kElectron, kJet, kMuonMO, kTauMO, kElectronMO, kJetMO */
339  for (unsigned int j = 0; j < 8; ++j) {
340  for (unsigned int i = 0, I = temp_vec_all[j].size(); i < I; ++i ) temp_weight_rel[j] *= (1.0 - temp_vec_all[j][i]->GetExpectancy());
341  // for triggers intended to be used in ORing, set weight to 1. if there is no object and an AND is require: (if no object is added, assume none is required)
342  if( j < 4 ) temp_weight_rel[j] = (temp_vec_all[j].size() > 0 || evt_weight->GetType() == APEvtWeight::kORed || evt_weight->GetType() == APEvtWeight::kMOORed) ? (1.0 - temp_weight_rel[j]) : 1.;
343  // for triggers inteded to be used in ANDing, set weight to 1. if there is no object added (if none is added assume none is required)
344  else temp_weight_rel[j] = (temp_vec_all[j].size() > 0) ? (1.0 - temp_weight_rel[j]) : 1.;
345  }
346 
347 
348  /* calculate diobject trigger weights: OR of all objects of same type but require at least 2: kDiMuon, kDiTau, kDiElectron, kDiJet */
349  for (unsigned int j = 8; j < 12; ++j) {
350  if( temp_vec_all[j].size() >= 2 ) {
351  for (unsigned int i = 0, I = temp_vec_all[j].size(); i < I; ++i) temp_weight_rel[j] *= (1.0 - temp_vec_all[j][i]->GetExpectancy());
352  for (unsigned int i = 0, I = temp_vec_all[j].size(); i < I; ++i) {
353  double temp_weight = temp_vec_all[j][i]->GetExpectancy();
354  for (unsigned int k = 0; k < I; ++k ) {
355  if( k == i ) continue;
356  temp_weight *= (1.0 - temp_vec_all[j][k]->GetExpectancy());
357  }
358  temp_weight_rel[j] += temp_weight;
359  }
360  }
361  temp_weight_rel[j] = (temp_vec_all[j].size() > 0 || evt_weight->GetType() == APEvtWeight::kORed || evt_weight->GetType() == APEvtWeight::kMOORed) ? (1.0 - temp_weight_rel[j]) : 1.;
362  }
363 
364  /* calculat weight for multiobject trigger (AND of all MO objects) */
365  double temp_weight_MO = 1.;
366  int n_noObject_MO = 0;
367  for (unsigned int l = 4; l < 8; ++l ) {
368  temp_weight_MO *= temp_weight_rel[l];
369  if( temp_vec_all[l].size() == 0 ) n_noObject_MO += 1;
370  }
371  if( /*(evt_weight->GetType() == APEvtWeight::kORed || evt_weight->GetType() == APEvtWeight::kMOORed) &&*/ n_noObject_MO >= 2 ) temp_weight_MO = 0.;
372 
373  /* all partial weights calculated; now calculate uncertainties */
374  /* single object triggers */
375  for (unsigned int j = 0; j < 8; ++j) {
376  for (unsigned int i = 0, I = temp_vec_all[j].size(); i < I; ++i ) {
377  vector<int> coord = temp_vec_all[j][i]->GetCoords();
378  double weight_uncert = sqrt(temp_vec_all[j][i]->GetVariance());
379  for (unsigned int k = 0; k < I; ++k ) {
380  if( k == i ) continue;
381  weight_uncert *= (1.0 - temp_vec_all[j][k]->GetExpectancy());
382  }
383  for( unsigned int l = 0; l < 4; ++l ) {
384  if( l == j ) continue;
385  if( evt_weight->GetType() == APEvtWeight::kMOANDed ) weight_uncert *= temp_weight_rel[l];
386  else if( evt_weight->GetType() == APEvtWeight::kORed || evt_weight->GetType() == APEvtWeight::kMOORed ) weight_uncert *= (1.0 - temp_weight_rel[l]);
387  else cout << "WARNING: handling for this weight type is unknown! uncertainties will be incorrect" << endl;
388  }
389  for( unsigned int l = 8; l < 12; ++l ) {
390  if( l == j ) continue;
391  if( evt_weight->GetType() == APEvtWeight::kMOANDed ) weight_uncert *= temp_weight_rel[l];
392  else if( evt_weight->GetType() == APEvtWeight::kORed || evt_weight->GetType() == APEvtWeight::kMOORed ) weight_uncert *= (1.0 - temp_weight_rel[l]);
393  else cout << "WARNING: handling for this weight type is unknown! uncertainties will be incorrect" << endl;
394  }
395 
396  if( j < 4 || j > 7 ) {
397  if( evt_weight->GetType() == APEvtWeight::kMOANDed ) weight_uncert *= temp_weight_MO;
398  else if( evt_weight->GetType() == APEvtWeight::kORed || evt_weight->GetType() == APEvtWeight::kMOORed ) weight_uncert *= (1.0 - temp_weight_MO);
399  else cout << "WARNING: handling for this weight type is unknown! uncertainties will be incorrect" << endl;
400  }
401  else if( j >= 4 && j <= 7 && temp_weight_rel[j] > numeric_limits<double>::epsilon() ) weight_uncert = weight_uncert*temp_weight_MO/temp_weight_rel[j];
402  m_linear_uncert[temp_vec_all[j][i]->GetID()]->SetBinContent(&coord.front(), m_linear_uncert[temp_vec_all[j][i]->GetID()]->GetBinContent(&coord.front())+weight_uncert);
403  m_variance_nocorr += weight_uncert*weight_uncert;
404  }
405  }
406 
407  /* diobject triggers */
408  for (unsigned int j = 8; j < 12; ++j) {
409  if( temp_vec_all[j].size() >= 2 ) {
410  for (unsigned int i = 0, I = temp_vec_all[j].size(); i < I; ++i ) {
411  vector<int> coord = temp_vec_all[j][i]->GetCoords();
412  double weight_uncert = sqrt(temp_vec_all[j][i]->GetVariance());
413  double weight_derivative = 0.;
414  for (unsigned int k = 0; k < I; ++k ) {
415  if( k == i ) continue;
416  double weight_derivative_temp = temp_vec_all[j][k]->GetExpectancy();
417  for (unsigned int l = 0; l < I; ++l ) {
418  if( l == k || l == i ) continue;
419  weight_derivative_temp *= (1.0 - temp_vec_all[j][l]->GetExpectancy());
420  }
421  weight_derivative += weight_derivative_temp;
422  }
423  weight_uncert *= weight_derivative;
424  for( unsigned int l = 0; l < 4; ++l ) {
425  if( l == j ) continue;
426  if( evt_weight->GetType() == APEvtWeight::kMOANDed ) weight_uncert *= temp_weight_rel[l];
427  else if( evt_weight->GetType() == APEvtWeight::kORed || evt_weight->GetType() == APEvtWeight::kMOORed ) weight_uncert *= (1.0 - temp_weight_rel[l]);
428  else cout << "WARNING: handling for this weight type is unknown! uncertainties will be incorrect" << endl;
429  }
430  for( unsigned int l = 8; l < 12; ++l ) {
431  if( l == j ) continue;
432  if( evt_weight->GetType() == APEvtWeight::kMOANDed ) weight_uncert *= temp_weight_rel[l];
433  else if( evt_weight->GetType() == APEvtWeight::kORed || evt_weight->GetType() == APEvtWeight::kMOORed ) weight_uncert *= (1.0 - temp_weight_rel[l]);
434  else cout << "WARNING: handling for this weight type is unknown! uncertainties will be incorrect" << endl;
435  }
436  if( evt_weight->GetType() == APEvtWeight::kMOANDed ) weight_uncert *= temp_weight_MO;
437  else if( evt_weight->GetType() == APEvtWeight::kORed || evt_weight->GetType() == APEvtWeight::kMOORed ) weight_uncert *= (1.0 - temp_weight_MO);
438  else cout << "WARNING: handling for this weight type is unknown! uncertainties will be incorrect" << endl;
439 
440  if( j >= 4 && j <= 7 && temp_weight_rel[j] > numeric_limits<double>::epsilon() ) weight_uncert /= temp_weight_rel[j];
441 
442  m_linear_uncert[temp_vec_all[j][i]->GetID()]->SetBinContent(&coord.front(), m_linear_uncert[temp_vec_all[j][i]->GetID()]->GetBinContent(&coord.front())+weight_uncert);
443  m_variance_nocorr += weight_uncert*weight_uncert;
444  }
445  }
446  }
447  }
448 
449  m_variance_sys += ext_weight * evt_weight->GetSysVariance();
450 
451  m_isComputed = false;
452 }

◆ AddWeightToEvt()

void APWeightSum::AddWeightToEvt ( APWeightEntry weight)

Adds a weight to the sum of weights.

Definition at line 35 of file APWeightSum.cxx.

35  {
36  m_current_evt_weights.push_back(weight);
37 }

◆ FinishEvt()

void APWeightSum::FinishEvt ( double  ext_weight = 1.0)

Finishes the current event and calculates the event weight.

Takes an optional external weight factor (e.g. mc weight).

Definition at line 78 of file APWeightSum.cxx.

78  {
79  ++m_k_evt_orig;
80  double evt_weight = 1.0;
81  double uncert = 0.0;
82  double uncert_sys = 0.0;
83  for (unsigned int i = 0, I = m_current_evt_weights.size(); i < I; ++i) {
84  double uncert_summand = 1.0;
85  evt_weight *= (1. - m_current_evt_weights[i]->GetExpectancy());
86  for (unsigned int k = 0; k < I; ++k) {
87  if (i != k) uncert_summand *= (1. - m_current_evt_weights[i]->GetExpectancy());
88  }
89  uncert += (uncert_summand * uncert_summand * m_current_evt_weights[i]->GetVariance());
90  uncert_sys += (uncert_summand * uncert_summand * m_current_evt_weights[i]->GetSysUncert2());
91  }
92  m_k_evt_weight += ext_weight * (1. - evt_weight);
94  m_k_evt_weight_external += ext_weight;
95  m_variance += fabs(ext_weight) * uncert;
96  m_variance_sys += ext_weight * uncert_sys;
97  m_current_evt_weights.clear();
98 }

◆ GetAllUncertHistograms()

const vector< THnSparse * > & APWeightSum::GetAllUncertHistograms ( )

Returns vector of THnSparses holding the uncertainties for all APReweight IDs.

Definition at line 480 of file APWeightSum.cxx.

480  {
481  return m_linear_uncert;
482 }

◆ GetKUnweighted()

unsigned long APWeightSum::GetKUnweighted ( ) const

Returns the unweighted sum of entries.

Definition at line 74 of file APWeightSum.cxx.

74  {
75  return m_k_evt_orig;
76 }

◆ GetStdDev()

double APWeightSum::GetStdDev ( )

Returns the standard deviation.

Definition at line 51 of file APWeightSum.cxx.

51  {
52  if ( !m_isComputed ) Compute();
53  return sqrt(m_variance);
54 }

◆ GetSumW()

double APWeightSum::GetSumW ( ) const

Returns the sum of weights.

Definition at line 39 of file APWeightSum.cxx.

39  {
40  return m_k_evt_weight;
41 }

◆ GetSumW2()

double APWeightSum::GetSumW2 ( ) const

Returns sum of (weights^2).

Definition at line 43 of file APWeightSum.cxx.

43  {
44  return m_k_evt_weight2;
45 }

◆ GetSumWExternal()

double APWeightSum::GetSumWExternal ( ) const

Returns the sum of weights without taking into account the trigger weighting (external weights only) to allow switching trigger weighting on/off.

Definition at line 47 of file APWeightSum.cxx.

47  {
49 }

◆ GetSysUncert()

double APWeightSum::GetSysUncert ( ) const

Returns the systematic uncertainty (from systematics assigned to weights).

Definition at line 70 of file APWeightSum.cxx.

70  {
71  return sqrt(m_variance_sys);
72 }

◆ GetUncertHistogram()

THnSparse * APWeightSum::GetUncertHistogram ( APReweightBase weighter)

Returns THnSparse holding the uncertainties for given APReweightBase instance.

Definition at line 471 of file APWeightSum.cxx.

471  {
472  unsigned int temp_ID = weighter->GetID();
473  if( temp_ID > m_linear_uncert.size()-1 ) {
474  cout << "WARNING: ID unknown. Returning 0-pointer!" << endl;
475  return 0;
476  }
477  else return m_linear_uncert[temp_ID];
478 }

◆ GetVariance()

double APWeightSum::GetVariance ( )

Returns the variance.

Definition at line 56 of file APWeightSum.cxx.

56  {
57  if ( !m_isComputed ) Compute();
58  return m_variance;
59 }

◆ GetVarianceFullCorr()

double APWeightSum::GetVarianceFullCorr ( )

Returns the variance, assuming full correlation amongst objects.

Definition at line 65 of file APWeightSum.cxx.

65  {
66  if ( !m_isComputed ) Compute();
67  return m_variance_fullcorr;
68 }

◆ GetVarianceNoCorr()

double APWeightSum::GetVarianceNoCorr ( )

Returns the variance, assuming no correlations.

Definition at line 61 of file APWeightSum.cxx.

61  {
62  return m_variance_nocorr;
63 }

Member Data Documentation

◆ m_current_evt_weights

ClassDef (APWeightSum,1) protected std::vector< APWeightEntry* > APWeightSum::m_current_evt_weights

< Calculates the final uncertainties including correlations.

Holds the expectancy values of the weights in the current event.

Definition at line 57 of file APWeightSum.h.

◆ m_isComputed

bool APWeightSum::m_isComputed

Definition at line 67 of file APWeightSum.h.

◆ m_k_evt_orig

unsigned long int APWeightSum::m_k_evt_orig

Holds the original amount of unweighted counts ("sum of 1's").

Definition at line 59 of file APWeightSum.h.

◆ m_k_evt_weight

double APWeightSum::m_k_evt_weight

Holds the sum of weights.

Definition at line 60 of file APWeightSum.h.

◆ m_k_evt_weight2

double APWeightSum::m_k_evt_weight2

Holds the sum of squared weights.

Definition at line 61 of file APWeightSum.h.

◆ m_k_evt_weight_external

double APWeightSum::m_k_evt_weight_external

Holds the sum of external weights (no trigger weighting).

Definition at line 62 of file APWeightSum.h.

◆ m_linear_uncert

std::vector< THnSparse* > APWeightSum::m_linear_uncert

Holds all histograms for uncertainties.

Definition at line 58 of file APWeightSum.h.

◆ m_variance

double APWeightSum::m_variance

Holds the variance.

Definition at line 63 of file APWeightSum.h.

◆ m_variance_fullcorr

double APWeightSum::m_variance_fullcorr

Holds the variance, assuming full correlation amongst objects.

Definition at line 65 of file APWeightSum.h.

◆ m_variance_nocorr

double APWeightSum::m_variance_nocorr

Holds the variance, assuming no correlations.

Definition at line 64 of file APWeightSum.h.

◆ m_variance_sys

double APWeightSum::m_variance_sys

Holds the systematic variance (from systematics assigned to weights).

Definition at line 66 of file APWeightSum.h.


The documentation for this class was generated from the following files:
APWeightSum::m_linear_uncert
std::vector< THnSparse * > m_linear_uncert
Holds all histograms for uncertainties.
Definition: APWeightSum.h:58
APEvtWeight::GetWeightObjects
std::vector< APWeightEntry * > GetWeightObjects(ObjType type)
Returns the vector of weight objects for a specific object type.
Definition: APEvtWeight.cxx:251
ID
std::vector< Identifier > ID
Definition: CalibHitIDCheck.h:24
APEvtWeight::kMuonMO
@ kMuonMO
Definition: APEvtWeight.h:29
APWeightSum::m_k_evt_orig
unsigned long int m_k_evt_orig
Holds the original amount of unweighted counts ("sum of 1's").
Definition: APWeightSum.h:59
APEvtWeight::GetType
ObjType GetType()
Returns the type of the event weight (muon, electron, jet, ANDed, ORed).
Definition: APEvtWeight.cxx:263
APEvtWeight::kDiElectron
@ kDiElectron
Definition: APEvtWeight.h:29
skel.it
it
Definition: skel.GENtoEVGEN.py:396
APEvtWeight::kElectron
@ kElectron
Definition: APEvtWeight.h:29
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
APWeightSum::m_variance_fullcorr
double m_variance_fullcorr
Holds the variance, assuming full correlation amongst objects.
Definition: APWeightSum.h:65
APEvtWeight::kANDed
@ kANDed
Definition: APEvtWeight.h:29
APEvtWeight::kDiMuon
@ kDiMuon
Definition: APEvtWeight.h:29
APWeightSum::m_k_evt_weight
double m_k_evt_weight
Holds the sum of weights.
Definition: APWeightSum.h:60
APEvtWeight::kMuon
@ kMuon
Definition: APEvtWeight.h:29
APEvtWeight::kDiJet
@ kDiJet
Definition: APEvtWeight.h:29
APEvtWeight::kTauMO
@ kTauMO
Definition: APEvtWeight.h:29
APEvtWeight::kElectronMO
@ kElectronMO
Definition: APEvtWeight.h:29
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
lumiFormat.i
int i
Definition: lumiFormat.py:85
xmin
double xmin
Definition: listroot.cxx:60
APEvtWeight::kJetMO
@ kJetMO
Definition: APEvtWeight.h:29
APEvtWeight::kORed
@ kORed
Definition: APEvtWeight.h:29
APEvtWeight::GetWeight
double GetWeight()
Returns the event weight.
Definition: APEvtWeight.cxx:223
APEvtWeight::GetSysVariance
double GetSysVariance()
Returns the systematic variance (from systematics assigned to weights).
Definition: APEvtWeight.cxx:246
APEvtWeight::kJet
@ kJet
Definition: APEvtWeight.h:29
APEvtWeight::kMOANDed
@ kMOANDed
Definition: APEvtWeight.h:29
plotting.yearwise_luminosity_vs_mu.bins
bins
Definition: yearwise_luminosity_vs_mu.py:30
APWeightSum::m_variance
double m_variance
Holds the variance.
Definition: APWeightSum.h:63
APWeightSum::GetVariance
double GetVariance()
Returns the variance.
Definition: APWeightSum.cxx:56
APReweightBase::GetID
unsigned int GetID() const
Returns the unique ID for assignment of APWeightEntries to source.
Definition: APReweightBase.cxx:23
APWeightSum::m_variance_sys
double m_variance_sys
Holds the systematic variance (from systematics assigned to weights).
Definition: APWeightSum.h:66
APWeightSum::m_current_evt_weights
ClassDef(APWeightSum, 1) protected std::vector< APWeightEntry * > m_current_evt_weights
< Calculates the final uncertainties including correlations.
Definition: APWeightSum.h:52
PixelConvert::GetID
unsigned int GetID(const Map &map, const unsigned int moduleID)
Definition: PixelConvert.cxx:433
JetVoronoiDiagramHelpers::coord
double coord
Definition: JetVoronoiDiagramHelpers.h:45
APWeightSum::m_k_evt_weight2
double m_k_evt_weight2
Holds the sum of squared weights.
Definition: APWeightSum.h:61
APEvtWeight::kMOORed
@ kMOORed
Definition: APEvtWeight.h:29
APWeightSum::m_isComputed
bool m_isComputed
Definition: APWeightSum.h:67
APWeightSum::m_variance_nocorr
double m_variance_nocorr
Holds the variance, assuming no correlations.
Definition: APWeightSum.h:64
xmax
double xmax
Definition: listroot.cxx:61
I
#define I(x, y, z)
Definition: MD5.cxx:116
APWeightSum::m_k_evt_weight_external
double m_k_evt_weight_external
Holds the sum of external weights (no trigger weighting).
Definition: APWeightSum.h:62
APEvtWeight::kDiTau
@ kDiTau
Definition: APEvtWeight.h:29
APEvtWeight::kTau
@ kTau
Definition: APEvtWeight.h:29
fitman.k
k
Definition: fitman.py:528