ATLAS Offline Software
RatesScanTrigger.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include "GaudiKernel/ITHistSvc.h"
9 
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(nullptr), m_rateScanHistCachedPtr(nullptr), m_thresholdPassed(0), m_behaviour(behaviour)
19  {
20  m_rateScanHist = std::make_unique<TH1D>("", TString(name + ";Threshold;Rate [Hz]"), thresholdBins, thresholdMin, thresholdMax);
21  m_rateScanHist->Sumw2(true);
22 
24  }
25 
27  IMessageSvc* msgSvc,
28  const std::vector<double>& thresholdBinEdged,
29  const TriggerBehaviour_t behaviour,
30  const double prescale,
31  const std::string& seedName, const double seedPrescale,
32  const ExtrapStrat_t extrapolation) :
33  RatesTrigger(name, msgSvc, prescale, -1, seedName, seedPrescale, false, extrapolation),
34  m_rateScanHist(nullptr), m_rateScanHistCachedPtr(nullptr), m_thresholdPassed(0), m_behaviour(behaviour)
35  {
36  if (thresholdBinEdged.size() < 2) {
37  ATH_MSG_ERROR("Need more than one entry in thresholdBinEdged to define histogram binning.");
38  return;
39  }
40  size_t nBins = thresholdBinEdged.size() - 1;
41  m_rateScanHist = std::make_unique<TH1D>("", TString(name + ";Threshold;Rate [Hz]"), nBins, thresholdBinEdged.data());
42  m_rateScanHist->Sumw2(true);
43 
45  }
46 
48 }
49 
50 void RatesScanTrigger::passThreshold(const double t, const bool unbiasedEvent) {
51  if (m_seedsFromRandom == true && unbiasedEvent == false) return;
53 }
54 
56  if (m_seedsFromRandom == true && weights.m_isUnbiased == false) return;
57  if (m_thresholdPassed != std::numeric_limits<double>::min()) return; // We've already done this event
59  execute(weights);
60 }
61 
62 
64  ATH_CHECK( svc->regHist(name, std::move(m_rateScanHist), m_rateScanHistCachedPtr) );
65  return StatusCode::SUCCESS;
66 }
67 
69  if (m_thresholdPassed == std::numeric_limits<double>::min()) return; // Did not pass
70  // This histogram we *do* include the extrapolation weight as we plot vs. some trigger property, not some event property
72  // Fill the histogram cumulatively
73  // We match exactly with the *lower* edge of all bins
74  const int nBins = m_rateScanHistCachedPtr->GetNbinsX();
75  for (int bin = 1; bin <= nBins; ++bin) {
76  const double low = m_rateScanHistCachedPtr->GetBinLowEdge(bin);
77  const double width = m_rateScanHistCachedPtr->GetBinWidth(bin);
81  }
82  }
83  // Underflow && Overflow
84  const double xMin = m_rateScanHistCachedPtr->GetXaxis()->GetXmin();
85  const double xMax = m_rateScanHistCachedPtr->GetXaxis()->GetXmax();
87  m_rateScanHistCachedPtr->Fill(xMin - 1., w);
88  }
90  m_rateScanHistCachedPtr->Fill(xMax + 1, w);
91  }
92 }
93 
94 const std::string RatesScanTrigger::printRate(const double ratesDenominator) const {
95  std::stringstream ss;
96  const int nBins = m_rateScanHistCachedPtr->GetNbinsX();
97  ss << std::setfill(' ');
98  ss << m_name << " [PS:" << m_prescale << "]";
99  if (m_seed != "") ss << " <- " << m_seed << " [PS:" << m_seedPrescale << "]";
100  ss << " (Extrap:"<< getExtrapolationFactorString(m_extrapolationStrategy) << ")" << std::endl;
101 
103 
104  ss << " Threshold <= " << std::setw(11) << std::left << std::as_const(*m_rateScanHistCachedPtr).GetXaxis()->GetXmin();
105  ss << " Rate :" << std::setw(11) << std::right << m_rateScanHistCachedPtr->GetBinContent(0)/ratesDenominator;
106  ss << " +- " << std::setw(11) << std::left << m_rateScanHistCachedPtr->GetBinError(0)/ratesDenominator << " Hz" << std::endl;
107 
108  for (int bin = 1; bin <= nBins; ++bin) {
109  ss << " Threshold <= ";
110  ss << std::setw(11) << std::left << m_rateScanHistCachedPtr->GetBinLowEdge(bin) + m_rateScanHistCachedPtr->GetBinWidth(bin);
111  ss << " Rate :" << std::setw(11) << std::right << m_rateScanHistCachedPtr->GetBinContent(bin)/ratesDenominator;
112  ss << " +- " << std::setw(11) << std::left << m_rateScanHistCachedPtr->GetBinError(bin)/ratesDenominator << " Hz";
113  ss << std::endl;
114  }
115 
116  ss << " Threshold > " << std::setw(11) << std::left << std::as_const(*m_rateScanHistCachedPtr).GetXaxis()->GetXmax();
117  ss << " Rate :" << std::setw(11) << std::right << m_rateScanHistCachedPtr->GetBinContent(nBins+1)/ratesDenominator;
118  ss << " +- " << std::setw(11) << std::left << m_rateScanHistCachedPtr->GetBinError(nBins+1)/ratesDenominator << " Hz";
119 
120  } else if (m_behaviour == kTriggerAboveThreshold) {
121 
122  ss << " Threshold < " << std::setw(11) << std::left << std::as_const(*m_rateScanHistCachedPtr).GetXaxis()->GetXmin();
123  ss << " Rate: " << std::setw(11) << std::right << m_rateScanHistCachedPtr->GetBinContent(0)/ratesDenominator;
124  ss << " +- " << std::setw(11) << std::left << m_rateScanHistCachedPtr->GetBinError(0)/ratesDenominator << " Hz" << std::endl;
125 
126  for (int bin = 1; bin <= nBins; ++bin) {
127  ss << " Threshold >= ";
128  ss << std::setw(11) << std::left << m_rateScanHistCachedPtr->GetBinLowEdge(bin);
129  ss << " Rate: " << std::setw(11) << std::right << m_rateScanHistCachedPtr->GetBinContent(bin)/ratesDenominator;
130  ss << " +- " << std::setw(11) << std::left << m_rateScanHistCachedPtr->GetBinError(bin)/ratesDenominator << " Hz";
131  ss << std::endl;
132  }
133 
134  ss << " Threshold >= " << std::setw(11) << std::left << std::as_const(*m_rateScanHistCachedPtr).GetXaxis()->GetXmax();
135  ss << " Rate: " << std::setw(11) << std::right << m_rateScanHistCachedPtr->GetBinContent(nBins+1)/ratesDenominator;
136  ss << " +- " << std::setw(11) << std::left << m_rateScanHistCachedPtr->GetBinError(nBins+1)/ratesDenominator << " Hz";
137 
138  }
139 
140  return ss.str();
141 }
RatesTrigger::m_prescale
const double m_prescale
My prescale factor.
Definition: RatesTrigger.h:133
RatesScanTrigger::m_rateScanHistCachedPtr
TH1 * m_rateScanHistCachedPtr
Definition: RatesScanTrigger.h:110
RatesTrigger::m_name
const std::string m_name
My name.
Definition: RatesTrigger.h:129
RatesScanTrigger::m_rateScanHist
std::unique_ptr< TH1 > m_rateScanHist
Even if we are not exporting it - we still need this histo.
Definition: RatesScanTrigger.h:109
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
RatesScanTrigger::~RatesScanTrigger
virtual ~RatesScanTrigger()
Definition: RatesScanTrigger.cxx:47
AthCheckMacros.h
WeightingValuesSummary_t
Structure to hold per-event weights for distribution.
Definition: RatesHistoBase.h:55
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
WeightingValuesSummary_t::m_isUnbiased
bool m_isUnbiased
If the event was taken online with a RD trigger.
Definition: RatesHistoBase.h:60
bin
Definition: BinsDiffFromStripMedian.h:43
RatesScanTrigger::printRate
const std::string printRate(const double ratesDenominator) const override
Prints the RatesScanTrigger's rate (different output to a regular trigger)
Definition: RatesScanTrigger.cxx:94
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
RatesScanTrigger::RatesScanTrigger
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 ...
Definition: RatesScanTrigger.cxx:10
RatesScanTrigger::execute
void execute(const WeightingValuesSummary_t &weights) override
Execute trigger rate emulation.
Definition: RatesScanTrigger.cxx:68
RatesScanTrigger::TriggerBehaviour_t
TriggerBehaviour_t
enum to describe if a trigger should activate for values >= or <= than the thresold
Definition: RatesScanTrigger.h:20
ExtrapStrat_t
ExtrapStrat_t
Extrapolation strategy to apply to each emulated trigger.
Definition: RatesHistoBase.h:30
RatesScanTrigger::kTriggerBelowThreshold
@ kTriggerBelowThreshold
Trigger for <= threshold.
Definition: RatesScanTrigger.h:22
RatesTrigger
Used to calculate the rate for a single trigger at L1 or the HLT.
Definition: RatesTrigger.h:15
WeightingValuesSummary_t::m_enhancedBiasWeight
double m_enhancedBiasWeight
A property of the event derived from online enhanced bias prescales.
Definition: RatesHistoBase.h:57
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
RatesScanTrigger::m_thresholdPassed
double m_thresholdPassed
Analogous to m_pass.
Definition: RatesScanTrigger.h:111
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
StdJOSetup.msgSvc
msgSvc
Provide convenience handles for various services.
Definition: StdJOSetup.py:36
RatesHistoBase::getExtrapolationFactor
double getExtrapolationFactor(const WeightingValuesSummary_t &weights, const ExtrapStrat_t strat) const
Definition: RatesHistoBase.cxx:95
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
RatesScanTrigger::passThreshold
void passThreshold(const double t, const bool unbiasedEvent=false)
Sets the threshold the event.
Definition: RatesScanTrigger.cxx:50
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
TH1::Fill
int Fill(double)
Definition: rootspy.cxx:285
min
#define min(a, b)
Definition: cfImp.cxx:40
dumpTgcDigiJitter.nBins
list nBins
Definition: dumpTgcDigiJitter.py:29
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
RatesScanTrigger::kTriggerAboveThreshold
@ kTriggerAboveThreshold
Trigger for >= threshold.
Definition: RatesScanTrigger.h:21
plotBeamSpotVxVal.bin
int bin
Definition: plotBeamSpotVxVal.py:83
TH1::GetBinContent
double GetBinContent(int) const
Definition: rootspy.cxx:298
Base_Fragment.width
width
Definition: Sherpa_i/share/common/Base_Fragment.py:59
RatesTrigger::m_seedPrescale
const double m_seedPrescale
Definition: RatesTrigger.h:135
RatesScanTrigger::giveThresholdHist
StatusCode giveThresholdHist(const ServiceHandle< ITHistSvc > &svc, const std::string &name)
Definition: RatesScanTrigger.cxx:63
RatesScanTrigger.h
RatesTrigger::m_extrapolationStrategy
const ExtrapStrat_t m_extrapolationStrategy
How this trigger is to scale with luminosity.
Definition: RatesTrigger.h:139
RatesScanTrigger::m_behaviour
TriggerBehaviour_t m_behaviour
If we need to be above or below the threshold to cause the trigger to fire.
Definition: RatesScanTrigger.h:112
ValidateEBMenu.seedName
seedName
Definition: ValidateEBMenu.py:100
RatesTrigger::m_seed
const std::string m_seed
My seed, "" if no seed.
Definition: RatesTrigger.h:130
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:200
RatesTrigger::m_totalPrescaleWeight
const double m_totalPrescaleWeight
Equal to 1/m_seedPrescale*m_prescale.
Definition: RatesTrigger.h:136
RatesScanTrigger::setPassedAndExecute
void setPassedAndExecute(const double t, const WeightingValuesSummary_t &weights)
Set the pass threshold and immediately call execute.
Definition: RatesScanTrigger.cxx:55
ServiceHandle< ITHistSvc >
RatesHistoBase::getExtrapolationFactorString
const std::string & getExtrapolationFactorString(ExtrapStrat_t strat) const
Definition: RatesHistoBase.cxx:89