CMS 3D CMS Logo

DualBzeroTrajectoryFactory.cc
Go to the documentation of this file.
8 
9 #include <algorithm>
10 
12 
14 
16 
17 
19 {
20 public:
22  ~DualBzeroTrajectoryFactory() override;
23 
27  const reco::BeamSpot &beamSpot) const override;
28 
30  const ConstTrajTrackPairCollection &tracks,
32  const reco::BeamSpot &beamSpot) const override;
33 
34  DualBzeroTrajectoryFactory* clone() const override { return new DualBzeroTrajectoryFactory(*this); }
35 
36 protected:
38  {
42  };
43 
45 
47  const Surface &surface,
48  const MagneticField *magField) const;
49 
50  double theMass;
52 
53 };
54 
58 
60  TrajectoryFactoryBase( config )
61 {
62  theMass = config.getParameter< double >( "ParticleMass" );
63  theMomentumEstimate = config.getParameter< double >( "MomentumEstimate" );
64 }
65 
66 
68 
69 
73  const reco::BeamSpot &beamSpot) const
74 {
76 
78  setup.get< IdealMagneticFieldRecord >().get( magneticField );
79 
80  ConstTrajTrackPairCollection::const_iterator itTracks = tracks.begin();
81 
82  while ( itTracks != tracks.end() )
83  {
84  const DualBzeroTrajectoryInput input = this->referenceStateAndRecHits( *itTracks );
85  // Check input: If all hits were rejected, the TSOS is initialized as invalid.
86  if ( input.refTsos.isValid() )
87  {
90  config.useBeamSpot = useBeamSpot_;
91  config.includeAPEs = includeAPEs_;
94  input.fwdRecHits,
95  input.bwdRecHits,
96  magneticField.product(),
97  beamSpot,
98  config));
99  trajectories.push_back( ptr );
100  }
101 
102  ++itTracks;
103  }
104 
105  return trajectories;
106 }
107 
112  const reco::BeamSpot &beamSpot) const
113 {
115 
116  if ( tracks.size() != external.size() )
117  {
118  edm::LogInfo("ReferenceTrajectories") << "@SUB=DualBzeroTrajectoryFactory::trajectories"
119  << "Inconsistent input:\n"
120  << "\tnumber of tracks = " << tracks.size()
121  << "\tnumber of external predictions = " << external.size();
122  return trajectories;
123  }
124 
126  setup.get< IdealMagneticFieldRecord >().get( magneticField );
127 
128  ConstTrajTrackPairCollection::const_iterator itTracks = tracks.begin();
129  ExternalPredictionCollection::const_iterator itExternal = external.begin();
130 
131  while ( itTracks != tracks.end() )
132  {
134  // Check input: If all hits were rejected, the TSOS is initialized as invalid.
135  if ( input.refTsos.isValid() )
136  {
137  if ( (*itExternal).isValid() )
138  {
139  TrajectoryStateOnSurface propExternal =
140  propagateExternal( *itExternal, input.refTsos.surface(), magneticField.product() );
141 
142  if ( !propExternal.isValid() ) continue;
143 
146  config.useBeamSpot = useBeamSpot_;
147  config.includeAPEs = includeAPEs_;
150  input.fwdRecHits,
151  input.bwdRecHits,
152  magneticField.product(),
153  beamSpot,
154  config));
155 
156  AlgebraicSymMatrix externalParamErrors( asHepMatrix<5>( propExternal.localError().matrix() ) );
157  ptr->setParameterErrors( externalParamErrors.sub( 2, 5 ) );
158  trajectories.push_back( ptr );
159  }
160  else
161  {
164  config.useBeamSpot = useBeamSpot_;
165  config.includeAPEs = includeAPEs_;
168  input.fwdRecHits,
169  input.bwdRecHits,
170  magneticField.product(),
171  beamSpot,
172  config));
173 
174  trajectories.push_back( ptr );
175  }
176  }
177 
178  ++itTracks;
179  ++itExternal;
180  }
181 
182  return trajectories;
183 }
184 
185 
188 {
190 
191  // get the trajectory measurements in the correct order, i.e. reverse if needed
192  Trajectory::DataContainer allTrajMeas = this->orderedTrajectoryMeasurements( *track.first );
193  Trajectory::DataContainer usedTrajMeas;
194  Trajectory::DataContainer::iterator itM;
195  // get all relevant trajectory measurements
196  for ( itM = allTrajMeas.begin(); itM != allTrajMeas.end(); itM++ )
197  {
198  if ( useRecHit( ( *itM ).recHit() ) ) usedTrajMeas.push_back( *itM );
199  }
200 
201  unsigned int iMeas = 0;
202  unsigned int nMeas = usedTrajMeas.size();
203  unsigned int nRefStateMeas = nMeas/2;
204  // get the valid RecHits
205  for ( itM = usedTrajMeas.begin(); itM != usedTrajMeas.end(); itM++, iMeas++ )
206  {
207  TransientTrackingRecHit::ConstRecHitPointer aRecHit = ( *itM ).recHit();
208 
209  if ( iMeas < nRefStateMeas ) {
210  input.bwdRecHits.push_back( aRecHit );
211  } else if ( iMeas > nRefStateMeas ) {
212  input.fwdRecHits.push_back( aRecHit );
213  } else { // iMeas == nRefStateMeas
214  if ( ( *itM ).updatedState().isValid() )
215  {
216  input.refTsos = ( *itM ).updatedState();
217  input.bwdRecHits.push_back( aRecHit );
218  input.fwdRecHits.push_back( aRecHit );
219  } else {
220  // if the tsos of the middle hit is not valid, try the next one ...
221  nRefStateMeas++;
222  input.bwdRecHits.push_back( aRecHit );
223  }
224  }
225  }
226 
227  // bring input.fwdRecHits into correct order
228  std::reverse( input.bwdRecHits.begin(), input.bwdRecHits.end() );
229 
230  return input;
231 }
232 
235  const Surface& surface,
236  const MagneticField* magField ) const
237 {
239  const std::pair< TrajectoryStateOnSurface, double > tsosWithPath =
240  propagator.propagateWithPath( external, surface );
241  return tsosWithPath.first;
242 }
243 
244 
T getParameter(std::string const &) const
const TrajectoryStateOnSurface propagateExternal(const TrajectoryStateOnSurface &external, const Surface &surface, const MagneticField *magField) const
TransientTrackingRecHit::ConstRecHitContainer bwdRecHits
MaterialEffects materialEffects(void) const
const DualBzeroTrajectoryInput referenceStateAndRecHits(const ConstTrajTrackPair &track) const
const ReferenceTrajectoryCollection trajectories(const edm::EventSetup &setup, const ConstTrajTrackPairCollection &tracks, const reco::BeamSpot &beamSpot) const override
Produce the reference trajectories.
virtual const Trajectory::DataContainer orderedTrajectoryMeasurements(const Trajectory &trajectory) const
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:1
AlignmentAlgorithmBase::ConstTrajTrackPair ConstTrajTrackPair
Definition: config.py:1
bool useRecHit(const TransientTrackingRecHit::ConstRecHitPointer &hitPtr) const
static std::string const input
Definition: EdmProvDump.cc:44
const SurfaceType & surface() const
std::vector< TrajectoryMeasurement > DataContainer
Definition: Trajectory.h:44
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
const AlgebraicSymMatrix55 & matrix() const
const LocalTrajectoryError & localError() const
std::vector< ConstRecHitPointer > ConstRecHitContainer
AlignmentAlgorithmBase::ConstTrajTrackPairCollection ConstTrajTrackPairCollection
DualBzeroTrajectoryFactory * clone() const override
std::vector< ReferenceTrajectoryPtr > ReferenceTrajectoryCollection
const T & get() const
Definition: EventSetup.h:55
PropagationDirection propagationDirection(void) const
CLHEP::HepSymMatrix AlgebraicSymMatrix
A factory that produces instances of class ReferenceTrajectory from a given TrajTrackPairCollection.
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::vector< TrajectoryStateOnSurface > ExternalPredictionCollection
TransientTrackingRecHit::ConstRecHitContainer fwdRecHits
T const * product() const
Definition: ESHandle.h:86
DualBzeroTrajectoryFactory(const edm::ParameterSet &config)
std::pair< TrajectoryStateOnSurface, double > propagateWithPath(const FreeTrajectoryState &fts, const Plane &plane) const override
propagation to plane with path length