CMS 3D CMS Logo

TriggerMatchMonitor.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * \author Bibhuprasad Mahakud (Purdue University, West Lafayette, USA)
5  */
12 #include "TLorentzVector.h"
13 
14 #include <string>
15 #include <TMath.h>
16 using namespace std;
17 using namespace edm;
18 
19 //#define DEBUG
20 
22  LogTrace(metname)<<"[TriggerMatchMonitor] Parameters initialization";
23 
24  parameters = pSet;
25 
26  // the services
27  theService = new MuonServiceProxy(parameters.getParameter<ParameterSet>("ServiceParameters"));
28  theDbe = edm::Service<DQMStore>().operator->();
29 
30  beamSpotToken_ = consumes<reco::BeamSpot >(parameters.getUntrackedParameter<edm::InputTag>("offlineBeamSpot")),
31  primaryVerticesToken_ = consumes<std::vector<reco::Vertex> >(parameters.getUntrackedParameter<edm::InputTag>("offlinePrimaryVertices")),
32  theMuonCollectionLabel_ = consumes<edm::View<reco::Muon> > (parameters.getParameter<edm::InputTag>("MuonCollection"));
33  thePATMuonCollectionLabel_ = consumes<edm::View<pat::Muon> > (parameters.getParameter<edm::InputTag>("patMuonCollection"));
34  theVertexLabel_ = consumes<reco::VertexCollection>(parameters.getParameter<edm::InputTag>("VertexLabel"));
35  theBeamSpotLabel_ = mayConsume<reco::BeamSpot> (parameters.getParameter<edm::InputTag>("BeamSpotLabel"));
36  triggerResultsToken_ = consumes<edm::TriggerResults>(parameters.getUntrackedParameter<edm::InputTag>("triggerResults"));
37  triggerObjects_ = consumes<std::vector<pat::TriggerObjectStandAlone>>(parameters.getParameter<edm::InputTag>("triggerObjects"));
38 
39  triggerPathName1_ = parameters.getParameter<string>("triggerPathName1");
40  triggerHistName1_ = parameters.getParameter<string>("triggerHistName1");
41  triggerPtThresholdPath1_ = parameters.getParameter<double>("triggerPtThresholdPath1");
42  triggerPathName2_ = parameters.getParameter<string>("triggerPathName2");
43  triggerHistName2_ = parameters.getParameter<string>("triggerHistName2");
44  triggerPtThresholdPath2_ = parameters.getParameter<double>("triggerPtThresholdPath2");
45  theFolder = parameters.getParameter<string>("folder");
46 }
48  delete theService;
49 }
50 
52  edm::Run const & /*iRun*/,
53  edm::EventSetup const& /*iSetup*/){
54  ibooker.cd();
55  ibooker.setCurrentFolder(theFolder);
56 
57  // monitoring of trigger match parameter
58 
59  matchHists.push_back(ibooker.book1D("DelR_HLT_"+triggerHistName1_+"_v1", "DeltaR_(offline,HLT)_triggerPass("+triggerHistName1_+")", 500, 0.0, 0.5));
60  matchHists.push_back(ibooker.book1D("DelR_HLT_"+triggerHistName1_+"_v2", "DeltaR_(offline,HLT)_triggerPass("+triggerHistName1_+")", 100, 0.5, 1.5));
61  matchHists.push_back(ibooker.book1D("PtRatio_HLT_"+triggerHistName1_, "PtRatio_(HLTPt/OfflinePt)_"+triggerHistName1_, 200, -5., 5.0));
62 
63  matchHists.push_back(ibooker.book1D("DelR_L1_"+triggerHistName1_+"_v1", "DeltaR_(offline, L1)_triggerPass("+triggerHistName1_+")", 500, 0.0, 1.0));
64  matchHists.push_back(ibooker.book1D("DelR_L1_"+triggerHistName1_+"_v2", "DeltaR_(offline, L1)_triggerPass("+triggerHistName1_+")", 500, 0.0, 2.0));
65  matchHists.push_back(ibooker.book1D("PtRatio_L1_"+triggerHistName1_, "PtRatio_(HLTPt/OfflinePt)_"+triggerHistName1_, 200, -5., 5.0));
66 
67  matchHists.push_back(ibooker.book1D("DelR_HLT_"+triggerHistName2_+"_v1", "DeltaR_(offline,HLT)_triggerPass("+triggerHistName2_+")", 500, 0.0, 0.5));
68  matchHists.push_back(ibooker.book1D("DelR_HLT_"+triggerHistName2_+"_v2", "DeltaR_(offline,HLT)_triggerPass("+triggerHistName2_+")", 100, 0.5, 1.5));
69  matchHists.push_back(ibooker.book1D("PtRatio_HLT_"+triggerHistName2_, "PtRatio_(HLTPt/OfflinePt)_"+triggerHistName2_, 200, -5., 5.0));
70 
71  matchHists.push_back(ibooker.book1D("DelR_L1_"+triggerHistName2_+"_v1", "DeltaR_(offline, L1)_triggerPass("+triggerHistName2_+")", 250, 0.0, 0.5));
72  matchHists.push_back(ibooker.book1D("DelR_L1_"+triggerHistName2_+"_v2", "DeltaR_(offline, L1)_triggerPass("+triggerHistName2_+")", 100, 0.5, 1.5));
73  matchHists.push_back(ibooker.book1D("PtRatio_L1_"+triggerHistName2_, "PtRatio_(HLTPt/OfflinePt)_"+triggerHistName2_, 200, -5., 5.0));
74 
75  ibooker.cd();
76  ibooker.setCurrentFolder(theFolder+"/EfficiencyInput");
77 
78  h_passHLTPath1_eta_Tight = ibooker.book1D("passHLT"+triggerHistName1_+"_eta_Tight", " HLT("+triggerHistName1_+") pass #eta", 8, -2.5, 2.5);
79  h_passHLTPath1_pt_Tight = ibooker.book1D("passHLT"+triggerHistName1_+"_pt_Tight", " HLT("+triggerHistName1_+") pass pt", 10, 20, 220);
80  h_passHLTPath1_phi_Tight = ibooker.book1D("passHLT"+triggerHistName1_+"_phi_Tight", " HLT("+triggerHistName1_+") pass phi", 8, -3.0, 3.0);
81  h_totalHLTPath1_eta_Tight = ibooker.book1D("totalHLT"+triggerHistName1_+"_eta_Tight", " HLT("+triggerHistName1_+") total #eta", 8, -2.5, 2.5);
82  h_totalHLTPath1_pt_Tight = ibooker.book1D("totalHLT"+triggerHistName1_+"_pt_Tight", " HLT("+triggerHistName1_+") total pt", 10, 20., 220);
83  h_totalHLTPath1_phi_Tight = ibooker.book1D("totalHLT"+triggerHistName1_+"_phi_Tight", " HLT("+triggerHistName1_+") total phi", 8, -3.0, 3.0);
84 
85  h_passHLTPath2_eta_Tight = ibooker.book1D("passHLT"+triggerHistName2_+"_eta_Tight", " HLT("+triggerHistName2_+") pass #eta", 8, -2.5, 2.5);
86  h_passHLTPath2_pt_Tight = ibooker.book1D("passHLT"+triggerHistName2_+"_pt_Tight", " HLT("+triggerHistName2_+") pass pt", 10, 20., 220);
87  h_passHLTPath2_phi_Tight = ibooker.book1D("passHLT"+triggerHistName2_+"_phi_Tight", " HLT("+triggerHistName2_+") pass phi", 8, -3.0, 3.0);
88  h_totalHLTPath2_eta_Tight = ibooker.book1D("totalHLT"+triggerHistName2_+"_eta_Tight", " HLT("+triggerHistName2_+") total #eta", 8, -2.5, 2.5);
89  h_totalHLTPath2_pt_Tight = ibooker.book1D("totalHLT"+triggerHistName2_+"_pt_Tight", " HLT("+triggerHistName2_+") total pt", 10, 20, 220);
90  h_totalHLTPath2_phi_Tight = ibooker.book1D("totalHLT"+triggerHistName2_+"_phi_Tight", " HLT("+triggerHistName2_+") total phi", 8, -3.0, 3.0);
91 
92 
93 }
95 
96  LogTrace(metname)<<"[TriggerMatchMonitor] Analyze the mu in different eta regions";
97  theService->update(iSetup);
98 
100  iEvent.getByToken(theMuonCollectionLabel_,muons);
101 
103  iEvent.getByToken(thePATMuonCollectionLabel_,PATmuons);
104 
106  iEvent.getByToken(triggerObjects_, triggerObjects);
107 
109  iEvent.getByToken(triggerResultsToken_, triggerResults);
110 
111  reco::Vertex::Point posVtx;
112  reco::Vertex::Error errVtx;
114  iEvent.getByToken(primaryVerticesToken_,recVtxs);
115  unsigned int theIndexOfThePrimaryVertex = 999.;
116  for (unsigned int ind = 0; ind < recVtxs->size(); ++ind) {
117  if ( (*recVtxs)[ind].isValid() && !((*recVtxs)[ind].isFake()) ) {
118  theIndexOfThePrimaryVertex = ind;
119  break;
120  }
121  }
122  if (theIndexOfThePrimaryVertex<100) {
123  posVtx = ((*recVtxs)[theIndexOfThePrimaryVertex]).position();
124  errVtx = ((*recVtxs)[theIndexOfThePrimaryVertex]).error();
125  }
126  else {
127  LogInfo("RecoMuonValidator") << "reco::PrimaryVertex not found, use BeamSpot position instead\n";
128  Handle<reco::BeamSpot> recoBeamSpotHandle;
129  iEvent.getByToken(beamSpotToken_,recoBeamSpotHandle);
130  reco::BeamSpot bs = *recoBeamSpotHandle;
131  posVtx = bs.position();
132  errVtx(0,0) = bs.BeamWidthX();
133  errVtx(1,1) = bs.BeamWidthY();
134  errVtx(2,2) = bs.sigmaZ();
135  }
136  const reco::Vertex thePrimaryVertex(posVtx,errVtx);
137 
138  if(PATmuons.isValid()){//valid pat Muon
139  for(const auto & patMuon : *PATmuons){//pat muon loop
140  bool Isolated=patMuon.pfIsolationR04().sumChargedHadronPt + TMath::Max(0., patMuon.pfIsolationR04().sumNeutralHadronEt + patMuon.pfIsolationR04().sumPhotonEt - 0.5*patMuon.pfIsolationR04().sumPUPt) / patMuon.pt() < 0.25;
141 
142  if(patMuon.isGlobalMuon() && Isolated && patMuon.isTightMuon(thePrimaryVertex)){//isolated tight muon
143 
144  TLorentzVector offlineMuon;
145  offlineMuon.SetPtEtaPhiM(patMuon.pt(), patMuon.eta(), patMuon.phi(),0.0);
146 
147  const char *ptrmuPath1 = triggerPathName1_.c_str(); //
148  const char *ptrmuPath2 = triggerPathName2_.c_str(); //
149  if(patMuon.pt() > triggerPtThresholdPath1_){
150  h_totalHLTPath1_eta_Tight->Fill(patMuon.eta());
151  h_totalHLTPath1_pt_Tight->Fill(patMuon.pt());
152  h_totalHLTPath1_phi_Tight->Fill(patMuon.phi());
153  }
154  if(patMuon.pt() > triggerPtThresholdPath2_){
155  h_totalHLTPath2_eta_Tight->Fill(patMuon.eta());
156  h_totalHLTPath2_pt_Tight->Fill(patMuon.pt());
157  h_totalHLTPath2_phi_Tight->Fill(patMuon.phi());
158  }
159  if(patMuon.triggered(ptrmuPath1) && patMuon.hltObject() !=nullptr){
160  TLorentzVector hltMuon;
161  hltMuon.SetPtEtaPhiM(patMuon.hltObject()->pt(),patMuon.hltObject()->eta(),patMuon.hltObject()->phi(),0.0);
162  double DelRrecoHLT=offlineMuon.DeltaR(hltMuon);
163 
164  matchHists[0]->Fill(DelRrecoHLT);
165  matchHists[1]->Fill(DelRrecoHLT);
166  matchHists[2]->Fill(patMuon.hltObject()->pt()/patMuon.pt());
167  if(DelRrecoHLT<0.2 && patMuon.pt() > triggerPtThresholdPath1_){
168  h_passHLTPath1_eta_Tight->Fill(patMuon.eta());
169  h_passHLTPath1_pt_Tight->Fill(patMuon.pt());
170  h_passHLTPath1_phi_Tight->Fill(patMuon.phi());
171  }
172  if(patMuon.l1Object() !=nullptr){
173  TLorentzVector L1Muon;
174  L1Muon.SetPtEtaPhiM(patMuon.l1Object()->pt(),patMuon.l1Object()->eta(),patMuon.l1Object()->phi(),0.0);
175  double DelRrecoL1=offlineMuon.DeltaR(L1Muon);
176  matchHists[3]->Fill(DelRrecoL1);
177  matchHists[4]->Fill(DelRrecoL1);
178  matchHists[5]->Fill(patMuon.l1Object()->pt()/patMuon.pt());
179  }
180 
181  }
182 
184  if(patMuon.triggered(ptrmuPath2)){
185  TLorentzVector hltMuon50;
186  hltMuon50.SetPtEtaPhiM(patMuon.hltObject()->pt(),patMuon.hltObject()->eta(),patMuon.hltObject()->phi(),0.0);
187  double DelRrecoHLT50=offlineMuon.DeltaR(hltMuon50);
188 
189  matchHists[6]->Fill(DelRrecoHLT50);
190  matchHists[7]->Fill(DelRrecoHLT50);
191  matchHists[8]->Fill(patMuon.hltObject()->pt()/patMuon.pt());
192  if(DelRrecoHLT50<0.2 && patMuon.pt() > triggerPtThresholdPath2_ ){
193  h_passHLTPath2_eta_Tight->Fill(patMuon.eta());
194  h_passHLTPath2_pt_Tight->Fill(patMuon.pt());
195  h_passHLTPath2_phi_Tight->Fill(patMuon.phi());
196  }
197 
198 
199  if(patMuon.l1Object() !=nullptr){
200  TLorentzVector L1Muon50;
201  L1Muon50.SetPtEtaPhiM(patMuon.l1Object()->pt(),patMuon.l1Object()->eta(),patMuon.l1Object()->phi(),0.0);
202  double DelRrecoL150=offlineMuon.DeltaR(L1Muon50);
203  matchHists[9]->Fill(DelRrecoL150);
204  matchHists[10]->Fill(DelRrecoL150);
205  matchHists[11]->Fill(patMuon.l1Object()->pt()/patMuon.pt());
206  }
207  }
208  }//isolated tight muon
209  } //pat muon loop
210  } //valid pat muon
211 
212 }
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
const std::string metname
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:43
int iEvent
Definition: GenABIO.cc:230
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
~TriggerMatchMonitor() override
Destructor.
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
math::XYZPoint Point
point in the space
Definition: Vertex.h:39
double BeamWidthX() const
beam width X
Definition: BeamSpot.h:86
static std::string const triggerResults
Definition: EdmProvDump.cc:42
bool isValid() const
Definition: HandleBase.h:74
#define LogTrace(id)
T Max(T a, T b)
Definition: MathUtil.h:44
double sigmaZ() const
sigma z
Definition: BeamSpot.h:80
double BeamWidthY() const
beam width Y
Definition: BeamSpot.h:88
HLT enums.
static int position[264][3]
Definition: ReadPGInfo.cc:509
void analyze(const edm::Event &, const edm::EventSetup &) override
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
const Point & position() const
position
Definition: BeamSpot.h:62
TriggerMatchMonitor(const edm::ParameterSet &pSet)
Constructor.
Definition: Run.h:44