Skip to content

Commit

Permalink
Merge pull request #3040 from battibass/muonHltDqmConsumes
Browse files Browse the repository at this point in the history
DQMOffline/Trigger -- Consumes migration for the Muon HLT DQM
  • Loading branch information
nclopezo committed Mar 27, 2014
2 parents bc81770 + 0ac63c8 commit 3fb5781
Show file tree
Hide file tree
Showing 6 changed files with 277 additions and 97 deletions.
27 changes: 13 additions & 14 deletions DQMOffline/Trigger/interface/HLTMuonMatchAndPlot.h
Expand Up @@ -4,9 +4,7 @@
/** \class HLTMuonMatchAndPlot
* Match reconstructed muons to HLT objects and plot efficiencies.
*
* Note that this is not a true EDAnalyzer; rather, the intent is that one
* EDAnalyzer would call a separate instantiation of HLTMuonMatchAndPlot
* for each HLT path under consideration.
* Note that this is not a true EDAnalyzer;
*
* Documentation available on the CMS TWiki:
* https://twiki.cern.ch/twiki/bin/view/CMS/MuonHLTOfflinePerformance
Expand All @@ -17,25 +15,24 @@

// Base Class Headers

//#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"
//#include "DataFormats/Common/interface/RefToBase.h"
//#include "DataFormats/TrackReco/interface/Track.h"
//#include "DataFormats/Candidate/interface/Candidate.h"
#include "DataFormats/Common/interface/Handle.h"

#include "DQMServices/Core/interface/DQMStore.h"
#include "DQMServices/Core/interface/MonitorElement.h"

#include "DataFormats/HLTReco/interface/TriggerEvent.h"
#include "DataFormats/HLTReco/interface/TriggerEventWithRefs.h"
#include "DataFormats/Common/interface/TriggerResults.h"
#include "DataFormats/MuonReco/interface/Muon.h"
#include "DataFormats/MuonReco/interface/MuonFwd.h"
#include "DataFormats/VertexReco/interface/Vertex.h"
#include "DataFormats/VertexReco/interface/VertexFwd.h"
#include "DataFormats/Math/interface/LorentzVector.h"
#include "DataFormats/HLTReco/interface/TriggerObject.h"
#include "DataFormats/MuonReco/interface/Muon.h"
#include "DataFormats/BeamSpot/interface/BeamSpot.h"
#include "DataFormats/Math/interface/deltaR.h"

Expand All @@ -48,7 +45,6 @@
#include "TPRegexp.h"



//////////////////////////////////////////////////////////////////////////////
//////// Typedefs and Constants //////////////////////////////////////////////

Expand All @@ -59,9 +55,10 @@ const std::string EFFICIENCY_SUFFIXES[2] = {"denom", "numer"};


//////////////////////////////////////////////////////////////////////////////
//////// Class Definition ////////////////////////////////////////////////////
//////// HLTMuonMatchAndPlot Class Definition ////////////////////////////////

class HLTMuonMatchAndPlot {
class HLTMuonMatchAndPlot
{

public:

Expand All @@ -71,7 +68,9 @@ class HLTMuonMatchAndPlot {

// Analyzer Methods
void beginRun(const edm::Run &, const edm::EventSetup &);
void analyze(const edm::Event &, const edm::EventSetup &);
void analyze(edm::Handle<reco::MuonCollection> &, edm::Handle<reco::BeamSpot> &,
edm::Handle<reco::VertexCollection> &, edm::Handle<trigger::TriggerEvent> &,
edm::Handle<edm::TriggerResults> &);
void endRun(const edm::Run &, const edm::EventSetup &);

// Helper Methods
Expand All @@ -81,7 +80,7 @@ class HLTMuonMatchAndPlot {
template <class T1, class T2> std::vector<size_t>
matchByDeltaR(const std::vector<T1> &, const std::vector<T2> &,
const double maxDeltaR = NOMATCH);

private:

// Internal Methods
Expand All @@ -102,7 +101,6 @@ class HLTMuonMatchAndPlot {
std::string hltProcessName_;
std::string destination_;
std::vector<std::string> requiredTriggers_;
std::map<std::string, edm::InputTag> inputTags_;
std::map<std::string, std::vector<double> > binParams_;
std::map<std::string, double> plotCuts_;
edm::ParameterSet targetParams_;
Expand All @@ -126,6 +124,7 @@ class HLTMuonMatchAndPlot {
StringCutObjectSelector<reco::Muon> probeMuonSelector_;
double probeZ0Cut_;
double probeD0Cut_;

};

#endif
79 changes: 79 additions & 0 deletions DQMOffline/Trigger/interface/HLTMuonMatchAndPlotContainer.h
@@ -0,0 +1,79 @@
#ifndef DQMOffline_Trigger_HLTMuonMatchAndPlotContainer_H
#define DQMOffline_Trigger_HLTMuonMatchAndPlotContainer_H

/** \class HLTMuonMatchAndPlot
* Contanier class to handle vector of reconstructed muons matched to
* HLT objects used to plot efficiencies.
*
* Note that this is not a true EDAnalyzer; rather, the intent is that one
* EDAnalyzer would call an instance of HLTMuonMatchAndPlotContainer
*
* Documentation available on the CMS TWiki:
* https://twiki.cern.ch/twiki/bin/view/CMS/MuonHLTOfflinePerformance
*
*
* \author C. Battilana
*/

