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 
7 /* This Class Header */
9 
10 /* Collaborating Class Header */
13 /* C++ Headers */
14 
15 
16 
18  const DTSLRecSegment2D& zedSeg,
19  const LocalPoint& posZInCh,
20  const LocalVector& dirZInCh):
21  RecSegment(phiSeg.chamberId()),
22  theProjection(full),
23  thePhiSeg(phiSeg),
24  theZedSeg(zedSeg),
25  theDimension(4)
26 {
27  // Check consistency of 2 sub-segments
28  if(DTChamberId(phiSeg.geographicalId().rawId()) != DTChamberId(zedSeg.geographicalId().rawId()))
29  throw cms::Exception("DTRecSegment4D")
30  <<"the z Segment and the phi segment have different chamber id"<<std::endl;
31 
32  // The position of 2D segments are defined in the SL frame: I must first
33  // extrapolate that position at the Chamber reference plane
34  LocalPoint posZAt0 = posZInCh +
35  dirZInCh * (-posZInCh.z())/cos(dirZInCh.theta());
36 
37 
38  thePosition=LocalPoint(phiSeg.localPosition().x(),posZAt0.y(),0.);
39  LocalVector dirPhiInCh=phiSeg.localDirection();
40 
41  // given the actual definition of chamber refFrame, (with z poiniting to IP),
42  // the zed component of direction is negative.
43  theDirection=LocalVector(dirPhiInCh.x()/fabs(dirPhiInCh.z()),
44  dirZInCh.y()/fabs(dirZInCh.z()),
45  -1.);
47 
48  // set cov matrix
50  theCovMatrix[0][0]=phiSeg.covMatrix()[0][0]; //sigma (dx/dz)
51  theCovMatrix[0][2]=phiSeg.covMatrix()[0][1]; //cov(dx/dz,x)
52  theCovMatrix[2][2]=phiSeg.covMatrix()[1][1]; //sigma (x)
53  setCovMatrixForZed(posZInCh);
54 }
55 
56 
58  RecSegment(phiSeg.chamberId()),
59  theProjection(phi),
60  thePhiSeg(phiSeg),
61  theZedSeg(DTSLRecSegment2D()),
62  theDimension(2)
63 {
65 
67 
68  // set cov matrix
70  theCovMatrix[0][0]=phiSeg.covMatrix()[0][0]; //sigma (dx/dz)
71  theCovMatrix[0][2]=phiSeg.covMatrix()[0][1]; //cov(dx/dz,x)
72  theCovMatrix[2][2]=phiSeg.covMatrix()[1][1]; //sigma (x)
73 }
74 
75 
77  const LocalPoint& posZInCh,
78  const LocalVector& dirZInCh) :
79  RecSegment(zedSeg.superLayerId().chamberId()),
80  theProjection(Z),
81  thePhiSeg(DTChamberRecSegment2D()),
82  theZedSeg(zedSeg),
83  theDimension(2)
84 {
85 
86  LocalPoint posZAt0=posZInCh+
87  dirZInCh*(-posZInCh.z()/cos(dirZInCh.theta()));
88 
89  thePosition=posZAt0;
90  theDirection = dirZInCh;
91 
92  // set cov matrix
94  setCovMatrixForZed(posZInCh);
95 }
96 
97 
99 
100 
102  if (dimension()==4) {
103  // (dx/dz,dy/dz,x,y)
105  result[2] = thePosition.x();
106  result[3] = thePosition.y();
107  result[0] = theDirection.x()/theDirection.z();
108  result[1] = theDirection.y()/theDirection.z();
109  return result;
110  }
111 
113  if (theProjection==phi) {
114  // (dx/dz,x)
115  result[1] = thePosition.x();
116  result[0] = theDirection.x()/theDirection.z();
117  } else if (theProjection==Z) {
118  // (dy/dz,y) (note we are in the chamber r.f.)
119  result[1] = thePosition.y();
120  result[0] = theDirection.y()/theDirection.z();
121  }
122  return result;
123 }
124 
125 
127 
128  if (dimension()==4) {
129  return theCovMatrix;
130  }
131 
133  if (theProjection==phi) {
134  result[0][0] = theCovMatrix[0][0]; //S(dx/dz)
135  result[0][1] = theCovMatrix[0][2]; //Cov(dx/dz,x)
136  result[1][1] = theCovMatrix[2][2]; //S(x)
137  } else if (theProjection==Z) {
138  result[0][0] = theCovMatrix[1][1]; //S(dy/dz)
139  result[0][1] = theCovMatrix[1][3]; //Cov(dy/dz,y)
140  result[1][1] = theCovMatrix[3][3]; //S(y)
141  }
142  return result;
143 }
144 
145 //These methods are only used to initialize the const static values
146 // used by projectionMatrix().
149  the4DProjectionMatrix[0][1] = 1;
150  the4DProjectionMatrix[1][2] = 1;
151  the4DProjectionMatrix[2][3] = 1;
152  the4DProjectionMatrix[3][4] = 1;
153  return the4DProjectionMatrix;
154 }
156 
159  the2DPhiProjMatrix[0][1] = 1;
160  the2DPhiProjMatrix[1][3] = 1;
161  return the2DPhiProjMatrix;
162 }
164 
167  the2DZProjMatrix[0][2] = 1;
168  the2DZProjMatrix[1][4] = 1;
169  return the2DZProjMatrix;
170 }
172 
173 
175  if (dimension()==4) {
176  return the4DProjectionMatrix;
177  } else if (theProjection==phi) {
178  return the2DPhiProjMatrix;
179  } else if (theProjection==Z) {
180  return the2DZProjMatrix;
181  } else {
182  return AlgebraicMatrix();
183  }
184 }
185 
186 
188  return LocalError(theCovMatrix[2][2],theCovMatrix[2][3],theCovMatrix[3][3]);
189 }
190 
191 
193  return LocalError(theCovMatrix[0][0],theCovMatrix[0][1],theCovMatrix[1][1]);
194 }
195 
196 
197 double DTRecSegment4D::chi2() const {
198  double result=0;
199  if (hasPhi()) result+=thePhiSeg.chi2();
200  if (hasZed()) result+=theZedSeg.chi2();
201  return result;
202 }
203 
204 
206  int result=0;
207  if (hasPhi()) result+=thePhiSeg.degreesOfFreedom();
208  if (hasZed()) result+=theZedSeg.degreesOfFreedom();
209  return result;
210 }
211 
212 
214  // Warning!!! the covariance matrix for Theta SL segment is defined in the SL
215  // reference frame, here that in the Chamber ref frame must be used.
216  // For direction, no problem, but the position is extrapolated, so we must
217  // propagate the error properly.
218 
219  // many thanks to Paolo Ronchese for the help in deriving the formulas!
220 
221  // y=m*z+q in SL frame
222  // y=m'*z+q' in CH frame
223 
224  // var(m') = var(m)
225  theCovMatrix[1][1] = theZedSeg.parametersError()[0][0]; //sigma (dy/dz)
226 
227  // cov(m',q') = DeltaZ*Var(m) + Cov(m,q)
228  theCovMatrix[1][3] =
229  posZInCh.z()*theZedSeg.parametersError()[0][0]+
230  theZedSeg.parametersError()[0][1]; //cov(dy/dz,y)
231 
232  // Var(q') = DeltaZ^2*Var(m) + Var(q) + 2*DeltaZ*Cov(m,q)
233  // cout << "Var(q') = DeltaZ^2*Var(m) + Var(q) + 2*DeltaZ*Cov(m,q)" << endl;
234  // cout << "Var(q')= " << posZInCh.z()*posZInCh.z() << "*" <<
235  // theZedSeg.parametersError()[0][0] << " + " <<
236  // theZedSeg.parametersError()[1][1] << " + " <<
237  // 2*posZInCh.z() << "*" << theZedSeg.parametersError()[0][1] ;
238  theCovMatrix[3][3] =
239  2.*(posZInCh.z()*posZInCh.z())*theZedSeg.parametersError()[0][0] +
240  theZedSeg.parametersError()[1][1] +
241  2.*posZInCh.z()*theZedSeg.parametersError()[0][1];
242  // cout << " = " << theCovMatrix[3][3] << endl;
243 }
244 
245 std::ostream& operator<<(std::ostream& os, const DTRecSegment4D& seg) {
246  os << "Pos " << seg.localPosition() <<
247  " Dir: " << seg.localDirection() <<
248  " dim: " << seg.dimension() <<
249  " chi2/ndof: " << seg.chi2() << "/" << seg.degreesOfFreedom() << " :";
250  if (seg.hasPhi()) os << seg.phiSegment()->recHits().size();
251  else os << 0;
252  os << ":";
253  if (seg.hasZed()) os << seg.zSegment()->recHits().size();
254  else os << 0;
255  return os;
256 }
257 
258 
260 std::vector<const TrackingRecHit*> DTRecSegment4D::recHits() const{
261  std::vector<const TrackingRecHit*> pointersOfRecHits;
262 
263  if (hasPhi()) pointersOfRecHits.push_back(phiSegment());
264  if (hasZed()) pointersOfRecHits.push_back(zSegment());
265 
266  return pointersOfRecHits;
267 }
268 
269 
271 std::vector<TrackingRecHit*> DTRecSegment4D::recHits(){
272 
273  std::vector<TrackingRecHit*> pointersOfRecHits;
274 
275  if (hasPhi()) pointersOfRecHits.push_back(phiSegment());
276  if (hasZed()) pointersOfRecHits.push_back(zSegment());
277 
278  return pointersOfRecHits;
279 }
280 
281 
283  return DTChamberId(geographicalId());
284 }
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
static AlgebraicMatrix initThe2DZProjMatrix()
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:43
virtual LocalVector localDirection() const
Local direction in Chamber frame.
CLHEP::HepMatrix AlgebraicMatrix
static const AlgebraicMatrix the2DPhiProjMatrix
virtual std::vector< const TrackingRecHit * > recHits() const
Access to component RecHits (if any)
static AlgebraicMatrix initThe4DProjectionMatrix()
~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
static const AlgebraicMatrix the2DZProjMatrix
AlgebraicSymMatrix parametersError() const
Covariance matrix fo parameters()
static AlgebraicMatrix initThe2DPhiProjMatrix()
virtual LocalVector localDirection() const
the local direction in SL frame
CLHEP::HepSymMatrix AlgebraicSymMatrix
Local3DPoint LocalPoint
Definition: LocalPoint.h:11
static const AlgebraicMatrix the4DProjectionMatrix
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