ATLAS Offline Software
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 
8 RatesTrigger::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),
15  m_rateAccumulator(0.),
16  m_rateAccumulator2(0.),
17  m_rateExpressAccumulator(0.),
18  m_rateExpressAccumulator2(0.),
19  m_ratesActive(0.),
20  m_ratesActive2(0.),
21  m_CPSID(0),
22  m_coherentFactor(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 
38 void 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 
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);
64  const double wExp = m_totalPrescaleWeightExpress * weights.m_enhancedBiasWeight * 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 
95 double RatesTrigger::getPrescale(const bool includeExpress) const {
96  if (includeExpress) return m_prescale * m_expressPrescale;
97  return m_prescale;
98 }
99 
100 const std::string RatesTrigger::printConfig() const {
101  std::stringstream ss;
102  ss << std::setfill(' ')
103  << "Prescale:" << std::setw(11) << std::left << m_prescale
104  << " xpress:" << std::setw(11) << std::left << m_expressPrescale
105  << " CPSID:" << std::setw(11) << std::left << m_CPSID
106  << " seedPS:" << std::setw(11) << std::left << m_seedPrescale
107  << " : " << (m_seed != "" ? m_seed : "") << (m_seed != "" ? " -> " : "") << m_name;
108  return ss.str();
109 }
110 
111 const std::string RatesTrigger::printRate(const double ratesDenominator) const {
112  std::stringstream ss;
113  ss << std::setfill(' ');
114  ss << "Rate: " << std::setw(11) << std::right << m_rateAccumulator/ratesDenominator
115  << " +- " << std::setw(11) << std::left << sqrt(m_rateAccumulator2)/ratesDenominator << " Hz";
116  if (m_uniqueGroup != nullptr) {
117  const double unique = (getDisabled() == true ? 0. : m_uniqueGroup->getUniqueWeight(ratesDenominator));
118  //const double unique = m_uniqueGroup->m_rateAccumulatorOR / ratesDenominator; // For dbg - this is the rate of N-1
119  // Getting the fractional error of refgular rate and applying it to the unique rate
120  const double uniqueErr = (isZero(m_rateAccumulator) ? 0. : (sqrt(m_rateAccumulator2)/m_rateAccumulator) * unique);
121  ss << ", Unique Rate: " << std::setw(11) << std::right << unique
122  << " +- " << std::setw(11) << std::left << uniqueErr << " Hz";
123  }
124  ss << " : ";
125  ss << m_name << " [PS:" << m_prescale << "]";
126  if (m_seed != "") ss << " <- " << m_seed << " [PS:" << m_seedPrescale << "]";
128  return ss.str();
129 }
130 
131 const std::string RatesTrigger::printExpressRate(const double ratesDenominator) const {
132  std::stringstream ss;
133  ss << std::setfill(' ');
134  ss << "Express Rate: " << std::setw(11) << std::right << m_rateExpressAccumulator/ratesDenominator
135  << " +- " << std::setw(11) << std::left << sqrt(m_rateExpressAccumulator2)/ratesDenominator << " Hz";
136  ss << " : ";
137  ss << m_name << " [PS:" << m_prescale << "] [EXPRESS PS:" << m_expressPrescale << "]";
138  if (m_seed != "") ss << " <- " << m_seed << " [PS:" << m_seedPrescale << "]";
140  return ss.str();
141 }
142 
143 void RatesTrigger::reset() { m_pass = false; m_active = false; }
144 
146 
147 size_t RatesTrigger::getSeedHash() const { return m_seedHash; }
148 
149 const std::string& RatesTrigger::getSeedName() const { return m_seed; }
150 
152 
153 size_t RatesTrigger::getHash() const { return m_nameHash; }
154 
155 const std::string& RatesTrigger::getName() const { return m_name; }
156 
157 bool RatesTrigger::getPassed() const { return m_pass; }
158 
159 bool RatesTrigger::getActive() const { return m_active; }
160 
162 
163 void RatesTrigger::setUniqueGroup(const RatesGroup* unique) { m_uniqueGroup = unique; }
164 
165 void RatesTrigger::setCoherentFactor(const double lowestCommonPrescale) { m_coherentFactor = lowestCommonPrescale; }
166 
167 void RatesTrigger::setCPS(const std::string& group) { m_CPSID = std::hash<std::string>{}(group); }
168 
169 size_t RatesTrigger::getCPSID() const { return m_CPSID; }
170 
RatesTrigger::setPassedAndExecute
void setPassedAndExecute(const bool passed, const bool active, const WeightingValuesSummary_t &weights)
Set the pass/fail bool and immediately call execute.
Definition: RatesTrigger.cxx:45
RatesTrigger::m_ratesActive
double m_ratesActive
Definition: RatesTrigger.h:121
RatesTrigger::getHash
size_t getHash() const
Get the hash of the name of this trigger.
Definition: RatesTrigger.cxx:153
RatesTrigger::m_prescale
const double m_prescale
My prescale factor.
Definition: RatesTrigger.h:133
RatesTrigger::m_active
bool m_active
Was the trigger active? (Did it run)
Definition: RatesTrigger.h:115
kACTIVE_RAW_BIN
@ kACTIVE_RAW_BIN
Bin used to store the raw total events in which the trigger was active.
Definition: RatesHistoBase.h:42
RatesGroup::getUniqueWeight
double getUniqueWeight(const double ratesDenominator) const
Get the unique rate of a unique-rate group For a group being used to get a unique rate,...
Definition: RatesGroup.cxx:178
RatesTrigger::m_name
const std::string m_name
My name.
Definition: RatesTrigger.h:129
RatesTrigger::getSeedHash
size_t getSeedHash() const
Definition: RatesTrigger.cxx:147
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
RatesHistoBase::m_dataCachedPtr
TH1 * m_dataCachedPtr
Cached, non-owning pointer.
Definition: RatesHistoBase.h:115
TrigCompositeUtils::passed
bool passed(DecisionID id, const DecisionIDContainer &idSet)
checks if required decision ID is in the set of IDs in the container
Definition: TrigCompositeUtilsRoot.cxx:117
WeightingValuesSummary_t
Structure to hold per-event weights for distribution.
Definition: RatesHistoBase.h:55
RatesTrigger::m_expressPrescale
const double m_expressPrescale
My express stream prescale factor, gets applied on top of the regular prescale.
Definition: RatesTrigger.h:134
RatesTrigger.h
RatesTrigger::getActive
bool getActive() const
If the trigger passed in the event.
Definition: RatesTrigger.cxx:159
RatesGroup.h
RatesTrigger::printExpressRate
const std::string printExpressRate(const double ratesDenominator) const
Prints the RatesTrigger's express rate.
Definition: RatesTrigger.cxx:131
RatesTrigger::m_rateExpressAccumulator2
double m_rateExpressAccumulator2
Weighted express stream events squared.
Definition: RatesTrigger.h:120
RatesHistoBase::isNotPositive
static bool isNotPositive(double v)
Definition: RatesHistoBase.h:104
RatesTrigger::setUniqueGroup
void setUniqueGroup(const RatesGroup *unique)
If I have a group which is calculating my unique rate.
Definition: RatesTrigger.cxx:163
ExtrapStrat_t
ExtrapStrat_t
Extrapolation strategy to apply to each emulated trigger.
Definition: RatesHistoBase.h:30
RatesTrigger::m_coherentFactor
double m_coherentFactor
If I'm in a coherent prescale group, the prescale of the lowest non-disabled chain in the group.
Definition: RatesTrigger.h:125
kPASS_WEIGHTED_OR_BIN
@ kPASS_WEIGHTED_OR_BIN
Bin used to store the total rate (OR)
Definition: RatesHistoBase.h:45
RatesGroup
Used to calculate the rate for a group of RatesTrigger objects at L1 or the HLT.
Definition: RatesGroup.h:29
RatesTrigger::printRate
virtual const std::string printRate(const double ratesDenominator) const
Prints the RatesTrigger's rate.
Definition: RatesTrigger.cxx:111
RatesTrigger::m_seedsFromRandom
bool m_seedsFromRandom
Does this trigger seed from a random trigger? If so it should only be exposed to unbiased events.
Definition: RatesTrigger.h:116
RatesTrigger::setSeedsFromRandom
void setSeedsFromRandom(const bool i)
Set if this trigger is to behave as if it seeds from a random L1 item.
Definition: RatesTrigger.cxx:145
RatesTrigger::reset
virtual void reset()
If I was used in an event, reset me.
Definition: RatesTrigger.cxx:143
Trk::active
@ active
Definition: Layer.h:48
StdJOSetup.msgSvc
msgSvc
Provide convenience handles for various services.
Definition: StdJOSetup.py:36
lumiFormat.i
int i
Definition: lumiFormat.py:85
RatesHistoBase::getExtrapolationFactor
double getExtrapolationFactor(const WeightingValuesSummary_t &weights, const ExtrapStrat_t strat) const
Definition: RatesHistoBase.cxx:93
RatesTrigger::setCPS
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)
Definition: RatesTrigger.cxx:167
RatesTrigger::m_seedHash
const size_t m_seedHash
Has of my seed name.
Definition: RatesTrigger.h:132
RatesTrigger::m_CPSID
size_t m_CPSID
If I'm in a coherent prescale group, my group's ID (hash of the group name)
Definition: RatesTrigger.h:124
RatesTrigger::m_uniqueGroup
const RatesGroup * m_uniqueGroup
Pointer to the group which is calculating my unique rate.
Definition: RatesTrigger.h:127
RatesTrigger::getCPSID
size_t getCPSID() const
Get the hash of my CPS group name.
Definition: RatesTrigger.cxx:169
kEXPRESS_BIN
@ kEXPRESS_BIN
Bin used to store the express rate.
Definition: RatesHistoBase.h:47
RatesHistoBase::m_rateVsTrainCachedPtr
TH1 * m_rateVsTrainCachedPtr
Cached, non-owning pointer.
Definition: RatesHistoBase.h:114
RatesTrigger::getDisabled
bool getDisabled() const
If I or my seed were prescaled out.
Definition: RatesTrigger.cxx:161
RatesHistoBase::m_rateVsMuCachedPtr
TH1 * m_rateVsMuCachedPtr
Cached, non-owning pointer.
Definition: RatesHistoBase.h:113
RatesTrigger::m_rateAccumulator
double m_rateAccumulator
Weighted events passed.
Definition: RatesTrigger.h:117
RatesHistoBase
Basic base class for any common functionality between RatesTrigger and RatesGroup This means that eve...
Definition: RatesHistoBase.h:84
RatesTrigger::m_rateExpressAccumulator
double m_rateExpressAccumulator
Weighted express stream events.
Definition: RatesTrigger.h:119
RatesHistoBase::isZero
static bool isZero(double v)
Definition: RatesHistoBase.h:103
RatesTrigger::m_rateAccumulator2
double m_rateAccumulator2
Weighted events passed squared.
Definition: RatesTrigger.h:118
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
RatesTrigger::m_ratesActive2
double m_ratesActive2
Definition: RatesTrigger.h:122
weights
Definition: herwig7_interface.h:38
RatesTrigger::m_totalPrescaleWeightExpress
const double m_totalPrescaleWeightExpress
Equal to 1/m_seedPrescale*m_prescale*m_expressPrescale.
Definition: RatesTrigger.h:137
RatesTrigger::execute
virtual void execute(const WeightingValuesSummary_t &weights)
Execute trigger rate emulation.
Definition: RatesTrigger.cxx:56
RatesTrigger::setPassed
void setPassed(const bool passed=true, const bool active=true, const bool unbiasedEvent=false)
Set the pass/fail bool.
Definition: RatesTrigger.cxx:38
RatesTrigger::RatesTrigger
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...
Definition: RatesTrigger.cxx:8
CaloLCW_tf.group
group
Definition: CaloLCW_tf.py:28
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
RatesTrigger::m_pass
bool m_pass
Did the trigger pass or not?
Definition: RatesTrigger.h:114
RatesTrigger::m_seedPrescale
const double m_seedPrescale
Definition: RatesTrigger.h:135
RatesTrigger::getCoherentFactor
double getCoherentFactor() const
Get the lowest common prescale factor of all triggers in my CPS group.
Definition: RatesTrigger.cxx:171
kPASS_RAW_BIN
@ kPASS_RAW_BIN
Bin used to store the raw total events in which the trigger passed.
Definition: RatesHistoBase.h:44
RatesTrigger::getPrescale
double getPrescale(const bool includeExpress=false) const
Gets the triggers prescale.
Definition: RatesTrigger.cxx:95
RatesTrigger::setCoherentFactor
void setCoherentFactor(const double lowestCommonPrescale)
If i'm in a CPS group, set the lowest commons PS factor of the group.
Definition: RatesTrigger.cxx:165
RatesTrigger::m_extrapolationStrategy
const ExtrapStrat_t m_extrapolationStrategy
How this trigger is to scale with luminosity.
Definition: RatesTrigger.h:139
ValidateEBMenu.seedName
seedName
Definition: ValidateEBMenu.py:100
RatesTrigger::getSeedPrescale
double getSeedPrescale() const
Get the prescale of the seed of this trigger.
Definition: RatesTrigger.cxx:151
RatesTrigger::~RatesTrigger
~RatesTrigger()
Definition: RatesTrigger.cxx:36
RatesTrigger::m_seed
const std::string m_seed
My seed, "" if no seed.
Definition: RatesTrigger.h:130
kACTIVE_WEIGHTED_BIN
@ kACTIVE_WEIGHTED_BIN
Bin used to store the weighted events in which the trigger was active.
Definition: RatesHistoBase.h:43
RatesTrigger::getName
const std::string & getName() const
Get the name of this trigger.
Definition: RatesTrigger.cxx:155
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:200
RatesTrigger::m_nameHash
const size_t m_nameHash
Hash of my name.
Definition: RatesTrigger.h:131
RatesTrigger::m_totalPrescaleWeight
const double m_totalPrescaleWeight
Equal to 1/m_seedPrescale*m_prescale.
Definition: RatesTrigger.h:136
RatesTrigger::getSeedName
const std::string & getSeedName() const
Get the name of the seed of this trigger.
Definition: RatesTrigger.cxx:149
RatesTrigger::getPassed
bool getPassed() const
If the trigger passed in the event.
Definition: RatesTrigger.cxx:157
RatesTrigger::printConfig
const std::string printConfig() const
Prints the RatesTrigger's configuration.
Definition: RatesTrigger.cxx:100
RatesHistoBase::getExtrapolationFactorString
const std::string & getExtrapolationFactorString(ExtrapStrat_t strat) const
Definition: RatesHistoBase.cxx:87