CMS 3D CMS Logo

TransientInitialStateEstimator.cc
Go to the documentation of this file.
2 
7 
9 
13 
16 
18 
19 using namespace std;
20 
22  thePropagatorAlongName(conf.getParameter<std::string>("propagatorAlongTISE")),
23  thePropagatorOppositeName(conf.getParameter<std::string>("propagatorOppositeTISE")),
24  thePropagatorAlong(nullptr),
25  thePropagatorOpposite(nullptr),
26  theNumberMeasurementsForFit(conf.getParameter<int>("numberMeasurementsForFit"))
27 {}
28 
30  theHitCloner = hc;
31 
33  edm::ESHandle<Propagator> hopposite;
34 
37  thePropagatorAlong = halong.product();
38  thePropagatorOpposite = hopposite.product();
39 }
40 
41 std::pair<TrajectoryStateOnSurface, const GeomDet*>
42 TransientInitialStateEstimator::innerState( const Trajectory& traj, bool doBackFit) const
43 {
44  if (!doBackFit && traj.firstMeasurement().forwardPredictedState().isValid()){
45  LogDebug("TransientInitialStateEstimator")
46  <<"a backward fit will not be done. assuming that the state on first measurement is OK";
47  TSOS firstStateFromForward = traj.firstMeasurement().forwardPredictedState();
48  firstStateFromForward.rescaleError(100.);
49  return std::pair<TrajectoryStateOnSurface, const GeomDet*>( std::move(firstStateFromForward),
50  traj.firstMeasurement().recHit()->det());
51  }
52  if (!doBackFit){
53  LogDebug("TransientInitialStateEstimator")
54  <<"told to not do a back fit, but the forward state of the first measurement is not valid. doing a back fit.";
55  }
56 
57  int nMeas = traj.measurements().size();
58  int lastFitted = theNumberMeasurementsForFit >=0 ? theNumberMeasurementsForFit : nMeas;
59  if (nMeas-1 < lastFitted) lastFitted = nMeas-1;
60 
61  auto const & measvec = traj.measurements();
63 
64  bool foundLast = false;
65  int actualLast = -99;
66 
67  for (int i=lastFitted; i >= 0; i--) {
68  if(measvec[i].recHit()->det()){
69  if(!foundLast){
70  actualLast = i;
71  foundLast = true;
72  }
73  firstHits.push_back( measvec[i].recHit());
74  }
75  }
76  TSOS startingState = measvec[actualLast].updatedState();
77  startingState.rescaleError(100.);
78 
79  // avoid cloning...
80  KFUpdator const aKFUpdator;
81  Chi2MeasurementEstimator const aChi2MeasurementEstimator( 100., 3);
82  KFTrajectoryFitter backFitter( thePropagatorAlong,
83  &aKFUpdator,
84  &aChi2MeasurementEstimator,
85  firstHits.size(),nullptr,&theHitCloner);
86 
88 
89  // only direction matters in this contest
92  backFitDirection);
93 
94  Trajectory && fitres = backFitter.fitOne( fakeSeed, firstHits, startingState, traj.nLoops()>0 ? TrajectoryFitter::looper : TrajectoryFitter::standard);
95 
96  LogDebug("TransientInitialStateEstimator")
97  <<"using a backward fit of :"<<firstHits.size()<<" hits, starting from:\n"<<startingState
98  <<" to get the estimate of the initial state of the track.";
99 
100  if (!fitres.isValid()) {
101  LogDebug("TransientInitialStateEstimator")
102  << "FitTester: first hits fit failed!";
103  return std::pair<TrajectoryStateOnSurface, const GeomDet*>();
104  }
105 
106  TrajectoryMeasurement const & firstMeas = fitres.lastMeasurement();
107 
108  // magnetic field can be different!
109  TSOS firstState(firstMeas.updatedState().localParameters(),
110  firstMeas.updatedState().localError(),
111  firstMeas.updatedState().surface(),
113 
114 
115  // TSOS & firstState = const_cast<TSOS&>(firstMeas.updatedState());
116 
117  // this fails in case of zero field? (for sure for beamhalo reconstruction)
118  // assert(thePropagatorAlong->magneticField()==firstState.magneticField());
119 
120  firstState.rescaleError(100.);
121 
122  LogDebug("TransientInitialStateEstimator")
123  <<"the initial state is found to be:\n:"<<firstState
124  <<"\n it's field pointer is: "<<firstState.magneticField()
125  <<"\n the pointer from the state of the back fit was: "<<firstMeas.updatedState().magneticField();
126 
127 
128  return std::pair<TrajectoryStateOnSurface, const GeomDet*>( std::move(firstState),
129  firstMeas.recHit()->det());
130 }
131 
#define LogDebug(id)
ConstRecHitPointer const & recHit() const
PropagationDirection
#define nullptr
signed char nLoops() const
Definition: Trajectory.h:347
PropagationDirection const & direction() const
Definition: Trajectory.cc:140
DataContainer const & measurements() const
Definition: Trajectory.h:196
virtual const MagneticField * magneticField() const =0
void setEventSetup(const edm::EventSetup &es, const TkClonerImpl &hc)
TrajectoryMeasurement const & lastMeasurement() const
Definition: Trajectory.h:174
TrajectoryStateOnSurface const & forwardPredictedState() const
Access to forward predicted state (from fitter or builder)
std::vector< ConstRecHitPointer > ConstRecHitContainer
bool isValid() const
Definition: Trajectory.h:279
TrajectoryMeasurement const & firstMeasurement() const
Definition: Trajectory.h:187
T get() const
Definition: EventSetup.h:63
susybsm::HSCParticleCollection hc
Definition: classes.h:25
TransientInitialStateEstimator(const edm::ParameterSet &conf)
T const * product() const
Definition: ESHandle.h:86
std::pair< TrajectoryStateOnSurface, const GeomDet * > innerState(const Trajectory &traj, bool doBackFit=true) const
def move(src, dest)
Definition: eostools.py:510