ATLAS Offline Software
Loading...
Searching...
No Matches
RatesGroup.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
8void RatesCPS::execute(const double prescale) {
9 m_weight *= 1. - (1. / ( prescale / m_coherentFactor ) );
10}
11
12double RatesCPS::getWeight() const {
13 return (1. - m_weight) / m_coherentFactor;
14}
15
16RatesGroup::RatesGroup(const std::string& name, IMessageSvc* msgSvc, const bool doHistograms, const bool doExtrapolation) :
17 RatesHistoBase(name, msgSvc, doHistograms),
18 m_name(name),
19 m_nameHash(std::hash<std::string>{}(name)),
20 m_rateAccumulatorOR(0.),
21 m_rateAccumulatorAND(0.),
22 m_rateAccumulatorOR2(0.),
23 m_rateAccumulatorAND2(0.),
24 m_doCachedWeights(false),
25 m_cachedWeights(),
26 m_useCachedWeights(false),
27 m_extrapolationStrategy(doExtrapolation ? ExtrapStrat_t::kLINEAR : ExtrapStrat_t::kNONE),
28 m_masterGroup(nullptr),
29 m_uniqueTrigger(nullptr),
30 m_isExpressGroup(false),
31 m_children()
32 {}
33
35
36const std::string RatesGroup::printConfig() const {
37 std::stringstream ss;
38 ss << m_name << std::endl;
39 for (const auto& child : m_children) {
40 if (child.first != std::hash<std::string>{}("")) ss << "\t" << (**(child.second.begin())).getSeedName() << " ->" << std::endl;
41 for (const auto& chain : child.second) {
42 ss << "\t\t" << chain->getName() << std::endl;
43 }
44 }
45 return ss.str();
46}
47
48const std::string RatesGroup::printRate(const double ratesDenominator) const {
49 std::stringstream ss;
50 ss <<"RateOR: " << std::setw(11) << std::right << m_rateAccumulatorOR/ratesDenominator
51 << " +- " << std::setw(11) << std::left << sqrt(m_rateAccumulatorOR2)/ratesDenominator << " Hz, "
52 << " RateAND: " << std::setw(11) << std::right << m_rateAccumulatorAND/ratesDenominator
53 << " +- " << std::setw(11) << std::left << sqrt(m_rateAccumulatorAND2)/ratesDenominator << " Hz"
54 << " : " << m_name
56 return ss.str();
57}
58
60 if (m_children.count(toAdd->getSeedHash()) == 0) {
61 m_children.insert( std::make_pair(toAdd->getSeedHash(), std::set<const RatesTrigger*>() ) );
62 m_cachedWeights.insert( std::make_pair(toAdd->getSeedHash(), 1.) );
63 }
64 m_children.at(toAdd->getSeedHash()).insert(toAdd);
65}
66
68 if (m_children.count(toRemove->getSeedHash()) == 0) return;
69 m_children.at(toRemove->getSeedHash()).erase(toRemove);
70}
71
73 for (auto iterator = m_children.begin(); iterator != m_children.end(); /*noop*/) {
74 if (iterator->first == toKeep->getSeedHash()) {
75 ++iterator; // Keep
76 } else {
78 }
79 }
80}
81
83 double weightOR = 1., weightAND = 1.;
84 if (m_doCachedWeights == true) { // Reset cache
85 for (auto& cacheElement : m_cachedWeights) cacheElement.second = 1.;
86 }
87
88 // Need a check for an empty group. Otherwise the "AND" logic will
89 if (m_children.size() == 0) weightAND = 0;
90
91 for (const auto& element : m_children) { // Loop over all children, partitioned by L1 seed
92 const std::set<const RatesTrigger*>& triggers = element.second; // I'm the set of triggers seeded off this item
93
94 double weightL1 = 0;
95 double weightHLT_OR = 1.;
96 double weightHLT_AND = 1.;
97 std::unordered_map<size_t, RatesCPS> weightHLT_CPS; // Map of CPS-group-hash to RatesCPS accumulators
98
99 for (const auto& trigger : triggers) { //
100 if (trigger->getPassed()) {
101
102 const double trigPrescaleReciprocal = 1. / trigger->getPrescale( m_isExpressGroup );
103
104 weightL1 = 1. / trigger->getSeedPrescale();
105 weightHLT_AND *= trigPrescaleReciprocal; // TODO - check that CPS doesn't affect AND
106
107 const size_t CPSID = trigger->getCPSID();
108 if (CPSID == 0) { // No CPS
109 weightHLT_OR *= 1. - trigPrescaleReciprocal;
110 } else { // Keep track for each CPS group
111 RatesCPS& cps = weightHLT_CPS[CPSID];
112 cps.setCoherentFactor( trigger->getCoherentFactor() );
113 cps.execute( 1. / trigPrescaleReciprocal );
114 }
115
116 } else { // Trigger FAILED
117 weightHLT_AND *= 0;
118 }
119
120 // Efficiency check.
121 // If any PS=1 chain passes, the weightHLT_OR = (1 - 1/1) = 0 [which gets inverted to 1 in weightOR below]
122 // If any chain fails, weightHLT_AND = 0
123 if (isZero(weightHLT_OR) && isZero(weightHLT_AND)) break;
124 }
125
126 // Include the CPS chain's contributions
127 for (const auto& cps : weightHLT_CPS) weightHLT_OR *= 1. - cps.second.getWeight();
128
129 weightOR *= 1. - (weightL1 * (1. - weightHLT_OR));
130 weightAND *= weightL1 * weightHLT_AND;
131
132 //if (m_name == "Main") std::cout << "|M|weightL1:" << weightL1 << ",weightHLT_OR:" << weightHLT_OR << ",weightOR:" << weightOR;
133
134 // If we are caching this result for use by the Unique groups
135 if (m_doCachedWeights) {
136 for (auto& cacheElement : m_cachedWeights) {
137 if (cacheElement.first == element.first) continue; // This is the one L1 seed in the combination we're excluding from this cache
138 cacheElement.second *= 1. - (weightL1 * (1. - weightHLT_OR));
139 }
140 }
141
142 }
143
144 // If we are a unique group then we only actually have one element above - the set of L1 items which have
145 // a common seed with our unique trigger. Everything else is identical to the global rate calc so we can fetch it from the cache
146 if (m_useCachedWeights == true) {
147 size_t myOneAndOnlyL1SeedHash = (m_children.begin())->first;
148 weightOR *= m_masterGroup->getCachedWeight( myOneAndOnlyL1SeedHash );
149 }
150
151 //TODO - we currently only let groups scale linearly. Should change this.
152 const double w = weights.m_enhancedBiasWeight * getExtrapolationFactor(weights, m_extrapolationStrategy);
153 const double wOR = w * (1. - weightOR);
154 const double wAND = w * weightAND;
155
156 m_rateAccumulatorOR += wOR;
157 m_rateAccumulatorAND += wAND;
158 m_rateAccumulatorOR2 += wOR * wOR;
159 m_rateAccumulatorAND2 += wAND * wAND;
160
161 if (m_rateVsMuCachedPtr != nullptr) {
162 m_rateVsMuCachedPtr->Fill(weights.m_eventMu, wOR);
163 }
164 if (m_rateVsTrainCachedPtr != nullptr) {
165 m_rateVsTrainCachedPtr->Fill(weights.m_distanceInTrain, wOR);
166 }
167 if (m_dataCachedPtr != nullptr) {
170 }
171
172 if (m_uniqueTrigger != nullptr && m_uniqueTrigger->getDataHist() != nullptr && !m_uniqueTrigger->getDisabled()) {
173 m_uniqueTrigger->getDataHist()->Fill(RatesBinIdentifier_t::kUNIQUE_BIN, wOR);
174 }
175
176}
177
178double RatesGroup::getUniqueWeight(const double ratesDenominator) const {
179 const double diff = m_masterGroup->m_rateAccumulatorOR - m_rateAccumulatorOR;
180 if (isZero(diff)) return 0.;
181 return diff / ratesDenominator;
182}
183
185
187
189
190void RatesGroup::duplicateChildren(const RatesGroup* toDuplicate) {
191 m_children = toDuplicate->getChildren(); m_masterGroup = toDuplicate;
192}
193
194double RatesGroup::getCachedWeight(const size_t l1Hash) const { return m_cachedWeights.at(l1Hash); }
195
197
199
200const std::unordered_map<size_t, std::set<const RatesTrigger*>>& RatesGroup::getChildren() const {
201 return m_children;
202}
203
static Double_t ss
@ kPASS_WEIGHTED_AND_BIN
Bin used to store the total rate (AND)
@ kPASS_WEIGHTED_OR_BIN
Bin used to store the total rate (OR)
@ kUNIQUE_BIN
Bin used to store data needed to get the unique rate.
@ kLINEAR
Scale trigger linearly with luminosity.
@ kNONE
Do not scale this trigger for changes in luminosity.
void diff(const Jet &rJet1, const Jet &rJet2, std::map< std::string, double > varDiff)
Difference between jets - Non-Class function required by trigger.
Definition Jet.cxx:631
Helper class to keep track of coherent prescales between chains in a group This class knows about its...
Definition RatesGroup.h:14
double m_coherentFactor
Definition RatesGroup.h:23
double getWeight() const
Return the union product (OR of many chains) coherently weighted by the coherent factor.
double m_weight
Definition RatesGroup.h:22
void execute(const double prescale)
Keep track of a union product (OR of many chains) excluding the coherent part.
Definition RatesGroup.cxx:8
void setCoherentFactor(const double coherentFactor)
Set a common prescale factor for this group.
Definition RatesGroup.h:17
bool m_useCachedWeights
Efficiency.
Definition RatesGroup.h:120
void setUseCachedWeights(const bool i)
Set to use cached weights from the Master group (need ptr to m_masterGroup)
double getCachedWeight(const size_t l1Hash) const
Get cached weight from triggers seeding from a given L1 item.
bool m_doCachedWeights
Used in the global rates group.
Definition RatesGroup.h:118
virtual ~RatesGroup()
void removeFromGroup(const RatesTrigger *toRemove)
Remove a trigger from this group.
void setDoCachedWeights(const bool i)
Flag group to cache weights.
double m_rateAccumulatorOR2
For stat error.
Definition RatesGroup.h:115
RatesTrigger * getUniqueTrigger()
Get the trigger I am doing unique rates for.
double m_rateAccumulatorAND
Numerator for the rate of the AND of all triggers.
Definition RatesGroup.h:114
const ExtrapStrat_t m_extrapolationStrategy
How this group is to scale with luminosity.
Definition RatesGroup.h:121
const std::string m_name
Name of the group.
Definition RatesGroup.h:110
const std::unordered_map< size_t, std::set< const RatesTrigger * > > & getChildren() const
void execute(const WeightingValuesSummary_t &weights)
Perform group rates evaluation.
void setExpressGroup(const bool i)
Flag this group as the express group (modifies group trigger's prescales)
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,...
RatesGroup(const std::string &name, IMessageSvc *msgSvc, const bool doHistograms=true, const bool doExtrapolation=true)
Construct new RatesGroup to enumerate the combined union (OR) and intersection (AND) rate of a set of...
const std::string printConfig() const
Prints the RatesGroup's configuration.
void duplicateChildren(const RatesGroup *toDuplicate)
Copy in triggers from another group.
const std::string printRate(const double ratesDenominator) const
Prints the RatesGroup's rate.
RatesTrigger * m_uniqueTrigger
If not nullptr, then a trigger this group is calculating the unique rate for.
Definition RatesGroup.h:123
void setUniqueTrigger(RatesTrigger *trigger)
Set trigger I am doing unique rates for.
void addToGroup(const RatesTrigger *toAdd)
Add a trigger to this group.
const RatesGroup * m_masterGroup
If not nullptr, then use the cached weights info in this master group object.
Definition RatesGroup.h:122
std::unordered_map< size_t, double > m_cachedWeights
Cached weight of the OR of all triggers except for the L1 seed-hash of the key here.
Definition RatesGroup.h:119
double m_rateAccumulatorAND2
For stat error.
Definition RatesGroup.h:116
double m_rateAccumulatorOR
Numerator for the rate of the OR of all triggers.
Definition RatesGroup.h:113
const size_t m_nameHash
Hash of the group's name.
Definition RatesGroup.h:111
bool m_isExpressGroup
If this group is calculating for the express stream - also include express prescales.
Definition RatesGroup.h:125
void removeOtherL1(const RatesTrigger *toKeep)
Remove from the groups mapping all triggers which have a dissimilar seed to the supplied trigger.
std::unordered_map< size_t, std::set< const RatesTrigger * > > m_children
Definition RatesGroup.h:127
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 isZero(double v)
TH1 * m_dataCachedPtr
Cached, non-owning pointer.
Used to calculate the rate for a single trigger at L1 or the HLT.
size_t getSeedHash() const
STL class.
STL namespace.
Structure to hold per-event weights for distribution.