|
ATLAS Offline Software
|
Go to the documentation of this file.
17 #include "GaudiKernel/ITHistSvc.h"
29 m_ratesDenominator(0),
31 m_weightedEventCounter(0),
32 m_scalingHist(nullptr),
34 m_metadataTree(nullptr),
41 const double thresholdMin,
42 const double thresholdMax,
45 const double prescale,
47 const double seedPrecale,
52 ATH_MSG_ERROR(
"Sorry - ScanTriggers have to be implemented with the kMANUAL method for now.");
53 return StatusCode::FAILURE;
57 m_scanTriggers.emplace(
name, std::make_unique<RatesScanTrigger>(
name,
msgSvc(), thresholdMin, thresholdMax, thresholdBins, behaviour, prescale,
seedName, seedPrecale,
e));
61 return StatusCode::SUCCESS;
66 const std::vector<double>& thresholdBinEdges,
68 const double prescale,
70 const double seedPrecale,
75 ATH_MSG_ERROR(
"Sorry - ScanTriggers have to be implemented with the kMANUAL method for now.");
76 return StatusCode::FAILURE;
85 return StatusCode::SUCCESS;
90 const double prescale,
91 const double expressPrescale,
93 const double seedPrecale,
98 std::set<std::string> groupSet;
102 if (!std::getline(
ss,
group,
','))
break;
103 groupSet.insert(
group);
110 const double prescale,
111 const double expressPrescale,
113 const double seedPrecale,
114 const std::set<std::string>&
groups,
119 ATH_MSG_FATAL(
"Too late to call newTrigger. All emulated triggers must be registered during ratesInitialize().");
120 return StatusCode::FAILURE;
128 return StatusCode::SUCCESS;
141 return StatusCode::SUCCESS;
155 if (
group.starts_with(
"BW") ||
group.starts_with(
"PS") ||
group.starts_with(
"STREAM:express"))
continue;
162 it->second->addToGroup( newTriggerPtr );
167 const size_t CPSID = newTriggerPtr->
getCPSID();
182 if (
level == 2 && expressPrescale >= 1) {
188 return StatusCode::SUCCESS;
206 for(
auto &
p : hltPrescalesSet.
data().get_child(
"prescales") ) {
211 ATH_MSG_WARNING(
"Trigger " <<
p.first <<
" disabled in supplied AOD file. DISABLING");
217 for(
auto &
p : l1PrescalesSet.
prescales() ) {
218 if ((!
m_prescalesJSON.value().count(
p.first) && !runWithPrescaleJSON) ||
p.second.prescale < 0){
221 if (
p.second.prescale < 0){
222 ATH_MSG_WARNING(
"Trigger " <<
p.first <<
" disabled in supplied AOD file. DISABLING");
228 for (
const auto& trigger :
triggers) {
230 const bool isHLT = (
getLevel(trigger) == 2);
231 const auto trigConf = (isHLT ?
m_tdt->ExperimentalAndExpertMethods().getChainConfigurationDetails(trigger) :
nullptr);
232 if (isHLT && !trigConf) {
233 ATH_MSG_ERROR(
"Problem with TDT trig conf - cannot get details for " << trigger <<
", will be ignored.");
236 const std::string lowerName = (isHLT ? trigConf->lower_chain_name() :
"");
237 std::set<std::string>
groups = std::set<std::string>();
241 if (lowerName.find(
",") != std::string::npos) {
242 ATH_MSG_WARNING(
"Can not add " << trigger <<
" due to multiple L1 seeds." );
246 if (lowerName.empty()) {
247 ATH_MSG_WARNING(
"Can not add " << trigger <<
" due to multiple L1 seeds: L1All" );
252 if (trigConf->prescale() < 1.) {
253 ATH_MSG_DEBUG(
"Will not add " << trigger <<
", it was disabled in the reprocessing.");
266 std::vector<std::string> chainGroups = (*chain).groups();
267 std::vector<std::string> chainStreams = (*chain).streams();
269 ATH_MSG_DEBUG(
" chain " << trigger <<
" has " << chainGroups.size() <<
" groups and " << chainStreams.size() <<
" streams");
271 groups.insert(chainGroups.begin(), chainGroups.end());
272 for (
const std::string&
stream : chainStreams){
278 double prescale = 1., expressPrescale = -1., lowerPrescale = 1.;
281 ATH_MSG_WARNING(
"Unable to find " << trigger <<
" in supplied JSON. DISABLING." );
289 ATH_MSG_WARNING(
"Unable to find " << trigger <<
"'s seed, " << lowerName <<
", in supplied JSON. DISABLING." );
299 ATH_MSG_DEBUG(
"Registering existing trigger " << trigger <<
" for automatic TDT based rates prediction." );
305 ATH_MSG_WARNING(
"Trigger " << trigger.first <<
" in supplied JSON is NOT AVAILABLE in the supplied AOD file.");
309 return StatusCode::SUCCESS;
315 return StatusCode::FAILURE;
317 [[maybe_unused]]
static std::atomic<bool> printed = [&]() {
318 ATH_MSG_INFO(
"TDT contains: " <<
m_tdt->getListOfTriggers().size() <<
" triggers, "
319 <<
m_tdt->getListOfStreams().size() <<
" streams and "
320 <<
m_tdt->getListOfGroups().size() <<
" groups.");
323 return StatusCode::SUCCESS;
332 return StatusCode::FAILURE;
336 const auto trigConf =
m_tdt->ExperimentalAndExpertMethods().getChainConfigurationDetails(
triggers.at(0));
337 if (trigConf->lower_chain_name() !=
seedName) {
338 ATH_MSG_FATAL(
"Tried to register an existing trigger '" <<
name <<
"' seeding from '" <<
seedName <<
"' but in this AOD it seeds from '" << trigConf->lower_chain_name() <<
"'");
339 return StatusCode::FAILURE;
341 return StatusCode::SUCCESS;
347 if (triggerIsPassed || triggerIsActive) {
350 ATH_MSG_ERROR(
"Cannot find trigger " <<
name <<
" did you call newTrigger for this in initialize?");
351 return StatusCode::FAILURE;
356 return StatusCode::SUCCESS;
363 ATH_MSG_ERROR(
"Cannot find scan-trigger " <<
name <<
" did you call newScanTrigger for this in initialize?");
364 return StatusCode::FAILURE;
368 return StatusCode::SUCCESS;
385 ATH_MSG_ERROR(
"DoUniqueRates=True requires DoGlobalGroups=True");
386 return StatusCode::FAILURE;
389 return StatusCode::SUCCESS;
394 ATH_MSG_INFO(
"Initializing User's Triggers (note: we are actually now in the event loop)");
410 ATH_MSG_INFO(
"Computing coherent factors for coherent prescale groups.");
413 const size_t CPSID = trigger.second->getCPSID();
414 if (CPSID != 0) trigger.second->setCoherentFactor(
m_lowestPrescale.at(CPSID) );
418 ATH_MSG_INFO(
"Creating extra groups to calculate unique rates.");
443 if (trigger.second->getDisabled() ==
false) {
449 ATH_MSG_INFO(
"Retrieving HLT chain's ID and Group from HLT menu.");
461 for( ; chain_itr != chain_end; ++chain_itr ) {
462 std::string
chainName = ( *chain_itr ).name() ;
463 unsigned int chainID = ( *chain_itr ).counter();
464 std::vector<std::string> chainGroups = ( *chain_itr ).groups();
465 for (std::string&
stream : (*chain_itr).streams()){
466 chainGroups.push_back(
"STREAM:" +
stream);
468 std::string singlechainGroups =
"";
469 for (
unsigned int j=0; j < chainGroups.size(); ++j){
470 if (j==0) singlechainGroups += chainGroups[j];
471 else singlechainGroups +=
", "+chainGroups[j];
487 for (
size_t i = 0;
i <
l1menu.size();
i++) {
496 for( ; item_itr != item_end; ++item_itr ) {
506 ATH_MSG_DEBUG(
"################## Configured to estimate rates for the following triggers:");
510 ATH_MSG_DEBUG(
"################## Configured to estimate rates for the following scan triggers:");
514 ATH_MSG_DEBUG(
"################## Configured to estimate rates for the following groups of triggers:");
518 ATH_MSG_DEBUG(
"################## Configured to estimate rates for the following global groups of triggers:");
524 ATH_MSG_DEBUG(
"################## Registering normalisation histogram:");
527 m_bcidHist =
new TH1D(
"bcid",
";BCID;Events",3565,-.5,3564.5);
529 ATH_MSG_DEBUG(
"################## Registering metadata tree histogram:");
530 ATH_CHECK(
histSvc()->regTree(
"/RATESTREAM/metadata", std::make_unique<TTree>(
"metadata",
"metadata")) );
533 ATH_MSG_DEBUG(
"################## Registering trigger histograms:");
535 if (!trigger.second->doHistograms())
continue;
536 std::string lvlSubdir =
"";
537 if (trigger.second->getName().find(
"L1") == 0){
538 lvlSubdir =
"Rate_ChainL1_HLT/";
539 }
else if (trigger.second->getName().find(
"HLT") == 0) {
540 lvlSubdir =
"Rate_ChainHLT_HLT/";
542 ATH_CHECK( trigger.second->giveDataHist(
histSvc(), std::string(
"/RATESTREAM/All/" + lvlSubdir + trigger.first +
"/data")) );
543 ATH_CHECK( trigger.second->giveMuHist(
histSvc(), std::string(
"/RATESTREAM/All/" + lvlSubdir + trigger.first +
"/rateVsMu")) );
545 else trigger.second->clearTrainHist();
549 ATH_MSG_DEBUG(
"################## Registering scan trigger histograms:");
551 ATH_CHECK( trigger.second->giveThresholdHist(
histSvc(), std::string(
"/RATESTREAM/ScanTriggers/" + trigger.first +
"/rateVsThreshold")) );
555 ATH_MSG_DEBUG(
"################## Registering group histograms:");
557 if (!
group.second->doHistograms())
continue;
563 else group.second->clearTrainHist();
567 ATH_MSG_DEBUG(
"################## Registering global group histograms:");
569 if (!
group.second->doHistograms())
continue;
570 ATH_CHECK(
group.second->giveDataHist(
histSvc(), std::string(
"/RATESTREAM/All/Rate_Group_HLT/RATE_GLOBAL_" +
group.first +
"/data")) );
571 ATH_CHECK(
group.second->giveMuHist(
histSvc(), std::string(
"/RATESTREAM/All/Rate_Group_HLT/RATE_GLOBAL_" +
group.first +
"/rateVsMu")) );
573 else group.second->clearTrainHist();
586 return StatusCode::SUCCESS;
652 setFilterPassed(
true);
653 return StatusCode::SUCCESS;
658 const bool passed = trigger.second->isPassed();
662 const std::unordered_map<std::string, const Trig::ChainGroup*>::const_iterator
it =
m_existingTriggers.find(lower);
666 return StatusCode::SUCCESS;
672 ATH_MSG_WARNING(
"Cannot do rates for " << trigger <<
". Automatic trigger emulation is not yet included, sorry :(");
674 return StatusCode::SUCCESS;
682 ATH_MSG_INFO(
"################## Computed Rate Scans for Threshold-Scan Items:");
686 ATH_MSG_INFO(
"################## Computed Rate Estimations for Single Items:");
687 std::set<std::string>
keys;
688 for (
const auto& trigger :
m_triggers)
keys.insert(trigger.first);
692 ATH_MSG_INFO(
"################## Computed Express Rate Estimations for Single Items:");
696 ATH_MSG_INFO(
"################## Computed Rate Estimations for Groups:");
700 ATH_MSG_INFO(
"################## Computed Rate Estimations for Global Groups:");
703 ATH_MSG_INFO(
"################## LHC Conditions and weighting information:");
711 return StatusCode::SUCCESS;
716 ATH_MSG_WARNING(
"Too late to call setTargetLumiMu. Do this during ratesInitialize().");
736 ATH_MSG_WARNING(
"Too late to call setTargetLumiBunches. Do this during ratesInitialize().");
753 ATH_MSG_WARNING(
"Too late to call setTargetMuBunches. Do this during ratesInitialize().");
776 ATH_MSG_INFO(
"Luminosity extrapolation is switched off. Input files will determin the paired bunches, L_inst. and mu profile.");
786 <<
" with <L_inst.> = "
788 <<
" cm-2s-1, <mu> = "
790 <<
", paired bunches = "
795 return (
group.find(
"CPS") != std::string::npos);
799 if (me.find(
"L1_RD") != std::string::npos)
return true;
800 if (me.find(
"L1RD") != std::string::npos)
return true;
801 if (seed.find(
"L1_RD") != std::string::npos)
return true;
806 if (
name.find(
"HLT_") != std::string::npos)
return 2;
807 if (
name.find(
"L1_") != std::string::npos)
return 1;
824 std::vector<std::string> lowers;
826 std::vector<double> express;
833 lowers.push_back(trigger.second->getSeedName());
834 prescales.push_back(trigger.second->getPrescale() );
835 express.push_back(trigger.second->getPrescale(
true ) );
840 lowers.push_back(
"-");
842 express.push_back(-1);
847 lowers.push_back(
"-");
849 express.push_back(-1);
857 std::vector<int32_t> bunchGroups;
858 bunchGroups.reserve(16);
867 bunchGroups.push_back(
bg.bunches().size());
874 if (bunchGroups.size() == 0 || std::all_of(bunchGroups.begin(), bunchGroups.end(), [](
int i) { return i==0; })) {
887 std::string atlasProject =
std::getenv(
"AtlasProject");
888 std::string atlasVersion =
std::getenv(
"AtlasVersion");
def retrieve(aClass, aKey=None)
JetConstituentVector::iterator iterator
const ptree & data() const
Access to the underlying data, if needed.
void printStatistics() const
Print some extra statistics on events processed.
const ServiceHandle< ITHistSvc > & histSvc() const
The standard THistSvc (for writing histograms and TTrees and more to a root file) Returns (kind of) a...
const std::string m_expressGroupName
std::string replace(std::string s, const std::string &s2, const std::string &s3)
StatusCode populateTriggers()
Register all triggers to emulate.
uint32_t m_runNumber
What is the RunNumber.
double m_eventLiveTime
How much wall-time at P1 did this event represent.
Used to calculate a rate scan as a function of some threshold value.
ToolHandle< Trig::TrigDecisionTool > m_tdt
StatusCode newTrigger(const std::string &name, const double prescale=1., const double expressPrescale=-1., const std::string &seedName="", const double seedPrecale=1., const std::string &groups="", const Method_t method=kMANUAL, const ExtrapStrat_t extrapolation=kLINEAR)
Version of newTrigger which accepts a set of group names rather than a comma separated string.
void removeFromGroup(const RatesTrigger *toRemove)
Remove a trigger from this group.
Gaudi::Property< bool > m_enableLumiExtrapolation
std::unordered_map< std::string, std::string > m_lowerTrigger
Map of triggers lower chain, to tell if a HLT trigger ran or not.
virtual StatusCode ratesExecute()=0
To be implemented by the user.
bool passed(DecisionID id, const DecisionIDContainer &idSet)
checks if required decision ID is in the set of IDs in the container
std::string find(const std::string &s)
return a remapped string
std::unordered_map< std::string, std::unique_ptr< RatesScanTrigger > > m_scanTriggers
All individual rates-scan triggers (L1 or HLT)
virtual ~RatesAnalysisAlg()
StatusCode checkGotTDT()
Internal check that the TDT is fetched.
StatusCode newScanTrigger(const std::string &name, const double thresholdMin, const double thresholdMax, const uint32_t thresholdBins=100, const RatesScanTrigger::TriggerBehaviour_t behaviour=RatesScanTrigger::TriggerBehaviour_t::kTriggerBelowThreshold, const double prescale=1., const std::string &seedName="", const double seedPrecale=1., const Method_t method=kMANUAL, const ExtrapStrat_t extrapolation=kLINEAR)
Register a new threshold scan trigger which plots rate as a function of some dependent variable.
bool m_isUnbiased
If the event was taken online with a RD trigger.
const std::string m_l2GroupName
void setUseCachedWeights(const bool i)
Set to use cached weights from the Master group (need ptr to m_masterGroup)
float round(const float toRound, const unsigned int decimals)
TH1D * m_bcidHist
Histogram of the BCIDs distribution of the processing.
double m_eventLumi
The instantaneous lumi in cm-2s-1.
ToolHandle< IEnhancedBiasWeighter > m_enhancedBiasRatesTool
virtual StatusCode ratesInitialize()=0
To be implemented by the user.
const std::string print()
Gaudi::Property< double > m_expoScalingFactor
const HLTPrescale & prescale_express(const std::string &chainName) const
HLT prescales by chain names.
std::unordered_map< std::string, std::unique_ptr< RatesGroup > > m_groups
All regular and CPS groups.
double m_ratesDenominator
How much walltime is seen by the algorithm.
double m_linearLumiFactor
What weight needs to be applied to extrapolate rates linear in mu and bunches.
uint32_t m_distanceInTrain
How far into the bunch train the event was, in bunch crossings.
Gaudi::Property< bool > m_doUniqueRates
std::unordered_map< std::string, std::unique_ptr< RatesGroup > > m_globalGroups
Big (master) groups which do the OR of the whole menu.
double m_targetMu
What pileup level the prediction is targeting.
std::vector< std::string > m_autoTriggers
List of triggers which it is up to us to the algorithm to work out the pass/fail for.
TriggerBehaviour_t
enum to describe if a trigger should activate for values >= or <= than the thresold
@ kEXISTING
The pass/fail decision is taken from the Trigger Decision Tool for an existing trigger.
std::string getTree(const std::string &file_name)
void setUniqueGroup(const RatesGroup *unique)
If I have a group which is calculating my unique rate.
ExtrapStrat_t
Extrapolation strategy to apply to each emulated trigger.
void setTargetMuBunches(const double mu, const int32_t bunches)
Set the target mu and number of bunches.
This file contains the class definition for the EventStreamInfo class.
Gaudi::Property< std::map< std::string, std::map< std::string, double > > > m_prescalesJSON
void setTargetLumiMu(const double lumi, const double mu)
Set the target instantaneous luminosity and mu.
@ kAUTO
The pass/fail decision is automatically emulated per event based on decoding the trigger name.
double m_weightedEventCounter
Count how many weighted events were processed.
Used to calculate the rate for a single trigger at L1 or the HLT.
virtual StatusCode initialize()
Get the trigger decision tool and set up global groups.
Used to calculate the rate for a group of RatesTrigger objects at L1 or the HLT.
Method_t
Method by which the trigger pass/fail decision is calculated.
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
double m_enhancedBiasWeight
A property of the event derived from online enhanced bias prescales.
StatusCode executeTriggerEmulation()
Internal call to get the pass/fail for all automatically emulated triggers.
void setSeedsFromRandom(const bool i)
Set if this trigger is to behave as if it seeds from a random L1 item.
msgSvc
Provide convenience handles for various services.
const HLTPrescale & prescale(const std::string &chainName) const
HLT prescales by chain names.
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)
::StatusCode StatusCode
StatusCode definition for legacy code.
TTree * m_metadataTree
Used to write out some metadata needed by post-processing (e.g.
double m_targetBunches
How many bunches the prediction is targeting.
void setTargetLumiBunches(const double lumi, const int32_t bunches)
Set the target instantaneous luminosity and number of bunches.
RatesAnalysisAlg(const std::string &name, ISvcLocator *pSvcLocator)
bool isCPS(const std::string &group) const
String match coherent prescale groups.
std::unordered_map< std::string, std::unique_ptr< RatesGroup > > m_uniqueGroups
Groups used to obtain unique rates for chains.
WeightingValuesSummary_t m_weightingValues
Possible weighting & lumi extrapolation values for the current event.
StatusCode addExisting(const std::string &pattern)
Register some existing triggers based on wild-card match, e.g.
double m_expoMuFactor
What weight needs to be applied to extrapolate rates linear in bunches and exponential in mu.
size_t getCPSID() const
Get the hash of my CPS group name.
@ kMANUAL
The pass/fail decision is evaluated by the user and supplied per event using setTriggerDesicison.
Gaudi::Property< bool > m_doHistograms
virtual StatusCode execute()
In first call - register all triggers.
void removeOtherL1(const RatesTrigger *toKeep)
Remove from the groups mapping all triggers which have a dissimilar seed to the supplied trigger.
std::unordered_set< RatesGroup * > m_activeGroups
All groups which are enabled (PS >= 1)
void printTarget() const
Print the target instantaneous luminosity, mu and number of bunches.
bool isRandomSeed(const std::string &me, const std::string &seed) const
String match random L1 items.
constexpr static uint32_t FULL_RING
Number of bunches in a full ring.
bool getDisabled() const
If I or my seed were prescaled out.
double m_bunchFactor
What weight needs to be applied to extrapolate rates linear in number of bunches.
Forward iterator over an iterable of type V returning an object of type T.
const std::vector< BunchGroup > & bunchGroups() const
std::unordered_set< RatesTrigger * > m_activatedTriggers
Triggers which were changed & hence need to be reset at the event end.
Gaudi::Property< bool > m_doExpressRates
static bool isZero(double v)
constexpr static double LHC_FREQUENCY
std::string to_string(const DetectorType &type)
TH1D * m_scalingHist
One-bin histogram to store the normalisation of the sample, for use in later combinations.
void setTargetLumi(const double lumi)
Set the target instantaneous luminosity.
StatusCode executeTrigDecisionToolTriggers()
Internal call to get the pass/fail for all TDT triggers.
void setUniqueTrigger(RatesTrigger *trigger)
Set trigger I am doing unique rates for.
Class describing the basic event information.
StatusCode checkExistingTrigger(const std::string &name, const std::string &seedName)
Internal function to check if a supplied HLT trigger and L1 seed match what is stored in the AOD conf...
void writeMetadata()
Write to outpute tree (if any) the metadata needed downstream.
std::unordered_map< std::string, std::unique_ptr< RatesTrigger > > m_triggers
All individual triggers (L1 or HLT)
uint32_t getLevel(const std::string &name) const
String match to a trigger level.
ServiceHandle< TrigConf::ITrigConfigSvc > m_configSvc
void printInputSummary() const
Print the input data instantaneous luminosity, mu and number of bunches.
std::string getenv(const std::string &variableName)
get an environment variable
const std::string m_l1GroupName
#define ATH_MSG_WARNING(x)
std::unordered_map< size_t, double > m_lowestPrescale
Lowest prescale within a CPS group, key is the hash of the CPS group name.
std::vector< std::vector< std::string > > m_l1ItemID
const std::map< std::string, L1Prescale > & prescales() const
virtual StatusCode ratesFinalize()=0
To be implemented by the user.
std::unordered_map< std::string, const Trig::ChainGroup * > m_existingTriggers
Map of triggers which we ask the TDT ChainGroup for the pass/fail.
Gaudi::Property< uint32_t > m_vetoStartOfTrain
double m_muFactor
What weight needs to be applied to extrapolate rates linear in mu.
StatusCode addAllExisting()
Register all existing triggers in the AOD into the rates algorithm.
virtual StatusCode finalize()
Print rates.
Gaudi::Property< bool > m_doTriggerGroups
Gaudi::Property< bool > m_useBunchCrossingData
uint32_t bcid() const
The bunch crossing ID of the event.
double m_targetLumi
What instantaneous luminosity the prediction is targeting.
uint32_t m_eventCounter
Count how many events processed.
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
StatusCode setTriggerDesicison(const std::string &name, const bool triggerIsPassed=true, const bool triggerIsActive=true)
Set the pass/fail decision for an item.
Gaudi::Property< double > m_inelasticCrossSection
Gaudi::Property< bool > m_doGlobalGroups
std::vector< std::vector< std::string > > m_hltChainIDGroup
bool isZero(double v) const
Helper function for floating point subtraction.
float actualInteractionsPerCrossing() const
Average interactions per crossing for the current BCID - for in-time pile-up.
void duplicateChildren(const RatesGroup *toDuplicate)
Copy in triggers from another group.
@ kNONE
Do not scale this trigger for changes in luminosity.
std::unordered_set< RatesTrigger * > m_expressTriggers
Triggers with non-zero express PS, used to print them at the end.
double m_eventMu
The actual number of interactions in the event.