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  */
11 #include "TLorentzVector.h"
12 
13 #include <string>
14 #include <TMath.h>
15 using namespace std;
16 using namespace edm;
17 
18 //#define DEBUG
19 
21  LogTrace(metname) << "[TriggerMatchMonitor] Parameters initialization";
22 
23  parameters = pSet;
24 
25  // the services
26  theService = new MuonServiceProxy(parameters.getParameter<ParameterSet>("ServiceParameters"));
27 
28  beamSpotToken_ = consumes<reco::BeamSpot>(parameters.getUntrackedParameter<edm::InputTag>("offlineBeamSpot")),
29  primaryVerticesToken_ =
30  consumes<std::vector<reco::Vertex>>(parameters.getUntrackedParameter<edm::InputTag>("offlinePrimaryVertices")),
31  theMuonCollectionLabel_ = consumes<edm::View<reco::Muon>>(parameters.getParameter<edm::InputTag>("MuonCollection"));
32  thePATMuonCollectionLabel_ =
33  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_ =
37  consumes<edm::TriggerResults>(parameters.getUntrackedParameter<edm::InputTag>("triggerResults"));
38  triggerObjects_ =
39  consumes<std::vector<pat::TriggerObjectStandAlone>>(parameters.getParameter<edm::InputTag>("triggerObjects"));
40 
41  triggerPathName1_ = parameters.getParameter<string>("triggerPathName1");
42  triggerHistName1_ = parameters.getParameter<string>("triggerHistName1");
43  triggerPtThresholdPath1_ = parameters.getParameter<double>("triggerPtThresholdPath1");
44  triggerPathName2_ = parameters.getParameter<string>("triggerPathName2");
45  triggerHistName2_ = parameters.getParameter<string>("triggerHistName2");
46  triggerPtThresholdPath2_ = parameters.getParameter<double>("triggerPtThresholdPath2");
47  theFolder = parameters.getParameter<string>("folder");
48 }
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",
60  "DeltaR_(offline,HLT)_triggerPass(" + triggerHistName1_ + ")",
61  500,
62  0.0,
63  0.5));
64  matchHists.push_back(ibooker.book1D("DelR_HLT_" + triggerHistName1_ + "_v2",
65  "DeltaR_(offline,HLT)_triggerPass(" + triggerHistName1_ + ")",
66  100,
67  0.5,
68  1.5));
69  matchHists.push_back(ibooker.book1D(
70  "PtRatio_HLT_" + triggerHistName1_, "PtRatio_(HLTPt/OfflinePt)_" + triggerHistName1_, 200, -5., 5.0));
71 
72  matchHists.push_back(ibooker.book1D("DelR_L1_" + triggerHistName1_ + "_v1",
73  "DeltaR_(offline, L1)_triggerPass(" + triggerHistName1_ + ")",
74  500,
75  0.0,
76  1.0));
77  matchHists.push_back(ibooker.book1D("DelR_L1_" + triggerHistName1_ + "_v2",
78  "DeltaR_(offline, L1)_triggerPass(" + triggerHistName1_ + ")",
79  500,
80  0.0,
81  2.0));
82  matchHists.push_back(ibooker.book1D(
83  "PtRatio_L1_" + triggerHistName1_, "PtRatio_(HLTPt/OfflinePt)_" + triggerHistName1_, 200, -5., 5.0));
84 
85  matchHists.push_back(ibooker.book1D("DelR_HLT_" + triggerHistName2_ + "_v1",
86  "DeltaR_(offline,HLT)_triggerPass(" + triggerHistName2_ + ")",
87  500,
88  0.0,
89  0.5));
90  matchHists.push_back(ibooker.book1D("DelR_HLT_" + triggerHistName2_ + "_v2",
91  "DeltaR_(offline,HLT)_triggerPass(" + triggerHistName2_ + ")",
92  100,
93  0.5,
94  1.5));
95  matchHists.push_back(ibooker.book1D(
96  "PtRatio_HLT_" + triggerHistName2_, "PtRatio_(HLTPt/OfflinePt)_" + triggerHistName2_, 200, -5., 5.0));
97 
98  matchHists.push_back(ibooker.book1D("DelR_L1_" + triggerHistName2_ + "_v1",
99  "DeltaR_(offline, L1)_triggerPass(" + triggerHistName2_ + ")",
100  250,
101  0.0,
102  0.5));
103  matchHists.push_back(ibooker.book1D("DelR_L1_" + triggerHistName2_ + "_v2",
104  "DeltaR_(offline, L1)_triggerPass(" + triggerHistName2_ + ")",
105  100,
106  0.5,
107  1.5));
108  matchHists.push_back(ibooker.book1D(
109  "PtRatio_L1_" + triggerHistName2_, "PtRatio_(HLTPt/OfflinePt)_" + triggerHistName2_, 200, -5., 5.0));
110 
111  ibooker.cd();
112  ibooker.setCurrentFolder(theFolder + "/EfficiencyInput");
113 
114  h_passHLTPath1_eta_Tight = ibooker.book1D(
115  "passHLT" + triggerHistName1_ + "_eta_Tight", " HLT(" + triggerHistName1_ + ") pass #eta", 8, -2.5, 2.5);
116  h_passHLTPath1_pt_Tight = ibooker.book1D(
117  "passHLT" + triggerHistName1_ + "_pt_Tight", " HLT(" + triggerHistName1_ + ") pass pt", 10, 20, 220);
118  h_passHLTPath1_phi_Tight = ibooker.book1D(
119  "passHLT" + triggerHistName1_ + "_phi_Tight", " HLT(" + triggerHistName1_ + ") pass phi", 8, -3.0, 3.0);
120  h_totalHLTPath1_eta_Tight = ibooker.book1D(
121  "totalHLT" + triggerHistName1_ + "_eta_Tight", " HLT(" + triggerHistName1_ + ") total #eta", 8, -2.5, 2.5);
122  h_totalHLTPath1_pt_Tight = ibooker.book1D(
123  "totalHLT" + triggerHistName1_ + "_pt_Tight", " HLT(" + triggerHistName1_ + ") total pt", 10, 20., 220);
124  h_totalHLTPath1_phi_Tight = ibooker.book1D(
125  "totalHLT" + triggerHistName1_ + "_phi_Tight", " HLT(" + triggerHistName1_ + ") total phi", 8, -3.0, 3.0);
126 
127  h_passHLTPath2_eta_Tight = ibooker.book1D(
128  "passHLT" + triggerHistName2_ + "_eta_Tight", " HLT(" + triggerHistName2_ + ") pass #eta", 8, -2.5, 2.5);
129  h_passHLTPath2_pt_Tight = ibooker.book1D(
130  "passHLT" + triggerHistName2_ + "_pt_Tight", " HLT(" + triggerHistName2_ + ") pass pt", 10, 20., 220);
131  h_passHLTPath2_phi_Tight = ibooker.book1D(
132  "passHLT" + triggerHistName2_ + "_phi_Tight", " HLT(" + triggerHistName2_ + ") pass phi", 8, -3.0, 3.0);
133  h_totalHLTPath2_eta_Tight = ibooker.book1D(
134  "totalHLT" + triggerHistName2_ + "_eta_Tight", " HLT(" + triggerHistName2_ + ") total #eta", 8, -2.5, 2.5);
135  h_totalHLTPath2_pt_Tight = ibooker.book1D(
136  "totalHLT" + triggerHistName2_ + "_pt_Tight", " HLT(" + triggerHistName2_ + ") total pt", 10, 20, 220);
137  h_totalHLTPath2_phi_Tight = ibooker.book1D(
138  "totalHLT" + triggerHistName2_ + "_phi_Tight", " HLT(" + triggerHistName2_ + ") total phi", 8, -3.0, 3.0);
139 }
141  LogTrace(metname) << "[TriggerMatchMonitor] Analyze the mu in different eta regions";
142  theService->update(iSetup);
143 
145  iEvent.getByToken(theMuonCollectionLabel_, muons);
146 
148  iEvent.getByToken(thePATMuonCollectionLabel_, PATmuons);
149 
151  iEvent.getByToken(triggerObjects_, triggerObjects);
152 
154  iEvent.getByToken(triggerResultsToken_, triggerResults);
155 
156  reco::Vertex::Point posVtx;
157  reco::Vertex::Error errVtx;
159  iEvent.getByToken(primaryVerticesToken_, recVtxs);
160  unsigned int theIndexOfThePrimaryVertex = 999.;
161  for (unsigned int ind = 0; ind < recVtxs->size(); ++ind) {
162  if ((*recVtxs)[ind].isValid() && !((*recVtxs)[ind].isFake())) {
163  theIndexOfThePrimaryVertex = ind;
164  break;
165  }
166  }
167  if (theIndexOfThePrimaryVertex < 100) {
168  posVtx = ((*recVtxs)[theIndexOfThePrimaryVertex]).position();
169  errVtx = ((*recVtxs)[theIndexOfThePrimaryVertex]).error();
170  } else {
171  LogInfo("RecoMuonValidator") << "reco::PrimaryVertex not found, use BeamSpot position instead\n";
172  Handle<reco::BeamSpot> recoBeamSpotHandle;
173  iEvent.getByToken(beamSpotToken_, recoBeamSpotHandle);
174  reco::BeamSpot bs = *recoBeamSpotHandle;
175  posVtx = bs.position();
176  errVtx(0, 0) = bs.BeamWidthX();
177  errVtx(1, 1) = bs.BeamWidthY();
178  errVtx(2, 2) = bs.sigmaZ();
179  }
180  const reco::Vertex thePrimaryVertex(posVtx, errVtx);
181 
182  if (PATmuons.isValid()) { //valid pat Muon
183  for (const auto& patMuon : *PATmuons) { //pat muon loop
184  bool Isolated =
185  patMuon.pfIsolationR04().sumChargedHadronPt +
186  TMath::Max(0.,
187  patMuon.pfIsolationR04().sumNeutralHadronEt + patMuon.pfIsolationR04().sumPhotonEt -
188  0.5 * patMuon.pfIsolationR04().sumPUPt) /
189  patMuon.pt() <
190  0.25;
191 
192  if (patMuon.isGlobalMuon() && Isolated && patMuon.isTightMuon(thePrimaryVertex)) { //isolated tight muon
193 
194  TLorentzVector offlineMuon;
195  offlineMuon.SetPtEtaPhiM(patMuon.pt(), patMuon.eta(), patMuon.phi(), 0.0);
196 
197  const char* ptrmuPath1 = triggerPathName1_.c_str(); //
198  const char* ptrmuPath2 = triggerPathName2_.c_str(); //
199  if (patMuon.pt() > triggerPtThresholdPath1_) {
200  h_totalHLTPath1_eta_Tight->Fill(patMuon.eta());
201  h_totalHLTPath1_pt_Tight->Fill(patMuon.pt());
202  h_totalHLTPath1_phi_Tight->Fill(patMuon.phi());
203  }
204  if (patMuon.pt() > triggerPtThresholdPath2_) {
205  h_totalHLTPath2_eta_Tight->Fill(patMuon.eta());
206  h_totalHLTPath2_pt_Tight->Fill(patMuon.pt());
207  h_totalHLTPath2_phi_Tight->Fill(patMuon.phi());
208  }
209  if (patMuon.triggered(ptrmuPath1) && patMuon.hltObject() != nullptr) {
210  TLorentzVector hltMuon;
211  hltMuon.SetPtEtaPhiM(patMuon.hltObject()->pt(), patMuon.hltObject()->eta(), patMuon.hltObject()->phi(), 0.0);
212  double DelRrecoHLT = offlineMuon.DeltaR(hltMuon);
213 
214  matchHists[0]->Fill(DelRrecoHLT);
215  matchHists[1]->Fill(DelRrecoHLT);
216  matchHists[2]->Fill(patMuon.hltObject()->pt() / patMuon.pt());
217  if (DelRrecoHLT < 0.2 && patMuon.pt() > triggerPtThresholdPath1_) {
218  h_passHLTPath1_eta_Tight->Fill(patMuon.eta());
219  h_passHLTPath1_pt_Tight->Fill(patMuon.pt());
220  h_passHLTPath1_phi_Tight->Fill(patMuon.phi());
221  }
222  if (patMuon.l1Object() != nullptr) {
223  TLorentzVector L1Muon;
224  L1Muon.SetPtEtaPhiM(patMuon.l1Object()->pt(), patMuon.l1Object()->eta(), patMuon.l1Object()->phi(), 0.0);
225  double DelRrecoL1 = offlineMuon.DeltaR(L1Muon);
226  matchHists[3]->Fill(DelRrecoL1);
227  matchHists[4]->Fill(DelRrecoL1);
228  matchHists[5]->Fill(patMuon.l1Object()->pt() / patMuon.pt());
229  }
230  }
231 
233  if (patMuon.triggered(ptrmuPath2)) {
234  TLorentzVector hltMuon50;
235  hltMuon50.SetPtEtaPhiM(
236  patMuon.hltObject()->pt(), patMuon.hltObject()->eta(), patMuon.hltObject()->phi(), 0.0);
237  double DelRrecoHLT50 = offlineMuon.DeltaR(hltMuon50);
238 
239  matchHists[6]->Fill(DelRrecoHLT50);
240  matchHists[7]->Fill(DelRrecoHLT50);
241  matchHists[8]->Fill(patMuon.hltObject()->pt() / patMuon.pt());
242  if (DelRrecoHLT50 < 0.2 && patMuon.pt() > triggerPtThresholdPath2_) {
243  h_passHLTPath2_eta_Tight->Fill(patMuon.eta());
244  h_passHLTPath2_pt_Tight->Fill(patMuon.pt());
245  h_passHLTPath2_phi_Tight->Fill(patMuon.phi());
246  }
247 
248  if (patMuon.l1Object() != nullptr) {
249  TLorentzVector L1Muon50;
250  L1Muon50.SetPtEtaPhiM(patMuon.l1Object()->pt(), patMuon.l1Object()->eta(), patMuon.l1Object()->phi(), 0.0);
251  double DelRrecoL150 = offlineMuon.DeltaR(L1Muon50);
252  matchHists[9]->Fill(DelRrecoL150);
253  matchHists[10]->Fill(DelRrecoL150);
254  matchHists[11]->Fill(patMuon.l1Object()->pt() / patMuon.pt());
255  }
256  }
257  } //isolated tight muon
258  } //pat muon loop
259  } //valid pat muon
260 }
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX)
Definition: DQMStore.cc:239
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
const std::string metname
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:418
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:43
int iEvent
Definition: GenABIO.cc:224
~TriggerMatchMonitor() override
Destructor.
math::XYZPoint Point
point in the space
Definition: Vertex.h:39
double BeamWidthX() const
beam width X
Definition: BeamSpot.h:82
static std::string const triggerResults
Definition: EdmProvDump.cc:45
bool isValid() const
Definition: HandleBase.h:70
#define LogTrace(id)
T Max(T a, T b)
Definition: MathUtil.h:44
double sigmaZ() const
sigma z
Definition: BeamSpot.h:76
double BeamWidthY() const
beam width Y
Definition: BeamSpot.h:84
HLT enums.
static int position[264][3]
Definition: ReadPGInfo.cc:289
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:59
TriggerMatchMonitor(const edm::ParameterSet &pSet)
Constructor.
Definition: Run.h:45