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 {
23  if(!theGeometry) theGeometry = &dummyGeometry;
24  // static SimpleConfigurable<bool> timeConf(false,"GsfTrajectoryFitter:activateTiming");
25  // theTiming = timeConf.value();
26 }
27 
28 GsfTrajectoryFitter::~GsfTrajectoryFitter() {
29  delete thePropagator;
30  delete theUpdator;
31  delete theEstimator;
32  delete theMerger;
33 }
34 
35 Trajectory GsfTrajectoryFitter::fitOne(const Trajectory& aTraj, fitType type) const {
36  if(aTraj.empty()) return Trajectory();
37 
38  TM const & firstTM = aTraj.firstMeasurement();
39  TSOS firstTsos = TrajectoryStateWithArbitraryError()(firstTM.updatedState());
40 
41  return fitOne(aTraj.seed(), aTraj.recHits(), firstTsos,type);
42 }
43 
44 Trajectory GsfTrajectoryFitter::fitOne(const TrajectorySeed& aSeed,
45  const RecHitContainer& hits, fitType type) const {
46 
47  edm::LogError("GsfTrajectoryFitter")
48  << "GsfTrajectoryFitter::fit(TrajectorySeed, vector<RecHit>) not implemented";
49 
50  return Trajectory();
51 }
52 
53 Trajectory GsfTrajectoryFitter::fitOne(const TrajectorySeed& aSeed,
54  const RecHitContainer& hits,
55  const TrajectoryStateOnSurface& firstPredTsos,
56  fitType) 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 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 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 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 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 myTraj;
139  }
140  else {
141  edm::LogInfo("GsfTrajectoryFitter")
142  << "GsfTrajectoryFitter: predicted tsos not valid after " << myTraj.foundHits()
143  << " hits, discarding candidate!";
144  return 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 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 Trajectory();
168  }
169  myTraj.push(TM(predTsos, *ihit,0., theGeometry->idToLayer( (*ihit)->geographicalId()) ));
170  }
171  }
172  return myTraj;
173 }
#define LogDebug(id)
bool empty() const
True if trajectory has no measurements.
Definition: Trajectory.h:246
type
Definition: HCALResponse.h:21
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
Definition: Trajectory.h:277
ConstRecHitContainer recHits(bool splitting=false) const
Definition: Trajectory.cc:67
U second(std::pair< T, U > const &p)
const SurfaceType & surface() const
void update(const LocalTrajectoryParameters &p, const SurfaceType &aSurface, const MagneticField *field, const SurfaceSide side=SurfaceSideDefinition::atCenterOfSurface)
TrajectoryMeasurement const & firstMeasurement() const
Definition: Trajectory.h:206
tuple clone
Definition: statics.py:58