CMS 3D CMS Logo

GsfTrajectorySmoother.cc
Go to the documentation of this file.
2 
8 
10 
12  const TrajectoryStateUpdator& aUpdator,
13  const MeasurementEstimator& aEstimator,
14  const MultiTrajectoryStateMerger& aMerger,
15  float errorRescaling,
16  const bool materialBeforeUpdate,
17  const DetLayerGeometry* detLayerGeometry)
18  : theAlongPropagator(nullptr),
19  theOppositePropagator(nullptr),
20  theGeomPropagator(nullptr),
21  theConvolutor(nullptr),
22  theUpdator(aUpdator.clone()),
23  theEstimator(aEstimator.clone()),
24  theMerger(aMerger.clone()),
25  theMatBeforeUpdate(materialBeforeUpdate),
26  theErrorRescaling(errorRescaling),
27  theGeometry(detLayerGeometry) {
28  auto p = aPropagator.clone();
29  p->setPropagationDirection(alongMomentum);
31  p = aPropagator.clone();
32  p->setPropagationDirection(oppositeToMomentum);
34  if (!theMatBeforeUpdate) {
37  }
38 
39  if (!theGeometry)
41 }
42 
44  delete theAlongPropagator;
45  delete theOppositePropagator;
46  delete theGeomPropagator;
47  delete theConvolutor;
48  delete theUpdator;
49  delete theEstimator;
50  delete theMerger;
51 }
52 
54  if (aTraj.empty())
55  return Trajectory();
56 
57  const Propagator* usePropagator = theAlongPropagator;
58  if (aTraj.direction() == alongMomentum) {
59  usePropagator = theOppositePropagator;
60  }
61  if (not usePropagator) {
62  usePropagator = theGeomPropagator;
63  }
64 
65  Trajectory myTraj(aTraj.seed(), usePropagator->propagationDirection());
66 
67  std::vector<TM> const& avtm = aTraj.measurements();
68 
69  TSOS predTsos = avtm.back().forwardPredictedState();
71 
72  if (!predTsos.isValid()) {
73  edm::LogInfo("GsfTrackFitters") << "GsfTrajectorySmoother: predicted tsos of last measurement not valid!";
74  return Trajectory();
75  }
76  TSOS currTsos;
77 
78  //first smoothed tm is last fitted
79  if (avtm.back().recHit()->isValid()) {
80  {
81  // TimeMe t(*updateTimer,false);
82  currTsos = updator()->update(predTsos, *avtm.back().recHit());
83  }
84 
85  if (!currTsos.isValid()) {
86  edm::LogInfo("GsfTrajectorySmoother") << "GsfTrajectorySmoother: tsos not valid after update!";
87  return Trajectory();
88  }
89 
90  //check validity
91  if (!avtm.back().forwardPredictedState().isValid() || !predTsos.isValid() ||
92  !avtm.back().updatedState().isValid()) {
93  edm::LogError("InvalidState") << "first hit";
94  return Trajectory();
95  }
96 
97  myTraj.push(TM(avtm.back().forwardPredictedState(),
98  predTsos,
99  avtm.back().updatedState(),
100  avtm.back().recHit(),
101  avtm.back().estimate(),
102  theGeometry->idToLayer(avtm.back().recHit()->geographicalId())),
103  avtm.back().estimate());
104  } else {
105  currTsos = predTsos;
106  //check validity
107  if (!avtm.back().forwardPredictedState().isValid()) {
108  edm::LogError("InvalidState") << "first hit on invalid hit";
109  return Trajectory();
110  }
111 
112  myTraj.push(TM(avtm.back().forwardPredictedState(),
113  avtm.back().recHit(),
114  0.,
115  theGeometry->idToLayer(avtm.back().recHit()->geographicalId())));
116  }
117 
119 
120  int hitcounter = avtm.size() - 1;
121  for (std::vector<TM>::const_reverse_iterator itm = avtm.rbegin() + 1; itm < avtm.rend() - 1; ++itm) {
122  predTsos = usePropagator->propagate(currTsos, *(*itm).recHit()->surface());
123  if (predTsos.isValid() && theConvolutor && theMatBeforeUpdate)
124  predTsos = (*theConvolutor)(predTsos, usePropagator->propagationDirection());
125  if (!predTsos.isValid()) {
126  edm::LogInfo("GsfTrackFitters") << "GsfTrajectorySmoother: predicted tsos not valid!";
127  return Trajectory();
128  }
129  if (theMerger)
130  predTsos = theMerger->merge(predTsos);
131 
132  if ((*itm).recHit()->isValid()) {
133  //update
134  currTsos = updator()->update(predTsos, *(*itm).recHit());
135 
136  if (currTsos.isValid() && theConvolutor && !theMatBeforeUpdate)
137  currTsos = (*theConvolutor)(currTsos, usePropagator->propagationDirection());
138  if (!currTsos.isValid()) {
139  edm::LogInfo("GsfTrackFitters") << "GsfTrajectorySmoother: tsos not valid after update / material effects!";
140  return Trajectory();
141  }
142  //3 different possibilities to calculate smoothed state:
143  //1: update combined predictions with hit
144  //2: combine fwd-prediction with bwd-filter
145  //3: combine bwd-prediction with fwd-filter
146  TSOS combTsos = combiner(predTsos, (*itm).forwardPredictedState());
147  if (!combTsos.isValid()) {
148  LogDebug("GsfTrackFitters") << "KFTrajectorySmoother: combined tsos not valid!\n"
149  << "pred Tsos pos: " << predTsos.globalPosition() << "\n"
150  << "pred Tsos mom: " << predTsos.globalMomentum() << "\n"
151  << "TrackingRecHit: "
152  << (*itm).recHit()->surface()->toGlobal((*itm).recHit()->localPosition()) << "\n";
153  return Trajectory();
154  }
155 
156  TSOS smooTsos = combiner((*itm).updatedState(), predTsos);
157 
158  if (!smooTsos.isValid()) {
159  LogDebug("GsfTrackFitters") << "KFTrajectorySmoother: smoothed tsos not valid!";
160  return Trajectory();
161  }
162 
163  if (!(*itm).forwardPredictedState().isValid() || !predTsos.isValid() || !smooTsos.isValid()) {
164  edm::LogError("InvalidState") << "inside hits with combination.";
165  return Trajectory();
166  }
167 
168  auto chi2 = estimator()->estimate(combTsos, *(*itm).recHit()).second;
169  myTraj.push(TM((*itm).forwardPredictedState(),
170  predTsos,
171  smooTsos,
172  (*itm).recHit(),
173  chi2,
174  theGeometry->idToLayer((*itm).recHit()->geographicalId())),
175  (*itm).estimate());
176  LogDebug("GsfTrackFitters") << "added measurement #" << hitcounter-- << " with chi2 " << chi2;
177  dump(predTsos, "predTsos", "GsfTrackFitters");
178  dump(smooTsos, "smooTsos", "GsfTrackFitters");
179 
180  } else {
181  currTsos = predTsos;
182  TSOS combTsos = combiner(predTsos, (*itm).forwardPredictedState());
183 
184  if (!combTsos.isValid()) {
185  LogDebug("GsfTrackFitters") << "KFTrajectorySmoother: combined tsos not valid!";
186  return Trajectory();
187  }
188 
189  if (!(*itm).forwardPredictedState().isValid() || !predTsos.isValid() || !combTsos.isValid()) {
190  edm::LogError("InvalidState") << "inside hits with invalid rechit.";
191  return Trajectory();
192  }
193 
194  myTraj.push(TM((*itm).forwardPredictedState(),
195  predTsos,
196  combTsos,
197  (*itm).recHit(),
198  0.,
199  theGeometry->idToLayer((*itm).recHit()->geographicalId())));
200  LogDebug("GsfTrackFitters") << "added invalid measurement #" << hitcounter--;
201  dump(predTsos, "predTsos", "GsfTrackFitters");
202  dump(combTsos, "smooTsos", "GsfTrackFitters");
203  }
204  if (theMerger)
205  currTsos = theMerger->merge(currTsos);
206 
207  dump(currTsos, "currTsos", "GsfTrackFitters");
208  }
209 
210  //last smoothed tm is last filtered
211  predTsos = usePropagator->propagate(currTsos, *avtm.front().recHit()->surface());
212  if (predTsos.isValid() && theConvolutor && theMatBeforeUpdate)
213  predTsos = (*theConvolutor)(predTsos, usePropagator->propagationDirection());
214  if (!predTsos.isValid()) {
215  edm::LogInfo("GsfTrackFitters") << "GsfTrajectorySmoother: predicted tsos not valid!";
216  return Trajectory();
217  }
218  if (theMerger)
219  predTsos = theMerger->merge(predTsos);
220 
221  if (avtm.front().recHit()->isValid()) {
222  //update
223  currTsos = updator()->update(predTsos, *avtm.front().recHit());
224  if (currTsos.isValid() && theConvolutor && !theMatBeforeUpdate)
225  currTsos = (*theConvolutor)(currTsos, usePropagator->propagationDirection());
226  if (!currTsos.isValid()) {
227  edm::LogInfo("GsfTrackFitters") << "GsfTrajectorySmoother: tsos not valid after update / material effects!";
228  return Trajectory();
229  }
230 
231  if (!avtm.front().forwardPredictedState().isValid() || !predTsos.isValid() || !currTsos.isValid()) {
232  edm::LogError("InvalidState") << "last hit";
233  return Trajectory();
234  }
235 
236  auto chi2 = estimator()->estimate(predTsos, *avtm.front().recHit()).second;
237  myTraj.push(TM(avtm.front().forwardPredictedState(),
238  predTsos,
239  currTsos,
240  avtm.front().recHit(),
241  chi2,
242  theGeometry->idToLayer(avtm.front().recHit()->geographicalId())),
243  avtm.front().estimate());
244  LogDebug("GsfTrackFitters") << "added measurement #" << hitcounter-- << " with chi2 " << chi2;
245  dump(predTsos, "predTsos", "GsfTrackFitters");
246  dump(currTsos, "smooTsos", "GsfTrackFitters");
247 
248  } else {
249  if (!avtm.front().forwardPredictedState().isValid()) {
250  edm::LogError("InvalidState") << "last invalid hit";
251  return Trajectory();
252  }
253  myTraj.push(TM(avtm.front().forwardPredictedState(),
254  avtm.front().recHit(),
255  0.,
256  theGeometry->idToLayer(avtm.front().recHit()->geographicalId())));
257  LogDebug("GsfTrackFitters") << "added invalid measurement #" << hitcounter--;
258  }
259 
260  return myTraj;
261 }
TrajectoryStateCombiner.h
MeasurementEstimator
Definition: MeasurementEstimator.h:19
MessageLogger.h
GsfTrajectorySmoother::theMatBeforeUpdate
bool theMatBeforeUpdate
Definition: GsfTrajectorySmoother.h:62
Trajectory::direction
PropagationDirection const & direction() const
Definition: Trajectory.cc:133
GsfTrajectorySmoother::dummyGeometry
const DetLayerGeometry dummyGeometry
Definition: GsfTrajectorySmoother.h:65
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
GsfTrajectorySmoother::~GsfTrajectorySmoother
~GsfTrajectorySmoother() override
Definition: GsfTrajectorySmoother.cc:43
TrajectoryStateOnSurface::globalPosition
GlobalPoint globalPosition() const
Definition: TrajectoryStateOnSurface.h:65
GsfTrajectorySmoother::estimator
const MeasurementEstimator * estimator() const
Definition: GsfTrajectorySmoother.h:43
oppositeToMomentum
Definition: PropagationDirection.h:4
DetLayerGeometry::idToLayer
virtual const DetLayer * idToLayer(const DetId &detId) const
Definition: DetLayerGeometry.h:33
GsfPropagatorWithMaterial::geometricalPropagator
const Propagator & geometricalPropagator() const
Access to the geometrical propagator.
Definition: GsfPropagatorWithMaterial.h:75
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
GsfTrajectorySmoother::GsfTrajectorySmoother
GsfTrajectorySmoother(const GsfPropagatorWithMaterial &aPropagator, const TrajectoryStateUpdator &aUpdator, const MeasurementEstimator &aEstimator, const MultiTrajectoryStateMerger &merger, float errorRescaling, const bool materialBeforeUpdate=true, const DetLayerGeometry *detLayerGeometry=nullptr)
Definition: GsfTrajectorySmoother.cc:11
TransientTrackingRecHit.h
MultiTrajectoryStateMerger::merge
TrajectoryStateOnSurface merge(const TrajectoryStateOnSurface &tsos) const
Definition: MultiTrajectoryStateMerger.cc:4
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
GsfTrajectorySmoother::theAlongPropagator
const GsfPropagatorWithMaterial * theAlongPropagator
Definition: GsfTrajectorySmoother.h:53
hltPixelTracks_cff.chi2
chi2
Definition: hltPixelTracks_cff.py:25
GsfTrajectorySmoother::theErrorRescaling
float theErrorRescaling
Definition: GsfTrajectorySmoother.h:63
GsfTrajectorySmoother::updator
const TrajectoryStateUpdator * updator() const
Definition: GsfTrajectorySmoother.h:42
GsfTrajectorySmoother::TM
TrajectoryMeasurement TM
Definition: GsfTrajectorySmoother.h:24
MeasurementEstimator::estimate
virtual HitReturnType estimate(const TrajectoryStateOnSurface &ts, const TrackingRecHit &hit) const =0
Propagator
Definition: Propagator.h:44
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
GsfPropagatorWithMaterial::convolutionWithMaterial
const FullConvolutionWithMaterial & convolutionWithMaterial() const
Access to the convolutor and thus to the material effects.
Definition: GsfPropagatorWithMaterial.h:77
clone
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
GsfTrajectorySmoother::theUpdator
const TrajectoryStateUpdator * theUpdator
Definition: GsfTrajectorySmoother.h:57
HLTSiStripMonitoring_cff.errorRescaling
errorRescaling
Definition: HLTSiStripMonitoring_cff.py:192
GsfTrajectorySmoother::theGeometry
const DetLayerGeometry * theGeometry
Definition: GsfTrajectorySmoother.h:66
GsfPropagatorWithMaterial::clone
GsfPropagatorWithMaterial * clone() const override
Definition: GsfPropagatorWithMaterial.h:79
TrajectoryStateUpdator::update
virtual TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TrackingRecHit &) const =0
GsfTrajectorySmoother::theEstimator
const MeasurementEstimator * theEstimator
Definition: GsfTrajectorySmoother.h:58
TrajectoryStateCombiner
Definition: TrajectoryStateCombiner.h:13
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
GsfTrajectorySmoother.h
DetLayerGeometry
Definition: DetLayerGeometry.h:18
FrontierConditions_GlobalTag_cff.dump
dump
Definition: FrontierConditions_GlobalTag_cff.py:12
MultiTrajectoryStateMerger.h
DebugHelpers.h
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
Trajectory::measurements
DataContainer const & measurements() const
Definition: Trajectory.h:178
TrajectoryStateOnSurface::rescaleError
void rescaleError(double factor)
Definition: TrajectoryStateOnSurface.h:82
TrajectoryStateOnSurface::globalMomentum
GlobalVector globalMomentum() const
Definition: TrajectoryStateOnSurface.h:66
GsfTrajectorySmoother::theOppositePropagator
const GsfPropagatorWithMaterial * theOppositePropagator
Definition: GsfTrajectorySmoother.h:54
GsfTrajectorySmoother::trajectory
Trajectory trajectory(const Trajectory &aTraj) const override
Definition: GsfTrajectorySmoother.cc:53
TrajectoryMeasurement::estimate
float estimate() const
Definition: TrajectoryMeasurement.h:192
Trajectory
Definition: Trajectory.h:38
GsfTrajectorySmoother::theConvolutor
const FullConvolutionWithMaterial * theConvolutor
Definition: GsfTrajectorySmoother.h:56
Trajectory::seed
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
Definition: Trajectory.h:263
TrajectoryStateOnSurface::surface
const SurfaceType & surface() const
Definition: TrajectoryStateOnSurface.h:78
BoundPlane.h
TrajectoryStateUpdator
Definition: TrajectoryStateUpdator.h:14
heavyFlavorValidationHarvestingSequence_cff.combiner
combiner
Definition: heavyFlavorValidationHarvestingSequence_cff.py:107
GsfPropagatorWithMaterial
Definition: GsfPropagatorWithMaterial.h:23
GsfPropagatorAdapter
Definition: GsfPropagatorAdapter.h:14
GsfTrajectorySmoother::theMerger
const MultiTrajectoryStateMerger * theMerger
Definition: GsfTrajectorySmoother.h:59
GsfTrajectorySmoother::theGeomPropagator
const GsfPropagatorAdapter * theGeomPropagator
Definition: GsfTrajectorySmoother.h:55
MultiTrajectoryStateMerger
Definition: MultiTrajectoryStateMerger.h:13
alongMomentum
Definition: PropagationDirection.h:4
TrajectoryStateOnSurface::isValid
bool isValid() const
Definition: TrajectoryStateOnSurface.h:54
FullConvolutionWithMaterial::clone
FullConvolutionWithMaterial * clone() const
Clone.
Definition: FullConvolutionWithMaterial.h:29
Trajectory::empty
bool empty() const
True if trajectory has no measurements.
Definition: Trajectory.h:233