diff --git a/Trigger/TrigMonitoring/TrigSteerMonitor/src/TrigSignatureMoniMT.cxx b/Trigger/TrigMonitoring/TrigSteerMonitor/src/TrigSignatureMoniMT.cxx index 9a03132e4625efd1b8ec32a37aa8920a1e5d1445..dca1c14278a365870de67d12fc04f912c15bfcfc 100644 --- a/Trigger/TrigMonitoring/TrigSteerMonitor/src/TrigSignatureMoniMT.cxx +++ b/Trigger/TrigMonitoring/TrigSteerMonitor/src/TrigSignatureMoniMT.cxx @@ -12,73 +12,72 @@ #include "TrigCompositeUtils/HLTIdentifier.h" #include "TrigSignatureMoniMT.h" -TrigSignatureMoniMT::TrigSignatureMoniMT( const std::string& name, - ISvcLocator* pSvcLocator ) : - base_class( name, pSvcLocator ) +TrigSignatureMoniMT::TrigSignatureMoniMT(const std::string& name, ISvcLocator* pSvcLocator) + : base_class(name, pSvcLocator) {} StatusCode TrigSignatureMoniMT::initialize() { - ATH_CHECK( m_l1DecisionsKey.initialize() ); - ATH_CHECK( m_finalDecisionKey.initialize() ); - ATH_CHECK( m_HLTMenuKey.initialize() ); - ATH_CHECK( m_L1MenuKey.initialize() ); - ATH_CHECK( m_decisionCollectorTools.retrieve() ); - ATH_CHECK( m_featureCollectorTools.retrieve() ); - ATH_CHECK( m_histSvc.retrieve() ); - - ATH_CHECK( m_incidentSvc.retrieve() ); + ATH_CHECK(m_l1DecisionsKey.initialize()); + ATH_CHECK(m_finalDecisionKey.initialize()); + ATH_CHECK(m_HLTMenuKey.initialize()); + ATH_CHECK(m_L1MenuKey.initialize()); + ATH_CHECK(m_decisionCollectorTools.retrieve()); + ATH_CHECK(m_featureCollectorTools.retrieve()); + ATH_CHECK(m_histSvc.retrieve()); + + ATH_CHECK(m_incidentSvc.retrieve()); m_incidentSvc->addListener(this, AthenaInterprocess::UpdateAfterFork::type()); return StatusCode::SUCCESS; } StatusCode TrigSignatureMoniMT::start() { - SG::ReadHandle<TrigConf::HLTMenu> hltMenuHandle = SG::makeHandle( m_HLTMenuKey ); - ATH_CHECK( hltMenuHandle.isValid() ); + SG::ReadHandle<TrigConf::L1Menu> l1MenuHandle = SG::makeHandle(m_L1MenuKey); + SG::ReadHandle<TrigConf::HLTMenu> hltMenuHandle = SG::makeHandle(m_HLTMenuKey); + ATH_CHECK(hltMenuHandle.isValid()); - SG::ReadHandle<TrigConf::L1Menu> l1MenuHandle = SG::makeHandle( m_L1MenuKey ); - bool gotL1Menu = l1MenuHandle.isValid(); - - // reset the state + // Retrieve chain information from menus + std::vector<std::string> bcidChainNames; m_groupToChainMap.clear(); m_streamToChainMap.clear(); m_chainIDToBunchMap.clear(); - - //retrieve chain information from menus - std::vector<std::string> bcidChainNames; - for ( const TrigConf::Chain& chain: *hltMenuHandle ){ - for ( const std::string& group : chain.groups() ){ - if ( group.find("RATE") == 0 ){ - m_groupToChainMap[group].insert( HLT::Identifier(chain.name()) ); + for (const TrigConf::Chain& chain : *hltMenuHandle) { + for (const std::string& group : chain.groups()) { + // Save chains per RATE group + if (group.find("RATE") == 0){ + m_groupToChainMap[group].insert(HLT::Identifier(chain.name())); } + // Save chains BCID monitored else if (group == "MON:BCID"){ bcidChainNames.push_back(chain.name()); } } - for ( const std::string& stream : chain.streams() ){ - m_streamToChainMap[stream].insert( HLT::Identifier(chain.name()) ); + // Save chain to stream map + for (const std::string& stream : chain.streams()){ + m_streamToChainMap[stream].insert(HLT::Identifier(chain.name())); } - if( gotL1Menu && !chain.l1item().empty() ) { + // Save chain id to bunchgroup name map + if (l1MenuHandle.isValid() && !chain.l1item().empty()) { bool isMultiItemSeeded = chain.l1item().find(',') != std::string::npos; try { - std::vector<std::string> seedingItems{}; + std::vector<std::string> seedingItems {}; if( isMultiItemSeeded ) { boost::split(seedingItems, chain.l1item(), boost::is_any_of(",")); } else { - seedingItems = { chain.l1item() }; + seedingItems = {chain.l1item()}; } - for( const std::string & itemName : seedingItems ) { + for (const std::string & itemName : seedingItems) { TrigConf::L1Item item = l1MenuHandle->item(itemName); - for ( const std::string & group : item.bunchgroups() ) { - if ( group != "BGRP0" ) { + for (const std::string & group : item.bunchgroups()) { + if (group != "BGRP0") { m_chainIDToBunchMap[HLT::Identifier(chain.name())].insert(group); } } } } catch(std::exception & ex) { - if( isMultiItemSeeded ) { + if(isMultiItemSeeded) { ATH_MSG_INFO("The L1 seed to multi-item-seeded chain " << chain.name() << " could not be completely resolved. This is currently OK. Exception from menu access: " << ex.what()); } else { ATH_MSG_WARNING("The L1 seed to chain " << chain.name() << " could not be resolved. Exception from menu access: " << ex.what()); @@ -87,59 +86,66 @@ StatusCode TrigSignatureMoniMT::start() { } } - auto l1Decisions = SG::makeHandle( m_l1DecisionsKey ); - std::set<std::string> sequencesSet; - for ( auto& ctool: m_decisionCollectorTools ){ - ctool->getSequencesNames(sequencesSet); - } - - const int x = nBinsX(hltMenuHandle); - const int xb = nBunchBinsX(hltMenuHandle); - const int xbc = nBCIDbinsX(); - const int xc = sequencesSet.size(); - const int y = nBinsY(); - const int yr = nRateBinsY(); - const int yb = gotL1Menu ? nBunchBinsY(l1MenuHandle) : 16; - const int ybc = bcidChainNames.size(); - const int yc = 1; //Rate + // Prepare the histograms + // Initialize SignatureAcceptance and DecisionCount histograms that will monitor + // chains, groups and sequences per each step + const int x {nBinsX(hltMenuHandle)}; + const int y {nSteps()}; ATH_MSG_DEBUG( "Histogram " << x << " x " << y << " bins"); - - std::unique_ptr<TH2> hSA = std::make_unique<TH2I>("SignatureAcceptance", "Raw acceptance of signatures in;chain;step", x, 1, x + 1, y, 1, y + 1); + std::unique_ptr<TH2> hSA = std::make_unique<TH2I>("SignatureAcceptance", "Raw acceptance of signatures in;chain;step", x, 1, x + 1, y, 1, y + 1); std::unique_ptr<TH2> hDC = std::make_unique<TH2I>("DecisionCount", "Positive decisions count per step;chain;step", x, 1, x + 1, y, 1, y + 1); - std::unique_ptr<TH2> hBG = std::make_unique<TH2I>("BunchGroupCount", "Bunch group count per chain;chain;bunchgroup", xb, 1, xb + 1, yb, 1, yb + 1); - ATH_CHECK( m_histSvc->regShared( m_bookingPath + "/" + name() + "/SignatureAcceptance", std::move(hSA), m_passHistogram)); - ATH_CHECK( m_histSvc->regShared( m_bookingPath + "/" + name() + "/DecisionCount", std::move(hDC), m_countHistogram)); - ATH_CHECK( m_histSvc->regShared( m_bookingPath + "/" + name() + "/BunchGroupCount", std::move(hBG), m_bunchHistogram)); + ATH_CHECK(m_histSvc->regShared(m_bookingPath + "/" + name() + "/SignatureAcceptance", std::move(hSA), m_passHistogram)); + ATH_CHECK(m_histSvc->regShared(m_bookingPath + "/" + name() + "/DecisionCount", std::move(hDC), m_countHistogram)); - ATH_CHECK( initHist( m_passHistogram, hltMenuHandle ) ); - ATH_CHECK( initHist( m_countHistogram, hltMenuHandle ) ); - ATH_CHECK( initBunchHist( m_bunchHistogram, hltMenuHandle, l1MenuHandle ) ); + ATH_CHECK(initHist(m_passHistogram, hltMenuHandle)); + ATH_CHECK(initHist(m_countHistogram, hltMenuHandle)); - std::string outputRateName ("Rate" + std::to_string(m_duration) + "s"); - std::string outputBCIDName ("DecisionsPerBCID" + std::to_string(m_duration) + "s"); - std::string outputSequenceName ("SequencesExecutionRate" + std::to_string(m_duration) + "s"); + // Initialize BunchGroupCount that will count bunchgroup per chain + const int xb {nChains(hltMenuHandle)}; + const int yb {nBunchGroups(l1MenuHandle)}; + std::unique_ptr<TH2> hBG = std::make_unique<TH2I>("BunchGroupCount", "Bunch group count per chain;chain;bunchgroup", xb, 1, xb + 1, yb, 1, yb + 1); + ATH_CHECK(m_histSvc->regShared( m_bookingPath + "/" + name() + "/BunchGroupCount", std::move(hBG), m_bunchHistogram)); + ATH_CHECK(initBunchHist(m_bunchHistogram, hltMenuHandle, l1MenuHandle)); + // Initialize Rate histogram to save the rates of positive decisions in given interval + // per chain/group/sequence per in, after ps, out steps + const int yr {nBaseSteps()}; if ( x > 0 ){ + std::string outputRateName ("Rate" + std::to_string(m_duration) + "s"); m_rateHistogram.init(outputRateName, "Rate of positive decisions;chain;step", x, yr, m_bookingPath + "/" + name() + '/' + outputRateName.c_str(), m_histSvc).ignore(); - ATH_CHECK( initHist( m_rateHistogram.getHistogram(), hltMenuHandle, false ) ); - ATH_CHECK( initHist( m_rateHistogram.getBuffer(), hltMenuHandle, false ) ); + ATH_CHECK(initHist(m_rateHistogram.getHistogram(), hltMenuHandle, false)); + ATH_CHECK(initHist(m_rateHistogram.getBuffer(), hltMenuHandle, false)); } + // Initialize SequencesExecutionRate histogram to save the rates of sequences execution + // Save sequences names to be monitored + std::set<std::string> sequencesSet; + for (auto& ctool: m_decisionCollectorTools){ + ctool->getSequencesNames(sequencesSet); + } + const int xc = sequencesSet.size(); + const int yc {1}; // Only rate, this histogram is really 1 D if (xc > 0){ + std::string outputSequenceName ("SequencesExecutionRate" + std::to_string(m_duration) + "s"); m_sequenceHistogram.init(outputSequenceName, "Rate of sequences execution;sequence;rate", xc, yc, m_bookingPath + "/" + name() + '/' + outputSequenceName.c_str(), m_histSvc).ignore(); - ATH_CHECK( initSeqHist( m_sequenceHistogram.getHistogram(), sequencesSet ) ); - ATH_CHECK( initSeqHist( m_sequenceHistogram.getBuffer(), sequencesSet ) ); + ATH_CHECK(initSeqHist(m_sequenceHistogram.getHistogram(), sequencesSet)); + ATH_CHECK(initSeqHist(m_sequenceHistogram.getBuffer(), sequencesSet)); } - if ( ybc > 0 ){ + // Initialize DecisionsPerBCID histogram to save the rates of positive decisions + // per BCID per chains that are bcid monitored (in MON:BCID group) + const int xbc {nBCIDs()}; + const int ybc = bcidChainNames.size(); + if (ybc > 0){ + std::string outputBCIDName ("DecisionsPerBCID" + std::to_string(m_duration) + "s"); m_bcidHistogram.init(outputBCIDName, "Number of positive decisions per BCID per chain;BCID;chain", xbc, ybc, m_bookingPath + "/" + name() + '/' + outputBCIDName.c_str(), m_histSvc).ignore(); - ATH_CHECK( initBCIDhist( m_bcidHistogram.getHistogram(), bcidChainNames ) ); - ATH_CHECK( initBCIDhist( m_bcidHistogram.getBuffer(), bcidChainNames ) ); + ATH_CHECK(initBCIDhist(m_bcidHistogram.getHistogram(), bcidChainNames)); + ATH_CHECK(initBCIDhist(m_bcidHistogram.getBuffer(), bcidChainNames)); } else { ATH_MSG_DEBUG("No chains configured for BCID monitoring."); @@ -164,26 +170,23 @@ StatusCode TrigSignatureMoniMT::stop() { return ss.str(); }; - SG::ReadHandle<TrigConf::HLTMenu> hltMenuHandle = SG::makeHandle( m_HLTMenuKey ); - ATH_CHECK( hltMenuHandle.isValid() ); + SG::ReadHandle<TrigConf::HLTMenu> hltMenuHandle = SG::makeHandle(m_HLTMenuKey); + ATH_CHECK(hltMenuHandle.isValid()); - // retrieve information whether chain was active in Step - std::map<std::string, std::set<std::string>> chainToSteps; + // Retrieve information whether chain was active in Step std::map<std::string, std::set<int>> chainToStepsId; - for ( const TrigConf::Chain& chain: *hltMenuHandle ){ - int nstep=1; //let's start from step=1 - for ( const auto& seq : chain.getList("sequencers", true) ){ - // example sequencer name is "Step1_FastCalo_electron", we need only information about Step + number - const std::string seqName = seq.getValue(); + for (const TrigConf::Chain& chain : *hltMenuHandle){ + int nstep {1}; // Start from step=1 + for (const std::string& seqName : chain.sequencers()){ + // Example sequencer name is "Step1_FastCalo_electron", we need only information about Step + number std::smatch stepNameMatch; std::regex_search(seqName.begin(), seqName.end(), stepNameMatch, std::regex("[Ss]tep[0-9]+")); std::string stepName = stepNameMatch[0]; - stepName[0] = std::toupper(stepName[0]); // fix for "step1" names - //check that the step name is set with the same position in the execution (empty steps support) - if ("Step"+std::to_string(nstep) == stepName) { - chainToSteps[chain.name()].insert( stepName ); - chainToStepsId[chain.name()].insert( nstep ); + stepName[0] = std::toupper(stepName[0]); // Fix "stepX" -> "StepX" + // Check that the step name is set with the same position in the execution (empty steps support) + if ("Step" + std::to_string(nstep) == stepName) { + chainToStepsId[chain.name()].insert(nstep); } else { ATH_MSG_INFO("Missing step" << nstep << " in chain " << chain.name()); } @@ -191,52 +194,52 @@ StatusCode TrigSignatureMoniMT::stop() { } } - auto collToString = [&]( int xbin, const LockedHandle<TH2>& hist, int startOfset=0, int endOffset=0){ + auto collToString = [&](int xbin, const LockedHandle<TH2>& hist, int startOfset=0, int endOffset=0){ std::string v; - const int stepsSize = hist->GetYaxis()->GetNbins()-3; //L1, AfterPS, Output - for ( int ybin = 1; ybin <= hist->GetYaxis()->GetNbins()-endOffset; ++ybin ) { - if ( ybin > startOfset ) { - // skip steps where chain wasn't active + const int stepsSize = hist->GetYaxis()->GetNbins() - 3; // L1, AfterPS, Output + for (int ybin = 1; ybin <= hist->GetYaxis()->GetNbins()-endOffset; ++ybin) { + if (ybin > startOfset) { + // Skip steps where chain wasn't active // ybins are for all axis labes, steps are in bins from 3 to stepsSize + 2 const std::string chainName = m_passHistogram->GetXaxis()->GetBinLabel(xbin); - if( ybin < 3 || ybin > stepsSize + 2 || chainToStepsId[chainName].count(ybin - 2) != 0 ) { - v += fixedWidth( std::to_string( int(hist->GetBinContent( xbin, ybin ))) , 11 ); + if (ybin < 3 || ybin > stepsSize + 2 || chainToStepsId[chainName].count(ybin - 2) != 0) { + v += fixedWidth(std::to_string( int(hist->GetBinContent( xbin, ybin ))) , 11); } else { - v += fixedWidth( "-", 11 ); + v += fixedWidth("-", 11); } } else { - v += fixedWidth( " ", 11 ); + v += fixedWidth(" ", 11); } } return v; }; std::string v; - v += fixedWidth( "L1", 11 ); - v += fixedWidth( "AfterPS", 11 ); - for ( int bin = 1; bin <= m_passHistogram->GetYaxis()->GetNbins()-3; ++bin ) { - v += fixedWidth( "Step" + std::to_string(bin), 11 ); + v += fixedWidth("L1", 11); + v += fixedWidth("AfterPS", 11); + for (int bin = 1; bin <= m_passHistogram->GetYaxis()->GetNbins()-3; ++bin) { + v += fixedWidth("Step" + std::to_string(bin), 11); } - v += fixedWidth( "Output", 11 ); + v += fixedWidth("Output", 11); - ATH_MSG_INFO( "Chains passing step (1st row events & 2nd row decision counts):" ); - ATH_MSG_INFO( fixedWidth("ChainName", 30) << v ); + ATH_MSG_INFO("Chains passing step (1st row events & 2nd row decision counts):"); + ATH_MSG_INFO(fixedWidth("ChainName", 30) << v); /* comment for future dev: for combined chains we find x2 the number of decisions, because we count both the HypoAlg and the combo Alg decisions */ - for ( int bin = 1; bin <= (*m_passHistogram)->GetXaxis()->GetNbins(); ++bin ) { + for (int bin = 1; bin <= (*m_passHistogram)->GetXaxis()->GetNbins(); ++bin) { const std::string chainName = m_passHistogram->GetXaxis()->GetBinLabel(bin); const std::string chainID = std::to_string( HLT::Identifier(chainName) ); - if ( chainName.find("HLT") == 0 ) { // print only for chains + if (chainName.find("HLT") == 0) { // print only for chains ATH_MSG_INFO( chainName + " #" + chainID); ATH_MSG_INFO( fixedWidth("-- #" + chainID + " Events", 30) << collToString( bin, m_passHistogram) ); ATH_MSG_INFO( fixedWidth("-- #" + chainID + " Features", 30) << collToString( bin, m_countHistogram , 2, 1 ) ); } - if ( chainName.find("All") == 0 ){ + if (chainName.find("All") == 0){ ATH_MSG_INFO( fixedWidth(chainName, 30) << collToString( bin, m_passHistogram) ); } } @@ -245,7 +248,7 @@ StatusCode TrigSignatureMoniMT::stop() { } StatusCode TrigSignatureMoniMT::fillHistogram(const TrigCompositeUtils::DecisionIDContainer& dc, int row, LockedHandle<TH2>& histogram) const { - for ( auto id : dc ) { + for (TrigCompositeUtils::DecisionID id : dc) { auto id2bin = m_chainIDToBinMap.find( id ); if ( id2bin == m_chainIDToBinMap.end() && HLT::Identifier(id).name().find("leg") != 0 ) { ATH_MSG_WARNING( "HLT chain " << HLT::Identifier(id) << " not configured to be monitored" ); @@ -265,15 +268,14 @@ StatusCode TrigSignatureMoniMT::fillPassEvents(const TrigCompositeUtils::Decisio } StatusCode TrigSignatureMoniMT::fillDecisionCount(const std::vector<TrigCompositeUtils::DecisionID>& dc, int row) const { - - for ( auto id : dc ) { - auto chain=id; + for (TrigCompositeUtils::DecisionID id : dc) { + TrigCompositeUtils::DecisionID chain = id; if (TrigCompositeUtils::isLegId(HLT::Identifier(id)) ) chain = TrigCompositeUtils::getIDFromLeg(id); auto id2bin = m_chainIDToBinMap.find( chain ); if ( id2bin == m_chainIDToBinMap.end()) { - ATH_MSG_WARNING( "HLT chain " << HLT::Identifier(chain) << " not configured to be monitored" ); + ATH_MSG_WARNING("HLT chain " << HLT::Identifier(chain) << " not configured to be monitored"); } else { - m_countHistogram->Fill( id2bin->second, double(row) ); + m_countHistogram->Fill(id2bin->second, double(row)); } } @@ -282,12 +284,12 @@ StatusCode TrigSignatureMoniMT::fillDecisionCount(const std::vector<TrigComposit } StatusCode TrigSignatureMoniMT::fillBunchGroups(const TrigCompositeUtils::DecisionIDContainer& dc ) const { - for ( auto id : dc ) { - auto id2bin = m_chainIDToBinMap.find( id ); - auto bunchGroups = m_chainIDToBunchMap.find( id ); - if ( id2bin != m_chainIDToBinMap.end() && bunchGroups != m_chainIDToBunchMap.end() ) { - for (auto group : bunchGroups->second){ - m_bunchHistogram->Fill( id2bin->second, double(m_nameToBinMap.at(group)) ); + for (TrigCompositeUtils::DecisionID id : dc) { + auto id2bin = m_chainIDToBinMap.find(id); + auto bunchGroups = m_chainIDToBunchMap.find(id); + if (id2bin != m_chainIDToBinMap.end() && bunchGroups != m_chainIDToBunchMap.end()) { + for (const std::string& group : bunchGroups->second){ + m_bunchHistogram->Fill( id2bin->second, double(m_nameToBinMap.at(group))); m_bunchHistogram->Fill( 1, double(m_nameToBinMap.at(group)) ); } } @@ -296,10 +298,10 @@ StatusCode TrigSignatureMoniMT::fillBunchGroups(const TrigCompositeUtils::Decisi } StatusCode TrigSignatureMoniMT::fillBCID(const TrigCompositeUtils::DecisionIDContainer& dc , int bcid) const { - if ( nBCIDbinsY() > 0 ){ - for ( auto id : dc ) { - auto id2bin = m_BCIDchainIDToBinMap.find( id ); - if ( id2bin != m_BCIDchainIDToBinMap.end() ) { + if (nBCIDchains() > 0){ + for (TrigCompositeUtils::DecisionID id : dc) { + auto id2bin = m_BCIDchainIDToBinMap.find(id); + if (id2bin != m_BCIDchainIDToBinMap.end()) { m_bcidHistogram.fill( bcid, id2bin->second ); } } @@ -308,23 +310,24 @@ StatusCode TrigSignatureMoniMT::fillBCID(const TrigCompositeUtils::DecisionIDCon } StatusCode TrigSignatureMoniMT::fillSequences(const std::set<std::string>& sequences) const { - for ( auto seq : sequences ) { + for (const std::string& seq : sequences) { m_sequenceHistogram.fill(m_sequenceToBinMap.at(seq), 1); } return StatusCode::SUCCESS; } -StatusCode TrigSignatureMoniMT::fillStreamsAndGroups(const std::map<std::string, TrigCompositeUtils::DecisionIDContainer>& map, const TrigCompositeUtils::DecisionIDContainer& dc) const { - const double row = nBinsY(); - const double rateRow = nRateBinsY(); - for ( auto m : map ) { - for ( auto id : dc ) { - if ( m.second.find(id) != m.second.end() ){ - double bin = m_nameToBinMap.at(m.first); - m_countHistogram->Fill( bin, row ); - m_rateHistogram.fill( bin, rateRow ); - m_passHistogram->Fill( bin, row ); +StatusCode TrigSignatureMoniMT::fillStreamsAndGroups(const std::map<std::string, TrigCompositeUtils::DecisionIDContainer>& nameToChainsMap, const TrigCompositeUtils::DecisionIDContainer& dc) const { + // Fill just the last row of the histograms + const double row = nSteps(); + const double rateRow = nBaseSteps(); + for (const auto& name : nameToChainsMap) { + for (TrigCompositeUtils::DecisionID id : dc) { + if (name.second.find(id) != name.second.end()){ + double bin = m_nameToBinMap.at(name.first); + m_countHistogram->Fill(bin, row); + m_rateHistogram.fill(bin, rateRow); + m_passHistogram->Fill(bin, row); break; } } @@ -340,16 +343,16 @@ void TrigSignatureMoniMT::handle( const Incident& incident ) { return; } - //prevent from publishing empty histograms - if ( nBinsX() > 0 ) { + // Prevent from publishing empty histograms + if (nBinsX() > 0) { m_rateHistogram.startTimer(m_duration, m_intervals); } - if ( nSequenceBinsX() > 0 ) { + if (nSequenceBins() > 0) { m_sequenceHistogram.startTimer(m_duration, m_intervals); } - if ( nBCIDbinsY() > 0 ){ + if (nBCIDchains() > 0){ m_bcidHistogram.startTimer(m_duration, m_intervals); } @@ -359,7 +362,7 @@ void TrigSignatureMoniMT::handle( const Incident& incident ) { StatusCode TrigSignatureMoniMT::execute( const EventContext& context ) const { - auto l1Decisions = SG::makeHandle( m_l1DecisionsKey, context ); + SG::ReadHandle<TrigCompositeUtils::DecisionContainer> l1Decisions = SG::makeHandle(m_l1DecisionsKey, context); const TrigCompositeUtils::Decision* l1SeededChains = nullptr; // Activated by L1 const TrigCompositeUtils::Decision* unprescaledChains = nullptr; // Activated and passed prescale check @@ -376,22 +379,24 @@ StatusCode TrigSignatureMoniMT::execute( const EventContext& context ) const { return StatusCode::FAILURE; } - auto fillL1 = [&]( int index ) -> StatusCode { + auto fillL1 = [&](int index) -> StatusCode { TrigCompositeUtils::DecisionIDContainer ids; - TrigCompositeUtils::decisionIDs( l1Decisions->at( index ), ids ); + TrigCompositeUtils::decisionIDs(l1Decisions->at(index), ids); ATH_MSG_DEBUG( "L1 " << index << " N positive decisions " << ids.size() ); - ATH_CHECK( fillPassEvents( ids, index + 1 )); - ATH_CHECK( fillRate( ids, index + 1) ); - if ( not ids.empty() ){ - m_passHistogram->Fill( 1, double(index + 1) ); - m_rateHistogram.fill( 1, double(index + 1) ); + ATH_CHECK(fillPassEvents(ids, index + 1)); + ATH_CHECK(fillRate(ids, index + 1)); + if (!ids.empty()){ + m_passHistogram->Fill(1, double(index + 1)); + m_rateHistogram.fill(1, double(index + 1)); } return StatusCode::SUCCESS; }; - ATH_CHECK( fillL1(0) ); - ATH_CHECK( fillL1(1) ); + // Fill histograms with L1 decisions in and after prescale + ATH_CHECK(fillL1(0)); + ATH_CHECK(fillL1(1)); + // Fill HLT steps int step = 0; for ( auto& ctool: m_decisionCollectorTools ) { std::vector<TrigCompositeUtils::DecisionID> stepSum; @@ -416,9 +421,10 @@ StatusCode TrigSignatureMoniMT::execute( const EventContext& context ) const { ++step; } - const int row = nBinsY(); - const int rateRow = nRateBinsY(); - auto finalDecisionsHandle = SG::makeHandle( m_finalDecisionKey, context ); + // Fill the final decisions + const int row {nSteps()}; + const int rateRow {nBaseSteps()}; + SG::ReadHandle<TrigCompositeUtils::DecisionContainer> finalDecisionsHandle = SG::makeHandle( m_finalDecisionKey, context ); ATH_CHECK( finalDecisionsHandle.isValid() ); TrigCompositeUtils::DecisionIDContainer finalIDs; const TrigCompositeUtils::Decision* decisionObject = TrigCompositeUtils::getTerminusNode(finalDecisionsHandle); @@ -428,55 +434,55 @@ StatusCode TrigSignatureMoniMT::execute( const EventContext& context ) const { TrigCompositeUtils::decisionIDs(decisionObject, finalIDs); } - ATH_CHECK( fillStreamsAndGroups( m_streamToChainMap, finalIDs ) ); - ATH_CHECK( fillStreamsAndGroups( m_groupToChainMap, finalIDs ) ); - ATH_CHECK( fillPassEvents( finalIDs, row ) ); - ATH_CHECK( fillRate( finalIDs, rateRow ) ); - ATH_CHECK( fillBunchGroups( finalIDs ) ); - ATH_CHECK( fillBCID( finalIDs , context.eventID().bunch_crossing_id()) ); + ATH_CHECK( fillStreamsAndGroups(m_streamToChainMap, finalIDs)); + ATH_CHECK( fillStreamsAndGroups(m_groupToChainMap, finalIDs)); + ATH_CHECK( fillPassEvents(finalIDs, row)); + ATH_CHECK( fillRate(finalIDs, rateRow)); + ATH_CHECK( fillBunchGroups( finalIDs)); + ATH_CHECK( fillBCID(finalIDs , context.eventID().bunch_crossing_id())); - if ( not finalIDs.empty() ) { - m_passHistogram->Fill( 1, double( row ) ); - m_rateHistogram.fill( 1, double( rateRow ) ); + if (!finalIDs.empty()) { + m_passHistogram->Fill(1, double(row)); + m_rateHistogram.fill(1, double(rateRow)); } return StatusCode::SUCCESS; } int TrigSignatureMoniMT::nBinsX(SG::ReadHandle<TrigConf::HLTMenu>& hltMenuHandle) const { - return hltMenuHandle->size() + m_groupToChainMap.size() + m_streamToChainMap.size() + 1; + return nChains(hltMenuHandle) + m_groupToChainMap.size() + m_streamToChainMap.size(); } int TrigSignatureMoniMT::nBinsX() const { return m_chainIDToBinMap.size() + m_groupToChainMap.size() + m_streamToChainMap.size() + 1; } -int TrigSignatureMoniMT::nBunchBinsX(SG::ReadHandle<TrigConf::HLTMenu>& hltMenuHandle) const { - return hltMenuHandle->size() + 1; //only chains +int TrigSignatureMoniMT::nChains(SG::ReadHandle<TrigConf::HLTMenu>& hltMenuHandle) const { + return hltMenuHandle->size() + 1; // Chains + "All" } -int TrigSignatureMoniMT::nBCIDbinsX() const { - return m_bcidNumber + 1; //only chains +int TrigSignatureMoniMT::nBCIDs() const { + return m_bcidNumber + 1; } -int TrigSignatureMoniMT::nSequenceBinsX() const { +int TrigSignatureMoniMT::nSequenceBins() const { return m_sequenceToBinMap.size(); } -int TrigSignatureMoniMT::nBinsY() const { - return m_decisionCollectorTools.size() + 3; // in, after ps, out +int TrigSignatureMoniMT::nSteps() const { + return m_decisionCollectorTools.size() + nBaseSteps(); } -int TrigSignatureMoniMT::nRateBinsY() const { +int TrigSignatureMoniMT::nBaseSteps() const { return 3; // in, after ps, out } -int TrigSignatureMoniMT::nBCIDbinsY() const { +int TrigSignatureMoniMT::nBCIDchains() const { return m_BCIDchainIDToBinMap.size(); } -int TrigSignatureMoniMT::nBunchBinsY(SG::ReadHandle<TrigConf::L1Menu>& l1MenuHandle) const { - return l1MenuHandle->getObject("bunchGroups").getKeys().size() - 1; +int TrigSignatureMoniMT::nBunchGroups(SG::ReadHandle<TrigConf::L1Menu>& l1MenuHandle) const { + return l1MenuHandle.isValid() ? (l1MenuHandle->getObject("bunchGroups").getKeys().size() - 1) : 16; } StatusCode TrigSignatureMoniMT::initHist(LockedHandle<TH2>& hist, SG::ReadHandle<TrigConf::HLTMenu>& hltMenuHandle, bool steps) { @@ -511,12 +517,12 @@ StatusCode TrigSignatureMoniMT::initHist(LockedHandle<TH2>& hist, SG::ReadHandle TAxis* y = hist->GetYaxis(); - y->SetBinLabel( 1, steps ? "L1" : "Input" ); - y->SetBinLabel( 2, "AfterPS" ); - for ( size_t i = 0; steps && i < m_decisionCollectorTools.size(); ++i ) { - y->SetBinLabel( 3+i, ("Step "+std::to_string(i)).c_str() ); + y->SetBinLabel(1, steps ? "L1" : "Input"); + y->SetBinLabel(2, "AfterPS"); + for ( size_t i = 0; steps && i < m_decisionCollectorTools.size(); ++i) { + y->SetBinLabel(3 + i, ("Step "+std::to_string(i)).c_str()); } - y->SetBinLabel( y->GetNbins(), "Output" ); // last bin + y->SetBinLabel(y->GetNbins(), "Output"); // Last bin return StatusCode::SUCCESS; } @@ -525,14 +531,15 @@ StatusCode TrigSignatureMoniMT::initSeqHist(LockedHandle<TH2>& hist, std::set<st TAxis* x = hist->GetXaxis(); int bin = 1; - for ( auto seqName : sequenceSet ) { - x->SetBinLabel( bin, seqName.c_str() ); - m_sequenceToBinMap[ seqName ] = bin; - bin++; + // Set bin labels + for (const std::string& seqName : sequenceSet) { + x->SetBinLabel(bin, seqName.c_str()); + m_sequenceToBinMap[seqName] = bin; + ++bin; } TAxis* y = hist->GetYaxis(); - y->SetBinLabel( 1, "Rate" ); + y->SetBinLabel(1, "Rate"); return StatusCode::SUCCESS; } @@ -544,7 +551,7 @@ StatusCode TrigSignatureMoniMT::initBCIDhist(LockedHandle<TH2>& hist, const std: TAxis* y = hist->GetYaxis(); int bin = 1; - for ( const std::string& chainName : sortedChainNames ){ + for (const std::string& chainName : sortedChainNames){ y->SetBinLabel( bin, chainName.c_str() ); m_BCIDchainIDToBinMap[HLT::Identifier(chainName).numeric()] = bin; ++bin; @@ -562,20 +569,20 @@ StatusCode TrigSignatureMoniMT::initBunchHist(LockedHandle<TH2>& hist, SG::ReadH int bin = 2; std::vector<std::string> sortedChainsList; - for ( const TrigConf::Chain& chain: *hltMenuHandle ) { + for (const TrigConf::Chain& chain : *hltMenuHandle) { sortedChainsList.push_back( chain.name() ); } std::sort( sortedChainsList.begin(), sortedChainsList.end() ); - for ( const std::string& chainName: sortedChainsList ) { + for (const std::string& chainName : sortedChainsList) { x->SetBinLabel( bin, chainName.c_str() ); ++bin; } std::vector<std::string> sortedBunchGroups; - if( gotL1Menu ) { + if (gotL1Menu) { sortedBunchGroups = l1MenuHandle->getObject("bunchGroups").getKeys(); - std::sort( sortedBunchGroups.begin(), sortedBunchGroups.end() ); + std::sort(sortedBunchGroups.begin(), sortedBunchGroups.end()); sortedBunchGroups.erase(std::remove(sortedBunchGroups.begin(), sortedBunchGroups.end(), "BGRP0"), sortedBunchGroups.end()); } else { for(size_t i = 1; i<=16; ++i) { @@ -585,7 +592,7 @@ StatusCode TrigSignatureMoniMT::initBunchHist(LockedHandle<TH2>& hist, SG::ReadH bin = 1; TAxis* y = hist->GetYaxis(); - for ( const std::string& group : sortedBunchGroups ){ + for (const std::string& group : sortedBunchGroups){ std::string bgname = gotL1Menu ? l1MenuHandle->getAttribute( "bunchGroups." + group + ".name", true) : group; y->SetBinLabel( bin, bgname.c_str() ); m_nameToBinMap[group] = bin; @@ -599,8 +606,8 @@ TrigSignatureMoniMT::RateHistogram::~RateHistogram(){ delete m_bufferHistogram.get(); } -StatusCode TrigSignatureMoniMT::RateHistogram::init( const std::string histoName, const std::string histoTitle, - const int x, const int y, const std::string registerPath, ServiceHandle<ITHistSvc> histSvc ){ +StatusCode TrigSignatureMoniMT::RateHistogram::init( const std::string& histoName, const std::string& histoTitle, + const int x, const int y, const std::string& registerPath, ServiceHandle<ITHistSvc> histSvc ){ std::unique_ptr<TH2> h = std::make_unique<TH2F>(histoName.c_str(), histoTitle.c_str(), x, 1, x + 1, y, 1, y + 1); ATH_CHECK( histSvc->regShared( registerPath.c_str(), std::move(h), m_histogram)); @@ -624,7 +631,7 @@ std::unique_ptr<Athena::AlgorithmTimer> & TrigSignatureMoniMT::RateHistogram::ge } void TrigSignatureMoniMT::RateHistogram::fill(const double x, const double y) const { - m_bufferHistogram->Fill( x, y ); + m_bufferHistogram->Fill(x, y); } void TrigSignatureMoniMT::RateHistogram::startTimer(unsigned int duration, unsigned int intervals) { @@ -639,7 +646,7 @@ void TrigSignatureMoniMT::RateHistogram::stopTimer() { time_t t = time(0); unsigned int interval; unsigned int duration = m_timeDivider->forcePassed(t, interval); - updatePublished(duration); //divide by time that really passed not by interval duration + updatePublished(duration); // Divide by time that really passed not by interval duration } } @@ -652,15 +659,15 @@ void TrigSignatureMoniMT::RateHistogram::updatePublished(unsigned int duration) void TrigSignatureMoniMT::RateHistogram::callback() const { - //ask time divider if we need to switch to new interval + // Ask time divider if we need to switch to new interval time_t t = time(0); unsigned int newinterval; unsigned int oldinterval; - if ( m_timeDivider->isPassed(t, newinterval, oldinterval) ) { + if (m_timeDivider->isPassed(t, newinterval, oldinterval)) { updatePublished(m_duration); } - //schedule itself in another 1/20 of the integration period in milliseconds - if ( m_timer ) m_timer->start(m_duration*50); + // Schedule itself in another 1/20 of the integration period in milliseconds + if (m_timer) m_timer->start(m_duration*50); } diff --git a/Trigger/TrigMonitoring/TrigSteerMonitor/src/TrigSignatureMoniMT.h b/Trigger/TrigMonitoring/TrigSteerMonitor/src/TrigSignatureMoniMT.h index 43e5856ed328ae44f8fd3bb450e4a6dfc4c560d8..fa1ff9fad0adb5ea1bb70a1f2568b6036cdccd6f 100644 --- a/Trigger/TrigMonitoring/TrigSteerMonitor/src/TrigSignatureMoniMT.h +++ b/Trigger/TrigMonitoring/TrigSteerMonitor/src/TrigSignatureMoniMT.h @@ -45,24 +45,38 @@ class TrigSignatureMoniMT : public extends<AthReentrantAlgorithm, IIncidentListe virtual void handle( const Incident& incident ) override; private: - //class representing asynchronously published histograms + // Class representing asynchronously published histograms class RateHistogram { public: ~RateHistogram(); - StatusCode init( const std::string histoName, const std::string histoTitle, - const int x, const int y, const std::string registerPath, ServiceHandle<ITHistSvc> histSvc ); + // Initialize rate histogram and create buffer + StatusCode init( const std::string& histoName, const std::string& histoTitle, + const int x, const int y, const std::string& registerPath, ServiceHandle<ITHistSvc> histSvc ); - LockedHandle<TH2> & getHistogram() const; - LockedHandle<TH2> & getBuffer() const; - std::unique_ptr<Athena::AlgorithmTimer> & getTimer(); + // Get the histogram + LockedHandle<TH2>& getHistogram() const; + // Get the histogram buffer + LockedHandle<TH2>& getBuffer() const; + + // Get rate histogram timer pointer + std::unique_ptr<Athena::AlgorithmTimer>& getTimer(); + + // Start the histogram timer with given duration and intervals void startTimer(unsigned int duration, unsigned int intervals); + + // Stop the histogram timer void stopTimer(); - void fill(const double, const double) const; + + // Fill the histogram with given bins x, y + void fill(const double x, const double y) const; private: + // Update the histogram with values from the buffer void updatePublished(unsigned int duration) const; + + // Callback to check if interval's duration passed and histogram should be published void callback() const; mutable LockedHandle<TH2> m_bufferHistogram; @@ -77,20 +91,20 @@ class TrigSignatureMoniMT : public extends<AthReentrantAlgorithm, IIncidentListe SG::ReadHandleKey<TrigCompositeUtils::DecisionContainer> m_finalDecisionKey{ this, "FinalDecisionKey", "HLTNav_Summary", "Final stage of all decisions" }; SG::ReadHandleKey<TrigConf::HLTMenu> m_HLTMenuKey{ this, "HLTTriggerMenu", "DetectorStore+HLTTriggerMenu", "HLT Menu" }; SG::ReadHandleKey<TrigConf::L1Menu> m_L1MenuKey{ this, "L1TriggerMenu", "DetectorStore+L1TriggerMenu", "L1 Menu" }; - - std::map<unsigned int, int> m_chainIDToBinMap; - std::map<unsigned int, int> m_BCIDchainIDToBinMap; - std::map<std::string, int> m_nameToBinMap; - std::map<std::string, int> m_sequenceToBinMap; - std::map<unsigned int, std::set<std::string>> m_chainIDToBunchMap; - std::map<std::string, TrigCompositeUtils::DecisionIDContainer> m_groupToChainMap; - std::map<std::string, TrigCompositeUtils::DecisionIDContainer> m_streamToChainMap; ServiceHandle<IIncidentSvc> m_incidentSvc{ this, "IncidentSvc", "IncidentSvc", "Incident service"}; ServiceHandle<ITHistSvc> m_histSvc{ this, "THistSvc", "THistSvc/THistSvc", "Histogramming svc" }; Gaudi::Property<std::string> m_bookingPath{ this, "HistPath", "/EXPERT/HLTFramework", "Booking path for the histogram"}; Gaudi::Property<unsigned int> m_bcidNumber{ this, "BCIDNumber", 500, "Number of BCIDs in BCIDperChain histogram"}; + // Necessary for asynchronous calling callback function + Gaudi::Property<unsigned int> m_duration {this, "RateIntegrationDuration", 10, "Integration time for the rate histogram in seconds"}; + Gaudi::Property<unsigned int> m_intervals {this, "RateIntegrationIntervals", 6, "Number of the rate histogram publications"}; + + ToolHandleArray<DecisionCollectorTool> m_decisionCollectorTools{ this, "DecisionCollectorTools", {}, "Tools that collect decisions (yes/no) for steps" }; + ToolHandleArray<DecisionCollectorTool> m_featureCollectorTools{ this, "FeatureCollectorTools", {}, "Tools that collect decision counts for specific features for steps" }; + + // Histograms mutable LockedHandle<TH2> m_passHistogram; mutable LockedHandle<TH2> m_countHistogram; mutable LockedHandle<TH2> m_bunchHistogram; @@ -98,28 +112,49 @@ class TrigSignatureMoniMT : public extends<AthReentrantAlgorithm, IIncidentListe RateHistogram m_bcidHistogram; RateHistogram m_sequenceHistogram; - //necessary for asynchronous calling callback function - Gaudi::Property<unsigned int> m_duration {this, "RateIntegrationDuration", 10, "Integration time for the rate histogram in seconds"}; - Gaudi::Property<unsigned int> m_intervals {this, "RateIntegrationIntervals", 6, "Number of the rate histogram publications"}; + std::map<unsigned int, int> m_chainIDToBinMap; //!< Chain id to histogram bin map + std::map<unsigned int, int> m_BCIDchainIDToBinMap; //!< Chain id to bin map for DecisionsPerBCID histogram + std::map<std::string, int> m_nameToBinMap; //!< Sequence/group/bunchgroup name to bin map + std::map<std::string, int> m_sequenceToBinMap; //!< Sequence to bin map for sequence histogram + std::map<unsigned int, std::set<std::string>> m_chainIDToBunchMap; //!< Chain ID to bunchgroup name map + std::map<std::string, TrigCompositeUtils::DecisionIDContainer> m_groupToChainMap; //!< Group name to chain objects map + std::map<std::string, TrigCompositeUtils::DecisionIDContainer> m_streamToChainMap; //!< Stream name to chain objects map - ToolHandleArray<DecisionCollectorTool> m_decisionCollectorTools{ this, "DecisionCollectorTools", {}, "Tools that collect decisions (yes/no) for steps" }; - ToolHandleArray<DecisionCollectorTool> m_featureCollectorTools{ this, "FeatureCollectorTools", {}, "Tools that collect decision counts for specific features for steps" }; - + + // Returns number of chains + groups + sequencers based on the menu handle int nBinsX(SG::ReadHandle<TrigConf::HLTMenu>& ) const; + + // Returns number of chains + groups + sequencers based of size of m_chainIDToBinMap int nBinsX() const; - int nBunchBinsX(SG::ReadHandle<TrigConf::HLTMenu>& ) const; - int nBCIDbinsX() const; - int nSequenceBinsX() const; - int nBinsY() const; - int nRateBinsY() const; - int nBunchBinsY(SG::ReadHandle<TrigConf::L1Menu>& ) const; - int nBCIDbinsY() const; + // Returns number of chains based on the menu handle + int nChains(SG::ReadHandle<TrigConf::HLTMenu>& ) const; + + // Returns number of BCIDs to monitor + int nBCIDs() const; + + // Returns number of sequences + int nSequenceBins() const; + + // Returns number of steps + int nSteps() const; + + // Returns number of base steps: in, after ps, out steps + int nBaseSteps() const; + + // Returns number of bunchgroups from l1 menu + int nBunchGroups(SG::ReadHandle<TrigConf::L1Menu>& ) const; + + // Returns number of BCID chains to monitor + int nBCIDchains() const; + + // Init different types of histograms StatusCode initHist(LockedHandle<TH2>&, SG::ReadHandle<TrigConf::HLTMenu>&, bool = true); StatusCode initBunchHist(LockedHandle<TH2>&, SG::ReadHandle<TrigConf::HLTMenu>&, SG::ReadHandle<TrigConf::L1Menu>&); StatusCode initBCIDhist(LockedHandle<TH2>&, const std::vector<std::string>&); StatusCode initSeqHist(LockedHandle<TH2>&, std::set<std::string>&); + // Fill different types of histograms StatusCode fillDecisionCount(const std::vector<TrigCompositeUtils::DecisionID>& , int) const; StatusCode fillPassEvents(const TrigCompositeUtils::DecisionIDContainer&, int) const; StatusCode fillRate(const TrigCompositeUtils::DecisionIDContainer&, int) const;