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