From 75f0ba2642313affb45254c7f61c2817b434eaaa Mon Sep 17 00:00:00 2001 From: Christopher Jones Date: Fri, 28 Dec 2018 10:04:41 -0600 Subject: [PATCH] Make sure named bins are unique in HLTObjectsMonitor In the newest version of ROOT, histograms with named bins are merged via the bin's name, not the index. This means we must avoid bins having the same bin names. HLTObjectsMonitor has a histogram which uses path names for the bin names. In the past, multiple bins could have the same path name. This change guarantees uniqueness for the bin names and only fills a bin once per event. --- DQM/HLTEvF/plugins/HLTObjectsMonitor.cc | 45 ++++++++++++++++++------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/DQM/HLTEvF/plugins/HLTObjectsMonitor.cc b/DQM/HLTEvF/plugins/HLTObjectsMonitor.cc index ee3c4c1c6fe5e..79b85470f080c 100644 --- a/DQM/HLTEvF/plugins/HLTObjectsMonitor.cc +++ b/DQM/HLTEvF/plugins/HLTObjectsMonitor.cc @@ -2,6 +2,8 @@ #include #include #include +#include +#include // user include files #include "DataFormats/Common/interface/TriggerResults.h" @@ -37,7 +39,6 @@ #include "TLorentzVector.h" -#include struct hltPlot { @@ -127,6 +128,7 @@ class HLTObjectsMonitor : public DQMEDAnalyzer { MonitorElement* eventsPlot_; std::vector hltPlots_; + std::unordered_map plotNamesToBins_; bool debug_; @@ -345,15 +347,20 @@ HLTObjectsMonitor::analyze(const edm::Event& iEvent, const edm::EventSetup& iSet // loop over path int ibin = -1; + std::unordered_set plottedPathNameIndices; for (auto & plot : hltPlots_) { ibin++; if ( plot.pathIDX <= 0 ) continue; if ( triggerResults->accept(plot.pathIDX) ) { - if ( debug_ ) - std::cout << plot.pathNAME << " --> bin: " << ibin << std::endl; - eventsPlot_->Fill(ibin); - + //We only want to fill this once per pathNAME per event + auto index = plotNamesToBins_[plot.pathNAME]; + if(plottedPathNameIndices.end() == plottedPathNameIndices.find(index)) { + plottedPathNameIndices.insert(index); + if ( debug_ ) + std::cout << plot.pathNAME << " --> bin: " << ibin << std::endl; + eventsPlot_->Fill(index); + } const trigger::TriggerObjectCollection objects = triggerEvent->getObjects(); if ( hltConfig_.saveTags(plot.moduleNAME) ) { if ( debug_ ) @@ -591,13 +598,27 @@ void HLTObjectsMonitor::bookHistograms(DQMStore::IBooker & ibooker, edm::Run con std::string name = "eventsPerPath_"+label_; std::string title = " events per path"; - int nbins = hltPlots_.size(); - eventsPlot_ = ibooker.book1D(name,title,nbins,-0.5,double(nbins)-0.5); - eventsPlot_->setAxisTitle("HLT path"); - for ( int i=0; isetBinLabel(i+1,hltPlots_[i].pathNAME); - if ( debug_ ) - std::cout << hltPlots_[i].pathNAME << " --> bin: " << i+1 << std::endl; + + //We must avoid repeating the same pathNAME + { + std::unordered_map uniqueNames; + for(auto const& p: hltPlots_) { + plotNamesToBins_[p.pathNAME] = -1; + } + int nbins = plotNamesToBins_.size(); + eventsPlot_ = ibooker.book1D(name,title,nbins,-0.5,double(nbins)-0.5); + eventsPlot_->setAxisTitle("HLT path"); + int i=0; + //keep the bin order the same as hltPlots_ + for (auto const& p : hltPlots_) { + //only add a bin if this is the first time we've seen the name + if( -1 == plotNamesToBins_[p.pathNAME]) { + plotNamesToBins_[p.pathNAME] = i; + eventsPlot_->setBinLabel(i,p.pathNAME); + if ( debug_ ) + std::cout << p.pathNAME << " --> bin: " << i << std::endl; + } + } } for (auto & plot : hltPlots_) {