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 }
Vector3DBase
Definition: Vector3DBase.h:8
edm::RefProd< TrackingRecHitCollection >
Propagator.h
edm::Event::getRefBeforePut
RefProd< PROD > getRefBeforePut()
Definition: Event.h:158
KfTrackProducerBase::useSplitting
bool useSplitting
Definition: KfTrackProducerBase.h:42
mps_fire.i
i
Definition: mps_fire.py:428
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11779
TrackProducerBase< reco::Track >::rTracks_
edm::OrphanHandle< TrackCollection > rTracks_
Definition: TrackProducerBase.h:109
MessageLogger.h
TrackerGeometry.h
GlobalTrajectoryParameters::position
GlobalPoint position() const
Definition: GlobalTrajectoryParameters.h:60
TrackerTopology
Definition: TrackerTopology.h:16
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
cms::cuda::assert
assert(be >=bs)
findQualityFiles.v
v
Definition: findQualityFiles.py:179
TrackProducerBase< reco::Track >::setSecondHitPattern
void setSecondHitPattern(Trajectory *traj, reco::Track &track, const Propagator *prop, const MeasurementTrackerEvent *measTk, const TrackerTopology *ttopo)
edm::Handle< MeasurementTrackerEvent >
AlgoProductTraits< reco::Track >::AlgoProductCollection
std::vector< AlgoProduct > AlgoProductCollection
Definition: AlgoProductTraits.h:20
edm::Ref
Definition: AssociativeIterator.h:58
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
Propagator
Definition: Propagator.h:44
reco::TrackExtra
Definition: TrackExtra.h:26
MeasurementTracker
Definition: MeasurementTracker.h:21
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
MakerMacros.h
ClusterRemovalRefSetter
Definition: ClusterRemovalRefSetter.h:21
KfTrackProducerBase.h
reco::Track
Definition: Track.h:27
reco::TrackExtraCollection
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:10
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:531
Traj2TrackHits.h
Point3DBase< float, GlobalTag >
TrajTrackAssociation.h
GlobalTrajectoryParameters::momentum
GlobalVector momentum() const
Definition: GlobalTrajectoryParameters.h:65
reco::TrackExtraBase::setTrajParams
void setTrajParams(TrajParams tmps, Chi2sFive chi2s)
Definition: TrackExtraBase.h:36
reco::TrackExtra::setResiduals
void setResiduals(const TrackResiduals &r)
set the residuals
Definition: TrackExtra.h:132
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
math::XYZPoint
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
ClusterRemovalRefSetter.h
KfTrackProducerBase::putInEvt
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.
Definition: KfTrackProducerBase.cc:21
Traj2TrackHits
Definition: Traj2TrackHits.h:16
math::XYZVector
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
reco::TrackExtraRef
edm::Ref< TrackExtraCollection > TrackExtraRef
persistent reference to a TrackExtra
Definition: TrackExtraFwd.h:16
reco::TrackExtraBase::trajParams
TrajParams const & trajParams() const
Definition: TrackExtraBase.h:76
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
trajectoryToResiduals
reco::TrackResiduals trajectoryToResiduals(const Trajectory &trajectory)
Definition: TrajectoryToResiduals.cc:7
ClusterRemovalRefSetter::reKey
void reKey(TrackingRecHit *hit) const
TrackProducerBase< reco::Track >::trajectoryInEvent_
bool trajectoryInEvent_
Definition: TrackProducerBase.h:108
edm::ESHandleBase::isValid
bool isValid() const
Definition: ESHandle.h:44
edm::Ref::key_type
std::remove_cv< typename std::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:164
reco::TrackExtraBase::setHits
void setHits(TrackingRecHitRefProd const &prod, unsigned firstH, unsigned int nH)
Definition: TrackExtraBase.h:30
reco::TrackExtraBase::recHitsSize
unsigned int recHitsSize() const
number of RecHits
Definition: TrackExtraBase.h:44
cms::cuda::device::unique_ptr
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
Definition: device_unique_ptr.h:33
Trajectory.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
edm::OrphanHandle
Definition: EDProductfwd.h:39
reco::TrackExtraBase::Chi2sFive
std::vector< unsigned char > Chi2sFive
Definition: TrackExtraBase.h:25
Frameworkfwd.h
TrackProducerBase< reco::Track >::mteSrc_
edm::EDGetTokenT< MeasurementTrackerEvent > mteSrc_
Definition: TrackProducerBase.h:111
TrackResiduals.h
TrajectoryStateOnSurface::curvilinearError
const CurvilinearTrajectoryError & curvilinearError() const
Definition: TrajectoryStateOnSurface.h:72
PropagationDirection
PropagationDirection
Definition: PropagationDirection.h:4
TrajTrackAssociationCollection
edm::AssociationMap< edm::OneToOne< std::vector< Trajectory >, reco::TrackCollection, unsigned short > > TrajTrackAssociationCollection
Definition: TrajTrackAssociation.h:9
TrackProducerBase< reco::Track >::rekeyClusterRefs_
bool rekeyClusterRefs_
Definition: TrackProducerBase.h:113
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:224
TrajectoryStateOnSurface::globalParameters
const GlobalTrajectoryParameters & globalParameters() const
Definition: TrajectoryStateOnSurface.h:64
edm::Event
Definition: Event.h:73
TransientTrackingRecHitBuilder
Definition: TransientTrackingRecHitBuilder.h:6
reco::TrackExtraBase::TrajParams
std::vector< LocalTrajectoryParameters > TrajParams
Definition: TrackExtraBase.h:24
alongMomentum
Definition: PropagationDirection.h:4
TrajectoryToResiduals.h
hit
Definition: SiStripHitEffFromCalibTree.cc:88
edm::OwnVector< TrackingRecHit >
TrackProducerBase< reco::Track >::clusterRemovalInfo_
edm::InputTag clusterRemovalInfo_
Definition: TrackProducerBase.h:114
TrackProducerBase< reco::Track >::theSchool
edm::ESHandle< NavigationSchool > theSchool
Definition: TrackProducerBase.h:116