CMS 3D CMS Logo

BasicMultiTrajectoryState.cc
Go to the documentation of this file.
2 
5 
6 using namespace SurfaceSideDefinition;
7 
9  : BasicTrajectoryState(tsvec.front().surface()), theStates(tsvec) {
10  // only accept planes!!
11  const BoundPlane* bp = dynamic_cast<const BoundPlane*>(&tsvec.begin()->surface());
12  if UNLIKELY (bp == nullptr)
13  throw cms::Exception("LogicError") << "MultiTrajectoryState constructed on cylinder";
14 
15  for (auto i = tsvec.begin(); i != tsvec.end(); i++) {
16  if UNLIKELY (!i->isValid()) {
17  throw cms::Exception("LogicError") << "MultiTrajectoryState constructed with invalid state";
18  }
19  if UNLIKELY (i->hasError() != tsvec.front().hasError()) {
20  throw cms::Exception("LogicError") << "MultiTrajectoryState mixes states with and without errors";
21  }
22  if UNLIKELY (&i->surface() != &tsvec.front().surface()) {
23  throw cms::Exception("LogicError") << "MultiTrajectoryState mixes states with different surfaces";
24  }
25  if UNLIKELY (i->surfaceSide() != tsvec.front().surfaceSide()) {
26  throw cms::Exception("LogicError") << "MultiTrajectoryState mixes states defined before and after material";
27  }
28  if UNLIKELY (i->localParameters().pzSign() * tsvec.front().localParameters().pzSign() < 0.) {
29  throw cms::Exception("LogicError") << "MultiTrajectoryState mixes states with different signs of local p_z";
30  }
31  }
32  //
33  combine();
34 }
35 
37  if UNLIKELY (theStates.empty()) {
38  edm::LogError("BasicMultiTrajectoryState") << "Trying to rescale errors of empty MultiTrajectoryState!";
39  return;
40  }
41 
42  for (auto& is : theStates)
43  is.rescaleError(factor);
44  combine();
45 }
46 
48  const std::vector<TrajectoryStateOnSurface>& tsos = theStates;
49 
50  if UNLIKELY (tsos.empty()) {
51  edm::LogError("MultiTrajectoryStateCombiner") << "Trying to collapse empty set of trajectory states!";
52  return;
53  }
54 
55  double pzSign = tsos.front().localParameters().pzSign();
56  for (std::vector<TrajectoryStateOnSurface>::const_iterator it = tsos.begin(); it != tsos.end(); it++) {
57  if UNLIKELY (it->localParameters().pzSign() != pzSign) {
58  edm::LogError("MultiTrajectoryStateCombiner")
59  << "Trying to collapse trajectory states with different signs on p_z!";
60  return;
61  }
62  }
63 
64  if UNLIKELY (tsos.size() == 1) {
65  BasicTrajectoryState::update(tsos.front().weight(),
66  tsos.front().localParameters(),
67  tsos.front().localError(),
68  tsos.front().surface(),
69  tsos.front().magneticField(),
70  tsos.front().surfaceSide());
71  return;
72  }
73 
74  double sumw = 0.;
75  //int dim = tsos.front().localParameters().vector().num_row();
77  AlgebraicSymMatrix55 covarPart1, covarPart2, covtmp;
78  for (auto it1 = tsos.begin(); it1 != tsos.end(); it1++) {
79  auto weight = it1->weight();
80  auto const& param = it1->localParameters().vector();
81  sumw += weight;
82  mean += weight * param;
83  covarPart1 += weight * it1->localError().matrix();
84  for (auto it2 = it1 + 1; it2 != tsos.end(); it2++) {
85  AlgebraicVector5 diff = param - it2->localParameters().vector();
86  ROOT::Math::AssignSym::Evaluate(covtmp, ROOT::Math::TensorProd(diff, diff));
87  covarPart2 += (weight * it2->weight()) * covtmp;
88  }
89  }
90  double sumwI = 1.0 / sumw;
91  mean *= sumwI;
92  covarPart1 *= sumwI;
93  covarPart2 *= (sumwI * sumwI);
94  AlgebraicSymMatrix55 covar = covarPart1 + covarPart2;
95 
98  LocalTrajectoryError(covar),
99  tsos.front().surface(),
100  tsos.front().magneticField(),
101  tsos.front().surfaceSide());
102 }
103 
105  const Surface& aSurface,
106  const MagneticField* field,
107  const SurfaceSide side) {
108  throw cms::Exception("LogicError",
109  "BasicMultiTrajectoryState::update(LocalTrajectoryParameters, Surface, ...) called even if "
110  "canUpdateLocalParameters() is false");
111 }
112 
115  const LocalTrajectoryError& err,
116  const Surface& aSurface,
117  const MagneticField* field,
118  const SurfaceSide side) {
119  throw cms::Exception("LogicError",
120  "BasicMultiTrajectoryState::update(LocalTrajectoryParameters, LocalTrajectoryError, ...) called "
121  "even if canUpdateLocalParameters() is false");
122 }
virtual void update(const LocalTrajectoryParameters &p, const SurfaceType &aSurface, const MagneticField *field, const SurfaceSide side)
Definition: weight.py:1
void update(const LocalTrajectoryParameters &p, const Surface &aSurface, const MagneticField *field, const SurfaceSide side) override
Log< level::Error, false > LogError
ROOT::Math::SVector< double, 5 > AlgebraicVector5
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
#define UNLIKELY(x)
Definition: Likely.h:21