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 
27 // #include "TrackingTools/MaterialEffects/interface/PropagatorWithMaterial.h"
31 
32 namespace {
33 #ifdef STAT_TSB
34  struct StatCount {
35  long long totTrack=0;
36  long long totLoop=0;
37  long long totGsfTrack=0;
38  long long totFound=0;
39  long long totLost=0;
40  long long totAlgo[12];
41  void track(int l) {
42  if (l>0) ++totLoop; else ++totTrack;
43  }
44  void hits(int f, int l) { totFound+=f; totLost+=l;}
45  void gsf() {++totGsfTrack;}
46  void algo(int a) { if (a>=0 && a<12) ++totAlgo[a];}
47 
48 
49  void print() const {
50  std::cout << "TrackProducer stat\nTrack/Loop/Gsf/FoundHits/LostHits/algos "
51  << totTrack <<'/'<< totLoop <<'/'<< totGsfTrack <<'/'<< totFound <<'/'<< totLost;
52  for (auto a : totAlgo) std::cout << '/'<< a;
53  std::cout << std::endl;
54  }
55  StatCount() {}
56  ~StatCount() { print();}
57  };
58 
59 #else
60  struct StatCount {
61  void track(int){}
62  void hits(int, int){}
63  void gsf(){}
64  void algo(int){}
65  };
66 #endif
67 
68  StatCount statCount;
69 
70 }
71 
72 
73 
74 
75 template <> bool
77  const Propagator * thePropagator,
78  AlgoProductCollection& algoResults,
80  TrajectoryStateOnSurface& theTSOS,
81  const TrajectorySeed& seed,
82  float ndof,
83  const reco::BeamSpot& bs,
84  SeedRef seedRef,
85  int qualityMask,signed char nLoops)
86 {
87  //variable declarations
88  reco::Track * theTrack;
89  Trajectory * theTraj;
90  PropagationDirection seedDir = seed.direction();
91 
92  //perform the fit: the result's size is 1 if it succeded, 0 if fails
93  Trajectory && trajTmp = theFitter->fitOne(seed, hits, theTSOS,(nLoops>0) ? TrajectoryFitter::looper : TrajectoryFitter::standard);
94  if unlikely(!trajTmp.isValid()) return false;
95 
96 
97 
98  theTraj = new Trajectory(std::move(trajTmp));
99  theTraj->setSeedRef(seedRef);
100 
101  statCount.hits(theTraj->foundHits(),theTraj->lostHits());
102  statCount.algo(int(algo_));
103 
104  // TrajectoryStateOnSurface innertsos;
105  // if (theTraj->direction() == alongMomentum) {
106  // innertsos = theTraj->firstMeasurement().updatedState();
107  // } else {
108  // innertsos = theTraj->lastMeasurement().updatedState();
109  // }
110 
111  ndof = 0;
112  for (auto const & tm : theTraj->measurements()) {
113  auto const & h = tm.recHitR();
114  if (h.isValid()) ndof = ndof + float(h.dimension())*h.weight(); // two virtual calls!
115  }
116 
117  ndof -= 5.f;
118  if unlikely(std::abs(theTSOS.magneticField()->nominalValue())<DBL_MIN) ++ndof; // same as -4
119 
120 
121  //if geometricInnerState_ is false the state for projection to beam line is the state attached to the first hit: to be used for loopers
122  //if geometricInnerState_ is true the state for projection to beam line is the one from the (geometrically) closest measurement to the beam line: to be sued for non-collision tracks
123  //the two shouuld give the same result for collision tracks that are NOT loopers
124  TrajectoryStateOnSurface stateForProjectionToBeamLineOnSurface;
125  if (geometricInnerState_) {
126  stateForProjectionToBeamLineOnSurface = theTraj->closestMeasurement(GlobalPoint(bs.x0(),bs.y0(),bs.z0())).updatedState();
127  } else {
128  if (theTraj->direction() == alongMomentum) {
129  stateForProjectionToBeamLineOnSurface = theTraj->firstMeasurement().updatedState();
130  } else {
131  stateForProjectionToBeamLineOnSurface = theTraj->lastMeasurement().updatedState();
132  }
133  }
134 
135  if unlikely(!stateForProjectionToBeamLineOnSurface.isValid()){
136  edm::LogError("CannotPropagateToBeamLine")<<"the state on the closest measurement isnot valid. skipping track.";
137  delete theTraj;
138  return false;
139  }
140  const FreeTrajectoryState & stateForProjectionToBeamLine=*stateForProjectionToBeamLineOnSurface.freeState();
141 
142  LogDebug("TrackProducer") << "stateForProjectionToBeamLine=" << stateForProjectionToBeamLine;
143 
144  TSCBLBuilderNoMaterial tscblBuilder;
145  TrajectoryStateClosestToBeamLine tscbl = tscblBuilder(stateForProjectionToBeamLine,bs);
146 
147  if unlikely(!tscbl.isValid()) {
148  delete theTraj;
149  return false;
150  }
151 
153  math::XYZPoint pos( v.x(), v.y(), v.z() );
155  math::XYZVector mom( p.x(), p.y(), p.z() );
156 
157  LogDebug("TrackProducer") << "pos=" << v << " mom=" << p << " pt=" << p.perp() << " mag=" << p.mag();
158 
159  theTrack = new reco::Track(theTraj->chiSquared(),
160  int(ndof),//FIXME fix weight() in TrackingRecHit
161  pos, mom, tscbl.trackStateAtPCA().charge(),
163  algo_);
164 
165  theTrack->setQualityMask(qualityMask);
166  theTrack->setNLoops(nLoops);
167 
168  LogDebug("TrackProducer") << "theTrack->pt()=" << theTrack->pt();
169 
170  LogDebug("TrackProducer") <<"track done\n";
171 
172  AlgoProduct aProduct(theTraj,std::make_pair(theTrack,seedDir));
173  algoResults.push_back(aProduct);
174 
175  statCount.track(nLoops);
176 
177  return true;
178 }
179 
180 template <> bool
182  const Propagator * thePropagator,
183  AlgoProductCollection& algoResults,
185  TrajectoryStateOnSurface& theTSOS,
186  const TrajectorySeed& seed,
187  float ndof,
188  const reco::BeamSpot& bs,
189  SeedRef seedRef,
190  int qualityMask,signed char nLoops)
191 {
192  //variable declarations
193  reco::GsfTrack * theTrack;
194  Trajectory * theTraj;
195  PropagationDirection seedDir = seed.direction();
196 
197  Trajectory && trajTmp = theFitter->fitOne(seed, hits, theTSOS,(nLoops>0) ? TrajectoryFitter::looper: TrajectoryFitter::standard);
198  if unlikely(!trajTmp.isValid()) return false;
199 
200 
201  theTraj = new Trajectory( std::move(trajTmp) );
202  theTraj->setSeedRef(seedRef);
203 
204  // TrajectoryStateOnSurface innertsos;
205  // TrajectoryStateOnSurface outertsos;
206 
207  // if (theTraj->direction() == alongMomentum) {
208  // innertsos = theTraj->firstMeasurement().updatedState();
209  // outertsos = theTraj->lastMeasurement().updatedState();
210  // } else {
211  // innertsos = theTraj->lastMeasurement().updatedState();
212  // outertsos = theTraj->firstMeasurement().updatedState();
213  // }
214  // std::cout
215  // << "Nr. of first / last states = "
216  // << innertsos.components().size() << " "
217  // << outertsos.components().size() << std::endl;
218  // std::vector<TrajectoryStateOnSurface> components =
219  // innertsos.components();
220  // double sinTheta =
221  // sin(innertsos.globalMomentum().theta());
222  // for ( std::vector<TrajectoryStateOnSurface>::const_iterator ic=components.begin();
223  // ic!=components.end(); ic++ ) {
224  // std::cout << " comp " << ic-components.begin() << " "
225  // << (*ic).weight() << " "
226  // << (*ic).localParameters().vector()[0]/sinTheta << " "
227  // << sqrt((*ic).localError().matrix()[0][0])/sinTheta << std::endl;
228  // }
229 
230  ndof = 0;
231  for (auto const & tm : theTraj->measurements()) {
232  auto const & h = tm.recHitR();
233  if (h.isValid()) ndof = ndof + h.dimension()*h.weight();
234  }
235 
236  ndof = ndof - 5;
237  if unlikely(std::abs(theTSOS.magneticField()->nominalValue())<DBL_MIN) ++ndof; // same as -4
238 
239 
240  //if geometricInnerState_ is false the state for projection to beam line is the state attached to the first hit: to be used for loopers
241  //if geometricInnerState_ is true the state for projection to beam line is the one from the (geometrically) closest measurement to the beam line: to be sued for non-collision tracks
242  //the two shouuld give the same result for collision tracks that are NOT loopers
243  TrajectoryStateOnSurface stateForProjectionToBeamLineOnSurface;
244  if (geometricInnerState_) {
245  stateForProjectionToBeamLineOnSurface = theTraj->closestMeasurement(GlobalPoint(bs.x0(),bs.y0(),bs.z0())).updatedState();
246  } else {
247  if (theTraj->direction() == alongMomentum) {
248  stateForProjectionToBeamLineOnSurface = theTraj->firstMeasurement().updatedState();
249  } else {
250  stateForProjectionToBeamLineOnSurface = theTraj->lastMeasurement().updatedState();
251  }
252  }
253 
254  if unlikely(!stateForProjectionToBeamLineOnSurface.isValid()){
255  edm::LogError("CannotPropagateToBeamLine")<<"the state on the closest measurement isnot valid. skipping track.";
256  delete theTraj;
257  return false;
258  }
259 
260  const FreeTrajectoryState & stateForProjectionToBeamLine=*stateForProjectionToBeamLineOnSurface.freeState();
261 
262  LogDebug("GsfTrackProducer") << "stateForProjectionToBeamLine=" << stateForProjectionToBeamLine;
263 
264  TSCBLBuilderNoMaterial tscblBuilder;
265  TrajectoryStateClosestToBeamLine tscbl = tscblBuilder(stateForProjectionToBeamLine,bs);
266 
267  if unlikely(tscbl.isValid()==false) {
268  delete theTraj;
269  return false;
270  }
271 
273  math::XYZPoint pos( v.x(), v.y(), v.z() );
275  math::XYZVector mom( p.x(), p.y(), p.z() );
276 
277  LogDebug("GsfTrackProducer") << "pos=" << v << " mom=" << p << " pt=" << p.perp() << " mag=" << p.mag();
278 
279  theTrack = new reco::GsfTrack(theTraj->chiSquared(),
280  int(ndof),//FIXME fix weight() in TrackingRecHit
281  // theTraj->foundHits(),//FIXME to be fixed in Trajectory.h
282  // 0, //FIXME no corresponding method in trajectory.h
283  // theTraj->lostHits(),//FIXME to be fixed in Trajectory.h
284  pos, mom, tscbl.trackStateAtPCA().charge(), tscbl.trackStateAtPCA().curvilinearError());
285  theTrack->setAlgorithm(algo_);
286 
287  LogDebug("GsfTrackProducer") <<"track done\n";
288 
289  AlgoProduct aProduct(theTraj,std::make_pair(theTrack,seedDir));
290  LogDebug("GsfTrackProducer") <<"track done1\n";
291  algoResults.push_back(aProduct);
292  LogDebug("GsfTrackProducer") <<"track done2\n";
293 
294  statCount.gsf();
295  return true;
296 }
#define LogDebug(id)
PropagationDirection direction() const
void setQualityMask(int qualMask)
Definition: TrackBase.h:285
double z0() const
z coordinate
Definition: BeamSpot.h:68
T perp() const
Definition: PV3DBase.h:72
int nominalValue() const
The nominal field value for this map in kGauss.
std::string print(const Track &, edm::Verbosity=edm::Concise)
Track print utility.
Definition: print.cc:8
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
T y() const
Definition: PV3DBase.h:63
PropagationDirection
TrackCharge charge() const
std::vector< AlgoProduct > AlgoProductCollection
const MagneticField * magneticField() const
const CurvilinearTrajectoryError & curvilinearError() const
std::vector< ConstRecHitPointer > RecHitContainer
bool buildTrack(const TrajectoryFitter *, const Propagator *, AlgoProductCollection &, TransientTrackingRecHit::RecHitContainer &, TrajectoryStateOnSurface &, const TrajectorySeed &, float, const reco::BeamSpot &, SeedRef seedRef=SeedRef(), int qualityMask=0, signed char nLoops=0)
Construct Tracks to be put in the event.
#define unlikely(x)
Definition: Likely.h:21
void setNLoops(signed char value)
Definition: TrackBase.h:288
std::pair< Trajectory *, std::pair< reco::Track *, PropagationDirection > > AlgoProduct
double pt() const
track transverse momentum
Definition: TrackBase.h:129
FreeTrajectoryState const * freeState(bool withErrors=true) const
T z() const
Definition: PV3DBase.h:64
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
virtual Trajectory fitOne(const Trajectory &traj, fitType type=standard) const =0
GlobalVector momentum() const
GlobalPoint position() const
bool isValid() const
Definition: Trajectory.h:271
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
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
reco::TrackBase::TrackAlgorithm algo_
void setAlgorithm(const TrackAlgorithm a, bool set=true)
position index
Definition: TrackBase.h:271
double a
Definition: hdecay.h:121
double y0() const
y coordinate
Definition: BeamSpot.h:66
tuple cout
Definition: gather_cfg.py:121
T x() const
Definition: PV3DBase.h:62
double x0() const
x coordinate
Definition: BeamSpot.h:64