CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FastTSGFromIOHit.cc
Go to the documentation of this file.
2 
17 
18 
20 {
21  theCategory = "FastSimulation|Muons||FastTSGFromIOHit";
22 
23  thePtCut = iConfig.getParameter<double>("PtCut");
24 
25  theSeedCollectionLabels = iConfig.getParameter<std::vector<edm::InputTag> >("SeedCollectionLabels");
26 
27  theSimTrackCollectionLabel = iConfig.getParameter<edm::InputTag>("SimTrackCollectionLabel");
28 
29 }
30 
32 {
33 
34  LogTrace(theCategory) << " FastTSGFromIOHit dtor called ";
35 
36 }
37 
38 void FastTSGFromIOHit::trackerSeeds(const TrackCand& staMuon, const TrackingRegion& region, std::vector<TrajectorySeed> & result) {
39 
40  // Retrieve the Monte Carlo truth (SimTracks)
43 
44  // Retrieve Seed collection
45  unsigned seedCollections = theSeedCollectionLabels.size();
46  std::vector<edm::Handle<edm::View<TrajectorySeed> > > theSeeds;
47  theSeeds.resize(seedCollections);
48  unsigned seed_size = 0;
49  for ( unsigned iseed=0; iseed<seedCollections; ++iseed ) {
50  getEvent()->getByLabel(theSeedCollectionLabels[iseed], theSeeds[iseed]);
51  seed_size += theSeeds[iseed]->size();
52  }
53 
54  // Make a ref to l2 muon
55  reco::TrackRef muRef(staMuon.second);
56 
57  // Cut on muons with low momenta
58  if ( muRef->pt() < thePtCut
59  || muRef->innerMomentum().Rho() < thePtCut
60  || muRef->innerMomentum().R() < 2.5 ) return;
61 
62  // Copy the collection of seeds (ahem, this is time consuming!)
63  std::vector<TrajectorySeed> tkSeeds;
64  std::set<unsigned> tkIds;
65  tkSeeds.reserve(seed_size);
66  for ( unsigned iseed=0; iseed<seedCollections; ++iseed ) {
67  edm::Handle<edm::View<TrajectorySeed> > aSeedCollection = theSeeds[iseed];
68  unsigned nSeeds = aSeedCollection->size();
69  for (unsigned seednr = 0; seednr < nSeeds; ++seednr) {
70 
71  // The seed
72  const BasicTrajectorySeed* aSeed = &((*aSeedCollection)[seednr]);
73 
74  // Find the first hit of the Seed
75  TrajectorySeed::range theSeedingRecHitRange = aSeed->recHits();
76  const SiTrackerGSMatchedRecHit2D * theFirstSeedingRecHit =
77  (const SiTrackerGSMatchedRecHit2D*) (&(*(theSeedingRecHitRange.first)));
78 
79  // The SimTrack id associated to that recHit
80  int simTrackId = theFirstSeedingRecHit->simtrackId();
81 
82  // Track already associated to a seed
83  std::set<unsigned>::iterator tkId = tkIds.find(simTrackId);
84  if( tkId != tkIds.end() ) continue;
85 
86  const SimTrack& theSimTrack = (*theSimTracks)[simTrackId];
87 
88  const RectangularEtaPhiTrackingRegion & regionRef = dynamic_cast<const RectangularEtaPhiTrackingRegion & > (region);
89 
90  if( clean(muRef,regionRef,aSeed,theSimTrack) ) tkSeeds.push_back(*aSeed);
91  tkIds.insert(simTrackId);
92 
93  } // End loop on seeds
94 
95  } // End loop on seed collections
96 
97  // Now create the Muon Trajectory Seed
98  unsigned int is=0;
99  unsigned int isMax=tkSeeds.size();
100  for (;is!=isMax;++is){
101  result.push_back( L3MuonTrajectorySeed(tkSeeds[is], muRef));
102  } // End of tk seed loop
103 
104 }
105 
106 bool
108  const RectangularEtaPhiTrackingRegion& region,
109  const BasicTrajectorySeed* aSeed,
110  const SimTrack& theSimTrack)
111 {
112  // return true;
113  //}
114 
115  // Eta cleaner
116  const PixelRecoRange<float>& etaRange = region.etaRange() ;
117  // return true;
118  //}
119 
120  double etaSeed = theSimTrack.momentum().Eta();
121  double etaLimit = (fabs(fabs(etaRange.max())-fabs(etaRange.mean())) <0.05) ?
122  0.05 : fabs(fabs(etaRange.max()) - fabs(etaRange.mean())) ;
123  bool inEtaRange =
124  etaSeed >= (etaRange.mean() - etaLimit) &&
125  etaSeed <= (etaRange.mean() + etaLimit) ;
126  if ( !inEtaRange ) return false;
127 
128  // Phi cleaner
129  const TkTrackingRegionsMargin<float>& phiMargin = region.phiMargin();
130  double phiSeed = theSimTrack.momentum().Phi();
131  double phiLimit = (phiMargin.right() < 0.05 ) ? 0.05 : phiMargin.right();
132  bool inPhiRange =
133  (fabs(deltaPhi(phiSeed,double(region.direction().phi()))) < phiLimit );
134  if ( !inPhiRange ) return false;
135 
136  // pt cleaner
137  double ptSeed = std::sqrt(theSimTrack.momentum().Perp2());
138  double ptMin = (region.ptMin()>3.5) ? 3.5: region.ptMin();
139  bool inPtRange = ptSeed >= ptMin && ptSeed<= 2*(muRef->pt());
140  return inPtRange;
141 
142 }
T getParameter(std::string const &) const
T max() const
FastTSGFromIOHit(const edm::ParameterSet &pset, edm::ConsumesCollector &iC)
constructor
std::pair< const Trajectory *, reco::TrackRef > TrackCand
edm::InputTag theSimTrackCollectionLabel
virtual ~FastTSGFromIOHit()
destructor
std::vector< edm::InputTag > theSeedCollectionLabels
void trackerSeeds(const TrackCand &, const TrackingRegion &, std::vector< TrajectorySeed > &)
generate seed(s) for a track
T sqrt(T t)
Definition: SSEVec.h:48
const edm::Event * getEvent() const
tuple result
Definition: query.py:137
std::pair< const_iterator, const_iterator > range
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
#define LogTrace(id)
int iseed
Definition: AMPTWrapper.h:124
T mean() const
range recHits() const
const math::XYZTLorentzVectorD & momentum() const
Definition: CoreSimTrack.h:22
bool clean(reco::TrackRef muRef, const RectangularEtaPhiTrackingRegion &region, const BasicTrajectorySeed *aSeed, const SimTrack &theSimTrack)
std::string theCategory