/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Calibration/CalibData/CalibData-00-01-18/src/Muc/MucIdTransform.cxx

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------|
00002 //      [File  ]:                       MucIdTransform.cxx                      |
00003 //      [Brief ]:       Source file of MucIdTransform 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<cmath>
00011 
00012 using namespace std;
00013 
00014 #include "CalibData/Muc/MucIdTransform.h"
00015 #include "CalibData/Muc/MucCalibConst.h"
00016 namespace CalibData {
00017 
00018 // Constructor
00019 MucIdTransform::MucIdTransform()
00020 {
00021         m_Id      = 0;
00022         m_Part    = 0;
00023         m_Segment = 0;
00024         m_Layer   = 0;
00025         m_Strip   = 0;
00026 }
00027 
00028 // Destructor
00029 MucIdTransform::~MucIdTransform() { ; }
00030 
00031 // Get properties 
00032 int MucIdTransform::GetId()      { return m_Id;      }
00033 int MucIdTransform::GetPart()    { return m_Part;    }
00034 int MucIdTransform::GetSegment() { return m_Segment; }
00035 int MucIdTransform::GetLayer()   { return m_Layer;   }
00036 int MucIdTransform::GetStrip()   { return m_Strip;   }
00037 
00038 // Return the maximum strip in a box
00039 int MucIdTransform::GetStripMax( int part, int segment, int layer )
00040 {
00041         int max = 0;
00042 
00043         if( part != BRID )              max = E_STR_NUM;
00044         else if( (layer+1)%2 == 1 )     max = B_ZSTR_NUM;
00045         else if( segment == B_TOP )     max = B_TOPSTR_NUM;
00046         else                            max = B_PHISTR_NUM;
00047 
00048         return max;
00049 }
00050 
00051 // Return the id of a box according its position
00052 int MucIdTransform::GetBoxId( int part, int segment, int layer )
00053 {
00054         int boxId = 0;
00055         for(int i=0; i<part; i++) {
00056                 boxId += BOX_PER_PART[i];
00057         }
00058 
00059         if( segment == 0 )
00060                 boxId += layer;
00061         else
00062                 boxId += ( segment * BOX_PER_SEG[part] + layer );
00063 
00064         return boxId;
00065 }
00066 
00067 // Return the id of a strip according its position
00068 int MucIdTransform::GetStripId( int part, int segment, int layer, int strSubId )
00069 {
00070         int strId = 0;
00071         int boxId = 0;
00072 
00073         boxId = GetBoxId( part, segment, layer );
00074 
00075         if( part == EEID )
00076         {
00077                 strId = boxId*E_STR_NUM + strSubId;
00078         }
00079         else if( part == BRID )
00080         {
00081                 strId = STR_PER_PART[0];
00082 
00083                 if( segment > B_TOP )
00084                         strId += segment * B_STR_PER_SEG[0] + E_STR_NUM;
00085                 else
00086                         strId += segment * B_STR_PER_SEG[0];
00087 
00088                 strId += ((1+layer)/2) * B_ZSTR_NUM;
00089                 strId += (layer/2) * ( (segment == B_TOP)?B_TOPSTR_NUM:B_PHISTR_NUM );
00090 
00091                 strId += strSubId;
00092         }
00093         else
00094         {
00095                 strId = STR_PER_PART[0] + STR_PER_PART[1];
00096                 strId += (boxId - BOX_SUM[1])*E_STR_NUM + strSubId;
00097         }
00098 
00099         return strId;
00100 }
00101 
00102 // Get the box posistion according to histogram pointer id of the box
00103 bool MucIdTransform::SetBoxPos( int boxId, int* part, int* segment, int* layer )
00104 {
00105 
00106         if( (boxId < 0) || (boxId > BOX_MAX-1) )
00107         {
00108                 *part    = 0;
00109                 *segment = 0;
00110                 *layer   = 0;
00111                 cout << "box id out range:\t" << boxId << "!" << endl;
00112                 return false;
00113         }
00114 
00115         // get part
00116         if( boxId < BOX_SUM[0] )         { *part = 0;                       }
00117         else if( boxId < BOX_SUM[1] )    { *part = 1; boxId -= BOX_SUM[0];  }
00118         else                             { *part = 2; boxId -= BOX_SUM[1];  }
00119 
00120         // get segment and layer
00121         if( *part == BRID )
00122         {
00123                 *segment = boxId / B_LAY_NUM;
00124                 *layer = boxId % B_LAY_NUM;
00125         }
00126         else
00127         {
00128                 *segment = boxId / E_LAY_NUM;
00129                 *layer = boxId % E_LAY_NUM;
00130         }
00131 
00132         return true;
00133 }       
00134 
00135 // Get the strip posistion according to histogram pointer id of the strip
00136 bool MucIdTransform::SetStripPos( int stripId, int *part, int *segment, int *layer, int *strSubId )
00137 {
00138         if( (stripId < 0) || (stripId > STRIP_MAX-1) )
00139         {
00140                 *part       = 0;
00141                 *segment    = 0;
00142                 *layer      = 0;
00143                 *strSubId   = 0;
00144                 cout << "strip id out range:\t" << stripId << "!" << endl;
00145                 return false;
00146         }
00147 
00148         // get part
00149         if( stripId < STR_SUM[0] )       { *part = 0;                        }
00150         else if ( stripId < STR_SUM[1] ) { *part = 1; stripId -= STR_SUM[0]; }
00151         else                             { *part = 2; stripId -= STR_SUM[1]; }
00152 
00153         // get segment and layer
00154         if( *part == BRID )
00155         {
00156                 int temp = 0;
00157                 if ( stripId >= 2*B_STR_PER_SEG[0] && stripId < 2*B_STR_PER_SEG[0] + B_STR_PER_SEG[1] )
00158                 {
00159                         // get segment
00160                         *segment = B_TOP;
00161 
00162                         stripId -= 2*B_STR_PER_SEG[0];
00163                         temp = stripId % ( B_ZSTR_NUM + B_TOPSTR_NUM );
00164 
00165                         // get layer
00166                         if( temp < B_ZSTR_NUM ) *layer = 2*( stripId / ( B_ZSTR_NUM + B_TOPSTR_NUM ) );
00167                         else                    *layer = 2*( stripId / ( B_ZSTR_NUM + B_TOPSTR_NUM ) ) + 1;
00168 
00169                         // get strip
00170                         if( temp < B_ZSTR_NUM ) *strSubId = temp;
00171                         else                    *strSubId = temp - B_ZSTR_NUM;
00172 
00173                 } // top segment
00174                 else
00175                 {
00176                         if (stripId >= 2*B_STR_PER_SEG[0] + B_STR_PER_SEG[1] ) stripId -= E_STR_NUM;
00177 
00178                         // get segment
00179                         *segment = stripId / B_STR_PER_SEG[0];
00180 
00181                         stripId %= B_STR_PER_SEG[0];
00182                         temp = stripId % ( B_ZSTR_NUM + B_PHISTR_NUM );
00183 
00184                         // get layer
00185                         if( temp < B_ZSTR_NUM ) *layer = 2*( stripId / ( B_ZSTR_NUM + B_PHISTR_NUM ) );
00186                         else                    *layer = 2*( stripId / ( B_ZSTR_NUM + B_PHISTR_NUM ) ) + 1;
00187 
00188                         // get strip
00189                         if( temp < B_ZSTR_NUM ) *strSubId = temp;
00190                         else                    *strSubId = temp - B_ZSTR_NUM;
00191                 }
00192         } // barrel
00193         else
00194         {
00195                 *strSubId   = stripId % E_STR_NUM;
00196                 *layer      = ( stripId / E_STR_NUM ) % E_LAY_NUM ;
00197                 *segment    = ( stripId / E_STR_NUM ) / E_LAY_NUM ;
00198         }
00199         
00200         return true;
00201 }
00202    
00203 // Show transform results
00204 void MucIdTransform::Print( int mode )  
00205 {
00206         if( mode == 0 ) // position to id
00207         {
00208                 cout << "prt: "   << m_Part
00209                      << "\tseg: " << m_Segment
00210                      << "\tlay: " << m_Layer
00211                      << "\tstr: " << m_Strip 
00212                      << "\tid: "  << m_Id << endl;              
00213         }
00214         else            // id to position
00215         {
00216                 cout << "id: "    << m_Id                       
00217                      << "\tprt: " << m_Part
00218                      << "\tseg: " << m_Segment
00219                      << "\tlay: " << m_Layer
00220                      << "\tstr: " << m_Strip << endl;
00221         }
00222 }
00223 }
00224 //END
00225 

Generated on Tue Nov 29 22:57:48 2016 for BOSS_7.0.2 by  doxygen 1.4.7