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.
8 
9 #include <algorithm>
10 
13 
15 
16 
18 {
19 public:
21  virtual ~DualTrajectoryFactory();
22 
26  const reco::BeamSpot &beamSpot) const;
27 
29  const ConstTrajTrackPairCollection &tracks,
30  const ExternalPredictionCollection &external,
31  const reco::BeamSpot &beamSpot) const;
32 
33  virtual DualTrajectoryFactory* clone() const { return new DualTrajectoryFactory(*this); }
34 
35 protected:
37  {
41  };
42 
44 
46  const Surface &surface,
47  const MagneticField *magField) const;
48 
49  double theMass;
50 };
51 
55 
57  TrajectoryFactoryBase( config )
58 {
59  theMass = config.getParameter< double >( "ParticleMass" );
60 }
61 
62 
64 
65 
69  const reco::BeamSpot &beamSpot) const
70 {
72 
73  edm::ESHandle< MagneticField > magneticField;
74  setup.get< IdealMagneticFieldRecord >().get( magneticField );
75 
76  ConstTrajTrackPairCollection::const_iterator itTracks = tracks.begin();
77 
78  while ( itTracks != tracks.end() )
79  {
80  const DualTrajectoryInput input = this->referenceStateAndRecHits( *itTracks );
81  // Check input: If all hits were rejected, the TSOS is initialized as invalid.
82  if ( input.refTsos.isValid() )
83  {
85  input.fwdRecHits,
86  input.bwdRecHits,
87  magneticField.product(),
90  theMass,
92  trajectories.push_back( ptr );
93  }
94 
95  ++itTracks;
96  }
97 
98  return trajectories;
99 }
100 
104  const ExternalPredictionCollection &external,
105  const reco::BeamSpot &beamSpot) const
106 {
108 
109  if ( tracks.size() != external.size() )
110  {
111  edm::LogInfo("ReferenceTrajectories") << "@SUB=DualTrajectoryFactory::trajectories"
112  << "Inconsistent input:\n"
113  << "\tnumber of tracks = " << tracks.size()
114  << "\tnumber of external predictions = " << external.size();
115  return trajectories;
116  }
117 
118  edm::ESHandle< MagneticField > magneticField;
119  setup.get< IdealMagneticFieldRecord >().get( magneticField );
120 
121  ConstTrajTrackPairCollection::const_iterator itTracks = tracks.begin();
122  ExternalPredictionCollection::const_iterator itExternal = external.begin();
123 
124  while ( itTracks != tracks.end() )
125  {
127  // Check input: If all hits were rejected, the TSOS is initialized as invalid.
128  if ( input.refTsos.isValid() )
129  {
130  if ( (*itExternal).isValid() )
131  {
132  TrajectoryStateOnSurface propExternal =
133  propagateExternal( *itExternal, input.refTsos.surface(), magneticField.product() );
134 
135  if ( !propExternal.isValid() ) continue;
136 
137  // set the flag for reversing the RecHits to false, since they are already in the correct order.
138  ReferenceTrajectoryPtr ptr( new DualReferenceTrajectory( propExternal,
139  input.fwdRecHits,
140  input.bwdRecHits,
141  magneticField.product(),
142  materialEffects(),
144  theMass,
146 
147  AlgebraicSymMatrix externalParamErrors( asHepMatrix<5>( propExternal.localError().matrix() ) );
148  ptr->setParameterErrors( externalParamErrors );
149  trajectories.push_back( ptr );
150  }
151  else
152  {
154  input.fwdRecHits,
155  input.bwdRecHits,
156  magneticField.product(),
157  materialEffects(),
159  theMass,
161  trajectories.push_back( ptr );
162  }
163  }
164 
165  ++itTracks;
166  ++itExternal;
167  }
168 
169  return trajectories;
170 }
171 
172 
175 {
177 
178  // get the trajectory measurements in the correct order, i.e. reverse if needed
179  Trajectory::DataContainer allTrajMeas = this->orderedTrajectoryMeasurements( *track.first );
180  Trajectory::DataContainer usedTrajMeas;
181  Trajectory::DataContainer::iterator itM;
182  // get all relevant trajectory measurements
183  for ( itM = allTrajMeas.begin(); itM != allTrajMeas.end(); itM++ )
184  {
185  if ( useRecHit( ( *itM ).recHit() ) ) usedTrajMeas.push_back( *itM );
186  }
187 
188  unsigned int iMeas = 0;
189  unsigned int nMeas = usedTrajMeas.size();
190  unsigned int nRefStateMeas = nMeas/2;
191  // get the valid RecHits
192  for ( itM = usedTrajMeas.begin(); itM != usedTrajMeas.end(); itM++, iMeas++ )
193  {
194  TransientTrackingRecHit::ConstRecHitPointer aRecHit = ( *itM ).recHit();
195 
196  if ( iMeas < nRefStateMeas ) {
197  input.bwdRecHits.push_back( aRecHit );
198  } else if ( iMeas > nRefStateMeas ) {
199  input.fwdRecHits.push_back( aRecHit );
200  } else { // iMeas == nRefStateMeas
201  if ( ( *itM ).updatedState().isValid() )
202  {
203  input.refTsos = ( *itM ).updatedState();
204  input.bwdRecHits.push_back( aRecHit );
205  input.fwdRecHits.push_back( aRecHit );
206  } else {
207  // if the tsos of the middle hit is not valid, try the next one ...
208  nRefStateMeas++;
209  input.bwdRecHits.push_back( aRecHit );
210  }
211  }
212  }
213 
214  // bring input.fwdRecHits into correct order
215  std::reverse( input.bwdRecHits.begin(), input.bwdRecHits.end() );
216 
217  return input;
218 }
219 
222  const Surface& surface,
223  const MagneticField* magField ) const
224 {
226  const std::pair< TrajectoryStateOnSurface, double > tsosWithPath =
227  propagator.propagateWithPath( external, surface );
228  return tsosWithPath.first;
229 }
230 
231 
T getParameter(std::string const &) const
const TrajectoryStateOnSurface propagateExternal(const TrajectoryStateOnSurface &external, const Surface &surface, const MagneticField *magField) const
const DualTrajectoryInput referenceStateAndRecHits(const ConstTrajTrackPair &track) const
MaterialEffects materialEffects(void) const
virtual const Trajectory::DataContainer orderedTrajectoryMeasurements(const Trajectory &trajectory) const
AlignmentAlgorithmBase::ConstTrajTrackPair ConstTrajTrackPair
bool useRecHit(const TransientTrackingRecHit::ConstRecHitPointer &hitPtr) const
virtual const ReferenceTrajectoryCollection trajectories(const edm::EventSetup &setup, const ConstTrajTrackPairCollection &tracks, const reco::BeamSpot &beamSpot) const
Produce the reference trajectories.
TransientTrackingRecHit::ConstRecHitContainer fwdRecHits
std::vector< TrajectoryMeasurement > DataContainer
Definition: Trajectory.h:42
std::pair< TrajectoryStateOnSurface, double > propagateWithPath(const FreeTrajectoryState &fts, const Plane &plane) const
propagation to plane with path length
const AlgebraicSymMatrix55 & matrix() const
const LocalTrajectoryError & localError() const
std::vector< ConstRecHitPointer > ConstRecHitContainer
virtual DualTrajectoryFactory * clone() const
DualTrajectoryFactory(const edm::ParameterSet &config)
AlignmentAlgorithmBase::ConstTrajTrackPairCollection ConstTrajTrackPairCollection
std::vector< ReferenceTrajectoryPtr > ReferenceTrajectoryCollection
tuple tracks
Definition: testEve_cfg.py:39
const T & get() const
Definition: EventSetup.h:55
TransientTrackingRecHit::ConstRecHitContainer bwdRecHits
T const * product() const
Definition: ESHandle.h:62
const Surface & surface() const
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.
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")