ATLAS Offline Software
Loading...
Searching...
No Matches
TrigGlobalEfficiencyCorrectionTool.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5// contact: jmaurer@cern.ch
6
7#ifndef TRIGGLOBALEFFICIENCYCORRECTION_TRIGGLOBALEFFICIENCYCORRECTIONTOOL_H
8#define TRIGGLOBALEFFICIENCYCORRECTION_TRIGGLOBALEFFICIENCYCORRECTIONTOOL_H 1
9
10#include <boost/container/container_fwd.hpp>
11#include <map>
12#include <memory>
13#include <set>
14#include <string>
15#include <vector>
16
17#include "AsgTools/AsgTool.h"
26
27namespace TrigGlobEffCorr {
28class ImportData;
29class Calculator;
30class CheckConfig;
31class Efficiencies;
32class Lepton;
33} // namespace TrigGlobEffCorr
34
36 : public asg::AsgTool,
38 public:
41
42 TrigGlobalEfficiencyCorrectionTool(const std::string& name);
44
45 virtual StatusCode initialize() override;
46
48 const std::vector<const xAOD::IParticle*>& particles,
49 double& efficiencyScaleFactor) override;
51 unsigned runNumber, const std::vector<const xAOD::IParticle*>& particles,
52 double& efficiencyScaleFactor) override;
54 const std::vector<const xAOD::IParticle*>& particles,
55 double& efficiencyData, double& efficiencyMc) override;
57 unsigned runNumber, const std::vector<const xAOD::IParticle*>& particles,
58 double& efficiencyData, double& efficiencyMc) override;
59
60 virtual bool isAffectedBySystematic(
61 const CP::SystematicVariation& systematic) const override;
62 virtual CP::SystematicSet affectingSystematics() const override;
63 virtual CP::SystematicSet recommendedSystematics() const override;
64 virtual StatusCode applySystematicVariation(
65 const CP::SystematicSet& systConfig) override;
66
68 bool& matched,
69 const std::vector<const xAOD::IParticle*>& particles) override;
71 std::unordered_map<std::string, bool>& matched_per_trigger,
72 const std::vector<const xAOD::IParticle*>& particles) override;
74 std::vector<std::string>& triggers) override;
76 const std::string& trigger, std::size_t& numberOfLegs) override;
77
79 const std::map<std::string, std::string>& triggerCombination,
80 const std::string& version,
81 std::map<std::string, std::string>& legsPerKey) {
82 return suggestEgammaMapKeys(triggerCombination, version, legsPerKey,
84 }
86 const std::map<std::string, std::string>& triggerCombination,
87 const std::string& version,
88 std::map<std::string, std::string>& legsPerKey) {
89 return suggestEgammaMapKeys(triggerCombination, version, legsPerKey,
91 }
93 const std::map<std::string, std::string>& triggerCombination,
94 const std::string& version,
95 std::map<std::string, std::string>& legsPerKey,
97
98 private:
99 struct Hierarchy {
100 short offset, nLegs;
101 float minPt, maxPt;
102 };
105 std::size_t hash;
107 // cppcheck-suppress uninitMemberVar; false positive
108 // (https://trac.cppcheck.net/ticket/13444)
109 TagDecorator(const std::string& name, std::size_t the_hash, bool suffixed)
110 : decorator(name), hash(the_hash), suffixed(suffixed) {}
111 };
113 float minPt, maxPt;
114 unsigned long ranking;
115 operator bool() const { return ranking + 1; }
116 static bool invalid(unsigned long ranking) { return !(ranking + 1); }
117 };
118 struct ToolKey {
119 std::size_t hash;
120 std::pair<unsigned, unsigned> boundaries;
121 bool operator<(const ToolKey& rhs) const {
122 return hash < rhs.hash ||
123 (hash == rhs.hash && boundaries.second < rhs.boundaries.first);
124 }
125 bool operator==(const ToolKey& rhs) const {
126 return hash == rhs.hash && boundaries.second >= rhs.boundaries.first &&
127 rhs.boundaries.second >= boundaries.first;
128 }
129 // cppcheck-suppress uninitMemberVar; false positive
130 // (https://trac.cppcheck.net/ticket/13444)
131 ToolKey(std::size_t leg, std::size_t tag, unsigned runNumber)
132 : hash(leg ^ tag), boundaries(runNumber, runNumber) {}
133 // cppcheck-suppress uninitMemberVar; false positive
134 // (https://trac.cppcheck.net/ticket/13444)
135 ToolKey(std::size_t leg, std::size_t tag,
136 std::pair<unsigned, unsigned> bounds)
137 : hash(leg ^ tag), boundaries(bounds) {}
138 // cppcheck-suppress uninitMemberVar; false positive
139 // (https://trac.cppcheck.net/ticket/13444)
140 ToolKey(std::size_t leg = 0, std::size_t tag = 0)
141 : hash(leg ^ tag), boundaries(0, 999999) {}
142 };
143 using LeptonList = std::vector<TrigGlobEffCorr::Lepton>;
144
146 ToolHandleArray<IAsgElectronEfficiencyCorrectionTool>
148 ToolHandleArray<IAsgElectronEfficiencyCorrectionTool>
150 ToolHandleArray<IAsgPhotonEfficiencyCorrectionTool>
152 ToolHandleArray<IAsgPhotonEfficiencyCorrectionTool>
154 ToolHandleArray<CP::IMuonTriggerScaleFactors> m_suppliedMuonTools;
155 std::map<std::string, std::string> m_legsPerTool;
156 std::map<std::string, std::string> m_triggerCb;
157 std::map<std::string, std::string> m_triggerCbPerYear;
159 std::map<std::string, std::string> m_tagsPerTool;
160 std::map<std::string, std::string> m_electronLegsPerTag;
161 std::map<std::string, std::string> m_muonLegsPerTag;
162 std::map<std::string, std::string> m_legsPerTag;
163 std::map<std::string, std::string> m_overrideThresholds;
164 unsigned long m_numberOfToys;
166 ToolHandle<Trig::IMatchingTool> m_trigMatchTool;
167
168 std::hash<std::string> m_hasher;
169 std::map<std::size_t, float> m_thresholds;
170 std::multimap<std::size_t, CachedRanking> m_cachedLegRankings;
171 std::map<ToolKey, std::size_t> m_electronSfToolIndex;
172 std::map<ToolKey, std::size_t> m_electronEffToolIndex;
173 std::map<ToolKey, std::size_t> m_photonSfToolIndex;
174 std::map<ToolKey, std::size_t> m_photonEffToolIndex;
175 std::map<ToolKey, std::size_t> m_muonToolIndex;
176 std::set<std::size_t> m_validLegTagPairs;
180 std::map<std::size_t, std::string> m_dictionary;
181 std::set<ToolKey> m_unsupportedLegs;
182
183 std::vector<Hierarchy> m_hierarchyMeta;
184 std::vector<std::size_t> m_hierarchyData;
185
186 bool m_initialized = false;
188 unsigned long m_seed;
190
191 std::vector<TagDecorator> m_leptonTagDecorators;
193 std::unique_ptr<TrigGlobEffCorr::Calculator> m_calculator;
194
195 template <typename Key>
196 using flat_set = boost::container::flat_set<Key>;
197
200 template <class CPTool>
202 ToolHandleArray<CPTool>& suppliedTools,
203 std::map<ToolKey, std::size_t>& toolIndex,
204 flat_set<std::size_t>& collectedTags);
206 const std::string& inputList,
207 bool& success);
208 bool parseTagString(const std::string& tagstring,
211 bool useDefaultElectronTools,
212 bool useDefaultPhotonTools);
213 bool loadTagDecorators(const flat_set<std::size_t>& collectedElectronTags,
214 const flat_set<std::size_t>& collectedMuonTags,
215 const flat_set<std::size_t>& collectedPhotonTags);
218
220 bool retrieveRunNumber(unsigned& runNumber);
221 bool retrieveEventNumber(unsigned long& eventNumber);
222 bool aboveThreshold(const TrigGlobEffCorr::Lepton& p, std::size_t leg) const;
223 template <class... ListOfLegs>
224 unsigned long getCachedTriggerLegsRanking(
225 const TrigGlobEffCorr::Lepton& lepton, ListOfLegs... legs);
227 const flat_set<std::size_t>& legs,
228 bool& success);
229 std::size_t getLoosestLeg(const TrigGlobEffCorr::Lepton& lepton,
230 std::size_t leg1, std::size_t leg2, bool& success);
231 std::pair<std::size_t, std::size_t> getTwoLoosestLegs(
232 const TrigGlobEffCorr::Lepton& lepton, const flat_set<std::size_t>& legs,
233 bool& success);
234 std::vector<std::size_t> getSortedLegs(const TrigGlobEffCorr::Lepton& lepton,
235 const flat_set<std::size_t>& legs,
236 bool& success);
237 template <class Container>
239 template <class Particle>
240 bool updateLeptonList(LeptonList& leptons,
241 const std::vector<const Particle*>& particles);
242 void updateMuonTriggerNames(std::size_t leg, const std::string& name);
245 const xAOD::Electron* p, unsigned runNumber, std::size_t leg,
246 std::size_t tag, TrigGlobEffCorr::Efficiencies& efficiencies);
248 const xAOD::Muon* p, unsigned runNumber, std::size_t leg, std::size_t tag,
249 TrigGlobEffCorr::Efficiencies& efficiencies);
251 const xAOD::Photon* p, unsigned runNumber, std::size_t leg,
252 std::size_t tag, TrigGlobEffCorr::Efficiencies& efficiencies);
253 template <class ParticleType>
255 const ParticleType* p, unsigned runNumber, std::size_t leg,
256 std::size_t tag, TrigGlobEffCorr::Efficiencies& efficiencies);
287 std::size_t getCombinedHash(const flat_set<std::size_t>& legs);
288 std::size_t getCombinedHash(std::size_t leg1, std::size_t leg2);
289 static inline constexpr const flat_set<std::size_t>& forwardLegs(
290 const flat_set<std::size_t>& legs);
291 static inline constexpr std::array<std::size_t, 2> forwardLegs(
292 std::size_t leg1, std::size_t leg2);
293
295 inline bool checkAndRecord(CP::CorrectionCode&& cc);
297 bool& success);
298
302};
303
304#endif
#define ASG_TOOL_CLASS(CLASSNAME, INT1)
Base class for elements of a container that can have aux data.
boost::container::flat_set< Key > flat_set
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
ParticleType
Definition TruthClasses.h:8
Return value from object correction CP tools.
@ Ok
The correction was done successfully.
Class to wrap a set of SystematicVariations.
storage of the time histories of all the cells
SG::ConstAccessor< T, ALLOC > ConstAccessor
Definition AuxElement.h:569
std::size_t getLoosestLeg(const TrigGlobEffCorr::Lepton &lepton, std::size_t leg1, std::size_t leg2, bool &success)
bool loadHierarchies()
Internal methods (I) – initialization of the tool.
std::map< ToolKey, std::size_t > m_electronSfToolIndex
decltype(m_electronEffToolIndex) & GetEfficiencyToolIndex(const xAOD::Electron *)
std::unique_ptr< TrigGlobEffCorr::Calculator > m_calculator
void updateMuonTriggerNames(std::size_t leg, const std::string &name)
ToolHandleArray< IAsgPhotonEfficiencyCorrectionTool > m_suppliedPhotonScaleFactorTools
virtual CP::CorrectionCode getEfficiencyScaleFactor(const std::vector< const xAOD::IParticle * > &particles, double &efficiencyScaleFactor) override
std::vector< TrigGlobEffCorr::Lepton > LeptonList
bool checkAndRecord(CP::CorrectionCode &&cc)
Internal methods (III) – misc. helpers.
flat_set< ToolKey > parseListOfLegs(TrigGlobEffCorr::ImportData &data, const std::string &inputList, bool &success)
std::multimap< std::size_t, CachedRanking > m_cachedLegRankings
virtual CP::CorrectionCode checkTriggerMatching(bool &matched, const std::vector< const xAOD::IParticle * > &particles) override
std::map< std::string, std::string > m_overrideThresholds
virtual CP::SystematicSet recommendedSystematics() const override
the list of all systematics this tool recommends to use
std::map< std::string, std::string > m_muonLegsPerTag
deprecated
decltype(m_photonEffToolIndex) & GetEfficiencyToolIndex(const xAOD::Photon *)
bool parseTagString(const std::string &tagstring, flat_set< std::size_t > &tags)
ToolHandleArray< IAsgPhotonEfficiencyCorrectionTool > m_suppliedPhotonEfficiencyTools
std::map< std::string, std::string > m_tagsPerTool
std::size_t getCombinedHash(const flat_set< std::size_t > &legs)
std::map< ToolKey, std::size_t > m_photonEffToolIndex
std::vector< std::size_t > getSortedLegs(const TrigGlobEffCorr::Lepton &lepton, const flat_set< std::size_t > &legs, bool &success)
virtual StatusCode applySystematicVariation(const CP::SystematicSet &systConfig) override
effects: configure this tool for the given list of systematic variations.
std::map< std::size_t, std::string > m_dictionary
virtual CP::CorrectionCode countTriggerLegs(const std::string &trigger, std::size_t &numberOfLegs) override
This utility function provides the number of legs for the specified trigger.
IAsgElectronEfficiencyCorrectionTool & GetEfficiencyTool(const xAOD::Electron *, std::size_t index)
decltype(m_electronSfToolIndex) & GetScaleFactorToolIndex(const xAOD::Electron *)
static CP::CorrectionCode suggestPhotonMapKeys(const std::map< std::string, std::string > &triggerCombination, const std::string &version, std::map< std::string, std::string > &legsPerKey)
virtual CP::CorrectionCode getRelevantTriggers(std::vector< std::string > &triggers) override
This will fill the 'triggers' argument with the names of the triggers relevant for the current run nu...
flat_set< std::size_t > listNonOrderedCSValues(const std::string &s, bool &success)
Parses the input string (comma-separated list) and returns a set of hashes Watch out: since a flat_se...
std::map< std::string, std::string > m_triggerCb
std::pair< std::size_t, std::size_t > getTwoLoosestLegs(const TrigGlobEffCorr::Lepton &lepton, const flat_set< std::size_t > &legs, bool &success)
bool loadTagDecorators(const flat_set< std::size_t > &collectedElectronTags, const flat_set< std::size_t > &collectedMuonTags, const flat_set< std::size_t > &collectedPhotonTags)
bool enumerateTools(TrigGlobEffCorr::ImportData &data, ToolHandleArray< CPTool > &suppliedTools, std::map< ToolKey, std::size_t > &toolIndex, flat_set< std::size_t > &collectedTags)
bool aboveThreshold(const TrigGlobEffCorr::Lepton &p, std::size_t leg) const
SG::AuxElement::ConstAccessor< unsigned int > m_runNumberDecorator
std::map< std::string, std::string > m_electronLegsPerTag
TLE_RESULT getTriggerLegEfficiencies(const xAOD::Electron *p, unsigned runNumber, std::size_t leg, std::size_t tag, TrigGlobEffCorr::Efficiencies &efficiencies)
TLE_RESULT getEgammaTriggerLegEfficiencies(const ParticleType *p, unsigned runNumber, std::size_t leg, std::size_t tag, TrigGlobEffCorr::Efficiencies &efficiencies)
IAsgPhotonEfficiencyCorrectionTool & GetEfficiencyTool(const xAOD::Photon *, std::size_t index)
static constexpr const flat_set< std::size_t > & forwardLegs(const flat_set< std::size_t > &legs)
virtual CP::SystematicSet affectingSystematics() const override
the list of all systematics this tool can be affected by
IAsgPhotonEfficiencyCorrectionTool & GetScaleFactorTool(const xAOD::Photon *, std::size_t index)
bool loadTriggerCombination(TrigGlobEffCorr::ImportData &data, bool useDefaultElectronTools, bool useDefaultPhotonTools)
virtual CP::CorrectionCode getEfficiency(const std::vector< const xAOD::IParticle * > &particles, double &efficiencyData, double &efficiencyMc) override
bool retrieveRunNumber(unsigned &runNumber)
Internal methods (II) – core task.
CachedRanking rankTriggerLegs(float pt, const Container &legs)
std::map< std::string, std::string > m_triggerCbPerYear
static CP::CorrectionCode suggestEgammaMapKeys(const std::map< std::string, std::string > &triggerCombination, const std::string &version, std::map< std::string, std::string > &legsPerKey, xAOD::Type::ObjectType type)
ToolHandleArray< IAsgElectronEfficiencyCorrectionTool > m_suppliedElectronEfficiencyTools
Properties:
decltype(m_photonSfToolIndex) & GetScaleFactorToolIndex(const xAOD::Photon *)
std::map< ToolKey, std::size_t > m_electronEffToolIndex
ToolHandleArray< CP::IMuonTriggerScaleFactors > m_suppliedMuonTools
unsigned long getCachedTriggerLegsRanking(const TrigGlobEffCorr::Lepton &lepton, ListOfLegs... legs)
std::size_t getLoosestLegAboveThreshold(const TrigGlobEffCorr::Lepton &lepton, const flat_set< std::size_t > &legs, bool &success)
bool updateLeptonList(LeptonList &leptons, const std::vector< const Particle * > &particles)
IAsgElectronEfficiencyCorrectionTool & GetScaleFactorTool(const xAOD::Electron *, std::size_t index)
virtual ASG_TOOL_CLASS(TrigGlobalEfficiencyCorrectionTool, ITrigGlobalEfficiencyCorrectionTool) TrigGlobalEfficiencyCorrectionTool(const std ~TrigGlobalEfficiencyCorrectionTool()
std::map< std::string, std::string > m_legsPerTag
deprecated
std::map< std::string, std::string > m_legsPerTool
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
virtual bool isAffectedBySystematic(const CP::SystematicVariation &systematic) const override
Declare the interface that this class provides.
ToolHandleArray< IAsgElectronEfficiencyCorrectionTool > m_suppliedElectronScaleFactorTools
static CP::CorrectionCode suggestElectronMapKeys(const std::map< std::string, std::string > &triggerCombination, const std::string &version, std::map< std::string, std::string > &legsPerKey)
Base class for the dual-use tool implementation classes.
Definition AsgTool.h:47
std::vector< std::string > tags
Definition hcg.cxx:105
the template specializations below must be enclosed in this namespace
Definition index.py:1
ObjectType
Type of objects that have a representation in the xAOD EDM.
Definition ObjectType.h:32
@ Photon
The object is a photon.
Definition ObjectType.h:47
@ Electron
The object is an electron.
Definition ObjectType.h:46
Muon_v1 Muon
Reference the current persistent version:
Photon_v1 Photon
Definition of the current "egamma version".
Electron_v1 Electron
Definition of the current "egamma version".
TagDecorator(const std::string &name, std::size_t the_hash, bool suffixed)
ToolKey(std::size_t leg, std::size_t tag, unsigned runNumber)
ToolKey(std::size_t leg, std::size_t tag, std::pair< unsigned, unsigned > bounds)