ATLAS Offline Software
Loading...
Searching...
No Matches
RatesTrigger.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
7
8RatesTrigger::RatesTrigger(const std::string& name, IMessageSvc* msgSvc, const double prescale, const double expressPrescale,
9 const std::string& seedName, const double seedPrescale, const bool doHistograms,
10 const ExtrapStrat_t extrapolation) :
11 RatesHistoBase(name, msgSvc, doHistograms),
12 m_pass(false),
13 m_active(false),
14 m_seedsFromRandom(false),
19 m_ratesActive(0.),
21 m_CPSID(0),
23 m_uniqueGroup(nullptr),
24 m_name(name),
25 m_seed(seedName),
26 m_nameHash(std::hash<std::string>{}(name)),
27 m_seedHash(std::hash<std::string>{}(seedName)),
28 m_prescale(prescale < 1. ? -1 : prescale),
29 m_expressPrescale(expressPrescale < 1. ? -1 : expressPrescale),
30 m_seedPrescale(seedPrescale < 1. ? -1 : seedPrescale),
31 m_totalPrescaleWeight(1. / (m_prescale * m_seedPrescale)),
32 m_totalPrescaleWeightExpress(1. / (m_prescale * m_seedPrescale * m_expressPrescale)),
33 m_extrapolationStrategy(extrapolation)
34 {}
35
37
38void RatesTrigger::setPassed(const bool passed, const bool active, const bool unbiasedEvent) {
39 if (m_seedsFromRandom == true && unbiasedEvent == false) return;
40 if (m_active && !m_pass) throw std::runtime_error("Cannot pass if not active");
41 m_pass = passed;
42 m_active = active;
43}
44
45void RatesTrigger::setPassedAndExecute(const bool passed, const bool active, const WeightingValuesSummary_t& weights) {
46 if (m_seedsFromRandom == true && weights.m_isUnbiased == false) return;
47 if (m_pass == false && m_active == false) { // Protect against two positive calls/event
48 if (m_active && !m_pass) throw std::runtime_error("Cannot pass if not active");
49 m_pass = passed;
50 m_active = active;
52 }
53}
54
55
57 // Efficiency
58 if (getDisabled()) {
59 return;
60 }
61
62 const double w_noLScale = m_totalPrescaleWeight * weights.m_enhancedBiasWeight;
63 const double w = w_noLScale * getExtrapolationFactor(weights, m_extrapolationStrategy);
65
66 if (m_active) {
67 m_ratesActive += w;
68 m_ratesActive2 += w * w;
69 if (m_dataCachedPtr != nullptr) {
72 }
73 }
74
75 if (m_pass) {
76 // The vs. mu histogram is a property of the INPUT event so we don't apply any L scaling here
77 if (m_rateVsMuCachedPtr != nullptr) m_rateVsMuCachedPtr->Fill(weights.m_eventMu, w_noLScale);
78 // The vs. position in train is agnostic to INPUT event & TARGET conditions - i.e. the bunch train structure is not
79 // re-weighted in any way. Hence we can apply whatever extrapolation strategy we want here.
80 if (m_rateVsTrainCachedPtr != nullptr) m_rateVsTrainCachedPtr->Fill(weights.m_distanceInTrain, w);
82 m_rateAccumulator2 += w * w;
83 if (m_dataCachedPtr != nullptr) {
86 }
87 if (m_expressPrescale >= 1) {
89 m_rateExpressAccumulator2 += wExp * wExp;
91 }
92 }
93}
94
98
99double RatesTrigger::getPrescale(const bool includeExpress) const {
100 if (includeExpress) return m_prescale * m_expressPrescale;
101 return m_prescale;
102}
103
104const std::string RatesTrigger::printConfig() const {
105 std::stringstream ss;
106 ss << std::setfill(' ')
107 << "Prescale:" << std::setw(11) << std::left << m_prescale
108 << " xpress:" << std::setw(11) << std::left << m_expressPrescale
109 << " CPSID:" << std::setw(11) << std::left << m_CPSID
110 << " seedPS:" << std::setw(11) << std::left << m_seedPrescale
111 << " : " << (m_seed != "" ? m_seed : "") << (m_seed != "" ? " -> " : "") << m_name;
112 return ss.str();
113}
114
115const std::string RatesTrigger::printRate(const double ratesDenominator) const {
116 std::stringstream ss;
117 ss << std::setfill(' ');
118 ss << "Rate: " << std::setw(11) << std::right << m_rateAccumulator/ratesDenominator
119 << " +- " << std::setw(11) << std::left << sqrt(m_rateAccumulator2)/ratesDenominator << " Hz";
120 if (m_uniqueGroup != nullptr) {
121 const double unique = (getDisabled() == true ? 0. : m_uniqueGroup->getUniqueWeight(ratesDenominator));
122 //const double unique = m_uniqueGroup->m_rateAccumulatorOR / ratesDenominator; // For dbg - this is the rate of N-1
123 // Getting the fractional error of refgular rate and applying it to the unique rate
124 const double uniqueErr = (isZero(m_rateAccumulator) ? 0. : (sqrt(m_rateAccumulator2)/m_rateAccumulator) * unique);
125 ss << ", Unique Rate: " << std::setw(11) << std::right << unique
126 << " +- " << std::setw(11) << std::left << uniqueErr << " Hz";
127 }
128 ss << " : ";
129 ss << m_name << " [PS:" << m_prescale << "]";
130 if (m_seed != "") ss << " <- " << m_seed << " [PS:" << m_seedPrescale << "]";
132 return ss.str();
133}
134
135const std::string RatesTrigger::printExpressRate(const double ratesDenominator) const {
136 std::stringstream ss;
137 ss << std::setfill(' ');
138 ss << "Express Rate: " << std::setw(11) << std::right << m_rateExpressAccumulator/ratesDenominator
139 << " +- " << std::setw(11) << std::left << sqrt(m_rateExpressAccumulator2)/ratesDenominator << " Hz";
140 ss << " : ";
141 ss << m_name << " [PS:" << m_prescale << "] [EXPRESS PS:" << m_expressPrescale << "]";
142 if (m_seed != "") ss << " <- " << m_seed << " [PS:" << m_seedPrescale << "]";
144 return ss.str();
145}
146
147void RatesTrigger::reset() { m_pass = false; m_active = false; }
148
150
151size_t RatesTrigger::getSeedHash() const { return m_seedHash; }
152
153const std::string& RatesTrigger::getSeedName() const { return m_seed; }
154
156
157size_t RatesTrigger::getHash() const { return m_nameHash; }
158
159const std::string& RatesTrigger::getName() const { return m_name; }
160
161bool RatesTrigger::getPassed() const { return m_pass; }
162
163bool RatesTrigger::getActive() const { return m_active; }
164
166
167void RatesTrigger::setUniqueGroup(const RatesGroup* unique) { m_uniqueGroup = unique; }
168
169void RatesTrigger::setCoherentFactor(const double lowestCommonPrescale) { m_coherentFactor = lowestCommonPrescale; }
170
171void RatesTrigger::setCPS(const std::string& group) { m_CPSID = std::hash<std::string>{}(group); }
172
173size_t RatesTrigger::getCPSID() const { return m_CPSID; }
174
bool passed(DecisionID id, const DecisionIDContainer &)
checks if required decision ID is in the set of IDs in the container
static Double_t ss
@ kPASS_RAW_BIN
Bin used to store the raw total events in which the trigger passed.
@ kEXPRESS_BIN
Bin used to store the express rate.
@ kPASS_WEIGHTED_OR_BIN
Bin used to store the total rate (OR)
@ kACTIVE_RAW_BIN
Bin used to store the raw total events in which the trigger was active.
@ kACTIVE_WEIGHTED_BIN
Bin used to store the weighted events in which the trigger was active.
ExtrapStrat_t
Extrapolation strategy to apply to each emulated trigger.
Used to calculate the rate for a group of RatesTrigger objects at L1 or the HLT.
Definition RatesGroup.h:29
const std::string & getExtrapolationFactorString(ExtrapStrat_t strat) const
double getExtrapolationFactor(const WeightingValuesSummary_t &weights, const ExtrapStrat_t strat) const
bool doHistograms() const
If histogramming was enabled in this rates object.
TH1 * m_rateVsTrainCachedPtr
Cached, non-owning pointer.
RatesHistoBase(const std::string &name, IMessageSvc *msgSvc, const bool doHistograms=true)
TH1 * m_rateVsMuCachedPtr
Cached, non-owning pointer.
static bool isNotPositive(double v)
static bool isZero(double v)
TH1 * m_dataCachedPtr
Cached, non-owning pointer.
bool m_seedsFromRandom
Does this trigger seed from a random trigger?
const std::string & getSeedName() const
Get the name of the seed of this trigger.
double m_ratesActive
bool m_active
Was the trigger active?
void setUniqueGroup(const RatesGroup *unique)
If I have a group which is calculating my unique rate.
bool getPassed() const
If the trigger passed in the event.
const double m_expressPrescale
My express stream prescale factor, gets applied on top of the regular prescale.
const std::string m_seed
My seed, "" if no seed.
double m_rateAccumulator
Weighted events passed.
size_t m_CPSID
If I'm in a coherent prescale group, my group's ID (hash of the group name)
bool getActive() const
If the trigger passed in the event.
const ExtrapStrat_t m_extrapolationStrategy
How this trigger is to scale with luminosity.
void setPassed(const bool passed=true, const bool active=true, const bool unbiasedEvent=false)
Set the pass/fail bool.
const std::string m_name
My name.
double getCoherentFactor() const
Get the lowest common prescale factor of all triggers in my CPS group.
const std::string printConfig() const
Prints the RatesTrigger's configuration.
double getSeedPrescale() const
Get the prescale of the seed of this trigger.
void setSeedsFromRandom(const bool i)
Set if this trigger is to behave as if it seeds from a random L1 item.
const RatesGroup * m_uniqueGroup
Pointer to the group which is calculating my unique rate.
void setCPS(const std::string &group)
If I'm in a CPS group, set the group name (I'll keep a copy of the hash)
size_t getHash() const
Get the hash of the name of this trigger.
size_t getSeedHash() const
double m_rateExpressAccumulator2
Weighted express stream events squared.
const size_t m_nameHash
Hash of my name.
virtual const std::string printRate(const double ratesDenominator) const
Prints the RatesTrigger's rate.
void setCoherentFactor(const double lowestCommonPrescale)
If i'm in a CPS group, set the lowest commons PS factor of the group.
double m_ratesActive2
bool getDisabled() const
If I or my seed were prescaled out.
const std::string printExpressRate(const double ratesDenominator) const
Prints the RatesTrigger's express rate.
const double m_totalPrescaleWeightExpress
Equal to 1/m_seedPrescale*m_prescale*m_expressPrescale.
virtual void reset()
If I was used in an event, reset me.
RatesTrigger(const std::string &name, IMessageSvc *log, const double prescale=1., const double expressPrescale=-1, const std::string &seedName="", const double seedPrecale=1., const bool doHistograms=true, const ExtrapStrat_t extrapolation=ExtrapStrat_t::kLINEAR)
Construct new RatesTrigger to enumerate the rate for a single L1 or HLT trigger Provide pass/fail inf...
double m_coherentFactor
If I'm in a coherent prescale group, the prescale of the lowest non-disabled chain in the group.
const double m_totalPrescaleWeight
Equal to 1/m_seedPrescale*m_prescale.
virtual void execute(const WeightingValuesSummary_t &weights)
Execute trigger rate emulation.
double getPrescale(const bool includeExpress=false) const
Gets the triggers prescale.
bool m_pass
Did the trigger pass or not?
void setPassedAndExecute(const bool passed, const bool active, const WeightingValuesSummary_t &weights)
Set the pass/fail bool and immediately call execute.
double m_rateExpressAccumulator
Weighted express stream events.
double m_rateAccumulator2
Weighted events passed squared.
const double m_seedPrescale
const size_t m_seedHash
Has of my seed name.
size_t getCPSID() const
Get the hash of my CPS group name.
const double m_prescale
My prescale factor.
double getTotalPrescaleWeight() const
const std::string & getName() const
Get the name of this trigger.
STL class.
STL namespace.
Structure to hold per-event weights for distribution.