BOSS 7.0.5
BESIII Offline Software System
Loading...
Searching...
No Matches
HoughZsFit Class Reference

#include <HoughZsFit.h>

Classes

struct  Line
 

Public Member Functions

 HoughZsFit (vector< HoughRecHit > *recHitCol)
 
 ~HoughZsFit ()
 
void leastFit (Line &linefit, int N)
 
int leastLine (int, double x[], double y[], double &, double &, double &)
 
void doit ()
 
void initPoint ()
 
double getTanl () const
 
double getZ0 () const
 
double getPro () const
 
void sortHit ()
 
void print ()
 
 HoughZsFit (vector< HoughRecHit > *recHitCol)
 
 ~HoughZsFit ()
 
void leastFit (Line &linefit, int N)
 
int leastLine (int, double x[], double y[], double &, double &, double &)
 
void doit ()
 
void initPoint ()
 
double getTanl () const
 
double getZ0 () const
 
double getPro () const
 
void sortHit ()
 
void print ()
 

Static Public Attributes

static int m_debug =0
 

Detailed Description

Constructor & Destructor Documentation

◆ HoughZsFit() [1/2]

HoughZsFit::HoughZsFit ( vector< HoughRecHit > *  recHitCol)

Definition at line 11 of file HoughZsFit.cxx.

12{
13 vector<HoughRecHit>::iterator iter=recHitCol->begin();
14 for(;iter!=recHitCol->end();iter++){
15 //if( fabs((*iter).getzAmb(0))>10 && fabs((*iter).getzAmb(1))>10 ) continue;
16 if( (*iter).getSlayerType() !=0 && (*iter).getflag()==0 && (*iter).getLayerId()<8 ) _recStereoHit.push_back(&(*iter));
17 }
18 _hitSize=_recStereoHit.size();
19 _pro_correct =0;
20 sortHit();
21 if(m_debug>0) print();
22 if(m_debug>0) cout<<"size of rechit in zs fit "<<_hitSize<<endl;
23
24// _vecPoint = new Point*[_hitSize];
25// for(int i=0;i<_hitSize;i++){
26// _vecPoint[i] = new Point[2];
27// }
28// initPoint();
29 if(_hitSize>=3) doit();
30 else {_tanl=0;_z0=0;}
31}
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
std::vector< HoughRecHit > recHitCol
void doit()
Definition: HoughZsFit.cxx:36
void print()
Definition: HoughZsFit.cxx:370
void sortHit()
Definition: HoughZsFit.cxx:367

◆ ~HoughZsFit() [1/2]

HoughZsFit::~HoughZsFit ( )

Definition at line 33 of file HoughZsFit.cxx.

33 {
34}

◆ HoughZsFit() [2/2]

HoughZsFit::HoughZsFit ( vector< HoughRecHit > *  recHitCol)

◆ ~HoughZsFit() [2/2]

HoughZsFit::~HoughZsFit ( )

Member Function Documentation

◆ doit() [1/2]

void HoughZsFit::doit ( )

Definition at line 36 of file HoughZsFit.cxx.