// Base Class Headers

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"

#include "DQMOffline/Trigger/interface/HLTMuonMatchAndPlot.h"

#include "DataFormats/HLTReco/interface/TriggerEvent.h"
#include "DataFormats/HLTReco/interface/TriggerEventWithRefs.h"
#include "DataFormats/Common/interface/TriggerResults.h"
#include "DataFormats/MuonReco/interface/Muon.h"
#include "DataFormats/MuonReco/interface/MuonFwd.h"
#include "DataFormats/VertexReco/interface/Vertex.h"
#include "DataFormats/VertexReco/interface/VertexFwd.h"
#include "DataFormats/BeamSpot/interface/BeamSpot.h"
#include "DataFormats/Math/interface/deltaR.h"

#include<vector>
#include<string>


//////////////////////////////////////////////////////////////////////////////
///Container Class Definition (this is what is used by the DQM module) ///////

class HLTMuonMatchAndPlotContainer
{

public:

/// Constructor
HLTMuonMatchAndPlotContainer(edm::ConsumesCollector &&, const edm::ParameterSet &);

/// Destructor
~HLTMuonMatchAndPlotContainer() { plotters_.clear(); };

/// Add a HLTMuonMatchAndPlot for a given path
void addPlotter(const edm::ParameterSet &, std::string,
const std::vector<std::string>&);

// Analyzer Methods
void beginRun(const edm::Run &, const edm::EventSetup &);
void analyze(const edm::Event &, const edm::EventSetup &);
void endRun(const edm::Run &, const edm::EventSetup &);

private:

std::vector<HLTMuonMatchAndPlot> plotters_;

edm::EDGetTokenT<reco::BeamSpot> bsToken_;
edm::EDGetTokenT<reco::MuonCollection> muonToken_;
edm::EDGetTokenT<reco::VertexCollection> pvToken_;

edm::EDGetTokenT<trigger::TriggerEvent> trigSummaryToken_;
edm::EDGetTokenT<edm::TriggerResults> trigResultsToken_;

};

#endif


3 changes: 2 additions & 1 deletion DQMOffline/Trigger/python/HLTMuonOfflineAnalyzer_cfi.py
Expand Up @@ -48,8 +48,9 @@
inputTags = cms.PSet(
recoMuon = cms.InputTag("muons"),
beamSpot = cms.InputTag("offlineBeamSpot"),
offlinePVs = cms.InputTag("offlinePrimaryVertices"),
triggerSummary = cms.InputTag("hltTriggerSummaryAOD"),
triggerResults = cms.InputTag("TriggerResults"),
triggerResults = cms.InputTag("TriggerResults")
),

## Both 1D and 2D plots use the binnings defined here
Expand Down
73 changes: 19 additions & 54 deletions DQMOffline/Trigger/src/HLTMuonMatchAndPlot.cc
Expand Up @@ -11,14 +11,7 @@
#include "SimDataFormats/GeneratorProducts/interface/GenRunInfoProduct.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/HLTReco/interface/TriggerEventWithRefs.h"
#include "DataFormats/HLTReco/interface/TriggerEvent.h"
#include "DataFormats/Candidate/interface/CandMatchMap.h"
#include "DataFormats/BeamSpot/interface/BeamSpot.h"
#include "DataFormats/VertexReco/interface/Vertex.h"
#include "DataFormats/Common/interface/TriggerResults.h"
#include "DataFormats/VertexReco/interface/VertexFwd.h"

#include <iostream>

Expand All @@ -35,7 +28,7 @@ typedef std::vector<std::string> vstring;


//////////////////////////////////////////////////////////////////////////////
//////// Class Members ///////////////////////////////////////////////////////
//////// HLTMuonMatchAndPlot Class Members ///////////////////////////////////

