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