CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GsfTrackProducerBase.cc
Go to the documentation of this file.
2 // system include files
3 #include <memory>
4 // user include files
20 
22 
25 
26 void
28  const Propagator* prop,
29  const MeasurementTracker* measTk,
30  std::auto_ptr<TrackingRecHitCollection>& selHits,
31  std::auto_ptr<reco::GsfTrackCollection>& selTracks,
32  std::auto_ptr<reco::TrackExtraCollection>& selTrackExtras,
33  std::auto_ptr<reco::GsfTrackExtraCollection>& selGsfTrackExtras,
34  std::auto_ptr<std::vector<Trajectory> >& selTrajectories,
35  AlgoProductCollection& algoResults,
36  const reco::BeamSpot& bs)
37 {
38 
43 
48  edm::Ref< std::vector<Trajectory> >::key_type iTjRef = 0;
49  std::map<unsigned int, unsigned int> tjTkMap;
50 
51  TSCBLBuilderNoMaterial tscblBuilder;
52 
53  for(AlgoProductCollection::iterator i=algoResults.begin(); i!=algoResults.end();i++){
54  Trajectory * theTraj = (*i).first;
55  if(trajectoryInEvent_) {
56  selTrajectories->push_back(*theTraj);
57  iTjRef++;
58  }
59 
60  // const TrajectoryFitter::RecHitContainer& transHits = theTraj->recHits(useSplitting); // NO: the return type in Trajectory is by VALUE
62  reco::GsfTrack * theTrack = (*i).second.first;
63  PropagationDirection seedDir = (*i).second.second;
64 
65  LogDebug("TrackProducer") << "In GsfTrackProducerBase::putInEvt - seedDir=" << seedDir;
66 
67  reco::GsfTrack t = * theTrack;
68  selTracks->push_back( t );
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  //build the TrackExtra
93  GlobalPoint v = outertsos.globalParameters().position();
94  GlobalVector p = outertsos.globalParameters().momentum();
95  math::XYZVector outmom( p.x(), p.y(), p.z() );
96  math::XYZPoint outpos( v.x(), v.y(), v.z() );
97  v = innertsos.globalParameters().position();
98  p = innertsos.globalParameters().momentum();
99  math::XYZVector inmom( p.x(), p.y(), p.z() );
100  math::XYZPoint inpos( v.x(), v.y(), v.z() );
101 
102  reco::TrackExtraRef teref= reco::TrackExtraRef ( rTrackExtras, idx ++ );
103  reco::GsfTrack & track = selTracks->back();
104  track.setExtra( teref );
105 
106  //======= I want to set the second hitPattern here =============
107  if (theSchool.isValid())
108  {
109  NavigationSetter setter( *theSchool );
110  setSecondHitPattern(theTraj,track,prop,measTk);
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 
122 
123  size_t ih = 0;
124  // --- NOTA BENE: the convention is to sort hits and measurements "along the momentum".
125  // This is consistent with innermost and outermost labels only for tracks from LHC collisions
126  if (theTraj->direction() == alongMomentum) {
127  for( TrajectoryFitter::RecHitContainer::const_iterator j = transHits.begin();
128  j != transHits.end(); j ++ ) {
129  if ((**j).hit()!=0){
130  TrackingRecHit * hit = (**j).hit()->clone();
131  track.setHitPattern( * hit, ih ++ );
132  selHits->push_back( hit );
133  tx.add( TrackingRecHitRef( rHits, hidx ++ ) );
134  }
135  }
136  }else{
137  for( TrajectoryFitter::RecHitContainer::const_iterator j = transHits.end()-1;
138  j != transHits.begin()-1; --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  }
147  // ----
148 
149  std::vector<reco::GsfTangent> tangents;
150  const Trajectory::DataContainer& measurements = theTraj->measurements();
151  if ( measurements.size()>2 ) {
152  tangents.reserve(measurements.size()-2);
153  Trajectory::DataContainer::const_iterator ibegin,iend;
154  int increment(0);
155  if (theTraj->direction() == alongMomentum) {
156  ibegin = measurements.begin() + 1;
157  iend = measurements.end() - 1;
158  increment = 1;
159  }
160  else {
161  ibegin = measurements.end() - 2;
162  iend = measurements.begin();
163  increment = -1;
164  }
166  math::XYZVector momentum;
167  Measurement1D deltaP;
168  // only measurements on "mono" detectors
169  for ( Trajectory::DataContainer::const_iterator i=ibegin;
170  i!=iend; i+=increment ) {
171  if ( i->recHit().get() ) {
172  DetId detId(i->recHit()->geographicalId());
173  if ( detId.det()==DetId::Tracker ) {
174  int subdetId = detId.subdetId();
175  if ( subdetId==SiStripDetId::TIB || subdetId==SiStripDetId::TID ||
176  subdetId==SiStripDetId::TOB || subdetId==SiStripDetId::TEC ) {
177  if ( SiStripDetId(detId).stereo() ) continue;
178  }
179  }
180  }
181  bool valid = computeModeAtTM(*i,position,momentum,deltaP);
182  if ( valid ) {
183  tangents.push_back(reco::GsfTangent(position,momentum,deltaP));
184  }
185  }
186  }
187 
188 
189  //build the GsfTrackExtra
190  std::vector<reco::GsfComponent5D> outerStates;
191  outerStates.reserve(outertsos.components().size());
192  fillStates(outertsos,outerStates);
193  std::vector<reco::GsfComponent5D> innerStates;
194  innerStates.reserve(innertsos.components().size());
195  fillStates(innertsos,innerStates);
196 
197 
198  reco::GsfTrackExtraRef terefGsf = reco::GsfTrackExtraRef ( rGsfTrackExtras, idxGsf ++ );
199  track.setGsfExtra( terefGsf );
200  selGsfTrackExtras->push_back( reco::GsfTrackExtra (outerStates, outertsos.localParameters().pzSign(),
201  innerStates, innertsos.localParameters().pzSign(),
202  tangents));
203 
204  if ( innertsos.isValid() ) {
206  TransverseImpactPointExtrapolator tipExtrapolator(gsfProp);
207  fillMode(track,innertsos,gsfProp,tipExtrapolator,tscblBuilder,bs);
208  }
209 
210  delete theTrack;
211  delete theTraj;
212  }
213 
214  LogTrace("TrackingRegressionTest") << "========== TrackProducer Info ===================";
215  LogTrace("TrackingRegressionTest") << "number of finalGsfTracks: " << selTracks->size();
216  for (reco::GsfTrackCollection::const_iterator it = selTracks->begin(); it != selTracks->end(); it++) {
217  LogTrace("TrackingRegressionTest") << "track's n valid and invalid hit, chi2, pt : "
218  << it->found() << " , "
219  << it->lost() <<" , "
220  << it->normalizedChi2() << " , "
221  << it->pt() << " , "
222  << it->eta() ;
223  }
224  LogTrace("TrackingRegressionTest") << "=================================================";
225 
226 
227  rTracks_ = evt.put( selTracks );
228  evt.put( selTrackExtras );
229  evt.put( selGsfTrackExtras );
230  evt.put( selHits );
231 
232  if(trajectoryInEvent_) {
233  edm::OrphanHandle<std::vector<Trajectory> > rTrajs = evt.put(selTrajectories);
234 
235  // Now Create traj<->tracks association map
236  std::auto_ptr<TrajGsfTrackAssociationCollection> trajTrackMap( new TrajGsfTrackAssociationCollection() );
237  for ( std::map<unsigned int, unsigned int>::iterator i = tjTkMap.begin();
238  i != tjTkMap.end(); i++ ) {
239  edm::Ref<std::vector<Trajectory> > trajRef( rTrajs, (*i).first );
240  edm::Ref<reco::GsfTrackCollection> tkRef( rTracks_, (*i).second );
241  trajTrackMap->insert( edm::Ref<std::vector<Trajectory> >( rTrajs, (*i).first ),
243  }
244  evt.put( trajTrackMap );
245  }
246 }
247 
248 void
250  std::vector<reco::GsfComponent5D>& states) const
251 {
254  std::vector<TrajectoryStateOnSurface> components(tsos.components());
255  for ( std::vector<TrajectoryStateOnSurface>::const_iterator i=components.begin();
256  i!=components.end(); ++i ) {
257  states.push_back(reco::GsfComponent5D(i->weight(),i->localParameters().vector(),i->localError().matrix()));
258  }
259 }
260 
261 void
263  const Propagator& gsfProp,
264  const TransverseImpactPointExtrapolator& tipExtrapolator,
266  const reco::BeamSpot& bs) const
267 {
268  // Get transverse impact parameter plane (from mean). This is a first approximation;
269  // the mode is then extrapolated to the
270  // final position closest to the beamline.
271  GlobalPoint bsPos(bs.position().x()+(track.vz()-bs.position().z())*bs.dxdz(),
272  bs.position().y()+(track.vz()-bs.position().z())*bs.dydz(),
273  track.vz());
274  TrajectoryStateOnSurface vtxTsos = tipExtrapolator.extrapolate(innertsos,bsPos);
275  if ( !vtxTsos.isValid() ) vtxTsos = innertsos;
276  // extrapolate mixture
277  vtxTsos = gsfProp.propagate(innertsos,vtxTsos.surface());
278  if ( !vtxTsos.isValid() ) return; // failed (GsfTrack keeps mode = mean)
279  // extract mode
280  // build perigee parameters (for covariance to be stored)
281  AlgebraicVector5 modeParameters;
282  AlgebraicSymMatrix55 modeCovariance;
283  // set parameters and variances for "mode" state (local parameters)
284  for ( unsigned int iv=0; iv<5; ++iv ) {
286  GaussianSumUtilities1D utils(state1D);
287  modeParameters(iv) = utils.mode().mean();
288  modeCovariance(iv,iv) = utils.mode().variance();
289  if ( !utils.modeIsValid() ) {
290  // if mode calculation fails: use mean
291  modeParameters(iv) = utils.mean();
292  modeCovariance(iv,iv) = utils.variance();
293  }
294  }
295  // complete covariance matrix
296  // approximation: use correlations from mean
297  const AlgebraicSymMatrix55& meanCovariance(vtxTsos.localError().matrix());
298  for ( unsigned int iv1=0; iv1<5; ++iv1 ) {
299  for ( unsigned int iv2=0; iv2<iv1; ++iv2 ) {
300  double cov12 = meanCovariance(iv1,iv2) *
301  sqrt(modeCovariance(iv1,iv1)/meanCovariance(iv1,iv1)*
302  modeCovariance(iv2,iv2)/meanCovariance(iv2,iv2));
303  modeCovariance(iv1,iv2) = modeCovariance(iv2,iv1) = cov12;
304  }
305  }
306  TrajectoryStateOnSurface modeTsos(LocalTrajectoryParameters(modeParameters,
307  vtxTsos.localParameters().pzSign()),
308  LocalTrajectoryError(modeCovariance),
309  vtxTsos.surface(),
310  vtxTsos.magneticField(),
311  vtxTsos.surfaceSide());
312  TrajectoryStateClosestToBeamLine tscbl = tscblBuilder(*modeTsos.freeState(),bs);
313  if ( !tscbl.isValid() ) return; // failed (GsfTrack keeps mode = mean)
314  //
315  // extract state at PCA and create momentum vector and covariance matrix
316  //
317  FreeTrajectoryState fts = tscbl.trackStateAtPCA();
318  GlobalVector tscblMom = fts.momentum();
319  reco::GsfTrack::Vector mom(tscblMom.x(),tscblMom.y(),tscblMom.z());
321  const AlgebraicSymMatrix55& tscblCov = fts.curvilinearError().matrix();
322  for ( unsigned int iv1=0; iv1<reco::GsfTrack::dimensionMode; ++iv1 ) {
323  for ( unsigned int iv2=0; iv2<reco::GsfTrack::dimensionMode; ++iv2 ) {
324  cov(iv1,iv2) = tscblCov(iv1,iv2);
325  }
326  }
327  track.setMode(fts.charge(),mom,cov);
328 }
329 
330 void
333  AlgebraicSymMatrix55& covariance) const
334 {
335  //
336  // parameters and errors from combined state
337  //
338  parameters = tsos.localParameters().vector();
339  covariance = tsos.localError().matrix();
340  //
341  // mode for parameter 0 (q/p)
342  //
344  GaussianSumUtilities1D qpGS(qpState);
345  if ( !qpGS.modeIsValid() ) return;
346  double qp = qpGS.mode().mean();
347  double varQp = qpGS.mode().variance();
348  //
349  // replace q/p value and variance, rescale correlation terms
350  // (heuristic procedure - alternative would be mode in 5D ...)
351  //
352  double VarQpRatio = sqrt(varQp/covariance(0,0));
353  parameters(0) = qp;
354  covariance(0,0) = varQp;
355  for ( int i=1; i<5; ++i ) covariance(i,0) *= VarQpRatio;
356 }
357 
358 bool
361  reco::GsfTrackExtra::Vector& momentum,
362  Measurement1D& deltaP) const
363 {
364  //
365  // states
366  //
369  TrajectoryStateOnSurface upState = tm.updatedState();
370 
371 
372  if ( !fwdState.isValid() || !bwdState.isValid() || !upState.isValid() ) {
373  return false;
374  }
375  //
376  // position from mean, momentum from mode (in cartesian coordinates)
377  // following PF code
378  //
379  GlobalPoint pos = upState.globalPosition();
380  position = reco::GsfTrackExtra::Point(pos.x(),pos.y(),pos.z());
382  GlobalVector mom;
383  bool result = mts.momentumFromModeCartesian(upState,mom);
384  if ( !result ) {
385 // std::cout << "momentumFromModeCartesian failed" << std::endl;
386  return false;
387  }
388  momentum = reco::GsfTrackExtra::Vector(mom.x(),mom.y(),mom.z());
389  //
390  // calculation from deltaP from fit to forward & backward predictions
391  // (momentum from mode) and hit
392  //
393  // prepare input parameter vectors and covariance matrices
394  AlgebraicVector5 fwdPars = fwdState.localParameters().vector();
395  AlgebraicSymMatrix55 fwdCov = fwdState.localError().matrix();
396  localParametersFromQpMode(fwdState,fwdPars,fwdCov);
397  AlgebraicVector5 bwdPars = bwdState.localParameters().vector();
398  AlgebraicSymMatrix55 bwdCov = bwdState.localError().matrix();
399  localParametersFromQpMode(bwdState,bwdPars,bwdCov);
400  LocalPoint hitPos(0.,0.,0.);
401  LocalError hitErr(-1.,-1.,-1.);
402  if ( tm.recHit()->isValid() ) {
403  hitPos = tm.recHit()->localPosition();
404  hitErr = tm.recHit()->localPositionError();
405  }
406  CollinearFitAtTM2 collinearFit(fwdPars,fwdCov,bwdPars,bwdCov,hitPos,hitErr);
407  deltaP = collinearFit.deltaP();
408 
409  return true;
410 }
#define LogDebug(id)
math::Error< dimension >::type CovarianceMatrix
int i
Definition: DBlmapReader.cc:9
dictionary parameters
Definition: Parameters.py:2
double pzSign() const
Sign of the z-component of the momentum in the local frame.
math::Error< dimensionMode >::type CovarianceMatrixMode
3 parameter covariance matrix (momentum part) from mode
Definition: GsfTrack.h:20
const LocalTrajectoryParameters & localParameters() const
void setGsfExtra(const GsfTrackExtraRef &ref)
set reference to GSF &quot;extra&quot; object
Definition: GsfTrack.h:29
TrajectoryStateOnSurface forwardPredictedState() const
Access to forward predicted state (from fitter or builder)
void setSecondHitPattern(Trajectory *traj, reco::GsfTrack &track, const Propagator *prop, const MeasurementTracker *measTk)
const CurvilinearTrajectoryError & curvilinearError() const
T y() const
Definition: PV3DBase.h:62
std::vector< GsfTrackExtra > GsfTrackExtraCollection
collection of GsfTrackExtra objects
GlobalPoint globalPosition() const
ConstRecHitPointer recHit() const
edm::Ref< TrackExtraCollection > TrackExtraRef
persistent reference to a TrackExtra
Definition: TrackExtraFwd.h:13
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
PropagationDirection
TrackCharge charge() const
void fillMode(reco::GsfTrack &track, const TrajectoryStateOnSurface innertsos, const Propagator &gsfProp, const TransverseImpactPointExtrapolator &tipExtrapolator, TrajectoryStateClosestToBeamLineBuilder &tscblBuilder, const reco::BeamSpot &bs) const
const MagneticField * magneticField() const
const CurvilinearTrajectoryError & curvilinearError() const
void fillStates(TrajectoryStateOnSurface tsos, std::vector< reco::GsfComponent5D > &states) const
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
ConstRecHitContainer recHits(bool splitting=false) const
Definition: Trajectory.cc:67
PropagationDirection const & direction() const
Definition: Trajectory.cc:195
double dydz() const
dydz slope
Definition: BeamSpot.h:85
DataContainer const & measurements() const
Definition: Trajectory.h:203
AlgebraicVector5 vector() const
void setMode(int chargeMode, const Vector &momentumMode, const CovarianceMatrixMode &covarianceMode)
set mode parameters
Definition: GsfTrack.cc:27
std::vector< TrajectoryMeasurement > DataContainer
Definition: Trajectory.h:42
virtual void putInEvt(edm::Event &, const Propagator *prop, const MeasurementTracker *measTk, std::auto_ptr< TrackingRecHitCollection > &, std::auto_ptr< reco::GsfTrackCollection > &, std::auto_ptr< reco::TrackExtraCollection > &, std::auto_ptr< reco::GsfTrackExtraCollection > &, std::auto_ptr< std::vector< Trajectory > > &, AlgoProductCollection &, const reco::BeamSpot &)
Put produced collections in the event.
MultiGaussianState1D multiState1D(const std::vector< MultiGaussianState< N >::Vector > &, const std::vector< MultiGaussianState< N >::Matrix > &, const std::vector< double > &, unsigned int)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
double mean() const
parameter vector
edm::Ref< TrackingRecHitCollection > TrackingRecHitRef
persistent reference to a TrackingRecHit
T sqrt(T t)
Definition: SSEVec.h:46
Measurement1D deltaP() const
estimated deltaP (out-in) from fit parameters
TrajectoryMeasurement const & lastMeasurement() const
Definition: Trajectory.h:181
T z() const
Definition: PV3DBase.h:63
std::vector< GsfTrack > GsfTrackCollection
collection of GsfTracks
Definition: GsfTrackFwd.h:9
tuple result
Definition: query.py:137
double variance() const
variance
const SingleGaussianState1D & mode() const
int j
Definition: DBlmapReader.cc:9
TrajectoryStateOnSurface updatedState() const
const AlgebraicSymMatrix55 & matrix() const
const LocalTrajectoryError & localError() const
edm::RefToBase< TrajectorySeed > seedRef(void) const
Definition: Trajectory.h:296
std::vector< AlgoProduct > AlgoProductCollection
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
void localParametersFromQpMode(const TrajectoryStateOnSurface tsos, AlgebraicVector5 &parameters, AlgebraicSymMatrix55 &covariance) const
local parameters rescaled with q/p from mode
GlobalVector momentum() const
#define LogTrace(id)
double dxdz() const
dxdz slope
Definition: BeamSpot.h:83
RefProd< PROD > getRefBeforePut()
Definition: Event.h:97
virtual TrajectoryStateOnSurface propagate(const FreeTrajectoryState &, const Surface &) const
Definition: Propagator.cc:12
edm::Ref< GsfTrackExtraCollection > GsfTrackExtraRef
persistent reference to a GsfTrackExtra
edm::AssociationMap< edm::OneToOne< std::vector< Trajectory >, reco::GsfTrackCollection, unsigned short > > TrajGsfTrackAssociationCollection
Detector identifier class for the strip tracker.
Definition: SiStripDetId.h:17
double vz() const
z coordinate of the reference point on track
Definition: TrackBase.h:147
bool computeModeAtTM(const TrajectoryMeasurement &tm, reco::GsfTrackExtra::Point &position, reco::GsfTrackExtra::Vector &momentum, Measurement1D &deltaP) const
position, momentum and estimated deltaP at an intermediate measurement (true if successful) ...
Definition: DetId.h:20
void setHitPattern(const C &c)
set hit patterns from vector of hit references
Definition: TrackBase.h:246
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
ROOT::Math::SVector< double, 5 > AlgebraicVector5
const GlobalTrajectoryParameters & globalParameters() const
double mean(unsigned int i) const
mean value of a component
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:13
math::XYZPoint Point
point in the space
Definition: GsfTrackExtra.h:25
void add(const TrackingRecHitRef &r)
add a reference to a RecHit
double variance(unsigned int i) const
variance of a component
TrajectoryStateOnSurface extrapolate(const FreeTrajectoryState &fts, const GlobalPoint &vtx) const
extrapolation with default (=geometrical) propagator
const AlgebraicSymMatrix55 & matrix() const
const Surface & surface() const
edm::ESHandle< NavigationSchool > theSchool
const Point & position() const
position
Definition: BeamSpot.h:63
math::XYZVector Vector
spatial vector
Definition: GsfTrackExtra.h:27
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_
std::vector< TrajectoryStateOnSurface > components() const
T x() const
Definition: PV3DBase.h:61
math::XYZVector Vector
spatial vector
Definition: TrackBase.h:74
Trajectory::RecHitContainer RecHitContainer
mathSSE::Vec4< T > v
TrajectoryStateOnSurface backwardPredictedState() const
Access to backward predicted state (from smoother)
bool modeIsValid() const
mode status
math::Vector< dimension >::type ParameterVector