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