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#include "IAdditionalWeight.h"
21
22#include "TTree.h"
23
24#include <unordered_set>
25
26namespace TrigConf {
27 class ITrigConfigSvc;
28}
29
39 public:
49
50 RatesAnalysisAlg( const std::string& name, ISvcLocator* pSvcLocator );
51 virtual ~RatesAnalysisAlg();
52 virtual StatusCode ratesInitialize() = 0;
53 virtual StatusCode ratesExecute() = 0;
54 virtual StatusCode ratesFinalize() = 0;
55
59 StatusCode newTrigger(const std::string& name,
60 const double prescale = 1.,
61 const double expressPrescale = -1.,
62 const std::string& seedName = "",
63 const double seedPrecale = 1.,
64 const std::string& groups = "",
65 const Method_t method = kMANUAL,
66 const ExtrapStrat_t extrapolation = kLINEAR);
67
79 StatusCode newTrigger(const std::string& name,
80 const double prescale = 1.,
81 const double expressPrescale = -1.,
82 const std::string& seedName = "",
83 const double seedPrecale = 1.,
84 const std::set<std::string>& groups = std::set<std::string>(),
85 const Method_t method = kMANUAL,
86 const ExtrapStrat_t extrapolation = kLINEAR);
87
101 StatusCode newScanTrigger(const std::string& name,
102 const double thresholdMin,
103 const double thresholdMax,
104 const uint32_t thresholdBins = 100,
106 const double prescale = 1.,
107 const std::string& seedName = "",
108 const double seedPrecale = 1.,
109 const Method_t method = kMANUAL,
110 const ExtrapStrat_t extrapolation = kLINEAR);
111
116 StatusCode newScanTrigger(const std::string& name,
117 const std::vector<double>& thresholdBinEdges,
119 const double prescale = 1.,
120 const std::string& seedName = "",
121 const double seedPrecale = 1.,
122 const Method_t method = kMANUAL,
123 const ExtrapStrat_t extrapolation = kLINEAR);
124
125
126 StatusCode addAllExisting();
127
132 StatusCode addExisting(const std::string& pattern);
133
139 StatusCode setTriggerDesicison(const std::string& name, const bool triggerIsPassed = true, const bool triggerIsActive = true);
140
146 StatusCode setTriggerDesicison(const std::string& name, const double threshold);
147
153 void setTargetLumiMu(const double lumi, const double mu);
154
160 void setTargetLumiBunches(const double lumi, const int32_t bunches);
161
167 void setTargetMuBunches(const double mu, const int32_t bunches);
168
174
180
186
187 protected:
188 virtual StatusCode initialize();
192 Gaudi::Property<bool> m_doHistograms{this, "DoHistograms", true, "Switch on histogram output of rate vs. mu and position in train."};
193 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."};
194 StatusCode pass_HstpFilter(bool &pass);
195 virtual StatusCode initialize_extra_content();
196 std::unordered_map<std::string, std::unique_ptr<RatesTrigger>> m_triggers;
197 const std::unordered_map<std::string, std::unique_ptr<RatesTrigger>>& getTriggerMap() const;
198
199 private:
200
201 virtual StatusCode execute();
202 virtual StatusCode finalize();
203
204 StatusCode populateTriggers();
206 StatusCode executeTriggerEmulation();
207
214 StatusCode checkExistingTrigger(const std::string& name, const std::string& seedName);
215 StatusCode checkGotTDT();
216
221 void printInputSummary() const;
222
223 void printStatistics() const;
224 void printTarget() const;
225 void writeMetadata();
226
227
233 bool isCPS(const std::string& group) const;
234
241 bool isRandomSeed(const std::string& me, const std::string& seed) const;
242
247 uint32_t getLevel(const std::string& name) const;
248
249 bool isZero(double v) const { return fabs(v) < 1e-10; }
250
251 std::unordered_map<std::string, std::unique_ptr<RatesScanTrigger>> m_scanTriggers;
252 std::unordered_map<std::string, std::unique_ptr<RatesGroup>> m_groups;
253 std::unordered_map<std::string, std::unique_ptr<RatesGroup>> m_globalGroups;
254 std::unordered_map<std::string, std::unique_ptr<RatesGroup>> m_uniqueGroups;
255
256 std::unordered_set<RatesTrigger*> m_activatedTriggers;
257 std::unordered_set<RatesTrigger*> m_expressTriggers;
258 std::unordered_set<RatesGroup*> m_activeGroups;
259 std::unordered_map<size_t, double> m_lowestPrescale;
260 std::vector<std::string> m_autoTriggers;
261
262 std::unordered_map<std::string, const Trig::ChainGroup*> m_existingTriggers;
263 std::unordered_map<std::string, std::string> m_lowerTrigger;
264
265 std::vector<std::vector<std::string>> m_hltChainIDGroup;
266 std::vector<std::vector<std::string>> m_l1ItemID;
267
268 const std::string m_l1GroupName = "L1";
269 const std::string m_l2GroupName = "HLT";
270 const std::string m_expressGroupName = "Express";
271
272 ToolHandle<IEnhancedBiasWeighter> m_enhancedBiasRatesTool{this, "EnhancedBiasRatesTool", "EnhancedBiasWeighter/EnhancedBiasRatesTool"};
273 ToolHandle<Trig::TrigDecisionTool> m_tdt{this, "TrigDecisionTool", "Trig::TrigDecisionTool/TrigDecisionTool"};
274 ServiceHandle<TrigConf::ITrigConfigSvc> m_configSvc{this, "TrigConfigSvc", "TrigConf::xAODConfigSvc"};
275 ToolHandleArray<IAdditionalWeight> m_additionalWeights {this, "AdditionalWeights", {}, "Any additional reweightings to be applied directly on EB weight"};
276
277 SG::ReadHandleKey<xAOD::EventInfo> m_eventInfoKey{this, "EventInfo", "EventInfo", "EventInfo name"};
278 SG::ReadHandleKey<xAOD::JetContainer> m_truthHS_jets_RHKey{this, "TruthHSJetsKey", "AntiKt4TruthJets", "Key for the hard scatter truth jet collection"};
279 SG::ReadHandleKey<xAOD::JetContainer> m_truthPU_jets_RHKey{this, "truthPUJetsKey", "InTimeAntiKt4TruthJets", "Key for the pileup jet collection"};
280
281 Gaudi::Property<double> m_expoScalingFactor{this, "ExpoScalingFactor", 0.1, "Optional. Exponential factor if using exponential-mu rates scaling."};
282 Gaudi::Property<double> m_inelasticCrossSection{this, "InelasticCrossSection", 8e-26, "Inelastic cross section in units cm^2. Default 80 mb at 13 TeV."};
283 Gaudi::Property<bool> m_doUniqueRates{this, "DoUniqueRates", false, "Calculate unique rates for all chains (slow). Requires DoGlobalGroups=True too."};
284 Gaudi::Property<bool> m_doGlobalGroups{this, "DoGlobalGroups", false, "Calculate total rates for each trigger level."};
285 Gaudi::Property<bool> m_doTriggerGroups{this, "DoTriggerGroups", false, "Calculate total rates for each group of triggers."};
286 Gaudi::Property<bool> m_doExpressRates{this, "DoExpressRates", false, "Calculate total rates for the express stream."};
287 Gaudi::Property<bool> m_useBunchCrossingData{this, "UseBunchCrossingData", true, "BunchCrossing data requires CONDBR2 access. Can be disabled here if this is a problem."};
288 Gaudi::Property<bool> m_currentEventIsUnbiased;
289 Gaudi::Property<bool> m_enableLumiExtrapolation{this, "EnableLumiExtrapolation", true, "If false then no extrapolation in L, N_bunch or <mu> will be performed.."};
290 Gaudi::Property<uint32_t> m_vetoStartOfTrain{this, "VetoStartOfTrain", 0, "How many BCID to veto at the start of a bunch train."};
291 Gaudi::Property<std::map<std::string, std::map<std::string, double>>> m_prescalesJSON{this, "PrescalesJSON", {}, "Optional JSON of prescales from the TrigMenuRuleBook to apply."};
292 Gaudi::Property<std::string> m_histogramSuffix{this, "histogramSuffix", "", "Optional suffix to add to the name of the rate denominator histogram."};
293
294 double m_targetMu;
297 uint32_t m_runNumber;
298 uint32_t m_eventCounter;
300
301 uint32_t m_metadataMasterKey = 0;
302 uint32_t m_metadataHLTPSK = 0;
303 uint32_t m_metadataL1PSK = 0;
304 bool m_metadataKeysCached = false;
305
308
310
311};
312
313#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
uint32_t m_metadataHLTPSK
<smk read patched
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
ToolHandleArray< IAdditionalWeight > m_additionalWeights
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.
uint32_t m_metadataL1PSK
<hltpsk read patched
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.
bool m_metadataKeysCached
< l1psk read patched
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
< patched key read
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.