CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
KFTrajectoryFitter.cc
Go to the documentation of this file.
16 
17 
19 
20 std::vector<Trajectory> KFTrajectoryFitter::fit(const Trajectory& aTraj) const {
21 
22  if(aTraj.empty()) return std::vector<Trajectory>();
23 
24  TM firstTM = aTraj.firstMeasurement();
25  TSOS firstTsos = TrajectoryStateWithArbitraryError()(firstTM.updatedState());
26 
27  return fit(aTraj.seed(), aTraj.recHits(), firstTsos);
28 }
29 
30 std::vector<Trajectory> KFTrajectoryFitter::fit(const TrajectorySeed& aSeed,
31  const RecHitContainer& hits) const{
32 
33  throw cms::Exception("TrackFitters",
34  "KFTrajectoryFitter::fit(TrajectorySeed, <TransientTrackingRecHit>) not implemented");
35 
36  return std::vector<Trajectory>();
37 }
38 
39 std::vector<Trajectory> KFTrajectoryFitter::fit(const TrajectorySeed& aSeed,
40  const RecHitContainer& hits,
41  const TSOS& firstPredTsos) const
42 {
43  if(hits.empty()) return std::vector<Trajectory>();
44 
45 
46  if (aSeed.direction() == anyDirection)
47  throw cms::Exception("KFTrajectoryFitter","TrajectorySeed::direction() requested but not set");
48 
50 
51 #ifdef EDM_LM_DEBUG
52  LogDebug("TrackFitters")
53  <<" +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
54  <<" KFTrajectoryFitter::fit starting with " << hits.size() <<" HITS";
55 
56  for (unsigned int j=0;j<hits.size();j++) {
57  if (hits[j]->det())
58  LogTrace("TrackFitters") << "hit #:" << j+1 << " rawId=" << hits[j]->det()->geographicalId().rawId()
59  << " validity=" << hits[j]->isValid();
60  else
61  LogTrace("TrackFitters") << "hit #:" << j+1 << " Hit with no Det information";
62  }
63  LogTrace("TrackFitters") << " INITIAL STATE "<< firstPredTsos;
64 #endif
65 
66  std::vector<Trajectory> ret(1, Trajectory(aSeed, thePropagator->propagationDirection()));
67  Trajectory & myTraj = ret.front();
68  myTraj.reserve(hits.size());
69 
70  TSOS predTsos(firstPredTsos);
71  TSOS currTsos;
72 
73  int hitcounter = 1;
74  for(RecHitContainer::const_iterator ihit = hits.begin(); ihit != hits.end(); ++ihit, ++hitcounter) {
75 
76  const TransientTrackingRecHit & hit = (**ihit);
77 
78  if (hit.isValid() == false && hit.surface() == 0) {
79  LogDebug("TrackFitters")<< " Error: invalid hit with no GeomDet attached .... skipping";
80  continue;
81  }
82 
83 #ifdef EDM_LM_DEBUG
84  if (hit.isValid()) {
85  LogTrace("TrackFitters")
86  << " ----------------- HIT #" << hitcounter << " (VALID)-----------------------\n"
87  << " HIT IS AT R " << hit.globalPosition().perp() << "\n"
88  << " HIT IS AT Z " << hit.globalPosition().z() << "\n"
89  << " HIT IS AT Phi " << hit.globalPosition().phi() << "\n"
90  << " HIT IS AT Loc " << hit.localPosition() << "\n"
91  << " WITH LocError " << hit.localPositionError() << "\n"
92  << " HIT IS AT Glo " << hit.globalPosition() << "\n"
93  << "SURFACE POSITION" << "\n"
94  << hit.surface()->position()<<"\n"
95  << "SURFACE ROTATION" << "\n"
96  << hit.surface()->rotation();
97 
98  DetId hitId = hit.geographicalId();
99 
100  LogTrace("TrackFitters") << " hit det=" << hitId.rawId();
101 
102  if(hitId.det() == DetId::Tracker) {
103  if (hitId.subdetId() == StripSubdetector::TIB )
104  LogTrace("TrackFitters") << " I am TIB " << TIBDetId(hitId).layer();
105  else if (hitId.subdetId() == StripSubdetector::TOB )
106  LogTrace("TrackFitters") << " I am TOB " << TOBDetId(hitId).layer();
107  else if (hitId.subdetId() == StripSubdetector::TEC )
108  LogTrace("TrackFitters") << " I am TEC " << TECDetId(hitId).wheel();
109  else if (hitId.subdetId() == StripSubdetector::TID )
110  LogTrace("TrackFitters") << " I am TID " << TIDDetId(hitId).wheel();
111  else if (hitId.subdetId() == StripSubdetector::TID )
112  LogTrace("TrackFitters") << " I am TID " << TIDDetId(hitId).wheel();
113  else if (hitId.subdetId() == (int) PixelSubdetector::PixelBarrel )
114  LogTrace("TrackFitters") << " I am PixBar " << PXBDetId(hitId).layer();
115  else if (hitId.subdetId() == (int) PixelSubdetector::PixelEndcap )
116  LogTrace("TrackFitters") << " I am PixFwd " << PXFDetId(hitId).disk();
117  else
118  LogTrace("TrackFitters") << " UNKNOWN TRACKER HIT TYPE ";
119  }
120  else if(hitId.det() == DetId::Muon) {
121  if(hitId.subdetId() == MuonSubdetId::DT)
122  LogTrace("TrackFitters") << " I am DT " << DTWireId(hitId);
123  else if (hitId.subdetId() == MuonSubdetId::CSC )
124  LogTrace("TrackFitters") << " I am CSC " << CSCDetId(hitId);
125  else if (hitId.subdetId() == MuonSubdetId::RPC )
126  LogTrace("TrackFitters") << " I am RPC " << RPCDetId(hitId);
127  else
128  LogTrace("TrackFitters") << " UNKNOWN MUON HIT TYPE ";
129  }
130  else
131  LogTrace("TrackFitters") << " UNKNOWN HIT TYPE ";
132 
133  } else {
134  LogTrace("TrackFitters")
135  << " ----------------- INVALID HIT #" << hitcounter << " -----------------------";
136  }
137 #endif
138 
139  if ( hitcounter != 1) //no propagation needed for the first hit
140  predTsos = thePropagator->propagate( currTsos, *(hit.surface()) );
141 
142 
143  if(!predTsos.isValid()) {
144  LogDebug("TrackFitters")
145  << "SOMETHING WRONG !" << "\n"
146  << "KFTrajectoryFitter: predicted tsos not valid!\n"
147  << "current TSOS: " << currTsos << "\n";
148 
149  if(hit.surface()) LogTrace("TrackFitters") << "next Surface: " << hit.surface()->position() << "\n";
150 
151  if( myTraj.foundHits() >= minHits_ ) {
152  LogDebug("TrackFitters") << " breaking trajectory" << "\n";
153  break;
154  } else {
155  LogDebug("TrackFitters") << " killing trajectory" << "\n";
156  return std::vector<Trajectory>();
157  }
158  }
159 
160  if(hit.isValid()) {
161  //update
162  LogTrace("TrackFitters") << "THE HIT IS VALID: updating hit with predTsos";
163  TransientTrackingRecHit::RecHitPointer preciseHit = hit.clone(predTsos);
164 
165  if (preciseHit->isValid() == false){
166  LogTrace("TrackFitters") << "THE Precise HIT IS NOT VALID: using currTsos = predTsos" << "\n";
167  currTsos = predTsos;
168  myTraj.push(TM(predTsos, *ihit,0,theGeometry->idToLayer((*ihit)->geographicalId()) ));
169 
170  }else{
171  LogTrace("TrackFitters") << "THE Precise HIT IS VALID: updating currTsos" << "\n";
172  currTsos = updator()->update(predTsos, *preciseHit);
173  //check for valid hits with no det (refitter with constraints)
174  bool badState = (!currTsos.isValid())
175  || (hit.geographicalId().det() == DetId::Tracker
176  &&
177  (std::abs(currTsos.localParameters().qbp())>100
178  || std::abs(currTsos.localParameters().position().y()) > 1000
179  || std::abs(currTsos.localParameters().position().x()) > 1000
180  ) ) || std::isnan(currTsos.localParameters().qbp());
181  if (badState){
182  if (!currTsos.isValid()) edm::LogError("FailedUpdate")<<"updating with the hit failed. Not updating the trajectory with the hit";
183  else if (std::isnan(currTsos.localParameters().qbp())) edm::LogError("TrajectoryNaN")<<"Trajectory has NaN";
184  else LogTrace("FailedUpdate")<<"updated state is valid but pretty bad, skipping. currTsos "<<currTsos<<"\n predTsos "<<predTsos;
185  myTraj.push(TM(predTsos, *ihit,0,theGeometry->idToLayer((*ihit)->geographicalId()) ));
186  //There is a no-fail policy here. So, it's time to give up
187  //Keep the traj with invalid TSOS so that it's clear what happened
188  if( myTraj.foundHits() >= minHits_ ) {
189  LogDebug("TrackFitters") << " breaking trajectory" << "\n";
190  break;
191  } else {
192  LogDebug("TrackFitters") << " killing trajectory" << "\n";
193  return std::vector<Trajectory>();
194  }
195  }
196  else{
197  if (preciseHit->det()) myTraj.push(TM(predTsos, currTsos, preciseHit,
198  estimator()->estimate(predTsos, *preciseHit).second,
199  theGeometry->idToLayer(preciseHit->geographicalId()) ));
200  else myTraj.push(TM(predTsos, currTsos, preciseHit,
201  estimator()->estimate(predTsos, *preciseHit).second));
202  }
203  }
204  } else {
205  //no update
206  LogDebug("TrackFitters") << "THE HIT IS NOT VALID: using currTsos" << "\n";
207  currTsos = predTsos;
208  myTraj.push(TM(predTsos, *ihit,0,theGeometry->idToLayer((*ihit)->geographicalId()) ));
209  }
210 
211  LogTrace("TrackFitters")
212  << "predTsos !" << "\n"
213  << predTsos << "\n"
214  <<"currTsos !" << "\n"
215  << currTsos;
216  }
217 
218  LogDebug("TrackFitters") << "Found 1 trajectory with " << myTraj.foundHits() << " valid hits\n";
219 
220  return ret;
221 }
222 
#define LogDebug(id)
PropagationDirection direction() const
bool empty() const
True if trajectory has no measurements.
Definition: Trajectory.h:234
int foundHits() const
Definition: Trajectory.h:224
T perp() const
Definition: PV3DBase.h:71
unsigned int layer() const
layer id
Definition: TOBDetId.h:39
virtual PropagationDirection propagationDirection() const
Definition: Propagator.h:143
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
Definition: Trajectory.h:265
const LocalTrajectoryParameters & localParameters() const
const TrajectoryStateUpdator * updator() const
LocalPoint position() const
Local x and y position coordinates.
virtual TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TransientTrackingRecHit &) const =0
Geom::Phi< T > phi() const
Definition: PV3DBase.h:68
const MeasurementEstimator * estimator() const
T y() const
Definition: PV3DBase.h:62
#define abs(x)
Definition: mlp_lapack.h:159
TrajectoryMeasurement TM
void reserve(unsigned int n)
Definition: Trajectory.h:159
unsigned int layer() const
layer id
Definition: PXBDetId.h:35
ConstRecHitContainer recHits(bool splitting=false) const
Definition: Trajectory.cc:67
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
U second(std::pair< T, U > const &p)
static const int CSC
Definition: MuonSubdetId.h:15
static const DetLayerGeometry dummyGeometry
virtual std::vector< Trajectory > fit(const Trajectory &aTraj) const
bool isnan(float x)
Definition: math.h:13
T z() const
Definition: PV3DBase.h:63
int j
Definition: DBlmapReader.cc:9
TrajectoryStateOnSurface updatedState() const
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
#define LogTrace(id)
unsigned int disk() const
disk id
Definition: PXFDetId.h:43
virtual TrajectoryStateOnSurface propagate(const FreeTrajectoryState &, const Surface &) const
Definition: Propagator.cc:12
const DetLayerGeometry * theGeometry
Definition: DetId.h:20
TrajectoryMeasurement const & firstMeasurement() const
Definition: Trajectory.h:194
virtual LocalError localPositionError() const =0
bool isValid() const
unsigned int wheel() const
wheel id
Definition: TECDetId.h:52
unsigned int layer() const
layer id
Definition: TIBDetId.h:41
virtual RecHitPointer clone(const TrajectoryStateOnSurface &ts) const
virtual GlobalPoint globalPosition() const
static const int RPC
Definition: MuonSubdetId.h:16
const Propagator * thePropagator
virtual const Surface * surface() const
const RotationType & rotation() const
static const int DT
Definition: MuonSubdetId.h:14
DetId geographicalId() const
virtual const DetLayer * idToLayer(const DetId &detId) const
Detector det() const
get the detector field from this detid
Definition: DetId.h:37
T x() const
Definition: PV3DBase.h:61
virtual LocalPoint localPosition() const =0
const PositionType & position() const
Trajectory::RecHitContainer RecHitContainer
void push(const TrajectoryMeasurement &tm)
Definition: Trajectory.cc:35
unsigned int wheel() const
wheel id
Definition: TIDDetId.h:50