Belle II Software  release-08-01-10
SpacepointMeasurement.cc
1 /* Copyright 2008-2010, Technische Universitaet Muenchen,
2  Authors: Christian Hoeppner & Sebastian Neubert & Johannes Rauch
3 
4  This file is part of GENFIT.
5 
6  GENFIT is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published
8  by the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  GENFIT is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with GENFIT. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "SpacepointMeasurement.h"
21 
22 #include "Exception.h"
23 #include "RKTrackRep.h"
24 #include "Tools.h"
25 #include "HMatrixUV.h"
26 #include "MeasurementOnPlane.h"
27 
28 #include <cassert>
29 #include <TBuffer.h>
30 
31 namespace genfit {
32 
33 SpacepointMeasurement::SpacepointMeasurement(int nDim)
34  : AbsMeasurement(nDim), weightedPlaneContruction_(true), G_(3), cutCov_(true)
35 {
36  assert(nDim >= 3);
37 
38  //this->initG();
39 }
40 
41 SpacepointMeasurement::SpacepointMeasurement(const TVectorD& rawHitCoords, const TMatrixDSym& rawHitCov, int detId, int hitId, TrackPoint* trackPoint,
42  bool weightedPlaneContruction, bool cutCov)
43  : AbsMeasurement(rawHitCoords, rawHitCov, detId, hitId, trackPoint),
44  weightedPlaneContruction_(weightedPlaneContruction), cutCov_(cutCov)
45 {
46  assert(rawHitCoords_.GetNrows() >= 3);
47 
48  if (weightedPlaneContruction_)
49  this->initG();
50 }
51 
52 
53 SharedPlanePtr SpacepointMeasurement::constructPlane(const StateOnPlane& state) const {
54 
55  // copy state. Neglect covariance.
56  StateOnPlane st(state);
57 
58  const TVector3 point(rawHitCoords_(0), rawHitCoords_(1), rawHitCoords_(2));
59 
60  if (weightedPlaneContruction_)
61  st.extrapolateToPoint(point, G_);
62  else
63  st.extrapolateToPoint(point);
64 
65  return st.getPlane();
66 }
67 
68 
69 std::vector<MeasurementOnPlane*> SpacepointMeasurement::constructMeasurementsOnPlane(const StateOnPlane& state) const
70 {
71  MeasurementOnPlane* mop = new MeasurementOnPlane(TVectorD(2),
72  TMatrixDSym(3), // will be resized to 2x2 by Similarity later
73  state.getPlane(), state.getRep(), constructHMatrix(state.getRep()));
74 
75  TVectorD& m = mop->getState();
76  TMatrixDSym& V = mop->getCov();
77 
78  const TVector3& o(state.getPlane()->getO());
79  const TVector3& u(state.getPlane()->getU());
80  const TVector3& v(state.getPlane()->getV());
81 
82  // m
83  m(0) = (rawHitCoords_(0)-o.X()) * u.X() +
84  (rawHitCoords_(1)-o.Y()) * u.Y() +
85  (rawHitCoords_(2)-o.Z()) * u.Z();
86 
87  m(1) = (rawHitCoords_(0)-o.X()) * v.X() +
88  (rawHitCoords_(1)-o.Y()) * v.Y() +
89  (rawHitCoords_(2)-o.Z()) * v.Z();
90 
91  //
92  // V
93  //
94  V = rawHitCov_;
95 
96  // jac = dF_i/dx_j = s_unitvec * t_untivec, with s=u,v and t=x,y,z
97  TMatrixD jac(3,2);
98  jac(0,0) = u.X();
99  jac(1,0) = u.Y();
100  jac(2,0) = u.Z();
101  jac(0,1) = v.X();
102  jac(1,1) = v.Y();
103  jac(2,1) = v.Z();
104 
105  if (cutCov_) { // cut (default)
106  tools::invertMatrix(V);
107  V.SimilarityT(jac);
108  tools::invertMatrix(V);
109  }
110  else { // projection
111  V.SimilarityT(jac);
112  }
113 
114  std::vector<MeasurementOnPlane*> retVal;
115  retVal.push_back(mop);
116  return retVal;
117 }
118 
119 
120 const AbsHMatrix* SpacepointMeasurement::constructHMatrix(const AbsTrackRep* rep) const {
121  if (dynamic_cast<const RKTrackRep*>(rep) == nullptr) {
122  Exception exc("SpacepointMeasurement default implementation can only handle state vectors of type RKTrackRep!", __LINE__,__FILE__);
123  throw exc;
124  }
125 
126  return new HMatrixUV();
127 }
128 
129 
130 void SpacepointMeasurement::initG() {
131  rawHitCov_.GetSub(0, 2, G_);
132  tools::invertMatrix(G_);
133 }
134 
135 
136 // Modified from auto-generated Streamer to account for non-persistent G_
137 void SpacepointMeasurement::Streamer(TBuffer &R__b)
138 {
139  // Stream an object of class genfit::SpacepointMeasurement.
140 
141  if (R__b.IsReading()) {
142  R__b.ReadClassBuffer(genfit::SpacepointMeasurement::Class(),this);
143 
144  if (weightedPlaneContruction_)
145  this->initG();
146  } else {
147  R__b.WriteClassBuffer(genfit::SpacepointMeasurement::Class(),this);
148  }
149 }
150 
151 
152 } /* End of namespace genfit */
HMatrix for projecting from AbsTrackRep parameters to measured parameters in a DetPlane.
Definition: AbsHMatrix.h:37
Abstract base class for a track representation.
Definition: AbsTrackRep.h:66
Exception class for error handling in GENFIT (provides storage for diagnostic information)
Definition: Exception.h:48
AbsHMatrix implementation for two-dimensional MeasurementOnPlane and RKTrackRep parameterization.
Definition: HMatrixUV.h:39
Measured coordinates on a plane.
AbsTrackRep with 5D track parameterization in plane coordinates: (q/p, u', v', u, v)
Definition: RKTrackRep.h:72
A state with arbitrary dimension defined in a DetPlane.
Definition: StateOnPlane.h:47
Defines for I/O streams used for error and debug printing.
std::shared_ptr< genfit::DetPlane > SharedPlanePtr
Shared Pointer to a DetPlane.