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;
28 
30  const ConstTrajTrackPairCollection &tracks,
31  const ExternalPredictionCollection &external,
32  const reco::BeamSpot &beamSpot) const;
33 
34  virtual DualTrajectoryFactory* clone() const { 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 
76  edm::ESHandle< MagneticField > magneticField;
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  input.fwdRecHits,
95  input.bwdRecHits,
96  magneticField.product(),
99  theMass,
101  trajectories.push_back( ptr );
102  }
103 
104  ++itTracks;
105  }
106 
107  return trajectories;
108 }
109 
113  const ExternalPredictionCollection &external,
114  const reco::BeamSpot &beamSpot) const
115 {
117 
118  if ( tracks.size() != external.size() )
119  {
120  edm::LogInfo("ReferenceTrajectories") << "@SUB=DualTrajectoryFactory::trajectories"
121  << "Inconsistent input:\n"
122  << "\tnumber of tracks = " << tracks.size()
123  << "\tnumber of external predictions = " << external.size();
124  return trajectories;
125  }
126 
127  edm::ESHandle< MagneticField > magneticField;
128  setup.get< IdealMagneticFieldRecord >().get( magneticField );
129  if (magneticField->inTesla(GlobalPoint(0.,0.,0.)).mag2() < 1.e-6) {
130  edm::LogWarning("Alignment") << "@SUB=DualTrajectoryFactory::trajectories"
131  << "B-field in z is " << magneticField->inTesla(GlobalPoint(0.,0.,0.)).z()
132  << ": You should probably use the DualBzeroTrajectoryFactory\n"
133  << "or fix this code to switch automatically as the ReferenceTrajectoryFactory does.";
134  }
135 
136  ConstTrajTrackPairCollection::const_iterator itTracks = tracks.begin();
137  ExternalPredictionCollection::const_iterator itExternal = external.begin();
138 
139  while ( itTracks != tracks.end() )
140  {
142  // Check input: If all hits were rejected, the TSOS is initialized as invalid.
143  if ( input.refTsos.isValid() )
144  {
145  if ( (*itExternal).isValid() )
146  {
147  TrajectoryStateOnSurface propExternal =
148  propagateExternal( *itExternal, input.refTsos.surface(), magneticField.product() );
149 
150  if ( !propExternal.isValid() ) continue;
151 
152  // set the flag for reversing the RecHits to false, since they are already in the correct order.
153  ReferenceTrajectoryPtr ptr( new DualReferenceTrajectory( propExternal,
154  input.fwdRecHits,
155  input.bwdRecHits,
156  magneticField.product(),
157  materialEffects(),
159  theMass,
161 
162  AlgebraicSymMatrix externalParamErrors( asHepMatrix<5>( propExternal.localError().matrix() ) );
163  ptr->setParameterErrors( externalParamErrors );
164  trajectories.push_back( ptr );
165  }
166  else
167  {
169  input.fwdRecHits,
170  input.bwdRecHits,
171  magneticField.product(),
172  materialEffects(),
174  theMass,
176  trajectories.push_back( ptr );
177  }
178  }
179 
180  ++itTracks;
181  ++itExternal;
182  }
183 
184  return trajectories;
185 }
186 
187 
190 {
192 
193  // get the trajectory measurements in the correct order, i.e. reverse if needed
194  Trajectory::DataContainer allTrajMeas = this->orderedTrajectoryMeasurements( *track.first );
195  Trajectory::DataContainer usedTrajMeas;
196  Trajectory::DataContainer::iterator itM;
197  // get all relevant trajectory measurements
198  for ( itM = allTrajMeas.begin(); itM != allTrajMeas.end(); itM++ )
199  {
200  if ( useRecHit( ( *itM ).recHit() ) ) usedTrajMeas.push_back( *itM );
201  }
202 
203  unsigned int iMeas = 0;
204  unsigned int nMeas = usedTrajMeas.size();
205  unsigned int nRefStateMeas = nMeas/2;
206  // get the valid RecHits
207  for ( itM = usedTrajMeas.begin(); itM != usedTrajMeas.end(); itM++, iMeas++ )
208  {
209  TransientTrackingRecHit::ConstRecHitPointer aRecHit = ( *itM ).recHit();
210 
211  if ( iMeas < nRefStateMeas ) {
212  input.bwdRecHits.push_back( aRecHit );
213  } else if ( iMeas > nRefStateMeas ) {
214  input.fwdRecHits.push_back( aRecHit );
215  } else { // iMeas == nRefStateMeas
216  if ( ( *itM ).updatedState().isValid() )
217  {
218  input.refTsos = ( *itM ).updatedState();
219  input.bwdRecHits.push_back( aRecHit );
220  input.fwdRecHits.push_back( aRecHit );
221  } else {
222  // if the tsos of the middle hit is not valid, try the next one ...
223  nRefStateMeas++;
224  input.bwdRecHits.push_back( aRecHit );
225  }
226  }
227  }
228 
229  // bring input.fwdRecHits into correct order
230  std::reverse( input.bwdRecHits.begin(), input.bwdRecHits.end() );
231 
232  return input;
233 }
234 
237  const Surface& surface,
238  const MagneticField* magField ) const
239 {
241  const std::pair< TrajectoryStateOnSurface, double > tsosWithPath =
242  propagator.propagateWithPath( external, surface );
243  return tsosWithPath.first;
244 }
245 
246 
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
virtual const ReferenceTrajectoryCollection trajectories(const edm::EventSetup &setup, const ConstTrajTrackPairCollection &tracks, const reco::BeamSpot &beamSpot) const
Produce the reference trajectories.
TransientTrackingRecHit::ConstRecHitContainer fwdRecHits
const SurfaceType & surface() const
std::vector< TrajectoryMeasurement > DataContainer
Definition: Trajectory.h:42
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
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="")