BOSS 7.1.1
BESIII Offline Software System
Loading...
Searching...
No Matches
HoughStereo.cxx
Go to the documentation of this file.
3
5//HoughStereo::HoughStereo(){
6//}
7//HoughStereo::HoughStereo(double bunchTime):_bunchTime(bunchTime){
8//}
9HoughStereo::HoughStereo( double bunchTime , Hough2D *circle , HoughRecHit* rechit):_bunchTime(bunchTime),_circle(circle),_rechit(rechit){
10 _lleft=-99;
11 _zleft=-99;
12 _lright=-99;
13 _zright=-99;
14 _ambig=0;
15 _charge=circle->getCharge();
16}
18 //initial
19 _ambig=i;
20}
21
22
24 bool ok_ambig[2];
25 bool ok[2][2];
26 ok_ambig[0]=true;
27 ok_ambig[1]=true;
28 ok[0][0]=false;
29 ok[0][1]=false;
30 ok[1][0]=false;
31 ok[1][1]=false;
32 double xeast = _rechit->getEastPoint().x();
33 double xwest = _rechit->getWestPoint().x();
34 double yeast = _rechit->getEastPoint().y();
35 double ywest = _rechit->getWestPoint().y();
36 double zeast = _rechit->getEastPoint().z();
37 double zwest = _rechit->getWestPoint().z();
38// cout<<"xeast xwest "<<xeast<<" "<<xwest<<endl;
39 double k = (ywest-yeast)/(xwest-xeast);
40 double b = -k*xeast+yeast;
41 // cout<<" k b "<<k<<" "<<b<<endl;
42 double xc = _circle->getCirX();
43 double yc = _circle->getCirY();
44 double rc = _circle->getCirR();
45// cout<<"xc yc rc "<<xc<<" "<<yc<<" "<<rc<<endl;
46 double drift = _rechit->getDriftDist();
47 //double drift = _rechit->getDriftDistTruth();
48// cout<<"drift "<<_rechit->getDriftDist()<<endl;
49// cout<<"driftTruth "<<_rechit->getDriftDistTruth()<<endl;
50 double x1(999),y1(999);
51 double x2(999),y2(999);
52 double a = k*k+1;
53 double b1 = -2*(xc+k*yc-k*b);
54 double c1 = xc*xc+(yc-b)*(yc-b)-(rc+drift)*(rc+drift);
55 double c2 = xc*xc+(yc-b)*(yc-b)-(rc-drift)*(rc-drift);
56 double delta1 = (b1*b1-4*a*c1);
57 double delta2 = (b1*b1-4*a*c2);
58 if( delta1 <0 ) ok_ambig[0] = false;
59 if( delta2 <0 ) ok_ambig[1] = false;
60 // cout<<"(b1*b1-4*a*c1) "<<(b1*b1-4*a*c1)<<endl;
61 // cout<<"(b1*b1-4*a*c2) "<<(b1*b1-4*a*c2)<<endl;
62 if( delta1>=0 ) {
63 double x1_0 = ( -b1+sqrt(delta1) ) /(2*a);
64 double x1_1 = ( -b1-sqrt(delta1) ) /(2*a);
65// cout<<"x1 0 1 "<<x1_0<<" "<<x1_1<<endl;
66 if( (xeast>=x1_0 && xwest<=x1_0) or (xeast<=x1_0 && xwest>=x1_0) ) ok[0][0] = true;
67 if ( (xeast>=x1_1 && xwest<=x1_1) or (xeast<=x1_1 && xwest>=x1_1) ) ok[0][1]=true;
68 if( ok[0][0] == true && ok[0][1]==false ) x1 = x1_0;
69 if( ok[0][0] == false && ok[0][1]==true ) x1 = x1_1;
70 if( ok[0][0] == true && ok[0][1]==true ) {
71 x1 = x1_0; //??good
72// cout<<" error both ok "<<endl;
73 }
74 if( ok[0][0] == false && ok[0][1]==false ) ok_ambig[0] = false;
75 y1 = k*x1+b;
76 double theta1 = 0;
77 double l1= 0;
78 double z1= 0;
79 if(ok_ambig[0]==true) {
80 calcu(x1,y1,xc,yc,rc,xeast,yeast,zeast,xwest,ywest,zwest,theta1,l1,z1);
81 if(m_debug>0) cout<<" theta1 l1 z1 "<<theta1<<" "<<l1<<" "<<z1<<endl;
82 _zleft = z1;
83 _lleft = l1;
84 }
85 }
86
87 if( delta2>=0){
88 double x2_0 = ( -b1+sqrt(delta2) ) /(2*a);
89 double x2_1 = ( -b1-sqrt(delta2) ) /(2*a);
90// cout<<"x2 0 1 "<<x2_0<<" "<<x2_1<<endl;
91 if( (xeast>=x2_0 && xwest<=x2_0) or (xeast<=x2_0 && xwest>=x2_0) ) ok[1][0] = true;
92 if ( (xeast>=x2_1 && xwest<=x2_1) or (xeast<=x2_1 && xwest>=x2_1) ) ok[1][1]=true;
93 if( ok[1][0] == true && ok[1][1]==false ) x2 = x2_0;
94 if( ok[1][0] == false && ok[1][1]==true ) x2 = x2_1;
95 if( ok[1][0] == true && ok[1][1]==true ) {
96 x2 = x2_0;
97// cout<<" error both ok "<<endl;
98 }
99 if( ok[1][0] == false && ok[1][1]==false ) ok_ambig[1] = false;
100 y2 = k*x2+b;
101 double theta2 = 0;
102 double l2= 0;
103 double z2= 0;
104 if(ok_ambig[1]==true) {
105 calcu(x2,y2,xc,yc,rc,xeast,yeast,zeast,xwest,ywest,zwest,theta2,l2,z2);
106 if(m_debug>0) cout<<" theta2 l2 z2 "<<theta2<<" "<<l2<<" "<<z2<<endl;
107 _zright = z2;
108 _lright = l2;
109 }
110 }
111 if( ok_ambig[0] == true && ok_ambig[1] == false ) return -1;
112 if( ok_ambig[0] == false && ok_ambig[1] == true ) return 1;
113 if( ok_ambig[0] == true && ok_ambig[1] == true ) return 2;
114 if( ok_ambig[0] == false && ok_ambig[1] == false ) return 0;
115 //cout<<" ztruth : "<<_rechit->getZTruth()<<endl;
116}
117
118
119void HoughStereo::calcu(double x1 ,double y1 ,double xc,double yc,double rc,double x_east,double y_east,double z_east,double x_west,double y_west,double z_west,double& theta,double& l,double& z){
120 //rphi -> sz
121 if(xc==0||x1-xc==0){
122 theta=0;
123 }
124 else{
125 theta=M_PI-atan2(y1-yc,x1-xc)+atan2(yc,xc);
126 if(theta>2*M_PI){
127 theta=theta-2*M_PI;
128 }
129 if(theta<0){
130 theta=theta+2*M_PI;
131 }
132 }
133 if(_charge == 1 ) theta = 2*M_PI-theta;
134
135 double d1=sqrt((x1-x_west)*(x1-x_west)+(y1-y_west)*(y1-y_west));
136 double d2=sqrt((x_east-x_west)*(x_east-x_west)+(y_east-y_west)*(y_east-y_west));
137// cout<<"d1/d2 "<<d1/d2<<" "<<d1<<" "<<d2<<endl;
138// cout<<"zw ze "<<z_west<<" "<<z_east<<endl;
139 z = z_west-(z_west-z_east)*d1/d2;
140 l = rc*theta;
141}
142/*
143
144
145int HoughStereo::cald(){
146 HepPoint3D fp =_rechit->getWestPoint();
147 HepPoint3D rp =_rechit->getEastPoint();
148 HepPoint3D X=_rechit->getMidPoint();
149 if(m_debug>0) std::cout<<"fp rp "<<fp<<" "<<rp<<std::endl;//yzhang debug
150 if(m_debug>0) std::cout<<"Xmid "<<X<<std::endl;//yzhang debug
151 HepVector3D xx = HepVector3D(X.x(), X.y(), 0.);
152 HepPoint3D center( _circle->getCirX(),_circle->getCirY(),0 );
153 HepVector3D yy = center - xx;
154 HepVector3D ww = HepVector3D(yy.x(), yy.y(), 0.);
155 double wwmag2 = ww.mag2();
156 double wwmag = sqrt(wwmag2);
157 double driftdist = fabs( _rechit->calDriftDist(_bunchTime,_ambig) );
158 if(m_debug>0) cout<<"Bunch time: "<<_bunchTime<<endl;
159 HepVector3D lr(driftdist/wwmag * ww.x(), driftdist/wwmag * ww.y(), 0.);
160
161 if(m_debug>0){
162 std::cout<<"xc "<< _circle->getCirX()<< " yc "<<_circle->getCirY()<< " drfitdist "<<driftdist<<std::endl;
163 std::cout<<"lr "<<lr<<" "<<" ambig "<<_ambig
164 <<"left "<<_rechit->calDriftDist(0,1)
165 <<"right "<<_rechit->calDriftDist(0,-1)<<std::endl;
166 }
167
168 HepPoint3D ORIGIN = HepPoint3D(0., 0., 0.);
169 if (_ambig == 0) lr = ORIGIN;
170 if (_charge> 0){
171 if (_ambig == -1){
172 lr = - lr;
173 }
174 }else{
175 if (_ambig == 1){
176 lr = - lr;
177 }
178 }
179 X += lr;
180
181 HepPoint3D tmp(-9999., -9999., 0.);
182 HepVector3D x = HepVector3D(X.x(), X.y(), 0.);
183 HepVector3D w = x - center;
184 // //modified the next sentence because the direction are different from belle.
185 HepVector3D V = _rechit->wire()->zAxis();
186 HepVector3D v = HepVector3D(V.x(), V.y(), 0.);
187 double vmag2 = v.mag2();
188 //double vmag = sqrt(vmag2);
189 //double r = _helix->curv();
190 double wv = w.dot(v);
191 // wv = abs(wv);
192 if(m_debug>0){
193 std::cout<<"X_fix "<<X<<" center "<<center<<std::endl;
194 std::cout<<"V "<<V<<std::endl;//yzhang debug
195 std::cout<<"w "<<w<<" v "<<v<<std::endl;
196 std::cout<<"wv "<<wv<<endl;
197 }
198 double d2 = wv * wv - vmag2 * (w.mag2() - _circle->getCirR()* _circle->getCirR() );
199 if ( d2<0. ) return -1;
200 double d=sqrt(d2);
201
202 double l[2];
203 l[0] =-1*( (- wv + d) / vmag2 ); //multiply -1 ......?
204 l[1] =-1*( (- wv - d) / vmag2 );
205
206 double z[2];
207 //z[0] = X.z() + l[0] * V.z();
208 z[0] = X.z() - l[0] * V.z(); //l *-1
209 z[1] = X.z() - l[1] * V.z();
210 if(m_debug>0) cout<<"z0 z1: "<<z[0]<<" "<<z[1]<<endl;
211
212
213 bool ok[2];
214 ok[0] = true;
215 ok[1] = true;
216 //...Check z position...
217 if (_ambig == 0) {
218 if (z[0] > rp.z()+20. || z[0] < fp.z()-20.) {
219 ok[0] = false;
220 }
221 if (z[1] > rp.z()+20. || z[1] < fp.z()-20.) {
222 ok[1] = false;
223 }
224 } else {
225 if (fabs(z[0]/rp.z())>1.05 ) { ok[0] = false; }
226 if (fabs(z[1]/rp.z())>1.05 ) { ok[1] = false; }
227 }
228 if ((! ok[0]) && (! ok[1])) {
229 return -1;
230 }
231 if (( ok[0]) && ( ok[1])) {
232 return 2;
233 }
234
235 unsigned best = 0;
236 if (ok[1]) best = 1; //need improve
237 HepVector3D p[2];
238 p[0] = x + l[0] * v;
239 p[1] = x + l[1] * v;
240 double cosdPhi = - center.dot((p[best] - center).unit()) / center.mag();
241 double dPhi;
242 if(fabs(cosdPhi)<=1.0) {
243 dPhi = acos(cosdPhi);
244 } else if (cosdPhi>1.0) {
245 dPhi = 0.0;
246 } else {
247 dPhi = pi;
248 }
249
250 double stemp=_circle->getCirR()*dPhi;
251 if(_ambig==-1){
252 _zright=z[best];
253 _lright=stemp;
254 }
255 if(_ambig==1){
256 _zleft=z[best];
257 _lleft=stemp;
258 }
259 if(m_debug>0){
260 cout<<"in hough stereo "<<endl;
261 cout<<"left: "<<_zleft<<" "<<_lleft<<endl;
262 cout<<"right: "<<_zright<<" "<<_lright<<endl;
263 }
264 return 0;
265}
266*/
267
268
270 _rechit->setzAmb( 0 , _zleft);
271 _rechit->setsAmb( 0 , _lleft);
272 _rechit->setzAmb( 1 , _zright);
273 _rechit->setsAmb( 1 , _lright);
274}
276 cout<<"Hit"<<"("<<_rechit->getLayerId()<<","<<_rechit->getWireId()<<") "<<_rechit->getStyle()<<endl;
277 cout<<" left: "<<_lleft<<","<<_zleft<<endl;
278 cout<<" right: "<<_lright<<","<<_zright<<endl;
279}
280
#define M_PI
Definition TConstant.h:4
@ theta2
Definition TrkKalDeriv.h:24
@ theta1
Definition TrkKalDeriv.h:24
double getCirR() const
Definition Hough2D.h:35
double getCirX() const
Definition Hough2D.h:33
double getCirY() const
Definition Hough2D.h:34
int getCharge() const
Definition Hough2D.h:39
double getDriftDist() const
Definition HoughHit.h:69
HepPoint3D getWestPoint() const
Definition HoughHit.h:59
HepPoint3D getEastPoint() const
Definition HoughHit.h:58
int getStyle() const
Definition HoughHit.h:106
int getLayerId() const
Definition HoughHit.h:62
int getWireId() const
Definition HoughHit.h:63
void setzAmb(int i, double zPos)
Definition HoughRecHit.h:32
void setsAmb(int i, double sPos)
Definition HoughRecHit.h:33
HoughStereo(double bunchTime, Hough2D *circle, HoughRecHit *rechit)
static int m_debug
Definition HoughStereo.h:26
void setAmb(int i)
void calcu(double x1, double y1, double xc, double yc, double rc, double x_east, double y_east, double z_east, double x_west, double y_west, double z_west, double &theta, double &l, double &z)
const double b
Definition slope.cxx:9