CMS 3D CMS Logo

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