CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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::auto_ptr<TrackingRecHitCollection>& selHits,
26  std::auto_ptr<reco::TrackCollection>& selTracks,
27  std::auto_ptr<reco::TrackExtraCollection>& selTrackExtras,
28  std::auto_ptr<std::vector<Trajectory> >& selTrajectories,
29  AlgoProductCollection& algoResults, TransientTrackingRecHitBuilder const * hitBuilder)
30 {
31 
34 
37  edm::Ref< std::vector<Trajectory> >::key_type iTjRef = 0;
38  std::map<unsigned int, unsigned int> tjTkMap;
39 
40  selTracks->reserve(algoResults.size());
41  selTrackExtras->reserve(algoResults.size());
42  if(trajectoryInEvent_) selTrajectories->reserve(algoResults.size());
43 
44  for(AlgoProductCollection::iterator i=algoResults.begin(); i!=algoResults.end();i++){
45  Trajectory * theTraj = (*i).first;
46  if(trajectoryInEvent_) {
47  selTrajectories->push_back(*theTraj);
48  iTjRef++;
49  }
50 
51 
52  reco::Track * theTrack = (*i).second.first;
53 
54  // Hits are going to be re-sorted along momentum few lines later.
55  // Therefore the direction stored in the TrackExtra
56  // has to be "alongMomentum" as well. Anyway, this direction can be differnt from the one of the orignal
57  // seed! The name seedDirection() for the Track's method (and the corresponding data member) is
58  // misleading and should be changed into something like "hitsDirection()". TO BE FIXED!
59 
61 
62  LogDebug("TrackProducer") << "In KfTrackProducerBase::putInEvt - seedDir=" << seedDir;
63 
64 
65  selTracks->push_back(std::move(*theTrack));
66  delete theTrack;
67  iTkRef++;
68 
69  // Store indices in local map (starts at 0)
70  if(trajectoryInEvent_) tjTkMap[iTjRef-1] = iTkRef-1;
71 
72  //sets the outermost and innermost TSOSs
73  TrajectoryStateOnSurface outertsos;
74  TrajectoryStateOnSurface innertsos;
75  unsigned int innerId, outerId;
76 
77  // --- NOTA BENE: the convention is to sort hits and measurements "along the momentum".
78  // This is consistent with innermost and outermost labels only for tracks from LHC collision
79  if (theTraj->direction() == alongMomentum) {
80  outertsos = theTraj->lastMeasurement().updatedState();
81  innertsos = theTraj->firstMeasurement().updatedState();
82  outerId = theTraj->lastMeasurement().recHit()->geographicalId().rawId();
83  innerId = theTraj->firstMeasurement().recHit()->geographicalId().rawId();
84  } else {
85  outertsos = theTraj->firstMeasurement().updatedState();
86  innertsos = theTraj->lastMeasurement().updatedState();
87  outerId = theTraj->firstMeasurement().recHit()->geographicalId().rawId();
88  innerId = theTraj->lastMeasurement().recHit()->geographicalId().rawId();
89  }
90  // ---
91  //build the TrackExtra
92  GlobalPoint v = outertsos.globalParameters().position();
93  GlobalVector p = outertsos.globalParameters().momentum();
94  math::XYZVector outmom( p.x(), p.y(), p.z() );
95  math::XYZPoint outpos( v.x(), v.y(), v.z() );
96  v = innertsos.globalParameters().position();
97  p = innertsos.globalParameters().momentum();
98  math::XYZVector inmom( p.x(), p.y(), p.z() );
99  math::XYZPoint inpos( v.x(), v.y(), v.z() );
100 
101  reco::TrackExtraRef teref= reco::TrackExtraRef ( rTrackExtras, idx ++ );
102  reco::Track & track = selTracks->back();
103  track.setExtra( teref );
104  //======= I want to set the second hitPattern here =============
105  if (theSchool.isValid())
106  {
108  evt.getByToken(mteSrc_, mte);
109  // NavigationSetter setter( *theSchool );
110  setSecondHitPattern(theTraj,track,prop,&*mte);
111  }
112  //==============================================================
113 
114  selTrackExtras->push_back( reco::TrackExtra (outpos, outmom, true, inpos, inmom, true,
115  outertsos.curvilinearError(), outerId,
116  innertsos.curvilinearError(), innerId,
117  seedDir, theTraj->seedRef()));
118 
119 
120  reco::TrackExtra & tx = selTrackExtras->back();
121  // --- NOTA BENE: the convention is to sort hits and measurements "along the momentum".
122  // This is consistent with innermost and outermost labels only for tracks from LHC collisions
123  Traj2TrackHits t2t(hitBuilder,false);
124  auto ih = selHits->size();
125  t2t(*theTraj,*selHits,useSplitting);
126  auto ie = selHits->size();
127  tx.setHits(rHits,ih,ie-ih);
128  for (;ih<ie; ++ih) {
129  auto const & hit = (*selHits)[ih];
130  track.appendHitPattern(hit);
131  }
132 
133  // ----
134  tx.setResiduals(trajectoryToResiduals(*theTraj));
135 
136  delete theTraj;
137  }
138 
139  // Now we can re-set refs to hits, as they have already been cloned
140  if (rekeyClusterRefs_) {
142  for (TrackingRecHitCollection::iterator it = selHits->begin(), ed = selHits->end(); it != ed; ++it) {
143  refSetter.reKey(&*it);
144  }
145  }
146 
147  LogTrace("TrackingRegressionTest") << "========== TrackProducer Info ===================";
148  LogTrace("TrackingRegressionTest") << "number of finalTracks: " << selTracks->size();
149  for (reco::TrackCollection::const_iterator it = selTracks->begin(); it != selTracks->end(); it++) {
150  LogTrace("TrackingRegressionTest") << "track's n valid and invalid hit, chi2, pt, eta : "
151  << it->found() << " , "
152  << it->lost() <<" , "
153  << it->normalizedChi2() << " , "
154  << it->pt() << " , "
155  << it->eta() ;
156  }
157  LogTrace("TrackingRegressionTest") << "=================================================";
158 
159  selTracks->shrink_to_fit();
160  selTrackExtras->shrink_to_fit();
161  selHits->shrink_to_fit();
162  rTracks_ = evt.put( selTracks );
163  evt.put( selTrackExtras );
164  evt.put( selHits );
165 
166  if(trajectoryInEvent_) {
167  selTrajectories->shrink_to_fit();
168  edm::OrphanHandle<std::vector<Trajectory> > rTrajs = evt.put(selTrajectories);
169 
170  // Now Create traj<->tracks association map
171  std::auto_ptr<TrajTrackAssociationCollection> trajTrackMap( new TrajTrackAssociationCollection() );
172  for ( std::map<unsigned int, unsigned int>::iterator i = tjTkMap.begin();
173  i != tjTkMap.end(); i++ ) {
174  edm::Ref<std::vector<Trajectory> > trajRef( rTrajs, (*i).first );
175  edm::Ref<reco::TrackCollection> tkRef( rTracks_, (*i).second );
176  trajTrackMap->insert( edm::Ref<std::vector<Trajectory> >( rTrajs, (*i).first ),
177  edm::Ref<reco::TrackCollection>( rTracks_, (*i).second ) );
178  }
179  evt.put( trajTrackMap );
180  }
181 }
182 
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
ConstRecHitPointer const & recHit() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
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
edm::Ref< TrackExtraCollection > TrackExtraRef
persistent reference to a TrackExtra
Definition: TrackExtraFwd.h:17
PropagationDirection
virtual void putInEvt(edm::Event &, const Propagator *prop, const MeasurementTracker *measTk, std::auto_ptr< TrackingRecHitCollection > &, std::auto_ptr< reco::TrackCollection > &, std::auto_ptr< reco::TrackExtraCollection > &, std::auto_ptr< std::vector< Trajectory > > &, AlgoProductCollection &, TransientTrackingRecHitBuilder const *)
Put produced collections in the event.
PropagationDirection const & direction() const
Definition: Trajectory.cc:118
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
TrajectoryMeasurement const & lastMeasurement() const
Definition: Trajectory.h:181
void setSecondHitPattern(Trajectory *traj, reco::Track &track, const Propagator *prop, const MeasurementTrackerEvent *measTk)
T z() const
Definition: PV3DBase.h:64
def move
Definition: eostools.py:508
bool appendHitPattern(const TrackingRecHit &hit)
append a single hit to the HitPattern
Definition: TrackBase.h:421
edm::RefToBase< TrajectorySeed > seedRef(void) const
Definition: Trajectory.h:306
std::vector< AlgoProduct > AlgoProductCollection
edm::AssociationMap< edm::OneToOne< std::vector< Trajectory >, reco::TrackCollection, unsigned short > > TrajTrackAssociationCollection
#define LogTrace(id)
RefProd< PROD > getRefBeforePut()
Definition: Event.h:133
edm::EDGetTokenT< MeasurementTrackerEvent > mteSrc_
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:11
void setExtra(const TrackExtraRef &ref)
set reference to &quot;extra&quot; object
Definition: Track.h:184
TrajectoryMeasurement const & firstMeasurement() const
Definition: Trajectory.h:194
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
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
edm::ESHandle< NavigationSchool > theSchool
TrajectoryStateOnSurface const & updatedState() const
reco::TrackResiduals trajectoryToResiduals(const Trajectory &trajectory, enum reco::TrackResiduals::ResidualType type)
bool isValid() const
Definition: ESHandle.h:47
edm::OrphanHandle< TrackCollection > rTracks_
T x() const
Definition: PV3DBase.h:62
boost::remove_cv< typename boost::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:170
void setResiduals(const TrackResiduals &r)
set the residuals
Definition: TrackExtra.h:179