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  const TrackerTopology *ttopo,
31  int BeforeOrAfter)
32 {
33 
36 
39  edm::Ref< std::vector<Trajectory> >::key_type iTjRef = 0;
40  std::map<unsigned int, unsigned int> tjTkMap;
41 
42  selTracks->reserve(algoResults.size());
43  selTrackExtras->reserve(algoResults.size());
44  if(trajectoryInEvent_) selTrajectories->reserve(algoResults.size());
45 
46  for(AlgoProductCollection::iterator i=algoResults.begin(); i!=algoResults.end();i++){
47  Trajectory * theTraj = (*i).first;
48  if(trajectoryInEvent_) {
49  selTrajectories->push_back(*theTraj);
50  iTjRef++;
51  }
52 
53 
54  reco::Track * theTrack = (*i).second.first;
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 
67  selTracks->push_back(std::move(*theTrack));
68  delete theTrack;
69  iTkRef++;
70 
71  // Store indices in local map (starts at 0)
72  if(trajectoryInEvent_) 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())
108  {
110  evt.getByToken(mteSrc_, mte);
111  // NavigationSetter setter( *theSchool );
112  setSecondHitPattern(theTraj,track,prop,&*mte, ttopo);
113  }
114  //==============================================================
115 
116  selTrackExtras->push_back( reco::TrackExtra (outpos, outmom, true, inpos, inmom, true,
117  outertsos.curvilinearError(), outerId,
118  innertsos.curvilinearError(), innerId,
119  seedDir, theTraj->seedRef()));
120 
121 
122  reco::TrackExtra & tx = selTrackExtras->back();
123  // --- NOTA BENE: the convention is to sort hits and measurements "along the momentum".
124  // This is consistent with innermost and outermost labels only for tracks from LHC collisions
125  Traj2TrackHits t2t(hitBuilder,false);
126  auto ih = selHits->size();
127  t2t(*theTraj,*selHits,useSplitting);
128  auto ie = selHits->size();
129  tx.setHits(rHits,ih,ie-ih);
130  for (;ih<ie; ++ih) {
131  auto const & hit = (*selHits)[ih];
132  track.appendHitPattern(hit, *ttopo);
133  }
134 
135  // ----
136  tx.setResiduals(trajectoryToResiduals(*theTraj));
137 
138  delete theTraj;
139  }
140 
141  // Now we can re-set refs to hits, as they have already been cloned
142  if (rekeyClusterRefs_) {
144  for (TrackingRecHitCollection::iterator it = selHits->begin(), ed = selHits->end(); it != ed; ++it) {
145  refSetter.reKey(&*it);
146  }
147  }
148 
149  LogTrace("TrackingRegressionTest") << "========== TrackProducer Info ===================";
150  LogTrace("TrackingRegressionTest") << "number of finalTracks: " << selTracks->size();
151  for (reco::TrackCollection::const_iterator it = selTracks->begin(); it != selTracks->end(); it++) {
152  LogTrace("TrackingRegressionTest") << "track's n valid and invalid hit, chi2, pt, eta : "
153  << it->found() << " , "
154  << it->lost() <<" , "
155  << it->normalizedChi2() << " , "
156  << it->pt() << " , "
157  << it->eta() ;
158  }
159  LogTrace("TrackingRegressionTest") << "=================================================";
160 
161  selTracks->shrink_to_fit();
162  selTrackExtras->shrink_to_fit();
163  selHits->shrink_to_fit();
164  if(BeforeOrAfter == 1){
165  rTracks_ = evt.put( selTracks, "beforeDAF" );
166  evt.put( selTrackExtras , "beforeDAF");
167  } else if (BeforeOrAfter == 2){
168  rTracks_ = evt.put( selTracks, "afterDAF" );
169  evt.put( selTrackExtras, "afterDAF" );
170  } else {
171  rTracks_ = evt.put( selTracks );
172  evt.put( selTrackExtras );
173  evt.put( selHits );
174  }
175 
176 
177  if(trajectoryInEvent_ && BeforeOrAfter == 0) {
178  selTrajectories->shrink_to_fit();
179  edm::OrphanHandle<std::vector<Trajectory> > rTrajs = evt.put(selTrajectories);
180 
181  // Now Create traj<->tracks association map
182  std::auto_ptr<TrajTrackAssociationCollection> trajTrackMap( new TrajTrackAssociationCollection(rTrajs, rTracks_) );
183  for ( std::map<unsigned int, unsigned int>::iterator i = tjTkMap.begin();
184  i != tjTkMap.end(); i++ ) {
185  edm::Ref<std::vector<Trajectory> > trajRef( rTrajs, (*i).first );
186  edm::Ref<reco::TrackCollection> tkRef( rTracks_, (*i).second );
187  trajTrackMap->insert( edm::Ref<std::vector<Trajectory> >( rTrajs, (*i).first ),
188  edm::Ref<reco::TrackCollection>( rTracks_, (*i).second ) );
189  }
190  evt.put( trajTrackMap );
191  }
192 }
193 
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
ConstRecHitPointer const & recHit() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
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
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
PropagationDirection const & direction() const
Definition: Trajectory.cc:118
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
TrajectoryMeasurement const & lastMeasurement() const
Definition: Trajectory.h:181
T z() const
Definition: PV3DBase.h:64
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:140
edm::EDGetTokenT< MeasurementTrackerEvent > mteSrc_
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 *, const TrackerTopology *ttopo, int BeforeOrAfter=0)
Put produced collections in the event.
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...
bool appendHitPattern(const TrackingRecHit &hit, const TrackerTopology &ttopo)
append a single hit to the HitPattern
Definition: TrackBase.h:447
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:168
void setResiduals(const TrackResiduals &r)
set the residuals
Definition: TrackExtra.h:179