Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stop using bare ROOT objects in HLTDQMHist* classes [12_6_X] #40785

Merged
merged 1 commit into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 20 additions & 27 deletions DQMOffline/Trigger/interface/HLTDQMFilterEffHists.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename ObjType>
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);
Expand All @@ -52,8 +48,8 @@ class HLTDQMFilterEffHists {
void book2D(DQMStore::IBooker& iBooker, const edm::ParameterSet& histConfig);

private:
std::vector<std::unique_ptr<HLTDQMHist<ObjType> > > histsPass_;
std::vector<std::unique_ptr<HLTDQMHist<ObjType> > > histsTot_;
std::vector<std::unique_ptr<HLTDQMHist<ObjType>>> histsPass_;
std::vector<std::unique_ptr<HLTDQMHist<ObjType>>> histsTot_;
VarRangeCutColl<ObjType> rangeCuts_;
std::string filterName_;
std::string histTitle_;
Expand All @@ -66,7 +62,7 @@ template <typename ObjType>
HLTDQMFilterEffHists<ObjType>::HLTDQMFilterEffHists(const edm::ParameterSet& config,
std::string baseHistName,
std::string hltProcess)
: rangeCuts_(config.getParameter<std::vector<edm::ParameterSet> >("rangeCuts")),
: rangeCuts_(config.getParameter<std::vector<edm::ParameterSet>>("rangeCuts")),
filterName_(config.getParameter<std::string>("filterName")),
histTitle_(config.getParameter<std::string>("histTitle")),
folderName_(config.getParameter<std::string>("folderName")),
Expand All @@ -89,11 +85,11 @@ edm::ParameterSetDescription HLTDQMFilterEffHists<ObjType>::makePSetDescriptionH

//what this is doing is trival and is left as an exercise to the reader
auto histDescCases =
"1D" >> (edm::ParameterDescription<std::vector<double> >("binLowEdges", std::vector<double>(), true) and
"1D" >> (edm::ParameterDescription<std::vector<double>>("binLowEdges", std::vector<double>(), true) and
edm::ParameterDescription<std::string>("nameSuffex", "", true) and
edm::ParameterDescription<std::string>("vsVar", "", true)) or
"2D" >> (edm::ParameterDescription<std::vector<double> >("xBinLowEdges", std::vector<double>(), true) and
edm::ParameterDescription<std::vector<double> >("yBinLowEdges", std::vector<double>(), true) and
"2D" >> (edm::ParameterDescription<std::vector<double>>("xBinLowEdges", std::vector<double>(), true) and
edm::ParameterDescription<std::vector<double>>("yBinLowEdges", std::vector<double>(), true) and
edm::ParameterDescription<std::string>("nameSuffex", "", true) and
edm::ParameterDescription<std::string>("xVar", "", true) and
edm::ParameterDescription<std::string>("yVar", "", true));
Expand Down Expand Up @@ -121,7 +117,7 @@ void HLTDQMFilterEffHists<ObjType>::bookHists(DQMStore::IBooker& iBooker,

template <typename ObjType>
void HLTDQMFilterEffHists<ObjType>::book1D(DQMStore::IBooker& iBooker, const edm::ParameterSet& histConfig) {
auto binLowEdgesDouble = histConfig.getParameter<std::vector<double> >("binLowEdges");
auto binLowEdgesDouble = histConfig.getParameter<std::vector<double>>("binLowEdges");
std::vector<float> binLowEdges;
binLowEdges.reserve(binLowEdgesDouble.size());
for (double lowEdge : binLowEdgesDouble)
Expand All @@ -131,28 +127,28 @@ void HLTDQMFilterEffHists<ObjType>::book1D(DQMStore::IBooker& iBooker, const edm
(histTitle_ + nameSuffex + " Pass").c_str(),
binLowEdges.size() - 1,
&binLowEdges[0]);
std::unique_ptr<HLTDQMHist<ObjType> > hist;
std::unique_ptr<HLTDQMHist<ObjType>> hist;
auto vsVar = histConfig.getParameter<std::string>("vsVar");
auto vsVarFunc = hltdqm::getUnaryFuncFloat<ObjType>(vsVar);
if (!vsVarFunc) {
throw cms::Exception("ConfigError") << " vsVar " << vsVar << " is giving null ptr (likely empty) in " << __FILE__
<< "," << __LINE__ << std::endl;
}
VarRangeCutColl<ObjType> rangeCuts(histConfig.getParameter<std::vector<edm::ParameterSet> >("rangeCuts"));
hist = std::make_unique<HLTDQMHist1D<ObjType, float> >(mePass->getTH1(), vsVar, vsVarFunc, rangeCuts);
VarRangeCutColl<ObjType> rangeCuts(histConfig.getParameter<std::vector<edm::ParameterSet>>("rangeCuts"));
hist = std::make_unique<HLTDQMHist1D<ObjType, float>>(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<HLTDQMHist1D<ObjType, float> >(meTot->getTH1(), vsVar, vsVarFunc, rangeCuts);
hist = std::make_unique<HLTDQMHist1D<ObjType, float>>(meTot, vsVar, vsVarFunc, rangeCuts);
histsTot_.emplace_back(std::move(hist));
}

template <typename ObjType>
void HLTDQMFilterEffHists<ObjType>::book2D(DQMStore::IBooker& iBooker, const edm::ParameterSet& histConfig) {
auto xBinLowEdgesDouble = histConfig.getParameter<std::vector<double> >("xBinLowEdges");
auto yBinLowEdgesDouble = histConfig.getParameter<std::vector<double> >("yBinLowEdges");
auto xBinLowEdgesDouble = histConfig.getParameter<std::vector<double>>("xBinLowEdges");
auto yBinLowEdgesDouble = histConfig.getParameter<std::vector<double>>("yBinLowEdges");
std::vector<float> xBinLowEdges;
std::vector<float> yBinLowEdges;
xBinLowEdges.reserve(xBinLowEdgesDouble.size());
Expand All @@ -168,7 +164,7 @@ void HLTDQMFilterEffHists<ObjType>::book2D(DQMStore::IBooker& iBooker, const edm
&xBinLowEdges[0],
yBinLowEdges.size() - 1,
&yBinLowEdges[0]);
std::unique_ptr<HLTDQMHist<ObjType> > hist;
std::unique_ptr<HLTDQMHist<ObjType>> hist;
auto xVar = histConfig.getParameter<std::string>("xVar");
auto yVar = histConfig.getParameter<std::string>("yVar");
auto xVarFunc = hltdqm::getUnaryFuncFloat<ObjType>(xVar);
Expand All @@ -177,11 +173,9 @@ void HLTDQMFilterEffHists<ObjType>::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<ObjType> rangeCuts(histConfig.getParameter<std::vector<edm::ParameterSet> >("rangeCuts"));
VarRangeCutColl<ObjType> rangeCuts(histConfig.getParameter<std::vector<edm::ParameterSet>>("rangeCuts"));

//really? really no MonitorElement::getTH2...sigh
hist = std::make_unique<HLTDQMHist2D<ObjType, float> >(
static_cast<TH2*>(mePass->getTH1()), xVar, yVar, xVarFunc, yVarFunc, rangeCuts);
hist = std::make_unique<HLTDQMHist2D<ObjType, float>>(mePass, xVar, yVar, xVarFunc, yVarFunc, rangeCuts);
histsPass_.emplace_back(std::move(hist));

auto meTot = iBooker.book2D((baseHistName_ + filterName_ + nameSuffex + "_tot").c_str(),
Expand All @@ -191,8 +185,7 @@ void HLTDQMFilterEffHists<ObjType>::book2D(DQMStore::IBooker& iBooker, const edm
yBinLowEdges.size() - 1,
&yBinLowEdges[0]);

hist = std::make_unique<HLTDQMHist2D<ObjType, float> >(
static_cast<TH2*>(meTot->getTH1()), xVar, yVar, xVarFunc, yVarFunc, rangeCuts);
hist = std::make_unique<HLTDQMHist2D<ObjType, float>>(meTot, xVar, yVar, xVarFunc, yVarFunc, rangeCuts);
histsTot_.emplace_back(std::move(hist));
}

Expand Down
67 changes: 36 additions & 31 deletions DQMOffline/Trigger/interface/HLTDQMHist.h
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 <TH1.h>
#include <TH2.h>

//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 <typename ObjType>
class HLTDQMHist {
public:
Expand All @@ -45,40 +42,46 @@ 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 <typename ObjType, typename ValType>
class HLTDQMHist1D : public HLTDQMHist<ObjType> {
public:
HLTDQMHist1D(TH1* hist,
typedef dqm::legacy::MonitorElement MonitorElement;

HLTDQMHist1D(MonitorElement* me_ptr,
std::string varName,
std::function<ValType(const ObjType&)> func,
VarRangeCutColl<ObjType> 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<ObjType>& 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));
}
}

private:
std::function<ValType(const ObjType&)> var_;
std::string varName_;
VarRangeCutColl<ObjType> localRangeCuts_;
TH1* hist_; //we do not own this
MonitorElement* const me_ptr_; // we do not own this
};

template <typename ObjType, typename XValType, typename YValType = XValType>
class HLTDQMHist2D : public HLTDQMHist<ObjType> {
public:
HLTDQMHist2D(TH2* hist,
typedef dqm::legacy::MonitorElement MonitorElement;

HLTDQMHist2D(MonitorElement* me_ptr,
std::string xVarName,
std::string yVarName,
std::function<XValType(const ObjType&)> xFunc,
Expand All @@ -89,16 +92,18 @@ class HLTDQMHist2D : public HLTDQMHist<ObjType> {
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<ObjType>& 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<std::string>{xVarName_, yVarName_}) && localRangeCuts_(obj)) {
hist_->Fill(xVar_(obj), yVar_(obj));
me_ptr_->Fill(xVar_(obj), yVar_(obj));
}
}

Expand All @@ -108,7 +113,7 @@ class HLTDQMHist2D : public HLTDQMHist<ObjType> {
std::string xVarName_;
std::string yVarName_;
VarRangeCutColl<ObjType> localRangeCuts_;
TH2* hist_; //we do not own this
MonitorElement* const me_ptr_; // we do not own this
};

#endif
#endif // DQMOffline_Trigger_HLTDQMHist_h
1 change: 0 additions & 1 deletion DQMOffline/Trigger/interface/HLTDQMTagAndProbeEff.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ namespace {
template <typename TagType, typename TagCollType, typename ProbeType = TagType, typename ProbeCollType = TagCollType>
class HLTDQMTagAndProbeEff {
public:
typedef dqm::legacy::MonitorElement MonitorElement;
typedef dqm::legacy::DQMStore DQMStore;

explicit HLTDQMTagAndProbeEff(const edm::ParameterSet& pset, edm::ConsumesCollector&& cc);
Expand Down
35 changes: 8 additions & 27 deletions DQMOffline/Trigger/plugins/HLTTagAndProbeOfflineSource.cc
Original file line number Diff line number Diff line change
@@ -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 <vector>
#include <string>

template <typename TagType, typename TagCollType, typename ProbeType = TagType, typename ProbeCollType = TagCollType>
class HLTTagAndProbeOfflineSource : public DQMEDAnalyzer {
Expand All @@ -34,13 +21,13 @@ class HLTTagAndProbeOfflineSource : public DQMEDAnalyzer {
void bookHistograms(DQMStore::IBooker&, edm::Run const& run, edm::EventSetup const& c) override;

private:
std::vector<HLTDQMTagAndProbeEff<TagType, TagCollType, ProbeType, ProbeCollType> > tagAndProbeEffs_;
std::vector<HLTDQMTagAndProbeEff<TagType, TagCollType, ProbeType, ProbeCollType>> tagAndProbeEffs_;
};

template <typename TagType, typename TagCollType, typename ProbeType, typename ProbeCollType>
HLTTagAndProbeOfflineSource<TagType, TagCollType, ProbeType, ProbeCollType>::HLTTagAndProbeOfflineSource(
const edm::ParameterSet& config) {
auto histCollConfigs = config.getParameter<std::vector<edm::ParameterSet> >("tagAndProbeCollections");
auto histCollConfigs = config.getParameter<std::vector<edm::ParameterSet>>("tagAndProbeCollections");
for (auto& histCollConfig : histCollConfigs) {
tagAndProbeEffs_.emplace_back(
HLTDQMTagAndProbeEff<TagType, TagCollType, ProbeType, ProbeCollType>(histCollConfig, consumesCollector()));
Expand All @@ -51,16 +38,10 @@ template <typename TagType, typename TagCollType, typename ProbeType, typename P
void HLTTagAndProbeOfflineSource<TagType, TagCollType, ProbeType, ProbeCollType>::fillDescriptions(
edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("objs", edm::InputTag(""));
desc.addVPSet("tagAndProbeCollections",
HLTDQMTagAndProbeEff<TagType, TagCollType, ProbeType, ProbeCollType>::makePSetDescription(),
std::vector<edm::ParameterSet>());

// 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 <typename TagType, typename TagCollType, typename ProbeType, typename ProbeCollType>
Expand Down