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 {
82  edm::ESHandle< MagneticField > magneticField;
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  {
99  // set the flag for reversing the RecHits to false, since they are already in the correct order.
100  trajectories.push_back(ReferenceTrajectoryPtr(new ReferenceTrajectory(input.first, input.second, false,
101  magneticField.product(), materialEffects(),
104  }
105 
106  ++itTracks;
107  }
108 
109  return trajectories;
110 }
111 
112 
116  const ExternalPredictionCollection& external,
117  const reco::BeamSpot &beamSpot) const
118 {
120 
121  if ( tracks.size() != external.size() )
122  {
123  edm::LogInfo("ReferenceTrajectories") << "@SUB=ReferenceTrajectoryFactory::trajectories"
124  << "Inconsistent input:\n"
125  << "\tnumber of tracks = " << tracks.size()
126  << "\tnumber of external predictions = " << external.size();
127  return trajectories;
128  }
129 
130  edm::ESHandle< MagneticField > magneticField;
131  setup.get< IdealMagneticFieldRecord >().get( magneticField );
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() )
140  {
142  // Check input: If all hits were rejected, the TSOS is initialized as invalid.
143  if ( input.first.isValid() )
144  {
145  if ( (*itExternal).isValid() && sameSurface( (*itExternal).surface(), input.first.surface() ) )
146  {
147  // set the flag for reversing the RecHits to false, since they are already in the correct order.
148  ReferenceTrajectoryPtr refTraj( new ReferenceTrajectory( *itExternal, input.second, false,
149  magneticField.product(), materialEffects(),
152 
153  AlgebraicSymMatrix externalParamErrors( asHepMatrix<5>( (*itExternal).localError().matrix() ) );
154  refTraj->setParameterErrors( externalParamErrors );
155  trajectories.push_back( refTraj );
156  }
157  else
158  {
159  trajectories.push_back(ReferenceTrajectoryPtr(new ReferenceTrajectory(input.first, input.second, false,
160  magneticField.product(), materialEffects(),
163  }
164  }
165 
166  ++itTracks;
167  ++itExternal;
168  }
169 
170  return trajectories;
171 }
172 
174 {
175  if (!theBzeroFactory) {
176  const edm::ParameterSet &myPset = this->configuration();
177  edm::LogInfo("Alignment") << "@SUB=ReferenceTrajectoryFactory::bzeroFactory"
178  << "Using BzeroReferenceTrajectoryFactory for some (all?) events.";
179  // We take the config of this factory, copy it, replace its name and add
180  // the momentum parameter as expected by BzeroReferenceTrajectoryFactory and create it:
181  edm::ParameterSet pset;
182  pset.copyForModify(myPset);
183  // next two lines not needed, but may help to better understand log file:
184  pset.eraseSimpleParameter("TrajectoryFactoryName");
185  pset.addParameter("TrajectoryFactoryName", std::string("BzeroReferenceTrajectoryFactory"));
186  pset.addParameter("MomentumEstimate", myPset.getParameter<double>("MomentumEstimateFieldOff"));
188  }
189  return theBzeroFactory;
190 }
191 
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:142
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:55
const TrajectoryFactoryBase * theBzeroFactory
T const * product() const
Definition: ESHandle.h:62
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
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")