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

migrate PixelVTXMonitor to DQMEDAnalyzer #37942

Merged
merged 1 commit into from
May 14, 2022
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
166 changes: 101 additions & 65 deletions DQM/BeamMonitor/plugins/PixelVTXMonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,64 +6,114 @@
* Description: Pixel Vertex Monitoring for different HLT paths
*
*/
#include "DQM/BeamMonitor/plugins/PixelVTXMonitor.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Framework/interface/LuminosityBlock.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/Framework/interface/Event.h"

// system includes
#include <string>
#include <vector>
#include <map>

// user includes
#include "DQMServices/Core/interface/DQMEDAnalyzer.h"
#include "DQMServices/Core/interface/DQMStore.h"
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/Common/interface/TriggerResults.h"
#include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h"
#include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h"
#include "DataFormats/VertexReco/interface/Vertex.h"
#include "DataFormats/VertexReco/interface/VertexFwd.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/LuminosityBlock.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"

// ROOT includes
#include "TPRegexp.h"

//
// class declaration
//

class PixelVTXMonitor : public DQMEDAnalyzer {
public:
typedef dqm::legacy::MonitorElement MonitorElement;
typedef dqm::legacy::DQMStore DQMStore;
PixelVTXMonitor(const edm::ParameterSet&);
~PixelVTXMonitor() override = default;

protected:
void bookHistograms(DQMStore::IBooker& iBooker, const edm::Run& iRun, const edm::EventSetup& iSetup) override;

private:
void dqmBeginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) override;
void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;

edm::ParameterSet parameters_;

const std::string moduleName_;
const std::string folderName_;
const edm::InputTag pixelClusterInputTag_;
const edm::InputTag pixelVertexInputTag_;
const edm::InputTag hltInputTag_;
const edm::EDGetTokenT<SiPixelClusterCollectionNew> pixelClusterInputTagToken_;
const edm::EDGetTokenT<reco::VertexCollection> pixelVertexInputTagToken_;
const edm::EDGetTokenT<edm::TriggerResults> hltInputTagToken_;
const float minVtxDoF_;

HLTConfigProvider hltConfig_;

struct PixelMEs {
MonitorElement* clusME;
MonitorElement* vtxME;
};

std::map<std::string, PixelMEs> histoMap_;
};

// -----------------------------
// constructors and destructor
// -----------------------------

PixelVTXMonitor::PixelVTXMonitor(const edm::ParameterSet& ps) : parameters_(ps) {
moduleName_ = parameters_.getParameter<std::string>("ModuleName");
folderName_ = parameters_.getParameter<std::string>("FolderName");
pixelClusterInputTagToken_ =
consumes<SiPixelClusterCollectionNew>(parameters_.getParameter<edm::InputTag>("PixelClusterInputTag"));
pixelVertexInputTagToken_ =
consumes<reco::VertexCollection>(parameters_.getParameter<edm::InputTag>("PixelVertexInputTag"));
hltInputTagToken_ = consumes<edm::TriggerResults>(parameters_.getParameter<edm::InputTag>("HLTInputTag"));
pixelClusterInputTag_ = parameters_.getParameter<edm::InputTag>("PixelClusterInputTag");
pixelVertexInputTag_ = parameters_.getParameter<edm::InputTag>("PixelVertexInputTag");
hltInputTag_ = parameters_.getParameter<edm::InputTag>("HLTInputTag");
minVtxDoF_ = parameters_.getParameter<double>("MinVtxDoF");
}

PixelVTXMonitor::~PixelVTXMonitor() {}

