CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ReferenceTrajectoryFactory.cc
Go to the documentation of this file.
11 
13 
15 
19 
21 public:
23  ~ReferenceTrajectoryFactory() override;
24 
28  const reco::BeamSpot &beamSpot) const override;
29 
31  const ConstTrajTrackPairCollection &tracks,
33  const reco::BeamSpot &beamSpot) const override;
34 
35  ReferenceTrajectoryFactory *clone() const override { return new ReferenceTrajectoryFactory(*this); }
36 
37 protected:
39  const TrajectoryFactoryBase *bzeroFactory() const;
40 
41  double theMass;
44 };
45 
49 
51  : TrajectoryFactoryBase(config),
52  theMass(config.getParameter<double>("ParticleMass")),
53  theUseBzeroIfFieldOff(config.getParameter<bool>("UseBzeroIfFieldOff")),
55  edm::LogInfo("Alignment") << "@SUB=ReferenceTrajectoryFactory"
56  << "mass: " << theMass
57  << "\nusing Bzero if |B| = 0: " << (theUseBzeroIfFieldOff ? "yes" : "no");
58 }
59 
61  : TrajectoryFactoryBase(other),
62  theMass(other.theMass),
64  theBzeroFactory(nullptr) // copy data members, but no double pointing to same Bzero factory...
65 {}
66 
68 
72  setup.get<IdealMagneticFieldRecord>().get(magneticField);
73  if (theUseBzeroIfFieldOff && magneticField->inTesla(GlobalPoint(0., 0., 0.)).mag2() < 1.e-6) {
74  return this->bzeroFactory()->trajectories(setup, tracks, beamSpot);
75  }
76 
78 
79  ConstTrajTrackPairCollection::const_iterator itTracks = tracks.begin();
80 
81  while (itTracks != tracks.end()) {
83 
84  // Check input: If all hits were rejected, the TSOS is initialized as invalid.
85  if (input.first.isValid()) {
87  config.useBeamSpot = useBeamSpot_;
88  config.includeAPEs = includeAPEs_;
90  // set the flag for reversing the RecHits to false, since they are already in the correct order.
91  config.hitsAreReverse = false;
92  trajectories.push_back(ReferenceTrajectoryPtr(
93  new ReferenceTrajectory(input.first, input.second, magneticField.product(), beamSpot, config)));
94  }
95 
96  ++itTracks;
97  }
98 
99  return trajectories;
100 }
101 
103  const edm::EventSetup &setup,
106  const reco::BeamSpot &beamSpot) const {
108 
109  if (tracks.size() != external.size()) {
110  edm::LogInfo("ReferenceTrajectories")
111  << "@SUB=ReferenceTrajectoryFactory::trajectories"
112  << "Inconsistent input:\n"
113  << "\tnumber of tracks = " << tracks.size() << "\tnumber of external predictions = " << external.size();
114  return trajectories;
115  }
116 
118  setup.get<IdealMagneticFieldRecord>().get(magneticField);
119  if (theUseBzeroIfFieldOff && magneticField->inTesla(GlobalPoint(0., 0., 0.)).mag2() < 1.e-6) {
120  return this->bzeroFactory()->trajectories(setup, tracks, external, beamSpot);
121  }
122 
123  ConstTrajTrackPairCollection::const_iterator itTracks = tracks.begin();
124  ExternalPredictionCollection::const_iterator itExternal = external.begin();
125 
126  while (itTracks != tracks.end()) {
128  // Check input: If all hits were rejected, the TSOS is initialized as invalid.
129  if (input.first.isValid()) {
130  if ((*itExternal).isValid() && sameSurface((*itExternal).surface(), input.first.surface())) {
132  config.useBeamSpot = useBeamSpot_;
133  config.includeAPEs = includeAPEs_;
135  // set the flag for reversing the RecHits to false, since they are already in the correct order.
136  config.hitsAreReverse = false;
137  ReferenceTrajectoryPtr refTraj(
138  new ReferenceTrajectory(*itExternal, input.second, magneticField.product(), beamSpot, config));
139 
140  AlgebraicSymMatrix externalParamErrors(asHepMatrix<5>((*itExternal).localError().matrix()));
141  refTraj->setParameterErrors(externalParamErrors);
142  trajectories.push_back(refTraj);
143  } else {
145  config.useBeamSpot = useBeamSpot_;
146  config.includeAPEs = includeAPEs_;
148  config.hitsAreReverse = false;
149  trajectories.push_back(ReferenceTrajectoryPtr(
150  new ReferenceTrajectory(input.first, input.second, magneticField.product(), beamSpot, config)));
151  }
152  }
153 
154  ++itTracks;
155  ++itExternal;
156  }
157 
158  return trajectories;
159 }
160 
162  if (!theBzeroFactory) {
163  const edm::ParameterSet &myPset = this->configuration();
164  edm::LogInfo("Alignment") << "@SUB=ReferenceTrajectoryFactory::bzeroFactory"
165  << "Using BzeroReferenceTrajectoryFactory for some (all?) events.";
166  // We take the config of this factory, copy it, replace its name and add
167  // the momentum parameter as expected by BzeroReferenceTrajectoryFactory and create it:
169  pset.copyForModify(myPset);
170  // next two lines not needed, but may help to better understand log file:
171  pset.eraseSimpleParameter("TrajectoryFactoryName");
172  pset.addParameter("TrajectoryFactoryName", std::string("BzeroReferenceTrajectoryFactory"));
173  pset.addParameter("MomentumEstimate", myPset.getParameter<double>("MomentumEstimateFieldOff"));
175  }
176  return theBzeroFactory;
177 }
178 
T getParameter(std::string const &) const
T mag2() const
Definition: PV3DBase.h:66
const ReferenceTrajectoryCollection trajectories(const edm::EventSetup &setup, const ConstTrajTrackPairCollection &tracks, const reco::BeamSpot &beamSpot) const override
Produce the reference trajectories.
MaterialEffects materialEffects(void) const
ReferenceTrajectoryFactory * clone() const override
#define nullptr
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
Definition: config.py:1
static std::string const input
Definition: EdmProvDump.cc:48
config
Definition: looper.py:291
bool sameSurface(const Surface &s1, const Surface &s2) const
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:125
BzeroReferenceTrajectoryFactory
BzeroReferenceTrajectoryFactory.
const edm::ParameterSet & configuration() const
void eraseSimpleParameter(std::string const &name)
void copyForModify(ParameterSet const &other)
Definition: ParameterSet.cc:93
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
std::pair< TrajectoryStateOnSurface, TransientTrackingRecHit::ConstRecHitContainer > TrajectoryInput
virtual const ReferenceTrajectoryCollection trajectories(const edm::EventSetup &setup, const ConstTrajTrackPairCollection &tracks, const reco::BeamSpot &beamSpot) const =0
const TrajectoryFactoryBase * bzeroFactory() const
virtual const TrajectoryInput innermostStateAndRecHits(const ConstTrajTrackPair &track) const
AlignmentAlgorithmBase::ConstTrajTrackPairCollection ConstTrajTrackPairCollection
const TrajectoryFactoryBase * theBzeroFactory
ReferenceTrajectoryFactory(const edm::ParameterSet &config)
T get() const
Definition: EventSetup.h:71
PropagationDirection propagationDirection(void) const
CLHEP::HepSymMatrix AlgebraicSymMatrix
std::vector< TrajectoryStateOnSurface > ExternalPredictionCollection
#define DEFINE_EDM_PLUGIN(factory, type, name)
ReferenceTrajectoryBase::ReferenceTrajectoryPtr ReferenceTrajectoryPtr
T const * product() const
Definition: ESHandle.h:86
std::vector< ReferenceTrajectoryPtr > ReferenceTrajectoryCollection