test
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 {
22 public:
25 
29  const reco::BeamSpot &beamSpot) const override;
30 
32  const ConstTrajTrackPairCollection &tracks,
33  const ExternalPredictionCollection &external,
34  const reco::BeamSpot &beamSpot) const override;
35 
36  virtual ReferenceTrajectoryFactory* clone() const override { return new ReferenceTrajectoryFactory(*this); }
37 
38 protected:
40  const TrajectoryFactoryBase *bzeroFactory() const;
41 
42  double theMass;
45 };
46 
50 
52  TrajectoryFactoryBase( config ),
53  theMass(config.getParameter<double>("ParticleMass")),
54  theUseBzeroIfFieldOff(config.getParameter<bool>("UseBzeroIfFieldOff")),
55  theBzeroFactory(0)
56 {
57  edm::LogInfo("Alignment") << "@SUB=ReferenceTrajectoryFactory"
58  << "mass: " << theMass
59  << "\nusing Bzero if |B| = 0: "
60  << (theUseBzeroIfFieldOff ? "yes" : "no");
61 }
62 
64  TrajectoryFactoryBase(other),
65  theMass(other.theMass),
66  theUseBzeroIfFieldOff(other.theUseBzeroIfFieldOff),
67  theBzeroFactory(0) // copy data members, but no double pointing to same Bzero factory...
68 {
69 }
70 
72 {
73  delete theBzeroFactory;
74 }
75 
76 
80  const reco::BeamSpot &beamSpot) const
81 {
83  setup.get< IdealMagneticFieldRecord >().get( magneticField );
84  if (theUseBzeroIfFieldOff && magneticField->inTesla(GlobalPoint(0.,0.,0.)).mag2() < 1.e-6) {
85  return this->bzeroFactory()->trajectories(setup, tracks, beamSpot);
86  }
87 
89 
90  ConstTrajTrackPairCollection::const_iterator itTracks = tracks.begin();
91 
92  while ( itTracks != tracks.end() )
93  {
94  TrajectoryInput input = this->innermostStateAndRecHits( *itTracks );
95 
96  // Check input: If all hits were rejected, the TSOS is initialized as invalid.
97  if ( input.first.isValid() )
98  {
100  config.useBeamSpot = useBeamSpot_;
101  config.includeAPEs = includeAPEs_;
102  // set the flag for reversing the RecHits to false, since they are already in the correct order.
103  config.hitsAreReverse = false;
104  trajectories.push_back(ReferenceTrajectoryPtr(new ReferenceTrajectory(input.first, input.second,
105  magneticField.product(),
106  beamSpot, config)));
107  }
108 
109  ++itTracks;
110  }
111 
112  return trajectories;
113 }
114 
115 
119  const ExternalPredictionCollection& external,
120  const reco::BeamSpot &beamSpot) const
121 {
123 
124  if ( tracks.size() != external.size() )
125  {
126  edm::LogInfo("ReferenceTrajectories") << "@SUB=ReferenceTrajectoryFactory::trajectories"
127  << "Inconsistent input:\n"
128  << "\tnumber of tracks = " << tracks.size()
129  << "\tnumber of external predictions = " << external.size();
130  return trajectories;
131  }
132 
134  setup.get< IdealMagneticFieldRecord >().get( magneticField );
135  if (theUseBzeroIfFieldOff && magneticField->inTesla(GlobalPoint(0.,0.,0.)).mag2() < 1.e-6) {
136  return this->bzeroFactory()->trajectories(setup, tracks, external, beamSpot);
137  }
138 
139  ConstTrajTrackPairCollection::const_iterator itTracks = tracks.begin();
140  ExternalPredictionCollection::const_iterator itExternal = external.begin();
141 
142  while ( itTracks != tracks.end() )
143  {
145  // Check input: If all hits were rejected, the TSOS is initialized as invalid.
146  if ( input.first.isValid() )
147  {
148  if ( (*itExternal).isValid() && sameSurface( (*itExternal).surface(), input.first.surface() ) )
149  {
151  config.useBeamSpot = useBeamSpot_;
152  config.includeAPEs = includeAPEs_;
153  // set the flag for reversing the RecHits to false, since they are already in the correct order.
154  config.hitsAreReverse = false;
155  ReferenceTrajectoryPtr refTraj(new ReferenceTrajectory(*itExternal, input.second,
156  magneticField.product(),
157  beamSpot, config));
158 
159  AlgebraicSymMatrix externalParamErrors( asHepMatrix<5>( (*itExternal).localError().matrix() ) );
160  refTraj->setParameterErrors( externalParamErrors );
161  trajectories.push_back( refTraj );
162  }
163  else
164  {
166  config.useBeamSpot = useBeamSpot_;
167  config.includeAPEs = includeAPEs_;
168  config.hitsAreReverse = false;
169  trajectories.push_back(ReferenceTrajectoryPtr(new ReferenceTrajectory(input.first, input.second,
170  magneticField.product(),
171  beamSpot, config)));
172  }
173  }
174 
175  ++itTracks;
176  ++itExternal;
177  }
178 
179  return trajectories;
180 }
181 
183 {
184  if (!theBzeroFactory) {
185  const edm::ParameterSet &myPset = this->configuration();
186  edm::LogInfo("Alignment") << "@SUB=ReferenceTrajectoryFactory::bzeroFactory"
187  << "Using BzeroReferenceTrajectoryFactory for some (all?) events.";
188  // We take the config of this factory, copy it, replace its name and add
189  // the momentum parameter as expected by BzeroReferenceTrajectoryFactory and create it:
191  pset.copyForModify(myPset);
192  // next two lines not needed, but may help to better understand log file:
193  pset.eraseSimpleParameter("TrajectoryFactoryName");
194  pset.addParameter("TrajectoryFactoryName", std::string("BzeroReferenceTrajectoryFactory"));
195  pset.addParameter("MomentumEstimate", myPset.getParameter<double>("MomentumEstimateFieldOff"));
197  }
198  return theBzeroFactory;
199 }
200 
T getParameter(std::string const &) const
MaterialEffects materialEffects(void) const
virtual ReferenceTrajectoryFactory * clone() const override
static std::string const input
Definition: EdmProvDump.cc:44
bool sameSurface(const Surface &s1, const Surface &s2) const
tuple BzeroReferenceTrajectoryFactory
BzeroReferenceTrajectoryFactory.
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:144
virtual const ReferenceTrajectoryCollection trajectories(const edm::EventSetup &setup, const ConstTrajTrackPairCollection &tracks, const reco::BeamSpot &beamSpot) const override
Produce the reference trajectories.
const edm::ParameterSet & configuration() const
void eraseSimpleParameter(std::string const &name)
void copyForModify(ParameterSet const &other)
const TrajectoryFactoryBase * bzeroFactory() const
virtual const TrajectoryInput innermostStateAndRecHits(const ConstTrajTrackPair &track) const
AlignmentAlgorithmBase::ConstTrajTrackPairCollection ConstTrajTrackPairCollection
std::vector< ReferenceTrajectoryPtr > ReferenceTrajectoryCollection
tuple tracks
Definition: testEve_cfg.py:39
const T & get() const
Definition: EventSetup.h:56
const TrajectoryFactoryBase * theBzeroFactory
T const * product() const
Definition: ESHandle.h:86
ReferenceTrajectoryFactory(const edm::ParameterSet &config)
virtual const ReferenceTrajectoryCollection trajectories(const edm::EventSetup &setup, const ConstTrajTrackPairCollection &tracks, const reco::BeamSpot &beamSpot) const =0
PropagationDirection propagationDirection(void) const
CLHEP::HepSymMatrix AlgebraicSymMatrix
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::pair< TrajectoryStateOnSurface, TransientTrackingRecHit::ConstRecHitContainer > TrajectoryInput
std::vector< TrajectoryStateOnSurface > ExternalPredictionCollection
ReferenceTrajectoryBase::ReferenceTrajectoryPtr ReferenceTrajectoryPtr