ATLAS Offline Software
Loading...
Searching...
No Matches
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"
11
17
22
23// further ROOT includes
24#include <TFile.h>
25#include <TDirectory.h>
26
27// STL includes
28#include <string>
29#include <iostream>
30#include <exception>
31#include <map>
32#include <cmath>
33#include <memory>
34
35
36namespace CP {
37
38 class SystematicSet;
41
48 public:
51 EfficiencyScaleFactor(const MuonEfficiencyScaleFactors& ref_tool,
52 const std::string &file,
53 const std::string &time_unit);
54
61 EfficiencyScaleFactor(std::shared_ptr<EfficiencyScaleFactor> nominal,
62 const MuonEfficiencyScaleFactors& ref_tool,
63 const std::string& file,
64 const std::string& time_unit,
65 const std::string& syst_name,
66 int syst_type_bitmap);
70
71
74 bool CheckConsistency();
75
78 int nBins() const;
79
81 std::string GetBinName(int bin) const;
82
84 int nOverFlowBins() const;
86 bool isOverFlowBin(int b) const;
87
88
90 int FindBinSF(const xAOD::Muon & mu) const;
91
94 bool SetSystematicBin(int bin);
95
96 bool separateBinSyst() const;
97 bool IsUpVariation() const;
98
99
101
103 CorrectionCode ScaleFactor(const xAOD::Muon& mu, float & SF) const;
104 CorrectionCode ScaleFactor(columnar::MuonId mu, float & SF) const;
105 CorrectionCode ScaleFactorReplicas(const xAOD::Muon& mu, std::vector<float> & SF);
106
109 CorrectionCode ApplyScaleFactorReplicas(const xAOD::Muon& mu, int n_replicas);
110
112 CorrectionCode DataEfficiency(const xAOD::Muon& mu, float & Eff) const;
113 CorrectionCode DataEfficiencyReplicas(const xAOD::Muon& mu, std::vector<float> & eff);
116 CorrectionCode ApplyDataEfficiencyReplicas(const xAOD::Muon& mu, int n_replicas);
117
119 CorrectionCode MCEfficiency(const xAOD::Muon& mu, float & Eff) const;
120 CorrectionCode MCEfficiencyReplicas(const xAOD::Muon& mu, std::vector<float> & eff);
123 CorrectionCode ApplyMCEfficiencyReplicas(const xAOD::Muon& mu, int n_replicas);
124
126 void DebugPrint() const;
127
128
132 std::string sysname(bool with_direction = true) const;
133
136 unsigned int firstRun() const;
138 unsigned int lastRun() const;
139
141 bool coversRunNumber(unsigned int run) const;
142
144 void setFirstLastRun(unsigned int first, unsigned int last);
145 private:
146
147 typedef std::vector<std::unique_ptr<HistHandler>> SFReplicaVec;
148
150 bool ReadFromFile(const std::string &file, const std::string& time_unit);
151 std::unique_ptr<HistHandler> ReadHistFromFile(columnar::ColumnarTool<>* parent, const std::string& name, TFile* f, const std::string& time_unit);
152
153 // use some maps for easy histo loading / arithmetics by name
154
156 CorrectionCode GetContentFromHist(const HistHandler* Hist, const xAOD::Muon& mu, float & SF, bool add_kine_syst) const;
157 CorrectionCode GetContentFromHist(const HistHandler* Hist, columnar::MuonId mu, float & SF, bool add_kine_syst) const;
159 CorrectionCode GetContentReplicasFromHist(EfficiencyScaleFactor::SFReplicaVec &replicas, const xAOD::Muon& mu, std::vector<float> & SF, bool add_kine_syst);
160
161
162 // package a TH1 in a HistHandler
163 std::unique_ptr<HistHandler> package_histo(columnar::ColumnarTool<>* parent, TH1* h);
164
165
166 // replica generation
167 void GenerateReplicas(int nrep, int seed);
168 void GenerateReplicasFromHist(HistHandler* h, int nrep, int seed, EfficiencyScaleFactor::SFReplicaVec &repVector);
169
174 std::string m_syst_name;
175
186 std::unique_ptr<HistHandler> m_sf;
187 std::unique_ptr<HistHandler> m_eff;
188 std::unique_ptr<HistHandler> m_mc_eff;
189
193
194 std::unique_ptr<FloatDecorator> m_sf_decor;
195 std::unique_ptr<FloatDecorator> m_eff_decor;
196 std::unique_ptr<FloatDecorator> m_mc_eff_decor;
197
198 std::unique_ptr<FloatVectorDecorator> m_sf_rep_decor;
199 std::unique_ptr<FloatVectorDecorator> m_eff_rep_decor;
200 std::unique_ptr<FloatVectorDecorator> m_mc_eff_rep_decor;
201
202
203 // these are for the continuous pt dependent systematic if we have one
204 std::unique_ptr<IKinematicSystHandler> m_sf_KineDepsys;
205
206
211
213 std::shared_ptr<EfficiencyScaleFactor> m_NominalFallBack;
215
216
221
222 mutable std::atomic<unsigned int> m_warnsPrinted;
223 static const unsigned int m_warningLimit;
224
225 unsigned int m_firstRun;
226 unsigned int m_lastRun;
227
228 public:
229
235 };
236} /* namespace CP */
237
238#endif /* EFFICIENCYSCALEFACTOR_H_ */
Header file for AthHistogramAlgorithm.
Return value from object correction CP tools.
EfficiencyScaleFactor(const EfficiencyScaleFactor &)=delete
Do not allow for copy constructors and other assignments of the class.
CorrectionCode ApplyScaleFactor(const xAOD::Muon &mu) const
or you can just decorate the scale-factor to the muon
std::unique_ptr< FloatVectorDecorator > m_mc_eff_rep_decor
bool m_is_lowpt
states that this SF should respond to low pt systematics rather than high pt ones
int nOverFlowBins() const
Number of overflow bins in the map.
CorrectionCode MCEfficiencyReplicas(const xAOD::Muon &mu, std::vector< float > &eff)
bool SetSystematicBin(int bin)
This function will let the world implode since it allows to decorrelate the sysstematics bin by bin.
unsigned int firstRun() const
First run to which the map belongs to.
CorrectionCode ApplyMCEfficiencyReplicas(const xAOD::Muon &mu, int n_replicas)
EfficiencyScaleFactor & operator=(const EfficiencyScaleFactor &)=delete
std::unique_ptr< FloatDecorator > m_mc_eff_decor
columnar::MuonAccessor< columnar::RetypeColumn< double, float > > phiAcc
std::unique_ptr< FloatVectorDecorator > m_eff_rep_decor
std::shared_ptr< EfficiencyScaleFactor > m_NominalFallBack
Nominal fall-back scale-factor.
std::unique_ptr< IKinematicSystHandler > m_sf_KineDepsys
CorrectionCode ApplyDataEfficiency(const xAOD::Muon &mu) const
You can decorate the data efficiecny as well.
CorrectionCode ApplyDataEfficiencyReplicas(const xAOD::Muon &mu, int n_replicas)
void setFirstLastRun(unsigned int first, unsigned int last)
Set the run-number coverage.
float m_default_eff
default efficiency value (in case of OutOfValidityRange)
bool ReadFromFile(const std::string &file, const std::string &time_unit)
Read SF histrograms from a given input file.
CorrectionCode ScaleFactor(const xAOD::Muon &mu, float &SF) const
the important bits - extract SF info
float m_default_eff_ttva
default TTVA efficiency value (in case of MuonStandAlone for |eta|>2.5)
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
void DebugPrint() const
debug method
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...
std::unique_ptr< FloatDecorator > m_eff_decor
std::unique_ptr< HistHandler > package_histo(columnar::ColumnarTool<> *parent, TH1 *h)
CorrectionCode ApplyScaleFactorReplicas(const xAOD::Muon &mu, int n_replicas)
unsigned int lastRun() const
Last run to which the map belongs to. The last run number is given exclusvely...
void GenerateReplicas(int nrep, int seed)
std::string GetBinName(int bin) const
Returns the name of the bin using the axis title from the scale-factor map.
CorrectionCode DataEfficiencyReplicas(const xAOD::Muon &mu, std::vector< float > &eff)
bool CheckConsistency()
check the consistency of the scale-factor map.
std::unique_ptr< FloatDecorator > m_sf_decor
bool m_is_up
Boolean whether the scale-factor is varying upwards or downwards Only relevant if the systname is not...
columnar::MuonAccessor< columnar::RetypeColumn< double, float > > etaAcc
columnar::MuonAccessor< columnar::RetypeColumn< double, float > > ptAcc
SFReplicaVec m_sf_replicas
replicas, in case we use them
std::vector< std::unique_ptr< HistHandler > > SFReplicaVec
std::unique_ptr< FloatVectorDecorator > m_sf_rep_decor
CorrectionCode MCEfficiency(const xAOD::Muon &mu, float &Eff) const
... mc efficiency
columnar::MuonAccessor< columnar::RetypeColumn< xAOD::Muon::MuonType, std::uint16_t > > muonTypeAcc
std::unique_ptr< HistHandler > m_sf
the histograms needed to run
int nBins() const
How many bins does the scale-factor map have.
std::unique_ptr< HistHandler > m_eff
SG::AuxElement::Decorator< std::vector< float > > FloatVectorDecorator
int FindBinSF(const xAOD::Muon &mu) const
Finds the bin to which the muon corresponds to.
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...
bool isOverFlowBin(int b) const
Check whether the bin is overflow or not.
bool m_respond_to_kineDepSyst
steers the pt dependent systematics
CorrectionCode ApplyMCEfficiency(const xAOD::Muon &mu) const
... or decorate them directly
bool coversRunNumber(unsigned int run) const
Check if a run of data-taking is covered by this map.
columnar::MuonAccessor< columnar::ObjectColumn > m_muons
CorrectionCode ScaleFactorReplicas(const xAOD::Muon &mu, std::vector< float > &SF)
std::unique_ptr< HistHandler > m_mc_eff
CP::MuonEfficiencyType m_measurement
Section of variables of the tool.
std::unique_ptr< HistHandler > ReadHistFromFile(columnar::ColumnarTool<> *parent, const std::string &name, TFile *f, const std::string &time_unit)
static const unsigned int m_warningLimit
void GenerateReplicasFromHist(HistHandler *h, int nrep, int seed, EfficiencyScaleFactor::SFReplicaVec &repVector)
std::atomic< unsigned int > m_warnsPrinted
std::string sysname(bool with_direction=true) const
A string having the full name of the systematic including the measurement.
SG::AuxElement::Decorator< float > FloatDecorator
Typedef to make the definition of the follow decorators a bit shorted.
bool m_separateBinSyst
Can the systematic be decorrelated.
CorrectionCode DataEfficiency(const xAOD::Muon &mu, float &Eff) const
... and absolute efficiencies
Class to wrap a set of SystematicVariations.
SG::Decorator< T, ALLOC > Decorator
Definition AuxElement.h:575
the base class for all columnar components
Select isolated Photons, Electrons and Muons.
ObjectId< ContainerId::muon > MuonId
Definition MuonDef.h:25
AccessorTemplate< ContainerId::muon, CT, ColumnAccessMode::input, CM > MuonAccessor
Definition MuonDef.h:27
Definition run.py:1
Muon_v1 Muon
Reference the current persistent version:
TFile * file