CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DualTrajectoryFactory.cc
Go to the documentation of this file.
9 
10 #include <algorithm>
11 
14 
16 
18 public:
20  ~DualTrajectoryFactory() override;
22 
26  const reco::BeamSpot &beamSpot) const override;
27 
30  const ExternalPredictionCollection &external,
31  const reco::BeamSpot &beamSpot) const override;
32 
33  DualTrajectoryFactory *clone() const override { return new DualTrajectoryFactory(*this); }
34 
35 protected:
40  };
41 
43 
45  const Surface &surface,
46  const MagneticField *magField) const;
47 
48  double theMass;
49 };
50 
54 
56  : TrajectoryFactoryBase(config, iC),
57  m_MagFieldToken(iC.esConsumes()),
58  theMass(config.getParameter<double>("ParticleMass")) {
59  edm::LogInfo("Alignment") << "@SUB=DualTrajectoryFactory"
60  << "mass: " << theMass;
61 }
62 
64 
68 
70 
71  if (magneticField->inTesla(GlobalPoint(0., 0., 0.)).mag2() < 1.e-6) {
72  edm::LogWarning("Alignment") << "@SUB=DualTrajectoryFactory::trajectories"
73  << "B-field in z is " << magneticField->inTesla(GlobalPoint(0., 0., 0.)).z()
74  << ": You should probably use the DualBzeroTrajectoryFactory\n"
75  << "or fix this code to switch automatically as the ReferenceTrajectoryFactory does.";
76  }
77 
78  ConstTrajTrackPairCollection::const_iterator itTracks = tracks.begin();
79 
80  while (itTracks != tracks.end()) {
81  const DualTrajectoryInput input = this->referenceStateAndRecHits(*itTracks);
82  // Check input: If all hits were rejected, the TSOS is initialized as invalid.
83  if (input.refTsos.isValid()) {
85  config.useBeamSpot = useBeamSpot_;
86  config.includeAPEs = includeAPEs_;
89  input.refTsos, input.fwdRecHits, input.bwdRecHits, magneticField, beamSpot, config));
90  trajectories.push_back(ptr);
91  }
92 
93  ++itTracks;
94  }
95 
96  return trajectories;
97 }
98 
100  const edm::EventSetup &setup,
102  const ExternalPredictionCollection &external,
103  const reco::BeamSpot &beamSpot) const {
105 
106  if (tracks.size() != external.size()) {
107  edm::LogInfo("ReferenceTrajectories")
108  << "@SUB=DualTrajectoryFactory::trajectories"
109  << "Inconsistent input:\n"
110  << "\tnumber of tracks = " << tracks.size() << "\tnumber of external predictions = " << external.size();
111  return trajectories;
112  }
114 
115  if (magneticField->inTesla(GlobalPoint(0., 0., 0.)).mag2() < 1.e-6) {
116  edm::LogWarning("Alignment") << "@SUB=DualTrajectoryFactory::trajectories"
117  << "B-field in z is " << magneticField->inTesla(GlobalPoint(0., 0., 0.)).z()
118  << ": You should probably use the DualBzeroTrajectoryFactory\n"
119  << "or fix this code to switch automatically as the ReferenceTrajectoryFactory does.";
120  }
121 
122  ConstTrajTrackPairCollection::const_iterator itTracks = tracks.begin();
123  ExternalPredictionCollection::const_iterator itExternal = external.begin();
124 
125  while (itTracks != tracks.end()) {
127  // Check input: If all hits were rejected, the TSOS is initialized as invalid.
128  if (input.refTsos.isValid()) {
129  if ((*itExternal).isValid()) {
130  TrajectoryStateOnSurface propExternal = propagateExternal(*itExternal, input.refTsos.surface(), magneticField);
131 
132  if (!propExternal.isValid())
133  continue;
134 
136  config.useBeamSpot = useBeamSpot_;
137  config.includeAPEs = includeAPEs_;
140  propExternal, input.fwdRecHits, input.bwdRecHits, magneticField, beamSpot, config));
141 
142  AlgebraicSymMatrix externalParamErrors(asHepMatrix<5>(propExternal.localError().matrix()));
143  ptr->setParameterErrors(externalParamErrors);
144  trajectories.push_back(ptr);
145  } else {
147  config.useBeamSpot = useBeamSpot_;
148  config.includeAPEs = includeAPEs_;
151  input.refTsos, input.fwdRecHits, input.bwdRecHits, magneticField, beamSpot, config));
152  trajectories.push_back(ptr);
153  }
154  }
155 
156  ++itTracks;
157  ++itExternal;
158  }
159 
160  return trajectories;
161 }
162 
164  const ConstTrajTrackPair &track) const {
166 
167  // get the trajectory measurements in the correct order, i.e. reverse if needed
168  Trajectory::DataContainer allTrajMeas = this->orderedTrajectoryMeasurements(*track.first);
169  Trajectory::DataContainer usedTrajMeas;
170  Trajectory::DataContainer::iterator itM;
171  // get all relevant trajectory measurements
172  for (itM = allTrajMeas.begin(); itM != allTrajMeas.end(); itM++) {
173  if (useRecHit((*itM).recHit()))
174  usedTrajMeas.push_back(*itM);
175  }
176 
177  unsigned int iMeas = 0;
178  unsigned int nMeas = usedTrajMeas.size();
179  unsigned int nRefStateMeas = nMeas / 2;
180  // get the valid RecHits
181  for (itM = usedTrajMeas.begin(); itM != usedTrajMeas.end(); itM++, iMeas++) {
182  TransientTrackingRecHit::ConstRecHitPointer aRecHit = (*itM).recHit();
183 
184  if (iMeas < nRefStateMeas) {
185  input.bwdRecHits.push_back(aRecHit);
186  } else if (iMeas > nRefStateMeas) {
187  input.fwdRecHits.push_back(aRecHit);
188  } else { // iMeas == nRefStateMeas
189  if ((*itM).updatedState().isValid()) {
190  input.refTsos = (*itM).updatedState();
191  input.bwdRecHits.push_back(aRecHit);
192  input.fwdRecHits.push_back(aRecHit);
193  } else {
194  // if the tsos of the middle hit is not valid, try the next one ...
195  nRefStateMeas++;
196  input.bwdRecHits.push_back(aRecHit);
197  }
198  }
199  }
200 
201  // bring input.fwdRecHits into correct order
202  std::reverse(input.bwdRecHits.begin(), input.bwdRecHits.end());
203 
204  return input;
205 }
206 
208  const Surface &surface,
209  const MagneticField *magField) const {
211  const std::pair<TrajectoryStateOnSurface, double> tsosWithPath = propagator.propagateWithPath(external, surface);
212  return tsosWithPath.first;
213 }
214 
tuple propagator
T mag2() const
Definition: PV3DBase.h:63
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 GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
const auto & magField
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
virtual const Trajectory::DataContainer orderedTrajectoryMeasurements(const Trajectory &trajectory) const
AlignmentAlgorithmBase::ConstTrajTrackPair ConstTrajTrackPair
tuple magneticField
auto const & tracks
cannot be loose
bool useRecHit(const TransientTrackingRecHit::ConstRecHitPointer &hitPtr) const
static std::string const input
Definition: EdmProvDump.cc:47
bool getData(T &iHolder) const
Definition: EventSetup.h:128
TransientTrackingRecHit::ConstRecHitContainer fwdRecHits
const SurfaceType & surface() const
std::vector< TrajectoryMeasurement > DataContainer
Definition: Trajectory.h:40
std::pair< TrajectoryStateOnSurface, double > propagateWithPath(const FreeTrajectoryState &fts, const Plane &plane) const override
propagation to plane with path length
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
T z() const
Definition: PV3DBase.h:61
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > m_MagFieldToken
const AlgebraicSymMatrix55 & matrix() const
const LocalTrajectoryError & localError() const
std::vector< ConstRecHitPointer > ConstRecHitContainer
Log< level::Info, false > LogInfo
const ReferenceTrajectoryCollection trajectories(const edm::EventSetup &setup, const ConstTrajTrackPairCollection &tracks, const reco::BeamSpot &beamSpot) const override
Produce the reference trajectories.
AlignmentAlgorithmBase::ConstTrajTrackPairCollection ConstTrajTrackPairCollection
DualTrajectoryFactory * clone() const override
TransientTrackingRecHit::ConstRecHitContainer bwdRecHits
tuple config
parse the configuration file
PropagationDirection propagationDirection(void) const
CLHEP::HepSymMatrix AlgebraicSymMatrix
std::vector< TrajectoryStateOnSurface > ExternalPredictionCollection
#define DEFINE_EDM_PLUGIN(factory, type, name)
Log< level::Warning, false > LogWarning
A factory that produces instances of class ReferenceTrajectory from a given TrajTrackPairCollection.
DualTrajectoryFactory(const edm::ParameterSet &config, edm::ConsumesCollector &iC)
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
std::vector< ReferenceTrajectoryPtr > ReferenceTrajectoryCollection