BOSS 7.0.6
BESIII Offline Software System
Loading...
Searching...
No Matches
ExtMdcTrack.cxx
Go to the documentation of this file.
1
2////////////////
3//#define Helix Ext_Helix
4//File: ExtMdcTrack.cxx
5//Author: L.L.Wang
6//Deccription: A class to get MDC reconstuction track,
7// and supply information to track extrapolation.
8// It is a interface.
9//History: 2005.7.4 created by L.L.Wang
10//
11
12#include "CLHEP/Matrix/Matrix.h"
13//#include "CLHEP/config/CLHEP.h" //For constant PI(3.14......).
14
15/////////////////////////////change
16#include "TrkExtAlg/Helix.h"
17//#include "TrackUtil/Helix.h"
18/////////////////////////////////////////
19
20//#include "MdcFastTrkAlg/helix/Helix.h"
21
23#include <float.h>
24
25using namespace std;
26
27const double mass[5] = {0.511,105.658,139.57,493.677,938.27203};
28
29ExtMdcTrack::ExtMdcTrack():myMsgFlag(true),myInputTrk("Kal"),myParID(2),myHelixPar(NumHelixPar),myMdcErr(NdimMdcErr,0),myPhiTerm(0.){}
30
32
34{
35 myMdcTrackCol = aPointer;
36 myMdcRecTrkIter = myMdcTrackCol->begin();
37 myMdcRecTrkIter--;
38 myInputTrk="Mdc";
39 return true;
40}
41
43{
44 myMdcKalTrackCol = aPointer;
45 myMdcKalTrkIter = myMdcKalTrackCol->begin();
46 myMdcKalTrkIter--;
47 myInputTrk="Kal";
48 return true;
49}
50
52{
53 if(myMsgFlag) cout<<"ExtMdcTrack::GetOneGoodTrk() begin"<<endl;
54 if(myInputTrk=="Mdc")
55 {
56 myMdcRecTrkIter++;
57 if(myMdcRecTrkIter!=myMdcTrackCol->end()) return true;
58 else
59 {
60 if(myMsgFlag) cout<<"No more track!"<<endl;
61 return false;
62 }
63 }
64 else if(myInputTrk=="Kal") // use KalTrack as input
65 {
66 myMdcKalTrkIter++;
67 if(myMdcKalTrkIter!=myMdcKalTrackCol->end()) return true;
68 else
69 {
70 if(myMsgFlag) cout<<"No more track!"<<endl;
71 return false;
72 }
73 }
74}
75
76
77bool ExtMdcTrack::ReadTrk(int pid=2)
78{
79 if(myMsgFlag) cout<<"ExtMdcTrack::ReadTrk() begin"<<endl;
80 myParID = pid;
81 if(myInputTrk=="Mdc")
82 {
83 if(myMdcRecTrkIter!=myMdcTrackCol->end())
84 {
85 RecMdcTrack *aMdcTrack = *myMdcRecTrkIter;
86 // if(!aMdcTrack->getStat())//If good track.Now status default 0
87 {
88 if(myMsgFlag) cout<<"Read a good track!"<<endl;
89
90 //get MdcTrk data
91 myTrackID = aMdcTrack->trackId();
92 myHelixPar = aMdcTrack->helix();
93 myPivot = aMdcTrack->getPivot();
94 myMdcErr = aMdcTrack->err();
95 // double aPhiTerm = aMdcTrack->getFiTerm();
96 myPhiTerm = aMdcTrack->getFiTerm();
97 myTrkLength = GetTrackLength();
98 double p = (GetMomentum()).mag();
99 double beta = p/sqrt(mass[myParID]*mass[myParID]+p*p);
100 myTrkTof = myTrkLength/(beta*299.792458);
101
102 /* //Start caculation of myPhiTerm.(when pivot is (0,0,0).)
103 double r = DBL_MAX;
104 double rMdc = 81.0;
105 double dro = myHelixPar(1);
106 if(myHelixPar(3)!=0.0)
107 r = 333.564095/myHelixPar(3);
108 if( fabs(2.0*r+dro)>rMdc && fabs(dro)<rMdc )
109 {
110 double aValue = ((dro+r)*(dro+r)+r*r-rMdc*rMdc)/2.0/fabs(r)/fabs(dro+r);
111 if(r<0.0) myPhiTerm = acos(aValue);
112 else myPhiTerm = -1.0*acos(aValue);
113 }
114 else
115 {
116 if(myMsgFlag) cout<<"Get a track which can't go out of MDC!"<<endl;
117 myMdcRecTrkIter++;
118 continue;
119 }
120 */
121 // double aTrackLength=fabs(r*myPhiTerm)*sqrt(myHelixPar(5)*myHelixPar(5)+1);
122 if(myMsgFlag)
123 {
124 cout<<"MDC track:"<<myTrackID<<endl;
125 cout<<"Helix: "<<myHelixPar;
126 cout<<"pivot: "<<myPivot<<"cm"<<endl;
127 cout<<"Error: "<<myMdcErr<<endl;
128
129 /* Convert();
130 cout<<"********after convert:"<<endl;
131 cout<<"Helix: "<<myHelixPar;
132 cout<<"pivot: "<<myPivot;
133 cout<<"Error: "<<myMdcErr<<endl;
134 */
135 cout<<"Pt: "<<GetPt()<<"GeV/c"<<endl;
136 cout<<"PhiTerm: "<<myPhiTerm<<endl;
137 // cout<<"recPhiTerm: "<<aPhiTerm<<endl;
138 cout<<"trackLength(mm): "<<GetTrackLength()<<endl;
139 // cout<<"trackLengthTest(cm): "<<aTrackLength<<endl;
140 }
141
142 return true;
143 }
144 // else
145 // {
146 // myMdcRecTrkIter++;
147 // cout<<"Get a bad track!"<<endl;
148 // }
149 }
150 else
151 {
152 if(myMsgFlag) cout<<"No more track!"<<endl;
153 return false;
154 }
155 }
156 else if(myInputTrk=="Kal") // use KalTrack as input
157 {
158 if(myMdcKalTrkIter!=myMdcKalTrackCol->end())
159 {
160 RecMdcKalTrack *aMdcKalTrack = *myMdcKalTrkIter;
161 {
162 if(myMsgFlag) cout<<"Get a good track!"<<endl;
163
164 //get MdcTrk data
165 myTrackID = aMdcKalTrack->getTrackId();
166 myHelixPar = aMdcKalTrack->getLHelix(myParID);
167 //myPivot = HepPoint3D(0,0,0);
168 myPivot = aMdcKalTrack->getLPivot(myParID);
169 myMdcErr = aMdcKalTrack->getLError(myParID);
170 myPhiTerm = aMdcKalTrack->getFiTerm(myParID);
171 myPhiTerm = 0.0;
172 myTrkLength = aMdcKalTrack->getPathSM(myParID);
173 myLPosition = aMdcKalTrack->getLPoint(myParID);
174 myTrkTof = aMdcKalTrack->getTof(myParID);
175 //cout<<"myInitialTof = "<<myTrkTof<<endl;
176
177 if(myMsgFlag)
178 {
179 cout<<"Kal track:"<<myTrackID<<endl;
180 cout<<"myParID:"<<myParID<<endl;
181 cout<<"Helix: "<<myHelixPar;
182 cout<<"pivot: "<<myPivot<<"cm"<<endl;
183 cout<<"Error: "<<myMdcErr<<endl;
184 cout<<"Pt: "<<GetPt()<<"GeV/c"<<endl;
185 cout<<"PhiTerm: "<<myPhiTerm<<endl;
186// cout<<"trackLength(mm): "<<GetTrackLength()<<endl;
187 cout<<"trackLength(cm): "<<myTrkLength<<endl;
188 cout<<"myTrkTof: "<<myTrkTof<<endl;
189 cout<<"Last point position: "<<myLPosition<<endl;
190 }
191 return true;
192 }
193 }
194 else
195 {
196 if(myMsgFlag) cout<<"No more track!"<<endl;
197 return false;
198 }
199 }
200}
201
202void ExtMdcTrack::Convert()
203{
204 myHelixPar(1)*=10.;
205 myHelixPar(3)*=0.001;
206 myHelixPar(4)*=10.;
207 myPivot*=10.;
208 myMdcErr.fast(1,1)*=100.;
209 myMdcErr.fast(2,1)*=10.;
210 myMdcErr.fast(3,1)*=0.01;
211 myMdcErr.fast(3,2)*=0.001;
212 myMdcErr.fast(3,3)*=0.000001;
213 myMdcErr.fast(4,1)*=100.;
214 myMdcErr.fast(4,2)*=10.;
215 myMdcErr.fast(4,3)*=0.01;
216 myMdcErr.fast(4,4)*=100.;
217 myMdcErr.fast(5,1)*=10.;
218 myMdcErr.fast(5,3)*=0.001;
219 myMdcErr.fast(5,4)*=10.;
220}
221
223{
224 return (*myMdcRecTrkIter);
225}
226
227const Hep3Vector ExtMdcTrack::GetPosition() const
228{
229// if(myInputTrk=="Mdc") {
230 Ext_Helix aHelix(myPivot,myHelixPar,myMdcErr);
231 Hep3Vector aPoint = aHelix.x(myPhiTerm);
232 if(myMsgFlag) cout<<"PhiTerm Position: "<<aPoint<<endl;
233 aPoint*=10.0;
234 return (aPoint);
235/* }
236 else if(myInputTrk=="Kal") {
237 return (myLPosition);
238 }
239*/
240}
241
242const Hep3Vector ExtMdcTrack::GetMomentum() const
243{
244 Ext_Helix aHelix(myPivot,myHelixPar,myMdcErr);
245 Hep3Vector aMomentum = aHelix.momentum(myPhiTerm);//In GeV/c units.
246 if(myMsgFlag) cout<<"PhiTerm Momentum: "<<aMomentum<<endl;
247 aMomentum*=1000.0;//In MeV/c uints.
248 return (aMomentum);
249}
250
251const HepSymMatrix ExtMdcTrack::GetErrorMatrix() const
252{
253 Ext_Helix aHelix(myPivot,myHelixPar,myMdcErr);
254// aHelix.pivot(aHelix.x(myPhiTerm));//Move the pivot to the PhiTerm position.
255
256 Hep3Vector aPoint = aHelix.x(myPhiTerm);
257 double phi0 = aHelix.phi0();
258 double kappaInv = 1.0/aHelix.kappa();
259 double cosPhi0 = cos(phi0);
260 double sinPhi0 = sin(phi0);
261 // 0 -> myPhiTerm, 2009-5-29, by wangll
262// double px = aHelix.momentum(0).x();
263// double py = aHelix.momentum(0).y();
264// double pz = aHelix.momentum(0).z();
265 double px = aHelix.momentum(myPhiTerm).x();
266 double py = aHelix.momentum(myPhiTerm).y();
267 double pz = aHelix.momentum(myPhiTerm).z();
268
269 //Calculate the Jacobian: d(xp)/d(helix).
270 HepMatrix Helix2XpJcb(NdimExtErr,NdimMdcErr,0);
271
272 Helix2XpJcb(1,1) = cosPhi0;
273 Helix2XpJcb(1,2) = myPivot.y()-aPoint.y();
274 Helix2XpJcb(1,3) = (myPivot.x()-aPoint.x()+myHelixPar(1)*cosPhi0)*kappaInv;
275 Helix2XpJcb(2,1) = sinPhi0;
276 Helix2XpJcb(2,2) = aPoint.x()-myPivot.x();
277 Helix2XpJcb(2,2) = (myPivot.y()-aPoint.y()+myHelixPar(1)*sinPhi0)*kappaInv;
278 Helix2XpJcb(3,3) = (myPivot.z()-aPoint.z()+myHelixPar(4))*kappaInv;
279 Helix2XpJcb(3,4) = 1.0;
280 Helix2XpJcb(3,5) = (aPoint.z()-myPivot.z()-myHelixPar(4))/myHelixPar(5);
281 Helix2XpJcb(4,2) = -py;
282 Helix2XpJcb(4,3) = -px * kappaInv;
283 Helix2XpJcb(5,2) = px;
284 Helix2XpJcb(5,3) = -py * kappaInv;
285 Helix2XpJcb(6,3) = -pz * kappaInv;
286 Helix2XpJcb(6,5) = fabs(kappaInv);
287
288 //Calculate the Ext error matrix(6x6) in (x,p).
289// if(myMsgFlag) cout<<"Error matrix at new pivot: "<<endl;
290// aHelix.Ea();
291// cout<<"haha"<<endl;
292 HepSymMatrix aErrorMatrix = aHelix.Ea().similarity(Helix2XpJcb);
293 if(myMsgFlag) cout<<"PhiTerm Error matrix:"<<aErrorMatrix<<endl;
294
295 //Uints Conversion.
296 for(int i=1;i<=6;i++)
297 {
298 for(int j=1;j<=i;j++)
299 {
300 if(i<=3 && j<=3) aErrorMatrix.fast(i,j)*=100.0;
301 if(i>=4 && j>=4) aErrorMatrix.fast(i,j)*=1.0e+6;
302 if(i>=4 && j<=3) aErrorMatrix.fast(i,j)*=10000.0;
303 }
304 }
305
306 return aErrorMatrix;
307}
308
310{
311 if(myInputTrk=="Mdc") {
312
313/* //old version
314 Helix aHelix(myPivot,myHelixPar,myMdcErr);
315
316 double phi0 = aHelix.phi0();
317 HepPoint3D w = -(*this).GetParticleCharge() * aHelix.center();
318 Hep3Vector center( w.x(),w.y(),w.z() );
319 double centerX = center.x();
320 double centerY = center.y();
321 double phiCenter;
322 if(fabs(centerX) > 1.0e-10)
323 {
324 phiCenter = atan2(centerY,centerX);
325 if(phiCenter < 0.) phiCenter += 2.0*M_PI;
326 }
327 else
328 {
329 phiCenter = (centerY>0)? M_PI_2:3.0*M_PI_2;
330 }
331 double dPhi = fabs(phi0 + myPhiTerm - phiCenter);
332 if(dPhi >= 2.0*M_PI) dPhi -= 2.0*M_PI;
333 double tanLambda = aHelix.tanl();
334 double cosLambdaInv = sqrt(tanLambda*tanLambda + 1.0);
335 return (10*fabs(aHelix.radius() * dPhi * cosLambdaInv));//10* for cm -> mm
336*/
337
338 Ext_Helix aHelix(myPivot,myHelixPar,myMdcErr);
339 double dPhi = fabs(myPhiTerm);
340 double tanLambda = aHelix.tanl();
341 double cosLambdaInv = sqrt(tanLambda*tanLambda + 1.0);
342 return (10*fabs(aHelix.radius() * dPhi * cosLambdaInv));//10* for cm -> mm
343
344 }
345 else if(myInputTrk=="Kal")
346 {
347 return 10*myTrkLength; //10* for cm -> mm
348 }
349}
350
351double ExtMdcTrack::GetPt() const
352{
353 return (1.0/fabs(myHelixPar[2]));
354}
355
357{
358 return ((myHelixPar[2]>0.)? 1.0:-1.0);
359}
double sin(const BesAngle a)
Definition: BesAngle.h:210
double cos(const BesAngle a)
Definition: BesAngle.h:213
double mass
const double mass[5]
Definition: ExtMdcTrack.cxx:27
ObjectVector< RecMdcKalTrack > RecMdcKalTrackCol
ObjectVector< RecMdcTrack > RecMdcTrackCol
Definition: RecMdcTrack.h:79
const HepSymMatrix err() const
const int trackId() const
Definition: DstMdcTrack.h:52
const HepVector helix() const
......
bool GetOneGoodTrk()
Definition: ExtMdcTrack.cxx:51
ExtMdcTrack(void)
Definition: ExtMdcTrack.cxx:29
double GetParticleCharge() const
double GetTrackLength() const
~ExtMdcTrack(void)
Definition: ExtMdcTrack.cxx:31
double GetPt() const
bool SetMdcKalTrkCol(RecMdcKalTrackCol *aPointer)
Definition: ExtMdcTrack.cxx:42
RecMdcTrack * GetMdcRecTrkPtr() const
bool SetMdcRecTrkCol(RecMdcTrackCol *aPointer)
Definition: ExtMdcTrack.cxx:33
const Hep3Vector GetPosition() const
bool ReadTrk(int pid)
Definition: ExtMdcTrack.cxx:77
const HepSymMatrix GetErrorMatrix() const
const Hep3Vector GetMomentum() const
double radius(void) const
returns radious of helix.
const HepSymMatrix & Ea(void) const
returns error matrix.
HepPoint3D x(double dPhi=0.) const
returns position after rotating angle dPhi in phi direction.
Hep3Vector momentum(double dPhi=0.) const
returns momentum vector after rotating angle dPhi in phi direction.
double getPathSM(int pid) const
const HepPoint3D & getLPoint() const
const double getFiTerm(const int pid) const
double getTof(int pid) const
const HepVector & getLHelix() const
const HepSymMatrix & getLError() const
const HepPoint3D & getLPivot() const
int getTrackId(void) const
const HepPoint3D & getPivot() const
Definition: RecMdcTrack.h:56
const double getFiTerm() const
Definition: RecMdcTrack.h:52