ATLAS Offline Software
Loading...
Searching...
No Matches
RatesScanTrigger.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#include "GaudiKernel/ITHistSvc.h"
9
10RatesScanTrigger::RatesScanTrigger( const std::string& name,
11 IMessageSvc* msgSvc,
12 const double thresholdMin, const double thresholdMax, const uint32_t thresholdBins,
13 const TriggerBehaviour_t behaviour,
14 const double prescale,
15 const std::string& seedName, const double seedPrescale,
16 const ExtrapStrat_t extrapolation) :
17 RatesTrigger(name, msgSvc, prescale, -1, seedName, seedPrescale, /*base histograms*/false, extrapolation),
18 m_rateScanHist(std::make_unique<TH1D>("", TString(name + ";Threshold;Rate [Hz]"), thresholdBins, thresholdMin, thresholdMax)),
20 {
21 m_rateScanHist->Sumw2(true);
22 }
23
24RatesScanTrigger::RatesScanTrigger( const std::string& name,
25 IMessageSvc* msgSvc,
26 const std::vector<double>& thresholdBinEdged,
27 const TriggerBehaviour_t behaviour,
28 const double prescale,
29 const std::string& seedName, const double seedPrescale,
30 const ExtrapStrat_t extrapolation) :
31 RatesTrigger(name, msgSvc, prescale, -1, seedName, seedPrescale, false, extrapolation),
33 {
34 if (thresholdBinEdged.size() < 2) {
35 ATH_MSG_ERROR("Need more than one entry in thresholdBinEdged to define histogram binning.");
36 return;
37 }
38 size_t nBins = thresholdBinEdged.size() - 1;
39 m_rateScanHist = std::make_unique<TH1D>("", TString(name + ";Threshold;Rate [Hz]"), nBins, thresholdBinEdged.data());
40 m_rateScanHist->Sumw2(true);
41
43 }
44
47
48void RatesScanTrigger::passThreshold(const double t, const bool unbiasedEvent) {
49 if (m_seedsFromRandom == true && unbiasedEvent == false) return;
51}
52
54 if (m_seedsFromRandom == true && weights.m_isUnbiased == false) return;
55 if (m_thresholdPassed != std::numeric_limits<double>::min()) return; // We've already done this event
58}
59
60
61StatusCode RatesScanTrigger::giveThresholdHist(const ServiceHandle<ITHistSvc>& svc, const std::string& name) {
62 ATH_CHECK( svc->regHist(name, std::move(m_rateScanHist)) );
63 return StatusCode::SUCCESS;
64}
65
67 if (m_thresholdPassed == std::numeric_limits<double>::min()) return; // Did not pass
68 // This histogram we *do* include the extrapolation weight as we plot vs. some trigger property, not some event property
70 // Fill the histogram cumulatively
71 // We match exactly with the *lower* edge of all bins
72 const int nBins = m_rateScanHistCachedPtr->GetNbinsX();
73 for (int bin = 1; bin <= nBins; ++bin) {
74 const double low = m_rateScanHistCachedPtr->GetBinLowEdge(bin);
75 const double width = m_rateScanHistCachedPtr->GetBinWidth(bin);
79 }
80 }
81 // Underflow && Overflow
82 const double xMin = m_rateScanHistCachedPtr->GetXaxis()->GetXmin();
83 const double xMax = m_rateScanHistCachedPtr->GetXaxis()->GetXmax();
85 m_rateScanHistCachedPtr->Fill(xMin - 1., w);
86 }
88 m_rateScanHistCachedPtr->Fill(xMax + 1, w);
89 }
90}
91
92 void RatesScanTrigger::setHistoName(const std::string& newName){
93 m_rateScanHist->SetName(newName.c_str());
94 }
95
96
97const std::string RatesScanTrigger::printRate(const double ratesDenominator) const {
98 std::stringstream ss;
99 const int nBins = m_rateScanHistCachedPtr->GetNbinsX();
100 ss << std::setfill(' ');
101 ss << m_name << " [PS:" << m_prescale << "]";
102 if (m_seed != "") ss << " <- " << m_seed << " [PS:" << m_seedPrescale << "]";
103 ss << " (Extrap:"<< getExtrapolationFactorString(m_extrapolationStrategy) << ")" << std::endl;
104
106
107 ss << " Threshold <= " << std::setw(11) << std::left << std::as_const(*m_rateScanHistCachedPtr).GetXaxis()->GetXmin();
108 ss << " Rate :" << std::setw(11) << std::right << m_rateScanHistCachedPtr->GetBinContent(0)/ratesDenominator;
109 ss << " +- " << std::setw(11) << std::left << m_rateScanHistCachedPtr->GetBinError(0)/ratesDenominator << " Hz" << std::endl;
110
111 for (int bin = 1; bin <= nBins; ++bin) {
112 ss << " Threshold <= ";
113 ss << std::setw(11) << std::left << m_rateScanHistCachedPtr->GetBinLowEdge(bin) + m_rateScanHistCachedPtr->GetBinWidth(bin);
114 ss << " Rate :" << std::setw(11) << std::right << m_rateScanHistCachedPtr->GetBinContent(bin)/ratesDenominator;
115 ss << " +- " << std::setw(11) << std::left << m_rateScanHistCachedPtr->GetBinError(bin)/ratesDenominator << " Hz";
116 ss << std::endl;
117 }
118
119 ss << " Threshold > " << std::setw(11) << std::left << std::as_const(*m_rateScanHistCachedPtr).GetXaxis()->GetXmax();
120 ss << " Rate :" << std::setw(11) << std::right << m_rateScanHistCachedPtr->GetBinContent(nBins+1)/ratesDenominator;
121 ss << " +- " << std::setw(11) << std::left << m_rateScanHistCachedPtr->GetBinError(nBins+1)/ratesDenominator << " Hz";
122
123 } else if (m_behaviour == kTriggerAboveThreshold) {
124
125 ss << " Threshold < " << std::setw(11) << std::left << std::as_const(*m_rateScanHistCachedPtr).GetXaxis()->GetXmin();
126 ss << " Rate: " << std::setw(11) << std::right << m_rateScanHistCachedPtr->GetBinContent(0)/ratesDenominator;
127 ss << " +- " << std::setw(11) << std::left << m_rateScanHistCachedPtr->GetBinError(0)/ratesDenominator << " Hz" << std::endl;
128
129 for (int bin = 1; bin <= nBins; ++bin) {
130 ss << " Threshold >= ";
131 ss << std::setw(11) << std::left << m_rateScanHistCachedPtr->GetBinLowEdge(bin);
132 ss << " Rate: " << std::setw(11) << std::right << m_rateScanHistCachedPtr->GetBinContent(bin)/ratesDenominator;
133 ss << " +- " << std::setw(11) << std::left << m_rateScanHistCachedPtr->GetBinError(bin)/ratesDenominator << " Hz";
134 ss << std::endl;
135 }
136
137 ss << " Threshold >= " << std::setw(11) << std::left << std::as_const(*m_rateScanHistCachedPtr).GetXaxis()->GetXmax();
138 ss << " Rate: " << std::setw(11) << std::right << m_rateScanHistCachedPtr->GetBinContent(nBins+1)/ratesDenominator;
139 ss << " +- " << std::setw(11) << std::left << m_rateScanHistCachedPtr->GetBinError(nBins+1)/ratesDenominator << " Hz";
140
141 }
142
143 return ss.str();
144}
#define ATH_CHECK
Evaluate an expression and check for errors.
static Double_t ss
ExtrapStrat_t
Extrapolation strategy to apply to each emulated trigger.
const double width
const std::string & getExtrapolationFactorString(ExtrapStrat_t strat) const
double getExtrapolationFactor(const WeightingValuesSummary_t &weights, const ExtrapStrat_t strat) const
void setPassedAndExecute(const double t, const WeightingValuesSummary_t &weights)
Set the pass threshold and immediately call execute.
TriggerBehaviour_t
enum to describe if a trigger should activate for values >= or <= than the thresold
@ kTriggerBelowThreshold
Trigger for <= threshold.
@ kTriggerAboveThreshold
Trigger for >= threshold.
TriggerBehaviour_t m_behaviour
If we need to be above or below the threshold to cause the trigger to fire.
RatesScanTrigger(const std::string &name, IMessageSvc *msgSvc, const double thresholdMin, const double thresholdMax, const uint32_t thresholdBins=100, const TriggerBehaviour_t behaviour=kTriggerBelowThreshold, const double prescale=1., const std::string &seedName="", const double seedPrecale=1., const ExtrapStrat_t extrapolation=ExtrapStrat_t::kLINEAR)
Construct new RatesScanTrigger to enumerate the rate for a single L1 or HLT trigger as a function of ...
double m_thresholdPassed
Analogous to m_pass.
const std::string printRate(const double ratesDenominator) const override
Prints the RatesScanTrigger's rate (different output to a regular trigger)
StatusCode giveThresholdHist(const ServiceHandle< ITHistSvc > &svc, const std::string &name)
void passThreshold(const double t, const bool unbiasedEvent=false)
Sets the threshold the event.
void setHistoName(const std::string &newName)
std::unique_ptr< TH1 > m_rateScanHist
Even if we are not exporting it - we still need this histo.
void execute(const WeightingValuesSummary_t &weights) override
Execute trigger rate emulation.
bool m_seedsFromRandom
Does this trigger seed from a random trigger?
const std::string m_seed
My seed, "" if no seed.
const ExtrapStrat_t m_extrapolationStrategy
How this trigger is to scale with luminosity.
const std::string m_name
My name.
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...
const double m_totalPrescaleWeight
Equal to 1/m_seedPrescale*m_prescale.
const double m_seedPrescale
const double m_prescale
My prescale factor.
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition hcg.cxx:130
STL namespace.
Structure to hold per-event weights for distribution.