ATLAS Offline Software
MuonTriggerScaleFactors.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3  */
4 
5 #ifndef MUONTRIGGERSCALEFACTORS_H_
6 #define MUONTRIGGERSCALEFACTORS_H_
7 
9 #include "AsgTools/AsgTool.h"
10 #include "AsgTools/ToolHandle.h"
15 #include <stdexcept>
16 #include <iostream>
17 #include <string>
18 #include <sstream>
19 #include <memory>
20 
21 #include "TDirectory.h"
22 
23 #include <unordered_map>
24 
25 class TH1;
26 
27 namespace CP {
28  typedef std::shared_ptr<TH1> TH1_Ptr;
29 
32 
33  public:
34 
35  MuonTriggerScaleFactors(const std::string& name);
36 
37  virtual ~MuonTriggerScaleFactors();
38 
39  virtual StatusCode initialize(void);
40 
41  // for single lepton triggers
42  virtual CorrectionCode getTriggerScaleFactor(const xAOD::MuonContainer& mucont, Double_t& triggersf, const std::string& trigger) const;
43 
44  virtual CorrectionCode getTriggerScaleFactor(const xAOD::Muon& muon, Double_t& triggersf, const std::string& trigger) const;
45 
46  virtual CorrectionCode getTriggerEfficiency(const xAOD::Muon& mu, Double_t& efficiency, const std::string& trigger, Bool_t dataType) const;
47 
48  virtual bool isAffectedBySystematic(const CP::SystematicVariation& systematic) const;
49 
51 
53 
54  virtual StatusCode applySystematicVariation(const CP::SystematicSet& systConfig);
55 
56  virtual int getBinNumber(const xAOD::Muon& muon, const std::string& trigger) const;
57 
58  virtual int getReplica_index(const std::string& sysBaseName, const std::string& trigStr) const;
59 
61  virtual bool isTriggerSupported(const std::string& trigger) const;
62  private:
63 
64  virtual CorrectionCode getMuonEfficiency(Double_t& eff, const TrigMuonEff::Configuration& configuration, const xAOD::Muon& muon, const std::string& trigger, const std::string& systematic) const;
65 
66  virtual CorrectionCode GetTriggerSF_dimu(Double_t& TriggerSF, TrigMuonEff::Configuration& configuration, const xAOD::MuonContainer& mucont, const std::string& trigger) const;
67 
68  virtual CorrectionCode GetTriggerSF(Double_t& TriggerSF, TrigMuonEff::Configuration& configuration, const xAOD::MuonContainer& mucont, const std::string& trigger) const;
69 
70  virtual CorrectionCode GetTriggerSF(Double_t& TriggerSF, TrigMuonEff::Configuration& configuration, const xAOD::Muon& muon, const std::string& trigger) const;
71 
72  virtual CorrectionCode getDimuonEfficiency(Double_t& eff, const TrigMuonEff::Configuration& configuration, const xAOD::MuonContainer& mucont, const std::string& chain, const std::string& systematic) const;
73 
75  return *m_appliedSystematics;
76  }
77 
79 
80  StatusCode LoadTriggerMap(unsigned int year);
81 
82  //This function is needed during initialization to parse the histograms to the cache
83  unsigned int encodeHistoName(const std::string &period, const std::string& Trigger, bool isData, const std::string& Systematic, bool isBarrel = true) const;
84  //This function is the equivalent during run time to retrieve the histograms from the cache
85  unsigned int encodeHistoName(const std::string& Trigger, const TrigMuonEff::Configuration& configuration, const std::string& Systematic, bool isBarrel = true) const;
86  protected:
87  virtual std::shared_ptr<TH1> getEfficiencyHistogram(unsigned int year, const std::string& period, const std::string& trigger, bool isData, const std::string& Systematic, bool isBarrel = true) const;
88  virtual std::shared_ptr<TH1> getEfficiencyHistogram(const std::string& trigger, bool isData, const std::string& Systematic, bool isBarrel = true) const;
89  private:
90  typedef std::pair<unsigned int, std::string> YearPeriod;
91  typedef std::pair<YearPeriod, unsigned int> EffiHistoIdent;
92  typedef std::map<EffiHistoIdent, TH1_Ptr> EfficiencyMap;
93 
94  CorrectionCode getThreshold(Int_t& threshold, const std::string& trigger) const;
95 
96  std::string getTriggerCorrespondingToDimuonTrigger(const std::string& trigger) const;
97  protected:
98 
99  std::string getDataPeriod() const;
100  unsigned int getRunNumber() const;
101  unsigned int getYear(unsigned int run) const;
102  std::string getDataPeriod(unsigned int run) const;
103  std::string getDataPeriod(unsigned int runNumber, unsigned int year) const;
104  private:
105  SG::ReadHandleKey<xAOD::EventInfo> m_eventInfo{this, "EventInfoContName", "EventInfo", "event info key"};
106 
107  TDirectory* getTemporaryDirectory(void) const;
108 
109  //Generate replicas of h for Toys with each bin of h varied with Gaussian distribution
110  //with mean from bin content and sigma from bin error
111  std::vector<TH1_Ptr> generateReplicas(TH1_Ptr h, int nrep, int seed) const;
112 
113  std::unordered_map<CP::SystematicSet, CP::SystematicSet> m_systFilter;
114 
116  std::string m_fileName;
118  std::map<EffiHistoIdent, std::vector<TH1_Ptr> > m_efficiencyMapReplicaArray;
119 
120  std::string m_muonquality;
121 
122  // subfolder to load from the calibration db
124  std::string m_custom_dir;
125  std::string m_binning;
129  std::string m_forcePeriod;
130  //Variables for toy replicas setup
131  std::vector<std::string> m_replicaTriggerList;
132  std::set<std::string> m_replicaSet; //set of triggers for replicas, for fast searching
135 
137  static const std::map<unsigned int,int> m_runNumber_year;
138 
139  };
140 
141 }
142 
143 #endif
CP::MuonTriggerScaleFactors::affectingSystematics
virtual CP::SystematicSet affectingSystematics() const
returns: the list of all systematics this tool can be affected by
Definition: MuonTriggerScaleFactors.cxx:867
python.AtlRunQueryAMI.period
period
Definition: AtlRunQueryAMI.py:225
CP::MuonTriggerScaleFactors::m_replicaSet
std::set< std::string > m_replicaSet
Definition: MuonTriggerScaleFactors.h:132
CP::MuonTriggerScaleFactors::getTriggerCorrespondingToDimuonTrigger
std::string getTriggerCorrespondingToDimuonTrigger(const std::string &trigger) const
Definition: MuonTriggerScaleFactors.cxx:701
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
CP::MuonTriggerScaleFactors::getReplica_index
virtual int getReplica_index(const std::string &sysBaseName, const std::string &trigStr) const
Definition: MuonTriggerScaleFactors.cxx:281
CP::TH1_Ptr
std::shared_ptr< TH1 > TH1_Ptr
Definition: MuonTriggerScaleFactors.h:28
asg::AsgTool
Base class for the dual-use tool implementation classes.
Definition: AsgTool.h:47
CP::MuonTriggerScaleFactors::m_ReplicaRandomSeed
int m_ReplicaRandomSeed
Definition: MuonTriggerScaleFactors.h:134
CP::MuonTriggerScaleFactors::initialize
virtual StatusCode initialize(void)
Dummy implementation of the initialisation function.
Definition: MuonTriggerScaleFactors.cxx:201
CP::MuonTriggerScaleFactors::getYear
unsigned int getYear(unsigned int run) const
Definition: MuonTriggerScaleFactors.cxx:722
runLayerRecalibration.chain
chain
Definition: runLayerRecalibration.py:175
CP::MuonTriggerScaleFactors::appliedSystematics
const CP::SystematicSet & appliedSystematics() const
Definition: MuonTriggerScaleFactors.h:74
CP::MuonTriggerScaleFactors::m_muonquality
std::string m_muonquality
Definition: MuonTriggerScaleFactors.h:120
CP::MuonTriggerScaleFactors::m_binning
std::string m_binning
Definition: MuonTriggerScaleFactors.h:125
CP::MuonTriggerScaleFactors::getDimuonEfficiency
virtual CorrectionCode getDimuonEfficiency(Double_t &eff, const TrigMuonEff::Configuration &configuration, const xAOD::MuonContainer &mucont, const std::string &chain, const std::string &systematic) const
Definition: MuonTriggerScaleFactors.cxx:676
CP::MuonTriggerScaleFactors::m_appliedSystematics
CP::SystematicSet * m_appliedSystematics
Definition: MuonTriggerScaleFactors.h:115
CP::MuonTriggerScaleFactors::m_forcePeriod
std::string m_forcePeriod
Definition: MuonTriggerScaleFactors.h:129
CP::MuonTriggerScaleFactors::m_nReplicas
int m_nReplicas
Definition: MuonTriggerScaleFactors.h:133
CP::MuonTriggerScaleFactors::EffiHistoIdent
std::pair< YearPeriod, unsigned int > EffiHistoIdent
Definition: MuonTriggerScaleFactors.h:91
CP::MuonTriggerScaleFactors::generateReplicas
std::vector< TH1_Ptr > generateReplicas(TH1_Ptr h, int nrep, int seed) const
Definition: MuonTriggerScaleFactors.cxx:345
CP::MuonTriggerScaleFactors::m_allowZeroSF
bool m_allowZeroSF
Definition: MuonTriggerScaleFactors.h:126
CP::MuonTriggerScaleFactors::getTemporaryDirectory
TDirectory * getTemporaryDirectory(void) const
Definition: MuonTriggerScaleFactors.cxx:836
CP::MuonTriggerScaleFactors::EfficiencyMap
std::map< EffiHistoIdent, TH1_Ptr > EfficiencyMap
Definition: MuonTriggerScaleFactors.h:92
CP::SystematicSet
Class to wrap a set of SystematicVariations.
Definition: SystematicSet.h:31
CP::MuonTriggerScaleFactors::getTriggerScaleFactor
virtual CorrectionCode getTriggerScaleFactor(const xAOD::MuonContainer &mucont, Double_t &triggersf, const std::string &trigger) const
Definition: MuonTriggerScaleFactors.cxx:254
downloadSingle.dataType
string dataType
Definition: downloadSingle.py:18
CP::MuonTriggerScaleFactors::m_replicaTriggerList
std::vector< std::string > m_replicaTriggerList
Definition: MuonTriggerScaleFactors.h:131
CP::SystematicVariation
Definition: SystematicVariation.h:47
SG::ReadHandleKey< xAOD::EventInfo >
python.AtlRunQueryAMI.year
year
Definition: AtlRunQueryAMI.py:226
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
CP::MuonTriggerScaleFactors::~MuonTriggerScaleFactors
virtual ~MuonTriggerScaleFactors()
Definition: MuonTriggerScaleFactors.cxx:78
CP::MuonTriggerScaleFactors::applySystematicVariation
virtual StatusCode applySystematicVariation(const CP::SystematicSet &systConfig)
effects: configure this tool for the given list of systematic variations.
Definition: MuonTriggerScaleFactors.cxx:901
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
CP::MuonTriggerScaleFactors::getBinNumber
virtual int getBinNumber(const xAOD::Muon &muon, const std::string &trigger) const
Definition: MuonTriggerScaleFactors.cxx:368
ISystematicsTool.h
CP::MuonTriggerScaleFactors::GetTriggerSF_dimu
virtual CorrectionCode GetTriggerSF_dimu(Double_t &TriggerSF, TrigMuonEff::Configuration &configuration, const xAOD::MuonContainer &mucont, const std::string &trigger) const
Definition: MuonTriggerScaleFactors.cxx:475
TrigMuonEff::Configuration
structure to hold variables to configure behaviour of the tool
Definition: IMuonTriggerScaleFactors.h:23
efficiency
void efficiency(std::vector< double > &bins, std::vector< double > &values, const std::vector< std::string > &files, const std::string &histname, const std::string &tplotname, const std::string &label="")
Definition: dependence.cxx:128
SystematicRegistry.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ReadHandleKey.h
Property holding a SG store/key/clid from which a ReadHandle is made.
CP::MuonTriggerScaleFactors::m_runNumber_year
static const std::map< unsigned int, int > m_runNumber_year
Definition: MuonTriggerScaleFactors.h:137
CP::MuonTriggerScaleFactors::LoadTriggerMap
StatusCode LoadTriggerMap(unsigned int year)
Definition: MuonTriggerScaleFactors.cxx:80
IMuonTriggerScaleFactors.h
CP::IMuonTriggerScaleFactors
Definition: IMuonTriggerScaleFactors.h:37
CP::MuonTriggerScaleFactors::m_calibration_version
std::string m_calibration_version
Definition: MuonTriggerScaleFactors.h:123
run
Definition: run.py:1
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
CP::MuonTriggerScaleFactors::isAffectedBySystematic
virtual bool isAffectedBySystematic(const CP::SystematicVariation &systematic) const
Declare the interface that this class provides.
Definition: MuonTriggerScaleFactors.cxx:858
CP::MuonTriggerScaleFactors::getDataPeriod
std::string getDataPeriod() const
Definition: MuonTriggerScaleFactors.cxx:735
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
threshold
Definition: chainparser.cxx:74
CP::MuonTriggerScaleFactors::getMuonEfficiency
virtual CorrectionCode getMuonEfficiency(Double_t &eff, const TrigMuonEff::Configuration &configuration, const xAOD::Muon &muon, const std::string &trigger, const std::string &systematic) const
Definition: MuonTriggerScaleFactors.cxx:415
EventInfo.h
CP::MuonTriggerScaleFactors::m_eventInfo
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfo
Definition: MuonTriggerScaleFactors.h:105
CP::MuonTriggerScaleFactors::m_fileName
std::string m_fileName
Definition: MuonTriggerScaleFactors.h:116
CP::MuonTriggerScaleFactors::m_custom_dir
std::string m_custom_dir
Definition: MuonTriggerScaleFactors.h:124
DeMoAtlasDataLoss.runNumber
string runNumber
Definition: DeMoAtlasDataLoss.py:64
CP::MuonTriggerScaleFactors::MuonTriggerScaleFactors
MuonTriggerScaleFactors(const std::string &name)
Definition: MuonTriggerScaleFactors.cxx:42
CP::MuonTriggerScaleFactors::m_systFilter
std::unordered_map< CP::SystematicSet, CP::SystematicSet > m_systFilter
Definition: MuonTriggerScaleFactors.h:113
CP::MuonTriggerScaleFactors::YearPeriod
std::pair< unsigned int, std::string > YearPeriod
Definition: MuonTriggerScaleFactors.h:90
CP::MuonTriggerScaleFactors::recommendedSystematics
virtual CP::SystematicSet recommendedSystematics() const
returns: the list of all systematics this tool recommends to use
Definition: MuonTriggerScaleFactors.cxx:897
CP::MuonTriggerScaleFactors::getRunNumber
unsigned int getRunNumber() const
Definition: MuonTriggerScaleFactors.cxx:812
CP::MuonTriggerScaleFactors::m_efficiencyMap
EfficiencyMap m_efficiencyMap
Definition: MuonTriggerScaleFactors.h:117
h
CP::MuonTriggerScaleFactors::encodeHistoName
unsigned int encodeHistoName(const std::string &period, const std::string &Trigger, bool isData, const std::string &Systematic, bool isBarrel=true) const
Definition: MuonTriggerScaleFactors.cxx:390
ASG_TOOL_CLASS
#define ASG_TOOL_CLASS(CLASSNAME, INT1)
Definition: AsgToolMacros.h:68
CP::MuonTriggerScaleFactors::getTriggerEfficiency
virtual CorrectionCode getTriggerEfficiency(const xAOD::Muon &mu, Double_t &efficiency, const std::string &trigger, Bool_t dataType) const
Definition: MuonTriggerScaleFactors.cxx:288
CP::CorrectionCode
Return value from object correction CP tools.
Definition: CorrectionCode.h:31
python.LArCondContChannels.isBarrel
isBarrel
Definition: LArCondContChannels.py:659
CP::MuonTriggerScaleFactors
Definition: MuonTriggerScaleFactors.h:30
CP::MuonTriggerScaleFactors::registerSystematics
StatusCode registerSystematics()
Definition: MuonTriggerScaleFactors.cxx:887
CP::MuonTriggerScaleFactors::isTriggerSupported
virtual bool isTriggerSupported(const std::string &trigger) const
Returns whether the trigger is supported by the tool or not. The decision depends on the present (ran...
Definition: MuonTriggerScaleFactors.cxx:363
dqt_zlumi_alleff_HIST.eff
int eff
Definition: dqt_zlumi_alleff_HIST.py:113
CP::MuonTriggerScaleFactors::getThreshold
CorrectionCode getThreshold(Int_t &threshold, const std::string &trigger) const
Definition: MuonTriggerScaleFactors.cxx:707
CP::MuonTriggerScaleFactors::m_experimental
bool m_experimental
Definition: MuonTriggerScaleFactors.h:127
ToolHandle.h
AsgTool.h
Analysis::Systematic
@ Systematic
Definition: CalibrationDataInterfaceROOT.h:70
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
CP::MuonTriggerScaleFactors::getEfficiencyHistogram
virtual std::shared_ptr< TH1 > getEfficiencyHistogram(unsigned int year, const std::string &period, const std::string &trigger, bool isData, const std::string &Systematic, bool isBarrel=true) const
Definition: MuonTriggerScaleFactors.cxx:401
CP::MuonTriggerScaleFactors::m_efficiencyMapReplicaArray
std::map< EffiHistoIdent, std::vector< TH1_Ptr > > m_efficiencyMapReplicaArray
Definition: MuonTriggerScaleFactors.h:118
CP::MuonTriggerScaleFactors::getDataPeriod
std::string getDataPeriod(unsigned int runNumber, unsigned int year) const
CP::MuonTriggerScaleFactors::GetTriggerSF
virtual CorrectionCode GetTriggerSF(Double_t &TriggerSF, TrigMuonEff::Configuration &configuration, const xAOD::MuonContainer &mucont, const std::string &trigger) const
Definition: MuonTriggerScaleFactors.cxx:534
CP::MuonTriggerScaleFactors::m_forceYear
int m_forceYear
Definition: MuonTriggerScaleFactors.h:128