CMS 3D CMS Logo

KfTrackProducerBase.cc
Go to the documentation of this file.
2 // system include files
3 #include <memory>
4 // user include files
11 
13 
15 
17 #include "TrajectoryToResiduals.h"
18 
20 
22  const Propagator* prop,
23  const MeasurementTracker* measTk,
24  std::unique_ptr<TrackingRecHitCollection>& selHits,
25  std::unique_ptr<reco::TrackCollection>& selTracks,
26  std::unique_ptr<reco::TrackExtraCollection>& selTrackExtras,
27  std::unique_ptr<std::vector<Trajectory> >& selTrajectories,
28  std::unique_ptr<std::vector<int> >& indecesInput,
29  AlgoProductCollection& algoResults,
30  TransientTrackingRecHitBuilder const* hitBuilder,
31  const TrackerTopology* ttopo,
32  int BeforeOrAfter) {
35 
38  edm::Ref<std::vector<Trajectory> >::key_type iTjRef = 0;
39  std::map<unsigned int, unsigned int> tjTkMap;
40 
41  selTracks->reserve(algoResults.size());
42  selTrackExtras->reserve(algoResults.size());
44  selTrajectories->reserve(algoResults.size());
45 
46  for (AlgoProductCollection::iterator i = algoResults.begin(); i != algoResults.end(); i++) {
47  auto theTraj = (*i).trajectory;
48  (*indecesInput).push_back((*i).indexInput);
49  if (trajectoryInEvent_) {
50  selTrajectories->push_back(*theTraj);
51  iTjRef++;
52  }
53 
54  auto theTrack = (*i).track;
55 
56  // Hits are going to be re-sorted along momentum few lines later.
57  // Therefore the direction stored in the TrackExtra
58  // has to be "alongMomentum" as well. Anyway, this direction can be differnt from the one of the orignal
59  // seed! The name seedDirection() for the Track's method (and the corresponding data member) is
60  // misleading and should be changed into something like "hitsDirection()". TO BE FIXED!
61 
63 
64  LogDebug("TrackProducer") << "In KfTrackProducerBase::putInEvt - seedDir=" << seedDir;
65 
66  selTracks->push_back(std::move(*theTrack));
67  delete theTrack;
68  iTkRef++;
69 
70  // Store indices in local map (starts at 0)
72  tjTkMap[iTjRef - 1] = iTkRef - 1;
73 
74  //sets the outermost and innermost TSOSs
75  TrajectoryStateOnSurface outertsos;
76  TrajectoryStateOnSurface innertsos;
77  unsigned int innerId, outerId;
78 
79  // --- NOTA BENE: the convention is to sort hits and measurements "along the momentum".
80  // This is consistent with innermost and outermost labels only for tracks from LHC collision
81  if (theTraj->direction() == alongMomentum) {
82  outertsos = theTraj->lastMeasurement().updatedState();
83  innertsos = theTraj->firstMeasurement().updatedState();
84  outerId = theTraj->lastMeasurement().recHit()->geographicalId().rawId();
85  innerId = theTraj->firstMeasurement().recHit()->geographicalId().rawId();
86  } else {
87  outertsos = theTraj->firstMeasurement().updatedState();
88  innertsos = theTraj->lastMeasurement().updatedState();
89  outerId = theTraj->firstMeasurement().recHit()->geographicalId().rawId();
90  innerId = theTraj->lastMeasurement().recHit()->geographicalId().rawId();
91  }
92  // ---
93  //build the TrackExtra
94  GlobalPoint v = outertsos.globalParameters().position();
95  GlobalVector p = outertsos.globalParameters().momentum();
96  math::XYZVector outmom(p.x(), p.y(), p.z());
97  math::XYZPoint outpos(v.x(), v.y(), v.z());
98  v = innertsos.globalParameters().position();
99  p = innertsos.globalParameters().momentum();
100  math::XYZVector inmom(p.x(), p.y(), p.z());
101  math::XYZPoint inpos(v.x(), v.y(), v.z());
102 
103  reco::TrackExtraRef teref = reco::TrackExtraRef(rTrackExtras, idx++);
104  reco::Track& track = selTracks->back();
105  track.setExtra(teref);
106  //======= I want to set the second hitPattern here =============
107  if (theSchool.isValid()) {
109  evt.getByToken(mteSrc_, mte);
110  // NavigationSetter setter( *theSchool );
111  setSecondHitPattern(theTraj, track, prop, &*mte, ttopo);
112  }
113  //==============================================================
114 
115  selTrackExtras->push_back(reco::TrackExtra(outpos,
116  outmom,
117  true,
118  inpos,
119  inmom,
120  true,
121  outertsos.curvilinearError(),
122  outerId,
123  innertsos.curvilinearError(),
124  innerId,
125  seedDir,
126  theTraj->seedRef()));
127 
128  // FIXME will remove this obsolete config-param in a future PR
130 
131  reco::TrackExtra& tx = selTrackExtras->back();
132  // --- NOTA BENE: the convention is to sort hits and measurements "along the momentum".
133  // This is consistent with innermost and outermost labels only for tracks from LHC collisions
134  reco::TrackExtra::TrajParams trajParams;
136  Traj2TrackHits t2t;
137  auto ih = selHits->size();
138  t2t(*theTraj, *selHits, trajParams, chi2s);
139  auto ie = selHits->size();
140  tx.setHits(rHits, ih, ie - ih);
141  tx.setTrajParams(std::move(trajParams), std::move(chi2s));
142  assert(tx.trajParams().size() == tx.recHitsSize());
143  for (; ih < ie; ++ih) {
144  auto const& hit = (*selHits)[ih];
145  track.appendHitPattern(hit, *ttopo);
146  }
147 
148  // ----
149  tx.setResiduals(trajectoryToResiduals(*theTraj));
150 
151  delete theTraj;
152  }
153 
154  // Now we can re-set refs to hits, as they have already been cloned
155  if (rekeyClusterRefs_) {
157  for (TrackingRecHitCollection::iterator it = selHits->begin(), ed = selHits->end(); it != ed; ++it) {
158  refSetter.reKey(&*it);
159  }
160  }
161 
162  LogTrace("TrackingRegressionTest") << "========== TrackProducer Info ===================";
163  LogTrace("TrackingRegressionTest") << "number of finalTracks: " << selTracks->size();
164  for (reco::TrackCollection::const_iterator it = selTracks->begin(); it != selTracks->end(); it++) {
165  LogTrace("TrackingRegressionTest") << "track's n valid and invalid hit, chi2, pt, eta : " << it->found() << " , "
166  << it->lost() << " , " << it->normalizedChi2() << " , " << it->pt() << " , "
167  << it->eta();
168  }
169  LogTrace("TrackingRegressionTest") << "=================================================";
170 
171  selTracks->shrink_to_fit();
172  selTrackExtras->shrink_to_fit();
173  selHits->shrink_to_fit();
174  indecesInput->shrink_to_fit();
175  if (BeforeOrAfter == 1) {
176  rTracks_ = evt.put(std::move(selTracks), "beforeDAF");
177  evt.put(std::move(selTrackExtras), "beforeDAF");
178  evt.put(std::move(indecesInput), "beforeDAF");
179  } else if (BeforeOrAfter == 2) {
180  rTracks_ = evt.put(std::move(selTracks), "afterDAF");
181  evt.put(std::move(selTrackExtras), "afterDAF");
182  evt.put(std::move(indecesInput), "afterDAF");
183  } else {
184  rTracks_ = evt.put(std::move(selTracks));
185  evt.put(std::move(selTrackExtras));
186  evt.put(std::move(selHits));
187  evt.put(std::move(indecesInput));
188  }
189 
190  if (trajectoryInEvent_ && BeforeOrAfter == 0) {
191  selTrajectories->shrink_to_fit();
192  edm::OrphanHandle<std::vector<Trajectory> > rTrajs = evt.put(std::move(selTrajectories));
193 
194  // Now Create traj<->tracks association map
195  std::unique_ptr<TrajTrackAssociationCollection> trajTrackMap(new TrajTrackAssociationCollection(rTrajs, rTracks_));
196  for (std::map<unsigned int, unsigned int>::iterator i = tjTkMap.begin(); i != tjTkMap.end(); i++) {
197  edm::Ref<std::vector<Trajectory> > trajRef(rTrajs, (*i).first);
198  edm::Ref<reco::TrackCollection> tkRef(rTracks_, (*i).second);
199  trajTrackMap->insert(edm::Ref<std::vector<Trajectory> >(rTrajs, (*i).first),
201  }
202  evt.put(std::move(trajTrackMap));
203  }
204 }
std::remove_cv< typename std::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:164
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
TrajParams const & trajParams() const
virtual void putInEvt(edm::Event &, const Propagator *prop, const MeasurementTracker *measTk, std::unique_ptr< TrackingRecHitCollection > &, std::unique_ptr< reco::TrackCollection > &, std::unique_ptr< reco::TrackExtraCollection > &, std::unique_ptr< std::vector< Trajectory > > &, std::unique_ptr< std::vector< int > > &, AlgoProductCollection &, TransientTrackingRecHitBuilder const *, const TrackerTopology *ttopo, int BeforeOrAfter=0)
Put produced collections in the event.
std::vector< unsigned char > Chi2sFive
void setHits(TrackingRecHitRefProd const &prod, unsigned firstH, unsigned int nH)
unsigned int recHitsSize() const
number of RecHits
const GlobalTrajectoryParameters & globalParameters() const
void setSecondHitPattern(Trajectory *traj, reco::Track &track, const Propagator *prop, const MeasurementTrackerEvent *measTk, const TrackerTopology *ttopo)
edm::Ref< TrackExtraCollection > TrackExtraRef
persistent reference to a TrackExtra
Definition: TrackExtraFwd.h:16
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:536
PropagationDirection
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
assert(be >=bs)
#define LogTrace(id)
std::vector< LocalTrajectoryParameters > TrajParams
edm::AssociationMap< edm::OneToOne< std::vector< Trajectory >, reco::TrackCollection, unsigned short > > TrajTrackAssociationCollection
edm::InputTag clusterRemovalInfo_
RefProd< PROD > getRefBeforePut()
Definition: Event.h:158
bool isValid() const
Definition: ESHandle.h:44
edm::EDGetTokenT< MeasurementTrackerEvent > mteSrc_
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:10
const CurvilinearTrajectoryError & curvilinearError() const
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
std::vector< AlgoProduct > AlgoProductCollection
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
reco::TrackResiduals trajectoryToResiduals(const Trajectory &trajectory)
void reKey(TrackingRecHit *hit) const
edm::ESHandle< NavigationSchool > theSchool
edm::OrphanHandle< TrackCollection > rTracks_
def move(src, dest)
Definition: eostools.py:511
void setTrajParams(TrajParams tmps, Chi2sFive chi2s)
#define LogDebug(id)
void setResiduals(const TrackResiduals &r)
set the residuals
Definition: TrackExtra.h:132