CMS 3D CMS Logo

BasicTrajectoryState.cc
Go to the documentation of this file.
8 
9 #include <cmath>
10 #include <sstream>
11 
12 #ifdef DO_BTSCount
13 unsigned int BTSCount::maxReferences = 0;
14 unsigned long long BTSCount::aveReferences = 0;
15 unsigned long long BTSCount::toteReferences = 0;
16 
17 BTSCount::~BTSCount() {
18  maxReferences = std::max(referenceMax_, maxReferences);
19  toteReferences++;
20  aveReferences += referenceMax_;
21  // if (referenceMax_>100) std::cout <<"BST with " << referenceMax_ << std::endl;
22 }
23 
24 #include <iostream>
25 namespace {
26 
27  struct Printer {
28  ~Printer() {
29  std::cout << "maxReferences of BTSCount = " << BTSCount::maxReferences << " "
30  << double(BTSCount::aveReferences) / double(BTSCount::toteReferences) << std::endl;
31  }
32  };
33  Printer printer;
34 
35 } // namespace
36 #endif
37 
40  : theLocalError(InvalidError()),
41  theLocalParameters(),
42  theLocalParametersValid(false),
43  theValid(false),
45  theSurfaceP(&aSurface),
46  theWeight(1.) {}
47 
48 namespace {
49  inline FreeTrajectoryState makeFTS(const LocalTrajectoryParameters& par,
51  const MagneticField* field) {
52  GlobalPoint x = surface.toGlobal(par.position());
53  GlobalVector p = surface.toGlobal(par.momentum());
54  return FreeTrajectoryState(x, p, par.charge(), field);
55  }
56 
57  inline FreeTrajectoryState makeFTS(const LocalTrajectoryParameters& par,
58  const BasicTrajectoryState::SurfaceType& surface,
59  const MagneticField* field,
60  GlobalVector fieldValue) {
61  GlobalPoint x = surface.toGlobal(par.position());
62  GlobalVector p = surface.toGlobal(par.momentum());
63  return FreeTrajectoryState(x, p, par.charge(), field, fieldValue);
64  }
65 
66 } // namespace
67 
70  const SurfaceType& aSurface,
71  const MagneticField* field,
72  const SurfaceSide side)
73  : theFreeState(makeFTS(par, aSurface, field)),
74  theLocalError(err),
75  theLocalParameters(par),
77  theValid(true),
78  theSurfaceSide(side),
79  theSurfaceP(&aSurface),
80  theWeight(1.) {}
81 
83  throw TrajectoryStateException("TrajectoryStateOnSurface is invalid and cannot return any parameters");
84 }
85 
86 namespace {
87  void verifyLocalErr(LocalTrajectoryError const& err, const FreeTrajectoryState& state) {
88  if
89  UNLIKELY(!err.posDef())
90  edm::LogWarning("BasicTrajectoryState") << "local error not pos-def\n"
91  << err.matrix() << "\npos/mom/mf " << state.position() << ' '
92  << state.momentum() << ' ' << state.parameters().magneticFieldInTesla();
93  }
94  void verifyCurvErr(CurvilinearTrajectoryError const& err, const FreeTrajectoryState& state) {
95  if
96  UNLIKELY(!err.posDef())
97  edm::LogWarning("BasicTrajectoryState") << "curv error not pos-def\n"
98  << err.matrix() << "\npos/mom/mf " << state.position() << ' '
99  << state.momentum() << ' ' << state.parameters().magneticFieldInTesla();
100  }
101 } // namespace
102 
103 void BasicTrajectoryState::missingError(char const* where) const {
104  std::stringstream form;
105  form << "BasicTrajectoryState: attempt to access errors when none available " << where
106  << ".\nfreestate pointer: " << theFreeState << "\nlocal error valid/values :" << theLocalError.valid() << "\n"
107  << theLocalError.matrix();
108 
109  edm::LogWarning("BasicTrajectoryState") << form.str();
110 
111  // throw TrajectoryStateException(form.str());
112 }
113 
115  if
117 
118  if
120 
122  const AlgebraicMatrix55& jac = loc2Curv.jacobian();
123  const AlgebraicSymMatrix55& cov = ROOT::Math::Similarity(jac, theLocalError.matrix());
124 
126 
127  verifyLocalErr(theLocalError, theFreeState);
128  verifyCurvErr(cov, theFreeState);
129 }
130 
131 // create local parameters from global
135  // believe p.z() never exactly equals 0.
136  bool isCharged = theFreeState.charge() != 0;
138  p.x() / p.z(),
139  p.y() / p.z(),
140  x.x(),
141  x.y(),
142  p.z() > 0. ? 1. : -1.,
143  isCharged);
145 }
146 
148  if
151  else theLocalError = InvalidError();
152 }
153 
156  const AlgebraicMatrix55& jac = curv2Loc.jacobian();
157 
158  theLocalError = ROOT::Math::Similarity(jac, theFreeState.curvilinearError().matrix());
159 
160  verifyCurvErr(theFreeState.curvilinearError(), theFreeState);
161  verifyLocalErr(theLocalError, theFreeState);
162 }
163 
164 // update in place and in the very same place
167  theSurfaceSide = side;
170 
171  theValid = true;
173 }
174 
176  const SurfaceType& aSurface,
177  const MagneticField* field,
178  const SurfaceSide side) {
180  if (&aSurface != &*theSurfaceP)
181  theSurfaceP.reset(&aSurface);
182  theSurfaceSide = side;
183  theWeight = 1.0;
185  theFreeState = makeFTS(p, aSurface, field);
186 
187  theValid = true;
189 }
190 
193  const LocalTrajectoryError& err,
194  const SurfaceType& aSurface,
195  const MagneticField* field,
196  const SurfaceSide side) {
198  theLocalError = err;
199  if (&aSurface != &*theSurfaceP)
200  theSurfaceP.reset(&aSurface);
201  theSurfaceSide = side;
202  theWeight = weight;
203  theFreeState = makeFTS(p, aSurface, field);
204 
205  theValid = true;
207 }
208 
210  const LocalTrajectoryError& err,
211  const SurfaceSide side) {
213  theLocalError = err;
214  theSurfaceSide = side;
217 
218  theValid = true;
220 }
221 
223  if
224  UNLIKELY(!hasError()) missingError(" trying to rescale");
225  theFreeState.rescaleError(factor);
226 
227  if (theLocalError.valid()) {
228  //do it by hand if the free state is not around.
229  bool zeroField = (magneticField()->nominalValue() == 0);
230  if
231  UNLIKELY(zeroField) {
233  //scale the 0 indexed covariance by the square root of the factor
234  for (unsigned int i = 1; i != 5; ++i)
235  errors(i, 0) *= factor;
236  double factor_squared = factor * factor;
237  //scale all others by the scaled factor
238  for (unsigned int i = 1; i != 5; ++i)
239  for (unsigned int j = i; j != 5; ++j)
240  errors(i, j) *= factor_squared;
241  //term 0,0 is not scaled at all
243  }
244  else
245  theLocalError *= (factor * factor);
246  }
247 }
248 
251  edm::LogError("BasicSingleTrajectoryState") << "asking for componenets to a SingleTrajectoryState" << std::endl;
252  assert(false);
253 }
ConstReferenceCountingPointer< SurfaceType > theSurfaceP
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:81
BasicTrajectoryState::Components Components
const MagneticField * magneticField() const
const GlobalTrajectoryParameters & parameters() const
int nominalValue() const
The nominal field value for this map in kGauss.
Definition: MagneticField.h:49
LocalPoint position() const
Local x and y position coordinates.
bool hasCurvilinearError() const
virtual void update(const LocalTrajectoryParameters &p, const SurfaceType &aSurface, const MagneticField *field, const SurfaceSide side)
Components const & components() const override
T y() const
Definition: PV3DBase.h:60
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepStd< double, 5, 5 > > AlgebraicMatrix55
#define LIKELY(x)
Definition: Likely.h:20
Definition: weight.py:1
TrackCharge charge() const
const CurvilinearTrajectoryError & curvilinearError() const
void rescaleError(double factor)
T mag() const
Definition: PV3DBase.h:64
void createLocalErrorFromCurvilinearError() const
LocalPoint toLocal(const GlobalPoint &gp) const
GlobalVector magneticFieldInTesla() const
T z() const
Definition: PV3DBase.h:61
void createLocalParameters() const
const AlgebraicSymMatrix55 & matrix() const
LocalVector momentum() const
Momentum vector in the local frame.
GlobalVector momentum() const
GlobalPoint position() const
const SurfaceType & surface() const
const GlobalTrajectoryParameters & globalParameters() const
void rescaleError(double factor)
FreeTrajectoryState theFreeState
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
CurvilinearTrajectoryError & setCurvilinearError()
TrackCharge charge() const
Charge (-1, 0 or 1)
const AlgebraicMatrix55 & jacobian() const
void missingError(char const *where) const
const LocalTrajectoryParameters & localParameters() const
const AlgebraicSymMatrix55 & matrix() const
LocalTrajectoryParameters theLocalParameters
const AlgebraicMatrix55 & jacobian() const
Definition: errors.py:1
#define UNLIKELY(x)
Definition: Likely.h:21
T x() const
Definition: PV3DBase.h:59
LocalTrajectoryError theLocalError
double signedInverseMomentum() const