ATLAS Offline Software
APWeightSumEnsemble.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #define APWeightSumEnsemble_cxx
7 #include <cmath>
8 #include <iostream>
9 #include "TH1F.h"
10 #include "TVirtualFitter.h"
12 
14  m_k_evt_orig = 0;
15  m_ensembleTest_done = false;
16  m_pdf = 0;
17  m_ensemble_mode = 0.;
18  m_ensemble_sigma = 0.;
19  m_rel_prec = 0.01;
20 }
21 
23  delete m_pdf;
24 }
25 
26 void APWeightSumEnsemble::SetRelPrecision(double rel_prec) {
27  m_rel_prec = rel_prec;
28  m_ensembleTest_done = false;
29 }
30 
33  m_current_evt_pdfs.push_back(weight);
34  m_ensembleTest_done = false;
35 }
36 
37 double APWeightSumEnsemble::GetQuantile(const double prob) {
38  if (!m_ensembleTest_done) Compute();
39  double prob_in[1] = {prob};
40  double quant[1];
41  m_pdf->GetQuantiles(1, quant, prob_in);
42  return quant[0];
43 }
44 
46  if (!m_ensembleTest_done) Compute();
47  return m_pdf->GetRandom();
48 }
49 
51  if (!m_ensembleTest_done) Compute();
52  return m_ensemble_mode;
53 }
54 
56  if (!m_ensembleTest_done) Compute();
57  return m_ensemble_sigma;
58 }
59 
61  if (!m_ensembleTest_done) Compute();
62  return m_pdf;
63 }
64 
65 void APWeightSumEnsemble::FinishEvt(double ext_weight) {
66  APWeightSum::FinishEvt(ext_weight);
68  m_ext_weights.push_back(ext_weight);
69  m_current_evt_pdfs.clear();
70 }
71 
72 void APWeightSumEnsemble::Compute() {
73  if ( m_current_evt_pdfs.size() > 0 ) std::cout << "ERROR in APWeightSumEnsemble::Compute: Last event was not finished and will not be taken into account for the calculation!" << std::endl;
74  //Improve estimation of range
75  if (m_pdf != 0) delete m_pdf;
76  m_pdf = new TH1F("", "", 1000, m_k_evt_weight - 6. * sqrt(m_k_evt_weight), m_k_evt_weight + 6. * sqrt(m_k_evt_weight));
77 
78  for (unsigned int i = 0; i < 100000000; ++i) { //variable n_iter
79  double sum_weights = 0.0;
80  for (unsigned int j = 0; j < m_k_evt_orig; ++j) {
81  double weight = 1.0;
82  for (unsigned int l = 0, L = m_weight_vector[j].size(); l < L; ++l) {
83  weight *= (1. - (m_weight_vector[j][l])->GetRandom());
84  }
85  sum_weights += m_ext_weights[j] * (1. - weight);
86  }
87  m_pdf->Fill(sum_weights);
88  if (i % 100 == 0) {
89  m_pdf->Fit("gaus", "0Q");
90  TVirtualFitter *fitter = TVirtualFitter::GetFitter();
91  if ( fitter->GetParError(2) / fitter->GetParameter(2) < m_rel_prec ) break;
92  }
93  }
94 
95  m_pdf->Fit("gaus", "0Q");
96  TVirtualFitter *fitter = TVirtualFitter::GetFitter();
97  m_ensemble_mode = fitter->GetParameter(1);
98  m_ensemble_sigma = fitter->GetParameter(2);
99  m_ensembleTest_done = true;
100 }
LArSamples::FitterData::fitter
const ShapeFitter * fitter
Definition: ShapeFitter.cxx:23
APWeightSumEnsemble::GetQuantile
double GetQuantile(const double prob)
Returns the quantlile for p=prob for the distribution.
Definition: APWeightSumEnsemble.cxx:37
APWeightEntry
Definition: APWeightEntry.h:25
APWeightSum::FinishEvt
void FinishEvt(double ext_weight=1.0)
Finishes the current event and calculates the event weight.
Definition: APWeightSum.cxx:78
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
APWeightSumEnsemble::GetPDF
TH1F * GetPDF()
Returns the calculated PDF.
Definition: APWeightSumEnsemble.cxx:60
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
APWeightSumEnsemble::m_rel_prec
double m_rel_prec
Holds the relative precision of the gaussian fit to stop the ensemble test at.
Definition: APWeightSumEnsemble.h:52
APWeightSum::m_k_evt_weight
double m_k_evt_weight
Holds the sum of weights.
Definition: APWeightSum.h:60
covarianceTool.prob
prob
Definition: covarianceTool.py:678
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:200
APWeightSumEnsemble::m_ensemble_sigma
double m_ensemble_sigma
Holds the standard deviation from ensemble test.
Definition: APWeightSumEnsemble.h:55
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
APWeightSumEnsemble.h
lumiFormat.i
int i
Definition: lumiFormat.py:92
APWeightSumEnsemble::SetRelPrecision
void SetRelPrecision(double rel_prec)
Sets the relative precision of the gaussian fit to stop the ensemble test at.
Definition: APWeightSumEnsemble.cxx:26
APWeightSumEnsemble::m_ensembleTest_done
bool m_ensembleTest_done
Flag if the ensemble test has been performed with the current set of weights.
Definition: APWeightSumEnsemble.h:56
APWeightSumEnsemble::GetRandom
double GetRandom()
Returns a random value according to the pdf.
Definition: APWeightSumEnsemble.cxx:45
APWeightSumEnsemble::m_current_evt_pdfs
std::vector< APWeightEntry * > m_current_evt_pdfs
Holds the weight objects for the current event.
Definition: APWeightSumEnsemble.h:50
APWeightSumEnsemble::APWeightSumEnsemble
APWeightSumEnsemble()
Default constructor.
Definition: APWeightSumEnsemble.cxx:13
APWeightSumEnsemble::GetEnsemblePDFMode
double GetEnsemblePDFMode()
Returns the Mode (= sum of weights from PDF).
Definition: APWeightSumEnsemble.cxx:50
APWeightEntry.h
TH1F
Definition: rootspy.cxx:320
APWeightSumEnsemble::AddWeightToEvt
void AddWeightToEvt(APWeightEntry *weight)
Adds a weight to the sum of weights.
Definition: APWeightSumEnsemble.cxx:31
APWeightSumEnsemble::m_ext_weights
std::vector< double > m_ext_weights
Holds the external event weight provided when finishing the respective events.
Definition: APWeightSumEnsemble.h:51
APWeightSumEnsemble::~APWeightSumEnsemble
virtual ~APWeightSumEnsemble()
Default destructor.
Definition: APWeightSumEnsemble.cxx:22
APWeightSumEnsemble::m_pdf
TH1F * m_pdf
Holds the TH1F instance from the arrays if computed.
Definition: APWeightSumEnsemble.h:53
APWeightSumEnsemble::GetEnsemblePDFStdDev
double GetEnsemblePDFStdDev()
Returns the standard deviation from PDF .
Definition: APWeightSumEnsemble.cxx:55
APWeightSum::AddWeightToEvt
void AddWeightToEvt(APWeightEntry *weight)
Adds a weight to the sum of weights.
Definition: APWeightSum.cxx:35
python.TrigEgammaMonitorHelper.TH1F
def TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:24
APWeightSumEnsemble::FinishEvt
void FinishEvt(double ext_weight=1.0)
Finishes the current event and calculates the event weight.
Definition: APWeightSumEnsemble.cxx:65
APWeightSumEnsemble::m_ensemble_mode
double m_ensemble_mode
Holds the Mode (= sum of weights from PDF) from ensemble test.
Definition: APWeightSumEnsemble.h:54
APWeightSumEnsemble::m_weight_vector
ClassDef(APWeightSumEnsemble, 1) private std::vector< std::vector< APWeightEntry * > > m_weight_vector
< Performs the ensemble test to model final PDF.
Definition: APWeightSumEnsemble.h:45