16 if( (*iter).getSlayerType() !=0 && (*iter).getflag()==0 && (*iter).getLayerId()<8 ) _recStereoHit.push_back(&(*
iter));
18 _hitSize=_recStereoHit.size();
22 if(
m_debug>0) cout<<
"size of rechit in zs fit "<<_hitSize<<endl;
29 if(_hitSize>=3)
doit();
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]) );
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;
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;
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]) );
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;
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) {
116 if(
m_debug>0) cout<<
"left "<<line_size<<
" chi k b "<<chil<<
" "<<kl<<
" "<<bl<<endl;
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;
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) {
127 if(
m_debug>0) cout<<
"right "<<line_size<<
" chi k b "<<chir<<
" "<<kr<<
" "<<br<<endl;
130 linefit[i].
_pointCol[line_size].setAmb(0);
131 linefit[i].
_chi=chil;
134 linefit[i].
_ambig.push_back(0);
137 else linefit[i].
_ambig.push_back(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();
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;
162 if( fabs(dChi_n) > 25.)
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;
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;
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();
190 if (ambig!=-999) l= _recStereoHit.at(j)->getsAmb(ambig);
192 if (ambig!=-999) z= _recStereoHit.at(j)->getzAmb(ambig);
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;
197 _recStereoHit[j]->setAmb(ambig);
198 if( ambig ==-999) _recStereoHit[j]->setflag(-999);
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++;
204 _pro_correct = (double)ambig_correct/(
double)_hitSize;
210 if(
m_debug>0) cout<<
"z0 tanl : "<<_z0<<
" "<<_tanl<<endl;
312 double *
x=
new double[N+1];
313 double *
y=
new double[N+1];
314 for(
int i=0;i<N;i++){
319 if(
m_debug>0) cout<<
" x "<<a<<
" y "<<
b<<endl;
323 double k(0),
b(0),chi2(0);
342 for(
int i=0;i<nhit;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];
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);
353 for(
int i=0;i<nhit;i++){
356 if(yE[i]!=0) chi2_temp=(
y[i]-yE[i])*(
y[i]-yE[i])/yE[i]*yE[i];
365 return (*hita).getLayerId() > (*hitb).getLayerId();
368 std::sort (_recStereoHit.begin(),_recStereoHit.end(),
layer_in_track);
371 for(
int i =0;i<_recStereoHit.size();i++){
372 cout<<
"("<<_recStereoHit[i]->getLayerId()<<
","<<_recStereoHit[i]->getWireId()<<
")"<<endl;
std::vector< HoughRecHit > recHitCol
bool layer_in_track(const HoughRecHit *hita, const HoughRecHit *hitb)
bool compare_zsfit(const HoughZsFit::Line &a, const HoughZsFit::Line &b)
bool layer_in_track(const HoughRecHit *hita, const HoughRecHit *hitb)
bool compare_zsfit(const HoughZsFit::Line &a, const HoughZsFit::Line &b)
HoughZsFit(vector< HoughRecHit > *recHitCol)
int leastLine(int, double x[], double y[], double &, double &, double &)
void leastFit(Line &linefit, int N)
std::vector< int > _ambig
std::vector< HoughRecHit > _pointCol