ATLAS Offline Software
EfficiencyScaleFactor.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3  */
4 #ifndef MUONEFFICIENCYCORRECITONS_EFFICIENCYSCALEFACTOR_H_
5 #define MUONEFFICIENCYCORRECITONS_EFFICIENCYSCALEFACTOR_H_
6 
7 // EDM include(s):
8 #include "xAODMuon/Muon.h"
10 #include "xAODMuon/MuonContainer.h"
11 
17 
18 // further ROOT includes
19 #include <TFile.h>
20 #include <TDirectory.h>
21 
22 // STL includes
23 #include <string>
24 #include <iostream>
25 #include <exception>
26 #include <map>
27 #include <cmath>
28 #include <memory>
29 
30 
31 namespace CP {
32 
33  class SystematicSet;
34  class MuonEfficiencyScaleFactors;
36 
43  public:
47  const std::string &file,
48  const std::string &time_unit);
49 
56  EfficiencyScaleFactor(std::shared_ptr<EfficiencyScaleFactor> nominal,
57  const MuonEfficiencyScaleFactors& ref_tool,
58  const std::string& file,
59  const std::string& time_unit,
60  const std::string& syst_name,
61  int syst_type_bitmap);
65 
66 
69  bool CheckConsistency();
70 
73  int nBins() const;
74 
76  std::string GetBinName(int bin) const;
77 
79  int nOverFlowBins() const;
81  bool isOverFlowBin(int b) const;
82 
83 
85  int FindBinSF(const xAOD::Muon & mu) const;
86 
89  bool SetSystematicBin(int bin);
90 
91  bool separateBinSyst() const;
92  bool IsUpVariation() const;
93 
94 
96 
98  CorrectionCode ScaleFactor(const xAOD::Muon& mu, float & SF) const;
99  CorrectionCode ScaleFactorReplicas(const xAOD::Muon& mu, std::vector<float> & SF);
100 
103  CorrectionCode ApplyScaleFactorReplicas(const xAOD::Muon& mu, int n_replicas);
104 
106  CorrectionCode DataEfficiency(const xAOD::Muon& mu, float & Eff) const;
107  CorrectionCode DataEfficiencyReplicas(const xAOD::Muon& mu, std::vector<float> & eff);
111 
113  CorrectionCode MCEfficiency(const xAOD::Muon& mu, float & Eff) const;
114  CorrectionCode MCEfficiencyReplicas(const xAOD::Muon& mu, std::vector<float> & eff);
117  CorrectionCode ApplyMCEfficiencyReplicas(const xAOD::Muon& mu, int n_replicas);
118 
120  void DebugPrint() const;
121 
122 
126  std::string sysname(bool with_direction = true) const;
127 
130  unsigned int firstRun() const;
132  unsigned int lastRun() const;
133 
135  bool coversRunNumber(unsigned int run) const;
136 
138  void setFirstLastRun(unsigned int first, unsigned int last);
139  private:
140 
141  typedef std::vector<std::unique_ptr<HistHandler>> SFReplicaVec;
142 
144  bool ReadFromFile(const std::string &file, const std::string& time_unit);
145  std::unique_ptr<HistHandler> ReadHistFromFile(const std::string& name, TFile* f, const std::string& time_unit);
146 
147  // use some maps for easy histo loading / arithmetics by name
148 
150  CorrectionCode GetContentFromHist(const HistHandler* Hist, const xAOD::Muon& mu, float & SF, bool add_kine_syst) const;
152  CorrectionCode GetContentReplicasFromHist(EfficiencyScaleFactor::SFReplicaVec &replicas, const xAOD::Muon& mu, std::vector<float> & SF, bool add_kine_syst);
153 
154 
155  // package a TH1 in a HistHandler
156  std::unique_ptr<HistHandler> package_histo(TH1* h);
157 
158 
159  // replica generation
160  void GenerateReplicas(int nrep, int seed);
161  void GenerateReplicasFromHist(HistHandler* h, int nrep, int seed, EfficiencyScaleFactor::SFReplicaVec &repVector);
162 
167  std::string m_syst_name;
168 
171  bool m_is_up;
179  std::unique_ptr<HistHandler> m_sf;
180  std::unique_ptr<HistHandler> m_eff;
181  std::unique_ptr<HistHandler> m_mc_eff;
182 
186 
187  std::unique_ptr<FloatDecorator> m_sf_decor;
188  std::unique_ptr<FloatDecorator> m_eff_decor;
189  std::unique_ptr<FloatDecorator> m_mc_eff_decor;
190 
191  std::unique_ptr<FloatVectorDecorator> m_sf_rep_decor;
192  std::unique_ptr<FloatVectorDecorator> m_eff_rep_decor;
193  std::unique_ptr<FloatVectorDecorator> m_mc_eff_rep_decor;
194 
195 
196  // these are for the continuous pt dependent systematic if we have one
197  std::unique_ptr<IKinematicSystHandler> m_sf_KineDepsys;
198 
199 
204 
206  std::shared_ptr<EfficiencyScaleFactor> m_NominalFallBack;
208 
209 
214 
215  mutable std::atomic<unsigned int> m_warnsPrinted;
216  static const unsigned int m_warningLimit;
217 
218  unsigned int m_firstRun;
219  unsigned int m_lastRun;
220  };
221 } /* namespace CP */
222 
223 #endif /* EFFICIENCYSCALEFACTOR_H_ */
CP::EfficiencyScaleFactor::m_syst_name
std::string m_syst_name
Definition: EfficiencyScaleFactor.h:167
CP::EfficiencyScaleFactor::m_eff_decor
std::unique_ptr< FloatDecorator > m_eff_decor
Definition: EfficiencyScaleFactor.h:188
CP::EfficiencyScaleFactor::DataEfficiency
CorrectionCode DataEfficiency(const xAOD::Muon &mu, float &Eff) const
... and absolute efficiencies
Definition: EfficiencyScaleFactor.cxx:308
CP::EfficiencyScaleFactor::FloatVectorDecorator
SG::AuxElement::Decorator< std::vector< float > > FloatVectorDecorator
Definition: EfficiencyScaleFactor.h:185
CP::EfficiencyScaleFactor::m_warnsPrinted
std::atomic< unsigned int > m_warnsPrinted
Definition: EfficiencyScaleFactor.h:215
CP::EfficiencyScaleFactor::ScaleFactorReplicas
CorrectionCode ScaleFactorReplicas(const xAOD::Muon &mu, std::vector< float > &SF)
Definition: EfficiencyScaleFactor.cxx:403
CP::EfficiencyScaleFactor::package_histo
std::unique_ptr< HistHandler > package_histo(TH1 *h)
Definition: EfficiencyScaleFactor.cxx:267
CP::EfficiencyScaleFactor::isOverFlowBin
bool isOverFlowBin(int b) const
Check whether the bin is overflow or not.
Definition: EfficiencyScaleFactor.cxx:289
CP::EfficiencyScaleFactor::MCEfficiencyReplicas
CorrectionCode MCEfficiencyReplicas(const xAOD::Muon &mu, std::vector< float > &eff)
Definition: EfficiencyScaleFactor.cxx:409
CP::EfficiencyScaleFactor::ReadHistFromFile
std::unique_ptr< HistHandler > ReadHistFromFile(const std::string &name, TFile *f, const std::string &time_unit)
Definition: EfficiencyScaleFactor.cxx:252
CP::EfficiencyScaleFactor::GetContentReplicasFromHist
CorrectionCode GetContentReplicasFromHist(EfficiencyScaleFactor::SFReplicaVec &replicas, const xAOD::Muon &mu, std::vector< float > &SF, bool add_kine_syst)
read a vector of replica contents in the correct bin in one of my histos
Definition: EfficiencyScaleFactor.cxx:412
CP::EfficiencyScaleFactor::DebugPrint
void DebugPrint() const
debug method
CP::EfficiencyScaleFactor::m_mc_eff
std::unique_ptr< HistHandler > m_mc_eff
Definition: EfficiencyScaleFactor.h:181
CP::EfficiencyScaleFactor::FloatDecorator
SG::AuxElement::Decorator< float > FloatDecorator
Typedef to make the definition of the follow decorators a bit shorted.
Definition: EfficiencyScaleFactor.h:184
Muon.h
CP::EfficiencyScaleFactor::m_firstRun
unsigned int m_firstRun
Definition: EfficiencyScaleFactor.h:218
CP::EfficiencyScaleFactor::m_sf_KineDepsys
std::unique_ptr< IKinematicSystHandler > m_sf_KineDepsys
Definition: EfficiencyScaleFactor.h:197
CP::EfficiencyScaleFactor::IsUpVariation
bool IsUpVariation() const
Definition: EfficiencyScaleFactor.cxx:185
CP::EfficiencyScaleFactor::m_eff
std::unique_ptr< HistHandler > m_eff
Definition: EfficiencyScaleFactor.h:180
CP::EfficiencyScaleFactor::m_is_lowpt
bool m_is_lowpt
states that this SF should respond to low pt systematics rather than high pt ones
Definition: EfficiencyScaleFactor.h:173
CP::EfficiencyScaleFactor::m_NominalFallBack
std::shared_ptr< EfficiencyScaleFactor > m_NominalFallBack
Nominal fall-back scale-factor.
Definition: EfficiencyScaleFactor.h:206
CP::MuonEfficiencyScaleFactors
Definition: MuonEfficiencyScaleFactors.h:23
TRT_PAI_gasdata::SF
const float SF[NF]
Cross sections for Fluor.
Definition: TRT_PAI_gasdata.h:285
bin
Definition: BinsDiffFromStripMedian.h:43
CP::EfficiencyScaleFactor::FindBinSF
int FindBinSF(const xAOD::Muon &mu) const
Finds the bin to which the muon corresponds to.
Definition: EfficiencyScaleFactor.cxx:481
CP::EfficiencyScaleFactor::GetContentFromHist
CorrectionCode GetContentFromHist(const HistHandler *Hist, const xAOD::Muon &mu, float &SF, bool add_kine_syst) const
read the content of the correct bin in one of my histos. MCefficiencies actually do not need a pt-dep...
Definition: EfficiencyScaleFactor.cxx:339
CP::EfficiencyScaleFactor::m_sf_rep_decor
std::unique_ptr< FloatVectorDecorator > m_sf_rep_decor
Definition: EfficiencyScaleFactor.h:191
MuonEfficiencyType.h
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
CP::EfficiencyScaleFactor::m_warningLimit
static const unsigned int m_warningLimit
Definition: EfficiencyScaleFactor.h:216
ISystematicsTool.h
CP::EfficiencyScaleFactor::ApplyScaleFactor
CorrectionCode ApplyScaleFactor(const xAOD::Muon &mu) const
or you can just decorate the scale-factor to the muon
Definition: EfficiencyScaleFactor.cxx:366
CP::EfficiencyScaleFactor::DataEfficiencyReplicas
CorrectionCode DataEfficiencyReplicas(const xAOD::Muon &mu, std::vector< float > &eff)
Definition: EfficiencyScaleFactor.cxx:406
CP::EfficiencyScaleFactor::m_measurement
CP::MuonEfficiencyType m_measurement
Section of variables of the tool.
Definition: EfficiencyScaleFactor.h:166
CP::EfficiencyScaleFactor::coversRunNumber
bool coversRunNumber(unsigned int run) const
Check if a run of data-taking is covered by this map.
Definition: EfficiencyScaleFactor.cxx:194
CP::EfficiencyScaleFactor::m_default_eff
float m_default_eff
default efficiency value (in case of OutOfValidityRange)
Definition: EfficiencyScaleFactor.h:211
CP::EfficiencyScaleFactor::SetSystematicBin
bool SetSystematicBin(int bin)
This function will let the world implode since it allows to decorrelate the sysstematics bin by bin.
Definition: EfficiencyScaleFactor.cxx:460
CP::EfficiencyScaleFactor::EfficiencyScaleFactor
EfficiencyScaleFactor(const EfficiencyScaleFactor &)=delete
Do not allow for copy constructors and other assignments of the class.
CP::EfficiencyScaleFactor::m_lastRun
unsigned int m_lastRun
Definition: EfficiencyScaleFactor.h:219
CP::EfficiencyScaleFactor::m_separateBinSyst
bool m_separateBinSyst
Can the systematic be decorrelated.
Definition: EfficiencyScaleFactor.h:177
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:59
CP::EfficiencyScaleFactor::setFirstLastRun
void setFirstLastRun(unsigned int first, unsigned int last)
Set the run-number coverage.
Definition: EfficiencyScaleFactor.cxx:197
CP::HistHandler
Definition: HistHandler.h:37
CP::EfficiencyScaleFactor::m_sf_decor
std::unique_ptr< FloatDecorator > m_sf_decor
Definition: EfficiencyScaleFactor.h:187
CP::EfficiencyScaleFactor::m_sf_replicas
SFReplicaVec m_sf_replicas
replicas, in case we use them
Definition: EfficiencyScaleFactor.h:201
file
TFile * file
Definition: tile_monitor.h:29
CP::EfficiencyScaleFactor::MCEfficiency
CorrectionCode MCEfficiency(const xAOD::Muon &mu, float &Eff) const
... mc efficiency
Definition: EfficiencyScaleFactor.cxx:323
CP::EfficiencyScaleFactor::ReadFromFile
bool ReadFromFile(const std::string &file, const std::string &time_unit)
Read SF histrograms from a given input file.
hist_file_dump.f
f
Definition: hist_file_dump.py:135
CP::EfficiencyScaleFactor
Definition: EfficiencyScaleFactor.h:35
run
Definition: run.py:1
CP::EfficiencyScaleFactor::ApplyDataEfficiency
CorrectionCode ApplyDataEfficiency(const xAOD::Muon &mu) const
You can decorate the data efficiecny as well.
Definition: EfficiencyScaleFactor.cxx:379
CP::EfficiencyScaleFactor::ApplyDataEfficiencyReplicas
CorrectionCode ApplyDataEfficiencyReplicas(const xAOD::Muon &mu, int n_replicas)
Definition: EfficiencyScaleFactor.cxx:385
CP::EfficiencyScaleFactor::m_default_eff_ttva
float m_default_eff_ttva
default TTVA efficiency value (in case of MuonStandAlone for |eta|>2.5)
Definition: EfficiencyScaleFactor.h:213
CP::EfficiencyScaleFactor::lastRun
unsigned int lastRun() const
Last run to which the map belongs to. The last run number is given exclusvely...
Definition: EfficiencyScaleFactor.cxx:191
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
CP::EfficiencyScaleFactor::m_mc_eff_replicas
SFReplicaVec m_mc_eff_replicas
Definition: EfficiencyScaleFactor.h:203
CP::EfficiencyScaleFactor::nOverFlowBins
int nOverFlowBins() const
Number of overflow bins in the map.
Definition: EfficiencyScaleFactor.cxx:286
KinematicSystHandler.h
EventInfo.h
MuonContainer.h
CP::EfficiencyScaleFactor::GenerateReplicas
void GenerateReplicas(int nrep, int seed)
Definition: EfficiencyScaleFactor.cxx:440
HistHandler.h
CP::EfficiencyScaleFactor::GenerateReplicasFromHist
void GenerateReplicasFromHist(HistHandler *h, int nrep, int seed, EfficiencyScaleFactor::SFReplicaVec &repVector)
Definition: EfficiencyScaleFactor.cxx:445
h
CP::EfficiencyScaleFactor::ApplyMCEfficiency
CorrectionCode ApplyMCEfficiency(const xAOD::Muon &mu) const
... or decorate them directly
Definition: EfficiencyScaleFactor.cxx:391
CP::MuonEfficiencyType
MuonEfficiencyType
Definition: MuonEfficiencyType.h:12
CP::EfficiencyScaleFactor::ApplyScaleFactorReplicas
CorrectionCode ApplyScaleFactorReplicas(const xAOD::Muon &mu, int n_replicas)
Definition: EfficiencyScaleFactor.cxx:372
CP::EfficiencyScaleFactor::sysname
std::string sysname(bool with_direction=true) const
A string having the full name of the systematic including the measurement.
Definition: EfficiencyScaleFactor.cxx:179
DeMoScan.first
bool first
Definition: DeMoScan.py:536
CP::CorrectionCode
Return value from object correction CP tools.
Definition: CorrectionCode.h:31
CP::EfficiencyScaleFactor::ScaleFactor
CorrectionCode ScaleFactor(const xAOD::Muon &mu, float &SF) const
the important bits - extract SF info
Definition: EfficiencyScaleFactor.cxx:292
CP::EfficiencyScaleFactor::GetBinName
std::string GetBinName(int bin) const
Returns the name of the bin using the axis title from the scale-factor map.
Definition: EfficiencyScaleFactor.cxx:473
CP::EfficiencyScaleFactor::m_mc_eff_decor
std::unique_ptr< FloatDecorator > m_mc_eff_decor
Definition: EfficiencyScaleFactor.h:189
CP::EfficiencyScaleFactor::m_SystematicBin
int m_SystematicBin
Definition: EfficiencyScaleFactor.h:207
CP::EfficiencyScaleFactor::m_is_up
bool m_is_up
Boolean whether the scale-factor is varying upwards or downwards Only relevant if the systname is not...
Definition: EfficiencyScaleFactor.h:171
CP::EfficiencyScaleFactor::SFReplicaVec
std::vector< std::unique_ptr< HistHandler > > SFReplicaVec
Definition: EfficiencyScaleFactor.h:141
CorrectionCode.h
dqt_zlumi_alleff_HIST.eff
int eff
Definition: dqt_zlumi_alleff_HIST.py:113
CP::EfficiencyScaleFactor::nBins
int nBins() const
How many bins does the scale-factor map have.
Definition: EfficiencyScaleFactor.cxx:283
CP::EfficiencyScaleFactor::ApplyMCEfficiencyReplicas
CorrectionCode ApplyMCEfficiencyReplicas(const xAOD::Muon &mu, int n_replicas)
Definition: EfficiencyScaleFactor.cxx:397
CP::EfficiencyScaleFactor::CheckConsistency
bool CheckConsistency()
check the consistency of the scale-factor map.
Definition: EfficiencyScaleFactor.cxx:201
CP::EfficiencyScaleFactor::EfficiencyScaleFactor
EfficiencyScaleFactor(const MuonEfficiencyScaleFactors &ref_tool, const std::string &file, const std::string &time_unit)
Nominal constructor to use having the measurement (Reco/TTVA/Iso/BadMuon) path to the scale-factor ma...
Definition: EfficiencyScaleFactor.cxx:173
CP::EfficiencyScaleFactor::firstRun
unsigned int firstRun() const
First run to which the map belongs to.
Definition: EfficiencyScaleFactor.cxx:188
CP::EfficiencyScaleFactor::m_respond_to_kineDepSyst
bool m_respond_to_kineDepSyst
steers the pt dependent systematics
Definition: EfficiencyScaleFactor.h:175
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
CP::EfficiencyScaleFactor::m_sf
std::unique_ptr< HistHandler > m_sf
the histograms needed to run
Definition: EfficiencyScaleFactor.h:179
CP::EfficiencyScaleFactor::m_mc_eff_rep_decor
std::unique_ptr< FloatVectorDecorator > m_mc_eff_rep_decor
Definition: EfficiencyScaleFactor.h:193
CP::EfficiencyScaleFactor::m_eff_rep_decor
std::unique_ptr< FloatVectorDecorator > m_eff_rep_decor
Definition: EfficiencyScaleFactor.h:192
CP::EfficiencyScaleFactor::operator=
EfficiencyScaleFactor & operator=(const EfficiencyScaleFactor &)=delete
CP::EfficiencyScaleFactor::m_eff_replicas
SFReplicaVec m_eff_replicas
Definition: EfficiencyScaleFactor.h:202
CP::EfficiencyScaleFactor::separateBinSyst
bool separateBinSyst() const
Definition: EfficiencyScaleFactor.cxx:182