00001
00002
00003
00004
00005
00006
00007
00008
00009 #include<iostream>
00010 #include<cmath>
00011
00012 using namespace std;
00013
00014 #include "MucCalibAlg/MucIdTransform.h"
00015 #include "MucCalibAlg/MucStructConst.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 strId = boxId*E_STR_NUM + strSubId;
00076 }
00077 else if( part == BRID )
00078 {
00079 strId = STR_PER_PART[0];
00080
00081 if( segment > B_TOP )
00082 strId += segment * B_STR_PER_SEG[0] + E_STR_NUM;
00083 else
00084 strId += segment * B_STR_PER_SEG[0];
00085
00086 strId += ((1+layer)/2) * B_ZSTR_NUM;
00087 strId += (layer/2) * ( (segment == B_TOP)?B_TOPSTR_NUM:B_PHISTR_NUM );
00088
00089 strId += strSubId;
00090 }
00091 else {
00092 strId = STR_PER_PART[0] + STR_PER_PART[1];
00093 strId += (boxId - BOX_SUM[1])*E_STR_NUM + strSubId;
00094 }
00095
00096 return strId;
00097 }
00098
00099
00100 bool MucIdTransform::SetBoxPos( int boxId, int* part, int* segment, int* layer )
00101 {
00102 if( (boxId < 0) || (boxId > BOX_MAX-1) )
00103 {
00104 *part = 0;
00105 *segment = 0;
00106 *layer = 0;
00107 cout << "box id out range:\t" << boxId << "!" << endl;
00108 return false;
00109 }
00110
00111
00112 if( boxId < BOX_SUM[0] ) { *part = 0; }
00113 else if( boxId < BOX_SUM[1] ) { *part = 1; boxId -= BOX_SUM[0]; }
00114 else { *part = 2; boxId -= BOX_SUM[1]; }
00115
00116
00117 if( *part == BRID ) {
00118 *segment = boxId / B_LAY_NUM;
00119 *layer = boxId % B_LAY_NUM;
00120 }
00121 else {
00122 *segment = boxId / E_LAY_NUM;
00123 *layer = boxId % E_LAY_NUM;
00124 }
00125
00126 return true;
00127 }
00128
00129
00130 bool MucIdTransform::SetStripPos( int stripId, int *part, int *segment, int *layer, int *strSubId )
00131 {
00132 if( (stripId < 0) || (stripId > STRIP_MAX-1) )
00133 {
00134 *part = 0;
00135 *segment = 0;
00136 *layer = 0;
00137 *strSubId = 0;
00138 cout << "strip id out range:\t" << stripId << "!" << endl;
00139 return false;
00140 }
00141
00142
00143 if( stripId < STR_SUM[0] ) { *part = 0; }
00144 else if ( stripId < STR_SUM[1] ) { *part = 1; stripId -= STR_SUM[0]; }
00145 else { *part = 2; stripId -= STR_SUM[1]; }
00146
00147
00148 if( *part == BRID )
00149 {
00150 int temp = 0;
00151 if ( stripId >= 2*B_STR_PER_SEG[0] && stripId < 2*B_STR_PER_SEG[0] + B_STR_PER_SEG[1] )
00152 {
00153
00154 *segment = B_TOP;
00155
00156 stripId -= 2*B_STR_PER_SEG[0];
00157 temp = stripId % ( B_ZSTR_NUM + B_TOPSTR_NUM );
00158
00159
00160 if( temp < B_ZSTR_NUM ) *layer = 2*( stripId / ( B_ZSTR_NUM + B_TOPSTR_NUM ) );
00161 else *layer = 2*( stripId / ( B_ZSTR_NUM + B_TOPSTR_NUM ) ) + 1;
00162
00163
00164 if( temp < B_ZSTR_NUM ) *strSubId = temp;
00165 else *strSubId = temp - B_ZSTR_NUM;
00166
00167 }
00168 else
00169 {
00170 if (stripId >= 2*B_STR_PER_SEG[0] + B_STR_PER_SEG[1] ) stripId -= E_STR_NUM;
00171
00172
00173 *segment = stripId / B_STR_PER_SEG[0];
00174
00175 stripId %= B_STR_PER_SEG[0];
00176 temp = stripId % ( B_ZSTR_NUM + B_PHISTR_NUM );
00177
00178
00179 if( temp < B_ZSTR_NUM ) *layer = 2*( stripId / ( B_ZSTR_NUM + B_PHISTR_NUM ) );
00180 else *layer = 2*( stripId / ( B_ZSTR_NUM + B_PHISTR_NUM ) ) + 1;
00181
00182
00183 if( temp < B_ZSTR_NUM ) *strSubId = temp;
00184 else *strSubId = temp - B_ZSTR_NUM;
00185 }
00186 }
00187 else
00188 {
00189 *strSubId = stripId % E_STR_NUM;
00190 *layer = ( stripId / E_STR_NUM ) % E_LAY_NUM ;
00191 *segment = ( stripId / E_STR_NUM ) / E_LAY_NUM ;
00192 }
00193
00194 return true;
00195 }
00196
00197
00198 void MucIdTransform::Print( int mode )
00199 {
00200 if( mode == 0 )
00201 {
00202 cout << "prt: " << m_Part
00203 << "\tseg: " << m_Segment
00204 << "\tlay: " << m_Layer
00205 << "\tstr: " << m_Strip
00206 << "\tid: " << m_Id << endl;
00207 }
00208 else
00209 {
00210 cout << "id: " << m_Id
00211 << "\tprt: " << m_Part
00212 << "\tseg: " << m_Segment
00213 << "\tlay: " << m_Layer
00214 << "\tstr: " << m_Strip << endl;
00215 }
00216 }
00217
00218
00219