CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1TEfficiencyMuons_Offline.cc
Go to the documentation of this file.
1  /*
2  * \file L1TEfficiencyMuons_Offline.cc
3  *
4  * $Date: 2013/03/18 17:17:53 $
5  * $Revision: 1.2 $
6  * \author J. Pela, C. Battilana
7  *
8  */
9 
11 
13 
15 
17 
20 
21  #include "TMath.h"
22 
23  using namespace reco;
24  using namespace trigger;
25  using namespace edm;
26  using namespace std;
27 
28 
29 //__________RECO-GMT Muon Pair Helper Class____________________________
30 
32 
33  m_muon = muonGmtPair.m_muon;
34  m_gmt = muonGmtPair.m_gmt;
35  m_eta = muonGmtPair.m_eta;
36  m_phi_bar = muonGmtPair.m_phi_bar;
37  m_phi_end = muonGmtPair.m_phi_end;
38 
39 }
40 
41 
42 double MuonGmtPair::dR() {
43 
44  float dEta = m_gmt ? (m_gmt->etaValue() - eta()) : 999.;
45  float dPhi = m_gmt ? (m_gmt->phiValue() - phi()) : 999.;
46 
47  float dr = sqrt(dEta*dEta + dPhi*dPhi);
48 
49  return dr;
50 
51 }
52 
53 
55  ESHandle<Propagator> propagatorAlong,
56  ESHandle<Propagator> propagatorOpposite) {
57 
58  m_BField = bField;
59  m_propagatorAlong = propagatorAlong;
60  m_propagatorOpposite = propagatorOpposite;
61 
62  TrackRef standaloneMuon = m_muon->outerTrack();
63 
64  TrajectoryStateOnSurface trajectory;
65  trajectory = cylExtrapTrkSam(standaloneMuon, 500); // track at MB2 radius - extrapolation
66  if (trajectory.isValid()) {
67  m_eta = trajectory.globalPosition().eta();
68  m_phi_bar = trajectory.globalPosition().phi();
69  }
70 
71  trajectory = surfExtrapTrkSam(standaloneMuon, 790); // track at ME2+ plane - extrapolation
72  if (trajectory.isValid()) {
73  m_eta = trajectory.globalPosition().eta();
74  m_phi_end = trajectory.globalPosition().phi();
75  }
76 
77  trajectory = surfExtrapTrkSam(standaloneMuon, -790); // track at ME2- disk - extrapolation
78  if (trajectory.isValid()) {
79  m_eta = trajectory.globalPosition().eta();
80  m_phi_end = trajectory.globalPosition().phi();
81  }
82 
83 }
84 
85 
87 {
88 
89  Cylinder::PositionType pos(0, 0, 0);
91  Cylinder::CylinderPointer myCylinder = Cylinder::build(pos, rot, rho);
92 
93  FreeTrajectoryState recoStart = freeTrajStateMuon(track);
94  TrajectoryStateOnSurface recoProp;
95  recoProp = m_propagatorAlong->propagate(recoStart, *myCylinder);
96  if (!recoProp.isValid()) {
97  recoProp = m_propagatorOpposite->propagate(recoStart, *myCylinder);
98  }
99  return recoProp;
100 
101 }
102 
103 
105 {
106 
107  Plane::PositionType pos(0, 0, z);
109  Plane::PlanePointer myPlane = Plane::build(pos, rot);
110 
111  FreeTrajectoryState recoStart = freeTrajStateMuon(track);
112  TrajectoryStateOnSurface recoProp;
113  recoProp = m_propagatorAlong->propagate(recoStart, *myPlane);
114  if (!recoProp.isValid()) {
115  recoProp = m_propagatorOpposite->propagate(recoStart, *myPlane);
116  }
117  return recoProp;
118 }
119 
120 
122 {
123 
124  GlobalPoint innerPoint(track->innerPosition().x(), track->innerPosition().y(), track->innerPosition().z());
125  GlobalVector innerVec (track->innerMomentum().x(), track->innerMomentum().y(), track->innerMomentum().z());
126 
127  FreeTrajectoryState recoStart(innerPoint, innerVec, track->charge(), &*m_BField);
128 
129  return recoStart;
130 
131 }
132 
133 
134 //__________DQM_base_class_______________________________________________
136 
137  if (m_verbose) {
138  cout << "[L1TEfficiencyMuons_Offline:] ____________ Storage initialization ____________ " << endl;
139  }
140 
141  // Initializing DQM Store
142  dbe = Service<DQMStore>().operator->();
143  dbe->setVerbose(0);
144  if (m_verbose) {cout << "[L1TEfficiencyMuons_Offline:] Pointer for DQM Store: " << dbe << endl;}
145 
146  // Initializing config params
147  m_GmtPtCuts = ps.getUntrackedParameter< vector<int> >("gmtPtCuts");
148 
149  m_MuonInputTag = ps.getUntrackedParameter<InputTag>("muonInputTag");
150  m_GmtInputTag = ps.getUntrackedParameter<InputTag>("gmtInputTag");
151 
152  m_VtxInputTag = ps.getUntrackedParameter<InputTag>("vtxInputTag");
153  m_BsInputTag = ps.getUntrackedParameter<InputTag>("bsInputTag");
154 
155  m_trigInputTag = ps.getUntrackedParameter<InputTag>("trigInputTag");
156  m_trigProcess = ps.getUntrackedParameter<string>("trigProcess");
157  m_trigNames = ps.getUntrackedParameter<vector<string> >("triggerNames");
158 
159  // CB do we need them from cfi?
160  m_MaxMuonEta = 2.4;
161  m_MaxGmtMuonDR = 0.7;
162  m_MaxHltMuonDR = 0.1;
163  // CB ignored at present
164  //m_MinMuonDR = 1.2;
165 
166 }
167 
168 
169 //_____________________________________________________________________
171 
172 
173 //_____________________________________________________________________
175 
176  if (m_verbose) {cout << "[L1TEfficiencyMuons_Offline:] Called beginJob." << endl;}
177 
178  bookControlHistos();
179 
180  vector<int>::const_iterator gmtPtCutsIt = m_GmtPtCuts.begin();
181  vector<int>::const_iterator gmtPtCutsEnd = m_GmtPtCuts.end();
182 
183  for (; gmtPtCutsIt!=gmtPtCutsEnd; ++ gmtPtCutsIt) {
184  bookEfficiencyHistos((*gmtPtCutsIt));
185  }
186 
187 }
188 
189 
190 //_____________________________________________________________________
192 
193  if (m_verbose) {cout << "[L1TEfficiencyMuons_Offline:] Called endJob." << endl;}
194 
195 }
196 
197 
198 //_____________________________________________________________________
200 
201  if (m_verbose) {cout << "[L1TEfficiencyMuons_Offline:] Called beginRun." << endl;}
202 
203  bool changed = true;
204 
205  m_hltConfig.init(run,iSetup,m_trigProcess,changed);
206 
207  vector<string>::const_iterator trigNamesIt = m_trigNames.begin();
208  vector<string>::const_iterator trigNamesEnd = m_trigNames.end();
209 
210  for (; trigNamesIt!=trigNamesEnd; ++trigNamesIt) {
211 
212  TString tNameTmp = TString(*trigNamesIt); // use TString as it handles regex
213  TRegexp tNamePattern = TRegexp(tNameTmp,true);
214  int tIndex = -1;
215 
216  for (unsigned ipath = 0; ipath < m_hltConfig.size(); ++ipath) {
217 
218  TString tmpName = TString(m_hltConfig.triggerName(ipath));
219  if (tmpName.Contains(tNamePattern)) {
220  tIndex = int(ipath);
221  m_trigIndices.push_back(tIndex);
222  }
223 
224  }
225 
226  if (tIndex < 0 && m_verbose) {
227  cout << "[L1TEfficiencyMuons_Offline:] Warning: Could not find trigger "
228  << (*trigNamesIt) << endl;
229  }
230 
231  }
232 
233 }
234 
235 
236 //_____________________________________________________________________
238 
239  if (m_verbose) {cout << "[L1TEfficiencyMuons_Offline:] Called endRun." << endl;}
240 
241 }
242 
243 
244 //_____________________________________________________________________
246 
247  if(m_verbose){
248  cout << "[L1TEfficiencyMuons_Offline:] Called beginLuminosityBlock at LS="
249  << lumiBlock.id().luminosityBlock() << endl;
250  }
251 
252 }
253 
254 
255 //_____________________________________________________________________
257 
258  if(m_verbose){
259  cout << "[L1TEfficiencyMuons_Offline:] Called endLuminosityBlock at LS="
260  << lumiBlock.id().luminosityBlock() << endl;
261  }
262 
263 }
264 
265 
266 //_____________________________________________________________________
267 void L1TEfficiencyMuons_Offline::analyze(const Event & iEvent, const EventSetup & eventSetup){
268 
270  iEvent.getByLabel(m_MuonInputTag, muons);
271 
273  iEvent.getByLabel(m_BsInputTag, beamSpot);
274 
276  iEvent.getByLabel(m_VtxInputTag, vertex);
277 
279  iEvent.getByLabel(m_GmtInputTag,gmtCands);
280 
281  Handle<edm::TriggerResults> trigResults;
282  iEvent.getByLabel(InputTag("TriggerResults","",m_trigProcess),trigResults);
283 
285  iEvent.getByLabel(m_trigInputTag,trigEvent);
286 
287  eventSetup.get<IdealMagneticFieldRecord>().get(m_BField);
288 
289  eventSetup.get<TrackingComponentsRecord>().get("SmartPropagatorAny",m_propagatorAlong);
290  eventSetup.get<TrackingComponentsRecord>().get("SmartPropagatorAnyOpposite",m_propagatorOpposite);
291 
292  const Vertex primaryVertex = getPrimaryVertex(vertex,beamSpot);
293 
294  getTightMuons(muons,primaryVertex);
295  getProbeMuons(trigResults,trigEvent); // CB add flag to run on orthogonal datasets (no T&P)
296  getMuonGmtPairs(gmtCands);
297 
298  cout << "[L1TEfficiencyMuons_Offline:] Computing efficiencies" << endl;
299 
300  vector<MuonGmtPair>::const_iterator muonGmtPairsIt = m_MuonGmtPairs.begin();
301  vector<MuonGmtPair>::const_iterator muonGmtPairsEnd = m_MuonGmtPairs.end();
302 
303  for(; muonGmtPairsIt!=muonGmtPairsEnd; ++muonGmtPairsIt) {
304 
305  float eta = muonGmtPairsIt->eta();
306  float phi = muonGmtPairsIt->phi();
307  float pt = muonGmtPairsIt->pt();
308 
309  // unmatched gmt cands have gmtPt = -1.
310  float gmtPt = muonGmtPairsIt->gmtPt();
311 
312  vector<int>::const_iterator gmtPtCutsIt = m_GmtPtCuts.begin();
313  vector<int>::const_iterator gmtPtCutsEnd = m_GmtPtCuts.end();
314 
315  for (; gmtPtCutsIt!=gmtPtCutsEnd; ++ gmtPtCutsIt) {
316 
317  int gmtPtCut = (*gmtPtCutsIt);
318  bool gmtAboveCut = (gmtPt > gmtPtCut);
319 
320  stringstream ptCutToTag; ptCutToTag << gmtPtCut;
321  string ptTag = ptCutToTag.str();
322 
323  if (fabs(eta) < m_MaxMuonEta) {
324 
325  m_EfficiencyHistos[gmtPtCut]["EffvsPt" + ptTag + "Den"]->Fill(pt);
326  if (gmtAboveCut) m_EfficiencyHistos[gmtPtCut]["EffvsPt" + ptTag + "Num"]->Fill(pt);
327 
328  if (pt > gmtPtCut + 8.) { // efficiency in eta/phi at plateau
329 
330  m_EfficiencyHistos[gmtPtCut]["EffvsPhi" + ptTag + "Den"]->Fill(phi);
331  m_EfficiencyHistos[gmtPtCut]["EffvsEta" + ptTag + "Den"]->Fill(eta);
332 
333  if (gmtAboveCut) {
334  m_EfficiencyHistos[gmtPtCut]["EffvsPhi" + ptTag + "Num"]->Fill(phi);
335  m_EfficiencyHistos[gmtPtCut]["EffvsEta" + ptTag + "Num"]->Fill(eta);
336  }
337  }
338  }
339  }
340  }
341 
342  cout << "[L1TEfficiencyMuons_Offline:] Computation finished" << endl;
343 
344 
345 }
346 
347 
348 //_____________________________________________________________________
350 
351  if(m_verbose){cout << "[L1TEfficiencyMuons_Offline:] Booking Control Plot Histos" << endl;}
352 
353  dbe->setCurrentFolder("L1T/Efficiency/Muons/Control");
354 
355  string name = "MuonGmtDeltaR";
356  m_ControlHistos[name] = dbe->book1D(name.c_str(),name.c_str(),25.,0.,2.5);
357 
358  name = "NTightVsAll";
359  m_ControlHistos[name] = dbe->book2D(name.c_str(),name.c_str(),5,-0.5,4.5,5,-0.5,4.5);
360 
361  name = "NProbesVsTight";
362  m_ControlHistos[name] = dbe->book2D(name.c_str(),name.c_str(),5,-0.5,4.5,5,-0.5,4.5);
363 
364 }
365 
366 
367 //_____________________________________________________________________
369 
370  if(m_verbose){
371  cout << "[L1TEfficiencyMuons_Offline:] Booking Efficiency Plot Histos for pt cut = "
372  << ptCut << endl;
373  }
374 
375  stringstream ptCutToTag; ptCutToTag << ptCut;
376  string ptTag = ptCutToTag.str();
377 
378  dbe->setCurrentFolder("L1T/Efficiency/Muons/");
379 
380  string effTag[2] = {"Den", "Num"};
381 
382  for(int iEffTag=0; iEffTag<2; ++ iEffTag) {
383  string name = "EffvsPt" + ptTag + effTag[iEffTag];
384  m_EfficiencyHistos[ptCut][name] = dbe->book1D(name.c_str(),name.c_str(),16,0.,40.);
385 
386  name = "EffvsPhi" + ptTag + effTag[iEffTag];
387  m_EfficiencyHistos[ptCut][name] = dbe->book1D(name.c_str(),name.c_str(),12,0.,2*TMath::Pi());
388 
389  name = "EffvsEta" + ptTag + effTag[iEffTag];
390  m_EfficiencyHistos[ptCut][name] = dbe->book1D(name.c_str(),name.c_str(),12,-2.4,2.4);
391  }
392 
393 }
394 
395 
396 //_____________________________________________________________________
399 
400  Vertex::Point posVtx;
401  Vertex::Error errVtx;
402 
403  bool hasPrimaryVertex = false;
404 
405  if (vertex.isValid())
406  {
407 
408  vector<Vertex>::const_iterator vertexIt = vertex->begin();
409  vector<Vertex>::const_iterator vertexEnd = vertex->end();
410 
411  for (;vertexIt!=vertexEnd;++vertexIt)
412  {
413  if (vertexIt->isValid() &&
414  !vertexIt->isFake())
415  {
416  posVtx = vertexIt->position();
417  errVtx = vertexIt->error();
418  hasPrimaryVertex = true;
419  break;
420  }
421  }
422  }
423 
424  if ( !hasPrimaryVertex ) {
425 
426  if(m_verbose){
427  cout << "[L1TEfficiencyMuons_Offline:] PrimaryVertex not found, use BeamSpot position instead" << endl;
428  }
429 
430  posVtx = beamSpot->position();
431  errVtx(0,0) = beamSpot->BeamWidthX();
432  errVtx(1,1) = beamSpot->BeamWidthY();
433  errVtx(2,2) = beamSpot->sigmaZ();
434 
435  }
436 
437  const Vertex primaryVertex(posVtx,errVtx);
438 
439  return primaryVertex;
440 
441 }
442 
443 
444 //_____________________________________________________________________
446  const Vertex & vertex) {
447 
448  cout << "[L1TEfficiencyMuons_Offline:] Getting tight muons" << endl;
449 
450  m_TightMuons.clear();
451 
452  MuonCollection::const_iterator muonIt = muons->begin();
453  MuonCollection::const_iterator muonEnd = muons->end();
454 
455  for(; muonIt!=muonEnd; ++muonIt) {
456  if (muon::isTightMuon((*muonIt), vertex)) {
457  m_TightMuons.push_back(&(*muonIt));
458  }
459  }
460 
461  m_ControlHistos["NTightVsAll"]->Fill(muons->size(),m_TightMuons.size());
462 
463 }
464 
465 
466 //_____________________________________________________________________
469 
470  cout << "[L1TEfficiencyMuons_Offline:] getting probe muons" << endl;
471 
472  m_ProbeMuons.clear();
473 
474  vector<const Muon*>::const_iterator probeCandIt = m_TightMuons.begin();
475  vector<const Muon*>::const_iterator tightMuonsEnd = m_TightMuons.end();
476 
477  for (; probeCandIt!=tightMuonsEnd; ++probeCandIt) {
478 
479  bool tagHasTrig = false;
480  vector<const Muon*>::const_iterator tagCandIt = m_TightMuons.begin();
481 
482  for (; tagCandIt!=tightMuonsEnd; ++tagCandIt) {
483  if ((*tagCandIt) == (*probeCandIt)) continue; // CB has a little bias for closed-by muons
484  tagHasTrig |= matchHlt(trigEvent,(*tagCandIt));
485  }
486 
487  if (tagHasTrig) m_ProbeMuons.push_back((*probeCandIt));
488 
489  }
490 
491  m_ControlHistos["NProbesVsTight"]->Fill(m_TightMuons.size(),m_ProbeMuons.size());
492 
493 }
494 
495 //_____________________________________________________________________
497 
498  m_MuonGmtPairs.clear();
499 
500  cout << "[L1TEfficiencyMuons_Offline:] Getting muon GMT pairs" << endl;
501 
502  vector<const Muon*>::const_iterator probeMuIt = m_ProbeMuons.begin();
503  vector<const Muon*>::const_iterator probeMuEnd = m_ProbeMuons.end();
504 
505  vector<L1MuGMTExtendedCand> gmtContainer = gmtCands->getRecord(0).getGMTCands();
506 
507  vector<L1MuGMTExtendedCand>::const_iterator gmtIt;
508  vector<L1MuGMTExtendedCand>::const_iterator gmtEnd = gmtContainer.end();
509 
510  for (; probeMuIt!=probeMuEnd; ++probeMuIt) {
511 
512  MuonGmtPair pairBestCand((*probeMuIt),0);
513  pairBestCand.propagate(m_BField,m_propagatorAlong,m_propagatorOpposite);
514 
515  gmtIt = gmtContainer.begin();
516 
517  for(; gmtIt!=gmtEnd; ++gmtIt) {
518 
519  MuonGmtPair pairTmpCand((*probeMuIt),&(*gmtIt));
520  pairTmpCand.propagate(m_BField,m_propagatorAlong,m_propagatorOpposite);
521 
522  if (pairTmpCand.dR() < m_MaxGmtMuonDR && pairTmpCand.gmtPt() > pairBestCand.gmtPt())
523  pairBestCand = pairTmpCand;
524 
525  }
526 
527  m_MuonGmtPairs.push_back(pairBestCand);
528 
529  m_ControlHistos["MuonGmtDeltaR"]->Fill(pairBestCand.dR());
530 
531  }
532 
533 }
534 
535 //_____________________________________________________________________
537 
538 
539  double matchDeltaR = 9999;
540 
541  TriggerObjectCollection trigObjs = triggerEvent->getObjects();
542 
543  vector<int>::const_iterator trigIndexIt = m_trigIndices.begin();
544  vector<int>::const_iterator trigIndexEnd = m_trigIndices.end();
545 
546  for(; trigIndexIt!=trigIndexEnd; ++trigIndexIt) {
547 
548  const vector<string> moduleLabels(m_hltConfig.moduleLabels(*trigIndexIt));
549  const unsigned moduleIndex = m_hltConfig.size((*trigIndexIt))-2;
550  const unsigned hltFilterIndex = triggerEvent->filterIndex(InputTag(moduleLabels[moduleIndex],
551  "",m_trigProcess));
552 
553  if (hltFilterIndex < triggerEvent->sizeFilters()) {
554  const Keys triggerKeys(triggerEvent->filterKeys(hltFilterIndex));
555  const Vids triggerVids(triggerEvent->filterIds(hltFilterIndex));
556 
557  const unsigned nTriggers = triggerVids.size();
558  for (size_t iTrig = 0; iTrig < nTriggers; ++iTrig) {
559  const TriggerObject trigObject = trigObjs[triggerKeys[iTrig]];
560 
561  double dRtmp = deltaR((*mu),trigObject);
562  if (dRtmp < matchDeltaR) matchDeltaR = dRtmp;
563 
564  }
565  }
566  }
567 
568  return (matchDeltaR < m_MaxHltMuonDR);
569 
570 }
571 
572 
573 //define this as a plug-in
LuminosityBlockID id() const
TkRotation< Scalar > RotationType
Definition: Definitions.h:29
const double Pi
T getUntrackedParameter(std::string const &, T const &) const
MuonGmtPair(const reco::Muon *muon, const L1MuGMTExtendedCand *gmt)
void getTightMuons(edm::Handle< reco::MuonCollection > &muons, const reco::Vertex &vertex)
virtual void endLuminosityBlock(edm::LuminosityBlock const &lumiBlock, edm::EventSetup const &c)
const reco::Vertex getPrimaryVertex(edm::Handle< reco::VertexCollection > &vertex, edm::Handle< reco::BeamSpot > &beamSpot)
double gmtPt() const
virtual void beginLuminosityBlock(edm::LuminosityBlock const &lumiBlock, edm::EventSetup const &c)
Definition: DDAxes.h:10
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
math::Error< dimension >::type Error
covariance error matrix (3x3)
Definition: Vertex.h:44
GlobalPoint globalPosition() const
T eta() const
float float float z
const L1MuGMTExtendedCand * m_gmt
void beginRun(const edm::Run &run, const edm::EventSetup &iSetup)
Point3DBase< Scalar, GlobalTag > PositionType
Definition: Definitions.h:30
Single trigger physics object (e.g., an isolated muon)
Definition: TriggerObject.h:24
int iEvent
Definition: GenABIO.cc:243
double dPhi(double phi1, double phi2)
Definition: JetUtil.h:30
T sqrt(T t)
Definition: SSEVec.h:48
static PlanePointer build(Args &&...args)
Definition: Plane.h:36
TrajectoryStateOnSurface cylExtrapTrkSam(reco::TrackRef track, double rho)
const reco::Muon * m_muon
auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
math::XYZPoint Point
point in the space
Definition: Vertex.h:40
L1TEfficiencyMuons_Offline(const edm::ParameterSet &ps)
void getMuonGmtPairs(edm::Handle< L1MuGMTReadoutCollection > &gmtCands)
const int mu
Definition: Constants.h:23
void getProbeMuons(edm::Handle< edm::TriggerResults > &trigResults, edm::Handle< trigger::TriggerEvent > &trigEvent)
bool isValid() const
Definition: HandleBase.h:76
void endRun(const edm::Run &run, const edm::EventSetup &iSetup)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
void analyze(const edm::Event &e, const edm::EventSetup &c)
std::vector< TriggerObject > TriggerObjectCollection
collection of trigger physics objects (e.g., all isolated muons)
Definition: TriggerObject.h:83
DEFINE_FWK_MODULE(CosmicTrackingParticleSelector)
FreeTrajectoryState freeTrajStateMuon(reco::TrackRef track)
void propagate(edm::ESHandle< MagneticField > bField, edm::ESHandle< Propagator > propagatorAlong, edm::ESHandle< Propagator > propagatorOpposite)
std::vector< size_type > Keys
TrajectoryStateOnSurface surfExtrapTrkSam(reco::TrackRef track, double z)
const T & get() const
Definition: EventSetup.h:55
LuminosityBlockNumber_t luminosityBlock() const
T eta() const
Definition: PV3DBase.h:76
tuple muons
Definition: patZpeak.py:38
tuple cout
Definition: gather_cfg.py:121
bool matchHlt(edm::Handle< trigger::TriggerEvent > &triggerEvent, const reco::Muon *mu)
bool isTightMuon(const reco::Muon &, const reco::Vertex &)
std::vector< int > Vids
Definition: Run.h:36
Definition: DDAxes.h:10