36 {
37
38// Point point0;
39// point0.first=0.;
40// point0.second=0.;
41
42 Line linefit[8];
43
44 for(int iline=0;iline<8;iline++){
45 linefit[iline]._pointCol.push_back( *(_recStereoHit[0]) );
46 linefit[iline]._pointCol.push_back( *(_recStereoHit[1]) );
47 linefit[iline]._pointCol.push_back( *(_recStereoHit[2]) );
48 }
49 if(m_debug>0) {
50 for(int i =0;i<3;i++){
51 cout<<" the first 3 hits ("<<i<<" "<< _recStereoHit[i]->getLayerId()<<","<<_recStereoHit[i]->getWireId()<<")"<<endl;
52 cout<<" left "<<(_recStereoHit[i])->getsAmb(0)<<" "<<(_recStereoHit[i])->getzAmb(0)<<endl;
53 cout<<" right "<<(_recStereoHit[i])->getsAmb(1)<<" "<<(_recStereoHit[i])->getzAmb(1)<<endl;
54 }
55 }
56
57 linefit[0]._pointCol[0].setAmb(0);
58 linefit[0]._pointCol[1].setAmb(0);
59 linefit[0]._pointCol[2].setAmb(0);
60
61 linefit[1]._pointCol[0].setAmb(0);
62 linefit[1]._pointCol[1].setAmb(0);
63 linefit[1]._pointCol[2].setAmb(1);
64
65 linefit[2]._pointCol[0].setAmb(0);
66 linefit[2]._pointCol[1].setAmb(1);
67 linefit[2]._pointCol[2].setAmb(0);
68
69 linefit[3]._pointCol[0].setAmb(0);
70 linefit[3]._pointCol[1].setAmb(1);
71 linefit[3]._pointCol[2].setAmb(1);
72
73
74 linefit[4]._pointCol[0].setAmb(1);
75 linefit[4]._pointCol[1].setAmb(0);
76 linefit[4]._pointCol[2].setAmb(0);
77
78 linefit[5]._pointCol[0].setAmb(1);
79 linefit[5]._pointCol[1].setAmb(0);
80 linefit[5]._pointCol[2].setAmb(1);
81
82 linefit[6]._pointCol[0].setAmb(1);
83 linefit[6]._pointCol[1].setAmb(1);
84 linefit[6]._pointCol[2].setAmb(0);
85
86 linefit[7]._pointCol[0].setAmb(1);
87 linefit[7]._pointCol[1].setAmb(1);
88 linefit[7]._pointCol[2].setAmb(1);
89
90 for(int i=0;i<8;i++){
91 linefit[i]._ambig.push_back( linefit[i]._pointCol[0].getAmbig() );
92 linefit[i]._ambig.push_back( linefit[i]._pointCol[1].getAmbig() );
93 linefit[i]._ambig.push_back( linefit[i]._pointCol[2].getAmbig() );
94 if(m_debug>0) cout<<" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^begin line "<<i<<endl;
95 leastFit(linefit[i],3);
96 //judst if there is noise in the 3 outer
97 int line_size=3;
98 for(int j=3;j<_hitSize;j++){
99 double chi_last=linefit[i]._chi;
100 double k_last=linefit[i]._k;
101 double b_last=linefit[i]._b;
102 if(m_debug>0) cout<<"last "<<j<<" chi k b "<<chi_last<<" "<<k_last<<" "<<b_last<<endl;
103 linefit[i]._pointCol.push_back( *(_recStereoHit[j]) );
104 //int layer =linefit[i]._pointCol.back().getLayerId();
105 //int wire=linefit[i]._pointCol.back().getWireId();
106 //cout<<"???ambig ("<<layer<<","<<wire<<") "<<linefit[i]._pointCol.back().getLrTruth()<<endl;
107 linefit[i]._pointCol[line_size].setAmb(0);
108 if(m_debug>0) cout<<"Add point left "<<"("<<linefit[i]._pointCol[line_size].getLayerId()<<","<<linefit[i]._pointCol[line_size].getWireId()<<") "<<linefit[i]._pointCol[line_size].getStyle()<<" "<<linefit[i]._pointCol[line_size].getsPos()<<" "<<linefit[i]._pointCol[line_size].getzPos()<<endl;
109 leastFit(linefit[i],line_size+1);
110 double chil=linefit[i]._chi;
111 double kl=linefit[i]._k;
112 double bl=linefit[i]._b;
113 if (linefit[i]._pointCol[line_size].getsPos()==-99) {
114 chil = 9999;
115 }
116 if(m_debug>0) cout<<"left "<<line_size<<" chi k b "<<chil<<" "<<kl<<" "<<bl<<endl;
117
118 linefit[i]._pointCol[line_size].setAmb(1);
119 if(m_debug>0) cout<<"Add point right "<<"("<<linefit[i]._pointCol[line_size].getLayerId()<<","<<linefit[i]._pointCol[line_size].getWireId()<<") "<<linefit[i]._pointCol[line_size].getStyle()<<" "<<linefit[i]._pointCol[line_size].getsPos()<<" "<<linefit[i]._pointCol[line_size].getzPos()<<endl;
120 leastFit(linefit[i],line_size+1);
121 double chir=linefit[i]._chi;
122 double kr=linefit[i]._k;
123 double br=linefit[i]._b;
124 if (linefit[i]._pointCol[line_size].getsPos()==-99) {
125 chir = 9999;
126 }
127 if(m_debug>0) cout<<"right "<<line_size<<" chi k b "<<chir<<" "<<kr<<" "<<br<<endl;
128
129 if(chil<chir) {
130 linefit[i]._pointCol[line_size].setAmb(0);
131 linefit[i]._chi=chil;
132 linefit[i]._k=kl;
133 linefit[i]._b=bl;
134 linefit[i]._ambig.push_back(0);
135 //_recStereoHit[j]->setAmb(0);
136 }
137 else linefit[i]._ambig.push_back(1);
138 line_size++;
139
140 //test ambig with truth
141 int same_ambig = 1;
142 for(int ihit=0;ihit<line_size;ihit++){
143 int ambighit = linefit[i]._pointCol[ihit].getAmbig();
144 int ambigTruth = linefit[i]._pointCol[ihit].getLrTruth();
145 int layer =linefit[i]._pointCol[ihit].getLayerId();
146 int wire=linefit[i]._pointCol[ihit].getWireId();
147 //if (ambigTruth == -1) ambigTruth=1;
148 //else if (ambigTruth == 1) ambigTruth=0;
149 //else cout << "wrong in ambig Truth "<<endl;
150
151 //if(ambighit!= ambigTruth ) same_ambig=0;
152 }
153 //if(m_debug >0 ) cout << "same ambig ? "<<same_ambig<<endl;
154
155
156 double dChi = chi_last-linefit[i]._chi;
157 double dChi_n = (linefit[i]._chi)/(line_size-1)-(chi_last/line_size);
158 if(m_debug>0) cout<<"dChi: "<<dChi<<endl;
159 if(m_debug>0) cout<<"dChi/n: "<<dChi_n<<endl;
160 if(m_debug>0) cout<<endl;
161 // if( fabs(dChi) > 500.) //FIXME
162 if( fabs(dChi_n) > 25.) //FIXME
163 // linefit[i]._pointCol[j].setAmb(-999);
164 //_recStereoHit[j]->setAmb(-999);
165 //_recStereoHit[j]->setflag(-999);
166 {
167 linefit[i]._pointCol.pop_back();
168 linefit[i]._chi=chi_last;
169 linefit[i]._k=k_last;
170 linefit[i]._b=b_last;
171 linefit[i]._ambig.at(j)=-999;
172 line_size--;
173 }
174 }
175 //reject wrong line
176 if( (linefit[i]._pointCol[0].getsPos()==-99) || (linefit[i]._pointCol[1].getsPos()==-99) || (linefit[i]._pointCol[2].getsPos()==-99) ) {
177 linefit[i]._chi=99999;
178 }
179 }
180 std::sort(linefit,linefit+8,compare_zsfit);
181 for(int i=0;i<8;i++){
182 if(m_debug>0) cout<<"Line :"<<i<<" chis: "<<linefit[i]._chi<<" k,b: "<<linefit[i]._k<<" "<<linefit[i]._b<<endl;
183 int ambig_correct = 0;
184 for(int j=0;j<_hitSize;j++){
185 int ambig = linefit[i]._ambig.at(j);
186 int layer= _recStereoHit.at(j)->getLayerId();
187 int wire= _recStereoHit.at(j)->getWireId();
188 int style= _recStereoHit.at(j)->getStyle();
189 double l=-99;
190 if (ambig!=-999) l= _recStereoHit.at(j)->getsAmb(ambig);
191 double z=-99;
192 if (ambig!=-999) z= _recStereoHit.at(j)->getzAmb(ambig);
193 // cout<<"debug ("<<layer<<" ,"<<wire<<") style "<<style<<" ambig "<<ambig<<" s "<<l<<" z "<<z<<endl;
194 if (l==-99 && z==-99) ambig=-999;
195 if(m_debug>0) cout<<"("<<layer<<" ,"<<wire<<") style "<<style<<" ambig "<<ambig<<" s "<<l<<" z "<<z<<endl;
196 if(i==0) {
197 _recStereoHit[j]->setAmb(ambig); // when line 0 select
198 if( ambig ==-999) _recStereoHit[j]->setflag(-999); // when line 0 select
199 int ambigTruth = _recStereoHit.at(j)->getLrTruth();
200 if (ambigTruth == -1) ambigTruth=1;
201 else if (ambigTruth == 1) ambigTruth=0;
202 if(ambig ==ambigTruth) ambig_correct++;
203 //cout<<"ambig : "<<ambig<<" "<<ambigTruth<<endl;
204 _pro_correct = (double)ambig_correct/(double)_hitSize;
205 }
206 }
207 }
208 _tanl=linefit[0]._k;
209 _z0=linefit[0]._b;
210 if(m_debug>0) cout<<"z0 tanl : "<<_z0<<" "<<_tanl<<endl;
211
212 /*
213 linefit[0]._pointCol.push_back(_vecPoint[_hitSize-1][0]);
214 linefit[0]._pointCol.push_back(_vecPoint[_hitSize-2][0]);
215 linefit[0]._pointCol.push_back(_vecPoint[_hitSize-3][0]);
216
217 linefit[1]._pointCol.push_back(_vecPoint[_hitSize-1][0]);
218 linefit[1]._pointCol.push_back(_vecPoint[_hitSize-2][0]);
219 linefit[1]._pointCol.push_back(_vecPoint[_hitSize-3][1]);
220
221 linefit[2]._pointCol.push_back(_vecPoint[_hitSize-1][0]);
222 linefit[2]._pointCol.push_back(_vecPoint[_hitSize-2][1]);
223 linefit[2]._pointCol.push_back(_vecPoint[_hitSize-3][0]);
224
225 linefit[3]._pointCol.push_back(_vecPoint[_hitSize-1][0]);
226 linefit[3]._pointCol.push_back(_vecPoint[_hitSize-2][1]);
227 linefit[3]._pointCol.push_back(_vecPoint[_hitSize-3][1]);
228
229 linefit[4]._pointCol.push_back(_vecPoint[_hitSize-1][1]);
230 linefit[4]._pointCol.push_back(_vecPoint[_hitSize-2][0]);
231 linefit[4]._pointCol.push_back(_vecPoint[_hitSize-3][0]);
232
233 linefit[5]._pointCol.push_back(_vecPoint[_hitSize-1][1]);
234 linefit[5]._pointCol.push_back(_vecPoint[_hitSize-2][0]);
235 linefit[5]._pointCol.push_back(_vecPoint[_hitSize-3][1]);
236
237 linefit[6]._pointCol.push_back(_vecPoint[_hitSize-1][1]);
238 linefit[6]._pointCol.push_back(_vecPoint[_hitSize-2][1]);
239 linefit[6]._pointCol.push_back(_vecPoint[_hitSize-3][0]);
240
241 linefit[7]._pointCol.push_back(_vecPoint[_hitSize-1][1]);
242 linefit[7]._pointCol.push_back(_vecPoint[_hitSize-2][1]);
243 linefit[7]._pointCol.push_back(_vecPoint[_hitSize-3][1]);
244
245
246 for(int i=0;i<8;i++){
247 linefit[i]._amg=i*pow(10,(_hitSize-3));
248 if(m_debug>0) cout<<"Start line ooooooooooooooooooooooooooooooooooooooooooooooooo"<<i<<endl;
249 for(int j=4;j<_hitSize+1;j++){
250 if(m_debug>0) cout<<"Start add _vecPoint ****************************"<<j<<endl;
251 linefit[i]._pointCol.push_back(_vecPoint[_hitSize-j][0]);
252 leastFit(linefit[i],j);
253 double chil=linefit[i]._chi;
254 double kl=linefit[i]._k;
255 double bl=linefit[i]._b;
256
257 linefit[i]._pointCol[j-1]=_vecPoint[_hitSize-j][1];
258 leastFit(linefit[i],j);
259 double chir=linefit[i]._chi;
260 double kr=linefit[i]._k;
261 double br=linefit[i]._b;
262 if(m_debug>0){
263 cout<<chil<<" "<<kl<<" "<<bl<<endl;
264 cout<<chir<<" "<<kr<<" "<<br<<endl;
265 }
266
267 if(chil<chir) {
268 // cout<<"j: "<<j<<endl;
269 linefit[i]._pointCol[j-1]=_vecPoint[_hitSize-j][0];
270 linefit[i]._chi=chil;
271 linefit[i]._k=kl;
272 linefit[i]._b=bl;
273 linefit[i]._amg+=0*pow(10,(_hitSize-j));
274 }
275 else { linefit[i]._amg+=1*pow(10,(_hitSize-j)); }
276 }
277 if(m_debug>0) cout<<"Start add _vecPoint ****************************"<<"0"<<endl;
278 linefit[i]._pointCol.push_back(point0);
279 leastFit(linefit[i],_hitSize+1);
280 double chi0=linefit[i]._chi;
281 double k0=linefit[i]._k;
282 double b0=linefit[i]._b;
283 if(m_debug>0) cout<<chi0<<" "<<k0<<" "<<b0<<endl;
284}
285std::sort(linefit,linefit+8,compare_zsfit);
286for(int i=0;i<8;i++){
287 if(m_debug>0) cout<<"Line :"<<i<<" chis: "<<linefit[i]._chi<<" k,b: "<<linefit[i]._k<<" "<<linefit[i]._b<<" amg: "<<linefit[i]._amg<<endl;
288}
289_tanl=linefit[0]._k;
290_z0=linefit[0]._b;
291if(m_debug>0) cout<<"z0 tanl : "<<_z0<<" "<<_tanl<<endl;
292*/
293}
bool compare_zsfit(const HoughZsFit::Line &a, const HoughZsFit::Line &b)
Definition: HoughZsFit.cxx:332
void leastFit(Line &linefit, int N)
Definition: HoughZsFit.cxx:311