/// Constructor
HLTMuonMatchAndPlot::HLTMuonMatchAndPlot(const ParameterSet & pset,
Expand All @@ -59,16 +52,9 @@ HLTMuonMatchAndPlot::HLTMuonMatchAndPlot(const ParameterSet & pset,
{

// Create std::map<string, T> from ParameterSets.
fillMapFromPSet(inputTags_, pset, "inputTags");
fillMapFromPSet(binParams_, pset, "binParams");
fillMapFromPSet(plotCuts_, pset, "plotCuts");

// Set HLT process name for TriggerResults and TriggerSummary.
InputTag & resTag = inputTags_["triggerResults"];
resTag = InputTag(resTag.label(), resTag.instance(), hltProcessName_);
InputTag & sumTag = inputTags_["triggerSummary"];
sumTag = InputTag(sumTag.label(), sumTag.instance(), hltProcessName_);

// Prepare the DQMStore object.
dbe_ = edm::Service<DQMStore>().operator->();
dbe_->setVerbose(0);
Expand All @@ -93,6 +79,7 @@ HLTMuonMatchAndPlot::HLTMuonMatchAndPlot(const ParameterSet & pset,
cutMinPt_ = ceil(cutMinPt_ * plotCuts_["minPtFactor"]);
}
delete objArray;

}

void HLTMuonMatchAndPlot::beginRun(const edm::Run& iRun,
Expand Down Expand Up @@ -155,48 +142,18 @@ void HLTMuonMatchAndPlot::beginRun(const edm::Run& iRun,
void HLTMuonMatchAndPlot::endRun(const edm::Run& iRun,
const edm::EventSetup& iSetup)
{
}

}


void HLTMuonMatchAndPlot::analyze(const Event & iEvent,
const edm::EventSetup& iSetup)

void HLTMuonMatchAndPlot::analyze(Handle<MuonCollection> & allMuons,
Handle<BeamSpot> & beamSpot,
Handle<VertexCollection> & vertices,
Handle<TriggerEvent> & triggerSummary,
Handle<TriggerResults> & triggerResults)
{

// Get objects from the event.
Handle<MuonCollection> allMuons;
iEvent.getByLabel(inputTags_["recoMuon"], allMuons);

Handle<BeamSpot> beamSpot;
iEvent.getByLabel(inputTags_["beamSpot"], beamSpot);

Handle<TriggerEvent> triggerSummary;
iEvent.getByLabel(inputTags_["triggerSummary"], triggerSummary);
Handle<TriggerResults> triggerResults;

edm::Handle<VertexCollection> vertices;
iEvent.getByLabel("offlinePrimaryVertices", vertices);

//edm::Handle<GenParticleCollection> gen;
//iEvent.getByLabel("genParticles", gen);
//GenParticleCollection::const_iterator g_part;
//std::vector<const GenParticle *> gen_leptsp;
//std::vector<const GenParticle *> gen_momsp;


if(!triggerSummary.isValid())
{
edm::LogError("HLTMuonMatchAndPlot")<<"Missing triggerSummary with label " << inputTags_["triggerSummary"] <<std::endl;
return;
}
iEvent.getByLabel(inputTags_["triggerResults"], triggerResults);
if(!triggerResults.isValid())
{
edm::LogError("HLTMuonMatchAndPlot")<<"Missing triggerResults with label " << inputTags_["triggerResults"] <<std::endl;
return;
}

/*
if(gen != 0) {
for(g_part = gen->begin(); g_part != gen->end(); g_part++){
Expand Down Expand Up @@ -380,7 +337,8 @@ void HLTMuonMatchAndPlot::analyze(const Event & iEvent,
// Method to fill binning parameters from a vector of doubles.
void
HLTMuonMatchAndPlot::fillEdges(size_t & nBins, float * & edges,
const vector<double>& binning) {
const vector<double>& binning)
{

if (binning.size() < 3) {
LogWarning("HLTMuonVal") << "Invalid binning parameters!";
Expand Down Expand Up @@ -413,7 +371,8 @@ HLTMuonMatchAndPlot::fillEdges(size_t & nBins, float * & edges,
template <class T>
void
HLTMuonMatchAndPlot::fillMapFromPSet(map<string, T> & m,
const ParameterSet& pset, string target) {
const ParameterSet& pset, string target)
{

// Get the ParameterSet with name 'target' from 'pset'
ParameterSet targetPset;
Expand Down Expand Up @@ -442,7 +401,8 @@ template <class T1, class T2>
vector<size_t>
HLTMuonMatchAndPlot::matchByDeltaR(const vector<T1> & collection1,
const vector<T2> & collection2,
const double maxDeltaR) {
const double maxDeltaR)
{

const size_t n1 = collection1.size();
const size_t n2 = collection2.size();
Expand Down Expand Up @@ -490,6 +450,7 @@ HLTMuonMatchAndPlot::selectedMuons(const MuonCollection & allMuons,
const StringCutObjectSelector<reco::Muon> &selector,
double d0Cut, double z0Cut)
{

// If there is no selector (recoCuts does not exists), return an empty collection.
if (!hasRecoCuts)
return MuonCollection();
Expand Down Expand Up @@ -550,6 +511,7 @@ HLTMuonMatchAndPlot::selectedTriggerObjects(

void HLTMuonMatchAndPlot::book1D(string name, string binningType, string title)
{

/* Properly delete the array of floats that has been allocated on
* the heap by fillEdges. Avoid multiple copies and internal ROOT
* clones by simply creating the histograms directly in the DQMStore
Expand All @@ -567,6 +529,7 @@ void HLTMuonMatchAndPlot::book1D(string name, string binningType, string title)

if (edges)
delete [] edges;

}


Expand Down Expand Up @@ -600,5 +563,7 @@ HLTMuonMatchAndPlot::book2D(string name, string binningTypeX,
delete [] edgesX;
if (edgesY)
delete [] edgesY;

}


0 comments on commit 3fb5781

Please sign in to comment.