Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:13:39

0001 /** \file DQMOffline/Trigger/HLTMuonMatchAndPlotContainer.cc
0002  *
0003  */
0004 
0005 #include <utility>
0006 
0007 #include "DQMOffline/Trigger/interface/HLTMuonMatchAndPlotContainer.h"
0008 
0009 //////////////////////////////////////////////////////////////////////////////
0010 //////// Namespaces and Typedefs /////////////////////////////////////////////
0011 
0012 using namespace std;
0013 using namespace edm;
0014 using namespace reco;
0015 using namespace trigger;
0016 
0017 //////////////////////////////////////////////////////////////////////////////
0018 ///Container Class Members (this is what is used by the DQM module) //////////
0019 
0020 /// Constructor
0021 HLTMuonMatchAndPlotContainer::HLTMuonMatchAndPlotContainer(ConsumesCollector&& iC, const ParameterSet& pset) {
0022   plotters_.clear();
0023 
0024   string hltProcessName = pset.getParameter<string>("hltProcessName");
0025 
0026   ParameterSet inputTags = pset.getParameter<ParameterSet>("inputTags");
0027 
0028   InputTag resTag = inputTags.getParameter<InputTag>("triggerResults");
0029   InputTag sumTag = inputTags.getParameter<InputTag>("triggerSummary");
0030   resTag = InputTag(resTag.label(), resTag.instance(), hltProcessName);
0031   sumTag = InputTag(sumTag.label(), sumTag.instance(), hltProcessName);
0032 
0033   trigSummaryToken_ = iC.consumes<TriggerEvent>(sumTag);
0034   trigResultsToken_ = iC.consumes<TriggerResults>(resTag);
0035 
0036   bsToken_ = iC.consumes<BeamSpot>(inputTags.getParameter<InputTag>("beamSpot"));
0037   muonToken_ = iC.consumes<MuonCollection>(inputTags.getParameter<InputTag>("recoMuon"));
0038   pvToken_ = iC.consumes<VertexCollection>(inputTags.getParameter<InputTag>("offlinePVs"));
0039 }
0040 
0041 /// Add a HLTMuonMatchAndPlot for a given path
0042 void HLTMuonMatchAndPlotContainer::addPlotter(const edm::ParameterSet& pset,
0043                                               std::string path,
0044                                               std::string label,
0045                                               bool islastfilter) {
0046   plotters_.emplace_back(pset, std::move(path), std::move(label), islastfilter);
0047 }
0048 
0049 void HLTMuonMatchAndPlotContainer::beginRun(DQMStore::IBooker& iBooker,
0050                                             const edm::Run& iRun,
0051                                             const edm::EventSetup& iSetup) {
0052   auto iter = plotters_.begin();
0053   auto end = plotters_.end();
0054 
0055   for (; iter != end; ++iter) {
0056     iter->beginRun(iBooker, iRun, iSetup);
0057   }
0058 }
0059 
0060 void HLTMuonMatchAndPlotContainer::endRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
0061   auto iter = plotters_.begin();
0062   auto end = plotters_.end();
0063 
0064   for (; iter != end; ++iter) {
0065     iter->endRun(iRun, iSetup);
0066   }
0067 }
0068 
0069 void HLTMuonMatchAndPlotContainer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0070   // Get objects from the event.
0071   Handle<TriggerEvent> triggerSummary;
0072   iEvent.getByToken(trigSummaryToken_, triggerSummary);
0073 
0074   if (!triggerSummary.isValid()) {
0075     LogError("HLTMuonMatchAndPlot") << "Missing triggerSummary collection" << endl;
0076     return;
0077   }
0078 
0079   Handle<TriggerResults> triggerResults;
0080   iEvent.getByToken(trigResultsToken_, triggerResults);
0081   const edm::TriggerNames& trigNames = iEvent.triggerNames(*triggerResults);
0082 
0083   if (!triggerResults.isValid()) {
0084     LogError("HLTMuonMatchAndPlot") << "Missing triggerResults collection" << endl;
0085     return;
0086   }
0087 
0088   Handle<MuonCollection> allMuons;
0089   iEvent.getByToken(muonToken_, allMuons);
0090 
0091   if (!allMuons.isValid()) {
0092     LogError("HLTMuonMatchAndPlot") << "Missing muon collection " << endl;
0093     return;
0094   }
0095 
0096   Handle<BeamSpot> beamSpot;
0097   iEvent.getByToken(bsToken_, beamSpot);
0098 
0099   if (!beamSpot.isValid()) {
0100     LogError("HLTMuonMatchAndPlot") << "Missing beam spot collection " << endl;
0101     return;
0102   }
0103 
0104   Handle<VertexCollection> vertices;
0105   iEvent.getByToken(pvToken_, vertices);
0106 
0107   if (!vertices.isValid()) {
0108     LogError("HLTMuonMatchAndPlot") << "Missing vertices collection " << endl;
0109     return;
0110   }
0111 
0112   auto iter = plotters_.begin();
0113   auto end = plotters_.end();
0114 
0115   for (; iter != end; ++iter) {
0116     iter->analyze(allMuons, beamSpot, vertices, triggerSummary, triggerResults, trigNames);
0117   }
0118 }