Referenced by HoughZsFit().

◆ doit() [2/2]

void HoughZsFit::doit ( )

◆ getPro() [1/2]

double HoughZsFit::getPro ( ) const
inline

Definition at line 24 of file InstallArea/include/MdcHoughFinder/MdcHoughFinder/HoughZsFit.h.

24{return _pro_correct;}

Referenced by HoughTrack::fitzs().

◆ getPro() [2/2]

double HoughZsFit::getPro ( ) const
inline

Definition at line 24 of file Reconstruction/MdcHoughFinder/MdcHoughFinder-00-00-14/MdcHoughFinder/HoughZsFit.h.

24{return _pro_correct;}

◆ getTanl() [1/2]

double HoughZsFit::getTanl ( ) const
inline

Definition at line 22 of file InstallArea/include/MdcHoughFinder/MdcHoughFinder/HoughZsFit.h.

22{return _tanl;}

Referenced by HoughTrack::fitzs().

◆ getTanl() [2/2]

double HoughZsFit::getTanl ( ) const
inline

◆ getZ0() [1/2]

double HoughZsFit::getZ0 ( ) const
inline

Definition at line 23 of file InstallArea/include/MdcHoughFinder/MdcHoughFinder/HoughZsFit.h.

23{return _z0;}

Referenced by HoughTrack::fitzs().

