CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackProducerAlgorithm.cc
Go to the documentation of this file.
2 
5 
8 
12 
21 
24 
31 
32 template <> bool
34  const Propagator * thePropagator,
35  AlgoProductCollection& algoResults,
37  TrajectoryStateOnSurface& theTSOS,
38  const TrajectorySeed& seed,
39  float ndof,
40  const reco::BeamSpot& bs,
41  SeedRef seedRef,
42  int qualityMask)
43 {
44  //variable declarations
45  std::vector<Trajectory> trajVec;
46  reco::Track * theTrack;
47  Trajectory * theTraj;
48  PropagationDirection seedDir = seed.direction();
49 
50  //perform the fit: the result's size is 1 if it succeded, 0 if fails
51  trajVec = theFitter->fit(seed, hits, theTSOS);
52 
53  LogDebug("TrackProducer") <<" FITTER FOUND "<< trajVec.size() << " TRAJECTORIES" <<"\n";
54  TrajectoryStateOnSurface innertsos;
55 
56  if (trajVec.size() != 0){
57 
58  theTraj = new Trajectory( trajVec.front() );
59  theTraj->setSeedRef(seedRef);
60 
61  if (theTraj->direction() == alongMomentum) {
62  innertsos = theTraj->firstMeasurement().updatedState();
63  } else {
64  innertsos = theTraj->lastMeasurement().updatedState();
65  }
66 
67  ndof = 0;
69  theTraj->validRecHits(validHits);
70  for (TransientTrackingRecHit::RecHitContainer::iterator h=validHits.begin();h!=validHits.end();++h)
71  ndof = ndof + ((*h)->dimension())*((*h)->weight());
72  if (theTSOS.magneticField()->inTesla(GlobalPoint(0,0,0)).mag2()<DBL_MIN) ndof = ndof - 4;
73  else ndof = ndof - 5;
74 
75  TSCBLBuilderNoMaterial tscblBuilder;
76  // const FreeTrajectoryState & stateForProjectionToBeamLine=*innertsos.freeState();
77  const TrajectoryStateOnSurface & stateForProjectionToBeamLineOnSurface = theTraj->closestMeasurement(GlobalPoint(bs.x0(),bs.y0(),bs.z0())).updatedState();
78  if (!stateForProjectionToBeamLineOnSurface.isValid()){
79  edm::LogError("CannotPropagateToBeamLine")<<"the state on the closest measurement isnot valid. skipping track.";
80  delete theTraj;
81  return false;
82  }
83  const FreeTrajectoryState & stateForProjectionToBeamLine=*stateForProjectionToBeamLineOnSurface.freeState();
84 
85  LogDebug("TrackProducer") << "stateForProjectionToBeamLine=" << stateForProjectionToBeamLine;
86 
87  TrajectoryStateClosestToBeamLine tscbl = tscblBuilder(stateForProjectionToBeamLine,bs);
88 
89  if (tscbl.isValid()==false) {
90  delete theTraj;
91  return false;
92  }
93 
95  math::XYZPoint pos( v.x(), v.y(), v.z() );
97  math::XYZVector mom( p.x(), p.y(), p.z() );
98 
99  LogDebug("TrackProducer") << "pos=" << v << " mom=" << p << " pt=" << p.perp() << " mag=" << p.mag();
100 
101  theTrack = new reco::Track(theTraj->chiSquared(),
102  int(ndof),//FIXME fix weight() in TrackingRecHit
103  pos, mom, tscbl.trackStateAtPCA().charge(),
105  algo_);
106 
107  theTrack->setQualityMask(qualityMask);
108 
109  LogDebug("TrackProducer") << "theTrack->pt()=" << theTrack->pt();
110 
111  LogDebug("TrackProducer") <<"track done\n";
112 
113  AlgoProduct aProduct(theTraj,std::make_pair(theTrack,seedDir));
114  algoResults.push_back(aProduct);
115 
116  return true;
117  }
118  else return false;
119 }
120 
121 template <> bool
123  const Propagator * thePropagator,
124  AlgoProductCollection& algoResults,
126  TrajectoryStateOnSurface& theTSOS,
127  const TrajectorySeed& seed,
128  float ndof,
129  const reco::BeamSpot& bs,
130  SeedRef seedRef,
131  int qualityMask)
132 {
133  //variable declarations
134  std::vector<Trajectory> trajVec;
135  reco::GsfTrack * theTrack;
136  Trajectory * theTraj;
137  PropagationDirection seedDir = seed.direction();
138 
139  //perform the fit: the result's size is 1 if it succeded, 0 if fails
140  trajVec = theFitter->fit(seed, hits, theTSOS);
141 
142  LogDebug("GsfTrackProducer") <<" FITTER FOUND "<< trajVec.size() << " TRAJECTORIES" <<"\n";
143 
144  TrajectoryStateOnSurface innertsos;
145  TrajectoryStateOnSurface outertsos;
146 
147  if (trajVec.size() != 0){
148 
149  theTraj = new Trajectory( trajVec.front() );
150  theTraj->setSeedRef(seedRef);
151 
152  if (theTraj->direction() == alongMomentum) {
153  innertsos = theTraj->firstMeasurement().updatedState();
154  outertsos = theTraj->lastMeasurement().updatedState();
155  } else {
156  innertsos = theTraj->lastMeasurement().updatedState();
157  outertsos = theTraj->firstMeasurement().updatedState();
158  }
159 // std::cout
160 // << "Nr. of first / last states = "
161 // << innertsos.components().size() << " "
162 // << outertsos.components().size() << std::endl;
163 // std::vector<TrajectoryStateOnSurface> components =
164 // innertsos.components();
165 // double sinTheta =
166 // sin(innertsos.globalMomentum().theta());
167 // for ( std::vector<TrajectoryStateOnSurface>::const_iterator ic=components.begin();
168 // ic!=components.end(); ic++ ) {
169 // std::cout << " comp " << ic-components.begin() << " "
170 // << (*ic).weight() << " "
171 // << (*ic).localParameters().vector()[0]/sinTheta << " "
172 // << sqrt((*ic).localError().matrix()[0][0])/sinTheta << std::endl;
173 // }
174 
175  ndof = 0;
177  theTraj->validRecHits(validHits);
178  for (TransientTrackingRecHit::RecHitContainer::iterator h=validHits.begin();h!=validHits.end();++h)
179  ndof = ndof + ((*h)->dimension())*((*h)->weight());
180  if (theTSOS.magneticField()->inTesla(GlobalPoint(0,0,0)).mag2()<DBL_MIN) ndof = ndof - 4;
181  else ndof = ndof - 5;
182 
183  TSCBLBuilderNoMaterial tscblBuilder;
184  // const FreeTrajectoryState & stateForProjectionToBeamLine=*innertsos.freeState();
185  const TrajectoryStateOnSurface & stateForProjectionToBeamLineOnSurface = theTraj->closestMeasurement(GlobalPoint(bs.x0(),bs.y0(),bs.z0())).updatedState();
186  if (!stateForProjectionToBeamLineOnSurface.isValid()){
187  edm::LogError("CannotPropagateToBeamLine")<<"the state on the closest measurement isnot valid. skipping track.";
188  delete theTraj;
189  return false;
190  } const FreeTrajectoryState & stateForProjectionToBeamLine=*theTraj->closestMeasurement(GlobalPoint(bs.x0(),bs.y0(),bs.z0())).updatedState().freeState();
191 
192  LogDebug("TrackProducer") << "stateForProjectionToBeamLine=" << stateForProjectionToBeamLine;
193 
194  TrajectoryStateClosestToBeamLine tscbl = tscblBuilder(stateForProjectionToBeamLine,bs);
195 
196  if (tscbl.isValid()==false) {
197  delete theTraj;
198  return false;
199  }
200 
202  math::XYZPoint pos( v.x(), v.y(), v.z() );
204  math::XYZVector mom( p.x(), p.y(), p.z() );
205 
206  LogDebug("TrackProducer") << "pos=" << v << " mom=" << p << " pt=" << p.perp() << " mag=" << p.mag();
207 
208  theTrack = new reco::GsfTrack(theTraj->chiSquared(),
209  int(ndof),//FIXME fix weight() in TrackingRecHit
210  // theTraj->foundHits(),//FIXME to be fixed in Trajectory.h
211  // 0, //FIXME no corresponding method in trajectory.h
212  // theTraj->lostHits(),//FIXME to be fixed in Trajectory.h
213  pos, mom, tscbl.trackStateAtPCA().charge(), tscbl.trackStateAtPCA().curvilinearError());
214  theTrack->setAlgorithm(algo_);
215 
216  LogDebug("GsfTrackProducer") <<"track done\n";
217 
218  AlgoProduct aProduct(theTraj,std::make_pair(theTrack,seedDir));
219  LogDebug("GsfTrackProducer") <<"track done1\n";
220  algoResults.push_back(aProduct);
221  LogDebug("GsfTrackProducer") <<"track done2\n";
222 
223  return true;
224  }
225  else return false;
226 }
#define LogDebug(id)
PropagationDirection direction() const
void setQualityMask(int qualMask)
Definition: TrackBase.h:286
double z0() const
z coordinate
Definition: BeamSpot.h:69
T mag2() const
Definition: PV3DBase.h:60
T perp() const
Definition: PV3DBase.h:66
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
bool buildTrack(const TrajectoryFitter *, const Propagator *, AlgoProductCollection &, TransientTrackingRecHit::RecHitContainer &, TrajectoryStateOnSurface &, const TrajectorySeed &, float, const reco::BeamSpot &, SeedRef seedRef=SeedRef(), int qualityMask=0)
Construct Tracks to be put in the event.
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
T y() const
Definition: PV3DBase.h:57
PropagationDirection
TrackCharge charge() const
std::vector< AlgoProduct > AlgoProductCollection
TrajectoryMeasurement const & closestMeasurement(GlobalPoint) const
Definition: Trajectory.cc:269
const MagneticField * magneticField() const
const CurvilinearTrajectoryError & curvilinearError() const
std::vector< ConstRecHitPointer > RecHitContainer
PropagationDirection const & direction() const
Definition: Trajectory.cc:195
std::pair< Trajectory *, std::pair< reco::Track *, PropagationDirection > > AlgoProduct
FreeTrajectoryState * freeState(bool withErrors=true) const
double pt() const
track transverse momentum
Definition: TrackBase.h:131
TrajectoryMeasurement const & lastMeasurement() const
Definition: Trajectory.h:147
T z() const
Definition: PV3DBase.h:58
void validRecHits(ConstRecHitContainer &cont) const
Definition: Trajectory.cc:187
TrajectoryStateOnSurface updatedState() const
GlobalVector momentum() const
GlobalPoint position() const
TrajectoryMeasurement const & firstMeasurement() const
Definition: Trajectory.h:160
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
reco::TrackBase::TrackAlgorithm algo_
void setSeedRef(const edm::RefToBase< TrajectorySeed > &seedRef)
Definition: Trajectory.h:264
virtual std::vector< Trajectory > fit(const Trajectory &) const =0
void setAlgorithm(const TrackAlgorithm a, bool set=true)
position index
Definition: TrackBase.h:272
double y0() const
y coordinate
Definition: BeamSpot.h:67
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
T x() const
Definition: PV3DBase.h:56
mathSSE::Vec4< T > v
double chiSquared() const
Definition: Trajectory.h:208
double x0() const
x coordinate
Definition: BeamSpot.h:65