CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
BasicTrajectoryState.cc
Go to the documentation of this file.
6 
8 
9 
10 #include <cmath>
11 #include<sstream>
12 
15  const Surface& aSurface,
16  const SurfaceSide side) :
17  theFreeState( new FreeTrajectoryState(fts)),
18  theLocalError(InvalidError()),
19  theLocalParameters(),
20  theLocalParametersValid(false),
21  theGlobalParamsUp2Date(true),
22  theSurfaceSide(side),
23  theSurfaceP( &aSurface),
24  theWeight(1.),
25  theField( &fts.parameters().magneticField())
26 {}
27 
30  const Surface& aSurface,
31  const SurfaceSide side) :
32  theFreeState( new FreeTrajectoryState(par)),
33  theLocalError(InvalidError()),
34  theLocalParameters(),
35  theLocalParametersValid(false),
36  theGlobalParamsUp2Date(true),
37  theSurfaceSide(side),
38  theSurfaceP( &aSurface),
39  theWeight(1.),
40  theField( &par.magneticField())
41 {}
42 
45  const CartesianTrajectoryError& err,
46  const Surface& aSurface,
47  const SurfaceSide side) :
48  theFreeState( new FreeTrajectoryState(par, err)),
49  theLocalError(InvalidError()),
50  theLocalParameters(),
51  theLocalParametersValid(false),
52  theGlobalParamsUp2Date(true),
53  theSurfaceSide(side),
54  theSurfaceP( &aSurface),
55  theWeight(1.),
56  theField( &par.magneticField())
57 {}
58 
61  const CurvilinearTrajectoryError& err,
62  const Surface& aSurface,
63  const SurfaceSide side,
64  double weight) :
65  theFreeState( new FreeTrajectoryState(par, err)),
66  theLocalError(InvalidError()),
67  theLocalParameters(),
68  theLocalParametersValid(false),
69  theGlobalParamsUp2Date(true),
70  theSurfaceSide(side),
71  theSurfaceP( &aSurface),
72  theWeight(weight),
73  theField( &par.magneticField())
74 {}
75 
78  const CurvilinearTrajectoryError& err,
79  const Surface& aSurface,
80  double weight) :
81  theFreeState( new FreeTrajectoryState(par, err)),
82  theLocalError(InvalidError()),
83  theLocalParameters(),
84  theLocalParametersValid(false),
85  theGlobalParamsUp2Date(true),
86  theSurfaceSide(SurfaceSideDefinition::atCenterOfSurface),
87  theSurfaceP( &aSurface),
88  theWeight(weight),
89  theField( &par.magneticField())
90 {}
91 
94  const Surface& aSurface,
95  const MagneticField* field,
96  const SurfaceSide side) :
97  theFreeState(0),
98  theLocalError(InvalidError()),
99  theLocalParameters(par),
100  theLocalParametersValid(true),
101  theGlobalParamsUp2Date(false),
102  theSurfaceSide(side),
103  theSurfaceP( &aSurface),
104  theWeight(1.),
105  theField(field)
106 {}
107 
110  const LocalTrajectoryError& err,
111  const Surface& aSurface,
112  const MagneticField* field,
113  const SurfaceSide side,
114  double weight) :
115  theFreeState(0),
116  theLocalError(err),
117  theLocalParameters(par),
118  theLocalParametersValid(true),
119  theGlobalParamsUp2Date(false),
120  theSurfaceSide(side),
121  theSurfaceP( &aSurface),
122  theWeight(weight),
123  theField(field)
124 {}
125 
128  const LocalTrajectoryError& err,
129  const Surface& aSurface,
130  const MagneticField* field,
131  double weight) :
132  theFreeState(0),
133  theLocalError(err),
134  theLocalParameters(par),
135  theLocalParametersValid(true),
136  theGlobalParamsUp2Date(false),
137  theSurfaceSide(SurfaceSideDefinition::atCenterOfSurface),
138  theSurfaceP( &aSurface),
139  theWeight(weight),
140  theField(field)
141 {}
142 
144 BasicTrajectoryState(const Surface& aSurface) :
145  theFreeState(0),
146  theLocalError(InvalidError()),
147  theLocalParameters(),
148  theLocalParametersValid(false),
149  theGlobalParamsUp2Date(false),
150  theSurfaceSide(SurfaceSideDefinition::atCenterOfSurface),
151  theSurfaceP( &aSurface),
152  theWeight(0.),
153  theField(0)
154 {}
155 
156 
158 
160  throw TrajectoryStateException("TrajectoryStateOnSurface is invalid and cannot return any parameters");
161 }
162 
163 namespace {
164  void verifyLocalErr(LocalTrajectoryError const & err ) {
165  if unlikely(!err.posDef())
166  edm::LogWarning("BasicTrajectoryState") << "local error not pos-def\n"
167  << err.matrix();
168  }
169  void verifyCurvErr(CurvilinearTrajectoryError const & err ) {
170  if unlikely(!err.posDef())
171  edm::LogWarning("BasicTrajectoryState") << "curv error not pos-def\n"
172  << err.matrix();
173  }
174 
175 }
176 
177 void BasicTrajectoryState::missingError(char const * where) const{
178  std::stringstream form;
179  form<<"BasicTrajectoryState: attempt to access errors when none available "
180  <<where<<".\nfreestate pointer: " <<theFreeState
181  <<"\nlocal error valid/values :"<< theLocalError.valid() << "\n"
182  << theLocalError.matrix();
183 
184  edm::LogWarning("BasicTrajectoryState") << form.str();
185 
186  // throw TrajectoryStateException(form.str());
187 }
188 
189 
190 
191 
193  if likely(theGlobalParamsUp2Date) return;
194 
195  // cout<<"!theGlobalParamsUp2Date"<<endl;
196  theGlobalParamsUp2Date = true;
197  // calculate global parameters from local
200  // replace in place
201  FreeTrajectoryState * fts = &(*theFreeState);
202  if (fts) {
203  fts->~FreeTrajectoryState();
205  }else {
208  theField));
209  }
210 }
211 
212 
213 
216 
218 
219 
221  const AlgebraicMatrix55& jac = loc2Curv.jacobian();
222 
223  const AlgebraicSymMatrix55 &cov = ROOT::Math::Similarity(jac, theLocalError.matrix());
224 
226 
227  verifyLocalErr(theLocalError);
228  verifyCurvErr(cov);
229 }
230 
231 
232 
233 // create local parameters from global
237 // believe p.z() never exactly equals 0.
238  bool isCharged = theFreeState->charge()!=0;
241  p.x()/p.z(), p.y()/p.z(), x.x(), x.y(), p.z()>0. ? 1.:-1., isCharged);
243 }
244 
248  else theLocalError = InvalidError();
249 }
250 
251 void
253 
255  const AlgebraicMatrix55& jac = curv2Loc.jacobian();
256 
257  const AlgebraicSymMatrix55 &cov =
258  ROOT::Math::Similarity(jac, theFreeState->curvilinearError().matrix());
259  // cout<<"Clocal via curvilinear error"<<endl;
261 
262  verifyCurvErr(theFreeState->curvilinearError());
263  verifyLocalErr(theLocalError);
264 
265 }
266 
267 
268 
269 void
271  const Surface& aSurface,
272  const MagneticField* field,
273  const SurfaceSide side)
274 {
276  if (&aSurface != &*theSurfaceP) theSurfaceP.reset(&aSurface);
277  theField=field;
278  theSurfaceSide = side;
279  theWeight = 1.0;
281 
282  theGlobalParamsUp2Date = false;
284 }
285 
286 void
288  const LocalTrajectoryError& err,
289  const Surface& aSurface,
290  const MagneticField* field,
291  const SurfaceSide side,
292  double weight)
293 {
295  theLocalError = err;
296  if (&aSurface != &*theSurfaceP) theSurfaceP.reset(&aSurface);
297  theField=field;
298  theSurfaceSide = side;
299  theWeight = weight;
300 
301  theGlobalParamsUp2Date = false;
303 
304 }
305 
306 void
308  if unlikely(!hasError()) missingError(" trying to rescale");
309  if (theFreeState)
310  theFreeState->rescaleError(factor);
311 
312  if (theLocalError.valid()){
313  //do it by hand if the free state is not around.
314  bool zeroField = (theField->nominalValue()==0);
315  if unlikely(zeroField){
317  //scale the 0 indexed covariance by the square root of the factor
318  for (unsigned int i=1;i!=5;++i) errors(i,0)*=factor;
319  double factor_squared=factor*factor;
320  //scale all others by the scaled factor
321  for (unsigned int i=1;i!=5;++i) for (unsigned int j=i;j!=5;++j) errors(i,j)*=factor_squared;
322  //term 0,0 is not scaled at all
324  }
325  else theLocalError *= (factor*factor);
326  }
327 }
328 
331  if(!isValid()) notValid();
333  if(withErrors && hasError()) { // this is the right thing
335  }
336  return &(*theFreeState);
337 }
338 
339 
340 
342 std::vector<TrajectoryStateOnSurface>
344  std::vector<TrajectoryStateOnSurface> result; result.reserve(1);
345  result.push_back( const_cast<BasicTrajectoryState*>(this));
346  return result;
347 }
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:78
const Surface & surface() const
int i
Definition: DBlmapReader.cc:9
dictionary parameters
Definition: Parameters.py:2
void createLocalErrorFromCurvilinearError() const dso_internal
ConstReferenceCountingPointer< Surface > theSurfaceP
int nominalValue() const
The nominal field value for this map in kGauss.
Definition: MagneticField.h:57
LocalPoint position() const
Local x and y position coordinates.
bool hasCurvilinearError() const
T y() const
Definition: PV3DBase.h:62
virtual void update(const LocalTrajectoryParameters &p, const Surface &aSurface, const MagneticField *field, const SurfaceSide side)
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
TrackCharge charge() const
const CurvilinearTrajectoryError & curvilinearError() const
void rescaleError(double factor)
void checkCurvilinError() const dso_internal
#define unlikely(x)
Definition: Likely.h:21
T mag() const
Definition: PV3DBase.h:66
DeepCopyPointer< FreeTrajectoryState > theFreeState
LocalPoint toLocal(const GlobalPoint &gp) const
T z() const
Definition: PV3DBase.h:63
tuple result
Definition: query.py:137
int j
Definition: DBlmapReader.cc:9
void createLocalParameters() const
const AlgebraicSymMatrix55 & matrix() const
LocalVector momentum() const
Momentum vector in the local frame.
GlobalVector momentum() const
void setCurvilinearError(const CurvilinearTrajectoryError &err)
const MagneticField * theField
GlobalPoint position() const
void rescaleError(double factor)
void checkGlobalParameters() const dso_internal
TrackCharge charge() const
Charge (-1, 0 or 1)
void replaceWith(T *otherP)
const AlgebraicMatrix55 & jacobian() const
virtual double weight() const
void missingError(char const *where) const
const LocalTrajectoryParameters & localParameters() const
#define likely(x)
Definition: Likely.h:20
const AlgebraicSymMatrix55 & matrix() const
virtual std::vector< TrajectoryStateOnSurface > components() const
LocalTrajectoryParameters theLocalParameters
const AlgebraicMatrix55 & jacobian() const
FreeTrajectoryState * freeTrajectoryState(bool withErrors=true) const
Definition: DDAxes.h:10
T x() const
Definition: PV3DBase.h:61
LocalTrajectoryError theLocalError
double signedInverseMomentum() const
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepStd< double, 5, 5 > > AlgebraicMatrix55