CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GsfTrajectoryFitter.cc
Go to the documentation of this file.
2 
5 // #include "CommonDet/BasicDet/interface/Det.h"
8 // #include "Utilities/Notification/interface/Verbose.h"
9 // #include "Utilities/Notification/interface/TimingReport.h"
11 
12 
15 
16 
18  const TrajectoryStateUpdator& aUpdator,
19  const MeasurementEstimator& aEstimator,
20  const MultiTrajectoryStateMerger& aMerger,
21  const DetLayerGeometry* detLayerGeometry) :
22  thePropagator(aPropagator.clone()),
23  theUpdator(aUpdator.clone()),
24  theEstimator(aEstimator.clone()),
25  theMerger(aMerger.clone()),
26  theGeometry(detLayerGeometry)
27 {
29  // static SimpleConfigurable<bool> timeConf(false,"GsfTrajectoryFitter:activateTiming");
30  // theTiming = timeConf.value();
31 }
32 
34  delete thePropagator;
35  delete theUpdator;
36  delete theEstimator;
37  delete theMerger;
38 }
39 
41  if(aTraj.empty()) return Trajectory();
42 
43  TM const & firstTM = aTraj.firstMeasurement();
44  TSOS firstTsos = TrajectoryStateWithArbitraryError()(firstTM.updatedState());
45 
46  return fitOne(aTraj.seed(), aTraj.recHits(), firstTsos,type);
47 }
48 
50  const RecHitContainer& hits, fitType type) const {
51 
52  edm::LogError("GsfTrajectoryFitter")
53  << "GsfTrajectoryFitter::fit(TrajectorySeed, vector<RecHit>) not implemented";
54 
55  return Trajectory();
56 }
57 
59  const RecHitContainer& hits,
60  const TrajectoryStateOnSurface& firstPredTsos,
61  fitType) const {
62 
63  // static TimingReport::Item* propTimer =
64  // &(*TimingReport::current())[string("GsfTrajectoryFitter:propagation")];
65  // propTimer->switchCPU(false);
66  // if ( !theTiming ) propTimer->switchOn(false);
67  // static TimingReport::Item* updateTimer =
68  // &(*TimingReport::current())[string("GsfTrajectoryFitter:update")];
69  // updateTimer->switchCPU(false);
70  // if ( !theTiming ) updateTimer->switchOn(false);
71 
72  if(hits.empty()) return Trajectory();
73 
74  Trajectory myTraj(aSeed, propagator()->propagationDirection());
75 
76  TSOS predTsos(firstPredTsos);
77  if(!predTsos.isValid()) {
78  edm::LogInfo("GsfTrajectoryFitter")
79  << "GsfTrajectoryFitter: predicted tsos of first measurement not valid!";
80  return Trajectory();
81  }
82 
83  TSOS currTsos;
84  if(hits.front()->isValid()) {
85  auto const & ihit = hits.front();
86  //update
87  assert( (!(ihit)->canImproveWithTrack()) | (nullptr!=theHitCloner));
88  assert( (!(ihit)->canImproveWithTrack()) | (nullptr!=dynamic_cast<BaseTrackerRecHit const*>(ihit.get())));
89  auto preciseHit = theHitCloner->makeShared(ihit,predTsos);
90  {
91  // TimeMe t(*updateTimer,false);
92  currTsos = updator()->update(predTsos, *preciseHit);
93  }
94  if (!predTsos.isValid() || !currTsos.isValid()){
95  edm::LogError("InvalidState")<<"first hit";
96  return Trajectory();
97  }
98  myTraj.push(TM(predTsos, currTsos, preciseHit, 0., theGeometry->idToLayer(preciseHit->geographicalId() )),
99  estimator()->estimate(predTsos, *preciseHit).second);
100  } else {
101  currTsos = predTsos;
102  if (!predTsos.isValid()){
103  edm::LogError("InvalidState")<<"first invalid hit";
104  return Trajectory();
105  }
106  myTraj.push(TM(predTsos, *hits.begin(),0., theGeometry->idToLayer((*hits.begin())->geographicalId()) ));
107  }
108 
109  for(RecHitContainer::const_iterator ihit = hits.begin() + 1;
110  ihit != hits.end(); ihit++) {
111  //
112  // temporary protection copied from KFTrajectoryFitter.
113  //
114  if ((**ihit).isValid() == false && (**ihit).det() == 0) {
115  LogDebug("GsfTrajectoryFitter") << " Error: invalid hit with no GeomDet attached .... skipping";
116  continue;
117  }
118 
120  // //
121  // // check type of surface in case of invalid hit
122  // // (in this version only propagations to planes are
123  // // supported for multi trajectory states)
124  // //
125  // if ( !(**ihit).isValid() ) {
126  // const BoundPlane* plane =
127  // dynamic_cast<const BoundPlane*>(&(**ihit).det().surface());
128  // //
129  // // no plane: insert invalid measurement
130  // //
131  // if ( plane==0 ) {
132  // myTraj.push(TM(TrajectoryStateOnSurface(),&(**ihit)));
133  // continue;
134  // }
135  // }
136  {
137  // TimeMe t(*propTimer,false);
138  predTsos = propagator()->propagate(currTsos,
139  (**ihit).det()->surface());
140  }
141  if(!predTsos.isValid()) {
142  if ( myTraj.foundHits()>=3 ) {
143  edm::LogInfo("GsfTrajectoryFitter")
144  << "GsfTrajectoryFitter: predicted tsos not valid! \n"
145  << "Returning trajectory with " << myTraj.foundHits() << " found hits.";
146  return myTraj;
147  }
148  else {
149  edm::LogInfo("GsfTrajectoryFitter")
150  << "GsfTrajectoryFitter: predicted tsos not valid after " << myTraj.foundHits()
151  << " hits, discarding candidate!";
152  return Trajectory();
153  }
154  }
155  if ( merger() ) predTsos = merger()->merge(predTsos);
156 
157  if((**ihit).isValid()) {
158  //update
159  assert( (!(*ihit)->canImproveWithTrack()) | (nullptr!=theHitCloner));
160  assert( (!(*ihit)->canImproveWithTrack()) | (nullptr!=dynamic_cast<BaseTrackerRecHit const*>((*ihit).get())));
161  auto preciseHit = theHitCloner->makeShared(*ihit,predTsos);
162  {
163  // TimeMe t(*updateTimer,false);
164  currTsos = updator()->update(predTsos, *preciseHit);
165  }
166  if (!predTsos.isValid() || !currTsos.isValid()){
167  edm::LogError("InvalidState")<<"inside hit";
168  return Trajectory();
169  }
170  myTraj.push(TM(predTsos, currTsos, preciseHit,
171  estimator()->estimate(predTsos, *preciseHit).second,
172  theGeometry->idToLayer(preciseHit->geographicalId() )));
173  } else {
174  currTsos = predTsos;
175  if (!predTsos.isValid()){
176  edm::LogError("InvalidState")<<"inside invalid hit";
177  return Trajectory();
178  }
179  myTraj.push(TM(predTsos, *ihit,0., theGeometry->idToLayer( (*ihit)->geographicalId()) ));
180  }
181  }
182  return myTraj;
183 }
#define LogDebug(id)
bool empty() const
True if trajectory has no measurements.
Definition: Trajectory.h:244
const Propagator * thePropagator
type
Definition: HCALResponse.h:21
const MultiTrajectoryStateMerger * theMerger
int foundHits() const
Definition: Trajectory.h:234
virtual FreeTrajectoryState propagate(const FreeTrajectoryState &ftsStart, const GlobalPoint &pDest) const final
Definition: Propagator.h:119
GsfTrajectoryFitter(const Propagator &aPropagator, const TrajectoryStateUpdator &aUpdator, const MeasurementEstimator &aEstimator, const MultiTrajectoryStateMerger &aMerger, const DetLayerGeometry *detLayerGeometry=0)
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
Definition: Trajectory.h:275
assert(m_qm.get())
TrajectoryStateOnSurface merge(const TrajectoryStateOnSurface &tsos) const
const DetLayerGeometry * theGeometry
const MeasurementEstimator * theEstimator
U second(std::pair< T, U > const &p)
virtual TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TrackingRecHit &) const =0
const SurfaceType & surface() const
TrajectoryMeasurement TM
virtual HitReturnType estimate(const TrajectoryStateOnSurface &ts, const TrackingRecHit &hit) const =0
const MultiTrajectoryStateMerger * merger() const
TrajectoryMeasurement const & firstMeasurement() const
Definition: Trajectory.h:194
TrackingRecHit *operator()[[cms TrackingRecHit::ConstRecHitPointer makeShared(TrackingRecHit::ConstRecHitPointer const &hit, TrajectoryStateOnSurface const &tsos) const
Definition: TkCloner.h:22
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
Trajectory fitOne(const Trajectory &t, fitType type) const
const Propagator * propagator() const
const TrajectoryStateUpdator * updator() const
const TrajectoryStateUpdator * theUpdator
TrajectoryStateOnSurface const & updatedState() const
virtual const DetLayer * idToLayer(const DetId &detId) const
Trajectory::RecHitContainer RecHitContainer
void push(const TrajectoryMeasurement &tm)
Definition: Trajectory.cc:30
const MeasurementEstimator * estimator() const
const DetLayerGeometry dummyGeometry
TkCloner const * theHitCloner