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