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.
1 #include <memory>
2 
7 
16 
20 
22 //#include "FastSimulation/Tracking/interface/TrackerRecHitSplit.h"
23 
25 
26 #include <vector>
27 #include <map>
28 
33 
39 
40 //Propagator withMaterial
42 
44 {
45  // products
46  produces<TrackCandidateCollection>();
47 
48  // general parameters
49  minNumberOfCrossedLayers = conf.getParameter<unsigned int>("MinNumberOfCrossedLayers");
50  rejectOverlaps = conf.getParameter<bool>("OverlapCleaning");
51  splitHits = conf.getParameter<bool>("SplitHits");
52 
53  // input tags, labels, tokens
54  edm::InputTag simTrackLabel = conf.getParameter<edm::InputTag>("simTracks");
55  simVertexToken = consumes<edm::SimVertexContainer>(simTrackLabel);
56  simTrackToken = consumes<edm::SimTrackContainer>(simTrackLabel);
57 
58  edm::InputTag seedLabel = conf.getParameter<edm::InputTag>("src");
59  seedToken = consumes<edm::View<TrajectorySeed> >(seedLabel);
60 
61  edm::InputTag recHitLabel = conf.getParameter<edm::InputTag>("recHits");
62  recHitToken = consumes<SiTrackerGSMatchedRecHit2DCollection>(recHitLabel);
63 
64  propagatorLabel = conf.getParameter<std::string>("propagator");
65 }
66 
67 void
69 
70  // get services
72  es.get<IdealMagneticFieldRecord>().get(magneticField);
73 
74  edm::ESHandle<TrackerGeometry> trackerGeometry;
75  es.get<TrackerDigiGeometryRecord>().get(trackerGeometry);
76 
77  edm::ESHandle<TrackerTopology> trackerTopology;
78  es.get<TrackerTopologyRcd>().get(trackerTopology);
79 
81  es.get<TrackingComponentsRecord>().get(propagatorLabel,propagator);
82 
83  // get products
85  e.getByToken(seedToken,seeds);
86 
88  e.getByToken(recHitToken, recHits);
89 
91  e.getByToken(simVertexToken,simVertices);
92 
94  e.getByToken(simTrackToken,simTracks);
95 
96  // output collection
97  std::auto_ptr<TrackCandidateCollection> output(new TrackCandidateCollection);
98 
99  // loop over the seeds
100  for (unsigned seednr = 0; seednr < seeds->size(); ++seednr){
101 
102  const BasicTrajectorySeed seed = seeds->at(seednr);
103  if(seed.nHits()==0){
104  edm::LogError("TrackCandidateProducer") << "empty trajectory seed in TrajectorySeedCollection" << std::endl;
105  return;
106  }
107 
108  // Get all the rechits associated to this track
109  int simTrackId = ((const SiTrackerGSMatchedRecHit2D*) (&*(seed.recHits().first)))->simtrackId();
110  SiTrackerGSMatchedRecHit2DCollection::range recHitRange = recHits->get(simTrackId);
111  SiTrackerGSMatchedRecHit2DCollection::const_iterator recHitIter = recHitRange.first;
112  SiTrackerGSMatchedRecHit2DCollection::const_iterator recHitEnd = recHitRange.second;
113 
114  // Count number of crossed layers, apply overlap rejection
115  std::vector<TrajectorySeedHitCandidate> recHitCandidates;
116  TrajectorySeedHitCandidate recHitCandidate;
117  unsigned numberOfCrossedLayers = 0;
118  for ( ; recHitIter != recHitEnd; ++recHitIter) {
119  recHitCandidate = TrajectorySeedHitCandidate(&(*recHitIter),trackerGeometry.product(),trackerTopology.product());
120  if ( recHitCandidates.size() == 0 || !recHitCandidate.isOnTheSameLayer(recHitCandidates.back()) ) {
121  ++numberOfCrossedLayers;
122  }
123 
124  if( recHitCandidates.size() == 0 || // add the first seeding hit in any case
125  !rejectOverlaps || // without overlap rejection: add each hit
126  recHitCandidate.subDetId() != recHitCandidates.back().subDetId() || // with overlap rejection: only add if hits are not on the same layer
127  recHitCandidate.layerNumber() != recHitCandidates.back().layerNumber() ){
128  recHitCandidates.push_back(recHitCandidate);
129  }
130  else if ( recHitCandidate.localError() < recHitCandidates.back().localError() ){
131  recHitCandidates.back() = recHitCandidate;
132  }
133  }
134  if ( numberOfCrossedLayers < minNumberOfCrossedLayers ) {
135  continue;
136  }
137 
138  // Convert TrajectorySeedHitCandidate to TrackingRecHit and split hits
139  edm::OwnVector<TrackingRecHit> trackRecHits;
140  for ( unsigned index = 0; index<recHitCandidates.size(); ++index ) {
141  if(splitHits && recHitCandidates[index].matchedHit()->isMatched()){
142  trackRecHits.push_back(recHitCandidates[index].matchedHit()->firstHit()->clone());
143  trackRecHits.push_back(recHitCandidates[index].matchedHit()->secondHit()->clone());
144  }
145  else {
146  trackRecHits.push_back(recHitCandidates[index].hit()->clone());
147  }
148  }
149  // reverse order if needed
150  // when is this relevant? perhaps for the cases when track finding goes backwards?
151  if (seed.direction()==oppositeToMomentum){
152  LogDebug("FastTracking")<<"reversing the order of the hits";
153  std::reverse(recHitCandidates.begin(),recHitCandidates.end());
154  }
155 
156  // initial track candidate parameters parameters
157  int vertexIndex = simTracks->at(simTrackId).vertIndex();
158  GlobalPoint position(simVertices->at(vertexIndex).position().x(),
159  simVertices->at(vertexIndex).position().y(),
160  simVertices->at(vertexIndex).position().z());
161  GlobalVector momentum( simTracks->at(simTrackId).momentum().x() ,
162  simTracks->at(simTrackId).momentum().y() ,
163  simTracks->at(simTrackId).momentum().z() );
164  float charge = simTracks->at(simTrackId).charge();
165  GlobalTrajectoryParameters initialParams(position,momentum,(int)charge,magneticField.product());
166  AlgebraicSymMatrix55 errorMatrix= AlgebraicMatrixID();
167  CurvilinearTrajectoryError initialError(errorMatrix);
168  FreeTrajectoryState initialFTS(initialParams, initialError);
169 
170  // create track candidate
171  const GeomDet* initialLayer = trackerGeometry->idToDet(trackRecHits.front().geographicalId());
172  const TrajectoryStateOnSurface initialTSOS = propagator->propagate(initialFTS,initialLayer->surface()) ;
173  if (!initialTSOS.isValid()) continue;
175  TrackCandidate newTrackCandidate(trackRecHits,seed,PTSOD,edm::RefToBase<TrajectorySeed>(seeds,seednr));
176 
177  // add track candidate to output collection
178  output->push_back(newTrackCandidate);
179 
180  }
181 
182  // Save the track candidates
183  e.put(output);
184 }
#define LogDebug(id)
PropagationDirection direction() const
T getParameter(std::string const &) const
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:50
edm::EDGetTokenT< edm::View< TrajectorySeed > > seedToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
edm::EDGetTokenT< edm::SimVertexContainer > simVertexToken
edm::EDGetTokenT< edm::SimTrackContainer > simTrackToken
ROOT::Math::SMatrixIdentity AlgebraicMatrixID
TrackCandidateProducer(const edm::ParameterSet &conf)
std::vector< TrackCandidate > TrackCandidateCollection
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:40
virtual void produce(edm::Event &e, const edm::EventSetup &es) override
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:43
void push_back(D *&d)
Definition: OwnVector.h:280
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:115
edm::EDGetTokenT< SiTrackerGSMatchedRecHit2DCollection > recHitToken
tuple conf
Definition: dbtoconf.py:185
const T & get() const
Definition: EventSetup.h:55
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
static int position[264][3]
Definition: ReadPGInfo.cc:509
unsigned int layerNumber() const
The Layer Number.
DetId geographicalId() const
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