ATLAS Offline Software
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 
17 class TH1;
18 class TH2;
19 class TH3;
20 class TMinuit_LHMM;
21 class TDirectory;
22 class LhoodMMEvent;
23 
24 namespace 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);
42  ~LhoodMM_tools();
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 
64  void set_do_std_perEventWeight(bool val) {m_do_std_perEventWeight = val;}
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
78  static LhoodMM_tools* m_current_lhoodMM_tool;
79  static std::mutex s_mutex; // to prevent concurrent access to minuit / fit function
80 
81  LhoodMMFitInfo m_global_fitInfo{};
82  bool m_prevSave{};
83  bool m_perfectFit{};
84 
85  const LhoodMMFitInfo *m_current_fitInfo{};
86 
87  #ifndef __CLING__
88  std::vector<std::unique_ptr<FakeBkgTools::FinalState> > m_fsvec;
89  #else
90  std::vector<int> m_fsvec;
91  #endif
92  int m_curr_nlep{};
93  int m_minnlep{}, m_maxnlep{}, m_maxnlep_loose{};
94  int m_theta_tot_start_index{};
95  std::vector<std::vector<int>> m_real_indices, m_fake_indices;
96  bool m_requireSS{}, m_requireOS{};
97 
98  bool m_needToResize{};
99 
100  bool m_doFakeFactor{};
101 
102  bool m_fixNormalization{};
103 
104  float m_maxWeight{};
105 
106  bool m_alreadyMerged{};
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 
125  bool m_do_std_perEventWeight{};
126 
127  Int_t m_fitStatus{};
128 
129  Int_t m_printLevel{};
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
CP::BaseFakeBkgTool
Definition: BaseFakeBkgTool.h:41
PlotCalibFromCool.ft
ft
Definition: PlotCalibFromCool.py:329
max
#define max(a, b)
Definition: cfImp.cxx:41
CP::LhoodMM_tools::m_real_indices
std::vector< std::vector< int > > m_real_indices
Definition: LhoodMM_tools.h:95
ATLAS_NOT_THREAD_SAFE
#define ATLAS_NOT_THREAD_SAFE
getNoisyStrip() Find noisy strips from hitmaps and write out into xml/db formats
Definition: checker_macros.h:212
BeamSpot::mutex
std::mutex mutex
Definition: InDetBeamSpotVertex.cxx:18
initialize
void initialize()
Definition: run_EoverP.cxx:894
CP::LhoodMM_tools::m_nrf_mat_vec
std::vector< std::shared_ptr< TMatrixT< double > > > m_nrf_mat_vec
Definition: LhoodMM_tools.h:131
FakeBkgTools::Client
Client
Definition: FakeBkgInternals.h:141
CP::LhoodMM_tools::m_fsvec
std::vector< std::unique_ptr< FakeBkgTools::FinalState > > m_fsvec
Definition: LhoodMM_tools.h:88
CP::LhoodMM_tools::mapLhood
void mapLhood(TMinuit_LHMM *lhoodFit, int nlep, double min, double max)
CP::LhoodMM_tools::m_ntlpred_vec
std::vector< std::shared_ptr< TMatrixT< double > > > m_ntlpred_vec
Definition: LhoodMM_tools.h:133
read_hist_ntuple.h1
h1
Definition: read_hist_ntuple.py:21
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
CP::IFakeBkgTool
Top-level interface for the tools providing an estimate of the fake lepton background All the tools,...
Definition: IFakeBkgTool.h:27
CP::LhoodMM_tools::perfectFit
bool perfectFit()
Definition: LhoodMM_tools.h:70
CP::LhoodMM_tools::m_fitInfo_1dhisto_map
std::map< TH1 *, std::vector< LhoodMMFitInfo > > m_fitInfo_1dhisto_map
Definition: LhoodMM_tools.h:114
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
plotting.yearwise_efficiency_vs_mu.xval
float xval
Definition: yearwise_efficiency_vs_mu.py:35
CP::LhoodMM_tools::m_coeffs
std::vector< std::vector< std::vector< double > > > m_coeffs
Definition: LhoodMM_tools.h:112
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
CP::LhoodMM_tools::m_MMmatrix_vec
std::vector< std::shared_ptr< TMatrixT< double > > > m_MMmatrix_vec
Definition: LhoodMM_tools.h:132
BaseFakeBkgTool.h
hist_file_dump.f
f
Definition: hist_file_dump.py:135
CP::LhoodMM_tools::m_fitInfo_2dhisto_map
std::map< TH2 *, std::vector< LhoodMMFitInfo > > m_fitInfo_2dhisto_map
Definition: LhoodMM_tools.h:115
beamspotman.dir
string dir
Definition: beamspotman.py:623
min
#define min(a, b)
Definition: cfImp.cxx:40
CP::LhoodMMFitInfo
Definition: LhoodMMFitInfo.h:13
python.InDetPriVxFinderConfig.setup
setup
Definition: InDetPriVxFinderConfig.py:124
FPEAudit::s_mutex
std::mutex s_mutex
Definition: FPEAuditor.cxx:43
private
#define private
Definition: DetDescrConditionsDict_dict_fixes.cxx:13
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
createCoolChannelIdFile.par
par
Definition: createCoolChannelIdFile.py:29
LhoodMMEvent
Definition: LhoodMMEvent.h:11
LhoodMMFitInfo.h
CP::LhoodMM_tools::m_fitInfo_3dhisto_map
std::map< TH3 *, std::vector< LhoodMMFitInfo > > m_fitInfo_3dhisto_map
Definition: LhoodMM_tools.h:116
plotting.yearwise_efficiency_vs_mu.yval
float yval
Definition: yearwise_efficiency_vs_mu.py:36
CP::LhoodMM_tools::getFitStatus
Int_t getFitStatus()
Definition: LhoodMM_tools.h:60
CP::LhoodMM_tools::setPrintLevel
void setPrintLevel(Int_t printLevel)
Definition: LhoodMM_tools.h:62
h
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
ASG_TOOL_CLASS
#define ASG_TOOL_CLASS(CLASSNAME, INT1)
Definition: AsgToolMacros.h:68
CxxUtils::reset
constexpr std::enable_if_t< is_bitmask_v< E >, E & > reset(E &lhs, E rhs)
Convenience function to clear bits in a class enum bitmask.
Definition: bitmask.h:251
CP::LhoodMM_tools
Definition: LhoodMM_tools.h:28
CP::LhoodMM_tools::set_do_std_perEventWeight
void set_do_std_perEventWeight(bool val)
Definition: LhoodMM_tools.h:64
CP::LhoodMM_tools::m_OSfrac
std::vector< std::vector< double > > m_OSfrac
Definition: LhoodMM_tools.h:119
error
Definition: IImpactPoint3dEstimator.h:70
TMinuit_LHMM
Definition: TMinuit_LHMM.h:12