CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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()) {
10 
11  // only accept planes!!
12  const BoundPlane* bp = dynamic_cast<const BoundPlane*>(&tsvec.begin()->surface());
13  if unlikely( bp==0 )
14  throw cms::Exception("LogicError") << "MultiTrajectoryState constructed on cylinder";
15 
16  theStates.reserve(tsvec.size());
17  for (std::vector<TSOS>::const_iterator i=tsvec.begin(); i!=tsvec.end(); i++) {
18  if unlikely(!i->isValid()) {
19  throw cms::Exception("LogicError") << "MultiTrajectoryState constructed with invalid state";
20  }
21  if unlikely(i->hasError() != tsvec.front().hasError()) {
22  throw cms::Exception("LogicError") << "MultiTrajectoryState mixes states with and without errors";
23  }
24  if unlikely( &i->surface() != &tsvec.front().surface()) {
25  throw cms::Exception("LogicError") << "MultiTrajectoryState mixes states with different surfaces";
26  }
27  if unlikely( i->surfaceSide() != tsvec.front().surfaceSide()) {
28  throw cms::Exception("LogicError")
29  << "MultiTrajectoryState mixes states defined before and after material";
30  }
31  if unlikely( i->localParameters().pzSign()*tsvec.front().localParameters().pzSign()<0. ) {
32  throw cms::Exception("LogicError")
33  << "MultiTrajectoryState mixes states with different signs of local p_z";
34  }
35 
36  theStates.push_back( *i);
37  }
38  combine();
39 }
40 
41 
42 
44 
45  if unlikely(theStates.empty()) {
46  edm::LogError("BasicMultiTrajectoryState") << "Trying to rescale errors of empty MultiTrajectoryState!";
47  return;
48  }
49 
50  for (std::vector<TSOS>::iterator it = theStates.begin(); it != theStates.end(); it++) {
51  it->rescaleError(factor);
52  }
53  combine();
54 }
55 
56 void
58  const std::vector<TrajectoryStateOnSurface>& tsos = theStates;
59 
60  if unlikely(tsos.empty()) {
61  edm::LogError("MultiTrajectoryStateCombiner")
62  << "Trying to collapse empty set of trajectory states!";
63  return;
64  }
65 
66  double pzSign = tsos.front().localParameters().pzSign();
67  for (std::vector<TrajectoryStateOnSurface>::const_iterator it = tsos.begin();
68  it != tsos.end(); it++) {
69  if unlikely(it->localParameters().pzSign() != pzSign) {
70  edm::LogError("MultiTrajectoryStateCombiner")
71  << "Trying to collapse trajectory states with different signs on p_z!";
72  return;
73  }
74  }
75 
76  if unlikely(tsos.size() == 1) {
77  BasicTrajectoryState::update(tsos.front().localParameters(),
78  tsos.front().localError(),
79  tsos.front().surface(),
80  tsos.front().magneticField(),
81  tsos.front().surfaceSide(),
82  tsos.front().weight()
83  );
84  return;
85  }
86 
87  double sumw = 0.;
88  //int dim = tsos.front().localParameters().vector().num_row();
90  AlgebraicSymMatrix55 covarPart1, covarPart2;
91  for (std::vector<TrajectoryStateOnSurface>::const_iterator it1 = tsos.begin();
92  it1 != tsos.end(); it1++) {
93  double weight = it1->weight();
94  AlgebraicVector5 param = it1->localParameters().vector();
95  sumw += weight;
96  mean += weight * param;
97  covarPart1 += weight * it1->localError().matrix();
98  for (std::vector<TrajectoryStateOnSurface>::const_iterator it2 = it1 + 1;
99  it2 != tsos.end(); it2++) {
100  AlgebraicVector5 diff = param - it2->localParameters().vector();
101  AlgebraicSymMatrix11 s = AlgebraicMatrixID(); //stupid trick to make CLHEP work decently
102  covarPart2 += (weight * it2->weight()) *
103  ROOT::Math::Similarity(AlgebraicMatrix51(diff.Array(), 5), s);
104  //FIXME: we can surely write this thing in a better way
105  }
106  }
107  double sumwI = 1.0/sumw;
108  mean *= sumwI;
109  covarPart1 *= sumwI; covarPart2 *= (sumwI*sumwI);
110  AlgebraicSymMatrix55 covar = covarPart1 + covarPart2;
111 
113  LocalTrajectoryError(covar),
114  tsos.front().surface(),
115  tsos.front().magneticField(),
116  tsos.front().surfaceSide(),
117  sumw);
118 }
119 
120 void
123  const Surface& aSurface,
124  const MagneticField* field,
125  const SurfaceSide side)
126 {
127  throw cms::Exception("LogicError",
128  "BasicMultiTrajectoryState::update(LocalTrajectoryParameters, Surface, ...) called even if canUpdateLocalParameters() is false");
129 }
130 
131 void
134  const LocalTrajectoryError& err,
135  const Surface& aSurface,
136  const MagneticField* field,
137  const SurfaceSide side,
138  double weight)
139 {
140  throw cms::Exception("LogicError",
141  "BasicMultiTrajectoryState::update(LocalTrajectoryParameters, LocalTrajectoryError, ...) called even if canUpdateLocalParameters() is false");
142 }
143 
int i
Definition: DBlmapReader.cc:9
ROOT::Math::SMatrixIdentity AlgebraicMatrixID
ROOT::Math::SMatrix< double, 5, 1, ROOT::Math::MatRepStd< double, 5, 1 > > AlgebraicMatrix51
virtual void update(const LocalTrajectoryParameters &p, const Surface &aSurface, const MagneticField *field, const SurfaceSide side)
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
#define unlikely(x)
Definition: Likely.h:21
virtual void update(const LocalTrajectoryParameters &p, const Surface &aSurface, const MagneticField *field, const SurfaceSide side)
ROOT::Math::SVector< double, 5 > AlgebraicVector5
virtual double weight() const
ROOT::Math::SMatrix< double, 1, 1, ROOT::Math::MatRepSym< double, 1 > > AlgebraicSymMatrix11