◆ getZ0() [2/2]

double HoughZsFit::getZ0 ( ) const
inline

◆ initPoint() [1/2]

void HoughZsFit::initPoint ( )

◆ initPoint() [2/2]

void HoughZsFit::initPoint ( )

◆ leastFit() [1/2]

void HoughZsFit::leastFit ( Line linefit,
int  N 
)

Definition at line 311 of file HoughZsFit.cxx.

311 {
312 double *x=new double[N+1];
313 double *y=new double[N+1];
314 for(int i=0;i<N;i++){
315 double a=linefit._pointCol[i].getsPos();
316 double b=linefit._pointCol[i].getzPos();
317 x[i]=a;
318 y[i]=b;
319 if(m_debug>0) cout<<" x "<<a<<" y "<<b<<endl;
320 }
321 x[N]=0.;
322 y[N]=0.;
323 double k(0),b(0),chi2(0);
324 leastLine(N+1,x,y,k,b,chi2);
325 linefit._k =k;
326 linefit._b =b;
327 linefit._chi=chi2;
328 delete []x;
329 delete []y;
330
331}
Double_t x[10]
int leastLine(int, double x[], double y[], double &, double &, double &)
Definition: HoughZsFit.cxx:336
double y[1000]
const double b
Definition: slope.cxx:9

