CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DualKalmanFactory.cc
Go to the documentation of this file.
1 
17 
24 // #include "TrackingTools/GeomPropagators/interface/AnalyticalPropagator.h"
26 
28 
29 #include <algorithm>
30 
31 
33 {
34 
35 public:
36 
38  virtual ~DualKalmanFactory();
39 
41  virtual const ReferenceTrajectoryCollection
43  const reco::BeamSpot &beamSpot) const;
44 
45  virtual const ReferenceTrajectoryCollection
46  trajectories(const edm::EventSetup &setup, const ConstTrajTrackPairCollection &tracks,
47  const ExternalPredictionCollection &external, const reco::BeamSpot &beamSpot) const;
48 
49  virtual DualKalmanFactory* clone() const { return new DualKalmanFactory(*this); }
50 
51 protected:
52 
54  {
57  std::vector<unsigned int> fwdRecHitNums;
58  std::vector<unsigned int> bwdRecHitNums;
59  };
60 
62 
63 // const TrajectoryStateOnSurface propagateExternal(const TrajectoryStateOnSurface &external,
64 // const Surface &surface,
65 // const MagneticField *magField) const;
66 
67  const double theMass;
68  const int theResidMethod;
69 };
70 
71 
72 //-----------------------------------------------------------------------------------------------
73 //-----------------------------------------------------------------------------------------------
74 //-----------------------------------------------------------------------------------------------
76  : TrajectoryFactoryBase(config), theMass(config.getParameter<double>("ParticleMass")),
77  theResidMethod(config.getParameter<int>("ResidualMethod"))
78 {
79  // Since theResidMethod is passed to DualKalmanTrajectory, valid values are checked there.
80  edm::LogInfo("Alignment") << "@SUB=DualKalmanFactory" << "Factory created.";
81 }
82 
83 
84 //-----------------------------------------------------------------------------------------------
86 
87 
88 //-----------------------------------------------------------------------------------------------
92  const reco::BeamSpot &beamSpot) const
93 {
95 
96  edm::ESHandle<MagneticField> magneticField;
97  setup.get<IdealMagneticFieldRecord>().get(magneticField);
98 
99  ConstTrajTrackPairCollection::const_iterator itTracks = tracks.begin();
100 
101  while (itTracks != tracks.end()) {
102  const DualKalmanInput input = this->referenceStateAndRecHits(*itTracks);
103  // Check input: If all hits were rejected, the TSOS is initialized as invalid.
104  if (input.refTsos.isValid()) {
106  input.refTsos,
107  input.fwdRecHitNums,
108  input.bwdRecHitNums,
109  magneticField.product(),
110  this->materialEffects(),
111  this->propagationDirection(),
113  theResidMethod));
114  trajectories.push_back(ptr);
115  }
116  ++itTracks;
117  }
118 
119  return trajectories;
120 }
121 
122 //-----------------------------------------------------------------------------------------------
126  const ExternalPredictionCollection &external,
127  const reco::BeamSpot &beamSpot) const
128 {
130 
131  edm::LogError("Alignment") << "@SUB=DualKalmanFactory::trajectories"
132  << "Not implemented with ExternalPrediction.";
133  return trajectories;
134 
135  // copy paste from DualTrajectoryFactory:
136  if (tracks.size() != external.size()) {
137  edm::LogInfo("ReferenceTrajectories") << "@SUB=DualKalmanFactory::trajectories"
138  << "Inconsistent input:\n"
139  << "\tnumber of tracks = " << tracks.size()
140  << "\tnumber of external predictions = " << external.size();
141  return trajectories;
142  }
143  /*
144  edm::ESHandle<MagneticField> magneticField;
145  setup.get<IdealMagneticFieldRecord>().get(magneticField);
146 
147  ConstTrajTrackPairCollection::const_iterator itTracks = tracks.begin();
148  ExternalPredictionCollection::const_iterator itExternal = external.begin();
149 
150  while (itTracks != tracks.end()) {
151  const DualKalmanInput input = this->referenceStateAndRecHits(*itTracks);
152  // Check input: If all hits were rejected, the TSOS is initialized as invalid.
153  if (input.refTsos.isValid()) {
154  if ((*itExternal).isValid()) {
155  TrajectoryStateOnSurface propExternal =
156  this->propagateExternal(*itExternal, input.refTsos.surface(), magneticField.product());
157  if (!propExternal.isValid()) continue;
158 
159  // set the flag for reversing the RecHits to false, since they are already in the correct order.
160  ReferenceTrajectoryPtr ptr(new DualKalmanTrajectory(propExternal,
161  input.fwdRecHits,
162  input.bwdRecHits,
163  magneticField.product(),
164  materialEffects(),
165  propagationDirection(),
166  theMass, theResidMethod));
167 
168  AlgebraicSymMatrix externalParamErrors(asHepMatrix<5>(propExternal.localError().matrix()));
169  ptr->setParameterErrors(externalParamErrors);
170  trajectories.push_back(ptr);
171  } else {
172  ReferenceTrajectoryPtr ptr(new DualKalmanTrajectory(input.refTsos,
173  input.fwdRecHits,
174  input.bwdRecHits,
175  magneticField.product(),
176  materialEffects(),
177  propagationDirection(),
178  theMass, theResidMethod));
179  trajectories.push_back(ptr);
180  }
181  }
182 
183  ++itTracks;
184  ++itExternal;
185  }
186  */
187 
188  return trajectories;
189 }
190 
191 
192 //-----------------------------------------------------------------------------------------------
195 {
196  // Same idea as in DualTrajectoryFactory::referenceStateAndRecHits(..):
197  // Split trajectory in the middle, take middle as reference and provide first
198  // and second half of hits, each starting from this middle hit.
199  // In contrast to DualTrajectoryFactory we deal here with indices and not rechits directly
200  // to be able to get measurements and uncertainties later from the Trajectory that is
201  // provided by the Kalman track fit.
202 
204 
205  // get the trajectory measurements in the correct order, i.e. reverse if needed
206  input.trajMeasurements = this->orderedTrajectoryMeasurements(*track.first);
207 
208  // get indices of relevant trajectory measurements to find middle of them
209  std::vector<unsigned int> usedTrajMeasNums;
210  for (unsigned int iM = 0; iM < input.trajMeasurements.size(); ++iM) {
211  if (this->useRecHit(input.trajMeasurements[iM].recHit())) usedTrajMeasNums.push_back(iM);
212  }
213  unsigned int nRefStateMeas = usedTrajMeasNums.size()/2;
214 
215  // get the valid RecHits numbers
216  for (unsigned int iMeas = 0; iMeas < usedTrajMeasNums.size(); ++iMeas) {
217  if (iMeas < nRefStateMeas) {
218  input.bwdRecHitNums.push_back(usedTrajMeasNums[iMeas]);
219  } else if (iMeas > nRefStateMeas) {
220  input.fwdRecHitNums.push_back(usedTrajMeasNums[iMeas]);
221  } else { // iMeas == nRefStateMeas
222  if (input.trajMeasurements[usedTrajMeasNums[iMeas]].updatedState().isValid()) {
223  input.refTsos = input.trajMeasurements[usedTrajMeasNums[iMeas]].updatedState();
224  input.bwdRecHitNums.push_back(usedTrajMeasNums[iMeas]);
225  input.fwdRecHitNums.push_back(usedTrajMeasNums[iMeas]);
226  } else {
227  // if the hit/tsos of the middle hit is not valid, try the next one...
228  ++nRefStateMeas; // but keep hit if only TSOS bad
229  input.bwdRecHitNums.push_back(usedTrajMeasNums[iMeas]);
230  }
231  }
232  }
233 
234  // bring input.fwdRecHits into correct order
235  std::reverse(input.bwdRecHitNums.begin(), input.bwdRecHitNums.end());
236 
237  return input;
238 }
239 
240 // //-----------------------------------------------------------------------------------------------
241 // const TrajectoryStateOnSurface
242 // DualKalmanFactory::propagateExternal(const TrajectoryStateOnSurface &external,
243 // const Surface &surface,
244 // const MagneticField *magField) const
245 // {
246 // AnalyticalPropagator propagator(magField, anyDirection);
247 // const std::pair<TrajectoryStateOnSurface, double> tsosWithPath =
248 // propagator.propagateWithPath(external, surface);
249 // return tsosWithPath.first;
250 //}
251 
252 
std::vector< unsigned int > fwdRecHitNums
virtual const Trajectory::DataContainer orderedTrajectoryMeasurements(const Trajectory &trajectory) const
AlignmentAlgorithmBase::ConstTrajTrackPair ConstTrajTrackPair
virtual const ReferenceTrajectoryCollection trajectories(const edm::EventSetup &setup, const ConstTrajTrackPairCollection &tracks, const reco::BeamSpot &beamSpot) const
Produce the reference trajectories.
bool useRecHit(const TransientTrackingRecHit::ConstRecHitPointer &hitPtr) const
Trajectory::DataContainer trajMeasurements
std::vector< unsigned int > bwdRecHitNums
std::vector< TrajectoryMeasurement > DataContainer
Definition: Trajectory.h:42
const MaterialEffects materialEffects(void) const
virtual DualKalmanFactory * clone() const
tuple input
Definition: collect_tpl.py:10
AlignmentAlgorithmBase::ConstTrajTrackPairCollection ConstTrajTrackPairCollection
virtual ~DualKalmanFactory()
std::vector< ReferenceTrajectoryPtr > ReferenceTrajectoryCollection
tuple tracks
Definition: testEve_cfg.py:39
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
TrajectoryStateOnSurface refTsos
DualKalmanFactory(const edm::ParameterSet &config)
tuple config
Definition: cmsDriver.py:17
const PropagationDirection propagationDirection(void) const
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::vector< TrajectoryStateOnSurface > ExternalPredictionCollection
const DualKalmanInput referenceStateAndRecHits(const ConstTrajTrackPair &track) const