CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ReferenceTrajectoryFactory.cc
Go to the documentation of this file.
11 
13 
15 
19 
21 public:
23  ~ReferenceTrajectoryFactory() override;
25 
29  const reco::BeamSpot &beamSpot) const override;
30 
33  const ExternalPredictionCollection &external,
34  const reco::BeamSpot &beamSpot) const override;
35 
36  ReferenceTrajectoryFactory *clone() const override { return new ReferenceTrajectoryFactory(*this); }
37 
38 protected:
40  const TrajectoryFactoryBase *bzeroFactory() const;
42 
43  double theMass;
45  //edm::ParameterSet pset;
47 };
48 
52 
54  : TrajectoryFactoryBase(config, iC),
55  m_MagFieldToken(iC.esConsumes()),
56  theMass(config.getParameter<double>("ParticleMass")),
57  theUseBzeroIfFieldOff(config.getParameter<bool>("UseBzeroIfFieldOff")),
58  theBzeroFactory(nullptr) {
59  edm::LogInfo("Alignment") << "@SUB=ReferenceTrajectoryFactory"
60  << "mass: " << theMass
61  << "\nusing Bzero if |B| = 0: " << (theUseBzeroIfFieldOff ? "yes" : "no");
62  // We take the config of this factory, copy it, replace its name and add
63  // the momentum parameter as expected by BzeroReferenceTrajectoryFactory and create it:
64  //
66  pset.copyForModify(config);
67  // next two lines not needed, but may help to better understand log file:
68  pset.eraseSimpleParameter("TrajectoryFactoryName");
69  pset.addParameter("TrajectoryFactoryName", std::string("BzeroReferenceTrajectoryFactory"));
70  pset.addParameter("MomentumEstimate", config.getParameter<double>("MomentumEstimateFieldOff"));
72 }
73 
75  : TrajectoryFactoryBase(other),
76  theMass(other.theMass),
77  theUseBzeroIfFieldOff(other.theUseBzeroIfFieldOff),
78  theBzeroFactory(nullptr) // copy data members, but no double pointing to same Bzero factory...
79 {}
80 
82 
86 
87  if (theUseBzeroIfFieldOff && magneticField->inTesla(GlobalPoint(0., 0., 0.)).mag2() < 1.e-6) {
88  return this->bzeroFactory()->trajectories(setup, tracks, beamSpot);
89  }
90 
92 
93  ConstTrajTrackPairCollection::const_iterator itTracks = tracks.begin();
94 
95  while (itTracks != tracks.end()) {
97 
98  // Check input: If all hits were rejected, the TSOS is initialized as invalid.
99  if (input.first.isValid()) {
101  config.useBeamSpot = useBeamSpot_;
102  config.includeAPEs = includeAPEs_;
104  // set the flag for reversing the RecHits to false, since they are already in the correct order.
105  config.hitsAreReverse = false;
106  trajectories.push_back(
107  ReferenceTrajectoryPtr(new ReferenceTrajectory(input.first, input.second, magneticField, beamSpot, config)));
108  }
109 
110  ++itTracks;
111  }
112 
113  return trajectories;
114 }
115 
117  const edm::EventSetup &setup,
119  const ExternalPredictionCollection &external,
120  const reco::BeamSpot &beamSpot) const {
122 
123  if (tracks.size() != external.size()) {
124  edm::LogInfo("ReferenceTrajectories")
125  << "@SUB=ReferenceTrajectoryFactory::trajectories"
126  << "Inconsistent input:\n"
127  << "\tnumber of tracks = " << tracks.size() << "\tnumber of external predictions = " << external.size();
128  return trajectories;
129  }
131 
132  if (theUseBzeroIfFieldOff && magneticField->inTesla(GlobalPoint(0., 0., 0.)).mag2() < 1.e-6) {
133  return this->bzeroFactory()->trajectories(setup, tracks, external, beamSpot);
134  }
135 
136  ConstTrajTrackPairCollection::const_iterator itTracks = tracks.begin();
137  ExternalPredictionCollection::const_iterator itExternal = external.begin();
138 
139  while (itTracks != tracks.end()) {
141  // Check input: If all hits were rejected, the TSOS is initialized as invalid.
142  if (input.first.isValid()) {
143  if ((*itExternal).isValid() && sameSurface((*itExternal).surface(), input.first.surface())) {
145  config.useBeamSpot = useBeamSpot_;
146  config.includeAPEs = includeAPEs_;
148  // set the flag for reversing the RecHits to false, since they are already in the correct order.
149  config.hitsAreReverse = false;
150  ReferenceTrajectoryPtr refTraj(
151  new ReferenceTrajectory(*itExternal, input.second, magneticField, beamSpot, config));
152 
153  AlgebraicSymMatrix externalParamErrors(asHepMatrix<5>((*itExternal).localError().matrix()));
154  refTraj->setParameterErrors(externalParamErrors);
155  trajectories.push_back(refTraj);
156  } else {
158  config.useBeamSpot = useBeamSpot_;
159  config.includeAPEs = includeAPEs_;
161  config.hitsAreReverse = false;
162  trajectories.push_back(ReferenceTrajectoryPtr(
163  new ReferenceTrajectory(input.first, input.second, magneticField, beamSpot, config)));
164  }
165  }
166 
167  ++itTracks;
168  ++itExternal;
169  }
170 
171  return trajectories;
172 }
173 
175  if (!theBzeroFactory) {
176  edm::LogInfo("Alignment") << "@SUB=ReferenceTrajectoryFactory::bzeroFactory"
177  << "Using BzeroReferenceTrajectoryFactory for some (all?) events.";
178  }
179  return theBzeroFactory;
180 }
181 
T mag2() const
Definition: PV3DBase.h:63
MaterialEffects materialEffects(void) const
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
ReferenceTrajectoryFactory * clone() const override
tuple magneticField
auto const & tracks
cannot be loose
static std::string const input
Definition: EdmProvDump.cc:47
bool getData(T &iHolder) const
Definition: EventSetup.h:128
bool sameSurface(const Surface &s1, const Surface &s2) const
tuple BzeroReferenceTrajectoryFactory
BzeroReferenceTrajectoryFactory.
const ReferenceTrajectoryCollection trajectories(const edm::EventSetup &setup, const ConstTrajTrackPairCollection &tracks, const reco::BeamSpot &beamSpot) const override
Produce the reference trajectories.
std::pair< TrajectoryStateOnSurface, TransientTrackingRecHit::ConstRecHitContainer > TrajectoryInput
Log< level::Info, false > LogInfo
const TrajectoryFactoryBase * bzeroFactory() const
virtual const TrajectoryInput innermostStateAndRecHits(const ConstTrajTrackPair &track) const
AlignmentAlgorithmBase::ConstTrajTrackPairCollection ConstTrajTrackPairCollection
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > m_MagFieldToken
const TrajectoryFactoryBase * theBzeroFactory
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
tuple config
parse the configuration file
virtual const ReferenceTrajectoryCollection trajectories(const edm::EventSetup &setup, const ConstTrajTrackPairCollection &tracks, const reco::BeamSpot &beamSpot) const =0
PropagationDirection propagationDirection(void) const
CLHEP::HepSymMatrix AlgebraicSymMatrix
ReferenceTrajectoryFactory(const edm::ParameterSet &config, edm::ConsumesCollector &iC)
std::vector< TrajectoryStateOnSurface > ExternalPredictionCollection
#define DEFINE_EDM_PLUGIN(factory, type, name)
ReferenceTrajectoryBase::ReferenceTrajectoryPtr ReferenceTrajectoryPtr
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
std::vector< ReferenceTrajectoryPtr > ReferenceTrajectoryCollection