CMS 3D CMS Logo

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