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 
29  beamSpotToken_ = consumes<reco::BeamSpot >(parameters.getUntrackedParameter<edm::InputTag>("offlineBeamSpot")),
30  primaryVerticesToken_ = consumes<std::vector<reco::Vertex> >(parameters.getUntrackedParameter<edm::InputTag>("offlinePrimaryVertices")),
31  theMuonCollectionLabel_ = consumes<edm::View<reco::Muon> > (parameters.getParameter<edm::InputTag>("MuonCollection"));
32  thePATMuonCollectionLabel_ = consumes<edm::View<pat::Muon> > (parameters.getParameter<edm::InputTag>("patMuonCollection"));
33  theVertexLabel_ = consumes<reco::VertexCollection>(parameters.getParameter<edm::InputTag>("VertexLabel"));
34  theBeamSpotLabel_ = mayConsume<reco::BeamSpot> (parameters.getParameter<edm::InputTag>("BeamSpotLabel"));
35  triggerResultsToken_ = consumes<edm::TriggerResults>(parameters.getUntrackedParameter<edm::InputTag>("triggerResults"));
36  triggerObjects_ = 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  delete theService;
48 }
49 
51  edm::Run const & /*iRun*/,
52  edm::EventSetup const& /*iSetup*/){
53  ibooker.cd();
54  ibooker.setCurrentFolder(theFolder);
55 
56  // monitoring of trigger match parameter
57 
58  matchHists.push_back(ibooker.book1D("DelR_HLT_"+triggerHistName1_+"_v1", "DeltaR_(offline,HLT)_triggerPass("+triggerHistName1_+")", 500, 0.0, 0.5));
59  matchHists.push_back(ibooker.book1D("DelR_HLT_"+triggerHistName1_+"_v2", "DeltaR_(offline,HLT)_triggerPass("+triggerHistName1_+")", 100, 0.5, 1.5));
60  matchHists.push_back(ibooker.book1D("PtRatio_HLT_"+triggerHistName1_, "PtRatio_(HLTPt/OfflinePt)_"+triggerHistName1_, 200, -5., 5.0));
61 
62  matchHists.push_back(ibooker.book1D("DelR_L1_"+triggerHistName1_+"_v1", "DeltaR_(offline, L1)_triggerPass("+triggerHistName1_+")", 500, 0.0, 1.0));
63  matchHists.push_back(ibooker.book1D("DelR_L1_"+triggerHistName1_+"_v2", "DeltaR_(offline, L1)_triggerPass("+triggerHistName1_+")", 500, 0.0, 2.0));
64  matchHists.push_back(ibooker.book1D("PtRatio_L1_"+triggerHistName1_, "PtRatio_(HLTPt/OfflinePt)_"+triggerHistName1_, 200, -5., 5.0));
65 
66  matchHists.push_back(ibooker.book1D("DelR_HLT_"+triggerHistName2_+"_v1", "DeltaR_(offline,HLT)_triggerPass("+triggerHistName2_+")", 500, 0.0, 0.5));
67  matchHists.push_back(ibooker.book1D("DelR_HLT_"+triggerHistName2_+"_v2", "DeltaR_(offline,HLT)_triggerPass("+triggerHistName2_+")", 100, 0.5, 1.5));
68  matchHists.push_back(ibooker.book1D("PtRatio_HLT_"+triggerHistName2_, "PtRatio_(HLTPt/OfflinePt)_"+triggerHistName2_, 200, -5., 5.0));
69 
70  matchHists.push_back(ibooker.book1D("DelR_L1_"+triggerHistName2_+"_v1", "DeltaR_(offline, L1)_triggerPass("+triggerHistName2_+")", 250, 0.0, 0.5));
71  matchHists.push_back(ibooker.book1D("DelR_L1_"+triggerHistName2_+"_v2", "DeltaR_(offline, L1)_triggerPass("+triggerHistName2_+")", 100, 0.5, 1.5));
72  matchHists.push_back(ibooker.book1D("PtRatio_L1_"+triggerHistName2_, "PtRatio_(HLTPt/OfflinePt)_"+triggerHistName2_, 200, -5., 5.0));
73 
74  ibooker.cd();
75  ibooker.setCurrentFolder(theFolder+"/EfficiencyInput");
76 
77  h_passHLTPath1_eta_Tight = ibooker.book1D("passHLT"+triggerHistName1_+"_eta_Tight", " HLT("+triggerHistName1_+") pass #eta", 8, -2.5, 2.5);
78  h_passHLTPath1_pt_Tight = ibooker.book1D("passHLT"+triggerHistName1_+"_pt_Tight", " HLT("+triggerHistName1_+") pass pt", 10, 20, 220);
79  h_passHLTPath1_phi_Tight = ibooker.book1D("passHLT"+triggerHistName1_+"_phi_Tight", " HLT("+triggerHistName1_+") pass phi", 8, -3.0, 3.0);
80  h_totalHLTPath1_eta_Tight = ibooker.book1D("totalHLT"+triggerHistName1_+"_eta_Tight", " HLT("+triggerHistName1_+") total #eta", 8, -2.5, 2.5);
81  h_totalHLTPath1_pt_Tight = ibooker.book1D("totalHLT"+triggerHistName1_+"_pt_Tight", " HLT("+triggerHistName1_+") total pt", 10, 20., 220);
82  h_totalHLTPath1_phi_Tight = ibooker.book1D("totalHLT"+triggerHistName1_+"_phi_Tight", " HLT("+triggerHistName1_+") total phi", 8, -3.0, 3.0);
83 
84  h_passHLTPath2_eta_Tight = ibooker.book1D("passHLT"+triggerHistName2_+"_eta_Tight", " HLT("+triggerHistName2_+") pass #eta", 8, -2.5, 2.5);
85  h_passHLTPath2_pt_Tight = ibooker.book1D("passHLT"+triggerHistName2_+"_pt_Tight", " HLT("+triggerHistName2_+") pass pt", 10, 20., 220);
86  h_passHLTPath2_phi_Tight = ibooker.book1D("passHLT"+triggerHistName2_+"_phi_Tight", " HLT("+triggerHistName2_+") pass phi", 8, -3.0, 3.0);
87  h_totalHLTPath2_eta_Tight = ibooker.book1D("totalHLT"+triggerHistName2_+"_eta_Tight", " HLT("+triggerHistName2_+") total #eta", 8, -2.5, 2.5);
88  h_totalHLTPath2_pt_Tight = ibooker.book1D("totalHLT"+triggerHistName2_+"_pt_Tight", " HLT("+triggerHistName2_+") total pt", 10, 20, 220);
89  h_totalHLTPath2_phi_Tight = ibooker.book1D("totalHLT"+triggerHistName2_+"_phi_Tight", " HLT("+triggerHistName2_+") total phi", 8, -3.0, 3.0);
90 
91 
92 }
94 
95  LogTrace(metname)<<"[TriggerMatchMonitor] Analyze the mu in different eta regions";
96  theService->update(iSetup);
97 
99  iEvent.getByToken(theMuonCollectionLabel_,muons);
100 
102  iEvent.getByToken(thePATMuonCollectionLabel_,PATmuons);
103 
105  iEvent.getByToken(triggerObjects_, triggerObjects);
106 
108  iEvent.getByToken(triggerResultsToken_, triggerResults);
109 
110  reco::Vertex::Point posVtx;
111  reco::Vertex::Error errVtx;
113  iEvent.getByToken(primaryVerticesToken_,recVtxs);
114  unsigned int theIndexOfThePrimaryVertex = 999.;
115  for (unsigned int ind = 0; ind < recVtxs->size(); ++ind) {
116  if ( (*recVtxs)[ind].isValid() && !((*recVtxs)[ind].isFake()) ) {
117  theIndexOfThePrimaryVertex = ind;
118  break;
119  }
120  }
121  if (theIndexOfThePrimaryVertex<100) {
122  posVtx = ((*recVtxs)[theIndexOfThePrimaryVertex]).position();
123  errVtx = ((*recVtxs)[theIndexOfThePrimaryVertex]).error();
124  }
125  else {
126  LogInfo("RecoMuonValidator") << "reco::PrimaryVertex not found, use BeamSpot position instead\n";
127  Handle<reco::BeamSpot> recoBeamSpotHandle;
128  iEvent.getByToken(beamSpotToken_,recoBeamSpotHandle);
129  reco::BeamSpot bs = *recoBeamSpotHandle;
130  posVtx = bs.position();
131  errVtx(0,0) = bs.BeamWidthX();
132  errVtx(1,1) = bs.BeamWidthY();
133  errVtx(2,2) = bs.sigmaZ();
134  }
135  const reco::Vertex thePrimaryVertex(posVtx,errVtx);
136 
137  if(PATmuons.isValid()){//valid pat Muon
138  for(const auto & patMuon : *PATmuons){//pat muon loop
139  bool Isolated=patMuon.pfIsolationR04().sumChargedHadronPt + TMath::Max(0., patMuon.pfIsolationR04().sumNeutralHadronEt + patMuon.pfIsolationR04().sumPhotonEt - 0.5*patMuon.pfIsolationR04().sumPUPt) / patMuon.pt() < 0.25;
140 
141  if(patMuon.isGlobalMuon() && Isolated && patMuon.isTightMuon(thePrimaryVertex)){//isolated tight muon
142 
143  TLorentzVector offlineMuon;
144  offlineMuon.SetPtEtaPhiM(patMuon.pt(), patMuon.eta(), patMuon.phi(),0.0);
145 
146  const char *ptrmuPath1 = triggerPathName1_.c_str(); //
147  const char *ptrmuPath2 = triggerPathName2_.c_str(); //
148  if(patMuon.pt() > triggerPtThresholdPath1_){
149  h_totalHLTPath1_eta_Tight->Fill(patMuon.eta());
150  h_totalHLTPath1_pt_Tight->Fill(patMuon.pt());
151  h_totalHLTPath1_phi_Tight->Fill(patMuon.phi());
152  }
153  if(patMuon.pt() > triggerPtThresholdPath2_){
154  h_totalHLTPath2_eta_Tight->Fill(patMuon.eta());
155  h_totalHLTPath2_pt_Tight->Fill(patMuon.pt());
156  h_totalHLTPath2_phi_Tight->Fill(patMuon.phi());
157  }
158  if(patMuon.triggered(ptrmuPath1) && patMuon.hltObject() !=nullptr){
159  TLorentzVector hltMuon;
160  hltMuon.SetPtEtaPhiM(patMuon.hltObject()->pt(),patMuon.hltObject()->eta(),patMuon.hltObject()->phi(),0.0);
161  double DelRrecoHLT=offlineMuon.DeltaR(hltMuon);
162 
163  matchHists[0]->Fill(DelRrecoHLT);
164  matchHists[1]->Fill(DelRrecoHLT);
165  matchHists[2]->Fill(patMuon.hltObject()->pt()/patMuon.pt());
166  if(DelRrecoHLT<0.2 && patMuon.pt() > triggerPtThresholdPath1_){
167  h_passHLTPath1_eta_Tight->Fill(patMuon.eta());
168  h_passHLTPath1_pt_Tight->Fill(patMuon.pt());
169  h_passHLTPath1_phi_Tight->Fill(patMuon.phi());
170  }
171  if(patMuon.l1Object() !=nullptr){
172  TLorentzVector L1Muon;
173  L1Muon.SetPtEtaPhiM(patMuon.l1Object()->pt(),patMuon.l1Object()->eta(),patMuon.l1Object()->phi(),0.0);
174  double DelRrecoL1=offlineMuon.DeltaR(L1Muon);
175  matchHists[3]->Fill(DelRrecoL1);
176  matchHists[4]->Fill(DelRrecoL1);
177  matchHists[5]->Fill(patMuon.l1Object()->pt()/patMuon.pt());
178  }
179 
180  }
181 
183  if(patMuon.triggered(ptrmuPath2)){
184  TLorentzVector hltMuon50;
185  hltMuon50.SetPtEtaPhiM(patMuon.hltObject()->pt(),patMuon.hltObject()->eta(),patMuon.hltObject()->phi(),0.0);
186  double DelRrecoHLT50=offlineMuon.DeltaR(hltMuon50);
187 
188  matchHists[6]->Fill(DelRrecoHLT50);
189  matchHists[7]->Fill(DelRrecoHLT50);
190  matchHists[8]->Fill(patMuon.hltObject()->pt()/patMuon.pt());
191  if(DelRrecoHLT50<0.2 && patMuon.pt() > triggerPtThresholdPath2_ ){
192  h_passHLTPath2_eta_Tight->Fill(patMuon.eta());
193  h_passHLTPath2_pt_Tight->Fill(patMuon.pt());
194  h_passHLTPath2_phi_Tight->Fill(patMuon.phi());
195  }
196 
197 
198  if(patMuon.l1Object() !=nullptr){
199  TLorentzVector L1Muon50;
200  L1Muon50.SetPtEtaPhiM(patMuon.l1Object()->pt(),patMuon.l1Object()->eta(),patMuon.l1Object()->phi(),0.0);
201  double DelRrecoL150=offlineMuon.DeltaR(L1Muon50);
202  matchHists[9]->Fill(DelRrecoL150);
203  matchHists[10]->Fill(DelRrecoL150);
204  matchHists[11]->Fill(patMuon.l1Object()->pt()/patMuon.pt());
205  }
206  }
207  }//isolated tight muon
208  } //pat muon loop
209  } //valid pat muon
210 
211 }
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
const std::string metname
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:43
int iEvent
Definition: GenABIO.cc:224
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:45
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:45