Referenced by doit().

◆ leastFit() [2/2]

void HoughZsFit::leastFit ( Line linefit,
int  N 
)

◆ leastLine() [1/2]

int HoughZsFit::leastLine ( int  nhit,
double  x[],
double  y[],
double &  k,
double &  b,
double &  chi2 
)

Definition at line 336 of file HoughZsFit.cxx.

336 {
337 double x_sum=0;
338 double y_sum=0;
339 double x2_sum=0;
340 double y2_sum=0;
341 double xy_sum=0;
342 for(int i=0;i<nhit;i++){
343 x_sum=x_sum+x[i];
344 y_sum=y_sum+y[i];
345 x2_sum=x2_sum+x[i]*x[i];
346 y2_sum=y2_sum+y[i]*y[i];
347 xy_sum=xy_sum+x[i]*y[i];
348 }
349 b=(x2_sum*y_sum-xy_sum*x_sum)/(nhit*x2_sum-x_sum*x_sum);
350 k=(nhit*xy_sum-x_sum*y_sum)/(nhit*x2_sum-x_sum*x_sum);
351
352 double yE[3];
353 for(int i=0;i<nhit;i++){
354 yE[i]=k*x[i]+b;
355 double chi2_temp;
356 if(yE[i]!=0) chi2_temp=(y[i]-yE[i])*(y[i]-yE[i])/yE[i]*yE[i];
357 else chi2_temp=0;
358 chi2+=chi2_temp;
359 }
360
361 return 1;
362}

Referenced by leastFit().

◆ leastLine() [2/2]

int HoughZsFit::leastLine ( int  ,
double  x[],
double  y[],
double &  ,
double &  ,
double &   
)

◆ print() [1/2]

void HoughZsFit::print ( )

Definition at line 370 of file HoughZsFit.cxx.

370 {
371 for(int i =0;i<_recStereoHit.size();i++){
372 cout<<"("<<_recStereoHit[i]->getLayerId()<<","<<_recStereoHit[i]->getWireId()<<")"<<endl;
373 }
374}

Referenced by HoughZsFit().

◆ print() [2/2]

void HoughZsFit::print ( )

◆ sortHit() [1/2]

void HoughZsFit::sortHit ( )

Definition at line 367 of file HoughZsFit.cxx.

367 {
368 std::sort (_recStereoHit.begin(),_recStereoHit.end(),layer_in_track);
369}
bool layer_in_track(const HoughRecHit *hita, const HoughRecHit *hitb)
Definition: HoughZsFit.cxx:364

Referenced by HoughZsFit().

◆ sortHit() [2/2]

void HoughZsFit::sortHit ( )

Member Data Documentation

◆ m_debug

int HoughZsFit::m_debug =0
static

The documentation for this class was generated from the following files: