CMS 3D CMS Logo

TransientInitialStateEstimator.cc
Go to the documentation of this file.
2 
6 
8 
12 
15 
17 
18 using namespace std;
19 
21  : thePropagatorAlongToken(
22  iC.esConsumes(edm::ESInputTag("", conf.getParameter<std::string>("propagatorAlongTISE")))),
23  thePropagatorOppositeToken(
24  iC.esConsumes(edm::ESInputTag("", conf.getParameter<std::string>("propagatorOppositeTISE")))),
25  thePropagatorAlong(nullptr),
26  thePropagatorOpposite(nullptr),
27  theNumberMeasurementsForFit(conf.getParameter<int>("numberMeasurementsForFit")) {}
28 
30  theHitCloner = hc;
33 }
34 
35 std::pair<TrajectoryStateOnSurface, const GeomDet*> TransientInitialStateEstimator::innerState(const Trajectory& traj,
36  bool doBackFit) const {
37  if (!doBackFit && traj.firstMeasurement().forwardPredictedState().isValid()) {
38  LogDebug("TransientInitialStateEstimator")
39  << "a backward fit will not be done. assuming that the state on first measurement is OK";
40  TSOS firstStateFromForward = traj.firstMeasurement().forwardPredictedState();
41  firstStateFromForward.rescaleError(100.);
42  return std::pair<TrajectoryStateOnSurface, const GeomDet*>(std::move(firstStateFromForward),
43  traj.firstMeasurement().recHit()->det());
44  }
45  if (!doBackFit) {
46  LogDebug("TransientInitialStateEstimator")
47  << "told to not do a back fit, but the forward state of the first measurement is not valid. doing a back fit.";
48  }
49 
50  int nMeas = traj.measurements().size();
51  int lastFitted = theNumberMeasurementsForFit >= 0 ? theNumberMeasurementsForFit : nMeas;
52  if (nMeas - 1 < lastFitted)
53  lastFitted = nMeas - 1;
54 
55  auto const& measvec = traj.measurements();
57 
58  bool foundLast = false;
59  int actualLast = -99;
60 
61  for (int i = lastFitted; i >= 0; i--) {
62  if (measvec[i].recHit()->det()) {
63  if (!foundLast) {
64  actualLast = i;
65  foundLast = true;
66  }
67  firstHits.push_back(measvec[i].recHit());
68  }
69  }
70  TSOS startingState = measvec[actualLast].updatedState();
71  startingState.rescaleError(100.);
72 
73  // avoid cloning...
74  KFUpdator const aKFUpdator;
75  Chi2MeasurementEstimator const aChi2MeasurementEstimator(100., 3);
76  KFTrajectoryFitter backFitter(
77  thePropagatorAlong, &aKFUpdator, &aChi2MeasurementEstimator, firstHits.size(), nullptr, &theHitCloner);
78 
80 
81  // only direction matters in this contest
83 
84  Trajectory&& fitres = backFitter.fitOne(
85  fakeSeed, firstHits, startingState, traj.nLoops() > 0 ? TrajectoryFitter::looper : TrajectoryFitter::standard);
86 
87  LogDebug("TransientInitialStateEstimator")
88  << "using a backward fit of :" << firstHits.size() << " hits, starting from:\n"
89  << startingState << " to get the estimate of the initial state of the track.";
90 
91  if (!fitres.isValid()) {
92  LogDebug("TransientInitialStateEstimator") << "FitTester: first hits fit failed!";
93  return std::pair<TrajectoryStateOnSurface, const GeomDet*>();
94  }
95 
96  TrajectoryMeasurement const& firstMeas = fitres.lastMeasurement();
97 
98  // magnetic field can be different!
99  TSOS firstState(firstMeas.updatedState().localParameters(),
100  firstMeas.updatedState().localError(),
101  firstMeas.updatedState().surface(),
103 
104  // TSOS & firstState = const_cast<TSOS&>(firstMeas.updatedState());
105 
106  // this fails in case of zero field? (for sure for beamhalo reconstruction)
107  // assert(thePropagatorAlong->magneticField()==firstState.magneticField());
108 
109  firstState.rescaleError(100.);
110 
111  LogDebug("TransientInitialStateEstimator")
112  << "the initial state is found to be:\n:" << firstState
113  << "\n it's field pointer is: " << firstState.magneticField()
114  << "\n the pointer from the state of the back fit was: " << firstMeas.updatedState().magneticField();
115 
116  return std::pair<TrajectoryStateOnSurface, const GeomDet*>(std::move(firstState), firstMeas.recHit()->det());
117 }
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
const edm::ESGetToken< Propagator, TrackingComponentsRecord > thePropagatorAlongToken
bool isValid() const
Definition: Trajectory.h:257
const LocalTrajectoryError & localError() const
std::pair< TrajectoryStateOnSurface, const GeomDet * > innerState(const Trajectory &traj, bool doBackFit=true) const
TrajectoryStateOnSurface const & forwardPredictedState() const
Access to forward predicted state (from fitter or builder)
const LocalTrajectoryParameters & localParameters() const
PropagationDirection
const SurfaceType & surface() const
TrajectoryMeasurement const & lastMeasurement() const
Definition: Trajectory.h:150
DataContainer const & measurements() const
Definition: Trajectory.h:178
void setEventSetup(const edm::EventSetup &es, const TkClonerImpl &hc)
PropagationDirection const & direction() const
Definition: Trajectory.cc:133
bool getData(T &iHolder) const
Definition: EventSetup.h:122
std::vector< ConstRecHitPointer > ConstRecHitContainer
TrajectoryStateOnSurface const & updatedState() const
virtual const MagneticField * magneticField() const =0
signed char nLoops() const
Definition: Trajectory.h:329
HLT enums.
TrajectoryMeasurement const & firstMeasurement() const
Definition: Trajectory.h:166
TransientInitialStateEstimator(const edm::ParameterSet &conf, edm::ConsumesCollector iC)
const MagneticField * magneticField() const
def move(src, dest)
Definition: eostools.py:511
const edm::ESGetToken< Propagator, TrackingComponentsRecord > thePropagatorOppositeToken
ConstRecHitPointer const & recHit() const
#define LogDebug(id)