00001 #include <iostream>
00002 #include "PbGlIndexer.h"
00003
00004 PbGlIndexer * PbGlIndexer::single=0;
00005 int PbGlIndexer::access_count=0;
00006
00007
00008 PbGlIndexer::PbGlIndexer()
00009 {
00010 }
00011
00012 PbGlIndexer::~PbGlIndexer()
00013 {
00014 }
00015
00016
00017 PbGlIndexer * PbGlIndexer::buildPbGlIndexer()
00018 {
00019 if(!single) single = new PbGlIndexer();
00020 access_count++;
00021 return single;
00022 };
00023
00024 int PbGlIndexer::deletePbGlIndexer()
00025 {
00026 if(single)
00027 {
00028 access_count--;
00029 delete single;
00030 }
00031 return access_count;
00032 };
00033
00034
00035 void PbGlIndexer::iCHi24Packi24PackT(int & Channel, int & SMInFee, int & TowerInSM)
00036 {
00037
00038 int asics = Channel/24;
00039 int preamp = (Channel%24)/4;
00040
00041 int SMRow = preamp/2;
00042 int SMCol = asics/3;
00043
00044 SMInFee = 2 + SMRow + SMCol * 3;
00045
00046 int input = Channel%4;
00047
00048 int xc, yc;
00049 yc = input/2;
00050 xc = 1-input%2;
00051
00052 int RowInSM = ((preamp)-SMRow*2)*2+yc;
00053 int ColInSM = (asics-SMCol*3)*2+xc;
00054 TowerInSM =RowInSM*6+ColInSM;
00055 };
00056
00057
00058 int PbGlIndexer::iCHi144PackT(int & Channel)
00059 {
00060
00061 int PackList[144] = {
00062 1, 0, 7, 6, 13, 12, 19, 18, 25, 24, 31, 30, 37, 36,
00063 43, 42, 49, 48, 55, 54, 61, 60, 67, 66, 3, 2, 9, 8,
00064 15, 14, 21, 20, 27, 26, 33, 32, 39, 38, 45, 44, 51,
00065 50, 57, 56, 63, 62, 69, 68, 5, 4, 11, 10, 17, 16, 23,
00066 22, 29, 28, 35, 34, 41, 40, 47, 46, 53, 52, 59, 58,
00067 65, 64, 71, 70, 73, 72, 79, 78, 85, 84, 91, 90, 97,
00068 96, 103, 102, 109, 108, 115, 114, 121, 120, 127,
00069 126, 133, 132, 139, 138, 75, 74, 81, 80, 87, 86,
00070 93, 92, 99, 98, 105, 104, 111, 110, 117, 116, 123,
00071 122, 129, 128, 135, 134, 141, 140, 77, 76, 83, 82,
00072 89, 88, 95, 94, 101, 100, 107, 106, 113, 112, 119,
00073 118, 125, 124, 131, 130, 137, 136, 143, 142};
00074
00075 return PackList[Channel];
00076 };
00077
00078
00079 int PbGlIndexer::i24Packi24PackTiCH(int & iSM,int & iSMTower)
00080 {
00081 int x, y;
00082 iSM24TxySM24T(iSMTower, x, y);
00083 int xSM = (iSM-2)/3;
00084 int ySM = (iSM-2)%3;
00085 int asics = (x/2)+xSM*3;
00086 int ym = y/2+ySM*2;
00087 int preamp = ym;
00088 int xc = x%2;
00089 int yc = y%2;
00090 int cell = 2*yc+(1-xc);
00091 return asics*24+preamp*4+cell;
00092 };
00093
00094 int PbGlIndexer::i144PackTiCH(int & iPackT)
00095 {
00096 int PackList [144] = {
00097 1, 0, 25, 24, 49, 48, 3, 2, 27, 26, 51, 50,
00098 5, 4, 29, 28, 53, 52, 7, 6, 31, 30, 55, 54,
00099 9, 8, 33, 32, 57, 56, 11, 10, 35, 34, 59, 58,
00100 13, 12, 37, 36, 61, 60, 15, 14, 39, 38, 63, 62,
00101 17, 16, 41, 40, 65, 64, 19, 18, 43, 42, 67, 66,
00102 21, 20, 45, 44, 69, 68, 23, 22, 47, 46, 71, 70,
00103 73, 72, 97, 96, 121, 120, 75, 74, 99, 98, 123, 122,
00104 77, 76, 101, 100, 125, 124, 79, 78, 103, 102, 127, 126,
00105 81, 80, 105, 104, 129, 128, 83, 82, 107, 106, 131, 130,
00106 85, 84, 109, 108, 133, 132, 87, 86, 111, 110, 135, 134,
00107 89, 88, 113, 112, 137, 136, 91, 90, 115, 114, 139, 138,
00108 93, 92, 117, 116, 141, 140, 95, 94, 119, 118, 143, 142};
00109
00110 return PackList[iPackT];
00111 };
00112
00113 inline void PbGlIndexer::SMxySM(int i, int & x, int & y)
00114 {
00115 y = i/8;
00116 x = i%8;
00117 };
00118
00119
00120
00121 int
00122 PbGlIndexer::xySMiSM(int x, int y)
00123 {
00124 int rv = -1;
00125
00126 if ( x >= 0 && x < 8 && y >= 0 && y < 4 )
00127 {
00128 rv = y*8 + x;
00129 }
00130
00131 return rv;
00132 }
00133
00134
00135 int PbGlIndexer::SMxySMTiST(int iSM ,int xSMTower, int ySMTower)
00136 {
00137 int x, y;
00138 SMxySM(iSM, x, y);
00139 return (y*12+ySMTower)*96+x*12+xSMTower;
00140 };
00141
00142
00143 int PbGlIndexer::SMiSMTiST(int iSM ,int iSMTower)
00144 {
00145 int x, y, xx, yy;
00146 SMxySM(iSM, x, y);
00147 iSM144TxySM144T(iSMTower, xx, yy);
00148 return (y*12+yy)*96+x*12+xx;
00149 };
00150
00151
00152 void PbGlIndexer::iSM24TxySM24T(int ismt, int & xsmt, int & ysmt)
00153 {
00154 ysmt = ismt/6;
00155 xsmt = ismt - ysmt*6;
00156 };
00157
00158
00159
00160 void PbGlIndexer::iSTxyST(int const iTower, int & xTower, int & yTower)
00161 {
00162 yTower = iTower/96;
00163 xTower = iTower%96;
00164 };
00165
00166
00167 void PbGlIndexer::iST_SMInd(int const iTower, int & ism, int & ismt, int & xsmt, int & ysmt)
00168 {
00169 int x, y, xsm, ysm;
00170 iSTxyST(iTower, x, y);
00171 xsm = x/12;
00172 ysm = y/12;
00173 ism = ysm*8 + xsm;
00174 xsmt = x%12;
00175 ysmt = y%12;
00176 ismt = ysmt*12+xsmt;
00177 };
00178
00179
00180
00181
00182 int PbGlIndexer::SM24iSM24TiST(int iSM24, int iSM24T){
00183 int xt24, yt24, xSM24, ySM24;
00184 ySM24 = iSM24/16;
00185 xSM24 = iSM24%16;
00186 yt24 = iSM24T/6;
00187 xt24 = iSM24T%6;
00188 return (yt24+ySM24*4)*96+xSM24*6+xt24;
00189 ;
00190 }