CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
L1MuonRecoTreeProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*- // // Package: UserCode/L1Trigger // Class: L1MuonRecoTreeProducer // /**\class L1MuonRecoTreeProducer L1MuonRecoTreeProducer.cc
2 /*
3 UserCode/L1Trigger/src/L1MuonRecoTreeProducer.cc
4 
5  Description: Produce Muon Reco tree
6 
7  Implementation:
8 
9 */
10 //
11 // Original Author: Luigi Guiducci
12 // Created:
13 //
14 //
15 
16 // system include files
17 #include <memory>
18 // framework
29 
30 // Muons & Tracks Data Formats
40 
41 // Transient tracks (for extrapolations)
52 
53 // B Field
55 
56 // Geometry
62 
63 // ROOT output stuff
66 #include "TH1.h"
67 #include "TTree.h"
68 #include "TF1.h"
69 #include "TMath.h"
70 
73 
74 // GP
78 
81 
82 //vertex
85 
86 #include <typeinfo>
87 
88 // RECO TRIGGER MATCHING:
94 #include "TString.h"
95 #include "TRegexp.h"
96 #include <utility>
97 
98 //
99 // class declaration
100 //
101 
103 public:
104  explicit L1MuonRecoTreeProducer(const edm::ParameterSet &);
105  ~L1MuonRecoTreeProducer() override;
108  void empty_global();
109  void empty_tracker();
110  void empty_standalone();
111  void empty_hlt();
112 
113  double match_trigger(std::vector<int> &trigIndices,
116  const reco::Muon &mu);
117 
118 private:
119  void beginJob(void) override;
120  void analyze(const edm::Event &, const edm::EventSetup &) override;
121  void endJob() override;
122  void beginRun(const edm::Run &, const edm::EventSetup &) override;
123  void endRun(const edm::Run &, const edm::EventSetup &) override;
124 
125 public:
128 
131 
132 private:
133  unsigned maxMuon_;
134  unsigned maxRpcHit_;
135 
136  //---------------------------------------------------------------------------
137  // TRIGGER MATCHING
138  // member variables needed for matching, using reco muons instead of PAT
139  //---------------------------------------------------------------------------
143  std::vector<std::string> isoTriggerNames_;
144  std::vector<std::string> triggerNames_;
145 
146  std::vector<int> isoTriggerIndices_;
147  std::vector<int> triggerIndices_;
150 
151  enum { GL_MUON = 0, SA_MUON = 1, TR_MUON = 2, TRSA_MUON = 3 };
152 
153  // GP start
155  // GP end
156 
157  // DT Geometry
159 
160  // RPC Geometry
162 
163  // The Magnetic field
165 
166  // The GlobalTrackingGeometry
168 
169  // Extrapolator to cylinder
172 
174 
175  // output file
177 
178  // tree
179  TTree *tree_;
180 
182 
183  // EDM input tags
186 };
187 
189  maxMuon_ = iConfig.getParameter<unsigned int>("maxMuon");
190  maxRpcHit_ = iConfig.getParameter<unsigned int>("maxMuon");
191 
192  muonTag_ = iConfig.getParameter<edm::InputTag>("muonTag");
193  rpcHitTag_ = iConfig.getParameter<edm::InputTag>("rpcHitTag");
194 
195  runOnPostLS1_ = iConfig.getParameter<bool>("runOnPostLS1");
196 
198  muonData = muon->getData();
199 
202 
203  // set up output
204  tree_ = fs_->make<TTree>("MuonRecoTree", "MuonRecoTree");
205  tree_->Branch("Muon", "L1Analysis::L1AnalysisRecoMuonDataFormat", &muonData, 32000, 3);
206  tree_->Branch("RpcHit", "L1Analysis::L1AnalysisRecoRpcHitDataFormat", &rpcHitData, 32000, 3);
207 
208  //---------------------------------------------------------------------------
209  // TRIGGER MATCHING
210  // member variables needed for matching, if using reco muons instead of PAT
211  //---------------------------------------------------------------------------
212  triggerMatching_ = iConfig.getUntrackedParameter<bool>("triggerMatching");
213  triggerSummaryLabel_ = iConfig.getParameter<edm::InputTag>("triggerSummaryLabel");
214  triggerProcessLabel_ = iConfig.getUntrackedParameter<std::string>("triggerProcessLabel");
215  triggerNames_ = iConfig.getParameter<std::vector<std::string> >("triggerNames");
216  isoTriggerNames_ = iConfig.getParameter<std::vector<std::string> >("isoTriggerNames");
217  triggerMaxDeltaR_ = iConfig.getParameter<double>("triggerMaxDeltaR");
218 }
219 
221 
222 //
223 // member functions
224 //
225 
226 double L1MuonRecoTreeProducer::match_trigger(std::vector<int> &trigIndices,
229  const reco::Muon &mu) {
230  double matchDeltaR = 9999;
231 
232  for (size_t iTrigIndex = 0; iTrigIndex < trigIndices.size(); ++iTrigIndex) {
233  int triggerIndex = trigIndices[iTrigIndex];
234  const std::vector<std::string> moduleLabels(hltConfig_.moduleLabels(triggerIndex));
235  // find index of the last module:
236  const unsigned moduleIndex = hltConfig_.size(triggerIndex) - 2;
237  // find index of HLT trigger name:
238  const unsigned hltFilterIndex =
239  triggerEvent->filterIndex(edm::InputTag(moduleLabels[moduleIndex], "", triggerProcessLabel_));
240 
241  if (hltFilterIndex < triggerEvent->sizeFilters()) {
242  const trigger::Keys triggerKeys(triggerEvent->filterKeys(hltFilterIndex));
243  const trigger::Vids triggerVids(triggerEvent->filterIds(hltFilterIndex));
244 
245  const unsigned nTriggers = triggerVids.size();
246  for (size_t iTrig = 0; iTrig < nTriggers; ++iTrig) {
247  // loop over all trigger objects:
248  const trigger::TriggerObject trigObject = trigObjs[triggerKeys[iTrig]];
249 
250  double dRtmp = deltaR(mu, trigObject);
251 
252  if (dRtmp < matchDeltaR) {
253  matchDeltaR = dRtmp;
254  }
255 
256  } // loop over different trigger objects
257  } // if trigger is in event (should apply hltFilter with used trigger...)
258  } // loop over muon candidates
259 
260  return matchDeltaR;
261 }
262 
264  muonData->ch.push_back(-999999);
265  muonData->pt.push_back(-999999);
266  muonData->p.push_back(-999999);
267  muonData->eta.push_back(-999999);
268  muonData->phi.push_back(-999999);
269  muonData->normchi2.push_back(-999999);
270  muonData->validhits.push_back(-999999);
271  muonData->numberOfMatchedStations.push_back(-999999);
272  muonData->numberOfValidMuonHits.push_back(-999999);
273  muonData->imp_point_x.push_back(-999999);
274  muonData->imp_point_y.push_back(-999999);
275  muonData->imp_point_z.push_back(-999999);
276  muonData->imp_point_p.push_back(-999999);
277  muonData->imp_point_pt.push_back(-999999);
278  muonData->phi_hb.push_back(-999999);
279  muonData->z_hb.push_back(-999999);
280  muonData->r_he_p.push_back(-999999);
281  muonData->phi_he_p.push_back(-999999);
282  muonData->r_he_n.push_back(-999999);
283  muonData->phi_he_n.push_back(-999999);
284  muonData->calo_energy.push_back(-999999);
285  muonData->calo_energy3x3.push_back(-999999);
286  muonData->ecal_time.push_back(-999999);
287  muonData->ecal_terr.push_back(-999999);
288  muonData->hcal_time.push_back(-999999);
289  muonData->hcal_terr.push_back(-999999);
290  muonData->time_dir.push_back(-999999);
291  muonData->time_inout.push_back(-999999);
292  muonData->time_inout_err.push_back(-999999);
293  muonData->time_outin.push_back(-999999);
294  muonData->time_outin_err.push_back(-999999);
295 
296  muonData->hlt_isomu.push_back(-999999);
297  muonData->hlt_mu.push_back(-999999);
298  muonData->hlt_isoDeltaR.push_back(-999999);
299  muonData->hlt_deltaR.push_back(-999999);
300 }
301 
303  muonData->tr_ch.push_back(-999999);
304  muonData->tr_pt.push_back(-999999);
305  muonData->tr_p.push_back(-999999);
306  muonData->tr_eta.push_back(-999999);
307  muonData->tr_phi.push_back(-999999);
308  muonData->tr_normchi2.push_back(-999999);
309  muonData->tr_validhits.push_back(-999999);
310  muonData->tr_validpixhits.push_back(-999999);
311  muonData->tr_d0.push_back(-999999);
312  muonData->tr_imp_point_x.push_back(-999999);
313  muonData->tr_imp_point_y.push_back(-999999);
314  muonData->tr_imp_point_z.push_back(-999999);
315  muonData->tr_imp_point_p.push_back(-999999);
316  muonData->tr_imp_point_pt.push_back(-999999);
317 
318  muonData->tr_z_mb2.push_back(-999999);
319  muonData->tr_phi_mb2.push_back(-999999);
320  muonData->tr_r_me2_p.push_back(-999999);
321  muonData->tr_phi_me2_p.push_back(-999999);
322  muonData->tr_r_me2_n.push_back(-999999);
323  muonData->tr_phi_me2_n.push_back(-999999);
324 
325  muonData->tr_z_mb1.push_back(-999999);
326  muonData->tr_phi_mb1.push_back(-999999);
327  muonData->tr_r_me1_p.push_back(-999999);
328  muonData->tr_phi_me1_p.push_back(-999999);
329  muonData->tr_r_me1_n.push_back(-999999);
330  muonData->tr_phi_me1_n.push_back(-999999);
331 }
332 
334  muonData->sa_imp_point_x.push_back(-999999);
335  muonData->sa_imp_point_y.push_back(-999999);
336  muonData->sa_imp_point_z.push_back(-999999);
337  muonData->sa_imp_point_p.push_back(-999999);
338  muonData->sa_imp_point_pt.push_back(-999999);
339  muonData->sa_z_mb2.push_back(-999999);
340  muonData->sa_phi_mb2.push_back(-999999);
341  muonData->sa_pseta.push_back(-999999);
342 
343  muonData->sa_z_hb.push_back(-999999);
344  muonData->sa_phi_hb.push_back(-999999);
345 
346  muonData->sa_r_he_p.push_back(-999999);
347  muonData->sa_phi_he_p.push_back(-999999);
348  muonData->sa_r_he_n.push_back(-999999);
349  muonData->sa_phi_he_n.push_back(-999999);
350 
351  muonData->sa_normchi2.push_back(-999999);
352  muonData->sa_validhits.push_back(-999999);
353  muonData->sa_ch.push_back(-999999);
354  muonData->sa_pt.push_back(-999999);
355  muonData->sa_p.push_back(-999999);
356  muonData->sa_eta.push_back(-999999);
357  muonData->sa_phi.push_back(-999999);
358  muonData->sa_outer_pt.push_back(-999999);
359  muonData->sa_inner_pt.push_back(-999999);
360  muonData->sa_outer_eta.push_back(-999999);
361  muonData->sa_inner_eta.push_back(-999999);
362  muonData->sa_outer_phi.push_back(-999999);
363  muonData->sa_inner_phi.push_back(-999999);
364  muonData->sa_outer_x.push_back(-999999);
365  muonData->sa_outer_y.push_back(-999999);
366  muonData->sa_outer_z.push_back(-999999);
367  muonData->sa_inner_x.push_back(-999999);
368  muonData->sa_inner_y.push_back(-999999);
369  muonData->sa_inner_z.push_back(-999999);
370 
371  muonData->sa_r_me2_p.push_back(-999999);
372  muonData->sa_phi_me2_p.push_back(-999999);
373 
374  muonData->sa_r_me2_n.push_back(-999999);
375  muonData->sa_phi_me2_n.push_back(-999999);
376 
377  muonData->sa_z_mb1.push_back(-999999);
378  muonData->sa_phi_mb1.push_back(-999999);
379  muonData->sa_r_me1_p.push_back(-999999);
380  muonData->sa_phi_me1_p.push_back(-999999);
381  muonData->sa_r_me1_n.push_back(-999999);
382  muonData->sa_phi_me1_n.push_back(-999999);
383 
384  muonData->sa_nChambers.push_back(-999);
385  muonData->sa_nMatches.push_back(-999);
386 }
387 
389  muonData->hlt_isomu.push_back(-999999);
390  muonData->hlt_mu.push_back(-999999);
391  muonData->hlt_isoDeltaR.push_back(-9999999);
392  muonData->hlt_deltaR.push_back(-999999);
393 }
394 
395 //
396 // ------------ method called to for each event ------------
397 //
399  float pig = TMath::Pi();
400 
401  muon->Reset();
402  rpcHit->Reset();
403 
404  //GP start
405  // Get the CSC Geometry
406  iSetup.get<MuonGeometryRecord>().get(cscGeom);
407  //GP end
408 
409  // Get the DT Geometry from the setup
410  iSetup.get<MuonGeometryRecord>().get(dtGeom);
411 
412  // Get the RPC Geometry from the setup
413  iSetup.get<MuonGeometryRecord>().get(rpcGeom);
414 
415  //Get the Magnetic field from the setup
416  iSetup.get<IdealMagneticFieldRecord>().get(theBField);
417 
418  // Get the GlobalTrackingGeometry from the setup
420 
422 
423  iEvent.getByLabel(rpcHitTag_, rpcRecHits);
424  if (!rpcRecHits.isValid()) {
425  edm::LogInfo("L1Prompt") << "can't find RPCRecHitCollection with label " << rpcHitTag_.label();
426  } else {
427  RPCRecHitCollection::const_iterator recHitIt = rpcRecHits->begin();
428  RPCRecHitCollection::const_iterator recHitEnd = rpcRecHits->end();
429 
430  int iRpcRecHits = 0;
431 
432  for (; recHitIt != recHitEnd; ++recHitIt) {
433  if ((unsigned int)iRpcRecHits > maxRpcHit_ - 1)
434  continue;
435 
436  int cls = recHitIt->clusterSize();
437  int firststrip = recHitIt->firstClusterStrip();
438  int bx = recHitIt->BunchX();
439 
440  RPCDetId rpcId = recHitIt->rpcId();
441  int region = rpcId.region();
442  int stat = rpcId.station();
443  int sect = rpcId.sector();
444  int layer = rpcId.layer();
445  int subsector = rpcId.subsector();
446  int roll = rpcId.roll();
447  int ring = rpcId.ring();
448 
449  LocalPoint recHitPosLoc = recHitIt->localPosition();
450  const BoundPlane &RPCSurface = rpcGeom->roll(rpcId)->surface();
451  GlobalPoint recHitPosGlob = RPCSurface.toGlobal(recHitPosLoc);
452 
453  float xLoc = recHitPosLoc.x();
454  float phiGlob = recHitPosGlob.phi();
455 
456  rpcHitData->region.push_back(region);
457  rpcHitData->clusterSize.push_back(cls);
458  rpcHitData->strip.push_back(firststrip);
459  rpcHitData->bx.push_back(bx);
460  rpcHitData->xLoc.push_back(xLoc);
461  rpcHitData->phiGlob.push_back(phiGlob);
462  rpcHitData->station.push_back(stat);
463  rpcHitData->sector.push_back(sect);
464  rpcHitData->layer.push_back(layer);
465  rpcHitData->subsector.push_back(subsector);
466  rpcHitData->roll.push_back(roll);
467  rpcHitData->ring.push_back(ring);
468  rpcHitData->muonId.push_back(-999); // CB set to invalid now, updated when looking at muon info
469 
470  iRpcRecHits++;
471  }
472 
473  rpcHitData->nRpcHits = iRpcRecHits;
474  }
475 
476  // Get the muon candidates
478  iEvent.getByLabel(muonTag_, mucand);
479  if (!mucand.isValid()) {
480  edm::LogInfo("L1Prompt") << "can't find Muon Collection with label " << muonTag_.label();
481  return;
482  }
483 
484  // Get the beamspot
486  iEvent.getByLabel("offlineBeamSpot", beamSpot);
487 
488  // Get the primary vertices
490  iEvent.getByLabel(edm::InputTag("offlinePrimaryVertices"), vertex);
491 
492  // Get the propagators
493  iSetup.get<TrackingComponentsRecord>().get("SmartPropagatorAny", propagatorAlong);
494  iSetup.get<TrackingComponentsRecord>().get("SmartPropagatorAnyOpposite", propagatorOpposite);
495 
496  for (reco::MuonCollection::const_iterator imu = mucand->begin();
497  // for(pat::MuonCollection::const_iterator imu = mucand->begin();
498  imu != mucand->end() && (unsigned)muonData->nMuons < maxMuon_;
499  imu++) {
500  int type = 0;
501  if (imu->isGlobalMuon())
502  type = type + 1;
503  if (imu->isStandAloneMuon())
504  type = type + 2;
505  if (imu->isTrackerMuon())
506  type = type + 4;
507  if (imu->isCaloMuon())
508  type = type + 8;
509 
510  bool isTIGHT =
511  (!vertex->empty() && imu->isGlobalMuon() && imu->globalTrack()->normalizedChi2() < 10. &&
512  imu->globalTrack()->hitPattern().numberOfValidMuonHits() > 0 && imu->numberOfMatchedStations() > 1 &&
513  fabs(imu->innerTrack()->dxy(vertex->at(0).position())) < 0.2 &&
514  fabs(imu->innerTrack()->dz(vertex->at(0).position())) < 0.5 &&
515  imu->innerTrack()->hitPattern().numberOfValidPixelHits() > 0 &&
516  imu->innerTrack()->hitPattern().trackerLayersWithMeasurement() > 5);
517 
518  if (isTIGHT)
519  type = type + 16;
520  if (imu->isPFMuon())
521  type = type + 32;
522 
523  muonData->howmanytypes.push_back(type); // muon type is counting calo muons and multiple assignments
524 
525  // bool type identifiers are exclusive. is this correct? CB to check
526  bool isSA = (!imu->isGlobalMuon() && imu->isStandAloneMuon() && !imu->isTrackerMuon());
527  bool isTR = (!imu->isGlobalMuon() && imu->isTrackerMuon() && !imu->isStandAloneMuon());
528  bool isGL = (imu->isGlobalMuon()); //&&!(imu->isStandAloneMuon())&&!(imu->isTrackerMuon()));
529  bool isTRSA = (!imu->isGlobalMuon() && imu->isStandAloneMuon() && imu->isTrackerMuon());
530 
531  // How we fill this. We have 3 blocks of variables: muons_; muons_sa_; muons_tr_
532  // GL SA TR Description muon_type Bool id Filled Vars Variables to -99999
533  // 0 0 0 Muon does not exist / / / /
534  // 0 0 1 It is a Tracker muon TR_MUON isTR muons_tr_ muons_sa_,muons_
535  // 0 1 0 It is a SA muon SA_MUON isSA muons_sa muons_tr,muons_
536  // 0 1 1 It is a SA+Tracker muon TRSA_MUON isTRSA muons_sa,muons_tr muons_
537  // 1 0 0 It is a Global only muon GL_MUON isGL muons_,muons_sa,muons_tr /
538  // 1 0 1 Gl w/out SA cannot exist / / / /
539  // 1 1 0 Gl+SA (no trk-mu match) GL_MUON isGL muons_,muons_sa,muons_tr none
540  // 1 1 1 GL+SA+Tr (all matched) GL_MUON isGL muons_,muons_sa,muons_tr none
541 
542  //---------------------------------------------------------------------
543  // TRIGGER MATCHING:
544  // if specified the reconstructed muons are matched to a trigger
545  //---------------------------------------------------------------------
546  if (triggerMatching_) {
547  double isoMatchDeltaR = 9999.;
548  double matchDeltaR = 9999.;
549  int hasIsoTriggered = 0;
550  int hasTriggered = 0;
551 
552  // first check if the trigger results are valid:
554  iEvent.getByLabel(edm::InputTag("TriggerResults", "", triggerProcessLabel_), triggerResults);
555 
556  if (triggerResults.isValid()) {
558  iEvent.getByLabel(triggerSummaryLabel_, triggerEvent);
559  if (triggerEvent.isValid()) {
560  // get trigger objects:
561  const trigger::TriggerObjectCollection triggerObjects = triggerEvent->getObjects();
562 
563  matchDeltaR = match_trigger(triggerIndices_, triggerObjects, triggerEvent, (*imu));
564  if (matchDeltaR < triggerMaxDeltaR_)
565  hasTriggered = 1;
566 
567  isoMatchDeltaR = match_trigger(isoTriggerIndices_, triggerObjects, triggerEvent, (*imu));
568  if (isoMatchDeltaR < triggerMaxDeltaR_)
569  hasIsoTriggered = 1;
570  } // end if (triggerEvent.isValid())
571  } // end if (triggerResults.isValid())
572 
573  // fill trigger matching variables:
574  muonData->hlt_isomu.push_back(hasIsoTriggered);
575  muonData->hlt_mu.push_back(hasTriggered);
576  muonData->hlt_isoDeltaR.push_back(isoMatchDeltaR);
577  muonData->hlt_deltaR.push_back(matchDeltaR);
578  } else {
579  empty_hlt();
580  } // end if (triggerMatching_)
581 
582  if (isGL || isTR || isSA || isTRSA) {
583  muonData->nMuons = muonData->nMuons + 1;
584  if (isTR)
585  muonData->type.push_back(TR_MUON);
586  if (isGL)
587  muonData->type.push_back(GL_MUON);
588  if (isSA)
589  muonData->type.push_back(SA_MUON);
590  if (isTRSA)
591  muonData->type.push_back(TRSA_MUON);
592  if (!isGL)
593  empty_global();
594  if (!isTR && !isGL && !isTRSA)
595  empty_tracker();
596  if (!isSA && !isGL && !isTRSA)
598 
599  // begin GP
600  //---------------------------------------------------------------------
601  // RECHIT information in CSC: only for standalone/global muons!
602  //---------------------------------------------------------------------
603  // An artificial rank to sort RecHits
604  // the closer RecHit to key station/layer -> the smaller the rank
605  // KK's original idea
606  const int lutCSC[4][6] = {
607  {26, 24, 22, 21, 23, 25}, {6, 4, 2, 1, 3, 5}, {16, 14, 12, 11, 13, 15}, {36, 34, 32, 31, 33, 35}};
608 
609  int globalTypeRCH = -999999;
610  // float localEtaRCH = -999999;
611  // float localPhiRCH = -999999;
612  float globalEtaRCH = -999999;
613  float globalPhiRCH = -999999;
614 
615  if (isSA || isGL) {
616  trackingRecHit_iterator hit = imu->outerTrack()->recHitsBegin();
617  trackingRecHit_iterator hitEnd = imu->outerTrack()->recHitsEnd();
618 
619  for (; hit != hitEnd; ++hit) {
620  if (!((*hit)->isValid()))
621  continue;
622 
623  // Hardware ID of the RecHit (in terms of wire/strips/chambers)
624  DetId detid = (*hit)->geographicalId();
625 
626  // Interested in muon systems only
627  // Look only at CSC Hits (CSC id is 2)
628  if (detid.det() != DetId::Muon)
629  continue;
630  if (detid.subdetId() != MuonSubdetId::CSC)
631  continue;
632 
633  CSCDetId id(detid.rawId());
634  //std::cout << "before Lut id.station = " <<id.station()
635  // << " id.layer() = " << id.layer() << " globalTypeRCH = "
636  // << globalTypeRCH << std::endl;
637  // another sanity check
638  if (id.station() < 1)
639  continue;
640 
641  // Look up some stuff specific to CSCRecHit2D
642  // std::cout << " typeid().name() " << typeid(**hit).name() << std::endl;
643  // const CSCRecHit2D* CSChit =dynamic_cast<const CSCRecHit2D*>(&**hit);
644 
645  const CSCSegment *cscSegment = dynamic_cast<const CSCSegment *>(&**hit);
646  //std::cout << "cscSegment = " << cscSegment << std::endl;
647  if (cscSegment == nullptr)
648  continue;
649  // const CSCRecHit2D* CSChit =(CSCRecHit2D*)(&**hit);
650 
651  // std::cout << " after CSCRecHit2D, CSChit = " << CSChit << std::endl;
652  // LocalPoint rhitlocal = CSChit->localPosition();
653  LocalPoint rhitlocal = cscSegment->localPosition();
654 
655  // for debugging purpouses
656  //if (printLevel > 0) {
657  //std::cout << "!!!!rhitlocal.phi = "<<rhitlocal.phi() << std::endl;
658  //std::cout << "rhitlocal.y="<<rhitlocal.y();
659  //std::cout << "rhitlocal.z="<<rhitlocal.z();
660  //}
661 
662  GlobalPoint gp = GlobalPoint(0.0, 0.0, 0.0);
663 
664  const CSCChamber *cscchamber = cscGeom->chamber(id);
665 
666  if (!cscchamber)
667  continue;
668 
669  gp = cscchamber->toGlobal(rhitlocal);
670 
671  // identify the rechit position
672  //int pos = ( ((id.station()-1)*6) + (id.layer()-1) ) + (MAX_CSC_RECHIT*whichMuon);
673 
674  // --------------------------------------------------
675  // this part has to be deprecated once we are sure of
676  // the TMatrixF usage ;)
677  // fill the rechits array
678  //rchEtaList[pos] = gp.eta();
679  //rchPhiList[pos] = gp.phi();
680  //float phi02PI = gp.phi();
681  //if (gp.phi() < 0) phi02PI += (2*PI);
682 
683  //rchPhiList_02PI[pos] = phi02PI;
684  // --------------------------------------------------
685 
686  // --------------------------------------------------
687  // See if this hit is closer to the "key" position
688  //if( lutCSC[id.station()-1][id.layer()-1]<globalTypeRCH || globalTypeRCH<0 ){
689  if (lutCSC[id.station() - 1][3 - 1] < globalTypeRCH || globalTypeRCH < 0) {
690  //globalTypeRCH = lutCSC[id.station()-1][id.layer()-1];
691  globalTypeRCH = lutCSC[id.station() - 1][3 - 1];
692  // localEtaRCH = rhitlocal.eta();
693  // localPhiRCH = rhitlocal.phi();
694  globalEtaRCH = gp.eta();
695  globalPhiRCH = gp.phi(); // phi from -pi to pi
696  //std::cout << "globalEtaRCH = " <<globalEtaRCH
697  // << " globalPhiRCH = " << globalPhiRCH << std::endl;
698  if (globalPhiRCH < 0)
699  globalPhiRCH = globalPhiRCH + 2 * pig; // convert to [0; 2pi]
700  }
701  // --------------------------------------------------
702  }
703 
704  hit = imu->outerTrack()->recHitsBegin();
705 
706  for (; hit != hitEnd; hit++) {
707  if (!((*hit)->isValid()))
708  continue;
709 
710  DetId detId = (*hit)->geographicalId();
711 
712  if (detId.det() != DetId::Muon)
713  continue;
714  if (detId.subdetId() != MuonSubdetId::RPC)
715  continue;
716 
717  RPCDetId rpcId = (RPCDetId)(*hit)->geographicalId();
718 
719  int region = rpcId.region();
720  int stat = rpcId.station();
721  int sect = rpcId.sector();
722  int layer = rpcId.layer();
723  int subsector = rpcId.subsector();
724  int roll = rpcId.roll();
725  int ring = rpcId.ring();
726 
727  float xLoc = (*hit)->localPosition().x();
728 
729  for (int iRpcHit = 0; iRpcHit < rpcHitData->nRpcHits; ++iRpcHit) {
730  if (region == rpcHitData->region.at(iRpcHit) && stat == rpcHitData->station.at(iRpcHit) &&
731  sect == rpcHitData->sector.at(iRpcHit) && layer == rpcHitData->layer.at(iRpcHit) &&
732  subsector == rpcHitData->subsector.at(iRpcHit) && roll == rpcHitData->roll.at(iRpcHit) &&
733  ring == rpcHitData->ring.at(iRpcHit) && fabs(xLoc - rpcHitData->xLoc.at(iRpcHit)) < 0.01)
734 
735  rpcHitData->muonId.at(iRpcHit) = muonData->nMuons; // CB rpc hit belongs to mu imu
736  // due to cleaning as in 2012 1 rpc hit belogns to 1 mu
737  }
738  }
739  }
740  // at the end of the loop, write only the best rechit
741  // if(globalPhiRCH > -100.) std::cout << "globalPhiRCH = " << globalPhiRCH
742  // << "globalEtaRCH = " << globalEtaRCH << std::endl;
743  muonData->rchCSCtype.push_back(globalTypeRCH);
744  muonData->rchPhi.push_back(globalPhiRCH);
745  muonData->rchEta.push_back(globalEtaRCH);
746  // end GP
747 
748  if (isGL) {
749  // Filling calo energies and calo times
750  if (imu->isEnergyValid()) {
751  reco::MuonEnergy muon_energy;
752  muon_energy = imu->calEnergy();
753  muonData->calo_energy.push_back(muon_energy.tower);
754  muonData->calo_energy3x3.push_back(muon_energy.towerS9);
755  muonData->ecal_time.push_back(muon_energy.ecal_time);
756  muonData->ecal_terr.push_back(muon_energy.ecal_timeError);
757  muonData->hcal_time.push_back(muon_energy.hcal_time);
758  muonData->hcal_terr.push_back(muon_energy.hcal_timeError);
759  } else {
760  muonData->calo_energy.push_back(-999999);
761  muonData->calo_energy3x3.push_back(-999999);
762  muonData->ecal_time.push_back(-999999);
763  muonData->ecal_terr.push_back(-999999);
764  muonData->hcal_time.push_back(-999999);
765  muonData->hcal_terr.push_back(-999999);
766  }
767 
768  // Filling muon time data
769  if (imu->isTimeValid()) {
770  reco::MuonTime muon_time;
771  muon_time = imu->time();
772  muonData->time_dir.push_back(muon_time.direction());
773  muonData->time_inout.push_back(muon_time.timeAtIpInOut);
774  muonData->time_inout_err.push_back(muon_time.timeAtIpInOutErr);
775  muonData->time_outin.push_back(muon_time.timeAtIpOutIn);
776  muonData->time_outin_err.push_back(muon_time.timeAtIpOutInErr);
777  } else {
778  muonData->time_dir.push_back(-999999);
779  muonData->time_inout.push_back(-999999);
780  muonData->time_inout_err.push_back(-999999);
781  muonData->time_outin.push_back(-999999);
782  muonData->time_outin_err.push_back(-999999);
783  }
784 
785  // Use the track now, and make a transient track out of it (for extrapolations)
786  reco::TrackRef glb_mu = imu->globalTrack();
788 
789  // Track quantities
790  muonData->ch.push_back(glb_mu->charge());
791  muonData->pt.push_back(glb_mu->pt());
792  muonData->p.push_back(glb_mu->p());
793  muonData->eta.push_back(glb_mu->eta());
794  muonData->phi.push_back(glb_mu->phi());
795  muonData->normchi2.push_back(glb_mu->normalizedChi2());
796  muonData->validhits.push_back(glb_mu->numberOfValidHits());
797  muonData->numberOfMatchedStations.push_back(imu->numberOfMatchedStations());
798  muonData->numberOfValidMuonHits.push_back(glb_mu->hitPattern().numberOfValidMuonHits());
799 
800  // Extrapolation to IP
801  if (ttrack.impactPointTSCP().isValid()) {
802  muonData->imp_point_x.push_back(ttrack.impactPointTSCP().position().x());
803  muonData->imp_point_y.push_back(ttrack.impactPointTSCP().position().y());
804  muonData->imp_point_z.push_back(ttrack.impactPointTSCP().position().z());
805  muonData->imp_point_p.push_back(sqrt(ttrack.impactPointTSCP().position().mag()));
806  muonData->imp_point_pt.push_back(sqrt(ttrack.impactPointTSCP().position().perp2()));
807  } else {
808  muonData->imp_point_x.push_back(-999999);
809  muonData->imp_point_y.push_back(-999999);
810  muonData->imp_point_z.push_back(-999999);
811  muonData->imp_point_p.push_back(-999999);
812  muonData->imp_point_pt.push_back(-999999);
813  }
814 
815  if (!runOnPostLS1_) {
816  //Extrapolation to HB
818  tsos = cylExtrapTrkSam(glb_mu, 235);
819  if (tsos.isValid()) {
820  double xx = tsos.globalPosition().x();
821  double yy = tsos.globalPosition().y();
822  double zz = tsos.globalPosition().z();
823  muonData->z_hb.push_back(zz);
824  double rr = sqrt(xx * xx + yy * yy);
825  double cosphi = xx / rr;
826  if (yy >= 0)
827  muonData->phi_hb.push_back(acos(cosphi));
828  else
829  muonData->phi_hb.push_back(2 * pig - acos(cosphi));
830  } else {
831  muonData->phi_hb.push_back(-999999);
832  muonData->z_hb.push_back(-999999);
833  }
834 
835  //Extrapolation to HE+
836  tsos = surfExtrapTrkSam(glb_mu, 479);
837  if (tsos.isValid()) {
838  double xx = tsos.globalPosition().x();
839  double yy = tsos.globalPosition().y();
840  double rr = sqrt(xx * xx + yy * yy);
841  muonData->r_he_p.push_back(rr);
842  double cosphi = xx / rr;
843  if (yy >= 0)
844  muonData->phi_he_p.push_back(acos(cosphi));
845  else
846  muonData->phi_he_p.push_back(2 * pig - acos(cosphi));
847  } else {
848  muonData->r_he_p.push_back(-999999);
849  muonData->phi_he_p.push_back(-999999);
850  }
851 
852  //Extrapolation to HE-
853  tsos = surfExtrapTrkSam(glb_mu, -479);
854  if (tsos.isValid()) {
855  double xx = tsos.globalPosition().x();
856  double yy = tsos.globalPosition().y();
857  double rr = sqrt(xx * xx + yy * yy);
858  muonData->r_he_n.push_back(rr);
859  double cosphi = xx / rr;
860  if (yy >= 0)
861  muonData->phi_he_n.push_back(acos(cosphi));
862  else
863  muonData->phi_he_n.push_back(2 * pig - acos(cosphi));
864  } else {
865  muonData->r_he_n.push_back(-999999);
866  muonData->phi_he_n.push_back(-999999);
867  }
868  } else {
869  muonData->phi_hb.push_back(-999999);
870  muonData->z_hb.push_back(-999999);
871  muonData->r_he_p.push_back(-999999);
872  muonData->phi_he_p.push_back(-999999);
873  muonData->r_he_n.push_back(-999999);
874  muonData->phi_he_n.push_back(-999999);
875  }
876  } // end of IF IS GLOBAL
877 
878  // If global muon or tracker muon, fill the tracker track quantities
879  if (isTR || isGL || isTRSA) {
880  // Take the tracker track and build a transient track out of it
881  reco::TrackRef tr_mu = imu->innerTrack();
883  // Fill track quantities
884  muonData->tr_ch.push_back(tr_mu->charge());
885  muonData->tr_pt.push_back(tr_mu->pt());
886  muonData->tr_p.push_back(tr_mu->p());
887  muonData->tr_eta.push_back(tr_mu->eta());
888  muonData->tr_phi.push_back(tr_mu->phi());
889  muonData->tr_normchi2.push_back(tr_mu->normalizedChi2());
890  muonData->tr_validhits.push_back(tr_mu->numberOfValidHits());
891  muonData->tr_validpixhits.push_back(tr_mu->hitPattern().numberOfValidPixelHits());
892  // find d0 from vertex position
895  iEvent.getByLabel("offlineBeamSpot", beamSpot);
896  muonData->tr_d0.push_back(tr_mu->dxy(beamSpot->position()));
897 
898  // Extrapolation to the IP
899  if (ttrack.impactPointTSCP().isValid()) {
900  muonData->tr_imp_point_x.push_back(ttrack.impactPointTSCP().position().x());
901  muonData->tr_imp_point_y.push_back(ttrack.impactPointTSCP().position().y());
902  muonData->tr_imp_point_z.push_back(ttrack.impactPointTSCP().position().z());
903  muonData->tr_imp_point_p.push_back(sqrt(ttrack.impactPointTSCP().position().mag()));
904  muonData->tr_imp_point_pt.push_back(sqrt(ttrack.impactPointTSCP().position().perp2()));
905  } else {
906  muonData->tr_imp_point_x.push_back(-999999);
907  muonData->tr_imp_point_y.push_back(-999999);
908  muonData->tr_imp_point_z.push_back(-999999);
909  muonData->tr_imp_point_p.push_back(-999999);
910  muonData->tr_imp_point_pt.push_back(-999999);
911  }
912 
913  if (!runOnPostLS1_) {
915  tsos = cylExtrapTrkSam(tr_mu, 410); // track at MB1 radius - extrapolation
916  if (tsos.isValid()) {
917  double xx = tsos.globalPosition().x();
918  double yy = tsos.globalPosition().y();
919  double zz = tsos.globalPosition().z();
920  muonData->tr_z_mb1.push_back(zz);
921  double rr = sqrt(xx * xx + yy * yy);
922  double cosphi = xx / rr;
923  if (yy >= 0)
924  muonData->tr_phi_mb1.push_back(acos(cosphi));
925  else
926  muonData->tr_phi_mb1.push_back(2 * pig - acos(cosphi));
927  } else {
928  muonData->tr_z_mb1.push_back(-999999);
929  muonData->tr_phi_mb1.push_back(-999999);
930  }
931 
932  tsos = cylExtrapTrkSam(tr_mu, 500); // track at MB2 radius - extrapolation
933  if (tsos.isValid()) {
934  double xx = tsos.globalPosition().x();
935  double yy = tsos.globalPosition().y();
936  double zz = tsos.globalPosition().z();
937  muonData->tr_z_mb2.push_back(zz);
938  double rr = sqrt(xx * xx + yy * yy);
939  double cosphi = xx / rr;
940  if (yy >= 0)
941  muonData->tr_phi_mb2.push_back(acos(cosphi));
942  else
943  muonData->tr_phi_mb2.push_back(2 * pig - acos(cosphi));
944  } else {
945  muonData->tr_z_mb2.push_back(-999999);
946  muonData->tr_phi_mb2.push_back(-999999);
947  }
948 
949  tsos = surfExtrapTrkSam(tr_mu, 630); // track at ME1+ plane - extrapolation
950  if (tsos.isValid()) {
951  double xx = tsos.globalPosition().x();
952  double yy = tsos.globalPosition().y();
953  double rr = sqrt(xx * xx + yy * yy);
954  muonData->tr_r_me1_p.push_back(rr);
955  double cosphi = xx / rr;
956  if (yy >= 0)
957  muonData->tr_phi_me1_p.push_back(acos(cosphi));
958  else
959  muonData->tr_phi_me1_p.push_back(2 * pig - acos(cosphi));
960  } else {
961  muonData->tr_r_me1_p.push_back(-999999);
962  muonData->tr_phi_me1_p.push_back(-999999);
963  }
964 
965  tsos = surfExtrapTrkSam(tr_mu, 790); // track at ME2+ plane - extrapolation
966  if (tsos.isValid()) {
967  double xx = tsos.globalPosition().x();
968  double yy = tsos.globalPosition().y();
969  double rr = sqrt(xx * xx + yy * yy);
970  muonData->tr_r_me2_p.push_back(rr);
971  double cosphi = xx / rr;
972  if (yy >= 0)
973  muonData->tr_phi_me2_p.push_back(acos(cosphi));
974  else
975  muonData->tr_phi_me2_p.push_back(2 * pig - acos(cosphi));
976  } else {
977  muonData->tr_r_me2_p.push_back(-999999);
978  muonData->tr_phi_me2_p.push_back(-999999);
979  }
980 
981  tsos = surfExtrapTrkSam(tr_mu, -630); // track at ME1- plane - extrapolation
982  if (tsos.isValid()) {
983  double xx = tsos.globalPosition().x();
984  double yy = tsos.globalPosition().y();
985  double rr = sqrt(xx * xx + yy * yy);
986  muonData->tr_r_me1_n.push_back(rr);
987  double cosphi = xx / rr;
988  if (yy >= 0)
989  muonData->tr_phi_me1_n.push_back(acos(cosphi));
990  else
991  muonData->tr_phi_me1_n.push_back(2 * pig - acos(cosphi));
992  } else {
993  muonData->tr_r_me1_n.push_back(-999999);
994  muonData->tr_phi_me1_n.push_back(-999999);
995  }
996 
997  tsos = surfExtrapTrkSam(tr_mu, -790); // track at ME2- plane - extrapolation
998  if (tsos.isValid()) {
999  double xx = tsos.globalPosition().x();
1000  double yy = tsos.globalPosition().y();
1001  double rr = sqrt(xx * xx + yy * yy);
1002  muonData->tr_r_me2_n.push_back(rr);
1003  double cosphi = xx / rr;
1004  if (yy >= 0)
1005  muonData->tr_phi_me2_n.push_back(acos(cosphi));
1006  else
1007  muonData->tr_phi_me2_n.push_back(2 * pig - acos(cosphi));
1008  } else {
1009  muonData->tr_r_me2_n.push_back(-999999);
1010  muonData->tr_phi_me2_n.push_back(-999999);
1011  }
1012  } else {
1013  muonData->tr_z_mb1.push_back(-999999);
1014  muonData->tr_phi_mb1.push_back(-999999);
1015  muonData->tr_z_mb2.push_back(-999999);
1016  muonData->tr_phi_mb2.push_back(-999999);
1017  muonData->tr_r_me1_p.push_back(-999999);
1018  muonData->tr_phi_me1_p.push_back(-999999);
1019  muonData->tr_r_me2_p.push_back(-999999);
1020  muonData->tr_phi_me2_p.push_back(-999999);
1021  muonData->tr_r_me1_n.push_back(-999999);
1022  muonData->tr_phi_me1_n.push_back(-999999);
1023  muonData->tr_r_me2_n.push_back(-999999);
1024  muonData->tr_phi_me2_n.push_back(-999999);
1025  }
1026 
1027  } // end of IF IS TRACKER
1028 
1029  // If global muon or sa muon, fill the sa track quantities
1030  if (isGL || isSA || isTRSA) {
1031  muonData->sa_nChambers.push_back(imu->numberOfChambers());
1032  muonData->sa_nMatches.push_back(imu->numberOfMatches());
1033 
1034  // Take the SA track and build a transient track out of it
1035  reco::TrackRef sa_mu = imu->outerTrack();
1037 
1038  // Extrapolation to IP
1039  if (ttrack.impactPointTSCP().isValid()) {
1040  muonData->sa_imp_point_x.push_back(ttrack.impactPointTSCP().position().x());
1041  muonData->sa_imp_point_y.push_back(ttrack.impactPointTSCP().position().y());
1042  muonData->sa_imp_point_z.push_back(ttrack.impactPointTSCP().position().z());
1043  muonData->sa_imp_point_p.push_back(sqrt(ttrack.impactPointTSCP().position().mag()));
1044  muonData->sa_imp_point_pt.push_back(sqrt(ttrack.impactPointTSCP().position().perp2()));
1045  } else {
1046  muonData->sa_imp_point_x.push_back(-999999);
1047  muonData->sa_imp_point_y.push_back(-999999);
1048  muonData->sa_imp_point_z.push_back(-999999);
1049  muonData->sa_imp_point_p.push_back(-999999);
1050  muonData->sa_imp_point_pt.push_back(-999999);
1051  }
1052 
1053  // Extrapolation to MB2
1054 
1056  tsos = cylExtrapTrkSam(sa_mu, 410); // track at MB1 radius - extrapolation
1057  if (tsos.isValid()) {
1058  double xx = tsos.globalPosition().x();
1059  double yy = tsos.globalPosition().y();
1060  double zz = tsos.globalPosition().z();
1061  muonData->sa_z_mb1.push_back(zz);
1062  double rr = sqrt(xx * xx + yy * yy);
1063  double cosphi = xx / rr;
1064  if (yy >= 0)
1065  muonData->sa_phi_mb1.push_back(acos(cosphi));
1066  else
1067  muonData->sa_phi_mb1.push_back(2 * pig - acos(cosphi));
1068  } else {
1069  muonData->sa_z_mb1.push_back(-999999);
1070  muonData->sa_phi_mb1.push_back(-999999);
1071  }
1072 
1073  tsos = cylExtrapTrkSam(sa_mu, 500); // track at MB2 radius - extrapolation
1074  if (tsos.isValid()) {
1075  double xx = tsos.globalPosition().x();
1076  double yy = tsos.globalPosition().y();
1077  double zz = tsos.globalPosition().z();
1078  muonData->sa_z_mb2.push_back(zz);
1079  double rr = sqrt(xx * xx + yy * yy);
1080  double cosphi = xx / rr;
1081  if (yy >= 0)
1082  muonData->sa_phi_mb2.push_back(acos(cosphi));
1083  else
1084  muonData->sa_phi_mb2.push_back(2 * pig - acos(cosphi));
1085  double abspseta = -log(tan(atan(fabs(rr / zz)) / 2.0));
1086  if (zz >= 0)
1087  muonData->sa_pseta.push_back(abspseta);
1088  else
1089  muonData->sa_pseta.push_back(-abspseta);
1090  } else {
1091  muonData->sa_z_mb2.push_back(-999999);
1092  muonData->sa_phi_mb2.push_back(-999999);
1093  muonData->sa_pseta.push_back(-999999);
1094  }
1095 
1096  tsos = surfExtrapTrkSam(sa_mu, 630); // track at ME1+ plane - extrapolation
1097  if (tsos.isValid()) {
1098  double xx = tsos.globalPosition().x();
1099  double yy = tsos.globalPosition().y();
1100  double rr = sqrt(xx * xx + yy * yy);
1101  muonData->sa_r_me1_p.push_back(rr);
1102  double cosphi = xx / rr;
1103  if (yy >= 0)
1104  muonData->sa_phi_me1_p.push_back(acos(cosphi));
1105  else
1106  muonData->sa_phi_me1_p.push_back(2 * pig - acos(cosphi));
1107  } else {
1108  muonData->sa_r_me1_p.push_back(-999999);
1109  muonData->sa_phi_me1_p.push_back(-999999);
1110  }
1111 
1112  // Extrapolation to ME2+
1113  tsos = surfExtrapTrkSam(sa_mu, 790);
1114  if (tsos.isValid()) {
1115  double xx = tsos.globalPosition().x();
1116  double yy = tsos.globalPosition().y();
1117  double rr = sqrt(xx * xx + yy * yy);
1118  muonData->sa_r_me2_p.push_back(rr);
1119  double cosphi = xx / rr;
1120  if (yy >= 0)
1121  muonData->sa_phi_me2_p.push_back(acos(cosphi));
1122  else
1123  muonData->sa_phi_me2_p.push_back(2 * pig - acos(cosphi));
1124  } else {
1125  muonData->sa_r_me2_p.push_back(-999999);
1126  muonData->sa_phi_me2_p.push_back(-999999);
1127  }
1128 
1129  tsos = surfExtrapTrkSam(sa_mu, -630); // track at ME1- plane - extrapolation
1130  if (tsos.isValid()) {
1131  double xx = tsos.globalPosition().x();
1132  double yy = tsos.globalPosition().y();
1133  double rr = sqrt(xx * xx + yy * yy);
1134  muonData->sa_r_me1_n.push_back(rr);
1135  double cosphi = xx / rr;
1136  if (yy >= 0)
1137  muonData->sa_phi_me1_n.push_back(acos(cosphi));
1138  else
1139  muonData->sa_phi_me1_n.push_back(2 * pig - acos(cosphi));
1140  } else {
1141  muonData->sa_r_me1_n.push_back(-999999);
1142  muonData->sa_phi_me1_n.push_back(-999999);
1143  }
1144 
1145  // Extrapolation to ME2-
1146  tsos = surfExtrapTrkSam(sa_mu, -790); // track at ME2- disk - extrapolation
1147  if (tsos.isValid()) {
1148  double xx = tsos.globalPosition().x();
1149  double yy = tsos.globalPosition().y();
1150  double rr = sqrt(xx * xx + yy * yy);
1151  muonData->sa_r_me2_n.push_back(rr);
1152  double cosphi = xx / rr;
1153  if (yy >= 0)
1154  muonData->sa_phi_me2_n.push_back(acos(cosphi));
1155  else
1156  muonData->sa_phi_me2_n.push_back(2 * pig - acos(cosphi));
1157  } else {
1158  muonData->sa_r_me2_n.push_back(-999999);
1159  muonData->sa_phi_me2_n.push_back(-999999);
1160  }
1161 
1162  // Extrapolation to HB
1163  tsos = cylExtrapTrkSam(sa_mu, 235); // track at HB radius - extrapolation
1164  if (tsos.isValid()) {
1165  double xx = tsos.globalPosition().x();
1166  double yy = tsos.globalPosition().y();
1167  double zz = tsos.globalPosition().z();
1168  muonData->sa_z_hb.push_back(zz);
1169  double rr = sqrt(xx * xx + yy * yy);
1170  double cosphi = xx / rr;
1171  if (yy >= 0)
1172  muonData->sa_phi_hb.push_back(acos(cosphi));
1173  else
1174  muonData->sa_phi_hb.push_back(2 * pig - acos(cosphi));
1175  } else {
1176  muonData->sa_z_hb.push_back(-999999);
1177  muonData->sa_phi_hb.push_back(-999999);
1178  }
1179 
1180  // Extrapolation to HE+
1181  tsos = surfExtrapTrkSam(sa_mu, 479);
1182  if (tsos.isValid()) {
1183  double xx = tsos.globalPosition().x();
1184  double yy = tsos.globalPosition().y();
1185  double rr = sqrt(xx * xx + yy * yy);
1186  muonData->sa_r_he_p.push_back(rr);
1187  double cosphi = xx / rr;
1188  if (yy >= 0)
1189  muonData->sa_phi_he_p.push_back(acos(cosphi));
1190  else
1191  muonData->sa_phi_he_p.push_back(2 * pig - acos(cosphi));
1192  } else {
1193  muonData->sa_r_he_p.push_back(-999999);
1194  muonData->sa_phi_he_p.push_back(-999999);
1195  }
1196 
1197  // Extrapolation to HE-
1198  tsos = surfExtrapTrkSam(sa_mu, -479);
1199  if (tsos.isValid()) {
1200  double xx = tsos.globalPosition().x();
1201  double yy = tsos.globalPosition().y();
1202  double rr = sqrt(xx * xx + yy * yy);
1203  muonData->sa_r_he_n.push_back(rr);
1204  double cosphi = xx / rr;
1205  if (yy >= 0)
1206  muonData->sa_phi_he_n.push_back(acos(cosphi));
1207  else
1208  muonData->sa_phi_he_n.push_back(2 * pig - acos(cosphi));
1209  } else {
1210  muonData->sa_r_he_n.push_back(-999999);
1211  muonData->sa_phi_he_n.push_back(-999999);
1212  }
1213 
1214  // Several track quantities
1215  muonData->sa_normchi2.push_back(sa_mu->normalizedChi2());
1216  muonData->sa_validhits.push_back(sa_mu->numberOfValidHits());
1217  muonData->sa_ch.push_back(sa_mu->charge());
1218  muonData->sa_pt.push_back(sa_mu->pt());
1219  muonData->sa_p.push_back(sa_mu->p());
1220  muonData->sa_eta.push_back(sa_mu->eta());
1221  muonData->sa_phi.push_back(sa_mu->phi());
1222  muonData->sa_outer_pt.push_back(sqrt(sa_mu->outerMomentum().Perp2()));
1223  muonData->sa_inner_pt.push_back(sqrt(sa_mu->innerMomentum().Perp2()));
1224  muonData->sa_outer_eta.push_back(sa_mu->outerMomentum().Eta());
1225  muonData->sa_inner_eta.push_back(sa_mu->innerMomentum().Eta());
1226  muonData->sa_outer_phi.push_back(sa_mu->outerMomentum().Phi());
1227  muonData->sa_inner_phi.push_back(sa_mu->innerMomentum().Phi());
1228  muonData->sa_outer_x.push_back(sa_mu->outerPosition().x());
1229  muonData->sa_outer_y.push_back(sa_mu->outerPosition().y());
1230  muonData->sa_outer_z.push_back(sa_mu->outerPosition().z());
1231  muonData->sa_inner_x.push_back(sa_mu->innerPosition().x());
1232  muonData->sa_inner_y.push_back(sa_mu->innerPosition().y());
1233  muonData->sa_inner_z.push_back(sa_mu->innerPosition().z());
1234 
1235  } // end of IF IS STANDALONE
1236 
1237  } // end of if type 012 found
1238  } // end of muon loop
1239 
1240  tree_->Fill();
1241 }
1242 
1243 // to get the track position info at a particular rho
1245  Cylinder::PositionType pos(0, 0, 0);
1247  Cylinder::CylinderPointer myCylinder = Cylinder::build(pos, rot, rho);
1248 
1249  FreeTrajectoryState recoStart = freeTrajStateMuon(track);
1250  TrajectoryStateOnSurface recoProp;
1251  recoProp = propagatorAlong->propagate(recoStart, *myCylinder);
1252  if (!recoProp.isValid()) {
1253  recoProp = propagatorOpposite->propagate(recoStart, *myCylinder);
1254  }
1255  return recoProp;
1256 }
1257 
1258 // to get track position at a particular (xy) plane given its z
1260  Plane::PositionType pos(0, 0, z);
1262  Plane::PlanePointer myPlane = Plane::build(pos, rot);
1263 
1264  FreeTrajectoryState recoStart = freeTrajStateMuon(track);
1265  TrajectoryStateOnSurface recoProp;
1266  recoProp = propagatorAlong->propagate(recoStart, *myPlane);
1267  if (!recoProp.isValid()) {
1268  recoProp = propagatorOpposite->propagate(recoStart, *myPlane);
1269  }
1270  return recoProp;
1271 }
1272 
1274  GlobalPoint innerPoint(track->innerPosition().x(), track->innerPosition().y(), track->innerPosition().z());
1275  GlobalVector innerVec(track->innerMomentum().x(), track->innerMomentum().y(), track->innerMomentum().z());
1276 
1277  FreeTrajectoryState recoStart(innerPoint, innerVec, track->charge(), &*theBField);
1278 
1279  return recoStart;
1280 }
1281 
1283  // Prepare for trigger matching for each new run:
1284  // Look up triggetIndices in the HLT config for the different paths
1285  if (triggerMatching_) {
1286  bool changed = true;
1287  if (!hltConfig_.init(run, eventSetup, triggerProcessLabel_, changed)) {
1288  // if you can't initialize hlt configuration, crash!
1289  std::cout << "Error: didn't find process" << triggerProcessLabel_ << std::endl;
1290  assert(false);
1291  }
1292 
1293  bool enableWildcard = true;
1294  for (size_t iTrig = 0; iTrig < triggerNames_.size(); ++iTrig) {
1295  // prepare for regular expression (with wildcards) functionality:
1296  TString tNameTmp = TString(triggerNames_[iTrig]);
1297  TRegexp tNamePattern = TRegexp(tNameTmp, enableWildcard);
1298  int tIndex = -1;
1299  // find the trigger index:
1300  for (unsigned ipath = 0; ipath < hltConfig_.size(); ++ipath) {
1301  // use TString since it provides reg exp functionality:
1302  TString tmpName = TString(hltConfig_.triggerName(ipath));
1303  if (tmpName.Contains(tNamePattern)) {
1304  tIndex = int(ipath);
1305  triggerIndices_.push_back(tIndex);
1306  }
1307  }
1308  if (tIndex < 0) { // if can't find trigger path at all, give warning:
1309  std::cout << "Warning: Could not find trigger" << triggerNames_[iTrig] << std::endl;
1310  //assert(false);
1311  }
1312  } // end for triggerNames
1313  for (size_t iTrig = 0; iTrig < isoTriggerNames_.size(); ++iTrig) {
1314  // prepare for regular expression functionality:
1315  TString tNameTmp = TString(isoTriggerNames_[iTrig]);
1316  TRegexp tNamePattern = TRegexp(tNameTmp, enableWildcard);
1317  int tIndex = -1;
1318  // find the trigger index:
1319  for (unsigned ipath = 0; ipath < hltConfig_.size(); ++ipath) {
1320  // use TString since it provides reg exp functionality:
1321  TString tmpName = TString(hltConfig_.triggerName(ipath));
1322  if (tmpName.Contains(tNamePattern)) {
1323  tIndex = int(ipath);
1324  isoTriggerIndices_.push_back(tIndex);
1325  }
1326  }
1327  if (tIndex < 0) { // if can't find trigger path at all, give warning:
1328  std::cout << "Warning: Could not find trigger" << isoTriggerNames_[iTrig] << std::endl;
1329  //assert(false);
1330  }
1331  } // end for isoTriggerNames
1332  } // end if (triggerMatching_)
1333 }
1334 
1336 // ------------ method called once each job just before starting event loop ------------
1338 
1339 // ------------ method called once each job just after ending the event loop ------------
1341 
1342 //define this as a plug-in
void beginRun(const edm::Run &, const edm::EventSetup &) override
unsigned int size() const
number of trigger paths in trigger table
const double Pi
T getUntrackedParameter(std::string const &, T const &) const
float ecal_timeError
Definition: MuonEnergy.h:48
edm::ESHandle< DTGeometry > dtGeom
static std::vector< std::string > checklist log
LocalPoint localPosition() const override
Definition: CSCSegment.h:39
const std::string & triggerName(unsigned int triggerIndex) const
uint16_t *__restrict__ id
edm::ESHandle< CSCGeometry > cscGeom
void analyze(const edm::Event &, const edm::EventSetup &) override
TrajectoryStateClosestToPoint impactPointTSCP() const
TrajectoryStateOnSurface surfExtrapTrkSam(reco::TrackRef track, double z)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
T y() const
Definition: PV3DBase.h:60
GlobalPoint globalPosition() const
TrajectoryStateOnSurface cylExtrapTrkSam(reco::TrackRef track, double rho)
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
T perp2() const
Definition: PV3DBase.h:68
FreeTrajectoryState freeTrajStateMuon(reco::TrackRef track)
assert(be >=bs)
float timeAtIpOutInErr
Definition: MuonTime.h:17
float towerS9
total energy in 3x3 tower shape
Definition: MuonEnergy.h:22
float float float z
float ecal_time
Calorimeter timing.
Definition: MuonEnergy.h:47
constexpr std::array< uint8_t, layerIndexSize > layer
Single trigger physics object (e.g., an isolated muon)
Definition: TriggerObject.h:21
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:43
L1MuonRecoTreeProducer(const edm::ParameterSet &)
Direction direction() const
direction estimation based on time dispersion
Definition: MuonTime.h:20
int iEvent
Definition: GenABIO.cc:224
T mag() const
Definition: PV3DBase.h:64
int roll() const
Definition: RPCDetId.h:92
edm::ESHandle< RPCGeometry > rpcGeom
int ring() const
Definition: RPCDetId.h:59
T sqrt(T t)
Definition: SSEVec.h:19
static PlanePointer build(Args &&...args)
Definition: Plane.h:33
T z() const
Definition: PV3DBase.h:61
L1Analysis::L1AnalysisRecoMuonDataFormat * muonData
float timeAtIpInOutErr
Definition: MuonTime.h:14
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
float timeAtIpOutIn
b) particle is moving from outside in
Definition: MuonTime.h:16
double match_trigger(std::vector< int > &trigIndices, const trigger::TriggerObjectCollection &trigObjs, edm::Handle< trigger::TriggerEvent > &triggerEvent, const reco::Muon &mu)
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
edm::Service< TFileService > fs_
edm::ESHandle< MagneticField > theBField
const int mu
Definition: Constants.h:22
L1Analysis::L1AnalysisRecoRpcHitDataFormat * rpcHitData
static std::string const triggerResults
Definition: EdmProvDump.cc:44
bool isValid() const
Definition: HandleBase.h:70
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:500
std::vector< std::string > triggerNames_
const std::vector< std::string > & moduleLabels(unsigned int trigger) const
label(s) of module(s) on a trigger path
std::vector< TriggerObject > TriggerObjectCollection
collection of trigger physics objects (e.g., all isolated muons)
Definition: TriggerObject.h:75
Log< level::Info, false > LogInfo
Definition: DetId.h:17
int layer() const
Definition: RPCDetId.h:85
std::vector< int > triggerIndices_
static CylinderPointer build(const PositionType &pos, const RotationType &rot, Scalar radius, Bounds *bounds=nullptr)
Definition: Cylinder.h:45
edm::ESHandle< Propagator > propagatorOpposite
std::vector< size_type > Keys
edm::ESHandle< Propagator > propagatorAlong
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
static constexpr int RPC
Definition: MuonSubdetId.h:13
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
int sector() const
Sector id: the group of chambers at same phi (and increasing r)
Definition: RPCDetId.h:81
std::string const & label() const
Definition: InputTag.h:36
T eta() const
Definition: PV3DBase.h:73
int subsector() const
SubSector id : some sectors are divided along the phi direction in subsectors (from 1 to 4 in Barrel...
Definition: RPCDetId.h:88
std::vector< std::string > isoTriggerNames_
L1AnalysisRecoRpcHitDataFormat * getData()
T get() const
Definition: EventSetup.h:82
std::vector< int > isoTriggerIndices_
tuple cout
Definition: gather_cfg.py:144
L1Analysis::L1AnalysisRecoRpcHit * rpcHit
float hcal_timeError
Definition: MuonEnergy.h:50
static constexpr int CSC
Definition: MuonSubdetId.h:12
T x() const
Definition: PV3DBase.h:59
float timeAtIpInOut
Definition: MuonTime.h:13
edm::ESHandle< GlobalTrackingGeometry > theTrackingGeometry
std::vector< int > Vids
L1Analysis::L1AnalysisRecoMuon * muon
void endRun(const edm::Run &, const edm::EventSetup &) override
Definition: Run.h:45
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:53
int station() const
Definition: RPCDetId.h:78