ATLAS Offline Software
Loading...
Searching...
No Matches
RatesAnalysisAlg.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 RATESANALYSIS_RATESANALYSISALG_H
6#define RATESANALYSIS_RATESANALYSISALG_H 1
7
10
12
14
15#include "Gaudi/Parsers/Factory.h" // Gaudi::Property<std::map<std::string, std::map<std::string, double>>>
16
17#include "RatesTrigger.h"
18#include "RatesScanTrigger.h"
19#include "RatesGroup.h"
20
21#include "TTree.h"
22
23#include <unordered_set>
24
25namespace TrigConf {
26 class ITrigConfigSvc;
27}
28
38 public:
48
49 RatesAnalysisAlg( const std::string& name, ISvcLocator* pSvcLocator );
50 virtual ~RatesAnalysisAlg();
51 virtual StatusCode ratesInitialize() = 0;
52 virtual StatusCode ratesExecute() = 0;
53 virtual StatusCode ratesFinalize() = 0;
54
58 StatusCode newTrigger(const std::string& name,
59 const double prescale = 1.,
60 const double expressPrescale = -1.,
61 const std::string& seedName = "",
62 const double seedPrecale = 1.,
63 const std::string& groups = "",
64 const Method_t method = kMANUAL,
65 const ExtrapStrat_t extrapolation = kLINEAR);
66
78 StatusCode newTrigger(const std::string& name,
79 const double prescale = 1.,
80 const double expressPrescale = -1.,
81 const std::string& seedName = "",
82 const double seedPrecale = 1.,
83 const std::set<std::string>& groups = std::set<std::string>(),
84 const Method_t method = kMANUAL,
85 const ExtrapStrat_t extrapolation = kLINEAR);
86
100 StatusCode newScanTrigger(const std::string& name,
101 const double thresholdMin,
102 const double thresholdMax,
103 const uint32_t thresholdBins = 100,
105 const double prescale = 1.,
106 const std::string& seedName = "",
107 const double seedPrecale = 1.,
108 const Method_t method = kMANUAL,
109 const ExtrapStrat_t extrapolation = kLINEAR);
110
115 StatusCode newScanTrigger(const std::string& name,
116 const std::vector<double>& thresholdBinEdges,
118 const double prescale = 1.,
119 const std::string& seedName = "",
120 const double seedPrecale = 1.,
121 const Method_t method = kMANUAL,
122 const ExtrapStrat_t extrapolation = kLINEAR);
123
124
125 StatusCode addAllExisting();
126
131 StatusCode addExisting(const std::string& pattern);
132
138 StatusCode setTriggerDesicison(const std::string& name, const bool triggerIsPassed = true, const bool triggerIsActive = true);
139
145 StatusCode setTriggerDesicison(const std::string& name, const double threshold);
146
152 void setTargetLumiMu(const double lumi, const double mu);
153
159 void setTargetLumiBunches(const double lumi, const int32_t bunches);
160
166 void setTargetMuBunches(const double mu, const int32_t bunches);
167
173
179
185
186 protected:
187 virtual StatusCode initialize();
191 Gaudi::Property<bool> m_doHistograms{this, "DoHistograms", true, "Switch on histogram output of rate vs. mu and position in train."};
192 Gaudi::Property<bool> m_doMultiSliceDiJet{this, "DoMultiSliceDiJet", false, "Enable the HS-softer-than-PU (HSTP) filter; reweight the Slices according to Jet/ETMiss procedure; recommended by PMG for di-jet slices."};
193 StatusCode pass_HstpFilter(bool &pass);
194 virtual StatusCode initialize_extra_content();
195 std::unordered_map<std::string, std::unique_ptr<RatesTrigger>> m_triggers;
196 const std::unordered_map<std::string, std::unique_ptr<RatesTrigger>>& getTriggerMap() const;
197
198 private:
199
200 virtual StatusCode execute();
201 virtual StatusCode finalize();
202
203 StatusCode populateTriggers();
205 StatusCode executeTriggerEmulation();
206
213 StatusCode checkExistingTrigger(const std::string& name, const std::string& seedName);
214 StatusCode checkGotTDT();
215
220 void printInputSummary() const;
221
222 void printStatistics() const;
223 void printTarget() const;
224 void writeMetadata();
225
226
232 bool isCPS(const std::string& group) const;
233
240 bool isRandomSeed(const std::string& me, const std::string& seed) const;
241
246 uint32_t getLevel(const std::string& name) const;
247
248 bool isZero(double v) const { return fabs(v) < 1e-10; }
249
250 std::unordered_map<std::string, std::unique_ptr<RatesScanTrigger>> m_scanTriggers;
251 std::unordered_map<std::string, std::unique_ptr<RatesGroup>> m_groups;
252 std::unordered_map<std::string, std::unique_ptr<RatesGroup>> m_globalGroups;
253 std::unordered_map<std::string, std::unique_ptr<RatesGroup>> m_uniqueGroups;
254
255 std::unordered_set<RatesTrigger*> m_activatedTriggers;
256 std::unordered_set<RatesTrigger*> m_expressTriggers;
257 std::unordered_set<RatesGroup*> m_activeGroups;
258 std::unordered_map<size_t, double> m_lowestPrescale;
259 std::vector<std::string> m_autoTriggers;
260
261 std::unordered_map<std::string, const Trig::ChainGroup*> m_existingTriggers;
262 std::unordered_map<std::string, std::string> m_lowerTrigger;
263
264 std::vector<std::vector<std::string>> m_hltChainIDGroup;
265 std::vector<std::vector<std::string>> m_l1ItemID;
266
267 const std::string m_l1GroupName = "L1";
268 const std::string m_l2GroupName = "HLT";
269 const std::string m_expressGroupName = "Express";
270
271 ToolHandle<IEnhancedBiasWeighter> m_enhancedBiasRatesTool{this, "EnhancedBiasRatesTool", "EnhancedBiasWeighter/EnhancedBiasRatesTool"};
272 ToolHandle<Trig::TrigDecisionTool> m_tdt{this, "TrigDecisionTool", "Trig::TrigDecisionTool/TrigDecisionTool"};
273 ServiceHandle<TrigConf::ITrigConfigSvc> m_configSvc{this, "TrigConfigSvc", "TrigConf::xAODConfigSvc"};
274
275 SG::ReadHandleKey<xAOD::EventInfo> m_eventInfoKey{this, "EventInfo", "EventInfo", "EventInfo name"};
276 SG::ReadHandleKey<xAOD::JetContainer> m_truthHS_jets_RHKey{this, "TruthHSJetsKey", "AntiKt4TruthJets", "Key for the hard scatter truth jet collection"};
277 SG::ReadHandleKey<xAOD::JetContainer> m_truthPU_jets_RHKey{this, "truthPUJetsKey", "InTimeAntiKt4TruthJets", "Key for the pileup jet collection"};
278
279 Gaudi::Property<double> m_expoScalingFactor{this, "ExpoScalingFactor", 0.1, "Optional. Exponential factor if using exponential-mu rates scaling."};
280 Gaudi::Property<double> m_inelasticCrossSection{this, "InelasticCrossSection", 8e-26, "Inelastic cross section in units cm^2. Default 80 mb at 13 TeV."};
281 Gaudi::Property<bool> m_doUniqueRates{this, "DoUniqueRates", false, "Calculate unique rates for all chains (slow). Requires DoGlobalGroups=True too."};
282 Gaudi::Property<bool> m_doGlobalGroups{this, "DoGlobalGroups", false, "Calculate total rates for each trigger level."};
283 Gaudi::Property<bool> m_doTriggerGroups{this, "DoTriggerGroups", false, "Calculate total rates for each group of triggers."};
284 Gaudi::Property<bool> m_doExpressRates{this, "DoExpressRates", false, "Calculate total rates for the express stream."};
285 Gaudi::Property<bool> m_useBunchCrossingData{this, "UseBunchCrossingData", true, "BunchCrossing data requires CONDBR2 access. Can be disabled here if this is a problem."};
286 Gaudi::Property<bool> m_currentEventIsUnbiased;
287 Gaudi::Property<bool> m_enableLumiExtrapolation{this, "EnableLumiExtrapolation", true, "If false then no extrapolation in L, N_bunch or <mu> will be performed.."};
288 Gaudi::Property<uint32_t> m_vetoStartOfTrain{this, "VetoStartOfTrain", 0, "How many BCID to veto at the start of a bunch train."};
289 Gaudi::Property<std::map<std::string, std::map<std::string, double>>> m_prescalesJSON{this, "PrescalesJSON", {}, "Optional JSON of prescales from the TrigMenuRuleBook to apply."};
290 Gaudi::Property<std::string> m_histogramSuffix{this, "histogramSuffix", "", "Optional suffix to add to the name of the rate denominator histogram."};
291
292 double m_targetMu;
295 uint32_t m_runNumber;
296 uint32_t m_eventCounter;
298
301
303
304};
305
306#endif //> !RATESANALYSIS_RATESANALYSISALG_H
ExtrapStrat_t
Extrapolation strategy to apply to each emulated trigger.
@ kLINEAR
Scale trigger linearly with luminosity.
AthAnalysisAlgorithm(const std::string &name)
Constructor taking just a name.
static constexpr uint32_t FULL_RING
Number of bunches in a full ring.
TH1D * m_bcidHist
Histogram of the BCIDs distribution of the processing.
Method_t
Method by which the trigger pass/fail decision is calculated.
@ kMANUAL
The pass/fail decision is evaluated by the user and supplied per event using setTriggerDesicison.
@ kAUTO
The pass/fail decision is automatically emulated per event based on decoding the trigger name.
@ kEXISTING
The pass/fail decision is taken from the Trigger Decision Tool for an existing trigger.
StatusCode executeTrigDecisionToolTriggers()
Internal call to get the pass/fail for all TDT triggers.
void setTargetLumiBunches(const double lumi, const int32_t bunches)
Set the target instantaneous luminosity and number of bunches.
std::unordered_map< std::string, std::unique_ptr< RatesGroup > > m_uniqueGroups
Groups used to obtain unique rates for chains.
const std::string m_l2GroupName
double m_targetBunches
How many bunches the prediction is targeting.
RatesAnalysisAlg(const std::string &name, ISvcLocator *pSvcLocator)
void printInputSummary() const
Print the input data instantaneous luminosity, mu and number of bunches.
virtual StatusCode ratesInitialize()=0
To be implemented by the user.
uint32_t m_runNumber
What is the RunNumber.
std::unordered_set< RatesTrigger * > m_activatedTriggers
Triggers which were changed & hence need to be reset at the event end.
ServiceHandle< TrigConf::ITrigConfigSvc > m_configSvc
void printStatistics() const
Print some extra statistics on events processed.
SG::ReadHandleKey< xAOD::JetContainer > m_truthHS_jets_RHKey
Gaudi::Property< bool > m_doHistograms
Gaudi::Property< bool > m_doUniqueRates
uint32_t getLevel(const std::string &name) const
String match to a trigger level.
Gaudi::Property< double > m_expoScalingFactor
SG::ReadHandleKey< xAOD::JetContainer > m_truthPU_jets_RHKey
StatusCode setTriggerDesicison(const std::string &name, const bool triggerIsPassed=true, const bool triggerIsActive=true)
Set the pass/fail decision for an item.
std::unordered_set< RatesTrigger * > m_expressTriggers
Triggers with non-zero express PS, used to print them at the end.
double m_ratesDenominator
How much walltime is seen by the algorithm.
double m_targetLumi
What instantaneous luminosity the prediction is targeting.
virtual StatusCode finalize()
Print rates.
Gaudi::Property< bool > m_doMultiSliceDiJet
double m_weightedEventCounter
Count how many weighted events were processed.
Gaudi::Property< bool > m_doExpressRates
std::unordered_map< size_t, double > m_lowestPrescale
Lowest prescale within a CPS group, key is the hash of the CPS group name.
TTree * m_metadataTree
Used to write out some metadata needed by post-processing (e.g.
void setTargetLumiMu(const double lumi, const double mu)
Set the target instantaneous luminosity and mu.
bool isRandomSeed(const std::string &me, const std::string &seed) const
String match random L1 items.
std::unordered_map< std::string, std::unique_ptr< RatesGroup > > m_globalGroups
Big (master) groups which do the OR of the whole menu.
std::vector< std::vector< std::string > > m_hltChainIDGroup
std::unordered_map< std::string, std::unique_ptr< RatesGroup > > m_groups
All regular and CPS groups.
std::unordered_map< std::string, const Trig::ChainGroup * > m_existingTriggers
Map of triggers which we ask the TDT ChainGroup for the pass/fail.
virtual StatusCode ratesFinalize()=0
To be implemented by the user.
Gaudi::Property< bool > m_useBunchCrossingData
Gaudi::Property< std::string > m_histogramSuffix
const std::unordered_map< std::string, std::unique_ptr< RatesTrigger > > & getTriggerMap() const
virtual StatusCode execute()
In first call - register all triggers.
StatusCode populateTriggers()
Register all triggers to emulate.
StatusCode pass_HstpFilter(bool &pass)
Boolean indicating if the event passes the HS-softer-than-PU (HSTP) filter.
const std::string m_expressGroupName
WeightingValuesSummary_t m_weightingValues
Possible weighting & lumi extrapolation values for the current event.
StatusCode checkExistingTrigger(const std::string &name, const std::string &seedName)
Internal function to check if a supplied HLT trigger and L1 seed match what is stored in the AOD conf...
void setTargetMuBunches(const double mu, const int32_t bunches)
Set the target mu and number of bunches.
StatusCode checkGotTDT()
Internal check that the TDT is fetched.
virtual StatusCode ratesExecute()=0
To be implemented by the user.
Gaudi::Property< bool > m_doTriggerGroups
virtual StatusCode initialize()
Get the trigger decision tool and set up global groups.
virtual StatusCode initialize_extra_content()
Initialization of additional payload for inherited classes.
std::vector< std::vector< std::string > > m_l1ItemID
std::unordered_map< std::string, std::string > m_lowerTrigger
Map of triggers lower chain, to tell if a HLT trigger ran or not.
std::unordered_set< RatesGroup * > m_activeGroups
All groups which are enabled (PS >= 1)
bool isCPS(const std::string &group) const
String match coherent prescale groups.
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
void setTargetLumi(const double lumi)
Set the target instantaneous luminosity.
Gaudi::Property< uint32_t > m_vetoStartOfTrain
ToolHandle< Trig::TrigDecisionTool > m_tdt
Gaudi::Property< double > m_inelasticCrossSection
Gaudi::Property< bool > m_currentEventIsUnbiased
If the current event was triggered online by RDx or not.
StatusCode addExisting(const std::string &pattern)
Register some existing triggers based on wild-card match, e.g.
std::unordered_map< std::string, std::unique_ptr< RatesTrigger > > m_triggers
All individual triggers (L1 or HLT)
bool isZero(double v) const
Helper function for floating point subtraction.
std::vector< std::string > m_autoTriggers
List of triggers which it is up to us to the algorithm to work out the pass/fail for.
double m_targetMu
What pileup level the prediction is targeting.
StatusCode addAllExisting()
Register all existing triggers in the AOD into the rates algorithm.
void writeMetadata()
Write to outpute tree (if any) the metadata needed downstream.
void setTargetMu(const double mu)
Set the target pileup.
const std::string m_l1GroupName
TH1D * m_scalingHist
One-bin histogram to store the normalisation of the sample, for use in later combinations.
void setExponentialMuScalingFactor(const double f)
Set the exponential scaling factor for relevant chains.
void printTarget() const
Print the target instantaneous luminosity, mu and number of bunches.
StatusCode newTrigger(const std::string &name, const double prescale=1., const double expressPrescale=-1., const std::string &seedName="", const double seedPrecale=1., const std::string &groups="", const Method_t method=kMANUAL, const ExtrapStrat_t extrapolation=kLINEAR)
Version of newTrigger which accepts a set of group names rather than a comma separated string.
ToolHandle< IEnhancedBiasWeighter > m_enhancedBiasRatesTool
Gaudi::Property< bool > m_enableLumiExtrapolation
uint32_t m_eventCounter
Count how many events processed.
Gaudi::Property< bool > m_doGlobalGroups
Gaudi::Property< std::map< std::string, std::map< std::string, double > > > m_prescalesJSON
StatusCode newScanTrigger(const std::string &name, const double thresholdMin, const double thresholdMax, const uint32_t thresholdBins=100, const RatesScanTrigger::TriggerBehaviour_t behaviour=RatesScanTrigger::TriggerBehaviour_t::kTriggerBelowThreshold, const double prescale=1., const std::string &seedName="", const double seedPrecale=1., const Method_t method=kMANUAL, const ExtrapStrat_t extrapolation=kLINEAR)
Register a new threshold scan trigger which plots rate as a function of some dependent variable.
StatusCode executeTriggerEmulation()
Internal call to get the pass/fail for all automatically emulated triggers.
std::unordered_map< std::string, std::unique_ptr< RatesScanTrigger > > m_scanTriggers
All individual rates-scan triggers (L1 or HLT)
TriggerBehaviour_t
enum to describe if a trigger should activate for values >= or <= than the thresold
@ kTriggerBelowThreshold
Trigger for <= threshold.
@ kTriggerAboveThreshold
Trigger for >= threshold.
Property holding a SG store/key/clid from which a ReadHandle is made.
Athena interface for all service that provide L1Topo, LVL1, and HLT menu configuration information.
Forward iterator to traverse the main components of the trigger configuration.
Definition Config.h:22
Structure to hold per-event weights for distribution.