MdcxFindSegs Class Reference

#include <MdcxFindSegs.h>

List of all members.

Public Member Functions

 MdcxFindSegs (MdcDetector *g, const HepAList< MdcxHit > &l, int m_debug=0)
 MdcxFindSegs (const HepAList< MdcxHit > &l, int debug=0)
virtual ~MdcxFindSegs ()
void initWireGroups (void)
void process ()
const HepAList< MdcxSeg > & GetMdcxSeglist ()
void appendseg (MdcxFittedHel &fithel, int pat, int amb)
void printseg (MdcxFittedHel &fithel, int pat, int amb, int subtry=0)
void print (std::ostream &o, int pmax=10) const
void setDebug (bool debug=0)

Protected Member Functions

MdcxFittedHel trial (int i1, int i2, int i3, int i4, int amb)
MdcxFittedHel trial (int i1, int i2, int i3, int amb)
void KillList ()

Protected Attributes

HepAList< MdcxSegMdcxSeglist
int sl
MdcxFittedHel fithel
int nseg
const MdcDetectorgm
HepAList< MdcxHitdchitlist
int m_debug
MdcxSegPatterns m_segPat

Static Protected Attributes

static int wireGroups [11][288][16] = { { {0} } }


Detailed Description

Definition at line 34 of file MdcxFindSegs.h.


Constructor & Destructor Documentation

MdcxFindSegs::MdcxFindSegs ( MdcDetector g,
const HepAList< MdcxHit > &  l,
int  m_debug = 0 
)

Definition at line 18 of file MdcxFindSegs.cxx.

References dchitlist, gm, initWireGroups(), m_debug, and process().

00018                                                                                      {
00019   m_debug = debug;
00020   gm = g;
00021   dchitlist = hitlist;
00022   initWireGroups();
00023   process();
00024 }

MdcxFindSegs::MdcxFindSegs ( const HepAList< MdcxHit > &  l,
int  debug = 0 
)

Definition at line 26 of file MdcxFindSegs.cxx.

References dchitlist, gm, initWireGroups(), MdcDetector::instance(), m_debug, and process().

00026                                                                      {
00027   m_debug = debug;
00028   gm = MdcDetector::instance();
00029   dchitlist = hitlist;
00030   initWireGroups();
00031   process();
00032 }

MdcxFindSegs::~MdcxFindSegs (  )  [virtual]

Definition at line 34 of file MdcxFindSegs.cxx.

References KillList().

00034 { KillList(); }


Member Function Documentation

void MdcxFindSegs::appendseg ( MdcxFittedHel fithel,
int  pat,
int  amb 
)

Definition at line 318 of file MdcxFindSegs.cxx.

References fithel, and MdcxSeglist.

Referenced by process().

00318                                                                  {
00319   MdcxSeg *tempseg = new MdcxSeg(fithel, pat, amb);
00320   MdcxSeglist.append(tempseg);
00321 }

const HepAList<MdcxSeg>& MdcxFindSegs::GetMdcxSeglist (  )  [inline]

Definition at line 42 of file MdcxFindSegs.h.

References MdcxSeglist.

Referenced by MdcxTrackFinder::execute().

00042 {return MdcxSeglist;}

void MdcxFindSegs::initWireGroups ( void   ) 

Definition at line 36 of file MdcxFindSegs.cxx.

References gm, genRecEmupikp::i, ganga-rec::j, MdcSuperLayer::layer(), mdcWrapWire(), MdcSuperLayer::nLayers(), MdcDetector::nSuper(), MdcLayer::nWires(), BesAngle::rad(), sl, MdcSuperLayer::slayNum(), MdcDetector::SuperLayer(), w, and wireGroups.

Referenced by MdcxFindSegs().

