CMS 3D CMS Logo

DualTrajectoryFactory.cc
Go to the documentation of this file.
9 
10 #include <algorithm>
11 
14 
16 
18 public:
20  ~DualTrajectoryFactory() override;
21 
25  const reco::BeamSpot &beamSpot) const override;
26 
30  const reco::BeamSpot &beamSpot) const override;
31 
32  DualTrajectoryFactory *clone() const override { return new DualTrajectoryFactory(*this); }
33 
34 protected:
39  };
40 
42 
44  const Surface &surface,
45  const MagneticField *magField) const;
46 
47  double theMass;
48 };
49 
53 
55  : TrajectoryFactoryBase(config), theMass(config.getParameter<double>("ParticleMass")) {
56  edm::LogInfo("Alignment") << "@SUB=DualTrajectoryFactory"
57  << "mass: " << theMass;
58 }
59 
61 
65 
68  if (magneticField->inTesla(GlobalPoint(0., 0., 0.)).mag2() < 1.e-6) {
69  edm::LogWarning("Alignment") << "@SUB=DualTrajectoryFactory::trajectories"
70  << "B-field in z is " << magneticField->inTesla(GlobalPoint(0., 0., 0.)).z()
71  << ": You should probably use the DualBzeroTrajectoryFactory\n"
72  << "or fix this code to switch automatically as the ReferenceTrajectoryFactory does.";
73  }
74 
75  ConstTrajTrackPairCollection::const_iterator itTracks = tracks.begin();
76 
77  while (itTracks != tracks.end()) {
78  const DualTrajectoryInput input = this->referenceStateAndRecHits(*itTracks);
79  // Check input: If all hits were rejected, the TSOS is initialized as invalid.
80  if (input.refTsos.isValid()) {
82  config.useBeamSpot = useBeamSpot_;
83  config.includeAPEs = includeAPEs_;
84  config.allowZeroMaterial = allowZeroMaterial_;
86  input.refTsos, input.fwdRecHits, input.bwdRecHits, magneticField.product(), beamSpot, config));
87  trajectories.push_back(ptr);
88  }
89 
90  ++itTracks;
91  }
92 
93  return trajectories;
94 }
95 
97  const edm::EventSetup &setup,
100  const reco::BeamSpot &beamSpot) const {
102 
103  if (tracks.size() != external.size()) {
104  edm::LogInfo("ReferenceTrajectories")
105  << "@SUB=DualTrajectoryFactory::trajectories"
106  << "Inconsistent input:\n"
107  << "\tnumber of tracks = " << tracks.size() << "\tnumber of external predictions = " << external.size();
108  return trajectories;
109  }
110 
113  if (magneticField->inTesla(GlobalPoint(0., 0., 0.)).mag2() < 1.e-6) {
114  edm::LogWarning("Alignment") << "@SUB=DualTrajectoryFactory::trajectories"
115  << "B-field in z is " << magneticField->inTesla(GlobalPoint(0., 0., 0.)).z()
116  << ": You should probably use the DualBzeroTrajectoryFactory\n"
117  << "or fix this code to switch automatically as the ReferenceTrajectoryFactory does.";
118  }
119 
120  ConstTrajTrackPairCollection::const_iterator itTracks = tracks.begin();
121  ExternalPredictionCollection::const_iterator itExternal = external.begin();
122 
123  while (itTracks != tracks.end()) {
125  // Check input: If all hits were rejected, the TSOS is initialized as invalid.
126  if (input.refTsos.isValid()) {
127  if ((*itExternal).isValid()) {
128  TrajectoryStateOnSurface propExternal =
129  propagateExternal(*itExternal, input.refTsos.surface(), magneticField.product());
130 
131  if (!propExternal.isValid())
132  continue;
133 
135  config.useBeamSpot = useBeamSpot_;
136  config.includeAPEs = includeAPEs_;
137  config.allowZeroMaterial = allowZeroMaterial_;
139  propExternal, input.fwdRecHits, input.bwdRecHits, magneticField.product(), beamSpot, config));
140 
141  AlgebraicSymMatrix externalParamErrors(asHepMatrix<5>(propExternal.localError().matrix()));
142  ptr->setParameterErrors(externalParamErrors);
143  trajectories.push_back(ptr);
144  } else {
146  config.useBeamSpot = useBeamSpot_;
147  config.includeAPEs = includeAPEs_;
148  config.allowZeroMaterial = allowZeroMaterial_;
150  input.refTsos, input.fwdRecHits, input.bwdRecHits, magneticField.product(), beamSpot, config));
151  trajectories.push_back(ptr);
152  }
153  }
154 
155  ++itTracks;
156  ++itExternal;
157  }
158 
159  return trajectories;
160 }
161 
163  const ConstTrajTrackPair &track) const {
165 
166  // get the trajectory measurements in the correct order, i.e. reverse if needed
167  Trajectory::DataContainer allTrajMeas = this->orderedTrajectoryMeasurements(*track.first);
168  Trajectory::DataContainer usedTrajMeas;
169  Trajectory::DataContainer::iterator itM;
170  // get all relevant trajectory measurements
171  for (itM = allTrajMeas.begin(); itM != allTrajMeas.end(); itM++) {
172  if (useRecHit((*itM).recHit()))
173  usedTrajMeas.push_back(*itM);
174  }
175 
176  unsigned int iMeas = 0;
177  unsigned int nMeas = usedTrajMeas.size();
178  unsigned int nRefStateMeas = nMeas / 2;
179  // get the valid RecHits
180  for (itM = usedTrajMeas.begin(); itM != usedTrajMeas.end(); itM++, iMeas++) {
181  TransientTrackingRecHit::ConstRecHitPointer aRecHit = (*itM).recHit();
182 
183  if (iMeas < nRefStateMeas) {
184  input.bwdRecHits.push_back(aRecHit);
185  } else if (iMeas > nRefStateMeas) {
186  input.fwdRecHits.push_back(aRecHit);
187  } else { // iMeas == nRefStateMeas
188  if ((*itM).updatedState().isValid()) {
189  input.refTsos = (*itM).updatedState();
190  input.bwdRecHits.push_back(aRecHit);
191  input.fwdRecHits.push_back(aRecHit);
192  } else {
193  // if the tsos of the middle hit is not valid, try the next one ...
194  nRefStateMeas++;
195  input.bwdRecHits.push_back(aRecHit);
196  }
197  }
198  }
199 
200  // bring input.fwdRecHits into correct order
201  std::reverse(input.bwdRecHits.begin(), input.bwdRecHits.end());
202 
203  return input;
204 }
205 
207  const Surface &surface,
208  const MagneticField *magField) const {
210  const std::pair<TrajectoryStateOnSurface, double> tsosWithPath = propagator.propagateWithPath(external, surface);
211  return tsosWithPath.first;
212 }
213 
TrajectoryFactoryBase::useRecHit
bool useRecHit(const TransientTrackingRecHit::ConstRecHitPointer &hitPtr) const
Definition: TrajectoryFactoryBase.cc:94
PDWG_EXOHSCP_cff.tracks
tracks
Definition: PDWG_EXOHSCP_cff.py:28
DualTrajectoryFactory::DualTrajectoryFactory
DualTrajectoryFactory(const edm::ParameterSet &config)
Definition: DualTrajectoryFactory.cc:54
anyDirection
Definition: PropagationDirection.h:4
pwdgSkimBPark_cfi.beamSpot
beamSpot
Definition: pwdgSkimBPark_cfi.py:5
input
static const std::string input
Definition: EdmProvDump.cc:48
MessageLogger.h
ESHandle.h
DualTrajectoryFactory::clone
DualTrajectoryFactory * clone() const override
Definition: DualTrajectoryFactory.cc:32
HLT_2018_cff.magneticField
magneticField
Definition: HLT_2018_cff.py:348
DualReferenceTrajectory
Definition: DualReferenceTrajectory.h:37
edm::LogInfo
Definition: MessageLogger.h:254
TrajectoryFactoryBase::includeAPEs_
const bool includeAPEs_
Definition: TrajectoryFactoryBase.h:71
Surface
Definition: Surface.h:36
ReferenceTrajectoryBase::Config
Definition: ReferenceTrajectoryBase.h:121
LocalTrajectoryError::matrix
const AlgebraicSymMatrix55 & matrix() const
Definition: LocalTrajectoryError.h:60
ReferenceCountingPointer
Definition: ReferenceCounted.h:60
DualTrajectoryFactory::DualTrajectoryInput::refTsos
TrajectoryStateOnSurface refTsos
Definition: DualTrajectoryFactory.cc:36
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
groupFilesInBlocks.reverse
reverse
Definition: groupFilesInBlocks.py:131
IdealMagneticFieldRecord
Definition: IdealMagneticFieldRecord.h:11
config
Definition: config.py:1
DualTrajectoryFactory::DualTrajectoryInput
Definition: DualTrajectoryFactory.cc:35
external
Definition: HEPTopTaggerV2.h:20
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
TrackCandidateProducer_cfi.propagator
propagator
Definition: TrackCandidateProducer_cfi.py:17
Trajectory::DataContainer
std::vector< TrajectoryMeasurement > DataContainer
Definition: Trajectory.h:40
TrajectoryFactoryBase::ConstTrajTrackPair
AlignmentAlgorithmBase::ConstTrajTrackPair ConstTrajTrackPair
Definition: TrajectoryFactoryBase.h:24
TrajectoryFactoryBase::useBeamSpot_
const bool useBeamSpot_
Definition: TrajectoryFactoryBase.h:70
reco::BeamSpot
Definition: BeamSpot.h:21
IdealMagneticFieldRecord.h
edm::ESHandle< MagneticField >
DualTrajectoryFactory::DualTrajectoryInput::fwdRecHits
TransientTrackingRecHit::ConstRecHitContainer fwdRecHits
Definition: DualTrajectoryFactory.cc:37
TrajectoryFactoryBase::propagationDirection
PropagationDirection propagationDirection(void) const
Definition: TrajectoryFactoryBase.h:46
GlobalPoint
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
looper.config
config
Definition: looper.py:291
Point3DBase< float, GlobalTag >
DEFINE_EDM_PLUGIN
#define DEFINE_EDM_PLUGIN(factory, type, name)
Definition: PluginFactory.h:124
DualTrajectoryFactory::trajectories
const ReferenceTrajectoryCollection trajectories(const edm::EventSetup &setup, const ConstTrajTrackPairCollection &tracks, const reco::BeamSpot &beamSpot) const override
Produce the reference trajectories.
Definition: DualTrajectoryFactory.cc:62
edm::LogWarning
Definition: MessageLogger.h:141
DualReferenceTrajectory.h
TrajectoryFactoryBase::ReferenceTrajectoryCollection
std::vector< ReferenceTrajectoryPtr > ReferenceTrajectoryCollection
Definition: TrajectoryFactoryBase.h:26
edm::ParameterSet
Definition: ParameterSet.h:36
TrackingRecHit::ConstRecHitContainer
std::vector< ConstRecHitPointer > ConstRecHitContainer
Definition: TrackingRecHit.h:32
TrajectoryFactoryBase
Definition: TrajectoryFactoryBase.h:20
TrajectoryFactoryPlugin.h
DualTrajectoryFactory::~DualTrajectoryFactory
~DualTrajectoryFactory() override
Definition: DualTrajectoryFactory.cc:60
edmplugin::PluginFactory
Definition: PluginFactory.h:34
DualTrajectoryFactory::theMass
double theMass
Definition: DualTrajectoryFactory.cc:47
TrackingRecHit::ConstRecHitPointer
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
Definition: TrackingRecHit.h:25
AlgebraicSymMatrix
CLHEP::HepSymMatrix AlgebraicSymMatrix
Definition: AlgebraicObjects.h:15
MagneticField.h
edm::EventSetup
Definition: EventSetup.h:57
AnalyticalPropagator.h
TrajectoryFactoryBase::materialEffects
MaterialEffects materialEffects(void) const
Definition: TrajectoryFactoryBase.h:45
get
#define get
DualTrajectoryFactory::referenceStateAndRecHits
const DualTrajectoryInput referenceStateAndRecHits(const ConstTrajTrackPair &track) const
Definition: DualTrajectoryFactory.cc:162
TrajectoryFactoryBase::allowZeroMaterial_
const bool allowZeroMaterial_
Definition: TrajectoryFactoryBase.h:72
AnalyticalPropagator
Definition: AnalyticalPropagator.h:22
TrajectoryFactoryBase::ConstTrajTrackPairCollection
AlignmentAlgorithmBase::ConstTrajTrackPairCollection ConstTrajTrackPairCollection
Definition: TrajectoryFactoryBase.h:25
DualTrajectoryFactory::DualTrajectoryInput::bwdRecHits
TransientTrackingRecHit::ConstRecHitContainer bwdRecHits
Definition: DualTrajectoryFactory.cc:38
EventSetup.h
DualTrajectoryFactory
A factory that produces instances of class ReferenceTrajectory from a given TrajTrackPairCollection.
Definition: DualTrajectoryFactory.cc:17
HLT_2018_cff.track
track
Definition: HLT_2018_cff.py:10352
ParameterSet.h
DualTrajectoryFactory::propagateExternal
const TrajectoryStateOnSurface propagateExternal(const TrajectoryStateOnSurface &external, const Surface &surface, const MagneticField *magField) const
Definition: DualTrajectoryFactory.cc:206
TrajectoryStateOnSurface::localError
const LocalTrajectoryError & localError() const
Definition: TrajectoryStateOnSurface.h:77
MagneticField
Definition: MagneticField.h:19
TrajectoryStateOnSurface::isValid
bool isValid() const
Definition: TrajectoryStateOnSurface.h:54
TrajectoryFactoryBase.h
TrajectoryFactoryBase::orderedTrajectoryMeasurements
virtual const Trajectory::DataContainer orderedTrajectoryMeasurements(const Trajectory &trajectory) const
Definition: TrajectoryFactoryBase.cc:65
TrajectoryFactoryBase::ExternalPredictionCollection
std::vector< TrajectoryStateOnSurface > ExternalPredictionCollection
Definition: TrajectoryFactoryBase.h:28