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,
50  const BasicTrajectoryState::SurfaceType& surface,
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),
76  theLocalParametersValid(true),
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 UNLIKELY (!err.posDef())
89  edm::LogWarning("BasicTrajectoryState") << "local error not pos-def\n"
90  << err.matrix() << "\npos/mom/mf " << state.position() << ' '
91  << state.momentum() << ' ' << state.parameters().magneticFieldInTesla();
92  }
93  void verifyCurvErr(CurvilinearTrajectoryError const& err, const FreeTrajectoryState& state) {
94  if UNLIKELY (!err.posDef())
95  edm::LogWarning("BasicTrajectoryState") << "curv error not pos-def\n"
96  << err.matrix() << "\npos/mom/mf " << state.position() << ' '
97  << state.momentum() << ' ' << state.parameters().magneticFieldInTesla();
98  }
99 } // namespace
100 
101 void BasicTrajectoryState::missingError(char const* where) const {
102  std::stringstream form;
103  form << "BasicTrajectoryState: attempt to access errors when none available " << where
104  << ".\nfreestate pointer: " << theFreeState << "\nlocal error valid/values :" << theLocalError.valid() << "\n"
105  << theLocalError.matrix();
106 
107  edm::LogWarning("BasicTrajectoryState") << form.str();
108 
109  // throw TrajectoryStateException(form.str());
110 }
111 
114  return;
115 
118 
120  const AlgebraicMatrix55& jac = loc2Curv.jacobian();
121  const AlgebraicSymMatrix55& cov = ROOT::Math::Similarity(jac, theLocalError.matrix());
122 
124 
125  verifyLocalErr(theLocalError, theFreeState);
126  verifyCurvErr(cov, theFreeState);
127 }
128 
129 // create local parameters from global
133  // believe p.z() never exactly equals 0.
134  bool isCharged = theFreeState.charge() != 0;
136  p.x() / p.z(),
137  p.y() / p.z(),
138  x.x(),
139  x.y(),
140  p.z() > 0. ? 1. : -1.,
141  isCharged);
143 }
144 
148  else
150 }
151 
154  const AlgebraicMatrix55& jac = curv2Loc.jacobian();
155 
156  theLocalError = ROOT::Math::Similarity(jac, theFreeState.curvilinearError().matrix());
157 
158  verifyCurvErr(theFreeState.curvilinearError(), theFreeState);
159  verifyLocalErr(theLocalError, theFreeState);
160 }
161 
162 // update in place and in the very same place
168 
169  theValid = true;
171 }
172 
174  const SurfaceType& aSurface,
175  const MagneticField* field,
176  const SurfaceSide side) {
178  if (&aSurface != &*theSurfaceP)
179  theSurfaceP.reset(&aSurface);
181  theWeight = 1.0;
183  theFreeState = makeFTS(p, aSurface, field);
184 
185  theValid = true;
187 }
188 
191  const LocalTrajectoryError& err,
192  const SurfaceType& aSurface,
193  const MagneticField* field,
194  const SurfaceSide side) {
196  theLocalError = err;
197  if (&aSurface != &*theSurfaceP)
198  theSurfaceP.reset(&aSurface);
200  theWeight = weight;
201  theFreeState = makeFTS(p, aSurface, field);
202 
203  theValid = true;
205 }
206 
208  const LocalTrajectoryError& err,
209  const SurfaceSide side) {
211  theLocalError = err;
215 
216  theValid = true;
218 }
219 
221  if UNLIKELY (!hasError())
222  missingError(" trying to rescale");
224 
225  if (theLocalError.valid()) {
226  //do it by hand if the free state is not around.
227  bool zeroField = (magneticField()->nominalValue() == 0);
228  if UNLIKELY (zeroField) {
230  //scale the 0 indexed covariance by the square root of the factor
231  for (unsigned int i = 1; i != 5; ++i)
232  errors(i, 0) *= factor;
233  double factor_squared = factor * factor;
234  //scale all others by the scaled factor
235  for (unsigned int i = 1; i != 5; ++i)
236  for (unsigned int j = i; j != 5; ++j)
237  errors(i, j) *= factor_squared;
238  //term 0,0 is not scaled at all
240  } else
241  theLocalError *= (factor * factor);
242  }
243 }
244 
247  edm::LogError("BasicSingleTrajectoryState") << "asking for componenets to a SingleTrajectoryState" << std::endl;
248  assert(false);
249 }
ConstReferenceCountingPointer< SurfaceType > theSurfaceP
BasicTrajectoryState::Components Components
const CurvilinearTrajectoryError & curvilinearError() const
const GlobalTrajectoryParameters & globalParameters() const
virtual void update(const LocalTrajectoryParameters &p, const SurfaceType &aSurface, const MagneticField *field, const SurfaceSide side)
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepStd< double, 5, 5 > > AlgebraicMatrix55
bool hasCurvilinearError() const
#define LIKELY(x)
Definition: Likely.h:20
Definition: weight.py:1
Log< level::Error, false > LogError
LocalPoint toLocal(const GlobalPoint &gp) const
assert(be >=bs)
const GlobalTrajectoryParameters & parameters() const
void rescaleError(double factor)
GlobalPoint position() const
const AlgebraicMatrix55 & jacobian() const
TrackCharge charge() const
LocalVector momentum() const
Momentum vector in the local frame.
const SurfaceType & surface() const
GlobalVector momentum() const
double signedInverseMomentum() const
Components const & components() const override
TrackCharge charge() const
Charge (-1, 0 or 1)
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:79
const AlgebraicMatrix55 & jacobian() const
void missingError(char const *where) const
void rescaleError(double factor)
const AlgebraicSymMatrix55 & matrix() const
FreeTrajectoryState theFreeState
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
CurvilinearTrajectoryError & setCurvilinearError()
const LocalTrajectoryParameters & localParameters() const
const AlgebraicSymMatrix55 & matrix() const
LocalTrajectoryParameters theLocalParameters
void createLocalErrorFromCurvilinearError() const
float x
int nominalValue() const
The nominal field value for this map in kGauss.
Definition: MagneticField.h:49
Definition: errors.py:1
#define UNLIKELY(x)
Definition: Likely.h:21
Log< level::Warning, false > LogWarning
LocalTrajectoryError theLocalError
LocalPoint position() const
Local x and y position coordinates.
const MagneticField * magneticField() const