CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MuonRecoOneHLT.cc
Go to the documentation of this file.
2 
4 
5 #include <string>
6 #include "TMath.h"
7 using namespace std;
8 using namespace edm;
9 
10 // Uncomment to DEBUG
11 //#define DEBUG
12 
14  parameters = pSet;
15 
16  ParameterSet muonparms = parameters.getParameter<edm::ParameterSet>("SingleMuonTrigger");
17  ParameterSet dimuonparms = parameters.getParameter<edm::ParameterSet>("DoubleMuonTrigger");
18  _SingleMuonEventFlag = new GenericTriggerEventFlag(muonparms, consumesCollector(), *this, l1t::UseEventSetupIn::Run);
19  _DoubleMuonEventFlag =
20  new GenericTriggerEventFlag(dimuonparms, consumesCollector(), *this, l1t::UseEventSetupIn::Run);
21 
22  // Trigger Expresions in case de connection to the DB fails
23  singlemuonExpr_ = muonparms.getParameter<std::vector<std::string> >("hltPaths");
24  doublemuonExpr_ = dimuonparms.getParameter<std::vector<std::string> >("hltPaths");
25 
26  theMuonCollectionLabel_ = consumes<reco::MuonCollection>(parameters.getParameter<edm::InputTag>("MuonCollection"));
27  theVertexLabel_ = consumes<reco::VertexCollection>(parameters.getParameter<edm::InputTag>("VertexLabel"));
28  theBeamSpotLabel_ = mayConsume<reco::BeamSpot>(parameters.getParameter<edm::InputTag>("BeamSpotLabel"));
29  theTriggerResultsLabel_ = consumes<TriggerResults>(parameters.getParameter<InputTag>("TriggerResultsLabel"));
30 
31  // Parameters
32  etaBin = parameters.getParameter<int>("etaBin");
33  etaMin = parameters.getParameter<double>("etaMin");
34  etaMax = parameters.getParameter<double>("etaMax");
35  ptBin = parameters.getParameter<int>("ptBin");
36  ptMin = parameters.getParameter<double>("ptMin");
37  ptMax = parameters.getParameter<double>("ptMax");
38  chi2Bin = parameters.getParameter<int>("chi2Bin");
39  chi2Min = parameters.getParameter<double>("chi2Min");
40  chi2Max = parameters.getParameter<double>("chi2Max");
41  phiBin = parameters.getParameter<int>("phiBin");
42  phiMin = parameters.getParameter<double>("phiMin");
43  phiMax = parameters.getParameter<double>("phiMax");
44 }
46  delete _SingleMuonEventFlag;
47  delete _DoubleMuonEventFlag;
48 }
49 void MuonRecoOneHLT::bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const& iSetup) {
50 #ifdef DEBUG
51  cout << "[MuonRecoOneHLT] beginRun " << endl;
52  cout << "[MuonRecoOneHLT] Is MuonEventFlag On? " << _SingleMuonEventFlag->on() << endl;
53 #endif
54 
55  ibooker.cd();
56  ibooker.setCurrentFolder("Muons/MuonRecoOneHLT");
57 
58  muReco = ibooker.book1D("Muon_Reco", "Muon Reconstructed Tracks", 6, 1, 7);
59  muReco->setBinLabel(1, "glb+tk+sta");
60  muReco->setBinLabel(2, "glb+sta");
61  muReco->setBinLabel(3, "tk+sta");
62  muReco->setBinLabel(4, "tk");
63  muReco->setBinLabel(5, "sta");
64  muReco->setBinLabel(6, "calo");
65 
66  // monitoring of eta parameter
67  std::string histname = "GlbMuon_";
68  etaGlbTrack.push_back(ibooker.book1D(histname + "Glb_eta", "#eta_{GLB}", etaBin, etaMin, etaMax));
69  etaGlbTrack.push_back(ibooker.book1D(histname + "Tk_eta", "#eta_{TKfromGLB}", etaBin, etaMin, etaMax));
70  etaGlbTrack.push_back(ibooker.book1D(histname + "Sta_eta", "#eta_{STAfromGLB}", etaBin, etaMin, etaMax));
71  etaTight = ibooker.book1D("TightMuon_eta", "#eta_{GLB}", etaBin, etaMin, etaMax);
72  etaTrack = ibooker.book1D("TkMuon_eta", "#eta_{TK}", etaBin, etaMin, etaMax);
73  etaStaTrack = ibooker.book1D("StaMuon_eta", "#eta_{STA}", etaBin, etaMin, etaMax);
74 
75  // monitoring of phi paramater
76  phiGlbTrack.push_back(ibooker.book1D(histname + "Glb_phi", "#phi_{GLB}", phiBin, phiMin, phiMax));
77  phiGlbTrack[0]->setAxisTitle("rad");
78  phiGlbTrack.push_back(ibooker.book1D(histname + "Tk_phi", "#phi_{TKfromGLB}", phiBin, phiMin, phiMax));
79  phiGlbTrack[1]->setAxisTitle("rad");
80  phiGlbTrack.push_back(ibooker.book1D(histname + "Sta_phi", "#phi_{STAfromGLB}", phiBin, phiMin, phiMax));
81  phiGlbTrack[2]->setAxisTitle("rad");
82  phiTight = ibooker.book1D("TightMuon_phi", "#phi_{GLB}", phiBin, phiMin, phiMax);
83  phiTrack = ibooker.book1D("TkMuon_phi", "#phi_{TK}", phiBin, phiMin, phiMax);
84  phiTrack->setAxisTitle("rad");
85  phiStaTrack = ibooker.book1D("StaMuon_phi", "#phi_{STA}", phiBin, phiMin, phiMax);
86  phiStaTrack->setAxisTitle("rad");
87 
88  // monitoring of the chi2 parameter
89  chi2OvDFGlbTrack.push_back(
90  ibooker.book1D(histname + "Glb_chi2OverDf", "#chi_{2}OverDF_{GLB}", chi2Bin, chi2Min, chi2Max));
91  chi2OvDFGlbTrack.push_back(
92  ibooker.book1D(histname + "Tk_chi2OverDf", "#chi_{2}OverDF_{TKfromGLB}", phiBin, chi2Min, chi2Max));
93  chi2OvDFGlbTrack.push_back(
94  ibooker.book1D(histname + "Sta_chi2OverDf", "#chi_{2}OverDF_{STAfromGLB}", chi2Bin, chi2Min, chi2Max));
95  chi2OvDFTight = ibooker.book1D("TightMuon_chi2OverDf", "#chi_{2}OverDF_{GLB}", chi2Bin, chi2Min, chi2Max);
96  chi2OvDFTrack = ibooker.book1D("TkMuon_chi2OverDf", "#chi_{2}OverDF_{TK}", chi2Bin, chi2Min, chi2Max);
97  chi2OvDFStaTrack = ibooker.book1D("StaMuon_chi2OverDf", "#chi_{2}OverDF_{STA}", chi2Bin, chi2Min, chi2Max);
98 
99  // monitoring of the transverse momentum
100  ptGlbTrack.push_back(ibooker.book1D(histname + "Glb_pt", "pt_{GLB}", ptBin, ptMin, ptMax));
101  ptGlbTrack[0]->setAxisTitle("GeV");
102  ptGlbTrack.push_back(ibooker.book1D(histname + "Tk_pt", "pt_{TKfromGLB}", ptBin, ptMin, ptMax));
103  ptGlbTrack[1]->setAxisTitle("GeV");
104  ptGlbTrack.push_back(ibooker.book1D(histname + "Sta_pt", "pt_{STAfromGLB}", ptBin, ptMin, ptMax));
105  ptGlbTrack[2]->setAxisTitle("GeV");
106  ptTight = ibooker.book1D("TightMuon_pt", "pt_{GLB}", ptBin, ptMin, ptMax);
107  ptTight->setAxisTitle("GeV");
108  ptTrack = ibooker.book1D("TkMuon_pt", "pt_{TK}", ptBin, ptMin, ptMax);
109  ptTrack->setAxisTitle("GeV");
110  ptStaTrack = ibooker.book1D("StaMuon_pt", "pt_{STA}", ptBin, ptMin, ptMax);
111  ptStaTrack->setAxisTitle("GeV");
112 
113  if (_SingleMuonEventFlag->on())
114  _SingleMuonEventFlag->initRun(iRun, iSetup);
115  if (_DoubleMuonEventFlag->on())
116  _DoubleMuonEventFlag->initRun(iRun, iSetup);
117 
118  if (_SingleMuonEventFlag->on() &&
119  _SingleMuonEventFlag->expressionsFromDB(_SingleMuonEventFlag->hltDBKey(), iSetup)[0] != "CONFIG_ERROR")
120  singlemuonExpr_ = _SingleMuonEventFlag->expressionsFromDB(_SingleMuonEventFlag->hltDBKey(), iSetup);
121  if (_DoubleMuonEventFlag->on() &&
122  _DoubleMuonEventFlag->expressionsFromDB(_DoubleMuonEventFlag->hltDBKey(), iSetup)[0] != "CONFIG_ERROR")
123  singlemuonExpr_ = _DoubleMuonEventFlag->expressionsFromDB(_DoubleMuonEventFlag->hltDBKey(), iSetup);
124 }
126  // =================================================================================
127  // Look for the Primary Vertex (and use the BeamSpot instead, if you can't find it):
128  reco::Vertex::Point posVtx;
129  reco::Vertex::Error errVtx;
130  unsigned int theIndexOfThePrimaryVertex = 999.;
131 
133  iEvent.getByToken(theVertexLabel_, vertex);
134  if (vertex.isValid()) {
135  for (unsigned int ind = 0; ind < vertex->size(); ++ind) {
136  if ((*vertex)[ind].isValid() && !((*vertex)[ind].isFake())) {
137  theIndexOfThePrimaryVertex = ind;
138  break;
139  }
140  }
141  }
142 
143  if (theIndexOfThePrimaryVertex < 100) {
144  posVtx = ((*vertex)[theIndexOfThePrimaryVertex]).position();
145  errVtx = ((*vertex)[theIndexOfThePrimaryVertex]).error();
146  } else {
147  LogInfo("RecoMuonValidator") << "reco::PrimaryVertex not found, use BeamSpot position instead\n";
148 
149  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
150  iEvent.getByToken(theBeamSpotLabel_, recoBeamSpotHandle);
151  const reco::BeamSpot& bs = *recoBeamSpotHandle;
152 
153  posVtx = bs.position();
154  errVtx(0, 0) = bs.BeamWidthX();
155  errVtx(1, 1) = bs.BeamWidthY();
156  errVtx(2, 2) = bs.sigmaZ();
157  }
158 
159  const reco::Vertex vtx(posVtx, errVtx);
160 
161  // ==========================================================
162  // READ DATA:
164  iEvent.getByToken(theMuonCollectionLabel_, muons);
165 
167  iEvent.getByToken(theTriggerResultsLabel_, triggerResults);
168 
169  // check if muon collection is valid
170  if (!muons.isValid())
171  return;
172 
173  // Pick the leading lepton.
174  std::map<float, const reco::Muon*> muonMap;
175  for (reco::MuonCollection::const_iterator recoMu = muons->begin(); recoMu != muons->end(); ++recoMu) {
176  muonMap[recoMu->pt()] = &*recoMu;
177  }
178  std::vector<const reco::Muon*> LeadingMuon;
179  for (std::map<float, const reco::Muon*>::reverse_iterator rit = muonMap.rbegin(); rit != muonMap.rend(); ++rit) {
180  LeadingMuon.push_back((*rit).second);
181  }
182 
183  // Pick Trigger information.
184  const edm::TriggerNames& triggerNames = iEvent.triggerNames(*triggerResults);
185  const unsigned int nTrig(triggerNames.size());
186  bool _trig_SingleMu = false;
187  bool _trig_DoubleMu = false;
188  for (unsigned int i = 0; i < nTrig; ++i) {
189  if (triggerNames.triggerName(i).find(singlemuonExpr_[0].substr(0, singlemuonExpr_[0].rfind("_v") + 2)) !=
190  std::string::npos &&
191  triggerResults->accept(i))
192  _trig_SingleMu = true;
193  if (triggerNames.triggerName(i).find(doublemuonExpr_[0].substr(0, doublemuonExpr_[0].rfind("_v") + 2)) !=
194  std::string::npos &&
195  triggerResults->accept(i))
196  _trig_DoubleMu = true;
197  }
198 #ifdef DEBUG
199  cout << "[MuonRecoOneHLT] Trigger Fired ? " << (_trig_SingleMu || _trig_DoubleMu) << endl;
200 #endif
201 
202  if (!_trig_SingleMu && !_trig_DoubleMu)
203  return;
204  if (LeadingMuon.empty())
205  return;
206  // if (_MuonEventFlag->on() && !(_MuonEventFlag->accept(iEvent,iSetup))) return;
207 
208  // Check if Muon is Global
209  if ((*LeadingMuon[0]).isGlobalMuon()) {
210  LogTrace(metname) << "[MuonRecoOneHLT] The mu is global - filling the histos";
211  if ((*LeadingMuon[0]).isTrackerMuon() && (*LeadingMuon[0]).isStandAloneMuon())
212  muReco->Fill(1);
213  if (!((*LeadingMuon[0]).isTrackerMuon()) && (*LeadingMuon[0]).isStandAloneMuon())
214  muReco->Fill(2);
215  if (!(*LeadingMuon[0]).isStandAloneMuon())
216  LogTrace(metname) << "[MuonRecoOneHLT] ERROR: the mu is global but not standalone!";
217 
218  // get the track combinig the information from both the Tracker and the Spectrometer
219  reco::TrackRef recoCombinedGlbTrack = (*LeadingMuon[0]).combinedMuon();
220  // get the track using only the tracker data
221  reco::TrackRef recoTkGlbTrack = (*LeadingMuon[0]).track();
222  // get the track using only the mu spectrometer data
223  reco::TrackRef recoStaGlbTrack = (*LeadingMuon[0]).standAloneMuon();
224 
225  etaGlbTrack[0]->Fill(recoCombinedGlbTrack->eta());
226  etaGlbTrack[1]->Fill(recoTkGlbTrack->eta());
227  etaGlbTrack[2]->Fill(recoStaGlbTrack->eta());
228 
229  phiGlbTrack[0]->Fill(recoCombinedGlbTrack->phi());
230  phiGlbTrack[1]->Fill(recoTkGlbTrack->phi());
231  phiGlbTrack[2]->Fill(recoStaGlbTrack->phi());
232 
233  chi2OvDFGlbTrack[0]->Fill(recoCombinedGlbTrack->normalizedChi2());
234  chi2OvDFGlbTrack[1]->Fill(recoTkGlbTrack->normalizedChi2());
235  chi2OvDFGlbTrack[2]->Fill(recoStaGlbTrack->normalizedChi2());
236 
237  ptGlbTrack[0]->Fill(recoCombinedGlbTrack->pt());
238  ptGlbTrack[1]->Fill(recoTkGlbTrack->pt());
239  ptGlbTrack[2]->Fill(recoStaGlbTrack->pt());
240  }
241  // Check if Muon is Tight
242  if (muon::isTightMuon((*LeadingMuon[0]), vtx)) {
243  LogTrace(metname) << "[MuonRecoOneHLT] The mu is tracker only - filling the histos";
244 
245  reco::TrackRef recoCombinedGlbTrack = (*LeadingMuon[0]).combinedMuon();
246 
247  etaTight->Fill(recoCombinedGlbTrack->eta());
248  phiTight->Fill(recoCombinedGlbTrack->phi());
249  chi2OvDFTight->Fill(recoCombinedGlbTrack->normalizedChi2());
250  ptTight->Fill(recoCombinedGlbTrack->pt());
251  }
252 
253  // Check if Muon is Tracker but NOT Global
254  if ((*LeadingMuon[0]).isTrackerMuon() && !((*LeadingMuon[0]).isGlobalMuon())) {
255  LogTrace(metname) << "[MuonRecoOneHLT] The mu is tracker only - filling the histos";
256  if ((*LeadingMuon[0]).isStandAloneMuon())
257  muReco->Fill(3);
258  if (!((*LeadingMuon[0]).isStandAloneMuon()))
259  muReco->Fill(4);
260 
261  // get the track using only the tracker data
262  reco::TrackRef recoTrack = (*LeadingMuon[0]).track();
263 
264  etaTrack->Fill(recoTrack->eta());
265  phiTrack->Fill(recoTrack->phi());
266  chi2OvDFTrack->Fill(recoTrack->normalizedChi2());
267  ptTrack->Fill(recoTrack->pt());
268  }
269 
270  // Check if Muon is STA but NOT Global
271  if ((*LeadingMuon[0]).isStandAloneMuon() && !((*LeadingMuon[0]).isGlobalMuon())) {
272  LogTrace(metname) << "[MuonRecoOneHLT] The mu is STA only - filling the histos";
273  if (!((*LeadingMuon[0]).isTrackerMuon()))
274  muReco->Fill(5);
275 
276  // get the track using only the mu spectrometer data
277  reco::TrackRef recoStaTrack = (*LeadingMuon[0]).standAloneMuon();
278 
279  etaStaTrack->Fill(recoStaTrack->eta());
280  phiStaTrack->Fill(recoStaTrack->phi());
281  chi2OvDFStaTrack->Fill(recoStaTrack->normalizedChi2());
282  ptStaTrack->Fill(recoStaTrack->pt());
283  }
284  // Check if Muon is Only CaloMuon
285  if ((*LeadingMuon[0]).isCaloMuon() && !((*LeadingMuon[0]).isGlobalMuon()) && !((*LeadingMuon[0]).isTrackerMuon()) &&
286  !((*LeadingMuon[0]).isStandAloneMuon()))
287  muReco->Fill(6);
288 }
std::size_t size() const
Definition: TriggerNames.cc:59
__device__ WorkSpace float chi2Max
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
const std::string metname
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
constexpr float ptMin
void analyze(const edm::Event &, const edm::EventSetup &) override
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:44
tuple etaMin
Definition: Puppi_cff.py:46
Provides a code based selection for trigger and DCS information in order to have no failing filters i...
#define LogTrace(id)
edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const override
Definition: Event.cc:275
int iEvent
Definition: GenABIO.cc:224
math::XYZPoint Point
point in the space
Definition: Vertex.h:40
double BeamWidthX() const
beam width X
Definition: BeamSpot.h:82
static std::string const triggerResults
Definition: EdmProvDump.cc:44
bool isValid() const
Definition: HandleBase.h:70
virtual void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
Log< level::Info, false > LogInfo
MuonRecoOneHLT(const edm::ParameterSet &)
Constructor.
std::string const & triggerName(unsigned int index) const
Definition: TriggerNames.cc:50
double sigmaZ() const
sigma z
Definition: BeamSpot.h:76
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
double BeamWidthY() const
beam width Y
Definition: BeamSpot.h:84
~MuonRecoOneHLT() override
Destructor.
tuple muons
Definition: patZpeak.py:41
static int position[264][3]
Definition: ReadPGInfo.cc:289
tuple cout
Definition: gather_cfg.py:144
const Point & position() const
position
Definition: BeamSpot.h:59
bool isTightMuon(const reco::Muon &, const reco::Vertex &)
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
tuple etaMax
Definition: Puppi_cff.py:47
int etaBin(const l1t::HGCalMulticluster *cl)
Definition: Run.h:45
virtual void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)