Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 10:06:07

0001 #include <iostream>
0002 
0003 template <class T>
0004 T mod(const T& a, const T& b) {
0005   T c = a % b;
0006   return c < 0 ? c + b : c;
0007 }
0008 
0009 static const char endcapDccMap[401] = {
0010     "       777777       "
0011     "    666777777888    "
0012     "   66667777778888   "
0013     "  6666667777888888  "
0014     " 666666677778888888 "
0015     " 566666677778888880 "  //    Z
0016     " 555666667788888000 "  //     x-----> X
0017     "55555566677888000000"  //     |
0018     "555555566  880000000"  //     |
0019     "55555555    00000000"  //_          //     |
0020     "55555554    10000000"  //     V Y
0021     "554444444  111111100"
0022     "44444444332211111111"
0023     " 444444333222111111 "
0024     " 444443333222211111 "
0025     " 444433333222221111 "
0026     "  4443333322222111  "
0027     "   43333332222221   "
0028     "    333333222222    "
0029     "       333222       "};
0030 
0031 /** Gets the phi index of the DCC reading a RU (SC or TT)
0032  * @param iDet 0 for EE-, 1 for EB, 2 for EE+
0033  * @param i iEta or iX
0034  * @param j iPhi or iY
0035  * @return DCC phi index between 0 and 8 for EE
0036  * and between 0 and 17 for EB
0037  */
0038 inline int dccPhiIndexOfRU(int iDet, int i, int j) {
0039   if (iDet == 1) {  //barrel
0040     //iEta=i, iPhi=j
0041     //phi edge of a SM is 4 TT
0042     return (j + 2) / 4;
0043   }
0044   char flag = endcapDccMap[i + j * 20];
0045   return (flag == ' ') ? -1 : (flag - '0');
0046 }
0047 
0048 /** Gets the phi index of the DCC reading a crystal
0049  * @param iDet 0 for EE-, 1 for EB, 2 for EE+
0050  * @param i iEta or iX
0051  * @param j iPhi or iY
0052  * @return DCC phi index between 0 and 8 for EE
0053  * and between 0 and 17 for EB
0054  */
0055 inline int dccPhiIndex(int iDet, int i, int j) { return dccPhiIndexOfRU(iDet, i / 5, j / 5); }
0056 
0057 /** Gets the index of the DCC reading a crystal
0058  * @param iDet 0 for EE-, 1 for EB, 2 for EE+
0059  * @param i iEta or iX
0060  * @param j iPhi or iY
0061  * @return DCC index between 0 and 53 
0062  */
0063 inline int dccIndex(int iDet, int i, int j) {
0064   if (iDet == 1) {  //barrel
0065     //a SM is 85 crystal long:
0066     int iEtaSM = i / 85;
0067     //a SM is 20 crystal wide:
0068     int iPhiSM = (j + 10) / 20;
0069     //DCC numbers start at 9 in the barrel and there 18 DCC/SM
0070     return 9 + 18 * iEtaSM + iPhiSM;
0071   }
0072   int iPhi = dccPhiIndex(iDet, i, j);
0073   if (iPhi < 0)
0074     return -1;
0075   //34 DCCs in barrel and 8 in EE-=>in EE+ DCC numbering starts at 45,
0076   //iDet/2 is 0 for EE- and 1 for EE+:
0077   return iPhi + iDet / 2 * 45;
0078 }
0079 
0080 /** Gets the index of the DCC reading a crystal
0081  * @param iDet 0 for EE-, 1 for EB, 2 for EE+
0082  * @param i iEta (staring at eta=-1.48)  or iX
0083  * @param j iPhi or iY
0084  * @return DCC index between 0 and 53 
0085  */
0086 inline int dccIndexOfRU(int iDet, int i, int j) {
0087   if (iDet == 1) {  //barrel
0088     //a SM is 17 RU long:
0089     int iEtaSM = i / 17;
0090     //a SM is 4 RU wide:
0091     int iPhiSM = (j + 2) / 4;
0092     //DCC numbers start at 9 in the barrel and there 18 DCC/SM
0093     return 9 + 18 * iEtaSM + iPhiSM;
0094   }
0095   int iPhi = dccPhiIndexOfRU(iDet, i, j);
0096   if (iPhi < 0)
0097     return -1;
0098   //34 DCCs in barrel and 8 in EE-=>in EE+ DCC numbering starts at 45,
0099   //iDet/2 is 0 for EE- and 1 for EE+:
0100   return iPhi + iDet / 2 * 45;
0101 }
0102 
0103 inline int abOfDcc(int iDCC) {
0104   if (iDCC < 0 || iDCC > 54)
0105     return -1;
0106   if (iDCC < 9) {  //EE-
0107     return iDCC / 3;
0108   } else if (iDCC < 27) {  //EB-
0109     //an EB AB is made of 6 DCCs,
0110     //first EB- AB is numbered 3
0111     //and "1st" DCC of AB 3 is DCC 26
0112     //(AB 3 made of DCCs 26,9,10,11,12,13):
0113     return 3 + mod(iDCC - 26, 18) / 6;
0114   } else if (iDCC < 45) {  //EB+
0115     //an EB AB is made of 6 DCCs,
0116     //first EB+ AB is numbered 6
0117     //and "1st" DCC of AB6 is DCC 44
0118     //(AB 6 made of DCCs 44,27,28,29,30,31):
0119     return 6 + mod(iDCC - 44, 18) / 6;
0120   } else {  //EE+
0121     //AB numbering starts at DCC=45 and runs along phi in increasing phi
0122     //first EE+ AB is numbered 9:
0123     return 9 + (iDCC - 45) / 3;
0124   }
0125 }