00036                                       {
00037   //Assure initWireGroups run only once
00038   static bool alreadyInit = false;
00039   if (alreadyInit) return;
00040 
00041   //Make wire groups
00042   int lastsl= gm->nSuper();
00043   for (int sl = 0; sl < lastsl; sl++) { // loop over superLayers
00044     const MdcLayer *layArray[4];
00045     const MdcSuperLayer* slayer = gm->SuperLayer(sl);
00046     int nslay = slayer->nLayers();
00047     for (int i = 0; i < nslay; i++) layArray[i] = slayer->layer(i);
00048     int cellMax = layArray[1]->nWires();
00049     // loop over cells
00050     for (int cellIndex = 0; cellIndex < cellMax ; cellIndex++) {
00051       int wireIndex[4]; 
00052       if (slayer->slayNum() > 4) {
00053         wireIndex[0]= cellIndex;
00054         wireIndex[1]= cellIndex+1;
00055         wireIndex[2]= cellIndex;
00056         wireIndex[3]= cellIndex+1;
00057 
00058         wireIndex[1] = mdcWrapWire(wireIndex[1], layArray[1]->nWires());
00059         wireIndex[3] = mdcWrapWire(wireIndex[3], layArray[3]->nWires());
00060       } else {
00061         wireIndex[1]= cellIndex+1; 
00062         //take No.2 wire as referenc wire
00063         double phi = layArray[1]->getWire(wireIndex[1])->phiE();
00064         for(int i = 0; i < 4; i++ ) {
00065           if ( i == 1 ) continue;
00066           //change reference wire
00067           if ( i == 3 ) phi = layArray[2]->getWire(wireIndex[2])->phiE();
00068           BesAngle tmp(phi - layArray[i]->phiEPOffset());//yzhang temp
00069           if ( i==3 ) {
00070             wireIndex[i]=(tmp==0)?1:(int)ceil(layArray[i]->nWires()*tmp.rad()/twopi);
00071           }else{
00072             wireIndex[i]=(tmp==0)?-1:(int)floor(layArray[i]->nWires()*tmp.rad()/twopi);
00073           }
00074           wireIndex[i] = mdcWrapWire(wireIndex[i], layArray[i]->nWires());
00075         }
00076       }
00077       // set wireGroups
00078       int* w = wireGroups[sl][cellIndex];
00079       for (int i = 0; i < 4; i++) {
00080         for (int j = 0; j < 4; j++) {
00081           //wireGroups[sl][cellIndex][4*i+j] = wireIndex[i] + (j - 1);
00082           w[4*i+j] = mdcWrapWire((wireIndex[i]+j-1), layArray[i]->nWires());
00083         }
00084       }
00085     } //end loop cells
00086   } //end loop superLayers
00087 
00088   //Set alreadyInit flag
00089   alreadyInit = true;
00090   return;
00091 }

void MdcxFindSegs::KillList (  )  [inline, protected]

Definition at line 52 of file MdcxFindSegs.h.

References MdcxSeglist.

Referenced by ~MdcxFindSegs().

00052 {HepAListDeleteAll(MdcxSeglist);}

void MdcxFindSegs::print ( std::ostream o,
int  pmax = 10 
) const

void MdcxFindSegs::printseg ( MdcxFittedHel fithel,
int  pat,
int  amb,
int  subtry = 0 
)

Definition at line 323 of file MdcxFindSegs.cxx.

References MdcxFittedHel::Chisq(), MdcxFittedHel::Fail(), fithel, and sl.

Referenced by process().

00323                                                                               {
00324   cout << "Seg: pat " << pat << " amb " << amb << " subtry " << subtry 
00325     << " sl " << sl  << " fail "
00326     << fithel.Fail() << " chi2 " << fithel.Chisq() << endl;
00327 }

void MdcxFindSegs::process (  ) 

Definition at line 93 of file MdcxFindSegs.cxx.

References MdcxSegPatterns::ambigPatt3, MdcxSegPatterns::ambigPatt4, MdcxSegPatterns::ambPat3_size, MdcxSegPatterns::ambPat4_size, appendseg(), MdcxFittedHel::Chisq(), MdcxParameters::csmax3, MdcxParameters::csmax4, dchitlist, fithel, g_csmax3, g_csmax4, gm, genRecEmupikp::i, if(), MdcSuperLayer::index(), MdcSuperLayer::layer(), MdcDetector::Layer(), m_debug, m_segPat, MdcxSeglist, MdcDetector::nLayer(), MdcSuperLayer::nLayers(), MdcDetector::nSuper(), MdcLayer::nWires(), MdcxSegPatterns::patt3, MdcxSegPatterns::patt3_size, MdcxSegPatterns::patt4, MdcxSegPatterns::patt4_size, printseg(), sl, MdcDetector::SuperLayer(), subSeperate::temp, trial(), w, wireGroups, wireNo, MdcxSegPatterns::wirePat3, and MdcxSegPatterns::wirePat4.

Referenced by MdcxFindSegs().

