/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Muc/MucCalibAlg/MucCalibAlg-00-02-16/src/MucMark.cxx

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------|
00002 //      [File  ]:                       MucMark.cxx                             |
00003 //      [Brief ]:       Source file of MucMark class for encapsulation          |
00004 //      [Author]:       Xie Yuguang, <ygxie@mail.ihep.ac.cn>                    |
00005 //      [Date  ]:       Oct 19, 2006                                            |
00006 //------------------------------------------------------------------------------|
00007 
00008 
00009 #include<iostream>
00010 #include<vector>
00011 #include<cmath>
00012 
00013 #include "MucCalibAlg/MucStructConst.h"
00014 #include "MucCalibAlg/MucMark.h"
00015 
00016 using namespace std;
00017 
00018 // Constructor
00019 MucMark::MucMark( int part, int segment, int layer, int strip )
00020 {
00021   m_Part    = part;
00022   m_Segment = segment;
00023   m_Layer   = layer;
00024   m_Strip   = strip;
00025 }
00026 
00027 // Destructor
00028 MucMark::~MucMark() { ; }
00029 
00030 // Operator ==
00031 bool MucMark::operator ==( MucMark &other )
00032 {
00033   if( this == &other ) return true;
00034   
00035   if( (*this).Part()    == other.Part()    &&
00036       (*this).Segment() == other.Segment() &&
00037       (*this).Layer()   == other.Layer()   &&
00038       (*this).Strip()   == other.Strip()       )
00039     return true;
00040   else
00041     return false;
00042 }
00043 
00044 // Set properties
00045 bool MucMark::SetPart( int part ) 
00046 {
00047   if( part > PART_MAX || part < 0 ) {
00048     cout << "part overflow:\t" << part << endl;
00049     return false;
00050   }
00051   else {
00052     m_Part = part;
00053     return true;
00054   }
00055 } 
00056 
00057 bool MucMark::SetSegment( int segment )
00058 {
00059   if( segment > ((m_Part == BRID)?B_SEG_NUM:E_SEG_NUM) || segment < 0 ) {  
00060     cout << "segment overflow:\t" << segment << endl;
00061     return false;
00062   }
00063   else {
00064     m_Segment = segment;
00065     return true;
00066   }
00067 }
00068 
00069 bool MucMark::SetLayer( int layer )
00070 {
00071   if( layer > ((m_Part == BRID)?B_LAY_NUM:E_LAY_NUM) || layer < 0 ) {  
00072     cout << "layer overflow:\t" << layer << endl;
00073     return false;
00074   }
00075   else {
00076     m_Layer = layer;
00077     return true;
00078   }
00079 }
00080 
00081 bool MucMark::SetStrip( int strip )
00082 {
00083   if( strip > STRIP_INBOX_MAX || strip < 0 ) {  
00084     cout << "strip overflow:\t" << strip << endl;
00085     return false;
00086   }
00087   else {
00088     m_Strip = strip;
00089     return true;
00090   }
00091 }
00092 
00093 // Get properties 
00094 int MucMark::Part()    { return m_Part;    }
00095 int MucMark::Segment() { return m_Segment; }
00096 int MucMark::Layer()   { return m_Layer;   }
00097 int MucMark::Strip()   { return m_Strip;   }
00098 
00099 // Judge whether mark itself is in a Col or not
00100 int MucMark::IsInCol( int part, int segment, int layer, int strip, mark_col &aCol )
00101 {
00102   for( unsigned int i=0; i<aCol.size(); i++ ) {
00103     if( part    == aCol[i]->Part()    &&
00104         segment == aCol[i]->Segment() &&
00105         layer   == aCol[i]->Layer()   &&
00106         strip   == aCol[i]->Strip()     )
00107     return i;
00108   }
00109   
00110   return -1;
00111 }
00112 
00113 int MucMark::IsInCol( mark_col &aCol )
00114 {
00115   for( unsigned int i=0; i<aCol.size(); i++ ) {
00116     if( (*this) == (*aCol[i]) ) return i;
00117   }
00118   
00119   return -1;
00120 }
00121 
00122 int MucMark::IsInCol( vector< mark_col >  &aClusterCol )
00123 { 
00124   for( unsigned int i=0; i<aClusterCol.size(); i++ ) {
00125     if( (*this).IsInCol ( aClusterCol[i] ) ) return i;
00126   }
00127   
00128   return -1;
00129 }
00130 
00131 // Return the number of mark itself in a Col
00132 int MucMark::NumInCol( mark_col &aCol )
00133 {
00134   int num = 0;
00135   
00136   for( unsigned int i=0; i<aCol.size(); i++ ) {
00137     if( (*this) == (*aCol[i]) ) num ++;
00138   }
00139   
00140   return num;
00141 }
00142 
00143 // Judge whether mark itself is in the same segment with the other
00144 bool MucMark::IsInSegWith( MucMark &other )
00145 {
00146   if( (*this).Part() == other.Part() &&
00147       (*this).Segment() == other.Segment()  )
00148     return true;
00149   else
00150     return false;
00151 }
00152 
00153 // Judge whether mark itself is in the same box with the other
00154 bool MucMark::IsInBoxWith( MucMark &other )
00155 {
00156   if( (*this).Part() == other.Part()       &&
00157       (*this).Segment() == other.Segment() &&
00158       (*this).Layer() == other.Layer()        )
00159     return true;
00160   else
00161     return false;
00162 }
00163 
00164 // Judge whether mark itself is a neighbor with the other
00165 bool MucMark::IsNeighborWith( MucMark &other )
00166 {
00167   if( (*this).Part()    == other.Part()    &&
00168       (*this).Segment() == other.Segment() &&
00169       (*this).Layer()   == other.Layer()   &&
00170       fabs( (*this).Strip() - other.Strip() ) == 1 )
00171     return true;
00172   else 
00173     return false;
00174 }
00175 
00176 // Judge whether mark itself is a neighbor with a multi hit
00177 bool MucMark::IsNeighborWith( mark_col &aCluster )
00178 {
00179   for( unsigned int i=0; i<aCluster.size(); i++ ) {
00180     if( (*this).IsNeighborWith((*aCluster[i])) )
00181       return true;
00182   }
00183   
00184   return false;
00185 }
00186 
00187 // Return a cluster Col from a given mark Col
00188 vector< mark_col > MucMark::CreateClusterCol_A( mark_col &aMarkCol )
00189 {
00190   vector< mark_col > aClusterCol;
00191   mark_col      checkedMarkCol;
00192   
00193   int recordFlag      = 0;
00194   unsigned int circle = 0;
00195   
00196   for( unsigned int i=0; i<aMarkCol.size(); i++ )
00197   {
00198     recordFlag = 0;
00199     for( unsigned int j=0; j< aClusterCol.size(); j++ )
00200     {
00201       if( (*aMarkCol[i]).IsInCol(aClusterCol[j]) !=-1 ) {
00202         recordFlag = 1;
00203         break;
00204       }
00205       else if( (*aMarkCol[i]).IsNeighborWith(aClusterCol[j]) )
00206       {
00207         aClusterCol[j].push_back( aMarkCol[i] );
00208         recordFlag = 1;
00209         break;
00210       }
00211     }
00212     
00213     if( recordFlag == 0 )
00214     {
00215       mark_col aCluster;
00216       aCluster.push_back( aMarkCol[i] );
00217       aClusterCol.push_back( aCluster );
00218       
00219       circle =0;
00220       do {
00221         circle ++;
00222         for( unsigned int j = i+1; j<aMarkCol.size(); j++ )
00223         {
00224           if( (*aMarkCol[j]).IsInCol(aClusterCol.back()) !=-1 ) continue;
00225           else if( (*aMarkCol[j]).IsNeighborWith( aClusterCol.back()) )
00226           aClusterCol.back().push_back( aMarkCol[j] );
00227         }
00228       } while( circle < aMarkCol.size()-i-1);
00229     }
00230   }
00231   
00232   return aClusterCol;
00233 }
00234 
00235 vector< mark_col > MucMark::CreateClusterCol_B( mark_col &aMarkCol)
00236 {
00237   vector< mark_col > aClusterCol;
00238   mark_col  checkedMarkCol;
00239   
00240   unsigned int circle = 0;
00241   for( unsigned int i=0; i<aMarkCol.size(); i++ )
00242   {
00243     if( (*aMarkCol[i]).IsInCol(checkedMarkCol) !=-1 ) continue;
00244     
00245     mark_col aCluster;
00246     aCluster.push_back( aMarkCol[i] );
00247     aClusterCol.push_back( aCluster );
00248     checkedMarkCol.push_back( aMarkCol[i] );
00249     
00250     circle = 0;
00251     do {
00252       for( unsigned int j = i+1; j<aMarkCol.size(); j++ )
00253       {
00254         if( (*aMarkCol[j]).IsInCol(checkedMarkCol) != -1) continue;
00255         else if( (*aMarkCol[j]).IsNeighborWith( aClusterCol.back() ) ) {
00256           aClusterCol.back().push_back( aMarkCol[j] );
00257           checkedMarkCol.push_back( aMarkCol[j] );
00258         }
00259       }
00260       circle ++;
00261     } while(circle < aMarkCol.size()-i-1);
00262   }
00263   
00264   return aClusterCol;
00265 }
00266 
00267 vector< mark_col > MucMark::CreateClusterCol_C( mark_col &aMarkCol)
00268 {
00269   MucMark tmpMark;
00270   vector< mark_col > aClusterCol;
00271   mark_col  copyMarkCol;
00272   copyMarkCol = aMarkCol;
00273   
00274   mark_col::iterator it1;
00275   while( copyMarkCol.size() !=0 ) // while 1
00276   {
00277     it1 = copyMarkCol.begin();
00278     mark_col aCluster;
00279     aCluster.push_back( copyMarkCol[0] );
00280     aClusterCol.push_back( aCluster );
00281   
00282     copyMarkCol.erase( it1 );
00283     unsigned int circle = 0;
00284     unsigned int size   = 0;
00285     unsigned int beginsize = copyMarkCol.size();
00286     while( circle < beginsize ) // while 2
00287     {
00288       mark_col::iterator it2;
00289       size = copyMarkCol.size();
00290       for( unsigned int j=0, headNum=0; j < size; j++ )
00291       {
00292         it2 = copyMarkCol.begin() + headNum;
00293         if( (copyMarkCol[headNum])->IsNeighborWith( aClusterCol.back() ) ) {
00294           aClusterCol.back().push_back( (copyMarkCol[headNum]) );
00295           copyMarkCol.erase(it2);
00296         }
00297         else headNum ++;
00298       } // end for
00299   
00300       circle ++;
00301     }; // End while 2
00302   
00303   }; // End while 1
00304   
00305   return aClusterCol;
00306 }
00307 
00308 vector< mark_col > MucMark::CreateClusterCol_D( mark_col &aMarkCol )
00309 {
00310   vector< mark_col > aClusterCol;
00311 
00312   bool recordFlag     = false;
00313   unsigned int circle = 0;
00314 
00315   for( unsigned int i=0; i<aMarkCol.size(); i++ )
00316   {
00317     recordFlag = false;
00318     for( int j= aClusterCol.size()-1; j>-1; j-- )
00319     {
00320       if( (*aMarkCol[i]).IsInCol(aClusterCol[j]) !=-1 ) {
00321         recordFlag = true;
00322         break;
00323       }
00324       else if( (*aMarkCol[i]).IsNeighborWith(aClusterCol[j]) )
00325       {
00326         aClusterCol[j].push_back( aMarkCol[i] );
00327         recordFlag = true;
00328         break;
00329       }
00330     }
00331 
00332     if( recordFlag == false )
00333     {
00334       mark_col aCluster;
00335       aCluster.push_back( aMarkCol[i] );
00336       aClusterCol.push_back( aCluster );
00337 
00338       circle =0;
00339       do {
00340         circle ++;
00341         for( unsigned int j = i+1; j<aMarkCol.size(); j++ )
00342         {
00343           if( (*aMarkCol[j]).IsInCol(aClusterCol.back()) !=-1 ) continue;
00344           else if( (*aMarkCol[j]).IsNeighborWith( aClusterCol.back()) )
00345             aClusterCol.back().push_back( aMarkCol[j] );
00346         }
00347       } while( circle < aMarkCol.size()-i-1);
00348     } // End if recordflag
00349   } // End fist for
00350 
00351   return aClusterCol;
00352 }
00353 
00354 
00355 vector< mark_col > MucMark::CreateClusterCol( int buildMode, mark_col &aMarkCol )
00356 {
00357   vector< mark_col > aClusterCol;
00358   switch( buildMode ) 
00359   {
00360     case 1: return CreateClusterCol_A( aMarkCol );
00361             break;
00362     case 2: return CreateClusterCol_B( aMarkCol );
00363             break;
00364     case 3: return CreateClusterCol_C( aMarkCol );
00365             break;
00366     case 4: return CreateClusterCol_D( aMarkCol );
00367             break;
00368     default: return (aClusterCol);
00369   }
00370 }
00371 
00372 // Show mark itself
00373 void MucMark::Print()
00374 {
00375   cout << "prt: "   << m_Part
00376        << "\tseg: " << m_Segment
00377        << "\tlay: " << m_Layer
00378        << "\tstr: " << m_Strip << endl;
00379 }
00380 
00381 void MucMark::Print( mark_col &aMarkCol )
00382 {
00383   for( unsigned int i=0; i< aMarkCol.size(); i++ ) aMarkCol[i]->Print();
00384 }
00385 
00386 void MucMark::Print( vector< mark_col > &aClusterCol )
00387 {
00388   for( unsigned int i=0; i< aClusterCol.size(); i++ )
00389     for( unsigned int j=0; j< aClusterCol[i].size(); j++ ) {
00390       aClusterCol[i][j]->Print();
00391     }
00392 }
00393 
00394 // END
00395 

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