ATLAS Offline Software
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 
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)),
19  m_rateScanHistCachedPtr(m_rateScanHist.get()), m_thresholdPassed(0), m_behaviour(behaviour)
20  {
21  m_rateScanHist->Sumw2(true);
22  }
23 
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),
32  m_rateScanHist(nullptr), m_rateScanHistCachedPtr(nullptr), m_thresholdPassed(0), m_behaviour(behaviour)
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 
46 }
47 
48 void 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 
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 const std::string RatesScanTrigger::printRate(const double ratesDenominator) const {
93  std::stringstream ss;
94  const int nBins = m_rateScanHistCachedPtr->GetNbinsX();
95  ss << std::setfill(' ');
96  ss << m_name << " [PS:" << m_prescale << "]";
97  if (m_seed != "") ss << " <- " << m_seed << " [PS:" << m_seedPrescale << "]";
98  ss << " (Extrap:"<< getExtrapolationFactorString(m_extrapolationStrategy) << ")" << std::endl;
99 
101 
102  ss << " Threshold <= " << std::setw(11) << std::left << std::as_const(*m_rateScanHistCachedPtr).GetXaxis()->GetXmin();
103  ss << " Rate :" << std::setw(11) << std::right << m_rateScanHistCachedPtr->GetBinContent(0)/ratesDenominator;
104  ss << " +- " << std::setw(11) << std::left << m_rateScanHistCachedPtr->GetBinError(0)/ratesDenominator << " Hz" << std::endl;
105 
106  for (int bin = 1; bin <= nBins; ++bin) {
107  ss << " Threshold <= ";
108  ss << std::setw(11) << std::left << m_rateScanHistCachedPtr->GetBinLowEdge(bin) + m_rateScanHistCachedPtr->GetBinWidth(bin);
109  ss << " Rate :" << std::setw(11) << std::right << m_rateScanHistCachedPtr->GetBinContent(bin)/ratesDenominator;
110  ss << " +- " << std::setw(11) << std::left << m_rateScanHistCachedPtr->GetBinError(bin)/ratesDenominator << " Hz";
111  ss << std::endl;
112  }
113 
114  ss << " Threshold > " << std::setw(11) << std::left << std::as_const(*m_rateScanHistCachedPtr).GetXaxis()->GetXmax();
115  ss << " Rate :" << std::setw(11) << std::right << m_rateScanHistCachedPtr->GetBinContent(nBins+1)/ratesDenominator;
116  ss << " +- " << std::setw(11) << std::left << m_rateScanHistCachedPtr->GetBinError(nBins+1)/ratesDenominator << " Hz";
117 
118  } else if (m_behaviour == kTriggerAboveThreshold) {
119 
120  ss << " Threshold < " << std::setw(11) << std::left << std::as_const(*m_rateScanHistCachedPtr).GetXaxis()->GetXmin();
121  ss << " Rate: " << std::setw(11) << std::right << m_rateScanHistCachedPtr->GetBinContent(0)/ratesDenominator;
122  ss << " +- " << std::setw(11) << std::left << m_rateScanHistCachedPtr->GetBinError(0)/ratesDenominator << " Hz" << std::endl;
123 
124  for (int bin = 1; bin <= nBins; ++bin) {
125  ss << " Threshold >= ";
126  ss << std::setw(11) << std::left << m_rateScanHistCachedPtr->GetBinLowEdge(bin);
127  ss << " Rate: " << std::setw(11) << std::right << m_rateScanHistCachedPtr->GetBinContent(bin)/ratesDenominator;
128  ss << " +- " << std::setw(11) << std::left << m_rateScanHistCachedPtr->GetBinError(bin)/ratesDenominator << " Hz";
129  ss << std::endl;
130  }
131 
132  ss << " Threshold >= " << std::setw(11) << std::left << std::as_const(*m_rateScanHistCachedPtr).GetXaxis()->GetXmax();
133  ss << " Rate: " << std::setw(11) << std::right << m_rateScanHistCachedPtr->GetBinContent(nBins+1)/ratesDenominator;
134  ss << " +- " << std::setw(11) << std::left << m_rateScanHistCachedPtr->GetBinError(nBins+1)/ratesDenominator << " Hz";
135 
136  }
137 
138  return ss.str();
139 }
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:45
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
make_unique
std::unique_ptr< T > make_unique(Args &&... args)
Definition: SkimmingToolEXOT5.cxx:23
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
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:92
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:66
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
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:93
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:48
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
dumpTgcDigiJitter.nBins
list nBins
Definition: dumpTgcDigiJitter.py:29
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
RatesScanTrigger::kTriggerAboveThreshold
@ kTriggerAboveThreshold
Trigger for >= threshold.
Definition: RatesScanTrigger.h:21
plotBeamSpotVxVal.bin
int bin
Definition: plotBeamSpotVxVal.py:83
weights
Definition: herwig7_interface.h:38
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:61
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127
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:53
ServiceHandle< ITHistSvc >
RatesHistoBase::getExtrapolationFactorString
const std::string & getExtrapolationFactorString(ExtrapStrat_t strat) const
Definition: RatesHistoBase.cxx:87