38 static bool alreadyInit =
false;
39 if ( alreadyInit )
return;
42 int lastsl =
gm->nSuper();
43 for (
int sl = 0;
sl < lastsl;
sl++ )
48 for (
int i = 0; i < nslay; i++ ) layArray[i] = slayer->
layer( i );
49 int cellMax = layArray[1]->
nWires();
51 for (
int cellIndex = 0; cellIndex < cellMax; cellIndex++ )
56 wireIndex[0] = cellIndex;
57 wireIndex[1] = cellIndex + 1;
58 wireIndex[2] = cellIndex;
59 wireIndex[3] = cellIndex + 1;
61 wireIndex[1] =
mdcWrapWire( wireIndex[1], layArray[1]->nWires() );
62 wireIndex[3] =
mdcWrapWire( wireIndex[3], layArray[3]->nWires() );
66 wireIndex[1] = cellIndex + 1;
68 double phi = layArray[1]->
getWire( wireIndex[1] )->
phiE();
69 for (
int i = 0; i < 4; i++ )
71 if ( i == 1 )
continue;
73 if ( i == 3 ) phi = layArray[2]->
getWire( wireIndex[2] )->
phiE();
74 BesAngle tmp( phi - layArray[i]->phiEPOffset() );
78 ( tmp == 0 ) ? 1 : (int)ceil( layArray[i]->nWires() * tmp.
rad() / twopi );
83 ( tmp == 0 ) ? -1 : (int)floor( layArray[i]->nWires() * tmp.
rad() / twopi );
85 wireIndex[i] =
mdcWrapWire( wireIndex[i], layArray[i]->nWires() );
90 for (
int i = 0; i < 4; i++ )
92 for (
int j = 0; j < 4; j++ )
95 w[4 * i + j] =
mdcWrapWire( ( wireIndex[i] + j - 1 ), layArray[i]->nWires() );
109 int lflag[44][288] = { { 0 } };
110 int pflag[44][288] = { { 0 } };
111 int ix, iy, iyp, iyn, cellMax;
116 int lastlay =
gm->nLayer();
130 for (
ix = 0;
ix < lastlay;
ix++ )
132 cellMax =
gm->Layer(
ix )->nWires();
134 for ( iy = 0; iy < cellMax; iy++ )
137 if ( iyp == cellMax ) iyp = 0;
139 if ( iyn == -1 ) iyn = cellMax - 1;
140 if ( ( lflag[
ix][iyp] != 0 ) && ( lflag[
ix][iyn] != 0 ) )
153 int lastsl =
gm->nSuper();
156 for (
sl = 0;
sl < lastsl;
sl++ )
159 int l0 = fsl, l1 = fsl + 1, l2 = fsl + 2, l3 = fsl + 3;
165 for (
int i = 0; i < nslay; i++ ) layArray[i] = slayer->
layer( i );
168 cout <<
"slayer No. " << slayer->
index() << endl;
171 cellMax = layArray[1]->
nWires();
174 for (
int cellIndex = 0; cellIndex < cellMax; cellIndex++ )
177 unsigned int sig_mark = 0;
178 for (
int ilayer = l0; ilayer <= l3; ilayer++ )
180 for (
int iwire = 3; iwire >= 0; iwire-- )
182 if ( lflag[ilayer][
w[4 * ( ilayer - l0 ) + iwire]] ) { sig_mark |= 0x1; }
190 int iPat = ( sig_mark & 0x0200 ) ? 0 : 11;
191 for ( ; iPat < nPat; iPat++ )
194 if ( ( pat & sig_mark ) == pat )
199 cout <<
"pat " << pat <<
" with wire";
200 for (
int tmpi = 0; tmpi < 4; tmpi++ )
202 cout <<
"(" << l0 + tmpi <<
","
203 <<
w[4 * tmpi +
m_segPat.wirePat4[iPat][tmpi] - 1] <<
")";
207 int w0 = lflag[l0][
w[0 +
m_segPat.wirePat4[iPat][0] - 1]] - 1;
208 int w1 = lflag[l1][
w[4 +
m_segPat.wirePat4[iPat][1] - 1]] - 1;
209 int w2 = lflag[l2][
w[8 +
m_segPat.wirePat4[iPat][2] - 1]] - 1;
210 int w3 = lflag[l3][
w[12 +
m_segPat.wirePat4[iPat][3] - 1]] - 1;
211 int tw[4] = { w0, w1, w2, w3 };
213 int namb =
m_segPat.ambPat4_size[iPat];
214 for (
int iamb = 0; iamb < namb; iamb++ )
216 int amb =
m_segPat.ambigPatt4[iPat][iamb];
220 cout <<
"chisq " <<
fithel.Chisq() <<
" <? csmax4 " << csmax_4 << endl;
221 if (
fithel.Chisq() < csmax_4 ) { cout <<
"Accept this seg" << endl; }
222 else { cout <<
"DROP this seg" << endl; }
225 if (
fithel.Chisq() < csmax_4 )
234 if ( goodSegNo != 0 )
continue;
236 iPat = ( sig_mark & 0x0200 ) ? 0 : 14;
237 for ( ; iPat < nPat; iPat++ )
239 if ( iPat > nPat - 3 )
241 if ( ( iPat == nPat - 2 ) && ( sig_mark & 0x2121 == 0x2121 ) )
continue;
242 if ( ( iPat == nPat - 1 ) && ( sig_mark & 0x2122 == 0x2122 ) )
continue;
245 if ( ( pat & sig_mark ) == pat )
250 cout <<
"MdcxFindSegs: in pat " << pat <<
" with wire";
251 for (
int tmpi = 0; tmpi < 4; tmpi++ )
253 if (
m_segPat.wirePat3[iPat][tmpi] == 0 )
continue;
254 cout <<
" (" << l0 + tmpi <<
","
255 <<
w[4 * tmpi +
m_segPat.wirePat3[iPat][tmpi] - 1] <<
")";
260 for (
int iw = 0, iwp = 0; iwp < 4; iwp++ )
263 if (
wireNo == 0 )
continue;
264 wn[iw++] = lflag[l0 + iwp][
w[4 * iwp +
wireNo - 1]] - 1;
267 int namb =
m_segPat.ambPat3_size[iPat];
268 for (
int iamb = 0; iamb < namb; iamb++ )
270 int amb =
m_segPat.ambigPatt3[iPat][iamb];
274 cout <<
"chisq " <<
fithel.Chisq() <<
" <? csmax3 " << csmax_3 << endl;
275 if (
fithel.Chisq() < csmax_3 ) { cout <<
"Accept this seg" << endl; }
276 else { cout <<
"DROP this seg" << endl; }
279 if (
fithel.Chisq() < csmax_3 )
291 { cout <<
"MdcxFindSegs found " <<
MdcxSeglist.length() <<
" segs" << endl; }
365 double dx = 0., dy = 0., d0 = 0.;
391 double phi0 = atan2( dy, dx );
394 MdcxHel hel( d0, phi0, 0.0, 0.0, 0.0, 0.0, 111, 0, dx, dy );
400 cout <<
"trial3 amb " << amb <<
": phi0 " << phi0 <<
" d0 " << d0 <<
" dx " << dx <<
" dy "