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