CMS 3D CMS Logo

TrackProducerAlgorithm.cc
Go to the documentation of this file.
1 #include <sstream>
2 
28 
29 // #define VI_DEBUG
30 // #define STAT_TSB
31 
32 #ifdef VI_DEBUG
33 #define DPRINT(x) std::cout << x << ": "
34 #else
35 #define DPRINT(x) LogTrace(x)
36 #endif
37 
38 namespace {
39 #ifdef STAT_TSB
40  struct StatCount {
41  long long totTrack = 0;
42  long long totLoop = 0;
43  long long totGsfTrack = 0;
44  long long totFound = 0;
45  long long totLost = 0;
46  long long totAlgo[15];
47  void track(int l) {
48  if (l > 0)
49  ++totLoop;
50  else
51  ++totTrack;
52  }
53  void hits(int f, int l) {
54  totFound += f;
55  totLost += l;
56  }
57  void gsf() { ++totGsfTrack; }
58  void algo(int a) {
59  if (a >= 0 && a < 15)
60  ++totAlgo[a];
61  }
62 
63  void print() const {
64  std::cout << "TrackProducer stat\nTrack/Loop/Gsf/FoundHits/LostHits//algos " << totTrack << '/' << totLoop << '/'
65  << totGsfTrack << '/' << totFound << '/' << totLost << '/';
66  for (auto a : totAlgo)
67  std::cout << '/' << a;
68  std::cout << std::endl;
69  }
70  StatCount() {}
71  ~StatCount() { print(); }
72  };
73  StatCount statCount;
74 
75 #else
76  struct StatCount {
77  void track(int) {}
78  void hits(int, int) {}
79  void gsf() {}
80  void algo(int) {}
81  };
82  CMS_THREAD_SAFE StatCount statCount;
83 #endif
84 
85 } // namespace
86 
87 template <>
89  const Propagator* thePropagator,
90  AlgoProductCollection& algoResults,
92  TrajectoryStateOnSurface& theTSOS,
93  const TrajectorySeed& seed,
94  float ndof,
95  const reco::BeamSpot& bs,
96  SeedRef seedRef,
97  int qualityMask,
98  signed char nLoops) {
99  //variable declarations
100 
101  PropagationDirection seedDir = seed.direction();
102 
103  //perform the fit: the result's size is 1 if it succeded, 0 if fails
104  Trajectory&& trajTmp =
105  theFitter->fitOne(seed, hits, theTSOS, (nLoops > 0) ? TrajectoryFitter::looper : TrajectoryFitter::standard);
106  if
107  UNLIKELY(!trajTmp.isValid()) {
108  DPRINT("TrackFitters") << "fit failed " << algo_ << ": " << hits.size() << '|' << int(nLoops) << ' ' << std::endl;
109  return false;
110  }
111 
112  auto theTraj = new Trajectory(std::move(trajTmp));
113  theTraj->setSeedRef(seedRef);
114 
115  statCount.hits(theTraj->foundHits(), theTraj->lostHits());
116  statCount.algo(int(algo_));
117 
118  // TrajectoryStateOnSurface innertsos;
119  // if (theTraj->direction() == alongMomentum) {
120  // innertsos = theTraj->firstMeasurement().updatedState();
121  // } else {
122  // innertsos = theTraj->lastMeasurement().updatedState();
123  // }
124 
125  ndof = 0;
126  for (auto const& tm : theTraj->measurements()) {
127  auto const& h = tm.recHitR();
128  if (h.isValid())
129  ndof = ndof + float(h.dimension()) * h.weight(); // two virtual calls!
130  }
131 
132  ndof -= 5.f;
133  if
134  UNLIKELY(std::abs(theTSOS.magneticField()->nominalValue()) < DBL_MIN)++ ndof; // same as -4
135 
136 #if defined(VI_DEBUG) || defined(EDM_ML_DEBUG)
137  int chit[7] = {};
138  int kk = 0;
139  for (auto const& tm : theTraj->measurements()) {
140  ++kk;
141  auto const& hit = tm.recHitR();
142  if (!hit.isValid())
143  ++chit[0];
144  if (hit.det() == nullptr)
145  ++chit[1];
147  continue;
148  if (0)
149  std::cout << "h " << kk << ": " << hit.localPosition() << ' ' << hit.localPositionError() << ' ' << tm.estimate()
150  << std::endl;
151  if (hit.dimension() != 2) {
152  ++chit[2];
153  } else if (trackerHitRTTI::isFromDet(hit)) {
154  auto const& thit = static_cast<BaseTrackerRecHit const&>(hit);
155  auto const& clus = thit.firstClusterRef();
156  if (clus.isPixel())
157  ++chit[3];
158  else if (thit.isMatched()) {
159  ++chit[4];
160  } else if (thit.isProjected()) {
161  ++chit[5];
162  } else {
163  ++chit[6];
164  }
165  }
166  }
167 
168  std::ostringstream ss;
169  ss << algo_ << ": " << hits.size() << '|' << theTraj->measurements().size() << '|' << int(nLoops) << ' ';
170  for (auto c : chit)
171  ss << c << '/';
172  ss << std::endl;
173  DPRINT("TrackProducer") << ss.str();
174 
175 #endif
176 
177  //if geometricInnerState_ is false the state for projection to beam line is the state attached to the first hit: to be used for loopers
178  //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
179  //the two shouuld give the same result for collision tracks that are NOT loopers
180  TrajectoryStateOnSurface stateForProjectionToBeamLineOnSurface;
181  if (geometricInnerState_) {
182  stateForProjectionToBeamLineOnSurface =
183  theTraj->closestMeasurement(GlobalPoint(bs.x0(), bs.y0(), bs.z0())).updatedState();
184  } else {
185  if (theTraj->direction() == alongMomentum) {
186  stateForProjectionToBeamLineOnSurface = theTraj->firstMeasurement().updatedState();
187  } else {
188  stateForProjectionToBeamLineOnSurface = theTraj->lastMeasurement().updatedState();
189  }
190  }
191 
192  if
193  UNLIKELY(!stateForProjectionToBeamLineOnSurface.isValid()) {
194  edm::LogError("CannotPropagateToBeamLine") << "the state on the closest measurement isnot valid. skipping track.";
195  delete theTraj;
196  return false;
197  }
198  const FreeTrajectoryState& stateForProjectionToBeamLine = *stateForProjectionToBeamLineOnSurface.freeState();
199 
200  LogDebug("TrackProducer") << "stateForProjectionToBeamLine=" << stateForProjectionToBeamLine;
201 
202  // TSCBLBuilderNoMaterial tscblBuilder;
203  // TrajectoryStateClosestToBeamLine tscbl = tscblBuilder(stateForProjectionToBeamLine,bs);
204 
206  if (usePropagatorForPCA_) {
207  //std::cout << "PROPAGATOR FOR PCA" << std::endl;
208  TSCBLBuilderWithPropagator tscblBuilder(*thePropagator);
209  tscbl = tscblBuilder(stateForProjectionToBeamLine, bs);
210  } else {
211  TSCBLBuilderNoMaterial tscblBuilder;
212  tscbl = tscblBuilder(stateForProjectionToBeamLine, bs);
213  }
214 
215  if
216  UNLIKELY(!tscbl.isValid()) {
217  delete theTraj;
218  return false;
219  }
220 
222  math::XYZPoint pos(v.x(), v.y(), v.z());
224  math::XYZVector mom(p.x(), p.y(), p.z());
225 
226  LogDebug("TrackProducer") << "pos=" << v << " mom=" << p << " pt=" << p.perp() << " mag=" << p.mag();
227 
228  auto theTrack = new reco::Track(theTraj->chiSquared(),
229  int(ndof), //FIXME fix weight() in TrackingRecHit
230  pos,
231  mom,
232  tscbl.trackStateAtPCA().charge(),
234  algo_);
235 
238  if (algoMask_.any())
239  theTrack->setAlgoMask(algoMask_);
240  theTrack->setQualityMask(qualityMask);
241  theTrack->setNLoops(nLoops);
242  theTrack->setStopReason(stopReason_);
243 
244  LogDebug("TrackProducer") << "theTrack->pt()=" << theTrack->pt();
245 
246  LogDebug("TrackProducer") << "track done\n";
247 
248  AlgoProduct aProduct{theTraj, theTrack, seedDir, 0};
249  algoResults.push_back(aProduct);
250 
251  statCount.track(nLoops);
252 
253  return true;
254 }
255 
256 template <>
258  const Propagator* thePropagator,
259  AlgoProductCollection& algoResults,
261  TrajectoryStateOnSurface& theTSOS,
262  const TrajectorySeed& seed,
263  float ndof,
264  const reco::BeamSpot& bs,
265  SeedRef seedRef,
266  int qualityMask,
267  signed char nLoops) {
268  PropagationDirection seedDir = seed.direction();
269 
270  Trajectory&& trajTmp =
271  theFitter->fitOne(seed, hits, theTSOS, (nLoops > 0) ? TrajectoryFitter::looper : TrajectoryFitter::standard);
272  if
273  UNLIKELY(!trajTmp.isValid()) return false;
274 
275  auto theTraj = new Trajectory(std::move(trajTmp));
276  theTraj->setSeedRef(seedRef);
277 
278 #ifdef EDM_ML_DEBUG
279  TrajectoryStateOnSurface innertsos;
280  TrajectoryStateOnSurface outertsos;
281 
282  if (theTraj->direction() == alongMomentum) {
283  innertsos = theTraj->firstMeasurement().updatedState();
284  outertsos = theTraj->lastMeasurement().updatedState();
285  } else {
286  innertsos = theTraj->lastMeasurement().updatedState();
287  outertsos = theTraj->firstMeasurement().updatedState();
288  }
289  std::ostringstream ss;
290  auto dc = [&](TrajectoryStateOnSurface const& tsos) {
291  std::vector<TrajectoryStateOnSurface> const& components = tsos.components();
292  auto sinTheta = std::sin(tsos.globalMomentum().theta());
293  for (auto const& ic : components)
294  ss << ic.weight() << "/";
295  ss << "\n";
296  for (auto const& ic : components)
297  ss << ic.localParameters().vector()[0] / sinTheta << "/";
298  ss << "\n";
299  for (auto const& ic : components)
300  ss << std::sqrt(ic.localError().matrix()(0, 0)) / sinTheta << "/";
301  };
302  ss << "\ninner comps\n";
303  dc(innertsos);
304  ss << "\nouter comps\n";
305  dc(outertsos);
306  LogDebug("TrackProducer") << "Nr. of first / last states = " << innertsos.components().size() << " "
307  << outertsos.components().size() << ss.str();
308 #endif
309 
310  ndof = 0;
311  for (auto const& tm : theTraj->measurements()) {
312  auto const& h = tm.recHitR();
313  if (h.isValid())
314  ndof = ndof + h.dimension() * h.weight();
315  }
316 
317  ndof = ndof - 5;
318  if
319  UNLIKELY(std::abs(theTSOS.magneticField()->nominalValue()) < DBL_MIN)++ ndof; // same as -4
320 
321  //if geometricInnerState_ is false the state for projection to beam line is the state attached to the first hit: to be used for loopers
322  //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
323  //the two shouuld give the same result for collision tracks that are NOT loopers
324  TrajectoryStateOnSurface stateForProjectionToBeamLineOnSurface;
325  if (geometricInnerState_) {
326  stateForProjectionToBeamLineOnSurface =
327  theTraj->closestMeasurement(GlobalPoint(bs.x0(), bs.y0(), bs.z0())).updatedState();
328  } else {
329  if (theTraj->direction() == alongMomentum) {
330  stateForProjectionToBeamLineOnSurface = theTraj->firstMeasurement().updatedState();
331  } else {
332  stateForProjectionToBeamLineOnSurface = theTraj->lastMeasurement().updatedState();
333  }
334  }
335 
336  if
337  UNLIKELY(!stateForProjectionToBeamLineOnSurface.isValid()) {
338  edm::LogError("CannotPropagateToBeamLine") << "the state on the closest measurement isnot valid. skipping track.";
339  delete theTraj;
340  return false;
341  }
342 
343  const FreeTrajectoryState& stateForProjectionToBeamLine = *stateForProjectionToBeamLineOnSurface.freeState();
344 
345  LogDebug("GsfTrackProducer") << "stateForProjectionToBeamLine=" << stateForProjectionToBeamLine;
346 
347  // TSCBLBuilderNoMaterial tscblBuilder;
348  // TrajectoryStateClosestToBeamLine tscbl = tscblBuilder(stateForProjectionToBeamLine,bs);
349 
351  if (usePropagatorForPCA_) {
352  TSCBLBuilderWithPropagator tscblBuilder(*thePropagator);
353  tscbl = tscblBuilder(stateForProjectionToBeamLine, bs);
354  } else {
355  TSCBLBuilderNoMaterial tscblBuilder;
356  tscbl = tscblBuilder(stateForProjectionToBeamLine, bs);
357  }
358 
359  if
360  UNLIKELY(tscbl.isValid() == false) {
361  delete theTraj;
362  return false;
363  }
364 
366  math::XYZPoint pos(v.x(), v.y(), v.z());
368  math::XYZVector mom(p.x(), p.y(), p.z());
369 
370  LogDebug("GsfTrackProducer") << "pos=" << v << " mom=" << p << " pt=" << p.perp() << " mag=" << p.mag();
371 
372  auto theTrack =
373  new reco::GsfTrack(theTraj->chiSquared(),
374  int(ndof), //FIXME fix weight() in TrackingRecHit
375  // theTraj->foundHits(),//FIXME to be fixed in Trajectory.h
376  // 0, //FIXME no corresponding method in trajectory.h
377  // theTraj->lostHits(),//FIXME to be fixed in Trajectory.h
378  pos,
379  mom,
380  tscbl.trackStateAtPCA().charge(),
382  theTrack->setAlgorithm(algo_);
384  theTrack->setOriginalAlgorithm(originalAlgo_);
385  if (algoMask_.any())
386  theTrack->setAlgoMask(algoMask_);
387 
388  theTrack->setStopReason(stopReason_);
389 
390  LogDebug("GsfTrackProducer") << "track done\n";
391 
392  AlgoProduct aProduct{theTraj, theTrack, seedDir, 0};
393 
394  LogDebug("GsfTrackProducer") << "track done1\n";
395  algoResults.push_back(aProduct);
396  LogDebug("GsfTrackProducer") << "track done2\n";
397 
398  statCount.gsf();
399  return true;
400 }
Vector3DBase
Definition: Vector3DBase.h:8
TSCBLBuilderNoMaterial.h
FreeTrajectoryState::momentum
GlobalVector momentum() const
Definition: FreeTrajectoryState.h:68
TrajectoryStateClosestToBeamLine
Definition: TrajectoryStateClosestToBeamLine.h:15
TrajectoryStateOnSurface.h
MessageLogger.h
TrajectoryFitter::looper
Definition: TrajectoryFitter.h:21
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
TrackBase.h
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
gather_cfg.cout
cout
Definition: gather_cfg.py:144
pos
Definition: PixelAliasList.h:18
FreeTrajectoryState::charge
TrackCharge charge() const
Definition: FreeTrajectoryState.h:69
TrackingGeometry.h
trackerHitRTTI::isUndef
bool isUndef(TrackingRecHit const &hit)
Definition: trackerHitRTTI.h:23
TrackingRecHitFwd.h
FreeTrajectoryState::position
GlobalPoint position() const
Definition: FreeTrajectoryState.h:67
TransientTrack.h
findQualityFiles.v
v
Definition: findQualityFiles.py:179
TrackProducerAlgorithm::algo_
reco::TrackBase::TrackAlgorithm algo_
Definition: TrackProducerAlgorithm.h:137
TRecHit2DPosConstraint.h
TkTransientTrackingRecHitBuilder.h
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
ndof
Definition: HIMultiTrackSelector.h:49
reco::TrackBase::setOriginalAlgorithm
void setOriginalAlgorithm(const TrackAlgorithm a)
Definition: TrackBase.h:779
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
Propagator
Definition: Propagator.h:44
cmsdt::algo
algo
Definition: constants.h:164
UNLIKELY
#define UNLIKELY(x)
Definition: Likely.h:21
reco::GsfTrack
Definition: GsfTrack.h:12
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
cms::cuda::bs
bs
Definition: HistoContainer.h:127
TrajectoryStateOnSurface::freeState
FreeTrajectoryState const * freeState(bool withErrors=true) const
Definition: TrajectoryStateOnSurface.h:58
TrackingRecHit::RecHitContainer
std::vector< ConstRecHitPointer > RecHitContainer
Definition: TrackingRecHit.h:31
TrackProducerAlgorithm::usePropagatorForPCA_
bool usePropagatorForPCA_
Definition: TrackProducerAlgorithm.h:144
FreeTrajectoryState::curvilinearError
const CurvilinearTrajectoryError & curvilinearError() const
Definition: FreeTrajectoryState.h:89
OrphanHandle.h
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
reco::BeamSpot
Definition: BeamSpot.h:21
TrackingRecHitLessFromGlobalPosition.h
reco::Track
Definition: Track.h:27
MagneticField::nominalValue
int nominalValue() const
The nominal field value for this map in kGauss.
Definition: MagneticField.h:49
TrajectoryFitter.h
GetRecoTauVFromDQM_MC_cff.kk
kk
Definition: GetRecoTauVFromDQM_MC_cff.py:84
h
GlobalPoint
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
CMS_THREAD_SAFE
#define CMS_THREAD_SAFE
Definition: thread_safety_macros.h:4
Point3DBase< float, GlobalTag >
TrajectorySeed.h
TrackProducerAlgorithm::geometricInnerState_
bool geometricInnerState_
Definition: TrackProducerAlgorithm.h:143
TrajectoryStateOnSurface::components
Components const & components() const
Definition: TrajectoryStateOnSurface.h:85
TrajectoryFitter::standard
Definition: TrajectoryFitter.h:21
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
math::XYZPoint
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
edm::LogError
Definition: MessageLogger.h:183
a
double a
Definition: hdecay.h:119
TSCBLBuilderWithPropagator.h
thread_safety_macros.h
math::XYZVector
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
reco::TrackBase::undefAlgorithm
Definition: TrackBase.h:90
createfilelist.int
int
Definition: createfilelist.py:10
TrackProducerAlgorithm::algoMask_
reco::TrackBase::AlgoMask algoMask_
Definition: TrackProducerAlgorithm.h:139
trackerHitRTTI::isFromDet
bool isFromDet(TrackingRecHit const &hit)
Definition: trackerHitRTTI.h:35
ntupleEnum.gsf
gsf
Definition: ntupleEnum.py:48
MagneticField.h
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
edm::print
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
TrackProducerAlgorithm::originalAlgo_
reco::TrackBase::TrackAlgorithm originalAlgo_
Definition: TrackProducerAlgorithm.h:138
cmsLHEtoEOSManager.l
l
Definition: cmsLHEtoEOSManager.py:193
reco::TrackBase::setAlgorithm
void setAlgorithm(const TrackAlgorithm a)
Track algorithm.
Definition: TrackBase.h:773
TSCBLBuilderWithPropagator
Definition: TSCBLBuilderWithPropagator.h:16
TrajectoryFitter
Definition: TrajectoryFitter.h:19
TrackProducerAlgorithm.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
ErrorFrameTransformer.h
FreeTrajectoryState
Definition: FreeTrajectoryState.h:27
Trajectory
Definition: Trajectory.h:38
TSCBLBuilderNoMaterial
Definition: TSCBLBuilderNoMaterial.h:13
makeMuonMisalignmentScenario.components
string components
Definition: makeMuonMisalignmentScenario.py:58
PropagationDirection
PropagationDirection
Definition: PropagationDirection.h:4
TransverseImpactPointExtrapolator.h
TrajectorySeed
Definition: TrajectorySeed.h:17
TrackProducerAlgorithm::stopReason_
uint8_t stopReason_
Definition: TrackProducerAlgorithm.h:140
TrajectoryStateTransform.h
Exception.h
HLT_2018_cff.track
track
Definition: HLT_2018_cff.py:10352
TransientTrackingRecHitBuilder.h
TRecHit1DMomConstraint.h
TrackProducerAlgorithm::buildTrack
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.
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
TrajectoryStateClosestToBeamLine::isValid
bool isValid() const
Definition: TrajectoryStateClosestToBeamLine.h:50
TrackCandidate.h
TrajectoryStateClosestToBeamLine::trackStateAtPCA
FTS const & trackStateAtPCA() const
Definition: TrajectoryStateClosestToBeamLine.h:32
DPRINT
#define DPRINT(x)
Definition: TrackProducerAlgorithm.cc:35
TrajectoryFitter::fitOne
virtual Trajectory fitOne(const Trajectory &traj, fitType type=standard) const =0
RecHitSorter.h
TrajectoryStateOnSurface::magneticField
const MagneticField * magneticField() const
Definition: TrajectoryStateOnSurface.h:62
alongMomentum
Definition: PropagationDirection.h:4
TrajectoryStateOnSurface::isValid
bool isValid() const
Definition: TrajectoryStateOnSurface.h:54
Trajectory::isValid
bool isValid() const
Definition: Trajectory.h:257
SurveyInfoScenario_cff.seed
seed
Definition: SurveyInfoScenario_cff.py:295
hit
Definition: SiStripHitEffFromCalibTree.cc:88