CMS 3D CMS Logo

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