From d2599d8bc93d8eec2f1be68e4e89660ec0ba1df2 Mon Sep 17 00:00:00 2001 From: Marino Missiroli Date: Tue, 14 Feb 2023 11:02:49 +0100 Subject: [PATCH] stop using bare ROOT objects in HLTDQMHist* --- .../Trigger/interface/HLTDQMFilterEffHists.h | 47 ++++++------- DQMOffline/Trigger/interface/HLTDQMHist.h | 67 ++++++++++--------- .../Trigger/interface/HLTDQMTagAndProbeEff.h | 1 - .../plugins/HLTTagAndProbeOfflineSource.cc | 35 +++------- 4 files changed, 64 insertions(+), 86 deletions(-) diff --git a/DQMOffline/Trigger/interface/HLTDQMFilterEffHists.h b/DQMOffline/Trigger/interface/HLTDQMFilterEffHists.h index 34547fe3e711f..1eb0c55a8bf0a 100644 --- a/DQMOffline/Trigger/interface/HLTDQMFilterEffHists.h +++ b/DQMOffline/Trigger/interface/HLTDQMFilterEffHists.h @@ -18,22 +18,18 @@ // //*********************************************************************************** -#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" - -#include "DQMServices/Core/interface/DQMStore.h" - #include "DataFormats/HLTReco/interface/TriggerEvent.h" - #include "DQMOffline/Trigger/interface/HLTDQMHist.h" #include "DQMOffline/Trigger/interface/VarRangeCutColl.h" #include "DQMOffline/Trigger/interface/FunctionDefs.h" #include "DQMOffline/Trigger/interface/UtilFuncs.h" +#include "DQMServices/Core/interface/DQMStore.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" template class HLTDQMFilterEffHists { public: - typedef dqm::legacy::MonitorElement MonitorElement; typedef dqm::legacy::DQMStore DQMStore; explicit HLTDQMFilterEffHists(const edm::ParameterSet& config, std::string baseHistName, std::string hltProcess); @@ -52,8 +48,8 @@ class HLTDQMFilterEffHists { void book2D(DQMStore::IBooker& iBooker, const edm::ParameterSet& histConfig); private: - std::vector > > histsPass_; - std::vector > > histsTot_; + std::vector>> histsPass_; + std::vector>> histsTot_; VarRangeCutColl rangeCuts_; std::string filterName_; std::string histTitle_; @@ -66,7 +62,7 @@ template HLTDQMFilterEffHists::HLTDQMFilterEffHists(const edm::ParameterSet& config, std::string baseHistName, std::string hltProcess) - : rangeCuts_(config.getParameter >("rangeCuts")), + : rangeCuts_(config.getParameter>("rangeCuts")), filterName_(config.getParameter("filterName")), histTitle_(config.getParameter("histTitle")), folderName_(config.getParameter("folderName")), @@ -89,11 +85,11 @@ edm::ParameterSetDescription HLTDQMFilterEffHists::makePSetDescriptionH //what this is doing is trival and is left as an exercise to the reader auto histDescCases = - "1D" >> (edm::ParameterDescription >("binLowEdges", std::vector(), true) and + "1D" >> (edm::ParameterDescription>("binLowEdges", std::vector(), true) and edm::ParameterDescription("nameSuffex", "", true) and edm::ParameterDescription("vsVar", "", true)) or - "2D" >> (edm::ParameterDescription >("xBinLowEdges", std::vector(), true) and - edm::ParameterDescription >("yBinLowEdges", std::vector(), true) and + "2D" >> (edm::ParameterDescription>("xBinLowEdges", std::vector(), true) and + edm::ParameterDescription>("yBinLowEdges", std::vector(), true) and edm::ParameterDescription("nameSuffex", "", true) and edm::ParameterDescription("xVar", "", true) and edm::ParameterDescription("yVar", "", true)); @@ -121,7 +117,7 @@ void HLTDQMFilterEffHists::bookHists(DQMStore::IBooker& iBooker, template void HLTDQMFilterEffHists::book1D(DQMStore::IBooker& iBooker, const edm::ParameterSet& histConfig) { - auto binLowEdgesDouble = histConfig.getParameter >("binLowEdges"); + auto binLowEdgesDouble = histConfig.getParameter>("binLowEdges"); std::vector binLowEdges; binLowEdges.reserve(binLowEdgesDouble.size()); for (double lowEdge : binLowEdgesDouble) @@ -131,28 +127,28 @@ void HLTDQMFilterEffHists::book1D(DQMStore::IBooker& iBooker, const edm (histTitle_ + nameSuffex + " Pass").c_str(), binLowEdges.size() - 1, &binLowEdges[0]); - std::unique_ptr > hist; + std::unique_ptr> hist; auto vsVar = histConfig.getParameter("vsVar"); auto vsVarFunc = hltdqm::getUnaryFuncFloat(vsVar); if (!vsVarFunc) { throw cms::Exception("ConfigError") << " vsVar " << vsVar << " is giving null ptr (likely empty) in " << __FILE__ << "," << __LINE__ << std::endl; } - VarRangeCutColl rangeCuts(histConfig.getParameter >("rangeCuts")); - hist = std::make_unique >(mePass->getTH1(), vsVar, vsVarFunc, rangeCuts); + VarRangeCutColl rangeCuts(histConfig.getParameter>("rangeCuts")); + hist = std::make_unique>(mePass, vsVar, vsVarFunc, rangeCuts); histsPass_.emplace_back(std::move(hist)); auto meTot = iBooker.book1D((baseHistName_ + filterName_ + nameSuffex + "_tot").c_str(), (histTitle_ + nameSuffex + " Total").c_str(), binLowEdges.size() - 1, &binLowEdges[0]); - hist = std::make_unique >(meTot->getTH1(), vsVar, vsVarFunc, rangeCuts); + hist = std::make_unique>(meTot, vsVar, vsVarFunc, rangeCuts); histsTot_.emplace_back(std::move(hist)); } template void HLTDQMFilterEffHists::book2D(DQMStore::IBooker& iBooker, const edm::ParameterSet& histConfig) { - auto xBinLowEdgesDouble = histConfig.getParameter >("xBinLowEdges"); - auto yBinLowEdgesDouble = histConfig.getParameter >("yBinLowEdges"); + auto xBinLowEdgesDouble = histConfig.getParameter>("xBinLowEdges"); + auto yBinLowEdgesDouble = histConfig.getParameter>("yBinLowEdges"); std::vector xBinLowEdges; std::vector yBinLowEdges; xBinLowEdges.reserve(xBinLowEdgesDouble.size()); @@ -168,7 +164,7 @@ void HLTDQMFilterEffHists::book2D(DQMStore::IBooker& iBooker, const edm &xBinLowEdges[0], yBinLowEdges.size() - 1, &yBinLowEdges[0]); - std::unique_ptr > hist; + std::unique_ptr> hist; auto xVar = histConfig.getParameter("xVar"); auto yVar = histConfig.getParameter("yVar"); auto xVarFunc = hltdqm::getUnaryFuncFloat(xVar); @@ -177,11 +173,9 @@ void HLTDQMFilterEffHists::book2D(DQMStore::IBooker& iBooker, const edm throw cms::Exception("ConfigError") << " xVar " << xVar << " or yVar " << yVar << " is giving null ptr (likely empty str passed)" << std::endl; } - VarRangeCutColl rangeCuts(histConfig.getParameter >("rangeCuts")); + VarRangeCutColl rangeCuts(histConfig.getParameter>("rangeCuts")); - //really? really no MonitorElement::getTH2...sigh - hist = std::make_unique >( - static_cast(mePass->getTH1()), xVar, yVar, xVarFunc, yVarFunc, rangeCuts); + hist = std::make_unique>(mePass, xVar, yVar, xVarFunc, yVarFunc, rangeCuts); histsPass_.emplace_back(std::move(hist)); auto meTot = iBooker.book2D((baseHistName_ + filterName_ + nameSuffex + "_tot").c_str(), @@ -191,8 +185,7 @@ void HLTDQMFilterEffHists::book2D(DQMStore::IBooker& iBooker, const edm yBinLowEdges.size() - 1, &yBinLowEdges[0]); - hist = std::make_unique >( - static_cast(meTot->getTH1()), xVar, yVar, xVarFunc, yVarFunc, rangeCuts); + hist = std::make_unique>(meTot, xVar, yVar, xVarFunc, yVarFunc, rangeCuts); histsTot_.emplace_back(std::move(hist)); } diff --git a/DQMOffline/Trigger/interface/HLTDQMHist.h b/DQMOffline/Trigger/interface/HLTDQMHist.h index d4d581cace23f..8932374b2be3f 100644 --- a/DQMOffline/Trigger/interface/HLTDQMHist.h +++ b/DQMOffline/Trigger/interface/HLTDQMHist.h @@ -1,18 +1,18 @@ -#ifndef DQMOnline_Trigger_HLTDQMHist_h -#define DQMOnline_Trigger_HLTDQMHist_h +#ifndef DQMOffline_Trigger_HLTDQMHist_h +#define DQMOffline_Trigger_HLTDQMHist_h //******************************************************************************** // // Description: -// A histogram together with the necessary information to fill it when pass an +// A MonitorElement together with the necessary information to fill it when pass an // object and minimal selection cuts. These selection cuts are intended to be // simple selections on kinematic variables. There are two levels of these -// selection cuts, global (which apply to all histograms in the group and passed -// by the calling function) and local (which are stored with the histogram -// and are specific to that histogram. Global selection cuts on the variable being +// selection cuts, global (which apply to all MonitorElements in the group and passed +// by the calling function) and local (which are stored with the MonitorElement +// and are specific to that MonitorElement). Global selection cuts on the variable being // plotted are ignored, for example Et cuts are removed for turn on plots // -// Implimentation: +// Implementation: // std::function holds the function which generates the vs variable // the name of the vs variable is also stored so we can determine if we should not apply // a given selection cut @@ -24,15 +24,12 @@ #include "DQMOffline/Trigger/interface/FunctionDefs.h" #include "DQMOffline/Trigger/interface/VarRangeCutColl.h" +#include "DQMServices/Core/interface/MonitorElement.h" +#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/Event.h" - -#include -#include - -//our base class for our histograms -//takes an object, edm::Event,edm::EventSetup and fills the histogram -//with the predetermined variable (or varaibles) +//our base class for our MonitorElements +//takes an object, edm::Event,edm::EventSetup and fills the MonitorElement +//with the predetermined variable (or variables) template class HLTDQMHist { public: @@ -45,26 +42,30 @@ class HLTDQMHist { }; //this class is a specific implimentation of a HLTDQMHist -//it has the value with which to fill the histogram -//and the histogram itself -//we do not own the histogram +//it has the value with which to fill the MonitorElement +//and the MonitorElement itself +//we do not own the MonitorElement template class HLTDQMHist1D : public HLTDQMHist { public: - HLTDQMHist1D(TH1* hist, + typedef dqm::legacy::MonitorElement MonitorElement; + + HLTDQMHist1D(MonitorElement* me_ptr, std::string varName, std::function func, VarRangeCutColl rangeCuts) - : var_(std::move(func)), varName_(std::move(varName)), localRangeCuts_(std::move(rangeCuts)), hist_(hist) {} + : var_(std::move(func)), varName_(std::move(varName)), localRangeCuts_(std::move(rangeCuts)), me_ptr_(me_ptr) {} void fill(const ObjType& obj, const edm::Event& event, const edm::EventSetup& setup, const VarRangeCutColl& globalRangeCuts) override { - //local range cuts are specific to a histogram so dont ignore variables - //like global ones (all local cuts should be approprate to the histogram in question + if (me_ptr_ == nullptr) + return; + //local range cuts are specific to a MonitorElement so dont ignore variables + //like global ones (all local cuts should be appropriate to the MonitorElement in question if (globalRangeCuts(obj, varName_) && localRangeCuts_(obj)) { - hist_->Fill(var_(obj)); + me_ptr_->Fill(var_(obj)); } } @@ -72,13 +73,15 @@ class HLTDQMHist1D : public HLTDQMHist { std::function var_; std::string varName_; VarRangeCutColl localRangeCuts_; - TH1* hist_; //we do not own this + MonitorElement* const me_ptr_; // we do not own this }; template class HLTDQMHist2D : public HLTDQMHist { public: - HLTDQMHist2D(TH2* hist, + typedef dqm::legacy::MonitorElement MonitorElement; + + HLTDQMHist2D(MonitorElement* me_ptr, std::string xVarName, std::string yVarName, std::function xFunc, @@ -89,16 +92,18 @@ class HLTDQMHist2D : public HLTDQMHist { xVarName_(std::move(xVarName)), yVarName_(std::move(yVarName)), localRangeCuts_(std::move(rangeCuts)), - hist_(hist) {} + me_ptr_(me_ptr) {} void fill(const ObjType& obj, const edm::Event& event, const edm::EventSetup& setup, const VarRangeCutColl& globalRangeCuts) override { - //local range cuts are specific to a histogram so dont ignore variables - //like global ones (all local cuts should be approprate to the histogram in question + if (me_ptr_ == nullptr) + return; + //local range cuts are specific to a MonitorElement so dont ignore variables + //like global ones (all local cuts should be appropriate to the MonitorElement in question if (globalRangeCuts(obj, std::vector{xVarName_, yVarName_}) && localRangeCuts_(obj)) { - hist_->Fill(xVar_(obj), yVar_(obj)); + me_ptr_->Fill(xVar_(obj), yVar_(obj)); } } @@ -108,7 +113,7 @@ class HLTDQMHist2D : public HLTDQMHist { std::string xVarName_; std::string yVarName_; VarRangeCutColl localRangeCuts_; - TH2* hist_; //we do not own this + MonitorElement* const me_ptr_; // we do not own this }; -#endif +#endif // DQMOffline_Trigger_HLTDQMHist_h diff --git a/DQMOffline/Trigger/interface/HLTDQMTagAndProbeEff.h b/DQMOffline/Trigger/interface/HLTDQMTagAndProbeEff.h index 5d652cecb327c..c5135a1d2f262 100644 --- a/DQMOffline/Trigger/interface/HLTDQMTagAndProbeEff.h +++ b/DQMOffline/Trigger/interface/HLTDQMTagAndProbeEff.h @@ -58,7 +58,6 @@ namespace { template class HLTDQMTagAndProbeEff { public: - typedef dqm::legacy::MonitorElement MonitorElement; typedef dqm::legacy::DQMStore DQMStore; explicit HLTDQMTagAndProbeEff(const edm::ParameterSet& pset, edm::ConsumesCollector&& cc); diff --git a/DQMOffline/Trigger/plugins/HLTTagAndProbeOfflineSource.cc b/DQMOffline/Trigger/plugins/HLTTagAndProbeOfflineSource.cc index dd263456700ea..1049295f3e767 100644 --- a/DQMOffline/Trigger/plugins/HLTTagAndProbeOfflineSource.cc +++ b/DQMOffline/Trigger/plugins/HLTTagAndProbeOfflineSource.cc @@ -1,24 +1,11 @@ - -#include "DQMServices/Core/interface/DQMStore.h" - #include "DQMServices/Core/interface/DQMEDAnalyzer.h" - -#include "FWCore/Common/interface/TriggerNames.h" -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/MakerMacros.h" -#include "FWCore/MessageLogger/interface/MessageLogger.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" - -#include "DataFormats/Common/interface/TriggerResults.h" -#include "DataFormats/HLTReco/interface/TriggerEvent.h" -#include "DataFormats/HLTReco/interface/TriggerObject.h" -#include "DataFormats/HLTReco/interface/TriggerTypeDefs.h" - +#include "DQMServices/Core/interface/DQMStore.h" #include "DQMOffline/Trigger/interface/HLTDQMTagAndProbeEff.h" +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" #include -#include template class HLTTagAndProbeOfflineSource : public DQMEDAnalyzer { @@ -34,13 +21,13 @@ class HLTTagAndProbeOfflineSource : public DQMEDAnalyzer { void bookHistograms(DQMStore::IBooker&, edm::Run const& run, edm::EventSetup const& c) override; private: - std::vector > tagAndProbeEffs_; + std::vector> tagAndProbeEffs_; }; template HLTTagAndProbeOfflineSource::HLTTagAndProbeOfflineSource( const edm::ParameterSet& config) { - auto histCollConfigs = config.getParameter >("tagAndProbeCollections"); + auto histCollConfigs = config.getParameter>("tagAndProbeCollections"); for (auto& histCollConfig : histCollConfigs) { tagAndProbeEffs_.emplace_back( HLTDQMTagAndProbeEff(histCollConfig, consumesCollector())); @@ -51,16 +38,10 @@ template ::fillDescriptions( edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; - desc.add("objs", edm::InputTag("")); desc.addVPSet("tagAndProbeCollections", HLTDQMTagAndProbeEff::makePSetDescription(), - std::vector()); - - // addDefault must be used here instead of add unless this function is specialized - // for different sets of template parameter types. Each specialization would need - // a different module label. Otherwise the generated cfi filenames will conflict - // for the different plugins. - descriptions.addDefault(desc); + {}); + descriptions.addWithDefaultLabel(desc); } template