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 
53  ESHandle<Propagator> propagatorAlong,
54  ESHandle<Propagator> propagatorOpposite) {
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 DQM Store
140  dbe = Service<DQMStore>().operator->();
141  dbe->setVerbose(0);
142  if (m_verbose) {cout << "[L1TEfficiencyMuons_Offline:] Pointer for DQM Store: " << dbe << endl;}
143 
144  // Initializing config params
145  m_GmtPtCuts = ps.getUntrackedParameter< vector<int> >("gmtPtCuts");
146 
147  m_MuonInputTag = consumes<reco::MuonCollection>(ps.getUntrackedParameter<InputTag>("muonInputTag"));
148  m_GmtInputTag = consumes<L1MuGMTReadoutCollection>(ps.getUntrackedParameter<InputTag>("gmtInputTag"));
149 
150  m_VtxInputTag = consumes<VertexCollection>(ps.getUntrackedParameter<InputTag>("vtxInputTag"));
151  m_BsInputTag = consumes<BeamSpot>(ps.getUntrackedParameter<InputTag>("bsInputTag"));
152 
153  m_trigInputTag = consumes<trigger::TriggerEvent>(ps.getUntrackedParameter<InputTag>("trigInputTag"));
154  m_trigProcess = ps.getUntrackedParameter<string>("trigProcess");
155  m_trigProcess_token = consumes<edm::TriggerResults>(ps.getUntrackedParameter<string>("trigProcess_token"));
156  m_trigNames = ps.getUntrackedParameter<vector<string> >("triggerNames");
157 
158  // CB do we need them from cfi?
159  m_MaxMuonEta = 2.4;
160  m_MaxGmtMuonDR = 0.7;
161  m_MaxHltMuonDR = 0.1;
162  // CB ignored at present
163  //m_MinMuonDR = 1.2;
164 
165 }
166 
167 
168 //_____________________________________________________________________
170 
171 
172 //_____________________________________________________________________
174 
175  if (m_verbose) {cout << "[L1TEfficiencyMuons_Offline:] Called beginJob." << endl;}
176 
177 }
178 
179 
180 //_____________________________________________________________________
182 
183  if (m_verbose) {cout << "[L1TEfficiencyMuons_Offline:] Called endJob." << endl;}
184 
185 }
186 
187 
188 //_____________________________________________________________________
190 
191  if (m_verbose) {cout << "[L1TEfficiencyMuons_Offline:] Called beginRun." << endl;}
192 
193  //book histos
194  bookControlHistos();
195 
196  vector<int>::const_iterator gmtPtCutsIt = m_GmtPtCuts.begin();
197  vector<int>::const_iterator gmtPtCutsEnd = m_GmtPtCuts.end();
198 
199  for (; gmtPtCutsIt!=gmtPtCutsEnd; ++ gmtPtCutsIt) {
200  bookEfficiencyHistos((*gmtPtCutsIt));
201  }
202 
203 
204  bool changed = true;
205 
206  m_hltConfig.init(run,iSetup,m_trigProcess,changed);
207 
208  vector<string>::const_iterator trigNamesIt = m_trigNames.begin();
209  vector<string>::const_iterator trigNamesEnd = m_trigNames.end();
210 
211  for (; trigNamesIt!=trigNamesEnd; ++trigNamesIt) {
212 
213  TString tNameTmp = TString(*trigNamesIt); // use TString as it handles regex
214  TRegexp tNamePattern = TRegexp(tNameTmp,true);
215  int tIndex = -1;
216 
217  for (unsigned ipath = 0; ipath < m_hltConfig.size(); ++ipath) {
218 
219  TString tmpName = TString(m_hltConfig.triggerName(ipath));
220  if (tmpName.Contains(tNamePattern)) {
221  tIndex = int(ipath);
222  m_trigIndices.push_back(tIndex);
223  }
224 
225  }
226 
227  if (tIndex < 0 && m_verbose) {
228  cout << "[L1TEfficiencyMuons_Offline:] Warning: Could not find trigger "
229  << (*trigNamesIt) << endl;
230  }
231 
232  }
233 
234 }
235 
236 
237 //_____________________________________________________________________
239 
240  if (m_verbose) {cout << "[L1TEfficiencyMuons_Offline:] Called endRun." << endl;}
241 
242 }
243 
244 
245 //_____________________________________________________________________
247 
248  if(m_verbose){
249  cout << "[L1TEfficiencyMuons_Offline:] Called beginLuminosityBlock at LS="
250  << lumiBlock.id().luminosityBlock() << endl;
251  }
252 
253 }
254 
255 
256 //_____________________________________________________________________
258 
259  if(m_verbose){
260  cout << "[L1TEfficiencyMuons_Offline:] Called endLuminosityBlock at LS="
261  << lumiBlock.id().luminosityBlock() << endl;
262  }
263 
264 }
265 
266 
267 //_____________________________________________________________________
268 void L1TEfficiencyMuons_Offline::analyze(const Event & iEvent, const EventSetup & eventSetup){
269 
271  iEvent.getByToken(m_MuonInputTag, muons);
272 
274  iEvent.getByToken(m_BsInputTag, beamSpot);
275 
277  iEvent.getByToken(m_VtxInputTag, vertex);
278 
280  iEvent.getByToken(m_GmtInputTag,gmtCands);
281 
282  Handle<edm::TriggerResults> trigResults;
283  iEvent.getByToken(m_trigProcess_token,trigResults);
284 
286  iEvent.getByToken(m_trigInputTag,trigEvent);
287 
288  eventSetup.get<IdealMagneticFieldRecord>().get(m_BField);
289 
290  eventSetup.get<TrackingComponentsRecord>().get("SmartPropagatorAny",m_propagatorAlong);
291  eventSetup.get<TrackingComponentsRecord>().get("SmartPropagatorAnyOpposite",m_propagatorOpposite);
292 
293  const Vertex primaryVertex = getPrimaryVertex(vertex,beamSpot);
294 
295  getTightMuons(muons,primaryVertex);
296  getProbeMuons(trigResults,trigEvent); // CB add flag to run on orthogonal datasets (no T&P)
297  getMuonGmtPairs(gmtCands);
298 
299  cout << "[L1TEfficiencyMuons_Offline:] Computing efficiencies" << endl;
300 
301  vector<MuonGmtPair>::const_iterator muonGmtPairsIt = m_MuonGmtPairs.begin();
302  vector<MuonGmtPair>::const_iterator muonGmtPairsEnd = m_MuonGmtPairs.end();
303 
304  for(; muonGmtPairsIt!=muonGmtPairsEnd; ++muonGmtPairsIt) {
305 
306  float eta = muonGmtPairsIt->eta();
307  float phi = muonGmtPairsIt->phi();
308  float pt = muonGmtPairsIt->pt();
309 
310  // unmatched gmt cands have gmtPt = -1.
311  float gmtPt = muonGmtPairsIt->gmtPt();
312 
313  vector<int>::const_iterator gmtPtCutsIt = m_GmtPtCuts.begin();
314  vector<int>::const_iterator gmtPtCutsEnd = m_GmtPtCuts.end();
315 
316  for (; gmtPtCutsIt!=gmtPtCutsEnd; ++ gmtPtCutsIt) {
317 
318  int gmtPtCut = (*gmtPtCutsIt);
319  bool gmtAboveCut = (gmtPt > gmtPtCut);
320 
321  stringstream ptCutToTag; ptCutToTag << gmtPtCut;
322  string ptTag = ptCutToTag.str();
323 
324  if (fabs(eta) < m_MaxMuonEta) {
325 
326  m_EfficiencyHistos[gmtPtCut]["EffvsPt" + ptTag + "Den"]->Fill(pt);
327  if (gmtAboveCut) m_EfficiencyHistos[gmtPtCut]["EffvsPt" + ptTag + "Num"]->Fill(pt);
328 
329  if (pt > gmtPtCut + 8.) { // efficiency in eta/phi at plateau
330 
331  m_EfficiencyHistos[gmtPtCut]["EffvsPhi" + ptTag + "Den"]->Fill(phi);
332  m_EfficiencyHistos[gmtPtCut]["EffvsEta" + ptTag + "Den"]->Fill(eta);
333 
334  if (gmtAboveCut) {
335  m_EfficiencyHistos[gmtPtCut]["EffvsPhi" + ptTag + "Num"]->Fill(phi);
336  m_EfficiencyHistos[gmtPtCut]["EffvsEta" + ptTag + "Num"]->Fill(eta);
337  }
338  }
339  }
340  }
341  }
342 
343  cout << "[L1TEfficiencyMuons_Offline:] Computation finished" << endl;
344 
345 
346 }
347 
348 
349 //_____________________________________________________________________
351 
352  if(m_verbose){cout << "[L1TEfficiencyMuons_Offline:] Booking Control Plot Histos" << endl;}
353 
354  dbe->setCurrentFolder("L1T/Efficiency/Muons/Control");
355 
356  string name = "MuonGmtDeltaR";
357  m_ControlHistos[name] = dbe->book1D(name.c_str(),name.c_str(),25.,0.,2.5);
358 
359  name = "NTightVsAll";
360  m_ControlHistos[name] = dbe->book2D(name.c_str(),name.c_str(),5,-0.5,4.5,5,-0.5,4.5);
361 
362  name = "NProbesVsTight";
363  m_ControlHistos[name] = dbe->book2D(name.c_str(),name.c_str(),5,-0.5,4.5,5,-0.5,4.5);
364 
365 }
366 
367 
368 //_____________________________________________________________________
370 
371  if(m_verbose){
372  cout << "[L1TEfficiencyMuons_Offline:] Booking Efficiency Plot Histos for pt cut = "
373  << ptCut << endl;
374  }
375 
376  stringstream ptCutToTag; ptCutToTag << ptCut;
377  string ptTag = ptCutToTag.str();
378 
379  dbe->setCurrentFolder("L1T/Efficiency/Muons/");
380 
381  string effTag[2] = {"Den", "Num"};
382 
383  for(int iEffTag=0; iEffTag<2; ++ iEffTag) {
384  string name = "EffvsPt" + ptTag + effTag[iEffTag];
385  m_EfficiencyHistos[ptCut][name] = dbe->book1D(name.c_str(),name.c_str(),16,0.,40.);
386 
387  name = "EffvsPhi" + ptTag + effTag[iEffTag];
388  m_EfficiencyHistos[ptCut][name] = dbe->book1D(name.c_str(),name.c_str(),12,0.,2*TMath::Pi());
389 
390  name = "EffvsEta" + ptTag + effTag[iEffTag];
391  m_EfficiencyHistos[ptCut][name] = dbe->book1D(name.c_str(),name.c_str(),12,-2.4,2.4);
392  }
393 
394 }
395 
396 
397 //_____________________________________________________________________
400 
401  Vertex::Point posVtx;
402  Vertex::Error errVtx;
403 
404  bool hasPrimaryVertex = false;
405 
406  if (vertex.isValid())
407  {
408 
409  vector<Vertex>::const_iterator vertexIt = vertex->begin();
410  vector<Vertex>::const_iterator vertexEnd = vertex->end();
411 
412  for (;vertexIt!=vertexEnd;++vertexIt)
413  {
414  if (vertexIt->isValid() &&
415  !vertexIt->isFake())
416  {
417  posVtx = vertexIt->position();
418  errVtx = vertexIt->error();
419  hasPrimaryVertex = true;
420  break;
421  }
422  }
423  }
424 
425  if ( !hasPrimaryVertex ) {
426 
427  if(m_verbose){
428  cout << "[L1TEfficiencyMuons_Offline:] PrimaryVertex not found, use BeamSpot position instead" << endl;
429  }
430 
431  posVtx = beamSpot->position();
432  errVtx(0,0) = beamSpot->BeamWidthX();
433  errVtx(1,1) = beamSpot->BeamWidthY();
434  errVtx(2,2) = beamSpot->sigmaZ();
435 
436  }
437 
438  const Vertex primaryVertex(posVtx,errVtx);
439 
440  return primaryVertex;
441 
442 }
443 
444 
445 //_____________________________________________________________________
447  const Vertex & vertex) {
448 
449  cout << "[L1TEfficiencyMuons_Offline:] Getting tight muons" << endl;
450 
451  m_TightMuons.clear();
452 
453  MuonCollection::const_iterator muonIt = muons->begin();
454  MuonCollection::const_iterator muonEnd = muons->end();
455 
456  for(; muonIt!=muonEnd; ++muonIt) {
457  if (muon::isTightMuon((*muonIt), vertex)) {
458  m_TightMuons.push_back(&(*muonIt));
459  }
460  }
461 
462  m_ControlHistos["NTightVsAll"]->Fill(muons->size(),m_TightMuons.size());
463 
464 }
465 
466 
467 //_____________________________________________________________________
470 
471  cout << "[L1TEfficiencyMuons_Offline:] getting probe muons" << endl;
472 
473  m_ProbeMuons.clear();
474 
475  vector<const Muon*>::const_iterator probeCandIt = m_TightMuons.begin();
476  vector<const Muon*>::const_iterator tightMuonsEnd = m_TightMuons.end();
477 
478  for (; probeCandIt!=tightMuonsEnd; ++probeCandIt) {
479 
480  bool tagHasTrig = false;
481  vector<const Muon*>::const_iterator tagCandIt = m_TightMuons.begin();
482 
483  for (; tagCandIt!=tightMuonsEnd; ++tagCandIt) {
484  if ((*tagCandIt) == (*probeCandIt)) continue; // CB has a little bias for closed-by muons
485  tagHasTrig |= matchHlt(trigEvent,(*tagCandIt));
486  }
487 
488  if (tagHasTrig) m_ProbeMuons.push_back((*probeCandIt));
489 
490  }
491 
492  m_ControlHistos["NProbesVsTight"]->Fill(m_TightMuons.size(),m_ProbeMuons.size());
493 
494 }
495 
496 //_____________________________________________________________________
498 
499  m_MuonGmtPairs.clear();
500 
501  cout << "[L1TEfficiencyMuons_Offline:] Getting muon GMT pairs" << endl;
502 
503  vector<const Muon*>::const_iterator probeMuIt = m_ProbeMuons.begin();
504  vector<const Muon*>::const_iterator probeMuEnd = m_ProbeMuons.end();
505 
506  vector<L1MuGMTExtendedCand> gmtContainer = gmtCands->getRecord(0).getGMTCands();
507 
508  vector<L1MuGMTExtendedCand>::const_iterator gmtIt;
509  vector<L1MuGMTExtendedCand>::const_iterator gmtEnd = gmtContainer.end();
510 
511  for (; probeMuIt!=probeMuEnd; ++probeMuIt) {
512 
513  MuonGmtPair pairBestCand((*probeMuIt),0);
514  pairBestCand.propagate(m_BField,m_propagatorAlong,m_propagatorOpposite);
515 
516  gmtIt = gmtContainer.begin();
517 
518  for(; gmtIt!=gmtEnd; ++gmtIt) {
519 
520  MuonGmtPair pairTmpCand((*probeMuIt),&(*gmtIt));
521  pairTmpCand.propagate(m_BField,m_propagatorAlong,m_propagatorOpposite);
522 
523  if (pairTmpCand.dR() < m_MaxGmtMuonDR && pairTmpCand.gmtPt() > pairBestCand.gmtPt())
524  pairBestCand = pairTmpCand;
525 
526  }
527 
528  m_MuonGmtPairs.push_back(pairBestCand);
529 
530  m_ControlHistos["MuonGmtDeltaR"]->Fill(pairBestCand.dR());
531 
532  }
533 
534 }
535 
536 //_____________________________________________________________________
538 
539 
540  double matchDeltaR = 9999;
541 
542  TriggerObjectCollection trigObjs = triggerEvent->getObjects();
543 
544  vector<int>::const_iterator trigIndexIt = m_trigIndices.begin();
545  vector<int>::const_iterator trigIndexEnd = m_trigIndices.end();
546 
547  for(; trigIndexIt!=trigIndexEnd; ++trigIndexIt) {
548 
549  const vector<string> moduleLabels(m_hltConfig.moduleLabels(*trigIndexIt));
550  const unsigned moduleIndex = m_hltConfig.size((*trigIndexIt))-2;
551  const unsigned hltFilterIndex = triggerEvent->filterIndex(InputTag(moduleLabels[moduleIndex],
552  "",m_trigProcess));
553 
554  if (hltFilterIndex < triggerEvent->sizeFilters()) {
555  const Keys triggerKeys(triggerEvent->filterKeys(hltFilterIndex));
556  const Vids triggerVids(triggerEvent->filterIds(hltFilterIndex));
557 
558  const unsigned nTriggers = triggerVids.size();
559  for (size_t iTrig = 0; iTrig < nTriggers; ++iTrig) {
560  const TriggerObject trigObject = trigObjs[triggerKeys[iTrig]];
561 
562  double dRtmp = deltaR((*mu),trigObject);
563  if (dRtmp < matchDeltaR) matchDeltaR = dRtmp;
564 
565  }
566  }
567  }
568 
569  return (matchDeltaR < m_MaxHltMuonDR);
570 
571 }
572 
573 
574 //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)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
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:43
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:22
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: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:76
void endRun(const edm::Run &run, const edm::EventSetup &iSetup)
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
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:41
Definition: DDAxes.h:10