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 
38  edm::Ref< std::vector<Trajectory> >::key_type iTjRef = 0;
39  std::map<unsigned int, unsigned int> tjTkMap;
40 
41  for(AlgoProductCollection::iterator i=algoResults.begin(); i!=algoResults.end();i++){
42  Trajectory * theTraj = (*i).first;
43  if(trajectoryInEvent_) {
44  selTrajectories->push_back(*theTraj);
45  iTjRef++;
46  }
47 
48 
49  reco::Track * theTrack = (*i).second.first;
50 
51  // Hits are going to be re-sorted along momentum few lines later.
52  // Therefore the direction stored in the TrackExtra
53  // has to be "alongMomentum" as well. Anyway, this direction can be differnt from the one of the orignal
54  // seed! The name seedDirection() for the Track's method (and the corresponding data member) is
55  // misleading and should be changed into something like "hitsDirection()". TO BE FIXED!
57 
58  LogDebug("TrackProducer") << "In KfTrackProducerBase::putInEvt - seedDir=" << seedDir;
59 
60  reco::Track t = * theTrack;
61  selTracks->push_back( t );
62  iTkRef++;
63 
64  // Store indices in local map (starts at 0)
65  if(trajectoryInEvent_) tjTkMap[iTjRef-1] = iTkRef-1;
66 
67  //sets the outermost and innermost TSOSs
68  TrajectoryStateOnSurface outertsos;
69  TrajectoryStateOnSurface innertsos;
70  unsigned int innerId, outerId;
71 
72  // --- NOTA BENE: the convention is to sort hits and measurements "along the momentum".
73  // This is consistent with innermost and outermost labels only for tracks from LHC collision
74  if (theTraj->direction() == alongMomentum) {
75  outertsos = theTraj->lastMeasurement().updatedState();
76  innertsos = theTraj->firstMeasurement().updatedState();
77  outerId = theTraj->lastMeasurement().recHit()->geographicalId().rawId();
78  innerId = theTraj->firstMeasurement().recHit()->geographicalId().rawId();
79  } else {
80  outertsos = theTraj->firstMeasurement().updatedState();
81  innertsos = theTraj->lastMeasurement().updatedState();
82  outerId = theTraj->firstMeasurement().recHit()->geographicalId().rawId();
83  innerId = theTraj->lastMeasurement().recHit()->geographicalId().rawId();
84  }
85  // ---
86  //build the TrackExtra
87  GlobalPoint v = outertsos.globalParameters().position();
88  GlobalVector p = outertsos.globalParameters().momentum();
89  math::XYZVector outmom( p.x(), p.y(), p.z() );
90  math::XYZPoint outpos( v.x(), v.y(), v.z() );
91  v = innertsos.globalParameters().position();
92  p = innertsos.globalParameters().momentum();
93  math::XYZVector inmom( p.x(), p.y(), p.z() );
94  math::XYZPoint inpos( v.x(), v.y(), v.z() );
95 
96  reco::TrackExtraRef teref= reco::TrackExtraRef ( rTrackExtras, idx ++ );
97  reco::Track & track = selTracks->back();
98  track.setExtra( teref );
99 
100  //======= I want to set the second hitPattern here =============
101  if (theSchool.isValid())
102  {
104  evt.getByToken(mteSrc_, mte);
105  // NavigationSetter setter( *theSchool );
106  setSecondHitPattern(theTraj,track,prop,&*mte);
107  }
108  //==============================================================
109 
110  selTrackExtras->push_back( reco::TrackExtra (outpos, outmom, true, inpos, inmom, true,
111  outertsos.curvilinearError(), outerId,
112  innertsos.curvilinearError(), innerId,
113  seedDir, theTraj->seedRef()));
114 
115 
116  reco::TrackExtra & tx = selTrackExtras->back();
117  // --- NOTA BENE: the convention is to sort hits and measurements "along the momentum".
118  // This is consistent with innermost and outermost labels only for tracks from LHC collisions
119  Traj2TrackHits t2t(hitBuilder,false);
120  auto ih = selHits->size();
121  assert(ih==hidx);
122  t2t(*theTraj,*selHits,useSplitting);
123  auto ie = selHits->size();
124  size_t il = 0;
125  for (;ih<ie; ++ih) {
126  auto const & hit = (*selHits)[ih];
127  track.setHitPattern( hit, il ++ );
128  tx.add( TrackingRecHitRef( rHits, hidx ++ ) );
129  }
130 
131  /*
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  size_t ih = 0;
135  TrajectoryFitter::RecHitContainer transHits; theTraj->recHitsV(transHits, useSplitting);
136  if (theTraj->direction() == alongMomentum) {
137  for( TrajectoryFitter::RecHitContainer::const_iterator j = transHits.begin();
138  j != transHits.end(); j ++ ) {
139  if ((**j).hit()!=0){
140  TrackingRecHit * hit = (**j).hit()->clone();
141  track.setHitPattern( * hit, ih ++ );
142  selHits->push_back( hit );
143  tx.add( TrackingRecHitRef( rHits, hidx ++ ) );
144  }
145  }
146  }else{
147  for( TrajectoryFitter::RecHitContainer::const_iterator j = transHits.end()-1;
148  j != transHits.begin()-1; --j ) {
149  if ((**j).hit()!=0){
150  TrackingRecHit * hit = (**j).hit()->clone();
151  track.setHitPattern( * hit, ih ++ );
152  selHits->push_back( hit );
153  tx.add( TrackingRecHitRef( rHits, hidx ++ ) );
154  }
155  }
156  }
157  */
158 
159  // ----
160  tx.setResiduals(trajectoryToResiduals(*theTraj));
161 
162  delete theTrack;
163  delete theTraj;
164  }
165 
166  // Now we can re-set refs to hits, as they have already been cloned
167  if (rekeyClusterRefs_) {
169  for (TrackingRecHitCollection::iterator it = selHits->begin(), ed = selHits->end(); it != ed; ++it) {
170  refSetter.reKey(&*it);
171  }
172  }
173 
174  LogTrace("TrackingRegressionTest") << "========== TrackProducer Info ===================";
175  LogTrace("TrackingRegressionTest") << "number of finalTracks: " << selTracks->size();
176  for (reco::TrackCollection::const_iterator it = selTracks->begin(); it != selTracks->end(); it++) {
177  LogTrace("TrackingRegressionTest") << "track's n valid and invalid hit, chi2, pt, eta : "
178  << it->found() << " , "
179  << it->lost() <<" , "
180  << it->normalizedChi2() << " , "
181  << it->pt() << " , "
182  << it->eta() ;
183  }
184  LogTrace("TrackingRegressionTest") << "=================================================";
185 
186 
187  rTracks_ = evt.put( selTracks );
188  evt.put( selTrackExtras );
189  evt.put( selHits );
190 
191  if(trajectoryInEvent_) {
192  edm::OrphanHandle<std::vector<Trajectory> > rTrajs = evt.put(selTrajectories);
193 
194  // Now Create traj<->tracks association map
195  std::auto_ptr<TrajTrackAssociationCollection> trajTrackMap( new TrajTrackAssociationCollection() );
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( trajTrackMap );
204  }
205 }
206 
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
ConstRecHitPointer const & recHit() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
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:13
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:116
edm::Ref< TrackingRecHitCollection > TrackingRecHitRef
persistent reference to a TrackingRecHit
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
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:128
edm::EDGetTokenT< MeasurementTrackerEvent > mteSrc_
void setHitPattern(const C &c)
set hit patterns from vector of hit references
Definition: TrackBase.h:244
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:9
void setExtra(const TrackExtraRef &ref)
set reference to &quot;extra&quot; object
Definition: Track.h:95
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...
void add(const TrackingRecHitRef &r)
add a reference to a RecHit
edm::ESHandle< NavigationSchool > theSchool
TrajectoryStateOnSurface const & updatedState() const
reco::TrackResiduals trajectoryToResiduals(const Trajectory &trajectory, enum reco::TrackResiduals::ResidualType type)
boost::remove_cv< typename boost::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:170
bool isValid() const
Definition: ESHandle.h:37
edm::OrphanHandle< TrackCollection > rTracks_
T x() const
Definition: PV3DBase.h:62
void setResiduals(const TrackResiduals &r)
set the residuals
Definition: TrackExtra.h:131