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