ATLAS Offline Software
Loading...
Searching...
No Matches
LhoodMM_tools.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef Lhood_MM_tools_h
6#define Lhood_MM_tools_h
7
8#include "TMatrixT.h"
11
12#include <vector>
13#include <mutex>
14#include <memory>
15#include <map>
16
17class TH1;
18class TH2;
19class TH3;
20class TMinuit_LHMM;
21class TDirectory;
22class LhoodMMEvent;
23
24namespace CP
25{
26
28{
29
31
32 protected:
33
34 virtual void reset();
35
36 // implement base class methods
37 virtual StatusCode addEventCustom() override;
38
39 public:
40
41 LhoodMM_tools(const std::string& name);
43
44 virtual StatusCode initialize() override;
45
46 // implement base class methods
47
48 virtual StatusCode getTotalYield(float& yield, float& statErrUp, float& statErrDown) override final;
49 virtual StatusCode register1DHistogram(TH1* h1, const float *val) override;
50 virtual StatusCode register2DHistogram(TH2* h2, const float *xval, const float *yval) override;
51 virtual StatusCode register3DHistogram(TH3* h3, const float *xval, const float *yval, const float *zval) override;
52
53 double nfakes(Double_t *poserr, Double_t *negerr);
54
55 double nfakes_std(double *error);
56 double nfakes_std_perEventWeight(double *error);
57
58 StatusCode setFitType(const std::string& ft);
59
60 Int_t getFitStatus() {return m_fitStatus;}
61
62 void setPrintLevel(Int_t printLevel) { m_printLevel = printLevel;}
63
65
66 virtual StatusCode saveProgress(TDirectory* dir) override;
67
68 StatusCode mergeSubJobs();
69
70 bool perfectFit() { return m_perfectFit;}
71 protected:
73 virtual FakeBkgTools::Client clientForDB() override final;
74
75 private:
76
77 // pointer to instance of LhoodMM_tools to use in a given fit
79 static std::mutex s_mutex; // to prevent concurrent access to minuit / fit function
80
82 bool m_prevSave{};
84
86
87 #ifndef __CLING__
88 std::vector<std::unique_ptr<FakeBkgTools::FinalState> > m_fsvec;
89 #else
90 std::vector<int> m_fsvec;
91 #endif
93 int m_minnlep{}, m_maxnlep{}, m_maxnlep_loose{};
95 std::vector<std::vector<int>> m_real_indices, m_fake_indices;
96 bool m_requireSS{}, m_requireOS{};
97
99
101
103
104 float m_maxWeight{};
105
107
108 static constexpr int s_nLepMax = 6;
109 static constexpr int s_maxRank = 64; // i.e. 2^nLepMax
110
111
112 std::vector < std::vector < std::vector < double > > > m_coeffs;
113
114 std::map<TH1*, std::vector< LhoodMMFitInfo > > m_fitInfo_1dhisto_map;
115 std::map<TH2*, std::vector< LhoodMMFitInfo > > m_fitInfo_2dhisto_map;
116 std::map<TH3*, std::vector< LhoodMMFitInfo > > m_fitInfo_3dhisto_map;
117
118 double m_dilep_SSfrac_num{}, m_dilep_SSfrac_denom{};
119 std::vector< std::vector < double > > m_OSfrac;
120
121 double m_nfakes_std{}, m_nfakes_std_err{};
122
123 double m_nfakes_std_perEventWeight{}, m_nfakes_std_err_perEventWeight{};
124
126
127 Int_t m_fitStatus{};
128
130
131 std::vector<std::shared_ptr<TMatrixT<double>> > m_nrf_mat_vec;
132 std::vector<std::shared_ptr<TMatrixT<double>> > m_MMmatrix_vec;
133 std::vector<std::shared_ptr<TMatrixT<double>>> m_ntlpred_vec;
134
135 unsigned m_lastSaveIndex{};
136
137 //mathematical constants
138 inline static const double s_piover2 = 1.57079632679489661923;
139 inline static const double s_piover4 = 0.785398163397448309616;
140
141 StatusCode setup();
142
143 static double logPoisson(double obs, double pred);
144
145 StatusCode addEventCustom(const std::vector<bool>& isTight_vals,
146 const std::vector<FakeBkgTools::Efficiency>& realEff_vals,
147 const std::vector<FakeBkgTools::Efficiency>& fakeEff_vals,
148 const std::vector<int>& charges,
149 float weight);
150
151 StatusCode incrementMatrices(const LhoodMMEvent& mmevt);
152 StatusCode incrementOneMatrixSet(LhoodMMFitInfo& fitInfo,
153 const LhoodMMEvent& mmevt);
154
155 static void fcn_nlep(Int_t &npar , Double_t *gin , Double_t &f, Double_t *par, Int_t iflag );
156 static void fcn_minnlep_maxnlep(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag);
157
158 void get_init_pars(std::vector<double> &init_pars, int nlep);
159 void get_analytic(std::vector<double>& nrf, const int nlep);
160
161 double fixPosErr(double n_fake_fit, TMinuit_LHMM* lhoodFit);
162 double fixNegErr(double n_fake_fit, TMinuit_LHMM* lhoodFit);
163 void mapLhood(TMinuit_LHMM* lhoodFit, int nlep, double min, double max);
164
165 StatusCode fillHistograms();
166 StatusCode fillHisto_internal(const std::vector< LhoodMMFitInfo >& fitInfo_vec, TH1* h);
167};
168
169}
170
171#endif
#define ASG_TOOL_CLASS(CLASSNAME, INT1)
#define min(a, b)
Definition cfImp.cxx:40
#define max(a, b)
Definition cfImp.cxx:41
Header file for AthHistogramAlgorithm.
BaseFakeBkgTool(const std::string &toolname)
Top-level interface for the tools providing an estimate of the fake lepton background All the tools,...
double fixNegErr(double n_fake_fit, TMinuit_LHMM *lhoodFit)
static void fcn_nlep(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
virtual StatusCode addEventCustom() override
double m_nfakes_std_perEventWeight
static void fcn_minnlep_maxnlep(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
std::vector< std::vector< double > > m_OSfrac
double fixPosErr(double n_fake_fit, TMinuit_LHMM *lhoodFit)
double nfakes_std(double *error)
virtual StatusCode register3DHistogram(TH3 *h3, const float *xval, const float *yval, const float *zval) override
associates a 3D histogram to the tool, to obtain a binned estimate of the fake lepton background the ...
void mapLhood(TMinuit_LHMM *lhoodFit, int nlep, double min, double max)
static std::mutex s_mutex
std::vector< std::shared_ptr< TMatrixT< double > > > m_ntlpred_vec
std::map< TH3 *, std::vector< LhoodMMFitInfo > > m_fitInfo_3dhisto_map
const LhoodMMFitInfo * m_current_fitInfo
void get_init_pars(std::vector< double > &init_pars, int nlep)
std::vector< std::vector< int > > m_fake_indices
std::vector< std::vector< int > > m_real_indices
double nfakes_std_perEventWeight(double *error)
StatusCode incrementOneMatrixSet(LhoodMMFitInfo &fitInfo, const LhoodMMEvent &mmevt)
std::map< TH1 *, std::vector< LhoodMMFitInfo > > m_fitInfo_1dhisto_map
std::map< TH2 *, std::vector< LhoodMMFitInfo > > m_fitInfo_2dhisto_map
StatusCode fillHistograms()
LhoodMM_tools(const std::string &name)
virtual StatusCode getTotalYield(float &yield, float &statErrUp, float &statErrDown) override final
returns the accumulated fake lepton background yield (or compute it, in the case of the likelihood ma...
void set_do_std_perEventWeight(bool val)
static constexpr int s_maxRank
StatusCode setFitType(const std::string &ft)
StatusCode incrementMatrices(const LhoodMMEvent &mmevt)
std::vector< std::unique_ptr< FakeBkgTools::FinalState > > m_fsvec
std::vector< std::shared_ptr< TMatrixT< double > > > m_MMmatrix_vec
static const double s_piover2
void setPrintLevel(Int_t printLevel)
void get_analytic(std::vector< double > &nrf, const int nlep)
std::vector< std::shared_ptr< TMatrixT< double > > > m_nrf_mat_vec
static const double s_piover4
static double logPoisson(double obs, double pred)
virtual StatusCode register2DHistogram(TH2 *h2, const float *xval, const float *yval) override
associates a 2D histogram to the tool, to obtain a binned estimate of the fake lepton background the ...
std::vector< std::vector< std::vector< double > > > m_coeffs
virtual void reset()
static constexpr int s_nLepMax
virtual StatusCode register1DHistogram(TH1 *h1, const float *val) override
associates a 1D histogram to the tool, to obtain a binned estimate of the fake lepton background the ...
StatusCode fillHisto_internal(const std::vector< LhoodMMFitInfo > &fitInfo_vec, TH1 *h)
static LhoodMM_tools * m_current_lhoodMM_tool
double nfakes(Double_t *poserr, Double_t *negerr)
LhoodMMFitInfo m_global_fitInfo
STL class.
bool setup(asg::AnaToolHandle< Interface > &tool, const std::string &type, const std::vector< std::string > &config, const std::string &progressFile="")
mostly useful for athena, which will otherwise re-use the previous tool
Select isolated Photons, Electrons and Muons.
STL namespace.
void ErrorHandler ATLAS_NOT_THREAD_SAFE(Int_t level, Bool_t abort, const char *location, const char *message)
Function filtering the warnings coming from ROOT.
Definition Init.cxx:105
void initialize()
#define private