00093                            {
00094   //if(3 == m_debug) cout <<" Event contains "<<dchitlist.length()<<" MdcxHit "<<endl;
00095   // for last super layer use 44
00096   int lflag[44][288] = { {0} };
00097   int pflag[44][288] = { {0} };
00098   int ix,iy,iyp,iyn,cellMax;
00099 
00100   //yzhang 2009-10-20 do not use poison
00101   int ipoison=0;
00102   //number of last layer
00103   int lastlay= gm->nLayer();
00104 
00105   // tag hit's lfalg
00106   int k=0; 
00107   while(dchitlist[k]){
00108     MdcxHit* temp = dchitlist[k]; 
00109     k++; 
00110     lflag[temp->Layer()][temp->WireNo()]=k;
00111   }
00112 
00113   // try poisoning
00114   if (ipoison){
00115     for (ix=0; ix<lastlay; ix++){
00116       cellMax = gm->Layer(ix)->nWires();
00117       // if have hits in left and right , poison this cell
00118       for (iy=0; iy<cellMax; iy++){
00119         iyp=iy+1; if (iyp == cellMax)iyp=0; 
00120         iyn=iy-1; if (iyn == -1)iyn=cellMax-1;
00121         if ((lflag[ix][iyp] != 0) && (lflag[ix][iyn] != 0)) {
00122           pflag[ix][iy] = 1;
00123           lflag[ix][iy] = 0;
00124           //g_poison->fill(ix,iy);
00125         }
00126       }
00127       //for (iy=0; iy<cellMax; iy++) {if (pflag[ix][iy] != 0) lflag[ix][iy] = 0;}
00128     }
00129   }  //FIXME (optimize ???)
00130   
00131   float csmax_4 = MdcxParameters::csmax4;
00132   float csmax_3 = MdcxParameters::csmax3;
00133   int lastsl= gm->nSuper();//lastSLayNum;
00134 
00135   // loop superlayer
00136   for (sl = 0; sl < lastsl; sl++) {
00137     int fsl=4*sl;
00138     int l0=fsl, l1=fsl+1, l2=fsl+2, l3=fsl+3; 
00139     int iprt = 0; 
00140     //initialize superlayer pointer in layArray[]
00141     const MdcLayer *layArray[4];
00142     const MdcSuperLayer* slayer = gm->SuperLayer(sl);
00143     int nslay = slayer->nLayers();
00144     for (int i = 0; i < nslay; i++) layArray[i] = slayer->layer(i);
00145     if(3 == m_debug){
00146       cout<<"slayer No.  "<<slayer->index()<<endl;//yzhang debug
00147     }
00148     //reference point (2,1)
00149     cellMax = layArray[1]->nWires();
00150 
00151     // loop over cells
00152     for (int cellIndex=0; cellIndex<cellMax ; cellIndex++) {
00153       int* w = wireGroups[sl][cellIndex];
00154       unsigned int sig_mark = 0;
00155       for (int ilayer = l0; ilayer <= l3; ilayer++) {
00156         for (int iwire = 3; iwire >= 0; iwire--) {
00157           if (lflag[ilayer][w[4*(ilayer-l0)+iwire]]) {
00158             sig_mark |= 0x1;
00159           }
00160           sig_mark <<= 1;
00161         }
00162       }
00163       sig_mark >>= 1;
00164 
00165       int goodSegNo = 0;
00166       int nPat = m_segPat.patt4_size;
00167       int iPat = (sig_mark & 0x0200) ? 0 : 11;
00168       for ( ; iPat < nPat; iPat++) {
00169         int pat = m_segPat.patt4[iPat];
00170         if ((pat & sig_mark) == pat) {
00171           if(3 == m_debug) {
00172             cout<< "pat " << std::hex << pat << std::dec << "  with wire";
00173             for (int tmpi = 0; tmpi < 4; tmpi++) {
00174               cout<<"("<<l0+tmpi<<","<<w[4*tmpi+m_segPat.wirePat4[iPat][tmpi]-1]<<")";
00175             }
00176             cout << endl;
00177           }
00178           int w0 = lflag[l0][w[0 +m_segPat.wirePat4[iPat][0]-1]] - 1;
00179           int w1 = lflag[l1][w[4 +m_segPat.wirePat4[iPat][1]-1]] - 1;
00180           int w2 = lflag[l2][w[8 +m_segPat.wirePat4[iPat][2]-1]] - 1;
00181           int w3 = lflag[l3][w[12+m_segPat.wirePat4[iPat][3]-1]] - 1;
00182           int tw[4] = {w0, w1, w2, w3};
00183 
00184           int namb = m_segPat.ambPat4_size[iPat];
00185           for (int iamb = 0; iamb < namb; iamb++) {
00186             int amb = m_segPat.ambigPatt4[iPat][iamb];
00187             fithel = trial(w0, w1, w2, w3, amb);
00188             if(3 == m_debug){
00189               cout<<"chisq "<<fithel.Chisq()
00190                 <<" <? csmax4 "<<csmax_4<<  endl;
00191               if (fithel.Chisq() < csmax_4) {
00192                 cout<<"Accept this seg"<<endl;
00193               }else{
00194                 cout<<"DROP this seg"<<endl;
00195               }
00196             }
00197             if(g_csmax4) g_csmax4->fill(fithel.Chisq());
00198             if (fithel.Chisq() < csmax_4) {
00199               if (iprt) printseg(fithel, pat,amb);
00200               appendseg(fithel, pat, amb);
00201               goodSegNo++;
00202             }
00203           }
00204         }
00205       }
00206       if (goodSegNo != 0) continue;
00207       nPat = m_segPat.patt3_size;
00208       iPat = (sig_mark & 0x0200) ? 0 : 14;
00209       for ( ; iPat < nPat; iPat++) {
00210         if (iPat > nPat-3) {
00211           if ((iPat == nPat-2) && (sig_mark&0x2121 == 0x2121)) continue;
00212           if ((iPat == nPat-1) && (sig_mark&0x2122 == 0x2122)) continue;
00213         }
00214         int pat = m_segPat.patt3[iPat];
00215         if ((pat & sig_mark) == pat) {
00216           if(3 == m_debug) {
00217             cout<<"MdcxFindSegs: in pat "<<std::hex<<pat<<std::dec<<" with wire";
00218             for (int tmpi = 0; tmpi < 4; tmpi++) {
00219               if (m_segPat.wirePat3[iPat][tmpi] == 0) continue;
00220               cout<< " (" << l0+tmpi << "," << w[4*tmpi+m_segPat.wirePat3[iPat][tmpi]-1] << ")";
00221             }
00222             cout<< endl;
00223           }
00224           int wn[3];
00225           for (int iw = 0, iwp = 0; iwp < 4; iwp++) {
00226             int wireNo = m_segPat.wirePat3[iPat][iwp];
00227             if( wireNo == 0 ) continue;
00228             wn[iw++] = lflag[l0+iwp][w[4*iwp+wireNo-1]] - 1;
00229           }
00230 
00231           int namb = m_segPat.ambPat3_size[iPat];
00232           for (int iamb = 0; iamb < namb; iamb++) {
00233             int amb = m_segPat.ambigPatt3[iPat][iamb];
00234             fithel = trial(wn[0], wn[1], wn[2], amb);//FIXME
00235             if(3 == m_debug){
00236               cout<<"chisq "<<fithel.Chisq()
00237                 <<" <? csmax3 "<<csmax_3<<  endl;
00238               if (fithel.Chisq() < csmax_3) {
00239                 cout<<"Accept this seg"<<endl;
00240               }else{
00241                 cout<<"DROP this seg"<<endl;
00242               }
00243             }
00244             if(g_csmax3) g_csmax3->fill(fithel.Chisq());
00245             if (fithel.Chisq() < csmax_3) {
00246               if (iprt) printseg(fithel, pat, amb);
00247               appendseg(fithel, pat ,amb);
00248             }
00249           }
00250         }
00251       }//end of nPat3
00252     }
00253   }
00254 
00255   if(3 == m_debug){
00256     cout << "MdcxFindSegs found " << MdcxSeglist.length() << " segs" << endl;
00257   }
00258   return;
00259 }

