ATLAS Offline Software
RatesTrigger.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 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_CPSID(0),
20  m_coherentFactor(0.),
21  m_uniqueGroup(nullptr),
22  m_name(name),
23  m_seed(seedName),
24  m_nameHash(std::hash<std::string>{}(name)),
25  m_seedHash(std::hash<std::string>{}(seedName)),
26  m_prescale(prescale < 1. ? -1 : prescale),
27  m_expressPrescale(expressPrescale < 1. ? -1 : expressPrescale),
28  m_seedPrescale(seedPrescale < 1. ? -1 : seedPrescale),
29  m_totalPrescaleWeight(1. / (m_prescale * m_seedPrescale)),
30  m_totalPrescaleWeightExpress(1. / (m_prescale * m_seedPrescale * m_expressPrescale)),
31  m_extrapolationStrategy(extrapolation)
32  {}
33 
35 
36 void RatesTrigger::setPassed(const bool passed, const bool active, const bool unbiasedEvent) {
37  if (m_seedsFromRandom == true && unbiasedEvent == false) return;
38  if (m_active && !m_pass) throw std::runtime_error("Cannot pass if not active");
39  m_pass = passed;
40  m_active = active;
41 }
42 
43 void RatesTrigger::setPassedAndExecute(const bool passed, const bool active, const WeightingValuesSummary_t& weights) {
44  if (m_seedsFromRandom == true && weights.m_isUnbiased == false) return;
45  if (m_pass == false && m_active == false) { // Protect against two positive calls/event
46  if (m_active && !m_pass) throw std::runtime_error("Cannot pass if not active");
47  m_pass = passed;
48  m_active = active;
49  execute(weights);
50  }
51 }
52 
53 
55  // Efficiency
56  if (getDisabled()) {
57  return;
58  }
59 
60  const double w_noLScale = m_totalPrescaleWeight * weights.m_enhancedBiasWeight;
61  const double w = w_noLScale * getExtrapolationFactor(weights, m_extrapolationStrategy);
63 
64  if (m_active) {
65  m_ratesActive += w;
66  m_ratesActive2 += w * w;
67  if (m_dataCachedPtr != nullptr) {
70  }
71  }
72 
73  if (m_pass) {
74  // The vs. mu histogram is a property of the INPUT event so we don't apply any L scaling here
75  if (m_rateVsMuCachedPtr != nullptr) m_rateVsMuCachedPtr->Fill(weights.m_eventMu, w_noLScale);
76  // The vs. position in train is agnostic to INPUT event & TARGET conditions - i.e. the bunch train structure is not
77  // re-weighted in any way. Hence we can apply whatever extrapolation strategy we want here.
80  m_rateAccumulator2 += w * w;
81  if (m_dataCachedPtr != nullptr) {
84  }
85  if (m_expressPrescale >= 1) {
87  m_rateExpressAccumulator2 += wExp * wExp;
89  }
90  }
91 }
92 
93 double RatesTrigger::getPrescale(const bool includeExpress) const {
94  if (includeExpress) return m_prescale * m_expressPrescale;
95  return m_prescale;
96 }
97 
98 const std::string RatesTrigger::printConfig() const {
99  std::stringstream ss;
100  ss << std::setfill(' ')
101  << "Prescale:" << std::setw(11) << std::left << m_prescale
102  << " xpress:" << std::setw(11) << std::left << m_expressPrescale
103  << " CPSID:" << std::setw(11) << std::left << m_CPSID
104  << " seedPS:" << std::setw(11) << std::left << m_seedPrescale
105  << " : " << (m_seed != "" ? m_seed : "") << (m_seed != "" ? " -> " : "") << m_name;
106  return ss.str();
107 }
108 
109 const std::string RatesTrigger::printRate(const double ratesDenominator) const {
110  std::stringstream ss;
111  ss << std::setfill(' ');
112  ss << "Rate: " << std::setw(11) << std::right << m_rateAccumulator/ratesDenominator
113  << " +- " << std::setw(11) << std::left << sqrt(m_rateAccumulator2)/ratesDenominator << " Hz";
114  if (m_uniqueGroup != nullptr) {
115  const double unique = (getDisabled() == true ? 0. : m_uniqueGroup->getUniqueWeight(ratesDenominator));
116  //const double unique = m_uniqueGroup->m_rateAccumulatorOR / ratesDenominator; // For dbg - this is the rate of N-1
117  // Getting the fractional error of refgular rate and applying it to the unique rate
118  const double uniqueErr = (isZero(m_rateAccumulator) ? 0. : (sqrt(m_rateAccumulator2)/m_rateAccumulator) * unique);
119  ss << ", Unique Rate: " << std::setw(11) << std::right << unique
120  << " +- " << std::setw(11) << std::left << uniqueErr << " Hz";
121  }
122  ss << " : ";
123  ss << m_name << " [PS:" << m_prescale << "]";
124  if (m_seed != "") ss << " <- " << m_seed << " [PS:" << m_seedPrescale << "]";
126  return ss.str();
127 }
128 
129 const std::string RatesTrigger::printExpressRate(const double ratesDenominator) const {
130  std::stringstream ss;
131  ss << std::setfill(' ');
132  ss << "Express Rate: " << std::setw(11) << std::right << m_rateExpressAccumulator/ratesDenominator
133  << " +- " << std::setw(11) << std::left << sqrt(m_rateExpressAccumulator2)/ratesDenominator << " Hz";
134  ss << " : ";
135  ss << m_name << " [PS:" << m_prescale << "] [EXPRESS PS:" << m_expressPrescale << "]";
136  if (m_seed != "") ss << " <- " << m_seed << " [PS:" << m_seedPrescale << "]";
138  return ss.str();
139 }
140 
141 void RatesTrigger::reset() { m_pass = false; m_active = false; }
142 
144 
145 size_t RatesTrigger::getSeedHash() const { return m_seedHash; }
146 
147 const std::string& RatesTrigger::getSeedName() const { return m_seed; }
148 
150 
151 size_t RatesTrigger::getHash() const { return m_nameHash; }
152 
153 const std::string& RatesTrigger::getName() const { return m_name; }
154 
155 bool RatesTrigger::getPassed() const { return m_pass; }
156 
157 bool RatesTrigger::getActive() const { return m_active; }
158 
160 
161 void RatesTrigger::setUniqueGroup(const RatesGroup* unique) { m_uniqueGroup = unique; }
162 
163 void RatesTrigger::setCoherentFactor(const double lowestCommonPrescale) { m_coherentFactor = lowestCommonPrescale; }
164 
165 void RatesTrigger::setCPS(const std::string& group) { m_CPSID = std::hash<std::string>{}(group); }
166 
167 size_t RatesTrigger::getCPSID() const { return m_CPSID; }
168 
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:43
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:151
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:145
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:157
WeightingValuesSummary_t::m_isUnbiased
bool m_isUnbiased
If the event was taken online with a RD trigger.
Definition: RatesHistoBase.h:60
WeightingValuesSummary_t::m_distanceInTrain
uint32_t m_distanceInTrain
How far into the bunch train the event was, in bunch crossings.
Definition: RatesHistoBase.h:61
RatesGroup.h
RatesTrigger::printExpressRate
const std::string printExpressRate(const double ratesDenominator) const
Prints the RatesTrigger's express rate.
Definition: RatesTrigger.cxx:129
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:161
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
WeightingValuesSummary_t::m_enhancedBiasWeight
double m_enhancedBiasWeight
A property of the event derived from online enhanced bias prescales.
Definition: RatesHistoBase.h:57
RatesTrigger::printRate
virtual const std::string printRate(const double ratesDenominator) const
Prints the RatesTrigger's rate.
Definition: RatesTrigger.cxx:109
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:143
RatesTrigger::reset
virtual void reset()
If I was used in an event, reset me.
Definition: RatesTrigger.cxx:141
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:92
RatesHistoBase::getExtrapolationFactor
double getExtrapolationFactor(const WeightingValuesSummary_t &weights, const ExtrapStrat_t strat) const
Definition: RatesHistoBase.cxx:95
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:165
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:167
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
TH1::Fill
int Fill(double)
Definition: rootspy.cxx:285
RatesTrigger::getDisabled
bool getDisabled() const
If I or my seed were prescaled out.
Definition: RatesTrigger.cxx:159
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:195
RatesTrigger::m_ratesActive2
double m_ratesActive2
Definition: RatesTrigger.h:122
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:54
RatesTrigger::setPassed
void setPassed(const bool passed=true, const bool active=true, const bool unbiasedEvent=false)
Set the pass/fail bool.
Definition: RatesTrigger.cxx:36
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:169
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:93
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:163
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:149
RatesTrigger::~RatesTrigger
~RatesTrigger()
Definition: RatesTrigger.cxx:34
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:153
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:147
RatesTrigger::getPassed
bool getPassed() const
If the trigger passed in the event.
Definition: RatesTrigger.cxx:155
RatesTrigger::printConfig
const std::string printConfig() const
Prints the RatesTrigger's configuration.
Definition: RatesTrigger.cxx:98
RatesHistoBase::getExtrapolationFactorString
const std::string & getExtrapolationFactorString(ExtrapStrat_t strat) const
Definition: RatesHistoBase.cxx:89
WeightingValuesSummary_t::m_eventMu
double m_eventMu
The actual number of interactions in the event.
Definition: RatesHistoBase.h:58