|
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)
40 const double thresholdMin,
41 const double thresholdMax,
44 const double prescale,
46 const double seedPrecale,
51 ATH_MSG_ERROR(
"Sorry - ScanTriggers have to be implemented with the kMANUAL method for now.");
52 return StatusCode::FAILURE;
56 m_scanTriggers.emplace(
name, std::make_unique<RatesScanTrigger>(
name,
msgSvc(), thresholdMin, thresholdMax, thresholdBins, behaviour, prescale,
seedName, seedPrecale,
e));
60 return StatusCode::SUCCESS;
65 const std::vector<double>& thresholdBinEdges,
67 const double prescale,
69 const double seedPrecale,
74 ATH_MSG_ERROR(
"Sorry - ScanTriggers have to be implemented with the kMANUAL method for now.");
75 return StatusCode::FAILURE;
84 return StatusCode::SUCCESS;
89 const double prescale,
90 const double expressPrescale,
92 const double seedPrecale,
97 std::set<std::string> groupSet;
101 if (!std::getline(
ss,
group,
','))
break;
102 groupSet.insert(
group);
109 const double prescale,
110 const double expressPrescale,
112 const double seedPrecale,
113 const std::set<std::string>&
groups,
118 ATH_MSG_FATAL(
"Too late to call newTrigger. All emulated triggers must be registered during ratesInitialize().");
119 return StatusCode::FAILURE;
127 return StatusCode::SUCCESS;
140 return StatusCode::SUCCESS;
154 if (
group.find(
"BW") == 0 ||
group.find(
"PS") == 0 ||
group.find(
"STREAM:express") == 0)
continue;
165 const size_t CPSID = newTriggerPtr->
getCPSID();
180 if (
level == 2 && expressPrescale >= 1) {
186 return StatusCode::SUCCESS;
204 for(
auto &
p : hltPrescalesSet.
data().get_child(
"prescales") ) {
209 ATH_MSG_WARNING(
"Trigger " <<
p.first <<
" disabled in supplied AOD file. DISABLING");
215 for(
auto &
p : l1PrescalesSet.
prescales() ) {
216 if ((!
m_prescalesJSON.value().count(
p.first) && !runWithPrescaleJSON) ||
p.second.prescale < 0){
219 if (
p.second.prescale < 0){
220 ATH_MSG_WARNING(
"Trigger " <<
p.first <<
" disabled in supplied AOD file. DISABLING");
226 for (
const auto& trigger :
triggers) {
228 const bool isHLT = (
getLevel(trigger) == 2);
229 const auto trigConf = (isHLT ?
m_tdt->ExperimentalAndExpertMethods().getChainConfigurationDetails(trigger) :
nullptr);
230 if (isHLT && !trigConf) {
231 ATH_MSG_ERROR(
"Problem with TDT trig conf - cannot get details for " << trigger <<
", will be ignored.");
234 const std::string lowerName = (isHLT ? trigConf->lower_chain_name() :
"");
235 std::set<std::string>
groups = std::set<std::string>();
239 if (lowerName.find(
",") != std::string::npos) {
240 ATH_MSG_WARNING(
"Can not add " << trigger <<
" due to multiple L1 seeds." );
244 if (lowerName.empty()) {
245 ATH_MSG_WARNING(
"Can not add " << trigger <<
" due to multiple L1 seeds: L1All" );
250 if (trigConf->prescale() < 1.) {
251 ATH_MSG_DEBUG(
"Will not add " << trigger <<
", it was disabled in the reprocessing.");
264 std::vector<std::string> chainGroups = (*chain).groups();
265 std::vector<std::string> chainStreams = (*chain).streams();
267 ATH_MSG_DEBUG(
" chain " << trigger <<
" has " << chainGroups.size() <<
" groups and " << chainStreams.size() <<
" streams");
269 groups.insert(chainGroups.begin(), chainGroups.end());
270 for (
const std::string&
stream : chainStreams){
276 double prescale = 1., expressPrescale = -1., lowerPrescale = 1.;
279 ATH_MSG_WARNING(
"Unable to find " << trigger <<
" in supplied JSON. DISABLING." );
287 ATH_MSG_WARNING(
"Unable to find " << trigger <<
"'s seed, " << lowerName <<
", in supplied JSON. DISABLING." );
297 ATH_MSG_DEBUG(
"Registering existing trigger " << trigger <<
" for automatic TDT based rates prediction." );
303 ATH_MSG_WARNING(
"Trigger " << trigger.first <<
" in supplied JSON is NOT AVAILABLE in the supplied AOD file.");
307 return StatusCode::SUCCESS;
313 return StatusCode::FAILURE;
315 [[maybe_unused]]
static std::atomic<bool> printed = [&]() {
316 ATH_MSG_INFO(
"TDT contains: " <<
m_tdt->getListOfTriggers().size() <<
" triggers, "
317 <<
m_tdt->getListOfStreams().size() <<
" streams and "
318 <<
m_tdt->getListOfGroups().size() <<
" groups.");
321 return StatusCode::SUCCESS;
330 return StatusCode::FAILURE;
334 const auto trigConf =
m_tdt->ExperimentalAndExpertMethods().getChainConfigurationDetails(
triggers.at(0));
335 if (trigConf->lower_chain_name() !=
seedName) {
336 ATH_MSG_FATAL(
"Tried to register an existing trigger '" <<
name <<
"' seeding from '" <<
seedName <<
"' but in this AOD it seeds from '" << trigConf->lower_chain_name() <<
"'");
337 return StatusCode::FAILURE;
339 return StatusCode::SUCCESS;
345 if (triggerIsPassed || triggerIsActive) {
348 ATH_MSG_ERROR(
"Cannot find trigger " <<
name <<
" did you call newTrigger for this in initialize?");
349 return StatusCode::FAILURE;
354 return StatusCode::SUCCESS;
361 ATH_MSG_ERROR(
"Cannot find scan-trigger " <<
name <<
" did you call newScanTrigger for this in initialize?");
362 return StatusCode::FAILURE;
366 return StatusCode::SUCCESS;
383 ATH_MSG_ERROR(
"DoUniqueRates=True requires DoGlobalGroups=True");
384 return StatusCode::FAILURE;
387 return StatusCode::SUCCESS;
392 ATH_MSG_INFO(
"Initializing User's Triggers (note: we are actually now in the event loop)");
408 ATH_MSG_INFO(
"Computing coherent factors for coherent prescale groups.");
411 const size_t CPSID = trigger.second->getCPSID();
412 if (CPSID != 0) trigger.second->setCoherentFactor(
m_lowestPrescale.at(CPSID) );
416 ATH_MSG_INFO(
"Creating extra groups to calculate unique rates.");
441 if (trigger.second->getDisabled() ==
false) {
447 ATH_MSG_INFO(
"Retrieving HLT chain's ID and Group from HLT menu.");
459 for( ; chain_itr != chain_end; ++chain_itr ) {
460 std::string
chainName = ( *chain_itr ).name() ;
461 unsigned int chainID = ( *chain_itr ).counter();
462 std::vector<std::string> chainGroups = ( *chain_itr ).groups();
463 for (std::string&
stream : (*chain_itr).streams()){
464 chainGroups.push_back(
"STREAM:" +
stream);
466 std::string singlechainGroups =
"";
467 for (
unsigned int j=0; j < chainGroups.size(); ++j){
468 if (j==0) singlechainGroups += chainGroups[j];
469 else singlechainGroups +=
", "+chainGroups[j];
485 for (
size_t i = 0;
i <
l1menu.size();
i++) {
494 for( ; item_itr != item_end; ++item_itr ) {
504 ATH_MSG_DEBUG(
"################## Configured to estimate rates for the following triggers:");
508 ATH_MSG_DEBUG(
"################## Configured to estimate rates for the following scan triggers:");
512 ATH_MSG_DEBUG(
"################## Configured to estimate rates for the following groups of triggers:");
516 ATH_MSG_DEBUG(
"################## Configured to estimate rates for the following global groups of triggers:");
522 ATH_MSG_DEBUG(
"################## Registering normalisation histogram:");
525 m_bcidHist =
new TH1D(
"bcid",
";BCID;Events",3565,-.5,3564.5);
527 ATH_MSG_DEBUG(
"################## Registering metadata tree histogram:");
528 ATH_CHECK(
histSvc()->regTree(
"/RATESTREAM/metadata", std::make_unique<TTree>(
"metadata",
"metadata")) );
531 ATH_MSG_DEBUG(
"################## Registering trigger histograms:");
533 if (!trigger.second->doHistograms())
continue;
534 std::string lvlSubdir =
"";
535 if (trigger.second->getName().find(
"L1") == 0){
536 lvlSubdir =
"Rate_ChainL1_HLT/";
537 }
else if (trigger.second->getName().find(
"HLT") == 0) {
538 lvlSubdir =
"Rate_ChainHLT_HLT/";
540 ATH_CHECK( trigger.second->giveDataHist(
histSvc(), std::string(
"/RATESTREAM/All/" + lvlSubdir + trigger.first +
"/data")) );
541 ATH_CHECK( trigger.second->giveMuHist(
histSvc(), std::string(
"/RATESTREAM/All/" + lvlSubdir + trigger.first +
"/rateVsMu")) );
543 else trigger.second->clearTrainHist();
547 ATH_MSG_DEBUG(
"################## Registering scan trigger histograms:");
549 ATH_CHECK( trigger.second->giveThresholdHist(
histSvc(), std::string(
"/RATESTREAM/ScanTriggers/" + trigger.first +
"/rateVsThreshold")) );
553 ATH_MSG_DEBUG(
"################## Registering group histograms:");
555 if (!
group.second->doHistograms())
continue;
561 else group.second->clearTrainHist();
565 ATH_MSG_DEBUG(
"################## Registering global group histograms:");
567 if (!
group.second->doHistograms())
continue;
568 ATH_CHECK(
group.second->giveDataHist(
histSvc(), std::string(
"/RATESTREAM/All/Rate_Group_HLT/RATE_GLOBAL_" +
group.first +
"/data")) );
569 ATH_CHECK(
group.second->giveMuHist(
histSvc(), std::string(
"/RATESTREAM/All/Rate_Group_HLT/RATE_GLOBAL_" +
group.first +
"/rateVsMu")) );
571 else group.second->clearTrainHist();
584 return StatusCode::SUCCESS;
650 setFilterPassed(
true);
651 return StatusCode::SUCCESS;
656 const bool passed = trigger.second->isPassed();
660 const std::unordered_map<std::string, const Trig::ChainGroup*>::const_iterator
it =
m_existingTriggers.find(lower);
664 return StatusCode::SUCCESS;
670 ATH_MSG_WARNING(
"Cannot do rates for " << trigger <<
". Automatic trigger emulation is not yet included, sorry :(");
672 return StatusCode::SUCCESS;
680 ATH_MSG_INFO(
"################## Computed Rate Scans for Threshold-Scan Items:");
684 ATH_MSG_INFO(
"################## Computed Rate Estimations for Single Items:");
685 std::set<std::string>
keys;
686 for (
const auto& trigger :
m_triggers)
keys.insert(trigger.first);
690 ATH_MSG_INFO(
"################## Computed Express Rate Estimations for Single Items:");
694 ATH_MSG_INFO(
"################## Computed Rate Estimations for Groups:");
698 ATH_MSG_INFO(
"################## Computed Rate Estimations for Global Groups:");
701 ATH_MSG_INFO(
"################## LHC Conditions and weighting information:");
709 return StatusCode::SUCCESS;
714 ATH_MSG_WARNING(
"Too late to call setTargetLumiMu. Do this during ratesInitialize().");
734 ATH_MSG_WARNING(
"Too late to call setTargetLumiBunches. Do this during ratesInitialize().");
751 ATH_MSG_WARNING(
"Too late to call setTargetMuBunches. Do this during ratesInitialize().");
774 ATH_MSG_INFO(
"Luminosity extrapolation is switched off. Input files will determin the paired bunches, L_inst. and mu profile.");
784 <<
" with <L_inst.> = "
786 <<
" cm-2s-1, <mu> = "
788 <<
", paired bunches = "
793 return (
group.find(
"CPS") != std::string::npos);
797 if (me.find(
"L1_RD") != std::string::npos)
return true;
798 if (me.find(
"L1RD") != std::string::npos)
return true;
799 if (seed.find(
"L1_RD") != std::string::npos)
return true;
804 if (
name.find(
"HLT_") != std::string::npos)
return 2;
805 if (
name.find(
"L1_") != std::string::npos)
return 1;
822 std::vector<std::string> lowers;
824 std::vector<double> express;
831 lowers.push_back(trigger.second->getSeedName());
832 prescales.push_back(trigger.second->getPrescale() );
833 express.push_back(trigger.second->getPrescale(
true ) );
838 lowers.push_back(
"-");
840 express.push_back(-1);
845 lowers.push_back(
"-");
847 express.push_back(-1);
855 std::vector<int32_t> bunchGroups;
856 bunchGroups.reserve(16);
865 bunchGroups.push_back(
bg.bunches().size());
872 if (bunchGroups.size() == 0 || std::all_of(bunchGroups.begin(), bunchGroups.end(), [](
int i) { return i==0; })) {
885 std::string atlasProject =
std::getenv(
"AtlasProject");
886 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.
StatusCode addExisting(const std::string pattern)
Register some existing triggers based on wild-card match, e.g.
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.
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.