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