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

DQM TriggerMatch Monitor to Watch the Trigger matching feature in pat::Muon #24936

Closed
wants to merge 1 commit into from
Closed
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
79 changes: 79 additions & 0 deletions DQMOffline/Muon/interface/TriggerMatchMonitor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#ifndef TriggerMatchMonitor_H
#define TriggerMatchMonitor_H
/** \class MuRecoAnalyzer
*
* DQM monitoring source for Trigger matching feature added to miniAOD
*
* \author Bibhuprasad Mahakud (Purdue University, West Lafayette, USA)
*/

#include <memory>
#include <fstream>
#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/ServiceRegistry/interface/Service.h"
#include "DQMServices/Core/interface/DQMStore.h"
#include "DQMServices/Core/interface/MonitorElement.h"
#include "DQMServices/Core/interface/DQMEDAnalyzer.h"

#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/MuonReco/interface/Muon.h"
#include "DataFormats/MuonReco/interface/MuonFwd.h"
#include "DataFormats/MuonReco/interface/MuonEnergy.h"
#include "DataFormats/BeamSpot/interface/BeamSpot.h"
#include "DataFormats/VertexReco/interface/Vertex.h"
#include "DataFormats/VertexReco/interface/VertexFwd.h"
#include "DataFormats/TrackReco/interface/Track.h"
#include "DataFormats/TrackReco/interface/TrackFwd.h"
#include "DataFormats/MuonReco/interface/MuonSelectors.h"
#include "RecoMuon/TrackingTools/interface/MuonServiceProxy.h"
#include "FWCore/Common/interface/TriggerNames.h"
#include "DataFormats/Common/interface/TriggerResults.h"
#include "DataFormats/HLTReco/interface/TriggerEvent.h"
#include "DataFormats/PatCandidates/interface/Muon.h"
#include "DataFormats/PatCandidates/interface/TriggerObjectStandAlone.h"


class TriggerMatchMonitor : public DQMEDAnalyzer {
public:

/// Constructor
TriggerMatchMonitor(const edm::ParameterSet& pSet);

/// Destructor
~TriggerMatchMonitor() override;

void analyze(const edm::Event&, const edm::EventSetup&) override;
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;

private:

// ----------member data ---------------------------
MuonServiceProxy *theService;
DQMStore* theDbe;
edm::ParameterSet parameters;

// Switch for verbosity
std::string metname;

//Vertex requirements
edm::EDGetTokenT<edm::View<reco::Muon> > theMuonCollectionLabel_;
edm::EDGetTokenT<edm::View<pat::Muon> > thePATMuonCollectionLabel_;
edm::EDGetTokenT<reco::VertexCollection> theVertexLabel_;
edm::EDGetTokenT<reco::BeamSpot> theBeamSpotLabel_;
edm::EDGetTokenT<edm::TriggerResults > triggerResultsToken_;
edm::EDGetTokenT<std::vector<pat::TriggerObjectStandAlone>> triggerObjects_;

edm::EDGetTokenT<reco::BeamSpot > beamSpotToken_;
edm::EDGetTokenT<std::vector<reco::Vertex> > primaryVerticesToken_;



// global muon
std::vector<MonitorElement*> matchHists;

std::string theFolder;
};
#endif
1 change: 1 addition & 0 deletions DQMOffline/Muon/python/muonAnalyzer_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

