CMS 3D CMS Logo

DTRecSegment4D.cc
Go to the documentation of this file.
1 
7 /* This Class Header */
9 
10 /* Collaborating Class Header */
13 /* C++ Headers */
14 
16  const DTSLRecSegment2D& zedSeg,
17  const LocalPoint& posZInCh,
18  const LocalVector& dirZInCh)
19  : RecSegment(phiSeg.chamberId()), theProjection(full), thePhiSeg(phiSeg), theZedSeg(zedSeg), theDimension(4) {
20  // Check consistency of 2 sub-segments
21  if (DTChamberId(phiSeg.geographicalId().rawId()) != DTChamberId(zedSeg.geographicalId().rawId()))
22  throw cms::Exception("DTRecSegment4D")
23  << "the z Segment and the phi segment have different chamber id" << std::endl;
24 
25  // The position of 2D segments are defined in the SL frame: I must first
26  // extrapolate that position at the Chamber reference plane
27  LocalPoint posZAt0 = posZInCh + dirZInCh * (-posZInCh.z()) / cos(dirZInCh.theta());
28 
29  thePosition = LocalPoint(phiSeg.localPosition().x(), posZAt0.y(), 0.);
30  LocalVector dirPhiInCh = phiSeg.localDirection();
31 
32  // given the actual definition of chamber refFrame, (with z poiniting to IP),
33  // the zed component of direction is negative.
34  theDirection = LocalVector(dirPhiInCh.x() / fabs(dirPhiInCh.z()), dirZInCh.y() / fabs(dirZInCh.z()), -1.);
36 
37  // set cov matrix
39  theCovMatrix[0][0] = phiSeg.covMatrix()[0][0]; //sigma (dx/dz)
40  theCovMatrix[0][2] = phiSeg.covMatrix()[0][1]; //cov(dx/dz,x)
41  theCovMatrix[2][2] = phiSeg.covMatrix()[1][1]; //sigma (x)
42  setCovMatrixForZed(posZInCh);
43 }
44 
46  : RecSegment(phiSeg.chamberId()),
47  theProjection(phi),
48  thePhiSeg(phiSeg),
49  theZedSeg(DTSLRecSegment2D()),
50  theDimension(2) {
52 
54 
55  // set cov matrix
57  theCovMatrix[0][0] = phiSeg.covMatrix()[0][0]; //sigma (dx/dz)
58  theCovMatrix[0][2] = phiSeg.covMatrix()[0][1]; //cov(dx/dz,x)
59  theCovMatrix[2][2] = phiSeg.covMatrix()[1][1]; //sigma (x)
60 }
61 
62 DTRecSegment4D::DTRecSegment4D(const DTSLRecSegment2D& zedSeg, const LocalPoint& posZInCh, const LocalVector& dirZInCh)
63  : RecSegment(zedSeg.superLayerId().chamberId()),
64  theProjection(Z),
65  thePhiSeg(DTChamberRecSegment2D()),
66  theZedSeg(zedSeg),
67  theDimension(2) {
68  LocalPoint posZAt0 = posZInCh + dirZInCh * (-posZInCh.z() / cos(dirZInCh.theta()));
69 
70  thePosition = posZAt0;
71  theDirection = dirZInCh;
72 
73  // set cov matrix
75  setCovMatrixForZed(posZInCh);
76 }
77 
79 
81  if (dimension() == 4) {
82  // (dx/dz,dy/dz,x,y)
84  result[2] = thePosition.x();
85  result[3] = thePosition.y();
86  result[0] = theDirection.x() / theDirection.z();
87  result[1] = theDirection.y() / theDirection.z();
88  return result;
89  }
90 
92  if (theProjection == phi) {
93  // (dx/dz,x)
94  result[1] = thePosition.x();
95  result[0] = theDirection.x() / theDirection.z();
96  } else if (theProjection == Z) {
97  // (dy/dz,y) (note we are in the chamber r.f.)
98  result[1] = thePosition.y();
99  result[0] = theDirection.y() / theDirection.z();
100  }
101  return result;
102 }
103 
105  if (dimension() == 4) {
106  return theCovMatrix;
107  }
108 
110  if (theProjection == phi) {
111  result[0][0] = theCovMatrix[0][0]; //S(dx/dz)
112  result[0][1] = theCovMatrix[0][2]; //Cov(dx/dz,x)
113  result[1][1] = theCovMatrix[2][2]; //S(x)
114  } else if (theProjection == Z) {
115  result[0][0] = theCovMatrix[1][1]; //S(dy/dz)
116  result[0][1] = theCovMatrix[1][3]; //Cov(dy/dz,y)
117  result[1][1] = theCovMatrix[3][3]; //S(y)
118  }
119  return result;
120 }
121 
122 //These methods are only used to initialize the const static values
123 // used by projectionMatrix().
126  the4DProjectionMatrix[0][1] = 1;
127  the4DProjectionMatrix[1][2] = 1;
128  the4DProjectionMatrix[2][3] = 1;
129  the4DProjectionMatrix[3][4] = 1;
130  return the4DProjectionMatrix;
131 }
133 
136  the2DPhiProjMatrix[0][1] = 1;
137  the2DPhiProjMatrix[1][3] = 1;
138  return the2DPhiProjMatrix;
139 }
141 
144  the2DZProjMatrix[0][2] = 1;
145  the2DZProjMatrix[1][4] = 1;
146  return the2DZProjMatrix;
147 }
149 
151  if (dimension() == 4) {
152  return the4DProjectionMatrix;
153  } else if (theProjection == phi) {
154  return the2DPhiProjMatrix;
155  } else if (theProjection == Z) {
156  return the2DZProjMatrix;
157  } else {
158  return AlgebraicMatrix();
159  }
160 }
161 
163  return LocalError(theCovMatrix[2][2], theCovMatrix[2][3], theCovMatrix[3][3]);
164 }
165 
167  return LocalError(theCovMatrix[0][0], theCovMatrix[0][1], theCovMatrix[1][1]);
168 }
169 
170 double DTRecSegment4D::chi2() const {
171  double result = 0;
172  if (hasPhi())
173  result += thePhiSeg.chi2();
174  if (hasZed())
175  result += theZedSeg.chi2();
176  return result;
177 }
178 
180  int result = 0;
181  if (hasPhi())
183  if (hasZed())
185  return result;
186 }
187 
189  // Warning!!! the covariance matrix for Theta SL segment is defined in the SL
190  // reference frame, here that in the Chamber ref frame must be used.
191  // For direction, no problem, but the position is extrapolated, so we must
192  // propagate the error properly.
193 
194  // many thanks to Paolo Ronchese for the help in deriving the formulas!
195 
196  // y=m*z+q in SL frame
197  // y=m'*z+q' in CH frame
198 
199  // var(m') = var(m)
200  theCovMatrix[1][1] = theZedSeg.parametersError()[0][0]; //sigma (dy/dz)
201 
202  // cov(m',q') = DeltaZ*Var(m) + Cov(m,q)
203  theCovMatrix[1][3] =
204  posZInCh.z() * theZedSeg.parametersError()[0][0] + theZedSeg.parametersError()[0][1]; //cov(dy/dz,y)
205 
206  // Var(q') = DeltaZ^2*Var(m) + Var(q) + 2*DeltaZ*Cov(m,q)
207  // cout << "Var(q') = DeltaZ^2*Var(m) + Var(q) + 2*DeltaZ*Cov(m,q)" << endl;
208  // cout << "Var(q')= " << posZInCh.z()*posZInCh.z() << "*" <<
209  // theZedSeg.parametersError()[0][0] << " + " <<
210  // theZedSeg.parametersError()[1][1] << " + " <<
211  // 2*posZInCh.z() << "*" << theZedSeg.parametersError()[0][1] ;
212  theCovMatrix[3][3] = 2. * (posZInCh.z() * posZInCh.z()) * theZedSeg.parametersError()[0][0] +
213  theZedSeg.parametersError()[1][1] + 2. * posZInCh.z() * theZedSeg.parametersError()[0][1];
214  // cout << " = " << theCovMatrix[3][3] << endl;
215 }
216 
217 std::ostream& operator<<(std::ostream& os, const DTRecSegment4D& seg) {
218  os << "Pos " << seg.localPosition() << " Dir: " << seg.localDirection() << " dim: " << seg.dimension()
219  << " chi2/ndof: " << seg.chi2() << "/" << seg.degreesOfFreedom() << " :";
220  if (seg.hasPhi())
221  os << seg.phiSegment()->recHits().size();
222  else
223  os << 0;
224  os << ":";
225  if (seg.hasZed())
226  os << seg.zSegment()->recHits().size();
227  else
228  os << 0;
229  return os;
230 }
231 
233 std::vector<const TrackingRecHit*> DTRecSegment4D::recHits() const {
234  std::vector<const TrackingRecHit*> pointersOfRecHits;
235 
236  if (hasPhi())
237  pointersOfRecHits.push_back(phiSegment());
238  if (hasZed())
239  pointersOfRecHits.push_back(zSegment());
240 
241  return pointersOfRecHits;
242 }
243 
245 std::vector<TrackingRecHit*> DTRecSegment4D::recHits() {
246  std::vector<TrackingRecHit*> pointersOfRecHits;
247 
248  if (hasPhi())
249  pointersOfRecHits.push_back(phiSegment());
250  if (hasZed())
251  pointersOfRecHits.push_back(zSegment());
252 
253  return pointersOfRecHits;
254 }
255 
~DTRecSegment4D() override
Destructor.
DTRecSegment4D()
Empty constructor.
DTSLRecSegment2D theZedSeg
Local3DVector LocalVector
Definition: LocalVector.h:12
static AlgebraicMatrix initThe2DZProjMatrix()
LocalPoint localPosition() const override
local position in SL frame
LocalPoint thePosition
Point3DBase< Scalar, LocalTag > LocalPoint
Definition: Definitions.h:30
LocalVector localDirection() const override
the local direction in SL frame
bool hasPhi() const
Does it have the Phi projection?
T z() const
Definition: PV3DBase.h:61
double chi2() const override
the chi2 of the fit
virtual DTChamberId chamberId() const
The (specific) DetId of the chamber on which the segment resides.
LocalError localDirectionError() const override
Local direction error in the Chamber frame.
AlgebraicSymMatrix parametersError() const override
Covariance matrix fo parameters()
LocalVector localDirection() const override
Local direction in Chamber frame.
Projection theProjection
LocalVector theDirection
int dimension() const override
Dimension (in parameter space)
void setCovMatrixForZed(const LocalPoint &posZInCh)
LocalPoint localPosition() const override
Local position in Chamber frame.
const DTSLRecSegment2D * zSegment() const
The Z segment: 0 if not zed projection available.
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
CLHEP::HepMatrix AlgebraicMatrix
static const AlgebraicMatrix the2DPhiProjMatrix
static AlgebraicMatrix initThe4DProjectionMatrix()
std::ostream & operator<<(std::ostream &os, const DTRecSegment4D &seg)
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Definition: GenABIO.cc:168
AlgebraicSymMatrix parametersError() const override
std::vector< const TrackingRecHit * > recHits() const override
Access to component RecHits (if any)
AlgebraicSymMatrix theCovMatrix
std::vector< const TrackingRecHit * > recHits() const override
Access to component RecHits (if any)
CLHEP::HepVector AlgebraicVector
DetId geographicalId() const
const DTChamberRecSegment2D * phiSegment() const
The superPhi segment: 0 if no phi projection available.
static const AlgebraicMatrix the2DZProjMatrix
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
AlgebraicVector parameters() const override
AlgebraicSymMatrix covMatrix() const
the Covariance Matrix
int degreesOfFreedom() const override
Degrees of freedom of the segment fit.
int degreesOfFreedom() const override
return the DOF of the segment
LocalError localPositionError() const override
Local position error in Chamber frame.
static AlgebraicMatrix initThe2DPhiProjMatrix()
CLHEP::HepSymMatrix AlgebraicSymMatrix
static const AlgebraicMatrix the4DProjectionMatrix
Vector3DBase unit() const
Definition: Vector3DBase.h:54
bool hasZed() const
Does it have the Z projection?
AlgebraicMatrix projectionMatrix() const override
The projection matrix relates the trajectory state parameters to the segment parameters().
Geom::Theta< T > theta() const
Definition: PV3DBase.h:72
double chi2() const override
Chi2 of the segment fit.
DTChamberRecSegment2D thePhiSeg