BOSS 7.1.1
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcxHel.cxx
Go to the documentation of this file.
1// -------------------------------------------------------------------------
2// File and Version Information:
3// $Id: MdcxHel.cxx,v 1.7 2011/12/08 06:52:29 zhangy Exp $
4//
5// Description:
6// Class Implementation for |MdcxHel|
7//
8// Environment:
9// Software developed for the BaBar Detector at the SLAC B-Factory.
10//
11// Author List:
12// S. Wagner
13//
14// Copyright Information:
15// Copyright (C) 1996 BEPCII
16//
17// History:
18// Migration for BESIII MDC
19//
20//------------------------------------------------------------------------
21#include "MdcGeom/Constants.h"
22#include "MdcGeom/BesAngle.h"
23#include <math.h>
24#include "MdcxReco/MdcxHel.h"
25#include "MdcxReco/MdcxHit.h"
27using std::cout;
28using std::endl;
29
30//constructors
31
33
35(double D0, double Phi0, double Omega, double Z0, double Tanl,
36 double T0, int Code, int Mode, double X, double Y) :
37d0(D0), phi0(Phi0), omega(Omega), z0(Z0), tanl(Tanl), t0(T0),
38xref(X), yref(Y), code(Code), mode(Mode), omin(0.000005) {
39
40 ominfl = (fabs(omega) < omin) ? 0 : 1;
41 double m_2pi = 2.0*M_PI;
42 if (phi0 > M_PI) phi0 -= m_2pi;
43 if (phi0 < -M_PI) phi0 += m_2pi;
44 cphi0 = cos(phi0);
45 sphi0 = sin(phi0);
46 x0 = X0();
47 y0 = Y0();
48 xc = Xc();
49 yc = Yc();
51 turnflag = 1; ///FIXME
52 //std::cout << "MdcxHel::MdcxHel() -> (x0, y0) (" << x0 << ", " << y0 << ")" << std::endl;
53}//endof MdcxHel
54
56
57//accessors
58
59double MdcxHel::Xc()const {
60 if(ominfl) {
61 //return (X0() - sphi0/omega);
62 return (x0 - sphi0/omega);
63 } else {
64 return 999999999.9;
65 }//(ominfl)
66}//endof Xc
67
68double MdcxHel::Yc()const {
69 if(ominfl) {
70 //return (Y0()+cphi0/omega);
71 return (y0 + cphi0/omega);
72 } else {
73 return 999999999.9;
74 }//(ominfl)
75}//endof Yc
76
77double MdcxHel::X0()const{
78 return (xref - sphi0*d0);
79}//endof X0
80
81double MdcxHel::Y0()const{
82 return (yref + cphi0*d0);
83}//endof Y0
84
85double MdcxHel::Xh(double l)const{
86 if(ominfl){
87 double phit=phi0+omega*l;
88 return (xc+sin(phit)/omega);
89 }else{
90 return (x0+cphi0*l-0.5*l*l*omega*sphi0);
91 }//ominfl
92}//endof Xh
93
94double MdcxHel::Yh(double l)const{
95 if(ominfl){
96 double phit=phi0+omega*l;
97 return (yc-cos(phit)/omega);
98 }else{
99 return (y0+sphi0*l+0.5*l*l*omega*cphi0);
100 }//ominfl
101}//endof Yh
102
103double MdcxHel::Zh(double l)const{
104 return (z0+tanl*l);
105}//endof Zh
106
107double MdcxHel::Px(double l) const {
108 if(ominfl) {
109 double phit = phi0 + omega*l;
110 return 0.003*cos(phit)/fabs(omega); /// pt=0.003*r (0.003 -> q*B)
111 } else {
112 return 1000.0*cphi0;
113 }//ominfl
114}//endof Px
115
116double MdcxHel::Py(double l) const {
117 if(ominfl) {
118 double phit = phi0+omega*l;
119 return 0.003*sin(phit)/fabs(omega);
120 } else {
121 return 1000.0*sphi0;
122 }//ominfl
123}//endof Py
124
125double MdcxHel::Pz(double l) const {
126 if(ominfl) {
127 return 0.003*tanl/fabs(omega);
128 }
129 else{
130 return 1000.0*tanl;
131 }//ominfl
132}//endof Pz
133
134double MdcxHel::Ptot(double l)const{
135 if(ominfl) {
136 return 0.003*sqrt(1.0+tanl*tanl)/fabs(omega);
137 } else {
138 return 1000.0*sqrt(1.0+tanl*tanl);
139 }//ominfl
140}//endof Ptot
141
142double MdcxHel::Lmax() const {
143 double lmax = MdcxParameters::maxTrkLength;
144 if (ominfl) {
145 double rmax = 1.0/fabs(omega);
146 double dmax = fabs(d0) + 2.0*rmax;
147 if (dmax > MdcxParameters::maxMdcRadius) lmax = M_PI*rmax; ///FIXME
148 }
149 return lmax;
150}//endof Lmax
151
152//controls
153//control fitting mode
154void MdcxHel::SetMode(int n) { mode = n; }
155
156void MdcxHel::SetRef(double x, double y) {
157 xref = x;
158 yref = y;
159}
160//control free variables
161void MdcxHel::SetOmega(int Qomega) {
163 code = code + deltaq(qomega, Qomega)*100;
164 qomega = Qomega;
165}
166void MdcxHel::SetPhi0(int Qphi0) {
168 code = code + deltaq(qphi0, Qphi0)*10;
169 qphi0 = Qphi0;
170}
171void MdcxHel::SetD0(int Qd0) {
172 nfree = nfree + deltaq(qd0, Qd0);
173 code = code + deltaq(qd0, Qd0);
174 qd0 = Qd0;
175}
176void MdcxHel::SetTanl(int Qtanl) {
178 code = code + deltaq(qtanl, Qtanl)*10000;
179 qtanl = Qtanl;
180}
181void MdcxHel::SetZ0(int Qz0) {
182 nfree = nfree + deltaq(qz0, Qz0);
183 code = code + deltaq(qz0, Qz0)*1000;
184 qz0 = Qz0;
185}
186void MdcxHel::SetT0(int Qt0) {
187 nfree = nfree + deltaq(qt0, Qt0);
188 code = code + deltaq(qt0, Qt0)*100000;
189 qt0 = Qt0;
190}
191
192//operators
194 copy(rhs);
195 return *this;
196}
197
198//decode free parameter code
199void MdcxHel::decode(const int code,int& i1,int& i2,
200 int& i3,int& i4,int& i5,int& i6,int& n)
201{ ///FIXME use bit code ?
202 int temp = code;
203 temp=temp/1000000; temp=code-1000000*temp;
204 i6=temp/100000; temp=temp-100000*i6;
205 i5=temp/10000; temp=temp-10000*i5;
206 i4=temp/1000; temp=temp-1000*i4;
207 i3=temp/100; temp=temp-100*i3;
208 i2=temp/10; i1=temp-10*i2;
209 n = 0;
210 if(i6 == 1) n++; else i6 = 0;
211 if(i5 == 1) n++; else i5 = 0;
212 if(i4 == 1) n++; else i4 = 0;
213 if(i3 == 1) n++; else i3 = 0;
214 if(i2 == 1) n++; else i2 = 0;
215 if(i1 == 1) n++; else i1 = 0;
216}//endof decode
217
218//copy |MdcxHel| to |MdcxHel|
219void MdcxHel::copy(const MdcxHel& rhs)
220{
221 //FIXME
222 omega=rhs.Omega(); phi0=rhs.Phi0(); d0=rhs.D0(); t0=rhs.T0();
223 tanl=rhs.Tanl(); z0=rhs.Z0();
224 cphi0=rhs.CosPhi0(); sphi0=rhs.SinPhi0();
225 x0=rhs.X0(); y0=rhs.Y0(); xc=rhs.Xc(); yc=rhs.Yc();
226 xref=rhs.Xref(); yref=rhs.Yref();
227 qomega=rhs.Qomega(); qphi0=rhs.Qphi0(); qd0=rhs.Qd0(); qt0=rhs.Qt0();
228 qtanl=rhs.Qtanl(); qz0=rhs.Qz0();
229 mode=rhs.Mode(); nfree=rhs.Nfree();
230 code=rhs.Code(); ominfl=rhs.Ominfl(); omin=rhs.Omin();
231 turnflag=rhs.GetTurnFlag();
232}//endof copy
233
234double MdcxHel::Doca(const MdcxHit& h) {
235 //std::cout<< __FILE__ << " " << __LINE__ << " hit("<<h.Layer()<<","<<h.WireNo()<<")";
236 return Doca( h.wx(), h.wy(), h.wz(), h.x(), h.y() );
237}
238
239double MdcxHel::Doca( double wx, double wy, double wz,
240 double xi, double yi, double zi )
241{
242 double m_2pi = 2.0*M_PI;
243 // describe wire
244 //cout << " In Doca, xi = " << xi << " yi = " << yi << " zi = " << zi <<endl;
245 Hep3Vector ivec(xi, yi, zi);
246 wvec = Hep3Vector(wx, wy, wz);
247 //cout << " In Doca, wx = " << wx << " wy = " << wy << " wz = " << wz <<endl;
248 // calculate len to doca
249 double zd, xd = xi, yd = yi;
250 // cout << " In Doca, start xd = " << xd << " yd = " << yd << endl;
251 double lnew,t1,t2,dphi,dlen=1000.0;
252 len = 0.0;
253 int itry = 2;
254 // int segflg=0; if ((code==111)&&(z0==0.0)&&(tanl==0.0))segflg=1;
255 // int superseg=0; if ((code==11111)&&(xref!=0.0)&&(yref!=0.0))superseg=1;
256 double circut, circum = 10000.;
257 if (ominfl) circum = m_2pi/fabs(omega);
258 circut = 0.50 * circum;
259 while (itry) {
260 if (ominfl) {
261 ///calc the phi of point(i)
262 t1 = -xc + xd; t2 = yc - yd; phi = atan2(t1, t2);
263 if (omega < 0.0) phi += M_PI;
264 if (phi > M_PI) phi -= m_2pi;
265 dphi = phi - phi0;
266 if (omega < 0.0){
267 if (dphi > 0.0) dphi -= m_2pi;
268 if (dphi < -m_2pi) dphi += m_2pi;
269 }else{
270 if (dphi < 0.0) dphi += m_2pi;
271 if (dphi > m_2pi) dphi -= m_2pi;
272 }
273 lnew = dphi/omega;
274 // if ((lnew>circut)&&(segflg))lnew-=circum;
275 // if ((lnew>circut)&&(superseg))lnew-=circum;
276 if ((lnew>circut)&&(turnflag)) lnew -= circum; //FIXME attention
277
278 zh = Zh(lnew);
279 xd=xi+(zh-zi)*wx/wz; yd=yi+(zh-zi)*wy/wz; zd=zh;
280 // cout << " In Doca, xd = " << xd << " yd = " << yd << " zh = " << zh;
281 // cout << " lnew = " << lnew << endl;
282 dlen=fabs(lnew-len); len=lnew;
283 // if (segflg)break;
284 //std::cout<< __FILE__ << __LINE__<<" Doca() dlen " << dlen<< " zh "<<zh<<" >?"
285 //<<MdcxParameters::maxMdcZLen<<std::endl;
286 if (fabs(zh) > MdcxParameters::maxMdcZLen) break; //FIXME attention
287 if ( (0.0==wx) && (0.0==wy) )break; if (dlen < 0.000001)break; itry--;
288 } else {
289 len = (xi-xref)*cphi0 + (yi-yref)*sphi0;
290 zh = z0 + tanl*len;
291 phi = phi0;
292 break;
293 }
294 }
295 // Hep3Vector Dvec(xd,yd,zd);
296 xh = Xh(len); yh = Yh(len);
297 Hep3Vector hvec(xh, yh, zh);
298// cout << " In Doca, xh = " << xh << " yh = " << yh << " zh = " << zh << " len=" << len << " om " << omega << endl;
299 double lamb = atan(tanl);
300 cosl = cos(lamb); sinl = sin(lamb);
301 tx = cosl*cos(phi); ty = cosl*sin(phi); tz = sinl;
302 tvec = Hep3Vector(tx, ty, tz);
303 Hep3Vector vvec = wvec.cross(tvec);
304 vhat = vvec.unit(); vx = vhat.x(); vy = vhat.y(); vz = vhat.z();
305 // cout << " In Doca, vx = " << vx << " vy = " << vy << " vz = " << vz << endl;
306 dvec = ivec - hvec;
307 double doca = dvec*vhat;
308 // cout << " doca = " << doca << endl;
309 double f1 = dvec*tvec; double f2 = wvec*tvec; double f3 = dvec*wvec;
310 f0 = (f1 - f2*f3) / (1.0 - f2*f2);
311 samb = (doca > 0.0) ? -1 : +1;
312 double wirephi = atan2(yd, xd);
313 eang = BesAngle(phi-wirephi);
314 wamb = (fabs(eang) < Constants::pi/2) ? samb : -samb;
315 //std::cout<< __FILE__ << __LINE__<<" Doca() dlen " << dlen<< " zh "<<zh<<" >?"
316 //<<MdcxParameters::maxMdcZLen<<std::endl;
317 if (fabs(zh) > MdcxParameters::maxMdcZLen) doca = 1000.0; ///FIXME
318 //if(doca == 1000.0) cout << " In Doca, zh = " << zh << " len=" << len << " om " << omega <<" "<< ominfl<<
319 //" z0 " << z0 << "tanl " << tanl <<endl;
320 //cout << " doca = " << doca << endl;
321 return doca;
322}//endof Doca
323
324std::vector<float> MdcxHel::derivatives(const MdcxHit& hit)
325{
326 double doca = Doca(hit);
327 std::vector<float> temp(nfree+1);
328 temp[0] = doca;
329 double fac = 1.0;
330 if((mode==0) && (doca<0.0)) fac = -fac;
331 if(mode == 0) temp[0] = fabs(temp[0]);
332
333 int bump = 0;
334 if (qd0) temp[++bump] = (-vx*sphi0 + vy*cphi0) * fac;
335 if (qphi0) {
336 //double dddp0=-(yh-y0)*vx+(xh-x0)*vy;
337 double dddp0 = -(yh-y0+f0*ty)*vx + (xh-x0+f0*tx)*vy;
338 dddp0 *= (1.0 + d0*omega);
339 temp[++bump] = dddp0*fac;
340 }
341 if (qomega) {
342 double dddom;
343 if (ominfl) {
344 dddom = ((len*cos(phi)-xh+x0)*vx + (len*sin(phi)-yh+y0)*vy)/omega;
345 dddom += f0*len*cosl*(-sin(phi)*vx+cos(phi)*vy);
346 } else {
347 dddom = 0.5*len*len*(-vx*sphi0+vy*cphi0);
348 }
349 temp[++bump] = dddom * fac;
350 }
351 if (qz0) temp[++bump] = vz * fac;
352 if (qtanl) temp[++bump] = (vz *len) * fac;
353 if (qt0) temp[++bump] = -hit.v();
354 return temp;
355}//endof derivatives
356
357void MdcxHel::print() const {
358 cout << "MdcxHel(";
359 cout << d0<<",";
360 cout << phi0<<",";
361 cout << omega<<",";
362 cout << z0<<",";
363 cout << tanl<<")"<<endl;
364 cout << " t0 = " << t0 ;
365 cout << " nfree = " << nfree ;
366 cout << " (x0,y0) " << x0<<","<<y0;
367 cout << " (xc,yc) " << xc<<","<<yc;
368 cout << " (xref,yref) " << xref<<","<<yref;
369 cout << " code = " << code;
370 cout << " mode = " << mode;
371 cout << " ominfl = " << ominfl;
372 cout << " " << endl;
373}//endof print
374
376 double m_2pi = 2.0*M_PI;
377 if (ominfl) {
378 if ( (fabs(d0) + 2.0/fabs(omega)) > 80.0 ) return;
379 double lturn = m_2pi/fabs(omega);
380 double zturn = Zh(lturn);
381 // cout << "z0 " << z0 << " zturn " << zturn << endl;
382 if (fabs(zturn) < fabs(z0)) {
383 z0 = zturn;
384 tanl = -tanl;
385 omega = -omega;
386 d0 = -d0;
387 phi0 = phi0 - M_PI;
388 if (phi0 < -M_PI) phi0 += m_2pi;
389 cphi0 = cos(phi0);
390 sphi0 = sin(phi0);
391 x0 = X0();
392 y0 = Y0();
393 }
394 }
395}//endof flip
396
double sin(const BesAngle a)
Definition BesAngle.h:210
double cos(const BesAngle a)
Definition BesAngle.h:213
const Int_t n
TFile * f1
Double_t x[10]
#define M_PI
Definition TConstant.h:4
Definition Code.h:31
static const double pi
Definition Constants.h:38
double Phi0() const
Definition MdcxHel.h:54
double z0
Definition MdcxHel.h:126
double eang
Definition MdcxHel.h:164
double t0
Definition MdcxHel.h:128
double CosPhi0() const
Definition MdcxHel.h:63
double T0() const
Definition MdcxHel.h:62
double sphi0
Definition MdcxHel.h:132
double vy
Definition MdcxHel.h:162
Hep3Vector tvec
Definition MdcxHel.h:163
double vz
Definition MdcxHel.h:162
int ominfl
Definition MdcxHel.h:154
double X0() const
Definition MdcxHel.cxx:77
void SetZ0(int n)
Definition MdcxHel.cxx:181
double D0() const
Definition MdcxHel.h:53
double Omin() const
Definition MdcxHel.h:72
double Lmax() const
Definition MdcxHel.cxx:142
int turnflag
Definition MdcxHel.h:155
int wamb
Definition MdcxHel.h:164
double Yc() const
Definition MdcxHel.cxx:68
void SetRef(double x, double y)
Definition MdcxHel.cxx:156
double Xc() const
Definition MdcxHel.cxx:59
void SetD0(int n)
Definition MdcxHel.cxx:171
double vx
Definition MdcxHel.h:162
double len
Definition MdcxHel.h:162
double tz
Definition MdcxHel.h:162
double Py(double l=0.0) const
Definition MdcxHel.cxx:116
void SetOmega(int n)
Definition MdcxHel.cxx:161
double Px(double l=0.0) const
Definition MdcxHel.cxx:107
int nfree
Definition MdcxHel.h:153
double yc
Definition MdcxHel.h:136
double omin
Definition MdcxHel.h:158
int Code() const
Definition MdcxHel.h:74
Hep3Vector dvec
Definition MdcxHel.h:163
double yref
Definition MdcxHel.h:130
int mode
Definition MdcxHel.h:145
Hep3Vector wvec
Definition MdcxHel.h:163
double d0
Definition MdcxHel.h:123
double Ptot(double l=0.0) const
Definition MdcxHel.cxx:134
double f0
Definition MdcxHel.h:162
void SetTanl(int n)
Definition MdcxHel.cxx:176
void SetPhi0(int n)
Definition MdcxHel.cxx:166
double Pz(double l=0.0) const
Definition MdcxHel.cxx:125
void decode(const int i, int &i1, int &i2, int &i3, int &i4, int &i5, int &i6, int &n)
Definition MdcxHel.cxx:199
double Omega() const
Definition MdcxHel.h:55
double Doca(double WX, double WY, double WZ, double X, double Y, double Z=0.0)
Definition MdcxHel.cxx:239
double zh
Definition MdcxHel.h:162
double tanl
Definition MdcxHel.h:127
int qtanl
Definition MdcxHel.h:151
int Ominfl() const
Definition MdcxHel.h:76
void print() const
Definition MdcxHel.cxx:357
double xh
Definition MdcxHel.h:162
double xc
Definition MdcxHel.h:135
Hep3Vector vhat
Definition MdcxHel.h:163
double Yref() const
Definition MdcxHel.h:61
int qomega
Definition MdcxHel.h:149
void SetMode(int n)
Definition MdcxHel.cxx:154
double Y0() const
Definition MdcxHel.cxx:81
int qphi0
Definition MdcxHel.h:148
double phi0
Definition MdcxHel.h:124
double yh
Definition MdcxHel.h:162
double xref
Definition MdcxHel.h:129
double Z0() const
Definition MdcxHel.h:56
void flip()
Definition MdcxHel.cxx:375
double Yh(double l) const
Definition MdcxHel.cxx:94
double Zh(double l) const
Definition MdcxHel.cxx:103
int Qd0() const
Definition MdcxHel.h:77
int qt0
Definition MdcxHel.h:152
double omega
Definition MdcxHel.h:125
void copy(const MdcxHel &hel)
Definition MdcxHel.cxx:219
double x0
Definition MdcxHel.h:133
int Qomega() const
Definition MdcxHel.h:79
int Qphi0() const
Definition MdcxHel.h:78
int Qz0() const
Definition MdcxHel.h:80
int code
Definition MdcxHel.h:137
double Tanl() const
Definition MdcxHel.h:57
int deltaq(int i, int j) const
Definition MdcxHel.h:170
double Xh(double l) const
Definition MdcxHel.cxx:85
int qd0
Definition MdcxHel.h:147
void SetT0(int n)
Definition MdcxHel.cxx:186
MdcxHel()
Definition MdcxHel.cxx:32
double SinPhi0() const
Definition MdcxHel.h:64
virtual ~MdcxHel()
Definition MdcxHel.cxx:55
double cosl
Definition MdcxHel.h:162
double tx
Definition MdcxHel.h:162
double cphi0
Definition MdcxHel.h:131
int Mode() const
Definition MdcxHel.h:73
double Xref() const
Definition MdcxHel.h:59
int Qt0() const
Definition MdcxHel.h:82
int Nfree() const
Definition MdcxHel.h:75
int GetTurnFlag() const
Definition MdcxHel.h:116
double y0
Definition MdcxHel.h:134
int Qtanl() const
Definition MdcxHel.h:81
std::vector< float > derivatives(const MdcxHit &h)
Definition MdcxHel.cxx:324
double sinl
Definition MdcxHel.h:162
MdcxHel & operator=(const MdcxHel &)
Definition MdcxHel.cxx:193
int qz0
Definition MdcxHel.h:150
int samb
Definition MdcxHel.h:164
double phi
Definition MdcxHel.h:162
double ty
Definition MdcxHel.h:162
float wy() const
Definition MdcxHit.h:76
float x() const
Definition MdcxHit.h:69
float y() const
Definition MdcxHit.h:70
float wx() const
Definition MdcxHit.h:75
float wz() const
Definition MdcxHit.h:77
float v() const
Definition MdcxHit.h:81
static const double maxMdcZLen
static const double maxTrkLength
static const double maxMdcRadius
MDC Geometry.
double y[1000]