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 
25 
26 #include <vector>
27 #include <map>
28 
33 
39 
40 //Propagator withMaterial
42 
44  : hitSplitter()
45 {
46  // products
47  produces<TrackCandidateCollection>();
48 
49  // general parameters
50  minNumberOfCrossedLayers = conf.getParameter<unsigned int>("MinNumberOfCrossedLayers");
51  rejectOverlaps = conf.getParameter<bool>("OverlapCleaning");
52  splitHits = conf.getParameter<bool>("SplitHits");
53 
54  // input tags, labels, tokens
55  hitMasks_exists = conf.exists("hitMasks");
56  if (hitMasks_exists){
57  hitMasksToken = consumes<std::vector<bool> >(conf.getParameter<edm::InputTag>("hitMasks"));
58  }
59 
60  edm::InputTag simTrackLabel = conf.getParameter<edm::InputTag>("simTracks");
61  simVertexToken = consumes<edm::SimVertexContainer>(simTrackLabel);
62  simTrackToken = consumes<edm::SimTrackContainer>(simTrackLabel);
63 
64  edm::InputTag seedLabel = conf.getParameter<edm::InputTag>("src");
65  seedToken = consumes<edm::View<TrajectorySeed> >(seedLabel);
66 
67  edm::InputTag recHitCombinationsLabel = conf.getParameter<edm::InputTag>("recHitCombinations");
68  recHitCombinationsToken = consumes<FastTrackerRecHitCombinationCollection>(recHitCombinationsLabel);
69 
70  propagatorLabel = conf.getParameter<std::string>("propagator");
71 }
72 
73 void
75 
76  // get services
78  es.get<IdealMagneticFieldRecord>().get(magneticField);
79 
80  edm::ESHandle<TrackerGeometry> trackerGeometry;
81  es.get<TrackerDigiGeometryRecord>().get(trackerGeometry);
82 
83  edm::ESHandle<TrackerTopology> trackerTopology;
84  es.get<TrackerTopologyRcd>().get(trackerTopology);
85 
87  es.get<TrackingComponentsRecord>().get(propagatorLabel,propagator);
88  // Propagator* thePropagator = propagator.product()->clone();
89 
90  // get products
92  e.getByToken(seedToken,seeds);
93 
95  e.getByToken(recHitCombinationsToken, recHitCombinations);
96 
98  e.getByToken(simVertexToken,simVertices);
99 
101  e.getByToken(simTrackToken,simTracks);
102 
103  // the hits to be skipped
104  std::unique_ptr<HitMaskHelper> hitMaskHelper;
105  if (hitMasks_exists == true){
107  e.getByToken(hitMasksToken,hitMasks);
108  hitMaskHelper.reset(new HitMaskHelper(hitMasks.product()));
109  }
110 
111  // output collection
112  std::auto_ptr<TrackCandidateCollection> output(new TrackCandidateCollection);
113 
114  // loop over the seeds
115  for (unsigned seednr = 0; seednr < seeds->size(); ++seednr){
116 
117 
118  const TrajectorySeed seed = (*seeds)[seednr];
119  if(seed.nHits()==0){
120  edm::LogError("TrackCandidateProducer") << "empty trajectory seed in TrajectorySeedCollection: skip" << std::endl;
121  continue;
122  }
123 
124  // Get the combination of hits that produced the seed
125  int32_t icomb = fastTrackingHelper::getRecHitCombinationIndex(seed);
126  if(icomb < 0 || unsigned(icomb) >= recHitCombinations->size()){
127  throw cms::Exception("TrackCandidateProducer") << " found seed with recHitCombination out or range: " << icomb << std::endl;
128  }
129  const FastTrackerRecHitCombination & recHitCombination = (*recHitCombinations)[icomb];
130 
131  // select hits, temporarily store as TrajectorySeedHitCandidates
132  std::vector<TrajectorySeedHitCandidate> recHitCandidates;
133  TrajectorySeedHitCandidate recHitCandidate;
134  unsigned numberOfCrossedLayers = 0;
135  for (const auto & _hit : recHitCombination) {
136 
137 
138  // apply hit masking
139  if(hitMaskHelper
140  && hitMaskHelper->mask(_hit.get())){
141  continue;
142  }
143 
144  recHitCandidate = TrajectorySeedHitCandidate(_hit.get(),trackerGeometry.product(),trackerTopology.product());
145  if ( recHitCandidates.size() == 0 || !recHitCandidate.isOnTheSameLayer(recHitCandidates.back()) ) {
146  ++numberOfCrossedLayers;
147  }
148 
149  // hit selection
150  // - always select first hit
151  if( recHitCandidates.size() == 0 ) {
152  recHitCandidates.push_back(recHitCandidate);
153  }
154  // - in case of *no* verlap rejection: select all hits
155  else if( !rejectOverlaps) {
156  recHitCandidates.push_back(recHitCandidate);
157  }
158  // - in case of overlap rejection:
159  // - select hit if it is not on same layer as previous hit
160  else if( recHitCandidate.subDetId() != recHitCandidates.back().subDetId() ||
161  recHitCandidate.layerNumber() != recHitCandidates.back().layerNumber() ) {
162  recHitCandidates.push_back(recHitCandidate);
163  }
164  // - in case of overlap rejection and hit is on same layer as previous hit
165  // - replace previous hit with current hit if it has better precision
166  else if ( recHitCandidate.localError() < recHitCandidates.back().localError() ){
167  recHitCandidates.back() = recHitCandidate;
168 
169  }
170  }
171 
172  // TODO: verify it makes sense to have this selection
173  if ( numberOfCrossedLayers < minNumberOfCrossedLayers ) {
174  continue;
175  }
176 
177  // Convert TrajectorySeedHitCandidate to TrackingRecHit and split hits
178  edm::OwnVector<TrackingRecHit> trackRecHits;
179  for ( unsigned index = 0; index<recHitCandidates.size(); ++index ) {
180  if(splitHits){
181  hitSplitter.split(*recHitCandidates[index].hit(),trackRecHits);
182  }
183  else {
184  trackRecHits.push_back(recHitCandidates[index].hit()->clone());
185  }
186  }
187 
188  // order hits along the seed direction
189  if (seed.direction()==oppositeToMomentum){
190  LogDebug("FastTracking")<<"reversing the order of the hits";
191  std::reverse(recHitCandidates.begin(),recHitCandidates.end());
192  }
193 
194  // set the recHitCombinationIndex
196 
197  // create track candidate state
198  // - get seed state
199  DetId seedDetId(seed.startingState().detId());
200  const GeomDet* gdet = trackerGeometry->idToDet(seedDetId);
201  TrajectoryStateOnSurface seedTSOS = trajectoryStateTransform::transientState(seed.startingState(), &(gdet->surface()),magneticField.product());
202  // - backPropagate seedState to first recHit
203  const GeomDet* initialLayer = trackerGeometry->idToDet(trackRecHits.front().geographicalId());
204  const TrajectoryStateOnSurface initialTSOS = propagator->propagate(seedTSOS,initialLayer->surface()) ;
205  // - check validity and transform
206  if (!initialTSOS.isValid()) continue;
208 
209  // add track candidate to output collection
210  output->push_back(TrackCandidate(trackRecHits,seed,PTSOD,edm::RefToBase<TrajectorySeed>(seeds,seednr)));
211  }
212 
213  // Save the track candidates
214  e.put(output);
215 
216 }
#define LogDebug(id)
PropagationDirection direction() const
T getParameter(std::string const &) const
edm::EDGetTokenT< edm::View< TrajectorySeed > > seedToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
edm::EDGetTokenT< edm::SimVertexContainer > simVertexToken
edm::EDGetTokenT< edm::SimTrackContainer > simTrackToken
TrackCandidateProducer(const edm::ParameterSet &conf)
std::vector< TrackCandidate > TrackCandidateCollection
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
bool exists(std::string const &parameterName) const
checks if a parameter exists
void split(const FastTrackerRecHit &hitIn, edm::OwnVector< TrackingRecHit > &hitsOut) const
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:280
const SurfaceType & surface() const
edm::EDGetTokenT< FastTrackerRecHitCombinationCollection > recHitCombinationsToken
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
unsigned int detId() const
edm::EDGetTokenT< std::vector< bool > > hitMasksToken
tuple conf
Definition: dbtoconf.py:185
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
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)
unsigned int layerNumber() const
The Layer Number.
DetId geographicalId() const
int32_t getRecHitCombinationIndex(const T &object)
bool isOnTheSameLayer(const TrajectorySeedHitCandidate &other) const
Check if two hits are on the same layer of the same subdetector.
unsigned int subDetId() const
The subdet Id.
reference front()
Definition: OwnVector.h:355