File indexing completed on 2023-03-17 10:53:51
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <string>
0012 #include <vector>
0013 #include <map>
0014
0015
0016 #include "DQMServices/Core/interface/DQMEDAnalyzer.h"
0017 #include "DQMServices/Core/interface/DQMStore.h"
0018 #include "DataFormats/Common/interface/Handle.h"
0019 #include "DataFormats/Common/interface/TriggerResults.h"
0020 #include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h"
0021 #include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h"
0022 #include "DataFormats/VertexReco/interface/Vertex.h"
0023 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0024 #include "FWCore/Framework/interface/Event.h"
0025 #include "FWCore/Framework/interface/LuminosityBlock.h"
0026 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0027 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0028 #include "FWCore/ServiceRegistry/interface/Service.h"
0029 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
0030
0031
0032 #include "TPRegexp.h"
0033
0034
0035
0036
0037
0038 class PixelVTXMonitor : public DQMEDAnalyzer {
0039 public:
0040 typedef dqm::legacy::MonitorElement MonitorElement;
0041 typedef dqm::legacy::DQMStore DQMStore;
0042 PixelVTXMonitor(const edm::ParameterSet&);
0043 ~PixelVTXMonitor() override = default;
0044
0045 protected:
0046 void bookHistograms(DQMStore::IBooker& iBooker, const edm::Run& iRun, const edm::EventSetup& iSetup) override;
0047
0048 private:
0049 void dqmBeginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) override;
0050 void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;
0051
0052 edm::ParameterSet parameters_;
0053
0054 const std::string moduleName_;
0055 const std::string folderName_;
0056 const edm::InputTag pixelClusterInputTag_;
0057 const edm::InputTag pixelVertexInputTag_;
0058 const edm::InputTag hltInputTag_;
0059 const edm::EDGetTokenT<SiPixelClusterCollectionNew> pixelClusterInputTagToken_;
0060 const edm::EDGetTokenT<reco::VertexCollection> pixelVertexInputTagToken_;
0061 const edm::EDGetTokenT<edm::TriggerResults> hltInputTagToken_;
0062 const float minVtxDoF_;
0063
0064 HLTConfigProvider hltConfig_;
0065
0066 struct PixelMEs {
0067 MonitorElement* clusME;
0068 MonitorElement* vtxME;
0069 };
0070
0071 std::map<std::string, PixelMEs> histoMap_;
0072 };
0073
0074
0075
0076
0077
0078 PixelVTXMonitor::PixelVTXMonitor(const edm::ParameterSet& ps)
0079 : parameters_(ps),
0080 moduleName_(parameters_.getParameter<std::string>("ModuleName")),
0081 folderName_(parameters_.getParameter<std::string>("FolderName")),
0082 pixelClusterInputTag_(parameters_.getUntrackedParameter<edm::InputTag>("PixelClusterInputTag")),
0083 pixelVertexInputTag_(parameters_.getUntrackedParameter<edm::InputTag>("PixelVertexInputTag")),
0084 hltInputTag_(parameters_.getUntrackedParameter<edm::InputTag>("HLTInputTag")),
0085 pixelClusterInputTagToken_(consumes<SiPixelClusterCollectionNew>(pixelClusterInputTag_)),
0086 pixelVertexInputTagToken_(consumes<reco::VertexCollection>(pixelVertexInputTag_)),
0087 hltInputTagToken_(consumes<edm::TriggerResults>(hltInputTag_)),
0088 minVtxDoF_(parameters_.getParameter<double>("MinVtxDoF")) {}
0089
0090 void PixelVTXMonitor::bookHistograms(DQMStore::IBooker& iBooker, const edm::Run&, const edm::EventSetup&) {
0091 std::vector<std::string> hltPathsOfInterest =
0092 parameters_.getParameter<std::vector<std::string> >("HLTPathsOfInterest");
0093 if (hltPathsOfInterest.empty())
0094 return;
0095
0096 const std::vector<std::string>& pathList = hltConfig_.triggerNames();
0097 std::vector<std::string> selectedPaths;
0098 for (const auto& it : pathList) {
0099 int nmatch = 0;
0100 for (const auto& kt : hltPathsOfInterest) {
0101 nmatch += TPRegexp(kt).Match(it);
0102 }
0103 if (!nmatch)
0104 continue;
0105 else
0106 selectedPaths.push_back(it);
0107 }
0108
0109 edm::ParameterSet ClusHistoPar = parameters_.getParameter<edm::ParameterSet>("TH1ClusPar");
0110 edm::ParameterSet VtxHistoPar = parameters_.getParameter<edm::ParameterSet>("TH1VtxPar");
0111
0112 std::string currentFolder = moduleName_ + "/" + folderName_;
0113 iBooker.setCurrentFolder(currentFolder);
0114
0115 PixelMEs local_MEs;
0116 for (const auto& tag : selectedPaths) {
0117 std::map<std::string, PixelMEs>::iterator iPos = histoMap_.find(tag);
0118 if (iPos == histoMap_.end()) {
0119 std::string hname, htitle;
0120
0121 hname = "nPxlClus_";
0122 hname += tag;
0123 htitle = "# of Pixel Clusters (";
0124 htitle += tag + ")";
0125 local_MEs.clusME = iBooker.book1D(hname,
0126 htitle,
0127 ClusHistoPar.getParameter<int32_t>("Xbins"),
0128 ClusHistoPar.getParameter<double>("Xmin"),
0129 ClusHistoPar.getParameter<double>("Xmax"));
0130
0131 hname = "nPxlVtx_";
0132 hname += tag;
0133 htitle = "# of Pixel Vertices (";
0134 htitle += tag + ")";
0135 local_MEs.vtxME = iBooker.book1D(hname,
0136 htitle,
0137 VtxHistoPar.getParameter<int32_t>("Xbins"),
0138 VtxHistoPar.getParameter<double>("Xmin"),
0139 VtxHistoPar.getParameter<double>("Xmax"));
0140
0141 histoMap_.insert(std::make_pair(tag, local_MEs));
0142 }
0143 }
0144 }
0145
0146 void PixelVTXMonitor::dqmBeginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {
0147 bool changed = true;
0148 if (hltConfig_.init(iRun, iSetup, hltInputTag_.process(), changed)) {
0149
0150 edm::LogInfo("PixelVTXMonitor") << "HLT config with process name " << hltInputTag_.process()
0151 << " successfully extracted";
0152 } else {
0153
0154
0155 edm::LogError("PixelVTXMonotor") << "Error! HLT config extraction with process name " << hltInputTag_.process()
0156 << " failed";
0157
0158 }
0159 }
0160 void PixelVTXMonitor::analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) {
0161 if (histoMap_.empty())
0162 return;
0163
0164
0165 edm::Handle<SiPixelClusterCollectionNew> siPixelClusters = iEvent.getHandle(pixelClusterInputTagToken_);
0166
0167 if (!siPixelClusters.isValid()) {
0168 edm::LogError("PixelVTXMonotor") << "Could not find Cluster Collection " << pixelClusterInputTag_;
0169 return;
0170 }
0171 unsigned nClusters = siPixelClusters->size();
0172
0173
0174 edm::Handle<reco::VertexCollection> pixelVertices = iEvent.getHandle(pixelVertexInputTagToken_);
0175 if (!pixelVertices.isValid()) {
0176 edm::LogError("PixelVTXMonotor") << "Could not find Vertex Collection " << pixelVertexInputTag_;
0177 return;
0178 }
0179
0180 int nVtx = 0;
0181 for (const auto& ivtx : *pixelVertices) {
0182 if (minVtxDoF_ == -1)
0183 nVtx++;
0184 else {
0185 if ((ivtx.isValid() == true) && (ivtx.isFake() == false) && (ivtx.ndof() >= minVtxDoF_) &&
0186 (ivtx.tracksSize() != 0))
0187 nVtx++;
0188 }
0189 }
0190
0191 edm::Handle<edm::TriggerResults> triggerResults = iEvent.getHandle(hltInputTagToken_);
0192 if (!triggerResults.isValid())
0193 return;
0194
0195 for (const auto& it : histoMap_) {
0196 std::string path = it.first;
0197 MonitorElement* me_clus = it.second.clusME;
0198 MonitorElement* me_vtx = it.second.vtxME;
0199 unsigned int index = hltConfig_.triggerIndex(path);
0200 if (index < triggerResults->size() && triggerResults->accept(index)) {
0201 if (me_vtx)
0202 me_vtx->Fill(nVtx);
0203 if (me_clus)
0204 me_clus->Fill(nClusters);
0205 }
0206 }
0207 }
0208
0209
0210 #include "FWCore/Framework/interface/MakerMacros.h"
0211 DEFINE_FWK_MODULE(PixelVTXMonitor);