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

◆ 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 472 of file APWeightSum.cxx.

472  {
473  return m_linear_uncert;
474 }

◆ 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 463 of file APWeightSum.cxx.

463  {
464  unsigned int temp_ID = weighter->GetID();
465  if( temp_ID > m_linear_uncert.size()-1 ) {
466  cout << "WARNING: ID unknown. Returning 0-pointer!" << endl;
467  return 0;
468  }
469  else return m_linear_uncert[temp_ID];
470 }

◆ 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
CaloClusterMLCalib::epsilon
constexpr float epsilon
Definition: CaloClusterMLGaussianMixture.h:16
skel.it
it
Definition: skel.GENtoEVGEN.py:407
APEvtWeight::kElectron
@ kElectron
Definition: APEvtWeight.h:29
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:157
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:190
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