CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DualTrajectoryFactory.cc
Go to the documentation of this file.
9 
10 #include <algorithm>
11 
14 
16 
17 
19 {
20 public:
22  virtual ~DualTrajectoryFactory();
23 
27  const reco::BeamSpot &beamSpot) const override;
28 
30  const ConstTrajTrackPairCollection &tracks,
31  const ExternalPredictionCollection &external,
32  const reco::BeamSpot &beamSpot) const override;
33 
34  virtual DualTrajectoryFactory* clone() const override { return new DualTrajectoryFactory(*this); }
35 
36 protected:
38  {
42  };
43 
45 
47  const Surface &surface,
48  const MagneticField *magField) const;
49 
50  double theMass;
51 };
52 
56 
58  TrajectoryFactoryBase( config ),
59  theMass(config.getParameter<double>("ParticleMass"))
60 {
61  edm::LogInfo("Alignment") << "@SUB=DualTrajectoryFactory"
62  << "mass: " << theMass;
63 }
64 
65 
67 
68 
72  const reco::BeamSpot &beamSpot) const
73 {
75 
77  setup.get< IdealMagneticFieldRecord >().get( magneticField );
78  if (magneticField->inTesla(GlobalPoint(0.,0.,0.)).mag2() < 1.e-6) {
79  edm::LogWarning("Alignment") << "@SUB=DualTrajectoryFactory::trajectories"
80  << "B-field in z is " << magneticField->inTesla(GlobalPoint(0.,0.,0.)).z()
81  << ": You should probably use the DualBzeroTrajectoryFactory\n"
82  << "or fix this code to switch automatically as the ReferenceTrajectoryFactory does.";
83  }
84 
85  ConstTrajTrackPairCollection::const_iterator itTracks = tracks.begin();
86 
87  while ( itTracks != tracks.end() )
88  {
89  const DualTrajectoryInput input = this->referenceStateAndRecHits( *itTracks );
90  // Check input: If all hits were rejected, the TSOS is initialized as invalid.
91  if ( input.refTsos.isValid() )
92  {
94  config.useBeamSpot = useBeamSpot_;
95  config.includeAPEs = includeAPEs_;
97  input.fwdRecHits,
98  input.bwdRecHits,
99  magneticField.product(),
100  beamSpot,
101  config));
102  trajectories.push_back( ptr );
103  }
104 
105  ++itTracks;
106  }
107 
108  return trajectories;
109 }
110 
114  const ExternalPredictionCollection &external,
115  const reco::BeamSpot &beamSpot) const
116 {
118 
119  if ( tracks.size() != external.size() )
120  {
121  edm::LogInfo("ReferenceTrajectories") << "@SUB=DualTrajectoryFactory::trajectories"
122  << "Inconsistent input:\n"
123  << "\tnumber of tracks = " << tracks.size()
124  << "\tnumber of external predictions = " << external.size();
125  return trajectories;
126  }
127 
129  setup.get< IdealMagneticFieldRecord >().get( magneticField );
130  if (magneticField->inTesla(GlobalPoint(0.,0.,0.)).mag2() < 1.e-6) {
131  edm::LogWarning("Alignment") << "@SUB=DualTrajectoryFactory::trajectories"
132  << "B-field in z is " << magneticField->inTesla(GlobalPoint(0.,0.,0.)).z()
133  << ": You should probably use the DualBzeroTrajectoryFactory\n"
134  << "or fix this code to switch automatically as the ReferenceTrajectoryFactory does.";
135  }
136 
137  ConstTrajTrackPairCollection::const_iterator itTracks = tracks.begin();
138  ExternalPredictionCollection::const_iterator itExternal = external.begin();
139 
140  while ( itTracks != tracks.end() )
141  {
143  // Check input: If all hits were rejected, the TSOS is initialized as invalid.
144  if ( input.refTsos.isValid() )
145  {
146  if ( (*itExternal).isValid() )
147  {
148  TrajectoryStateOnSurface propExternal =
149  propagateExternal( *itExternal, input.refTsos.surface(), magneticField.product() );
150 
151  if ( !propExternal.isValid() ) continue;
152 
154  config.useBeamSpot = useBeamSpot_;
155  config.includeAPEs = includeAPEs_;
156  ReferenceTrajectoryPtr ptr(new DualReferenceTrajectory(propExternal,
157  input.fwdRecHits,
158  input.bwdRecHits,
159  magneticField.product(),
160  beamSpot,
161  config));
162 
163  AlgebraicSymMatrix externalParamErrors( asHepMatrix<5>( propExternal.localError().matrix() ) );
164  ptr->setParameterErrors( externalParamErrors );
165  trajectories.push_back( ptr );
166  }
167  else
168  {
170  config.useBeamSpot = useBeamSpot_;
171  config.includeAPEs = includeAPEs_;
173  input.fwdRecHits,
174  input.bwdRecHits,
175  magneticField.product(),
176  beamSpot,
177  config));
178  trajectories.push_back( ptr );
179  }
180  }
181 
182  ++itTracks;
183  ++itExternal;
184  }
185 
186  return trajectories;
187 }
188 
189 
192 {
194 
195  // get the trajectory measurements in the correct order, i.e. reverse if needed
196  Trajectory::DataContainer allTrajMeas = this->orderedTrajectoryMeasurements( *track.first );
197  Trajectory::DataContainer usedTrajMeas;
198  Trajectory::DataContainer::iterator itM;
199  // get all relevant trajectory measurements
200  for ( itM = allTrajMeas.begin(); itM != allTrajMeas.end(); itM++ )
201  {
202  if ( useRecHit( ( *itM ).recHit() ) ) usedTrajMeas.push_back( *itM );
203  }
204 
205  unsigned int iMeas = 0;
206  unsigned int nMeas = usedTrajMeas.size();
207  unsigned int nRefStateMeas = nMeas/2;
208  // get the valid RecHits
209  for ( itM = usedTrajMeas.begin(); itM != usedTrajMeas.end(); itM++, iMeas++ )
210  {
211  TransientTrackingRecHit::ConstRecHitPointer aRecHit = ( *itM ).recHit();
212 
213  if ( iMeas < nRefStateMeas ) {
214  input.bwdRecHits.push_back( aRecHit );
215  } else if ( iMeas > nRefStateMeas ) {
216  input.fwdRecHits.push_back( aRecHit );
217  } else { // iMeas == nRefStateMeas
218  if ( ( *itM ).updatedState().isValid() )
219  {
220  input.refTsos = ( *itM ).updatedState();
221  input.bwdRecHits.push_back( aRecHit );
222  input.fwdRecHits.push_back( aRecHit );
223  } else {
224  // if the tsos of the middle hit is not valid, try the next one ...
225  nRefStateMeas++;
226  input.bwdRecHits.push_back( aRecHit );
227  }
228  }
229  }
230 
231  // bring input.fwdRecHits into correct order
232  std::reverse( input.bwdRecHits.begin(), input.bwdRecHits.end() );
233 
234  return input;
235 }
236 
239  const Surface& surface,
240  const MagneticField* magField ) const
241 {
243  const std::pair< TrajectoryStateOnSurface, double > tsosWithPath =
244  propagator.propagateWithPath( external, surface );
245  return tsosWithPath.first;
246 }
247 
248 
const TrajectoryStateOnSurface propagateExternal(const TrajectoryStateOnSurface &external, const Surface &surface, const MagneticField *magField) const
const DualTrajectoryInput referenceStateAndRecHits(const ConstTrajTrackPair &track) const
MaterialEffects materialEffects(void) const
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
virtual const Trajectory::DataContainer orderedTrajectoryMeasurements(const Trajectory &trajectory) const
AlignmentAlgorithmBase::ConstTrajTrackPair ConstTrajTrackPair
bool useRecHit(const TransientTrackingRecHit::ConstRecHitPointer &hitPtr) const
std::pair< TrajectoryStateOnSurface, double > propagateWithPath(const FreeTrajectoryState &fts, const Plane &plane) const override
propagation to plane with path length
static std::string const input
Definition: EdmProvDump.cc:44
TransientTrackingRecHit::ConstRecHitContainer fwdRecHits
const SurfaceType & surface() const
std::vector< TrajectoryMeasurement > DataContainer
Definition: Trajectory.h:44
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
virtual DualTrajectoryFactory * clone() const override
const AlgebraicSymMatrix55 & matrix() const
const LocalTrajectoryError & localError() const
std::vector< ConstRecHitPointer > ConstRecHitContainer
DualTrajectoryFactory(const edm::ParameterSet &config)
virtual const ReferenceTrajectoryCollection trajectories(const edm::EventSetup &setup, const ConstTrajTrackPairCollection &tracks, const reco::BeamSpot &beamSpot) const override
Produce the reference trajectories.
AlignmentAlgorithmBase::ConstTrajTrackPairCollection ConstTrajTrackPairCollection
std::vector< ReferenceTrajectoryPtr > ReferenceTrajectoryCollection
tuple tracks
Definition: testEve_cfg.py:39
const T & get() const
Definition: EventSetup.h:56
TransientTrackingRecHit::ConstRecHitContainer bwdRecHits
T const * product() const
Definition: ESHandle.h:86
PropagationDirection propagationDirection(void) const
CLHEP::HepSymMatrix AlgebraicSymMatrix
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::vector< TrajectoryStateOnSurface > ExternalPredictionCollection
A factory that produces instances of class ReferenceTrajectory from a given TrajTrackPairCollection.