CMS 3D CMS Logo

DualBzeroTrajectoryFactory.cc
Go to the documentation of this file.
8 
9 #include <algorithm>
10 
12 
14 
16 
18 public:
20  ~DualBzeroTrajectoryFactory() override;
22 
26  const reco::BeamSpot &beamSpot) const override;
27 
31  const reco::BeamSpot &beamSpot) const override;
32 
33  DualBzeroTrajectoryFactory *clone() const override { return new DualBzeroTrajectoryFactory(*this); }
34 
35 protected:
40  };
41 
43 
45  const Surface &surface,
46  const MagneticField *magField) const;
47 
48  double theMass;
50 };
51 
55 
57  : TrajectoryFactoryBase(config, iC), m_MagFieldToken(iC.esConsumes()) {
58  theMass = config.getParameter<double>("ParticleMass");
59  theMomentumEstimate = config.getParameter<double>("MomentumEstimate");
60 }
61 
63 
67 
69 
70  ConstTrajTrackPairCollection::const_iterator itTracks = tracks.begin();
71 
72  while (itTracks != tracks.end()) {
74  // Check input: If all hits were rejected, the TSOS is initialized as invalid.
75  if (input.refTsos.isValid()) {
77  config.useBeamSpot = useBeamSpot_;
78  config.includeAPEs = includeAPEs_;
79  config.allowZeroMaterial = allowZeroMaterial_;
81  input.refTsos, input.fwdRecHits, input.bwdRecHits, magneticField, beamSpot, config));
82  trajectories.push_back(ptr);
83  }
84 
85  ++itTracks;
86  }
87 
88  return trajectories;
89 }
90 
92  const edm::EventSetup &setup,
95  const reco::BeamSpot &beamSpot) const {
97 
98  if (tracks.size() != external.size()) {
99  edm::LogInfo("ReferenceTrajectories")
100  << "@SUB=DualBzeroTrajectoryFactory::trajectories"
101  << "Inconsistent input:\n"
102  << "\tnumber of tracks = " << tracks.size() << "\tnumber of external predictions = " << external.size();
103  return trajectories;
104  }
105 
107 
108  ConstTrajTrackPairCollection::const_iterator itTracks = tracks.begin();
109  ExternalPredictionCollection::const_iterator itExternal = external.begin();
110 
111  while (itTracks != tracks.end()) {
113  // Check input: If all hits were rejected, the TSOS is initialized as invalid.
114  if (input.refTsos.isValid()) {
115  if ((*itExternal).isValid()) {
116  TrajectoryStateOnSurface propExternal = propagateExternal(*itExternal, input.refTsos.surface(), magneticField);
117 
118  if (!propExternal.isValid())
119  continue;
120 
122  config.useBeamSpot = useBeamSpot_;
123  config.includeAPEs = includeAPEs_;
124  config.allowZeroMaterial = allowZeroMaterial_;
126  propExternal, input.fwdRecHits, input.bwdRecHits, magneticField, beamSpot, config));
127 
128  AlgebraicSymMatrix externalParamErrors(asHepMatrix<5>(propExternal.localError().matrix()));
129  ptr->setParameterErrors(externalParamErrors.sub(2, 5));
130  trajectories.push_back(ptr);
131  } else {
133  config.useBeamSpot = useBeamSpot_;
134  config.includeAPEs = includeAPEs_;
135  config.allowZeroMaterial = allowZeroMaterial_;
137  input.refTsos, input.fwdRecHits, input.bwdRecHits, magneticField, beamSpot, config));
138 
139  trajectories.push_back(ptr);
140  }
141  }
142 
143  ++itTracks;
144  ++itExternal;
145  }
146 
147  return trajectories;
148 }
149 
151  const ConstTrajTrackPair &track) const {
153 
154  // get the trajectory measurements in the correct order, i.e. reverse if needed
155  Trajectory::DataContainer allTrajMeas = this->orderedTrajectoryMeasurements(*track.first);
156  Trajectory::DataContainer usedTrajMeas;
157  Trajectory::DataContainer::iterator itM;
158  // get all relevant trajectory measurements
159  for (itM = allTrajMeas.begin(); itM != allTrajMeas.end(); itM++) {
160  if (useRecHit((*itM).recHit()))
161  usedTrajMeas.push_back(*itM);
162  }
163 
164  unsigned int iMeas = 0;
165  unsigned int nMeas = usedTrajMeas.size();
166  unsigned int nRefStateMeas = nMeas / 2;
167  // get the valid RecHits
168  for (itM = usedTrajMeas.begin(); itM != usedTrajMeas.end(); itM++, iMeas++) {
169  TransientTrackingRecHit::ConstRecHitPointer aRecHit = (*itM).recHit();
170 
171  if (iMeas < nRefStateMeas) {
172  input.bwdRecHits.push_back(aRecHit);
173  } else if (iMeas > nRefStateMeas) {
174  input.fwdRecHits.push_back(aRecHit);
175  } else { // iMeas == nRefStateMeas
176  if ((*itM).updatedState().isValid()) {
177  input.refTsos = (*itM).updatedState();
178  input.bwdRecHits.push_back(aRecHit);
179  input.fwdRecHits.push_back(aRecHit);
180  } else {
181  // if the tsos of the middle hit is not valid, try the next one ...
182  nRefStateMeas++;
183  input.bwdRecHits.push_back(aRecHit);
184  }
185  }
186  }
187 
188  // bring input.fwdRecHits into correct order
189  std::reverse(input.bwdRecHits.begin(), input.bwdRecHits.end());
190 
191  return input;
192 }
193 
195  const Surface &surface,
196  const MagneticField *magField) const {
198  const std::pair<TrajectoryStateOnSurface, double> tsosWithPath = propagator.propagateWithPath(external, surface);
199  return tsosWithPath.first;
200 }
201 
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
const LocalTrajectoryError & localError() const
TransientTrackingRecHit::ConstRecHitContainer bwdRecHits
DualBzeroTrajectoryFactory * clone() const override
const ReferenceTrajectoryCollection trajectories(const edm::EventSetup &setup, const ConstTrajTrackPairCollection &tracks, const reco::BeamSpot &beamSpot) const override
Produce the reference trajectories.
const TrajectoryStateOnSurface propagateExternal(const TrajectoryStateOnSurface &external, const Surface &surface, const MagneticField *magField) const
AlignmentAlgorithmBase::ConstTrajTrackPair ConstTrajTrackPair
Definition: config.py:1
MaterialEffects materialEffects(void) const
static std::string const input
Definition: EdmProvDump.cc:50
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > m_MagFieldToken
DualBzeroTrajectoryFactory(const edm::ParameterSet &config, edm::ConsumesCollector &iC)
std::vector< TrajectoryMeasurement > DataContainer
Definition: Trajectory.h:40
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
bool useRecHit(const TransientTrackingRecHit::ConstRecHitPointer &hitPtr) const
std::vector< ConstRecHitPointer > ConstRecHitContainer
virtual const Trajectory::DataContainer orderedTrajectoryMeasurements(const Trajectory &trajectory) const
Log< level::Info, false > LogInfo
AlignmentAlgorithmBase::ConstTrajTrackPairCollection ConstTrajTrackPairCollection
const DualBzeroTrajectoryInput referenceStateAndRecHits(const ConstTrajTrackPair &track) const
const AlgebraicSymMatrix55 & matrix() const
CLHEP::HepSymMatrix AlgebraicSymMatrix
dictionary config
Read in AllInOne config in JSON format.
Definition: DiMuonV_cfg.py:29
A factory that produces instances of class ReferenceTrajectory from a given TrajTrackPairCollection.
std::vector< TrajectoryStateOnSurface > ExternalPredictionCollection
PropagationDirection propagationDirection(void) const
#define DEFINE_EDM_PLUGIN(factory, type, name)
TransientTrackingRecHit::ConstRecHitContainer fwdRecHits
std::vector< ReferenceTrajectoryPtr > ReferenceTrajectoryCollection