Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /*
0002  *  See header file for a description of this class.
0003  *
0004  *  \author Bibhuprasad Mahakud (Purdue University, West Lafayette, USA)
0005  */
0006 #include "DQMOffline/Muon/interface/TriggerMatchMonitor.h"
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 #include "DQMServices/Core/interface/DQMStore.h"
0009 #include "DataFormats/Common/interface/TriggerResults.h"
0010 #include "FWCore/Common/interface/TriggerNames.h"
0011 #include "TLorentzVector.h"
0012 
0013 #include <string>
0014 #include <TMath.h>
0015 using namespace std;
0016 using namespace edm;
0017 
0018 //#define DEBUG
0019 
0020 TriggerMatchMonitor::TriggerMatchMonitor(const edm::ParameterSet& pSet) {
0021   LogTrace("TriggerMatching") << "[TriggerMatchMonitor] Parameters initialization";
0022 
0023   parameters = pSet;
0024 
0025   beamSpotToken_ = consumes<reco::BeamSpot>(parameters.getUntrackedParameter<edm::InputTag>("offlineBeamSpot")),
0026   primaryVerticesToken_ =
0027       consumes<std::vector<reco::Vertex>>(parameters.getUntrackedParameter<edm::InputTag>("offlinePrimaryVertices")),
0028   theMuonCollectionLabel_ = consumes<edm::View<reco::Muon>>(parameters.getParameter<edm::InputTag>("MuonCollection"));
0029   thePATMuonCollectionLabel_ =
0030       consumes<edm::View<pat::Muon>>(parameters.getParameter<edm::InputTag>("patMuonCollection"));
0031   theVertexLabel_ = consumes<reco::VertexCollection>(parameters.getParameter<edm::InputTag>("VertexLabel"));
0032   theBeamSpotLabel_ = mayConsume<reco::BeamSpot>(parameters.getParameter<edm::InputTag>("BeamSpotLabel"));
0033   triggerResultsToken_ =
0034       consumes<edm::TriggerResults>(parameters.getUntrackedParameter<edm::InputTag>("triggerResults"));
0035   triggerObjects_ =
0036       consumes<std::vector<pat::TriggerObjectStandAlone>>(parameters.getParameter<edm::InputTag>("triggerObjects"));
0037 
0038   triggerPathName1_ = parameters.getParameter<string>("triggerPathName1");
0039   triggerHistName1_ = parameters.getParameter<string>("triggerHistName1");
0040   triggerPtThresholdPath1_ = parameters.getParameter<double>("triggerPtThresholdPath1");
0041   triggerPathName2_ = parameters.getParameter<string>("triggerPathName2");
0042   triggerHistName2_ = parameters.getParameter<string>("triggerHistName2");
0043   triggerPtThresholdPath2_ = parameters.getParameter<double>("triggerPtThresholdPath2");
0044   theFolder = parameters.getParameter<string>("folder");
0045 }
0046 TriggerMatchMonitor::~TriggerMatchMonitor() {}
0047 
0048 void TriggerMatchMonitor::bookHistograms(DQMStore::IBooker& ibooker,
0049                                          edm::Run const& /*iRun*/,
0050                                          edm::EventSetup const& /*iSetup*/) {
0051   ibooker.cd();
0052   ibooker.setCurrentFolder(theFolder);
0053 
0054   // monitoring of trigger match parameter
0055 
0056   matchHists.push_back(ibooker.book1D("DelR_HLT_" + triggerHistName1_ + "_v1",
0057                                       "DeltaR_(offline,HLT)_triggerPass(" + triggerHistName1_ + ")",
0058                                       500,
0059                                       0.0,
0060                                       0.5));
0061   matchHists.push_back(ibooker.book1D("DelR_HLT_" + triggerHistName1_ + "_v2",
0062                                       "DeltaR_(offline,HLT)_triggerPass(" + triggerHistName1_ + ")",
0063                                       100,
0064                                       0.5,
0065                                       1.5));
0066   matchHists.push_back(ibooker.book1D(
0067       "PtRatio_HLT_" + triggerHistName1_, "PtRatio_(HLTPt/OfflinePt)_" + triggerHistName1_, 200, -5., 5.0));
0068 
0069   matchHists.push_back(ibooker.book1D("DelR_L1_" + triggerHistName1_ + "_v1",
0070                                       "DeltaR_(offline, L1)_triggerPass(" + triggerHistName1_ + ")",
0071                                       500,
0072                                       0.0,
0073                                       1.0));
0074   matchHists.push_back(ibooker.book1D("DelR_L1_" + triggerHistName1_ + "_v2",
0075                                       "DeltaR_(offline, L1)_triggerPass(" + triggerHistName1_ + ")",
0076                                       500,
0077                                       0.0,
0078                                       2.0));
0079   matchHists.push_back(ibooker.book1D(
0080       "PtRatio_L1_" + triggerHistName1_, "PtRatio_(HLTPt/OfflinePt)_" + triggerHistName1_, 200, -5., 5.0));
0081 
0082   matchHists.push_back(ibooker.book1D("DelR_HLT_" + triggerHistName2_ + "_v1",
0083                                       "DeltaR_(offline,HLT)_triggerPass(" + triggerHistName2_ + ")",
0084                                       500,
0085                                       0.0,
0086                                       0.5));
0087   matchHists.push_back(ibooker.book1D("DelR_HLT_" + triggerHistName2_ + "_v2",
0088                                       "DeltaR_(offline,HLT)_triggerPass(" + triggerHistName2_ + ")",
0089                                       100,
0090                                       0.5,
0091                                       1.5));
0092   matchHists.push_back(ibooker.book1D(
0093       "PtRatio_HLT_" + triggerHistName2_, "PtRatio_(HLTPt/OfflinePt)_" + triggerHistName2_, 200, -5., 5.0));
0094 
0095   matchHists.push_back(ibooker.book1D("DelR_L1_" + triggerHistName2_ + "_v1",
0096                                       "DeltaR_(offline, L1)_triggerPass(" + triggerHistName2_ + ")",
0097                                       250,
0098                                       0.0,
0099                                       0.5));
0100   matchHists.push_back(ibooker.book1D("DelR_L1_" + triggerHistName2_ + "_v2",
0101                                       "DeltaR_(offline, L1)_triggerPass(" + triggerHistName2_ + ")",
0102                                       100,
0103                                       0.5,
0104                                       1.5));
0105   matchHists.push_back(ibooker.book1D(
0106       "PtRatio_L1_" + triggerHistName2_, "PtRatio_(HLTPt/OfflinePt)_" + triggerHistName2_, 200, -5., 5.0));
0107 
0108   ibooker.cd();
0109   ibooker.setCurrentFolder(theFolder + "/EfficiencyInput");
0110 
0111   h_passHLTPath1_eta_Tight = ibooker.book1D(
0112       "passHLT" + triggerHistName1_ + "_eta_Tight", " HLT(" + triggerHistName1_ + ") pass #eta", 8, -2.5, 2.5);
0113   h_passHLTPath1_pt_Tight = ibooker.book1D(
0114       "passHLT" + triggerHistName1_ + "_pt_Tight", " HLT(" + triggerHistName1_ + ") pass pt", 10, 20, 220);
0115   h_passHLTPath1_phi_Tight = ibooker.book1D(
0116       "passHLT" + triggerHistName1_ + "_phi_Tight", " HLT(" + triggerHistName1_ + ") pass phi", 8, -3.0, 3.0);
0117   h_totalHLTPath1_eta_Tight = ibooker.book1D(
0118       "totalHLT" + triggerHistName1_ + "_eta_Tight", " HLT(" + triggerHistName1_ + ") total #eta", 8, -2.5, 2.5);
0119   h_totalHLTPath1_pt_Tight = ibooker.book1D(
0120       "totalHLT" + triggerHistName1_ + "_pt_Tight", " HLT(" + triggerHistName1_ + ") total pt", 10, 20., 220);
0121   h_totalHLTPath1_phi_Tight = ibooker.book1D(
0122       "totalHLT" + triggerHistName1_ + "_phi_Tight", " HLT(" + triggerHistName1_ + ") total phi", 8, -3.0, 3.0);
0123 
0124   h_passHLTPath2_eta_Tight = ibooker.book1D(
0125       "passHLT" + triggerHistName2_ + "_eta_Tight", " HLT(" + triggerHistName2_ + ") pass #eta", 8, -2.5, 2.5);
0126   h_passHLTPath2_pt_Tight = ibooker.book1D(
0127       "passHLT" + triggerHistName2_ + "_pt_Tight", " HLT(" + triggerHistName2_ + ") pass pt", 10, 20., 220);
0128   h_passHLTPath2_phi_Tight = ibooker.book1D(
0129       "passHLT" + triggerHistName2_ + "_phi_Tight", " HLT(" + triggerHistName2_ + ") pass phi", 8, -3.0, 3.0);
0130   h_totalHLTPath2_eta_Tight = ibooker.book1D(
0131       "totalHLT" + triggerHistName2_ + "_eta_Tight", " HLT(" + triggerHistName2_ + ") total #eta", 8, -2.5, 2.5);
0132   h_totalHLTPath2_pt_Tight = ibooker.book1D(
0133       "totalHLT" + triggerHistName2_ + "_pt_Tight", " HLT(" + triggerHistName2_ + ") total pt", 10, 20, 220);
0134   h_totalHLTPath2_phi_Tight = ibooker.book1D(
0135       "totalHLT" + triggerHistName2_ + "_phi_Tight", " HLT(" + triggerHistName2_ + ") total phi", 8, -3.0, 3.0);
0136 }
0137 void TriggerMatchMonitor::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0138   LogTrace("TriggerMatching") << "[TriggerMatchMonitor] Analyze the mu in different eta regions";
0139 
0140   edm::Handle<edm::View<reco::Muon>> muons;
0141   iEvent.getByToken(theMuonCollectionLabel_, muons);
0142 
0143   edm::Handle<edm::View<pat::Muon>> PATmuons;
0144   iEvent.getByToken(thePATMuonCollectionLabel_, PATmuons);
0145 
0146   edm::Handle<std::vector<pat::TriggerObjectStandAlone>> triggerObjects;
0147   iEvent.getByToken(triggerObjects_, triggerObjects);
0148 
0149   Handle<edm::TriggerResults> triggerResults;
0150   iEvent.getByToken(triggerResultsToken_, triggerResults);
0151 
0152   reco::Vertex::Point posVtx;
0153   reco::Vertex::Error errVtx;
0154   Handle<std::vector<reco::Vertex>> recVtxs;
0155   iEvent.getByToken(primaryVerticesToken_, recVtxs);
0156   unsigned int theIndexOfThePrimaryVertex = 999.;
0157   for (unsigned int ind = 0; ind < recVtxs->size(); ++ind) {
0158     if ((*recVtxs)[ind].isValid() && !((*recVtxs)[ind].isFake())) {
0159       theIndexOfThePrimaryVertex = ind;
0160       break;
0161     }
0162   }
0163   if (theIndexOfThePrimaryVertex < 100) {
0164     posVtx = ((*recVtxs)[theIndexOfThePrimaryVertex]).position();
0165     errVtx = ((*recVtxs)[theIndexOfThePrimaryVertex]).error();
0166   } else {
0167     LogInfo("RecoMuonValidator") << "reco::PrimaryVertex not found, use BeamSpot position instead\n";
0168     Handle<reco::BeamSpot> recoBeamSpotHandle;
0169     iEvent.getByToken(beamSpotToken_, recoBeamSpotHandle);
0170     reco::BeamSpot bs = *recoBeamSpotHandle;
0171     posVtx = bs.position();
0172     errVtx(0, 0) = bs.BeamWidthX();
0173     errVtx(1, 1) = bs.BeamWidthY();
0174     errVtx(2, 2) = bs.sigmaZ();
0175   }
0176   const reco::Vertex thePrimaryVertex(posVtx, errVtx);
0177 
0178   if (PATmuons.isValid()) {                  //valid pat Muon
0179     for (const auto& patMuon : *PATmuons) {  //pat muon loop
0180       bool Isolated =
0181           patMuon.pfIsolationR04().sumChargedHadronPt +
0182               TMath::Max(0.,
0183                          patMuon.pfIsolationR04().sumNeutralHadronEt + patMuon.pfIsolationR04().sumPhotonEt -
0184                              0.5 * patMuon.pfIsolationR04().sumPUPt) /
0185                   patMuon.pt() <
0186           0.25;
0187 
0188       if (patMuon.isGlobalMuon() && Isolated && patMuon.isTightMuon(thePrimaryVertex)) {  //isolated tight muon
0189 
0190         TLorentzVector offlineMuon;
0191         offlineMuon.SetPtEtaPhiM(patMuon.pt(), patMuon.eta(), patMuon.phi(), 0.0);
0192 
0193         const char* ptrmuPath1 = triggerPathName1_.c_str();  //
0194         const char* ptrmuPath2 = triggerPathName2_.c_str();  //
0195         if (patMuon.pt() > triggerPtThresholdPath1_) {
0196           h_totalHLTPath1_eta_Tight->Fill(patMuon.eta());
0197           h_totalHLTPath1_pt_Tight->Fill(patMuon.pt());
0198           h_totalHLTPath1_phi_Tight->Fill(patMuon.phi());
0199         }
0200         if (patMuon.pt() > triggerPtThresholdPath2_) {
0201           h_totalHLTPath2_eta_Tight->Fill(patMuon.eta());
0202           h_totalHLTPath2_pt_Tight->Fill(patMuon.pt());
0203           h_totalHLTPath2_phi_Tight->Fill(patMuon.phi());
0204         }
0205         if (patMuon.triggered(ptrmuPath1) && patMuon.hltObject() != nullptr) {
0206           TLorentzVector hltMuon;
0207           hltMuon.SetPtEtaPhiM(patMuon.hltObject()->pt(), patMuon.hltObject()->eta(), patMuon.hltObject()->phi(), 0.0);
0208           double DelRrecoHLT = offlineMuon.DeltaR(hltMuon);
0209 
0210           matchHists[0]->Fill(DelRrecoHLT);
0211           matchHists[1]->Fill(DelRrecoHLT);
0212           matchHists[2]->Fill(patMuon.hltObject()->pt() / patMuon.pt());
0213           if (DelRrecoHLT < 0.2 && patMuon.pt() > triggerPtThresholdPath1_) {
0214             h_passHLTPath1_eta_Tight->Fill(patMuon.eta());
0215             h_passHLTPath1_pt_Tight->Fill(patMuon.pt());
0216             h_passHLTPath1_phi_Tight->Fill(patMuon.phi());
0217           }
0218           if (patMuon.l1Object() != nullptr) {
0219             TLorentzVector L1Muon;
0220             L1Muon.SetPtEtaPhiM(patMuon.l1Object()->pt(), patMuon.l1Object()->eta(), patMuon.l1Object()->phi(), 0.0);
0221             double DelRrecoL1 = offlineMuon.DeltaR(L1Muon);
0222             matchHists[3]->Fill(DelRrecoL1);
0223             matchHists[4]->Fill(DelRrecoL1);
0224             matchHists[5]->Fill(patMuon.l1Object()->pt() / patMuon.pt());
0225           }
0226         }
0227 
0228         /// Mu50 test
0229         if (patMuon.triggered(ptrmuPath2)) {
0230           TLorentzVector hltMuon50;
0231           hltMuon50.SetPtEtaPhiM(
0232               patMuon.hltObject()->pt(), patMuon.hltObject()->eta(), patMuon.hltObject()->phi(), 0.0);
0233           double DelRrecoHLT50 = offlineMuon.DeltaR(hltMuon50);
0234 
0235           matchHists[6]->Fill(DelRrecoHLT50);
0236           matchHists[7]->Fill(DelRrecoHLT50);
0237           matchHists[8]->Fill(patMuon.hltObject()->pt() / patMuon.pt());
0238           if (DelRrecoHLT50 < 0.2 && patMuon.pt() > triggerPtThresholdPath2_) {
0239             h_passHLTPath2_eta_Tight->Fill(patMuon.eta());
0240             h_passHLTPath2_pt_Tight->Fill(patMuon.pt());
0241             h_passHLTPath2_phi_Tight->Fill(patMuon.phi());
0242           }
0243 
0244           if (patMuon.l1Object() != nullptr) {
0245             TLorentzVector L1Muon50;
0246             L1Muon50.SetPtEtaPhiM(patMuon.l1Object()->pt(), patMuon.l1Object()->eta(), patMuon.l1Object()->phi(), 0.0);
0247             double DelRrecoL150 = offlineMuon.DeltaR(L1Muon50);
0248             matchHists[9]->Fill(DelRrecoL150);
0249             matchHists[10]->Fill(DelRrecoL150);
0250             matchHists[11]->Fill(patMuon.l1Object()->pt() / patMuon.pt());
0251           }
0252         }
0253       }  //isolated tight muon
0254     }    //pat muon loop
0255   }      //valid pat muon
0256 }