CMS 3D CMS Logo

DualTrajectoryFactory.cc
Go to the documentation of this file.
9 
10 #include <algorithm>
11 
14 
16 
17 
19 {
20 public:
22  ~DualTrajectoryFactory() override;
23 
27  const reco::BeamSpot &beamSpot) const override;
28 
30  const ConstTrajTrackPairCollection &tracks,
32  const reco::BeamSpot &beamSpot) const override;
33 
34  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_;
98  input.fwdRecHits,
99  input.bwdRecHits,
100  magneticField.product(),
101  beamSpot,
102  config));
103  trajectories.push_back( ptr );
104  }
105 
106  ++itTracks;
107  }
108 
109  return trajectories;
110 }
111 
116  const reco::BeamSpot &beamSpot) const
117 {
119 
120  if ( tracks.size() != external.size() )
121  {
122  edm::LogInfo("ReferenceTrajectories") << "@SUB=DualTrajectoryFactory::trajectories"
123  << "Inconsistent input:\n"
124  << "\tnumber of tracks = " << tracks.size()
125  << "\tnumber of external predictions = " << external.size();
126  return trajectories;
127  }
128 
130  setup.get< IdealMagneticFieldRecord >().get( magneticField );
131  if (magneticField->inTesla(GlobalPoint(0.,0.,0.)).mag2() < 1.e-6) {
132  edm::LogWarning("Alignment") << "@SUB=DualTrajectoryFactory::trajectories"
133  << "B-field in z is " << magneticField->inTesla(GlobalPoint(0.,0.,0.)).z()
134  << ": You should probably use the DualBzeroTrajectoryFactory\n"
135  << "or fix this code to switch automatically as the ReferenceTrajectoryFactory does.";
136  }
137 
138  ConstTrajTrackPairCollection::const_iterator itTracks = tracks.begin();
139  ExternalPredictionCollection::const_iterator itExternal = external.begin();
140 
141  while ( itTracks != tracks.end() )
142  {
144  // Check input: If all hits were rejected, the TSOS is initialized as invalid.
145  if ( input.refTsos.isValid() )
146  {
147  if ( (*itExternal).isValid() )
148  {
149  TrajectoryStateOnSurface propExternal =
150  propagateExternal( *itExternal, input.refTsos.surface(), magneticField.product() );
151 
152  if ( !propExternal.isValid() ) continue;
153 
155  config.useBeamSpot = useBeamSpot_;
156  config.includeAPEs = includeAPEs_;
158  ReferenceTrajectoryPtr ptr(new DualReferenceTrajectory(propExternal,
159  input.fwdRecHits,
160  input.bwdRecHits,
161  magneticField.product(),
162  beamSpot,
163  config));
164 
165  AlgebraicSymMatrix externalParamErrors( asHepMatrix<5>( propExternal.localError().matrix() ) );
166  ptr->setParameterErrors( externalParamErrors );
167  trajectories.push_back( ptr );
168  }
169  else
170  {
172  config.useBeamSpot = useBeamSpot_;
173  config.includeAPEs = includeAPEs_;
176  input.fwdRecHits,
177  input.bwdRecHits,
178  magneticField.product(),
179  beamSpot,
180  config));
181  trajectories.push_back( ptr );
182  }
183  }
184 
185  ++itTracks;
186  ++itExternal;
187  }
188 
189  return trajectories;
190 }
191 
192 
195 {
197 
198  // get the trajectory measurements in the correct order, i.e. reverse if needed
199  Trajectory::DataContainer allTrajMeas = this->orderedTrajectoryMeasurements( *track.first );
200  Trajectory::DataContainer usedTrajMeas;
201  Trajectory::DataContainer::iterator itM;
202  // get all relevant trajectory measurements
203  for ( itM = allTrajMeas.begin(); itM != allTrajMeas.end(); itM++ )
204  {
205  if ( useRecHit( ( *itM ).recHit() ) ) usedTrajMeas.push_back( *itM );
206  }
207 
208  unsigned int iMeas = 0;
209  unsigned int nMeas = usedTrajMeas.size();
210  unsigned int nRefStateMeas = nMeas/2;
211  // get the valid RecHits
212  for ( itM = usedTrajMeas.begin(); itM != usedTrajMeas.end(); itM++, iMeas++ )
213  {
214  TransientTrackingRecHit::ConstRecHitPointer aRecHit = ( *itM ).recHit();
215 
216  if ( iMeas < nRefStateMeas ) {
217  input.bwdRecHits.push_back( aRecHit );
218  } else if ( iMeas > nRefStateMeas ) {
219  input.fwdRecHits.push_back( aRecHit );
220  } else { // iMeas == nRefStateMeas
221  if ( ( *itM ).updatedState().isValid() )
222  {
223  input.refTsos = ( *itM ).updatedState();
224  input.bwdRecHits.push_back( aRecHit );
225  input.fwdRecHits.push_back( aRecHit );
226  } else {
227  // if the tsos of the middle hit is not valid, try the next one ...
228  nRefStateMeas++;
229  input.bwdRecHits.push_back( aRecHit );
230  }
231  }
232  }
233 
234  // bring input.fwdRecHits into correct order
235  std::reverse( input.bwdRecHits.begin(), input.bwdRecHits.end() );
236 
237  return input;
238 }
239 
242  const Surface& surface,
243  const MagneticField* magField ) const
244 {
246  const std::pair< TrajectoryStateOnSurface, double > tsosWithPath =
247  propagator.propagateWithPath( external, surface );
248  return tsosWithPath.first;
249 }
250 
251 
T mag2() const
Definition: PV3DBase.h:66
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
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
config
Definition: looper.py:287
TransientTrackingRecHit::ConstRecHitContainer fwdRecHits
const ReferenceTrajectoryCollection trajectories(const edm::EventSetup &setup, const ConstTrajTrackPairCollection &tracks, const reco::BeamSpot &beamSpot) const override
Produce the reference trajectories.
const SurfaceType & surface() const
std::vector< TrajectoryMeasurement > DataContainer
Definition: Trajectory.h:44
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
T z() const
Definition: PV3DBase.h:64
const AlgebraicSymMatrix55 & matrix() const
const LocalTrajectoryError & localError() const
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
std::vector< ConstRecHitPointer > ConstRecHitContainer
DualTrajectoryFactory(const edm::ParameterSet &config)
AlignmentAlgorithmBase::ConstTrajTrackPairCollection ConstTrajTrackPairCollection
std::vector< ReferenceTrajectoryPtr > ReferenceTrajectoryCollection
const T & get() const
Definition: EventSetup.h:55
TransientTrackingRecHit::ConstRecHitContainer bwdRecHits
DualTrajectoryFactory * clone() const override
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.
T const * product() const
Definition: ESHandle.h:86
std::pair< TrajectoryStateOnSurface, double > propagateWithPath(const FreeTrajectoryState &fts, const Plane &plane) const override
propagation to plane with path length