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
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");
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 }
Vector3DBase
Definition: Vector3DBase.h:8
JacobianCartesianToLocal.h
BasicTrajectoryState::magneticField
const MagneticField * magneticField() const
Definition: BasicTrajectoryState.h:224
FreeTrajectoryState::momentum
GlobalVector momentum() const
Definition: FreeTrajectoryState.h:68
TrajectoryStateOnSurface.h
mps_fire.i
i
Definition: mps_fire.py:355
BasicSingleTrajectoryState::Components
BasicTrajectoryState::Components Components
Definition: BasicSingleTrajectoryState.h:20
MessageLogger.h
funct::false
false
Definition: Factorize.h:34
BasicTrajectoryState::weight
double weight() const
Definition: BasicTrajectoryState.h:252
GlobalTrajectoryParameters::magneticFieldInTesla
GlobalVector magneticFieldInTesla() const
Definition: GlobalTrajectoryParameters.h:104
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
Printer
Definition: Printer.py:1
gather_cfg.cout
cout
Definition: gather_cfg.py:144
FreeTrajectoryState::charge
TrackCharge charge() const
Definition: FreeTrajectoryState.h:69
BasicSingleTrajectoryState::components
Components const & components() const override
Definition: BasicTrajectoryState.cc:250
MessageLogger_cfi.errors
errors
Definition: MessageLogger_cfi.py:18
cms::cuda::assert
assert(be >=bs)
Surface
Definition: Surface.h:36
SurfaceSideDefinition::SurfaceSide
SurfaceSide
Definition: SurfaceSideDefinition.h:8
FreeTrajectoryState::signedInverseMomentum
double signedInverseMomentum() const
Definition: FreeTrajectoryState.h:70
LocalTrajectoryError::matrix
const AlgebraicSymMatrix55 & matrix() const
Definition: LocalTrajectoryError.h:60
DDAxes::x
LocalTrajectoryError::valid
bool valid() const
Definition: LocalTrajectoryError.h:32
FreeTrajectoryState::position
GlobalPoint position() const
Definition: FreeTrajectoryState.h:67
BasicTrajectoryState::rescaleError
void rescaleError(double factor)
Definition: BasicTrajectoryState.cc:222
SurfaceSideDefinition::atCenterOfSurface
Definition: SurfaceSideDefinition.h:8
BasicTrajectoryState::theLocalParametersValid
bool theLocalParametersValid
Definition: BasicTrajectoryState.h:310
LocalTrajectoryParameters
Definition: LocalTrajectoryParameters.h:25
UNLIKELY
#define UNLIKELY(x)
Definition: Likely.h:21
JacobianCurvilinearToLocal
Definition: JacobianCurvilinearToLocal.h:19
AlgebraicMatrix55
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepStd< double, 5, 5 > > AlgebraicMatrix55
Definition: AlgebraicROOTObjects.h:55
CurvilinearTrajectoryError
Definition: CurvilinearTrajectoryError.h:27
JacobianLocalToCurvilinear.h
BasicTrajectoryState::BasicTrajectoryState
BasicTrajectoryState()
Definition: BasicTrajectoryState.h:76
errors
Definition: errors.py:1
LocalTrajectoryParameters::position
LocalPoint position() const
Local x and y position coordinates.
Definition: LocalTrajectoryParameters.h:85
BasicTrajectoryState::createLocalErrorFromCurvilinearError
void createLocalErrorFromCurvilinearError() const
Definition: BasicTrajectoryState.cc:154
FreeTrajectoryState::curvilinearError
const CurvilinearTrajectoryError & curvilinearError() const
Definition: FreeTrajectoryState.h:89
TrajectoryStateException
Common base class.
Definition: TrajectoryStateExceptions.h:12
BasicTrajectoryState::globalParameters
const GlobalTrajectoryParameters & globalParameters() const
Definition: BasicTrajectoryState.h:189
vertices_cff.x
x
Definition: vertices_cff.py:29
Surface::toGlobal
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:79
JacobianLocalToCartesian.h
MagneticField::nominalValue
int nominalValue() const
The nominal field value for this map in kGauss.
Definition: MagneticField.h:49
DQMScaleToClient_cfi.factor
factor
Definition: DQMScaleToClient_cfi.py:8
LocalTrajectoryParameters::charge
TrackCharge charge() const
Charge (-1, 0 or 1)
Definition: LocalTrajectoryParameters.h:110
BasicTrajectoryState::surface
const SurfaceType & surface() const
Definition: BasicTrajectoryState.h:250
Point3DBase< float, GlobalTag >
edm::LogWarning
Definition: MessageLogger.h:141
BasicTrajectoryState::theValid
bool theValid
Definition: BasicTrajectoryState.h:311
BasicTrajectoryState::notValid
static void notValid()
Definition: BasicTrajectoryState.cc:82
LocalTrajectoryError
Definition: LocalTrajectoryError.h:20
funct::true
true
Definition: Factorize.h:173
edm::LogError
Definition: MessageLogger.h:183
BasicTrajectoryState::hasError
bool hasError() const
Definition: BasicTrajectoryState.h:259
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
runTheMatrix.err
err
Definition: runTheMatrix.py:288
BasicTrajectoryState::createLocalParameters
void createLocalParameters() const
Definition: BasicTrajectoryState.cc:132
BasicTrajectoryState::theLocalError
LocalTrajectoryError theLocalError
Definition: BasicTrajectoryState.h:307
BasicTrajectoryState::theWeight
double theWeight
Definition: BasicTrajectoryState.h:316
BasicTrajectoryState::missingError
void missingError(char const *where) const
Definition: BasicTrajectoryState.cc:103
SurfaceSideDefinition
Definition: SurfaceSideDefinition.h:7
FreeTrajectoryState::parameters
const GlobalTrajectoryParameters & parameters() const
Definition: FreeTrajectoryState.h:79
BasicTrajectoryState::update
virtual void update(const LocalTrajectoryParameters &p, const SurfaceType &aSurface, const MagneticField *field, const SurfaceSide side)
Definition: BasicTrajectoryState.cc:175
MagneticField.h
JacobianCurvilinearToLocal::jacobian
const AlgebraicMatrix55 & jacobian() const
Definition: JacobianCurvilinearToLocal.h:37
JacobianLocalToCurvilinear::jacobian
const AlgebraicMatrix55 & jacobian() const
Definition: JacobianLocalToCurvilinear.h:42
BasicTrajectoryState::~BasicTrajectoryState
virtual ~BasicTrajectoryState()
Definition: BasicTrajectoryState.cc:38
BasicTrajectoryState::theLocalParameters
LocalTrajectoryParameters theLocalParameters
Definition: BasicTrajectoryState.h:308
BasicTrajectoryState.h
FreeTrajectoryState
Definition: FreeTrajectoryState.h:27
LocalTrajectoryParameters::momentum
LocalVector momentum() const
Momentum vector in the local frame.
Definition: LocalTrajectoryParameters.h:88
LIKELY
#define LIKELY(x)
Definition: Likely.h:20
GloballyPositioned::toLocal
LocalPoint toLocal(const GlobalPoint &gp) const
Definition: GloballyPositioned.h:98
BasicTrajectoryState::createLocalError
void createLocalError() const
Definition: BasicTrajectoryState.cc:147
BasicTrajectoryState::localParameters
const LocalTrajectoryParameters & localParameters() const
Definition: BasicTrajectoryState.h:227
FreeTrajectoryState::setCurvilinearError
CurvilinearTrajectoryError & setCurvilinearError()
Definition: FreeTrajectoryState.h:100
JacobianCurvilinearToLocal.h
BasicTrajectoryState::theFreeState
FreeTrajectoryState theFreeState
Definition: BasicTrajectoryState.h:305
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
JacobianLocalToCurvilinear
Definition: JacobianLocalToCurvilinear.h:21
FreeTrajectoryState::hasCurvilinearError
bool hasCurvilinearError() const
Definition: FreeTrajectoryState.h:75
MagneticField
Definition: MagneticField.h:19
AlgebraicSymMatrix55
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
Definition: AlgebraicROOTObjects.h:23
BasicTrajectoryState::theSurfaceP
ConstReferenceCountingPointer< SurfaceType > theSurfaceP
Definition: BasicTrajectoryState.h:314
BasicTrajectoryState::checkCurvilinError
void checkCurvilinError() const
Definition: BasicTrajectoryState.cc:114
CurvilinearTrajectoryError::matrix
const AlgebraicSymMatrix55 & matrix() const
Definition: CurvilinearTrajectoryError.h:61
weight
Definition: weight.py:1
FreeTrajectoryState::rescaleError
void rescaleError(double factor)
Definition: FreeTrajectoryState.cc:46
InvalidError
Definition: TrivialError.h:8
BasicTrajectoryState::theSurfaceSide
SurfaceSide theSurfaceSide
Definition: BasicTrajectoryState.h:313