CMS 3D CMS Logo

KFTrajectoryFitter.cc
Go to the documentation of this file.
11 
13 
15  if (aTraj.empty())
16  return Trajectory();
17 
18  const TM& firstTM = aTraj.firstMeasurement();
19  TSOS firstTsos = TrajectoryStateWithArbitraryError()(firstTM.updatedState());
20 
21  return fitOne(aTraj.seed(), aTraj.recHits(), firstTsos, type);
22 }
23 
25  throw cms::Exception("TrackFitters",
26  "KFTrajectoryFitter::fit(TrajectorySeed, <TransientTrackingRecHit>) not implemented");
27 
28  return Trajectory();
29 }
30 
32  const RecHitContainer& hits,
33  const TSOS& firstPredTsos,
34  fitType) const {
35  if (hits.empty())
36  return Trajectory();
37 
38  if
39  UNLIKELY(aSeed.direction() == anyDirection)
40  throw cms::Exception("KFTrajectoryFitter", "TrajectorySeed::direction() requested but not set");
41 
42  std::unique_ptr<Propagator> p_cloned = SetPropagationDirection(*thePropagator, aSeed.direction());
43 
44 #ifdef EDM_ML_DEBUG
45  LogDebug("TrackFitters")
46  << " +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
47  << " KFTrajectoryFitter::fit starting with " << hits.size() << " HITS";
48 
49  for (unsigned int j = 0; j < hits.size(); j++) {
50  if (hits[j]->det())
51  LogTrace("TrackFitters") << "hit #:" << j + 1 << " rawId=" << hits[j]->det()->geographicalId().rawId()
52  << " validity=" << hits[j]->isValid();
53  else
54  LogTrace("TrackFitters") << "hit #:" << j + 1 << " Hit with no Det information";
55  }
56  LogTrace("TrackFitters") << " INITIAL STATE " << firstPredTsos;
57 #endif
58 
59  Trajectory ret(aSeed, p_cloned->propagationDirection());
60  Trajectory& myTraj = ret;
61  myTraj.reserve(hits.size());
62 
63  TSOS predTsos(firstPredTsos);
64  TSOS currTsos;
65 
66  int hitcounter = 0;
67  for (auto ihit : hits) {
68  ++hitcounter;
69 
70  const TransientTrackingRecHit& hit = (*ihit);
71 
72  // if UNLIKELY(hit.det() == nullptr) continue;
73 
74  if
75  UNLIKELY((!hit.isValid()) && hit.surface() == nullptr) {
76  LogDebug("TrackFitters") << " Error: invalid hit with no GeomDet attached .... skipping";
77  continue;
78  }
79  // if (hit.det() && hit.geographicalId()<1000U) LogDebug("TrackFitters")<< "Problem 0 det id for " << typeid(hit).name() << ' ' << hit.det()->geographicalId() ;
80  // if (hit.isValid() && hit.geographicalId()<1000U) LogDebug("TrackFitters")<< "Problem 0 det id for " << typeid(hit).name() << ' ' << hit.det()->geographicalId();
81 
82  if (hitcounter != 1) //no propagation needed for the first hit
83  predTsos = p_cloned->propagate(currTsos, *(hit.surface()));
84 
85  if
86  UNLIKELY(!predTsos.isValid()) {
87  LogDebug("TrackFitters") << "SOMETHING WRONG !"
88  << "\n"
89  << "KFTrajectoryFitter: predicted tsos not valid!\n"
90  << "current TSOS: " << currTsos << "\n";
91 
92  if (hit.surface())
93  LogTrace("TrackFitters") << "next Surface: " << hit.surface()->position() << "\n";
94 
95  if (myTraj.foundHits() >= minHits_) {
96  LogDebug("TrackFitters") << " breaking trajectory"
97  << "\n";
98  break;
99  } else {
100  LogDebug("TrackFitters") << " killing trajectory"
101  << "\n";
102  return Trajectory();
103  }
104  }
105 
106  if
107  LIKELY(hit.isValid()) {
108  assert((hit.geographicalId() != 0U) | !hit.canImproveWithTrack());
109  assert(hit.surface() != nullptr);
110  //update
111  LogTrace("TrackFitters") << "THE HIT IS VALID: updating hit with predTsos";
112  assert((!hit.canImproveWithTrack()) | (nullptr != theHitCloner));
113  assert((!hit.canImproveWithTrack()) | (nullptr != dynamic_cast<BaseTrackerRecHit const*>((ihit).get())));
114  auto preciseHit = theHitCloner->makeShared(ihit, predTsos);
115  dump(*preciseHit, hitcounter, "TrackFitters");
116  assert(preciseHit->isValid());
117  assert((preciseHit->geographicalId() != 0U) | (!preciseHit->canImproveWithTrack()));
118  assert(preciseHit->surface() != nullptr);
119 
120  if
121  UNLIKELY(!preciseHit->isValid()) {
122  LogTrace("TrackFitters") << "THE Precise HIT IS NOT VALID: using currTsos = predTsos"
123  << "\n";
124  currTsos = predTsos;
125  myTraj.push(TM(predTsos, ihit, 0, theGeometry->idToLayer((ihit)->geographicalId())));
126  }
127  else {
128  LogTrace("TrackFitters") << "THE Precise HIT IS VALID: updating currTsos"
129  << "\n";
130  currTsos = updator()->update(predTsos, *preciseHit);
131  //check for valid hits with no det (refitter with constraints)
132  bool badState = (!currTsos.isValid()) ||
133  (hit.geographicalId().det() == DetId::Tracker &&
134  (std::abs(currTsos.localParameters().qbp()) > 100 ||
135  std::abs(currTsos.localParameters().position().y()) > 1000 ||
136  std::abs(currTsos.localParameters().position().x()) > 1000)) ||
137  edm::isNotFinite(currTsos.localParameters().qbp()) || !currTsos.localError().posDef();
138  if
139  UNLIKELY(badState) {
140  if (!currTsos.isValid()) {
141  edm::LogError("FailedUpdate")
142  << "updating with the hit failed. Not updating the trajectory with the hit";
143 
144  } else if (edm::isNotFinite(currTsos.localParameters().qbp())) {
145  edm::LogError("TrajectoryNaN") << "Trajectory has NaN";
146 
147  } else if (!currTsos.localError().posDef()) {
148  edm::LogError("TrajectoryNotPosDef") << "Trajectory covariance is not positive-definite";
149 
150  } else {
151  LogTrace("FailedUpdate") << "updated state is valid but pretty bad, skipping. currTsos " << currTsos
152  << "\n predTsos " << predTsos;
153  }
154  myTraj.push(TM(predTsos, ihit, 0, theGeometry->idToLayer((ihit)->geographicalId())));
155  //There is a no-fail policy here. So, it's time to give up
156  //Keep the traj with invalid TSOS so that it's clear what happened
157  if (myTraj.foundHits() >= minHits_) {
158  LogDebug("TrackFitters") << " breaking trajectory"
159  << "\n";
160  break;
161  } else {
162  LogDebug("TrackFitters") << " killing trajectory"
163  << "\n";
164  return Trajectory();
165  }
166  }
167  else {
168  if (preciseHit->det()) {
169  myTraj.push(TM(predTsos,
170  currTsos,
171  preciseHit,
172  estimator()->estimate(predTsos, *preciseHit).second,
173  theGeometry->idToLayer(preciseHit->geographicalId())));
174  } else {
175  myTraj.push(TM(predTsos, currTsos, preciseHit, estimator()->estimate(predTsos, *preciseHit).second));
176  }
177  }
178  }
179  }
180  else { // invalid hit
181  dump(hit, hitcounter, "TrackFitters");
182  //no update
183  LogDebug("TrackFitters") << "THE HIT IS NOT VALID: using currTsos"
184  << "\n";
185  currTsos = predTsos;
186  assert(((ihit)->det() == nullptr) || (ihit)->geographicalId() != 0U);
187  if ((ihit)->det())
188  myTraj.push(TM(predTsos, ihit, 0, theGeometry->idToLayer((ihit)->geographicalId())));
189  else
190  myTraj.push(TM(predTsos, ihit, 0));
191  }
192  LogTrace("TrackFitters") << "predTsos !"
193  << "\n"
194  << predTsos << " with local position " << predTsos.localPosition() << "currTsos !"
195  << "\n"
196  << currTsos << " with local position " << currTsos.localPosition();
197  }
198 
199  LogDebug("TrackFitters") << "Found 1 trajectory with " << myTraj.foundHits() << " valid hits\n";
200 
201  return ret;
202 }
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:355
Likely.h
anyDirection
Definition: PropagationDirection.h:4
MessageLogger.h
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
edm::isNotFinite
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
LocalTrajectoryParameters::qbp
float qbp() const
Definition: LocalTrajectoryParameters.h:158
cms::cuda::assert
assert(be >=bs)
DetLayerGeometry::idToLayer
virtual const DetLayer * idToLayer(const DetId &detId) const
Definition: DetLayerGeometry.h:33
KFTrajectoryFitter::theGeometry
const DetLayerGeometry * theGeometry
Definition: KFTrajectoryFitter.h:104
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:215
TransientTrackingRecHit.h
SetPropagationDirection
std::unique_ptr< Propagator > SetPropagationDirection(Propagator const &iprop, PropagationDirection dir)
Definition: HelperPropagatorUtility.cc:5
TrajectoryMeasurement::updatedState
TrajectoryStateOnSurface const & updatedState() const
Definition: TrajectoryMeasurement.h:184
TrajectoryStateWithArbitraryError
Definition: TrajectoryStateWithArbitraryError.h:15
KFTrajectoryFitter::dummyGeometry
static const DetLayerGeometry dummyGeometry
Definition: KFTrajectoryFitter.h:99
UNLIKELY
#define UNLIKELY(x)
Definition: Likely.h:21
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
KFTrajectoryFitter::updator
const TrajectoryStateUpdator * updator() const
Definition: KFTrajectoryFitter.h:83
LocalTrajectoryParameters::position
LocalPoint position() const
Local x and y position coordinates.
Definition: LocalTrajectoryParameters.h:85
KFTrajectoryFitter::TM
TrajectoryMeasurement TM
Definition: KFTrajectoryFitter.h:26
TrajectoryStateWithArbitraryError.h
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
TrajectoryStateOnSurface::localParameters
const LocalTrajectoryParameters & localParameters() const
Definition: TrajectoryStateOnSurface.h:73
TrajectoryStateUpdator::update
virtual TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TrackingRecHit &) const =0
KFTrajectoryFitter::fitOne
Trajectory fitOne(const Trajectory &aTraj, fitType) const override
Definition: KFTrajectoryFitter.cc:14
TrajectoryStateOnSurface::localPosition
LocalPoint localPosition() const
Definition: TrajectoryStateOnSurface.h:74
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
TrajectorySeed::direction
PropagationDirection direction() const
Definition: TrajectorySeed.h:54
edm::LogError
Definition: MessageLogger.h:183
DetId::Tracker
Definition: DetId.h:25
DetLayerGeometry
Definition: DetLayerGeometry.h:18
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
FrontierConditions_GlobalTag_cff.dump
dump
Definition: FrontierConditions_GlobalTag_cff.py:12
TkCloner.h
TkCloner::makeShared
TrackingRecHit::ConstRecHitPointer makeShared(TrackingRecHit::ConstRecHitPointer const &hit, TrajectoryStateOnSurface const &tsos) const
Definition: TkCloner.h:23
DebugHelpers.h
KFTrajectoryFitter::thePropagator
const Propagator * thePropagator
Definition: KFTrajectoryFitter.h:100
get
#define get
KFTrajectoryFitter::minHits_
int minHits_
Definition: KFTrajectoryFitter.h:105
TrackingRecHit
Definition: TrackingRecHit.h:21
BaseTrackerRecHit.h
Trajectory::recHits
ConstRecHitContainer recHits() const
Definition: Trajectory.h:186
type
type
Definition: HCALResponse.h:21
Trajectory::firstMeasurement
TrajectoryMeasurement const & firstMeasurement() const
Definition: Trajectory.h:166
isFinite.h
Trajectory
Definition: Trajectory.h:38
LIKELY
#define LIKELY(x)
Definition: Likely.h:20
Exception
Definition: hltDiff.cc:246
Trajectory::seed
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
Definition: Trajectory.h:263
TrajectorySeed
Definition: TrajectorySeed.h:17
KFTrajectoryFitter::estimator
const MeasurementEstimator * estimator() const
Definition: KFTrajectoryFitter.h:84
Exception.h
KFTrajectoryFitter.h
cms::Exception
Definition: Exception.h:70
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:671
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
TrajectoryStateOnSurface::localError
const LocalTrajectoryError & localError() const
Definition: TrajectoryStateOnSurface.h:77
TrajectoryMeasurement
Definition: TrajectoryMeasurement.h:25
TrajectoryFitter::RecHitContainer
Trajectory::RecHitContainer RecHitContainer
Definition: TrajectoryFitter.h:24
KFTrajectoryFitter::theHitCloner
TkCloner const * theHitCloner
Definition: KFTrajectoryFitter.h:103
TrajectoryStateOnSurface::isValid
bool isValid() const
Definition: TrajectoryStateOnSurface.h:54
hit
Definition: SiStripHitEffFromCalibTree.cc:88
LocalTrajectoryError::posDef
bool posDef() const
Definition: LocalTrajectoryError.h:35
Trajectory::empty
bool empty() const
True if trajectory has no measurements.
Definition: Trajectory.h:233
TrajectoryFitter::fitType
fitType
Definition: TrajectoryFitter.h:21