CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackCandidateProducer.cc
Go to the documentation of this file.
2 
3 #include <memory>
4 
9 
17 
21 
26 
27 #include <vector>
28 #include <map>
29 
34 
40 
41 //Propagator withMaterial
43 
45  : hitSplitter()
46 {
47  // products
48  produces<TrackCandidateCollection>();
49 
50  // general parameters
51  minNumberOfCrossedLayers = conf.getParameter<unsigned int>("MinNumberOfCrossedLayers");
52  rejectOverlaps = conf.getParameter<bool>("OverlapCleaning");
53  splitHits = conf.getParameter<bool>("SplitHits");
54 
55  // input tags, labels, tokens
56  hitMasks_exists = conf.exists("hitMasks");
57  if (hitMasks_exists){
58  hitMasksToken = consumes<std::vector<bool> >(conf.getParameter<edm::InputTag>("hitMasks"));
59  }
60 
61  edm::InputTag simTrackLabel = conf.getParameter<edm::InputTag>("simTracks");
62  simVertexToken = consumes<edm::SimVertexContainer>(simTrackLabel);
63  simTrackToken = consumes<edm::SimTrackContainer>(simTrackLabel);
64 
65  edm::InputTag seedLabel = conf.getParameter<edm::InputTag>("src");
66  seedToken = consumes<edm::View<TrajectorySeed> >(seedLabel);
67 
68  edm::InputTag recHitCombinationsLabel = conf.getParameter<edm::InputTag>("recHitCombinations");
69  recHitCombinationsToken = consumes<FastTrackerRecHitCombinationCollection>(recHitCombinationsLabel);
70 
71  propagatorLabel = conf.getParameter<std::string>("propagator");
72 
73  maxSeedMatchEstimator = conf.getUntrackedParameter<double>("maxSeedMatchEstimator",0);
74 }
75 
76 void
78 
79  // get services
81  es.get<IdealMagneticFieldRecord>().get(magneticField);
82 
83  edm::ESHandle<TrackerGeometry> trackerGeometry;
84  es.get<TrackerDigiGeometryRecord>().get(trackerGeometry);
85 
86  edm::ESHandle<TrackerTopology> trackerTopology;
87  es.get<TrackerTopologyRcd>().get(trackerTopology);
88 
90  es.get<TrackingComponentsRecord>().get(propagatorLabel,propagator);
91  // Propagator* thePropagator = propagator.product()->clone();
92 
93  // get products
95  e.getByToken(seedToken,seeds);
96 
98  e.getByToken(recHitCombinationsToken, recHitCombinations);
99 
101  e.getByToken(simVertexToken,simVertices);
102 
104  e.getByToken(simTrackToken,simTracks);
105 
106  // the hits to be skipped
107  std::unique_ptr<HitMaskHelper> hitMaskHelper;
108  if (hitMasks_exists == true){
110  e.getByToken(hitMasksToken,hitMasks);
111  hitMaskHelper.reset(new HitMaskHelper(hitMasks.product()));
112  }
113 
114  // output collection
115  std::auto_ptr<TrackCandidateCollection> output(new TrackCandidateCollection);
116 
117  // loop over the seeds
118  for (unsigned seednr = 0; seednr < seeds->size(); ++seednr){
119 
120 
121  const TrajectorySeed seed = (*seeds)[seednr];
122  std::vector<int32_t> recHitCombinationIndices;
123  if(seed.nHits()==0){
124  recHitCombinationIndices = SeedMatcher::matchRecHitCombinations(
125  seed,
126  *recHitCombinations,
127  *simTracks,
129  *propagator,
130  *magneticField,
131  *trackerGeometry);
132  }
133  else
134  {
135 
136  // Get the combination of hits that produced the seed
137  int32_t icomb = fastTrackingHelper::getRecHitCombinationIndex(seed);
138  recHitCombinationIndices.push_back(icomb);
139  }
140  for(auto icomb : recHitCombinationIndices)
141  {
142  if(icomb < 0 || unsigned(icomb) >= recHitCombinations->size()){
143  throw cms::Exception("TrackCandidateProducer") << " found seed with recHitCombination out or range: " << icomb << std::endl;
144  }
145  const FastTrackerRecHitCombination & recHitCombination = (*recHitCombinations)[icomb];
146 
147  // select hits, temporarily store as TrajectorySeedHitCandidates
148  std::vector<TrajectorySeedHitCandidate> recHitCandidates;
149  TrajectorySeedHitCandidate recHitCandidate;
150  TrajectorySeed::range seedHitRange = seed.recHits();//Hits in a seed
151  for (TrajectorySeed::const_iterator ihit = seedHitRange.first; ihit != seedHitRange.second; ++ihit) {
153  trackerGeometry.product(),trackerTopology.product());
154  recHitCandidates.push_back(seedHit);
155  }
156  bool passedLastSeedHit = false;
157 
158  for (const auto & _hit : recHitCombination) {
159  TrajectorySeedHitCandidate currentTrackerHit=TrajectorySeedHitCandidate(_hit.get(),trackerGeometry.product(),trackerTopology.product());
160  if(seed.nHits()==0)passedLastSeedHit=true;
161 
162  if(!passedLastSeedHit)
163  {
164  const FastTrackerRecHit * lastSeedHit = recHitCandidates.back().hit();
165  if(seed.nHits()==0||lastSeedHit->sameId(currentTrackerHit.hit()))
166  {
167  passedLastSeedHit=true;
168  }
169  continue;
170  }
171 
172  // apply hit masking
173  if(hitMaskHelper
174  && hitMaskHelper->mask(_hit.get())){
175  continue;
176  }
177 
178  recHitCandidate = TrajectorySeedHitCandidate(_hit.get(),trackerGeometry.product(),trackerTopology.product());
179  // hit selection
180  // - always select first hit
181  if( recHitCandidates.size() == 0 ) {
182  recHitCandidates.push_back(recHitCandidate);
183  }
184  // - in case of *no* verlap rejection: select all hits
185  else if( !rejectOverlaps) {
186  recHitCandidates.push_back(recHitCandidate);
187  }
188  // - in case of overlap rejection:
189  // - select hit if it is not on same layer as previous hit
190  else if( recHitCandidate.subDetId() != recHitCandidates.back().subDetId() ||
191  recHitCandidate.layerNumber() != recHitCandidates.back().layerNumber() ) {
192  recHitCandidates.push_back(recHitCandidate);
193  }
194  // - in case of overlap rejection and hit is on same layer as previous hit
195  // - replace previous hit with current hit if it has better precision
196  else if ( recHitCandidate.localError() < recHitCandidates.back().localError() ){
197  recHitCandidates.back() = recHitCandidate;
198 
199  }
200  }
201 
202  // order hits along the seed direction
203  bool oiSeed = seed.direction()==oppositeToMomentum;
204  if (oiSeed)
205  {
206  std::reverse(recHitCandidates.begin(),recHitCandidates.end());
207  }
208 
209  // Convert TrajectorySeedHitCandidate to TrackingRecHit and split hits
210  edm::OwnVector<TrackingRecHit> trackRecHits;
211  for ( unsigned index = 0; index<recHitCandidates.size(); ++index ) {
212  if(splitHits){
213  hitSplitter.split(*recHitCandidates[index].hit(),trackRecHits,oiSeed);
214  }
215  else {
216  trackRecHits.push_back(recHitCandidates[index].hit()->clone());
217  }
218  }
219 
220 
221  // set the recHitCombinationIndex
223 
224  // create track candidate state
225  // - get seed state
226  DetId seedDetId(seed.startingState().detId());
227  const GeomDet* gdet = trackerGeometry->idToDet(seedDetId);
228  TrajectoryStateOnSurface seedTSOS = trajectoryStateTransform::transientState(seed.startingState(), &(gdet->surface()),magneticField.product());
229  // - backPropagate seedState to first recHit
230  const GeomDet* initialLayer = trackerGeometry->idToDet(trackRecHits.front().geographicalId());
231  const TrajectoryStateOnSurface initialTSOS = propagator->propagate(seedTSOS,initialLayer->surface()) ;
232  // - check validity and transform
233  if (!initialTSOS.isValid()) continue;
235  // add track candidate to output collection
236  output->push_back(TrackCandidate(trackRecHits,seed,PTSOD,edm::RefToBase<TrajectorySeed>(seeds,seednr)));
237 
238  }
239  }
240 
241  // Save the track candidates
242  e.put(output);
243 
244 }
PropagationDirection direction() const
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
tuple propagator
static std::vector< int > matchRecHitCombinations(const TrajectorySeed &seed, const FastTrackerRecHitCombinationCollection &recHitCombinationCollection, const std::vector< SimTrack > &simTrackCollection, double maxMatchEstimator, const Propagator &propagator, const MagneticField &magneticField, const TrackerGeometry &trackerGeometry)
Definition: SeedMatcher.cc:14
edm::EDGetTokenT< edm::View< TrajectorySeed > > seedToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
edm::EDGetTokenT< edm::SimVertexContainer > simVertexToken
bool sameId(const FastTrackerRecHit *other, size_t i=0, size_t j=0) const
edm::EDGetTokenT< edm::SimTrackContainer > simTrackToken
TrackCandidateProducer(const edm::ParameterSet &conf)
std::vector< TrackCandidate > TrackCandidateCollection
void split(const FastTrackerRecHit &hitIn, edm::OwnVector< TrackingRecHit > &hitsOut, bool reverseHits) const
BaseTrackerRecHit const * hit() const final
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
bool exists(std::string const &parameterName) const
checks if a parameter exists
tuple magneticField
FastTrackerRecHitSplitter hitSplitter
virtual void produce(edm::Event &e, const edm::EventSetup &es) override
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
void push_back(D *&d)
Definition: OwnVector.h:290
const SurfaceType & surface() const
edm::EDGetTokenT< FastTrackerRecHitCombinationCollection > recHitCombinationsToken
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
recHitContainer::const_iterator const_iterator
std::pair< const_iterator, const_iterator > range
unsigned int detId() const
edm::EDGetTokenT< std::vector< bool > > hitMasksToken
Definition: DetId.h:18
std::vector< FastTrackerRecHitRef > FastTrackerRecHitCombination
PTrajectoryStateOnDet const & startingState() const
TrajectoryStateOnSurface transientState(const PTrajectoryStateOnDet &ts, const Surface *surface, const MagneticField *field)
T const * product() const
Definition: Handle.h:81
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
range recHits() const
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
unsigned int nHits() const
void setRecHitCombinationIndex(edm::OwnVector< T > &recHits, int32_t icomb)
const FastTrackerRecHit * hit() const
The Hit itself.
unsigned int layerNumber() const
The Layer Number.
DetId geographicalId() const
int32_t getRecHitCombinationIndex(const T &object)
unsigned int subDetId() const
The subdet Id.
reference front()
Definition: OwnVector.h:429