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