1#include "MdcxReco/MdcxFindSegs.h"
2#include "MdcxReco/MdcxHit.h"
3#include "MdcGeom/MdcDetector.h"
4#include "MdcTrkRecon/mdcWrapWire.h"
5#include "MdcGeom/BesAngle.h"
6#include "MdcxReco/MdcxParameters.h"
11#include "AIDA/IHistogram1D.h"
12#include "AIDA/IHistogram2D.h"
38 static bool alreadyInit =
false;
39 if (alreadyInit)
return;
43 for (
int sl = 0;
sl < lastsl;
sl++) {
47 for (
int i = 0; i < nslay; i++) layArray[i] = slayer->
layer(i);
48 int cellMax = layArray[1]->
nWires();
50 for (
int cellIndex = 0; cellIndex < cellMax ; cellIndex++) {
53 wireIndex[0]= cellIndex;
54 wireIndex[1]= cellIndex+1;
55 wireIndex[2]= cellIndex;
56 wireIndex[3]= cellIndex+1;
58 wireIndex[1] =
mdcWrapWire(wireIndex[1], layArray[1]->nWires());
59 wireIndex[3] =
mdcWrapWire(wireIndex[3], layArray[3]->nWires());
61 wireIndex[1]= cellIndex+1;
63 double phi = layArray[1]->
getWire(wireIndex[1])->
phiE();
64 for(
int i = 0; i < 4; i++ ) {
65 if ( i == 1 )
continue;
67 if ( i == 3 ) phi = layArray[2]->
getWire(wireIndex[2])->
phiE();
68 BesAngle tmp(phi - layArray[i]->phiEPOffset());
70 wireIndex[i]=(tmp==0)?1:(
int)ceil(layArray[i]->nWires()*tmp.
rad()/twopi);
72 wireIndex[i]=(tmp==0)?-1:(
int)floor(layArray[i]->nWires()*tmp.
rad()/twopi);
74 wireIndex[i] =
mdcWrapWire(wireIndex[i], layArray[i]->nWires());
79 for (
int i = 0; i < 4; i++) {
80 for (
int j = 0; j < 4; j++) {
82 w[4*i+j] =
mdcWrapWire((wireIndex[i]+j-1), layArray[i]->nWires());
96 int lflag[44][288] = { {0} };
97 int pflag[44][288] = { {0} };
98 int ix,iy,iyp,iyn,cellMax;
115 for (ix=0; ix<lastlay; ix++){
118 for (iy=0; iy<cellMax; iy++){
119 iyp=iy+1;
if (iyp == cellMax)iyp=0;
120 iyn=iy-1;
if (iyn == -1)iyn=cellMax-1;
121 if ((lflag[ix][iyp] != 0) && (lflag[ix][iyn] != 0)) {
136 for (
sl = 0;
sl < lastsl;
sl++) {
138 int l0=fsl, l1=fsl+1, l2=fsl+2, l3=fsl+3;
144 for (
int i = 0; i < nslay; i++) layArray[i] = slayer->
layer(i);
146 cout<<
"slayer No. "<<slayer->
index()<<endl;
149 cellMax = layArray[1]->
nWires();
152 for (
int cellIndex=0; cellIndex<cellMax ; cellIndex++) {
154 unsigned int sig_mark = 0;
155 for (
int ilayer = l0; ilayer <= l3; ilayer++) {
156 for (
int iwire = 3; iwire >= 0; iwire--) {
157 if (lflag[ilayer][w[4*(ilayer-l0)+iwire]]) {
167 int iPat = (sig_mark & 0x0200) ? 0 : 11;
168 for ( ; iPat < nPat; iPat++) {
170 if ((pat & sig_mark) == pat) {
172 cout<<
"pat " << std::hex << pat << std::dec <<
" with wire";
173 for (
int tmpi = 0; tmpi < 4; tmpi++) {
182 int tw[4] = {w0, w1, w2, w3};
185 for (
int iamb = 0; iamb < namb; iamb++) {
190 <<
" <? csmax4 "<<csmax_4<< endl;
192 cout<<
"Accept this seg"<<endl;
194 cout<<
"DROP this seg"<<endl;
206 if (goodSegNo != 0)
continue;
208 iPat = (sig_mark & 0x0200) ? 0 : 14;
209 for ( ; iPat < nPat; iPat++) {
211 if ((iPat == nPat-2) && (sig_mark&0x2121 == 0x2121))
continue;
212 if ((iPat == nPat-1) && (sig_mark&0x2122 == 0x2122))
continue;
215 if ((pat & sig_mark) == pat) {
217 cout<<
"MdcxFindSegs: in pat "<<std::hex<<pat<<std::dec<<
" with wire";
218 for (
int tmpi = 0; tmpi < 4; tmpi++) {
220 cout<<
" (" << l0+tmpi <<
"," << w[4*tmpi+
m_segPat.
wirePat3[iPat][tmpi]-1] <<
")";
225 for (
int iw = 0, iwp = 0; iwp < 4; iwp++) {
227 if(
wireNo == 0 )
continue;
228 wn[iw++] = lflag[l0+iwp][w[4*iwp+
wireNo-1]] - 1;
232 for (
int iamb = 0; iamb < namb; iamb++) {
237 <<
" <? csmax3 "<<csmax_3<< endl;
239 cout<<
"Accept this seg"<<endl;
241 cout<<
"DROP this seg"<<endl;
256 cout <<
"MdcxFindSegs found " <<
MdcxSeglist.length() <<
" segs" << endl;
263 o <<
" First " << mcheck <<
" Drift Chamber Segs:" << endl;
264 for(
int i=0; i<mcheck; i++){
265 o <<
" Superlayer # " <<
MdcxSeglist[i]->SuperLayer();
266 o <<
" # of hits " <<
MdcxSeglist[i]->Nhits() << endl;
274 seg.append(t1); seg.append(t2); seg.append(t3); seg.append(t4);
280 double phi0 = atan2(dy,dx); dx=t1->
x(); dy=t1->
y();
281 MdcxHel hel(d0,phi0,0.0,0.0,0.0,0.0,111,0,dx,dy);
285 cout<<
"trial4 amb "<<amb
286 <<
": phi0 " << phi0 <<
" d0 " << d0
287 <<
" dx " << dx <<
" dy " << dy << endl;
298 seg.append(t1); seg.append(t2); seg.append(t3);
305 double phi0 = atan2(dy,dx); dx=t1->
x(); dy=t1->
y();
306 MdcxHel hel(d0,phi0,0.0,0.0,0.0,0.0,111,0,dx,dy);
311 cout<<
"trial3 amb "<<amb
312 <<
": phi0 " << phi0 <<
" d0 " << d0
313 <<
" dx " << dx <<
" dy " << dy << endl;
324 cout <<
"Seg: pat " << pat <<
" amb " << amb <<
" subtry " << subtry
325 <<
" sl " <<
sl <<
" fail "
int mdcWrapWire(int wireIn, int nCell)
AIDA::IHistogram1D * g_csmax3
AIDA::IHistogram1D * g_csmax4
AIDA::IHistogram1D * g_csmax3
AIDA::IHistogram1D * g_csmax4
const MdcSuperLayer * SuperLayer(unsigned id) const
const MdcLayer * Layer(unsigned id) const
static MdcDetector * instance()
MdcSWire * getWire(int wire) const
const MdcLayer * layer(int i) const
HepAList< MdcxSeg > MdcxSeglist
HepAList< MdcxHit > dchitlist
void appendseg(MdcxFittedHel &fithel, int pat, int amb)
MdcxFindSegs(MdcDetector *g, const HepAList< MdcxHit > &l, int m_debug=0)
void initWireGroups(void)
MdcxFittedHel trial(int i1, int i2, int i3, int i4, int amb)
static int wireGroups[11][288][16]
void printseg(MdcxFittedHel &fithel, int pat, int amb, int subtry=0)
void print(std::ostream &o, int pmax=10) const
int Fail(float Probmin=0.0) const
void SetTurnFlag(const int &i)
float d(MdcxHel &hel) const
static const unsigned patt4[14]
static const int ambigPatt4[14][4]
static const int wirePat4[14][4]
static const int ambigPatt3[20][4]
static const int patt4_size
static const int ambPat3_size[20]
static const int ambPat4_size[14]
static const unsigned patt3[20]
static const int wirePat3[20][4]
static const int patt3_size