CMS 3D CMS Logo

KFTrajectorySmoother.cc
Go to the documentation of this file.
7 
11 
13  delete theAlongPropagator;
14  delete theOppositePropagator;
15  delete theUpdator;
16  delete theEstimator;
17 }
18 
20  if (aTraj.empty())
21  return Trajectory();
22 
23  const Propagator* usePropagator = theAlongPropagator;
24  if (aTraj.direction() == alongMomentum) {
25  usePropagator = theOppositePropagator;
26  }
27 
28  const std::vector<TM>& avtm = aTraj.measurements();
29 
30 #ifdef EDM_ML_DEBUG
31  LogDebug("TrackFitters") << "KFTrajectorySmoother::trajectories starting with " << avtm.size() << " HITS\n";
32  for (unsigned int j = 0; j < avtm.size(); j++) {
33  if (avtm[j].recHit()->det())
34  LogTrace("TrackFitters") << "hit #:" << j + 1 << " rawId=" << avtm[j].recHit()->det()->geographicalId().rawId()
35  << " validity=" << avtm[j].recHit()->isValid();
36  else
37  LogTrace("TrackFitters") << "hit #:" << j + 1 << " Hit with no Det information";
38  }
39 #endif // EDM_ML_DEBUG
40 
42  bool retry = false;
43  auto start = avtm.rbegin();
44 
45  do {
46  auto hitSize = avtm.rend() - start;
47  if
48  UNLIKELY(hitSize < minHits_) {
49  LogDebug("TrackFitters") << " killing trajectory"
50  << "\n";
51  return Trajectory();
52  }
53  Trajectory ret(aTraj.seed(), usePropagator->propagationDirection());
54  Trajectory& myTraj = ret;
55  myTraj.reserve(hitSize);
56  retry = false;
57 
58  TSOS predTsos = (*start).forwardPredictedState();
60  TSOS currTsos;
61 
62  auto hitCounter = hitSize;
63  for (std::vector<TM>::const_reverse_iterator itm = start; itm != (avtm.rend()); ++itm, --hitCounter) {
65 
66  //check surface just for safety: should never be ==0 because they are skipped in the fitter
67  // if UNLIKELY(hit->det() == nullptr) continue;
68  if
69  UNLIKELY(hit->surface() == nullptr) {
70  LogDebug("TrackFitters") << " Error: invalid hit with no GeomDet attached .... skipping";
71  continue;
72  }
73 
74  if (itm != start) //no propagation needed for first smoothed (==last fitted) hit
75  predTsos = usePropagator->propagate(currTsos, *(hit->surface()));
76 
77  if
78  UNLIKELY(!predTsos.isValid()) {
79  LogDebug("TrackFitters") << "KFTrajectorySmoother: predicted tsos not valid!";
80  LogDebug("TrackFitters") << " retry with last hit removed"
81  << "\n";
82  LogDebug("TrackFitters")
83  // std::cout
84  << "tsos not valid " << currTsos.globalMomentum().perp() << ' ' << hitSize << ' ' << hitCounter << ' '
85  << int(hit->geographicalId()) << ' ' << hit->surface()->position().perp() << ' ' << hit->surface()->eta()
86  << ' ' << hit->surface()->phi() << std::endl;
87  start++;
88  retry = true;
89  break;
90  }
91 
92  if (hit->isValid()) {
93  TSOS combTsos, smooTsos;
94 
95  //3 different possibilities to calculate smoothed state:
96  //1: update combined predictions with hit
97  //2: combine fwd-prediction with bwd-filter
98  //3: combine bwd-prediction with fwd-filter
99 
100  //combTsos is the predicted state with N-1 hits information. this means:
101  //forward predicted state for first smoothed (last fitted) hit
102  //backward predicted state for last smoothed (first fitted) hit
103  //combination of forward and backward predictions for other hits
104  if (itm == start)
105  combTsos = itm->forwardPredictedState();
106  else if (hitCounter == 1)
107  combTsos = predTsos;
108  else
109  combTsos = combiner(predTsos, itm->forwardPredictedState());
110 
111  if
112  UNLIKELY(!combTsos.isValid()) {
113  LogDebug("TrackFitters") << "KFTrajectorySmoother: combined tsos not valid!\n"
114  << "pred Tsos pos: " << predTsos.globalPosition() << "\n"
115  << "pred Tsos mom: " << predTsos.globalMomentum() << "\n"
116  << "TrackingRecHit: " << hit->surface()->toGlobal(hit->localPosition()) << "\n";
117  start++;
118  retry = true;
119  break;
120  }
121 
122  assert((hit->geographicalId() != 0U) | (!hit->canImproveWithTrack()));
123  assert(hit->surface() != nullptr);
124  assert((!(hit)->canImproveWithTrack()) | (nullptr != theHitCloner));
125  assert((!(hit)->canImproveWithTrack()) | (nullptr != dynamic_cast<BaseTrackerRecHit const*>(hit.get())));
126  auto preciseHit = theHitCloner->makeShared(hit, combTsos);
127  assert(preciseHit->isValid());
128  assert((preciseHit->geographicalId() != 0U) | (!preciseHit->canImproveWithTrack()));
129  assert(preciseHit->surface() != nullptr);
130 
131  dump(*hit, hitCounter, "TrackFitters");
132 
133  if
134  UNLIKELY(!preciseHit->isValid()) {
135  LogTrace("TrackFitters") << "THE Precise HIT IS NOT VALID: using currTsos = predTsos"
136  << "\n";
137  currTsos = predTsos;
138  myTraj.push(TM(predTsos, hit, 0, theGeometry->idToLayer(hit->geographicalId())));
139  }
140  else {
141  LogTrace("TrackFitters") << "THE Precise HIT IS VALID: updating currTsos"
142  << "\n";
143 
144  //update backward predicted tsos with the hit
145  currTsos = updator()->update(predTsos, *preciseHit);
146  if
147  UNLIKELY(!currTsos.isValid()) {
148  currTsos = predTsos;
149  edm::LogWarning("KFSmoother_UpdateFailed")
150  << "Failed updating state with hit. Rolling back to non-updated state.\n"
151  << "State: " << predTsos << "Hit local pos: " << hit->localPosition() << "\n"
152  << "Hit local err: " << hit->localPositionError() << "\n"
153  << "Hit global pos: " << hit->globalPosition() << "\n"
154  << "Hit global err: " << hit->globalPositionError().matrix() << "\n";
155  }
156 
157  //smooTsos updates the N-1 hits prediction with the hit
158  if (itm == start)
159  smooTsos = itm->updatedState();
160  else if (hitCounter == 1)
161  smooTsos = currTsos;
162  else
163  smooTsos = combiner(itm->forwardPredictedState(), currTsos);
164 
165  if
166  UNLIKELY(!smooTsos.isValid()) {
167  LogDebug("TrackFitters") << "KFTrajectorySmoother: smoothed tsos not valid!";
168  start++;
169  retry = true;
170  break;
171  }
172 
173  double estimate;
174  if (itm != start)
175  estimate = estimator()->estimate(combTsos, *preciseHit).second; //correct?
176  else
177  estimate = itm->estimate();
178 
179  LogTrace("TrackFitters") << "predTsos !"
180  << "\n"
181  << predTsos << " with local position " << predTsos.localPosition() << "\n\n"
182  << "currTsos !"
183  << "\n"
184  << currTsos << "\n"
185  << " with local position " << currTsos.localPosition() << "\n\n"
186  << "smooTsos !"
187  << "\n"
188  << smooTsos << " with local position " << smooTsos.localPosition() << "\n\n"
189  << "smoothing estimate (with combTSOS)=" << estimate << "\n"
190  << "filtering estimate=" << itm->estimate() << "\n";
191 
192  //check for valid hits with no det (refitter with constraints)
193  if (preciseHit->det())
194  myTraj.push(TM(itm->forwardPredictedState(),
195  predTsos,
196  smooTsos,
197  preciseHit,
198  estimate,
199  theGeometry->idToLayer(preciseHit->geographicalId())),
200  estimator()->estimate(predTsos, *preciseHit).second);
201  else
202  myTraj.push(TM(itm->forwardPredictedState(), predTsos, smooTsos, preciseHit, estimate),
203  estimator()->estimate(predTsos, *preciseHit).second);
204  //itm->estimate());
205  }
206  } else {
207  LogDebug("TrackFitters") << "----------------- HIT #" << hitCounter << " (INVALID)-----------------------";
208 
209  //no update
210  currTsos = predTsos;
211  TSOS combTsos;
212  if (itm == start)
213  combTsos = itm->forwardPredictedState();
214  else if (hitCounter == 1)
215  combTsos = predTsos;
216  else
217  combTsos = combiner(predTsos, itm->forwardPredictedState());
218 
219  if
220  UNLIKELY(!combTsos.isValid()) {
221  LogDebug("TrackFitters") << "KFTrajectorySmoother: combined tsos not valid!";
222  return Trajectory();
223  }
224  assert((hit->det() == nullptr) || hit->geographicalId() != 0U);
225  if (hit->det())
226  myTraj.push(TM(
227  itm->forwardPredictedState(), predTsos, combTsos, hit, 0, theGeometry->idToLayer(hit->geographicalId())));
228  else
229  myTraj.push(TM(itm->forwardPredictedState(), predTsos, combTsos, hit, 0));
230  }
231  } // for loop
232 
233  if (!retry)
234  return ret;
235  } while (true);
236 
237  return Trajectory();
238 }
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:367
TrajectoryStateCombiner.h
Likely.h
KFTrajectorySmoother::theHitCloner
TkCloner const * theHitCloner
Definition: KFTrajectorySmoother.h:99
KFTrajectorySmoother::theAlongPropagator
const Propagator * theAlongPropagator
Definition: KFTrajectorySmoother.h:95
KFTrajectorySmoother::trajectory
Trajectory trajectory(const Trajectory &aTraj) const override
Definition: KFTrajectorySmoother.cc:19
start
Definition: start.py:1
MessageLogger.h
Trajectory::direction
PropagationDirection const & direction() const
Definition: Trajectory.cc:133
KFTrajectorySmoother::minHits_
int minHits_
Definition: KFTrajectorySmoother.h:101
TrajectoryStateOnSurface::globalPosition
GlobalPoint globalPosition() const
Definition: TrajectoryStateOnSurface.h:65
KFTrajectorySmoother::theErrorRescaling
float theErrorRescaling
Definition: KFTrajectorySmoother.h:100
cms::cuda::assert
assert(be >=bs)
DetLayerGeometry::idToLayer
virtual const DetLayer * idToLayer(const DetId &detId) const
Definition: DetLayerGeometry.h:33
TransientTrackingRecHit.h
KFTrajectorySmoother.h
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
rpcPointValidation_cfi.recHit
recHit
Definition: rpcPointValidation_cfi.py:7
KFTrajectorySmoother::theOppositePropagator
const Propagator * theOppositePropagator
Definition: KFTrajectorySmoother.h:96
MeasurementEstimator::estimate
virtual HitReturnType estimate(const TrajectoryStateOnSurface &ts, const TrackingRecHit &hit) const =0
Propagator
Definition: Propagator.h:44
UNLIKELY
#define UNLIKELY(x)
Definition: Likely.h:21
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
Propagator::propagationDirection
virtual PropagationDirection propagationDirection() const final
Definition: Propagator.h:139
TrajectoryStateWithArbitraryError.h
KFTrajectorySmoother::theEstimator
const MeasurementEstimator * theEstimator
Definition: KFTrajectorySmoother.h:98
KFTrajectorySmoother::theUpdator
const TrajectoryStateUpdator * theUpdator
Definition: KFTrajectorySmoother.h:97
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
TrajectoryStateUpdator::update
virtual TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TrackingRecHit &) const =0
TrajectoryStateCombiner
Definition: TrajectoryStateCombiner.h:13
TrajectoryStateOnSurface::localPosition
LocalPoint localPosition() const
Definition: TrajectoryStateOnSurface.h:74
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
FrontierConditions_GlobalTag_cff.dump
dump
Definition: FrontierConditions_GlobalTag_cff.py:12
TrackingRecHit::ConstRecHitPointer
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
Definition: TrackingRecHit.h:25
createfilelist.int
int
Definition: createfilelist.py:10
TkCloner.h
TkCloner::makeShared
TrackingRecHit::ConstRecHitPointer makeShared(TrackingRecHit::ConstRecHitPointer const &hit, TrajectoryStateOnSurface const &tsos) const
Definition: TkCloner.h:24
DebugHelpers.h
Propagator::propagate
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
Definition: Propagator.h:50
Trajectory::measurements
DataContainer const & measurements() const
Definition: Trajectory.h:178
TrajectoryStateOnSurface::rescaleError
void rescaleError(double factor)
Definition: TrajectoryStateOnSurface.h:82
BaseTrackerRecHit.h
KFTrajectorySmoother::theGeometry
const DetLayerGeometry * theGeometry
Definition: KFTrajectorySmoother.h:102
TrajectoryStateOnSurface::globalMomentum
GlobalVector globalMomentum() const
Definition: TrajectoryStateOnSurface.h:66
Trajectory
Definition: Trajectory.h:38
KFTrajectorySmoother::estimator
const MeasurementEstimator * estimator() const
Definition: KFTrajectorySmoother.h:83
KFTrajectorySmoother::TM
TrajectoryMeasurement TM
Definition: KFTrajectorySmoother.h:24
KFTrajectorySmoother::updator
const TrajectoryStateUpdator * updator() const
Definition: KFTrajectorySmoother.h:82
KFTrajectorySmoother::~KFTrajectorySmoother
~KFTrajectorySmoother() override
Definition: KFTrajectorySmoother.cc:12
Trajectory::seed
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
Definition: Trajectory.h:263
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:224
command_line.start
start
Definition: command_line.py:167
heavyFlavorValidationHarvestingSequence_cff.combiner
combiner
Definition: heavyFlavorValidationHarvestingSequence_cff.py:107
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
TrajectoryMeasurement
Definition: TrajectoryMeasurement.h:25
PV3DBase::perp
T perp() const
Definition: PV3DBase.h:69
alongMomentum
Definition: PropagationDirection.h:4
TrajectoryStateOnSurface::isValid
bool isValid() const
Definition: TrajectoryStateOnSurface.h:54
hit
Definition: SiStripHitEffFromCalibTree.cc:88
Trajectory::empty
bool empty() const
True if trajectory has no measurements.
Definition: Trajectory.h:233