void MdcxFindSegs::setDebug ( bool  debug = 0  )  [inline]

Definition at line 46 of file MdcxFindSegs.h.

References m_debug.

00046 {m_debug = debug;}

MdcxFittedHel MdcxFindSegs::trial ( int  i1,
int  i2,
int  i3,
int  amb 
) [protected]

Definition at line 293 of file MdcxFindSegs.cxx.

References MdcxHit::d(), dchitlist, m_debug, phi0, MdcxHel::SetTurnFlag(), subSeperate::temp, MdcxHit::x(), MdcxHit::xneg(), MdcxHit::xpos(), MdcxHit::y(), MdcxHit::yneg(), and MdcxHit::ypos().

00293                                                                  {
00294   HepAList<MdcxHit> seg;
00295   MdcxHit* t1 = dchitlist[i1];
00296   MdcxHit* t2 = dchitlist[i2];
00297   MdcxHit* t3 = dchitlist[i3];
00298   seg.append(t1); seg.append(t2); seg.append(t3);
00299   double dx,dy,d0; 
00300   if (amb==0){dx=t3->xneg()-t1->xneg(); dy=t3->yneg()-t1->yneg(); d0=-t1->d();}
00301   if (amb==1){dx=t3->xneg()-t1->xpos(); dy=t3->yneg()-t1->ypos(); d0= t1->d();}
00302   if (amb==2){dx=t3->xpos()-t1->xneg(); dy=t3->ypos()-t1->yneg(); d0=-t1->d();}
00303   if (amb==3){dx=t3->xpos()-t1->xpos(); dy=t3->ypos()-t1->ypos(); d0= t1->d();}
00304 
00305   double phi0 = atan2(dy,dx); dx=t1->x(); dy=t1->y(); 
00306   MdcxHel hel(d0,phi0,0.0,0.0,0.0,0.0,111,0,dx,dy);
00307   hel.SetTurnFlag(1);
00308   MdcxFittedHel temp(seg,hel,1.0);
00309 
00310   if (3 == m_debug) {
00311     cout<<"trial3 amb "<<amb
00312       << ": phi0 " << phi0 << " d0 " << d0 
00313       << " dx " << dx << " dy " << dy << endl;
00314   }
00315   return temp;
00316 }