void PixelVTXMonitor::bookHistograms() {
PixelVTXMonitor::PixelVTXMonitor(const edm::ParameterSet& ps)
: parameters_(ps),
moduleName_(parameters_.getParameter<std::string>("ModuleName")),
folderName_(parameters_.getParameter<std::string>("FolderName")),
pixelClusterInputTag_(parameters_.getParameter<edm::InputTag>("PixelClusterInputTag")),
pixelVertexInputTag_(parameters_.getParameter<edm::InputTag>("PixelVertexInputTag")),
hltInputTag_(parameters_.getParameter<edm::InputTag>("HLTInputTag")),
pixelClusterInputTagToken_(consumes<SiPixelClusterCollectionNew>(pixelClusterInputTag_)),
pixelVertexInputTagToken_(consumes<reco::VertexCollection>(pixelVertexInputTag_)),
hltInputTagToken_(consumes<edm::TriggerResults>(hltInputTag_)),
minVtxDoF_(parameters_.getParameter<double>("MinVtxDoF")) {}

void PixelVTXMonitor::bookHistograms(DQMStore::IBooker& iBooker, const edm::Run&, const edm::EventSetup&) {
std::vector<std::string> hltPathsOfInterest =
parameters_.getParameter<std::vector<std::string> >("HLTPathsOfInterest");
if (hltPathsOfInterest.empty())
return;

const std::vector<std::string>& pathList = hltConfig_.triggerNames();
std::vector<std::string> selectedPaths;
for (std::vector<std::string>::const_iterator it = pathList.begin(); it != pathList.end(); ++it) {
for (const auto& it : pathList) {
int nmatch = 0;
for (std::vector<std::string>::const_iterator kt = hltPathsOfInterest.begin(); kt != hltPathsOfInterest.end();
++kt) {
nmatch += TPRegexp(*kt).Match(*it);
for (const auto& kt : hltPathsOfInterest) {
nmatch += TPRegexp(kt).Match(it);
}
if (!nmatch)
continue;
else
selectedPaths.push_back(*it);
selectedPaths.push_back(it);
}

edm::ParameterSet ClusHistoPar = parameters_.getParameter<edm::ParameterSet>("TH1ClusPar");
edm::ParameterSet VtxHistoPar = parameters_.getParameter<edm::ParameterSet>("TH1VtxPar");

std::string currentFolder = moduleName_ + "/" + folderName_;
dbe_->setCurrentFolder(currentFolder);
iBooker.setCurrentFolder(currentFolder);

PixelMEs local_MEs;
for (std::vector<std::string>::iterator it = selectedPaths.begin(); it != selectedPaths.end(); it++) {
std::string tag = (*it);
for (const auto& tag : selectedPaths) {
std::map<std::string, PixelMEs>::iterator iPos = histoMap_.find(tag);
if (iPos == histoMap_.end()) {
std::string hname, htitle;
Expand All @@ -72,30 +122,28 @@ void PixelVTXMonitor::bookHistograms() {
hname += tag;
htitle = "# of Pixel Clusters (";
htitle += tag + ")";
local_MEs.clusME = dbe_->book1D(hname,
htitle,
ClusHistoPar.getParameter<int32_t>("Xbins"),
ClusHistoPar.getParameter<double>("Xmin"),
ClusHistoPar.getParameter<double>("Xmax"));
local_MEs.clusME = iBooker.book1D(hname,
htitle,
ClusHistoPar.getParameter<int32_t>("Xbins"),
ClusHistoPar.getParameter<double>("Xmin"),
ClusHistoPar.getParameter<double>("Xmax"));

hname = "nPxlVtx_";
hname += tag;
htitle = "# of Pixel Vertices (";
htitle += tag + ")";
local_MEs.vtxME = dbe_->book1D(hname,
htitle,
VtxHistoPar.getParameter<int32_t>("Xbins"),
VtxHistoPar.getParameter<double>("Xmin"),
VtxHistoPar.getParameter<double>("Xmax"));
local_MEs.vtxME = iBooker.book1D(hname,
htitle,
VtxHistoPar.getParameter<int32_t>("Xbins"),
VtxHistoPar.getParameter<double>("Xmin"),
VtxHistoPar.getParameter<double>("Xmax"));

histoMap_.insert(std::make_pair(tag, local_MEs));
}
}
}

void PixelVTXMonitor::beginJob() { dbe_ = edm::Service<DQMStore>().operator->(); }

void PixelVTXMonitor::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {
void PixelVTXMonitor::dqmBeginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {
bool changed = true;
if (hltConfig_.init(iRun, iSetup, hltInputTag_.process(), changed)) {
// if init returns TRUE, initialisation has succeeded!
Expand All @@ -108,15 +156,13 @@ void PixelVTXMonitor::beginRun(edm::Run const& iRun, edm::EventSetup const& iSet
<< " failed";
// In this case, all access methods will return empty values!
}
bookHistograms();
}
void PixelVTXMonitor::analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) {
if (histoMap_.empty())
return;

//Access Pixel Clusters
edm::Handle<SiPixelClusterCollectionNew> siPixelClusters;
iEvent.getByToken(pixelClusterInputTagToken_, siPixelClusters);
edm::Handle<SiPixelClusterCollectionNew> siPixelClusters = iEvent.getHandle(pixelClusterInputTagToken_);

if (!siPixelClusters.isValid()) {
edm::LogError("PixelVTXMonotor") << "Could not find Cluster Collection " << pixelClusterInputTag_;
Expand All @@ -125,33 +171,31 @@ void PixelVTXMonitor::analyze(edm::Event const& iEvent, edm::EventSetup const& i
unsigned nClusters = siPixelClusters->size();

//Access Pixel Verteces
edm::Handle<reco::VertexCollection> pixelVertices;
iEvent.getByToken(pixelVertexInputTagToken_, pixelVertices);
edm::Handle<reco::VertexCollection> pixelVertices = iEvent.getHandle(pixelVertexInputTagToken_);
if (!pixelVertices.isValid()) {
edm::LogError("PixelVTXMonotor") << "Could not find Vertex Collection " << pixelVertexInputTag_;
return;
}

int nVtx = 0;
for (reco::VertexCollection::const_iterator ivtx = pixelVertices->begin(); ivtx != pixelVertices->end(); ++ivtx) {
for (const auto& ivtx : *pixelVertices) {
if (minVtxDoF_ == -1)
nVtx++;
else {
if ((ivtx->isValid() == true) && (ivtx->isFake() == false) && (ivtx->ndof() >= minVtxDoF_) &&
(ivtx->tracksSize() != 0))
if ((ivtx.isValid() == true) && (ivtx.isFake() == false) && (ivtx.ndof() >= minVtxDoF_) &&
(ivtx.tracksSize() != 0))
nVtx++;
}
}
// Access Trigger Results
edm::Handle<edm::TriggerResults> triggerResults;
iEvent.getByToken(hltInputTagToken_, triggerResults);
edm::Handle<edm::TriggerResults> triggerResults = iEvent.getHandle(hltInputTagToken_);
if (!triggerResults.isValid())
return;

for (std::map<std::string, PixelMEs>::iterator it = histoMap_.begin(); it != histoMap_.end(); ++it) {
std::string path = it->first;
MonitorElement* me_clus = it->second.clusME;
MonitorElement* me_vtx = it->second.vtxME;
for (const auto& it : histoMap_) {
std::string path = it.first;
MonitorElement* me_clus = it.second.clusME;
MonitorElement* me_vtx = it.second.vtxME;
unsigned int index = hltConfig_.triggerIndex(path);
if (index < triggerResults->size() && triggerResults->accept(index)) {
if (me_vtx)
Expand All @@ -162,14 +206,6 @@ void PixelVTXMonitor::analyze(edm::Event const& iEvent, edm::EventSetup const& i
}
}

void PixelVTXMonitor::endRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {}

void PixelVTXMonitor::endJob() {}
// Define this as a plug-in
#include "FWCore/Framework/interface/MakerMacros.h"
DEFINE_FWK_MODULE(PixelVTXMonitor);

// Local Variables:
// show-trailing-whitespace: t
// truncate-lines: t
// End:
75 changes: 0 additions & 75 deletions DQM/BeamMonitor/plugins/PixelVTXMonitor.h

This file was deleted.

3 changes: 2 additions & 1 deletion DQM/BeamMonitor/python/PixelVTXMonitor_cfi.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import FWCore.ParameterSet.Config as cms
from DQMServices.Core.DQMEDAnalyzer import DQMEDAnalyzer

pixelVTXMonitor = cms.EDAnalyzer("PixelVTXMonitor",
pixelVTXMonitor = DQMEDAnalyzer("PixelVTXMonitor",
ModuleName = cms.string('BeamPixel'),
FolderName = cms.string('PixelVertex'),
PixelClusterInputTag = cms.InputTag('siPixelClusters'),
Expand Down