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
165  theSurfaceSide = side;
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);
180  theSurfaceSide = side;
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);
199  theSurfaceSide = side;
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;
212  theSurfaceSide = side;
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 }
Vector3DBase
Definition: Vector3DBase.h:8
JacobianCartesianToLocal.h
BasicTrajectoryState::magneticField
const MagneticField * magneticField() const
Definition: BasicTrajectoryState.h:222
FreeTrajectoryState::momentum
GlobalVector momentum() const
Definition: FreeTrajectoryState.h:68
TrajectoryStateOnSurface.h
mps_fire.i
i
Definition: mps_fire.py:428
BasicSingleTrajectoryState::Components
BasicTrajectoryState::Components Components
Definition: BasicSingleTrajectoryState.h:20
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
BasicTrajectoryState::weight
double weight() const
Definition: BasicTrajectoryState.h:248
GlobalTrajectoryParameters::magneticFieldInTesla
GlobalVector magneticFieldInTesla() const
Definition: GlobalTrajectoryParameters.h:104
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:246
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:220
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
SurfaceSideDefinition::atCenterOfSurface
Definition: SurfaceSideDefinition.h:8
BasicTrajectoryState::theLocalParametersValid
bool theLocalParametersValid
Definition: BasicTrajectoryState.h:306
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:152
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
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:246
Point3DBase< float, GlobalTag >
BasicTrajectoryState::theValid
bool theValid
Definition: BasicTrajectoryState.h:307
BasicTrajectoryState::notValid
static void notValid()
Definition: BasicTrajectoryState.cc:82
LocalTrajectoryError
Definition: LocalTrajectoryError.h:20
funct::true
true
Definition: Factorize.h:173
BasicTrajectoryState::hasError
bool hasError() const
Definition: BasicTrajectoryState.h:255
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
BasicTrajectoryState::createLocalParameters
void createLocalParameters() const
Definition: BasicTrajectoryState.cc:130
BasicTrajectoryState::theLocalError
LocalTrajectoryError theLocalError
Definition: BasicTrajectoryState.h:303
BasicTrajectoryState::theWeight
double theWeight
Definition: BasicTrajectoryState.h:312
BasicTrajectoryState::missingError
void missingError(char const *where) const
Definition: BasicTrajectoryState.cc:101
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:173
MagneticField.h
JacobianCurvilinearToLocal::jacobian
const AlgebraicMatrix55 & jacobian() const
Definition: JacobianCurvilinearToLocal.h:37
JacobianLocalToCurvilinear::jacobian
const AlgebraicMatrix55 & jacobian() const
Definition: JacobianLocalToCurvilinear.h:42
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
submitPVResolutionJobs.err
err
Definition: submitPVResolutionJobs.py:85
BasicTrajectoryState::~BasicTrajectoryState
virtual ~BasicTrajectoryState()
Definition: BasicTrajectoryState.cc:38
BasicTrajectoryState::theLocalParameters
LocalTrajectoryParameters theLocalParameters
Definition: BasicTrajectoryState.h:304
BasicTrajectoryState.h
RunInfoPI::state
state
Definition: RunInfoPayloadInspectoHelper.h:16
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
genVertex_cff.x
x
Definition: genVertex_cff.py:13
BasicTrajectoryState::createLocalError
void createLocalError() const
Definition: BasicTrajectoryState.cc:145
BasicTrajectoryState::localParameters
const LocalTrajectoryParameters & localParameters() const
Definition: BasicTrajectoryState.h:225
FreeTrajectoryState::setCurvilinearError
CurvilinearTrajectoryError & setCurvilinearError()
Definition: FreeTrajectoryState.h:100
JacobianCurvilinearToLocal.h
BasicTrajectoryState::theFreeState
FreeTrajectoryState theFreeState
Definition: BasicTrajectoryState.h:301
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
edm::Log
Definition: MessageLogger.h:70
BasicTrajectoryState::theSurfaceP
ConstReferenceCountingPointer< SurfaceType > theSurfaceP
Definition: BasicTrajectoryState.h:310
BasicTrajectoryState::checkCurvilinError
void checkCurvilinError() const
Definition: BasicTrajectoryState.cc:112
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:309
debug_messages_cfi.errors
errors
Definition: debug_messages_cfi.py:54