MdcxFittedHel MdcxFindSegs::trial ( int  i1,
int  i2,
int  i3,
int  i4,
int  amb 
) [protected]

Definition at line 270 of file MdcxFindSegs.cxx.

References MdcxHit::d(), dchitlist, m_debug, phi0, MdcxHel::SetTurnFlag(), subSeperate::temp, MdcxHit::x(), MdcxHit::xneg(), MdcxHit::xpos(), MdcxHit::y(), MdcxHit::yneg(), and MdcxHit::ypos().

Referenced by process().

00270                                                                          {
00271   HepAList<MdcxHit> seg;
00272   MdcxHit* t1 = dchitlist[i1]; MdcxHit* t2 = dchitlist[i2];  
00273   MdcxHit* t3 = dchitlist[i3]; MdcxHit* t4 = dchitlist[i4];  
00274   seg.append(t1); seg.append(t2); seg.append(t3); seg.append(t4); 
00275   double dx, dy, d0; 
00276   if (amb==0){dx=t4->xneg()-t1->xneg(); dy=t4->yneg()-t1->yneg(); d0=-t1->d();}
00277   if (amb==1){dx=t4->xneg()-t1->xpos(); dy=t4->yneg()-t1->ypos(); d0= t1->d();}
00278   if (amb==2){dx=t4->xpos()-t1->xneg(); dy=t4->ypos()-t1->yneg(); d0=-t1->d();}
00279   if (amb==3){dx=t4->xpos()-t1->xpos(); dy=t4->ypos()-t1->ypos(); d0= t1->d();}
00280   double phi0 = atan2(dy,dx); dx=t1->x(); dy=t1->y(); 
00281   MdcxHel hel(d0,phi0,0.0,0.0,0.0,0.0,111,0,dx,dy);
00282   hel.SetTurnFlag(1);
00283   MdcxFittedHel temp(seg, hel, 1.0);
00284   if (3 == m_debug) {
00285     cout<<"trial4 amb "<<amb
00286       << ": phi0 " << phi0 << " d0 " << d0 
00287       << " dx " << dx << " dy " << dy << endl;
00288     //temp.FitPrint();
00289   }
00290   return temp;
00291 }


Member Data Documentation

HepAList<MdcxHit> MdcxFindSegs::dchitlist [protected]

Definition at line 59 of file MdcxFindSegs.h.

Referenced by MdcxFindSegs(), process(), and trial().

MdcxFittedHel MdcxFindSegs::fithel [protected]

Definition at line 55 of file MdcxFindSegs.h.

Referenced by appendseg(), printseg(), and process().

const MdcDetector* MdcxFindSegs::gm [protected]

Definition at line 58 of file MdcxFindSegs.h.

Referenced by initWireGroups(), MdcxFindSegs(), and process().

int MdcxFindSegs::m_debug [protected]

Definition at line 60 of file MdcxFindSegs.h.

Referenced by MdcxFindSegs(), process(), setDebug(), and trial().

MdcxSegPatterns MdcxFindSegs::m_segPat [protected]

Definition at line 61 of file MdcxFindSegs.h.

Referenced by process().

HepAList<MdcxSeg> MdcxFindSegs::MdcxSeglist [protected]

Definition at line 48 of file MdcxFindSegs.h.

Referenced by appendseg(), GetMdcxSeglist(), KillList(), and process().

int MdcxFindSegs::nseg [protected]

Definition at line 56 of file MdcxFindSegs.h.

int MdcxFindSegs::sl [protected]

Definition at line 53 of file MdcxFindSegs.h.

Referenced by initWireGroups(), printseg(), and process().

int MdcxFindSegs::wireGroups = { { {0} } } [static, protected]

Definition at line 63 of file MdcxFindSegs.h.

Referenced by initWireGroups(), and process().


Generated on Tue Nov 29 23:20:20 2016 for BOSS_7.0.2 by  doxygen 1.4.7