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 
136 
137 //-----------------------------------------------------------------------------------------------
140 {
141  // Same idea as in DualTrajectoryFactory::referenceStateAndRecHits(..):
142  // Split trajectory in the middle, take middle as reference and provide first
143  // and second half of hits, each starting from this middle hit.
144  // In contrast to DualTrajectoryFactory we deal here with indices and not rechits directly
145  // to be able to get measurements and uncertainties later from the Trajectory that is
146  // provided by the Kalman track fit.
147 
149 
150  // get the trajectory measurements in the correct order, i.e. reverse if needed
151  input.trajMeasurements = this->orderedTrajectoryMeasurements(*track.first);
152 
153  // get indices of relevant trajectory measurements to find middle of them
154  std::vector<unsigned int> usedTrajMeasNums;
155  for (unsigned int iM = 0; iM < input.trajMeasurements.size(); ++iM) {
156  if (this->useRecHit(input.trajMeasurements[iM].recHit())) usedTrajMeasNums.push_back(iM);
157  }
158  unsigned int nRefStateMeas = usedTrajMeasNums.size()/2;
159 
160  // get the valid RecHits numbers
161  for (unsigned int iMeas = 0; iMeas < usedTrajMeasNums.size(); ++iMeas) {
162  if (iMeas < nRefStateMeas) {
163  input.bwdRecHitNums.push_back(usedTrajMeasNums[iMeas]);
164  } else if (iMeas > nRefStateMeas) {
165  input.fwdRecHitNums.push_back(usedTrajMeasNums[iMeas]);
166  } else { // iMeas == nRefStateMeas
167  if (input.trajMeasurements[usedTrajMeasNums[iMeas]].updatedState().isValid()) {
168  input.refTsos = input.trajMeasurements[usedTrajMeasNums[iMeas]].updatedState();
169  input.bwdRecHitNums.push_back(usedTrajMeasNums[iMeas]);
170  input.fwdRecHitNums.push_back(usedTrajMeasNums[iMeas]);
171  } else {
172  // if the hit/tsos of the middle hit is not valid, try the next one...
173  ++nRefStateMeas; // but keep hit if only TSOS bad
174  input.bwdRecHitNums.push_back(usedTrajMeasNums[iMeas]);
175  }
176  }
177  }
178 
179  // bring input.fwdRecHits into correct order
180  std::reverse(input.bwdRecHitNums.begin(), input.bwdRecHitNums.end());
181 
182  return input;
183 }
184 
185 // //-----------------------------------------------------------------------------------------------
186 // const TrajectoryStateOnSurface
187 // DualKalmanFactory::propagateExternal(const TrajectoryStateOnSurface &external,
188 // const Surface &surface,
189 // const MagneticField *magField) const
190 // {
191 // AnalyticalPropagator propagator(magField, anyDirection);
192 // const std::pair<TrajectoryStateOnSurface, double> tsosWithPath =
193 // propagator.propagateWithPath(external, surface);
194 // return tsosWithPath.first;
195 //}
196 
197 
std::vector< unsigned int > fwdRecHitNums
MaterialEffects materialEffects(void) const
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
virtual DualKalmanFactory * clone() const
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)
PropagationDirection propagationDirection(void) const
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::vector< TrajectoryStateOnSurface > ExternalPredictionCollection
const DualKalmanInput referenceStateAndRecHits(const ConstTrajTrackPair &track) const
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")