muonAnalyzer_miniAOD = cms.Sequence(muonRecoAnalyzer_miniAOD*
muonKinVsEtaAnalyzer_miniAOD*
triggerMatchMonitor_miniAOD*
diMuonHistos_miniAOD*
LooseMuonEfficiencyAnalyzer_miniAOD*
MediumMuonEfficiencyAnalyzer_miniAOD*
Expand Down
32 changes: 32 additions & 0 deletions DQMOffline/Muon/python/triggerMatchMonitor_cfi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import FWCore.ParameterSet.Config as cms

from RecoMuon.TrackingTools.MuonServiceProxy_cff import *

from DQMServices.Core.DQMEDAnalyzer import DQMEDAnalyzer
triggerMatchMonitor = DQMEDAnalyzer('TriggerMatchMonitor',
MuonServiceProxy,

MuonCollection = cms.InputTag("muons"),
VertexLabel = cms.InputTag("offlinePrimaryVertices"),
BeamSpotLabel = cms.InputTag("offlineBeamSpot"),

etaBin = cms.int32(100),
etaMin = cms.double(-3.0),
etaMax = cms.double(3.0),

folder = cms.string("Muons/TriggerMatchMonitor")
)
triggerMatchMonitor_miniAOD = DQMEDAnalyzer('TriggerMatchMonitor',
MuonServiceProxy,
offlineBeamSpot = cms.untracked.InputTag("offlineBeamSpot"),
offlinePrimaryVertices = cms.untracked.InputTag("offlinePrimaryVertices"),
MuonCollection = cms.InputTag("slimmedMuons"),
patMuonCollection = cms.InputTag("slimmedMuons"),
VertexLabel = cms.InputTag("offlineSlimmedPrimaryVertices"),
BeamSpotLabel = cms.InputTag("offlineBeamSpot"),
triggerResults = cms.untracked.InputTag("TriggerResults","","HLT"),
triggerObjects = cms.InputTag("slimmedPatTrigger"),
hltCollectionFilters = cms.vstring('*'),
triggerNameList = cms.vstring('HLT_Mu27_v*'),
folder = cms.string("Muons_miniAOD/TriggerMatchMonitor")
)
2 changes: 1 addition & 1 deletion DQMOffline/Muon/src/SealModule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ DEFINE_FWK_MODULE(SegmentTrackAnalyzer);
DEFINE_FWK_MODULE(MuonEnergyDepositAnalyzer);
DEFINE_FWK_MODULE(MuonSeedsAnalyzer);
DEFINE_FWK_MODULE(MuonMiniAOD);

DEFINE_FWK_MODULE(TriggerMatchMonitor);



171 changes: 171 additions & 0 deletions DQMOffline/Muon/src/TriggerMatchMonitor.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
/*
* See header file for a description of this class.
*
* \author Bibhuprasad Mahakud (Purdue University, West Lafayette, USA)
*/
#include "DQMOffline/Muon/interface/TriggerMatchMonitor.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "DQMServices/Core/interface/DQMStore.h"
#include "DQMServices/Core/interface/MonitorElement.h"
#include "DataFormats/Common/interface/TriggerResults.h"
#include "FWCore/Common/interface/TriggerNames.h"
#include "TLorentzVector.h"

#include <string>
#include <TMath.h>
using namespace std;
using namespace edm;

//#define DEBUG

TriggerMatchMonitor::TriggerMatchMonitor(const edm::ParameterSet& pSet) {
LogTrace(metname)<<"[TriggerMatchMonitor] Parameters initialization";

parameters = pSet;

// the services
theService = new MuonServiceProxy(parameters.getParameter<ParameterSet>("ServiceParameters"));
theDbe = edm::Service<DQMStore>().operator->();

beamSpotToken_ = consumes<reco::BeamSpot >(parameters.getUntrackedParameter<edm::InputTag>("offlineBeamSpot")),
primaryVerticesToken_ = consumes<std::vector<reco::Vertex> >(parameters.getUntrackedParameter<edm::InputTag>("offlinePrimaryVertices")),
theMuonCollectionLabel_ = consumes<edm::View<reco::Muon> > (parameters.getParameter<edm::InputTag>("MuonCollection"));
thePATMuonCollectionLabel_ = consumes<edm::View<pat::Muon> > (parameters.getParameter<edm::InputTag>("patMuonCollection"));
theVertexLabel_ = consumes<reco::VertexCollection>(parameters.getParameter<edm::InputTag>("VertexLabel"));
theBeamSpotLabel_ = mayConsume<reco::BeamSpot> (parameters.getParameter<edm::InputTag>("BeamSpotLabel"));
triggerResultsToken_ = consumes<edm::TriggerResults>(parameters.getUntrackedParameter<edm::InputTag>("triggerResults"));
triggerObjects_ = consumes<std::vector<pat::TriggerObjectStandAlone>>(parameters.getParameter<edm::InputTag>("triggerObjects"));

// Parameters

theFolder = parameters.getParameter<string>("folder");
}
TriggerMatchMonitor::~TriggerMatchMonitor() {
delete theService;
}

void TriggerMatchMonitor::bookHistograms(DQMStore::IBooker & ibooker,
edm::Run const & /*iRun*/,
edm::EventSetup const& /*iSetup*/){
ibooker.cd();
ibooker.setCurrentFolder(theFolder);

// monitoring of eta parameter
matchHists.push_back(ibooker.book1D("DelEta_HLT_IsoMu24", "DeltaEta_HLT_IsoMu24", 600, 0.0, 6.0));
matchHists.push_back(ibooker.book1D("DelPhi_HLT_IsoMu24", "DeltaPhi_HLT_IsoMu24", 600, 0.0, 6.0));
matchHists.push_back(ibooker.book1D("DelR_HLT_IsoMu24", "DeltaR_HLT_IsoMu24", 600, 0.0, 6.0));
matchHists.push_back(ibooker.book1D("DelEta_L1_IsoMu24", "DeltaEta_L1_IsoMu24", 600, 0.0, 6.0));
matchHists.push_back(ibooker.book1D("DelPhi_L1_IsoMu24", "DeltaPhi_L1_IsoMu24", 600, 0.0, 6.0));
matchHists.push_back(ibooker.book1D("DelR_L1_IsoMu24", "DeltaR_L1_IsoMu24", 600, 0.0, 6.0));
matchHists.push_back(ibooker.book1D("PtDiff_HLT_IsoMu24", "PtDiff_HLT_IsoMu24", 400, -500., 500.0));
matchHists.push_back(ibooker.book1D("PtDiff_L1_IsoMu24", "PtDiff_L1_IsoMu24", 400, -500., 500.0));




}
void TriggerMatchMonitor::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup){

LogTrace(metname)<<"[TriggerMatchMonitor] Analyze the mu in different eta regions";
theService->update(iSetup);

edm::Handle<edm::View<reco::Muon> > muons;
iEvent.getByToken(theMuonCollectionLabel_,muons);

edm::Handle<edm::View<pat::Muon> > PATmuons;
iEvent.getByToken(thePATMuonCollectionLabel_,PATmuons);

edm::Handle<std::vector<pat::TriggerObjectStandAlone> > triggerObjects;
iEvent.getByToken(triggerObjects_, triggerObjects);

Handle<edm::TriggerResults> triggerResults;
iEvent.getByToken(triggerResultsToken_, triggerResults);


reco::Vertex::Point posVtx;
reco::Vertex::Error errVtx;
Handle<std::vector<reco::Vertex> > recVtxs;
iEvent.getByToken(primaryVerticesToken_,recVtxs);
unsigned int theIndexOfThePrimaryVertex = 999.;
for (unsigned int ind = 0; ind < recVtxs->size(); ++ind) {
if ( (*recVtxs)[ind].isValid() && !((*recVtxs)[ind].isFake()) ) {
theIndexOfThePrimaryVertex = ind;
break;
}
}
if (theIndexOfThePrimaryVertex<100) {
posVtx = ((*recVtxs)[theIndexOfThePrimaryVertex]).position();
errVtx = ((*recVtxs)[theIndexOfThePrimaryVertex]).error();
}
else {
LogInfo("RecoMuonValidator") << "reco::PrimaryVertex not found, use BeamSpot position instead\n";
Handle<reco::BeamSpot> recoBeamSpotHandle;
iEvent.getByToken(beamSpotToken_,recoBeamSpotHandle);
reco::BeamSpot bs = *recoBeamSpotHandle;
posVtx = bs.position();
errVtx(0,0) = bs.BeamWidthX();
errVtx(1,1) = bs.BeamWidthY();
errVtx(2,2) = bs.sigmaZ();
}
const reco::Vertex thePrimaryVertex(posVtx,errVtx);





const edm::TriggerNames& trigNames = iEvent.triggerNames(*triggerResults);

if(PATmuons.isValid()){//valid pat Muon

for( auto & patMuon : *PATmuons){//pat muon loop
bool Isolated=patMuon.pfIsolationR04().sumChargedHadronPt + TMath::Max(0., patMuon.pfIsolationR04().sumNeutralHadronEt + patMuon.pfIsolationR04().sumPhotonEt - 0.5*patMuon.pfIsolationR04().sumPUPt) / patMuon.pt() < 0.25;


if(patMuon.isGlobalMuon() && Isolated && patMuon.isTightMuon(thePrimaryVertex)){//isolated tight muon

TLorentzVector offlineMuon;
offlineMuon.SetPtEtaPhiM(patMuon.pt(), patMuon.eta(), patMuon.phi(),0.0);

char array[] = "HLT_IsoMu24_v*"; // modifiable array of 5 bytes
char *ptr; // array can be modified via p
ptr = array; // array cannot be modified via q

if(patMuon.triggered(ptr)){

try{


matchHists[0]->Fill(patMuon.eta()-patMuon.hltObject()->eta());
matchHists[1]->Fill(patMuon.phi()-patMuon.hltObject()->phi());
matchHists[6]->Fill(patMuon.pt()-patMuon.hltObject()->pt());
TLorentzVector hltMuon;
hltMuon.SetPtEtaPhiM(patMuon.hltObject()->pt(),patMuon.hltObject()->eta(),patMuon.hltObject()->phi(),0.0);

double DelRrecoHLT=offlineMuon.DeltaR(hltMuon);

matchHists[2]->Fill(DelRrecoHLT);

if(patMuon.l1Object() !=nullptr){
matchHists[3]->Fill(patMuon.eta()-patMuon.l1Object()->eta());
matchHists[4]->Fill(patMuon.phi()-patMuon.l1Object()->phi());

matchHists[7]->Fill(patMuon.pt()-patMuon.l1Object()->pt());

}

}catch(...){}

}

}//isolated tight muon
} //pat muon loop
} //valid pat muon








}