Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:57:51

0001 #include <iostream>
0002 #include <cstdlib>
0003 #include <string>
0004 #include <cassert>
0005 using namespace std;
0006 
0007 #include "CalibCalorimetry/EcalLaserAnalyzer/interface/ME.h"
0008 #include "CalibCalorimetry/EcalLaserAnalyzer/interface/MEEBGeom.h"
0009 
0010 #include <TGraph.h>
0011 
0012 //GHM ClassImp(MEEBGeom)
0013 
0014 int MEEBGeom::barrel(EBGlobalCoord ieta, EBGlobalCoord iphi) {
0015   int iz = 1;
0016   if (ieta < 0)
0017     iz = -1;
0018   ieta *= iz;
0019   assert(ieta > 0 && ieta <= 85);
0020   if (iphi < 0)
0021     iphi += 360;
0022   assert(iphi > 0 && iphi <= 360);
0023   return iz;
0024 }
0025 
0026 int MEEBGeom::sm(EBGlobalCoord ieta, EBGlobalCoord iphi) {
0027   int iz = 1;
0028   if (ieta < 0)
0029     iz = -1;
0030   ieta *= iz;
0031   assert(ieta > 0 && ieta <= 85);
0032 
0033   //  int iphi_ = iphi+10;
0034   int iphi_ = iphi;
0035   if (iphi_ > 360)
0036     iphi_ -= 360;
0037   assert(iphi_ > 0 && iphi_ <= 360);
0038 
0039   int ism = (iphi_ - 1) / 20 + 1;
0040   assert(ism >= 1 && ism <= 18);
0041   //  if( iz==1 ) ism += 18;
0042   if (iz == -1)
0043     ism += 18;
0044 
0045   return ism;
0046 }
0047 
0048 int MEEBGeom::dcc(EBGlobalCoord ieta, EBGlobalCoord iphi) {
0049   int ism = sm(ieta, iphi);
0050   return dccFromSm(ism);
0051 }
0052 
0053 int MEEBGeom::dccFromSm(int ism) {
0054   assert(ism >= 1 && ism <= 36);
0055   int iz = 1;
0056   if (ism > 18)
0057     iz = -1;
0058   if (iz == -1)
0059     ism -= 18;
0060   assert(ism >= 1 && ism <= 18);
0061   int idcc = 9 + ism;
0062   if (iz == +1)
0063     idcc += 18;
0064   return idcc;
0065 }
0066 
0067 int MEEBGeom::smFromDcc(int idcc) {
0068   if (idcc > 600)
0069     idcc -= 600;  // also works with FEDids
0070   assert(idcc >= 10 && idcc <= 45);
0071   int ism = idcc - 9;
0072   if (ism > 18)
0073     ism -= 18;
0074   else
0075     ism += 18;
0076   return ism;
0077 }
0078 
0079 TString MEEBGeom::smName(int ism) {
0080   assert(ism >= 1 && ism <= 36);
0081   TString out = "EB+";
0082   if (ism > 18) {
0083     out = "EB-";
0084     ism -= 18;
0085   }
0086   out += ism;
0087   return out;
0088 }
0089 
0090 int MEEBGeom::lmmod(EBGlobalCoord ieta, EBGlobalCoord iphi) {
0091   std::pair<EBLocalCoord, EBLocalCoord> ixy = localCoord(ieta, iphi);
0092   return lm_channel(ixy.first / 5, ixy.second / 5);
0093 }
0094 
0095 int MEEBGeom::tt(EBGlobalCoord ieta, EBGlobalCoord iphi) {
0096   std::pair<EBLocalCoord, EBLocalCoord> ixy = localCoord(ieta, iphi);
0097   return tt_channel(ixy.first / 5, ixy.second / 5);
0098 }
0099 
0100 int MEEBGeom::crystal(EBGlobalCoord ieta, EBGlobalCoord iphi) {
0101   std::pair<EBLocalCoord, EBLocalCoord> ixy = localCoord(ieta, iphi);
0102   return crystal_channel(ixy.first, ixy.second);
0103 }
0104 
0105 int MEEBGeom::side(EBGlobalCoord ieta, EBGlobalCoord iphi) {
0106   int ilmmod = lmmod(ieta, iphi);
0107   return (ilmmod % 2 == 0) ? 1 : 0;
0108 }
0109 
0110 int MEEBGeom::lmr(EBGlobalCoord ieta, EBGlobalCoord iphi) {
0111   int idcc = dcc(ieta, iphi);
0112   int ism = idcc - 9;
0113   int iside = side(ieta, iphi);
0114   int ilmr = 1 + 2 * (ism - 1) + iside;
0115   return ilmr;
0116 }
0117 
0118 std::pair<MEEBGeom::EBLocalCoord, MEEBGeom::EBLocalCoord> MEEBGeom::localCoord(MEEBGeom::EBGlobalCoord ieta,
0119                                                                                MEEBGeom::EBGlobalCoord iphi) {
0120   int iz = 1;
0121   if (ieta < 0)
0122     iz = -1;
0123   ieta *= iz;
0124   assert(ieta > 0 && ieta <= 85);
0125 
0126   //  int iphi_ = iphi+10;
0127   int iphi_ = iphi;
0128   if (iphi_ > 360)
0129     iphi_ -= 360;
0130   assert(iphi_ > 0 && iphi_ <= 360);
0131 
0132   int ix = ieta - 1;
0133 
0134   int iy = (iphi_ - 1) % 20;
0135   if (iz == -1)
0136     iy = 19 - iy;
0137   // if( iz==1 ) iy = 19-iy;
0138 
0139   return std::pair<EBLocalCoord, EBLocalCoord>(ix, iy);
0140 }
0141 
0142 std::pair<MEEBGeom::EBLocalCoord, MEEBGeom::EBLocalCoord> MEEBGeom::localCoord(int icr) {
0143   assert(icr >= 1 && icr <= 1700);
0144   int ix = (icr - 1) / 20;
0145   int iy = 19 - (icr - 1) % 20;
0146   return std::pair<EBLocalCoord, EBLocalCoord>(ix, iy);
0147 }
0148 
0149 std::pair<MEEBGeom::EBGlobalCoord, MEEBGeom::EBGlobalCoord> MEEBGeom::globalCoord(int ism,
0150                                                                                   MEEBGeom::EBLocalCoord ix,
0151                                                                                   MEEBGeom::EBLocalCoord iy) {
0152   assert(ism >= 1 && ism <= 36);
0153   assert(ix >= 0 && ix < 85);
0154   assert(iy >= 0 && iy < 20);
0155   //  int iz=-1;
0156   int iz = 1;
0157   if (ism > 18) {
0158     iz = -1;
0159     ism -= 18;
0160   }
0161   if (iz == -1)
0162     iy = 19 - iy;
0163   // if( iz==1 ) iy = 19-iy;
0164 
0165   int ieta = ix + 1;
0166   ieta *= iz;
0167   //  int iphi = -9 + iy + 20*(ism-1);
0168   int iphi = 1 + iy + 20 * (ism - 1);
0169 
0170   return std::pair<EBGlobalCoord, EBGlobalCoord>(ieta, iphi);
0171 }
0172 
0173 std::pair<float, float> MEEBGeom::globalCoord(int ism, float x, float y) {
0174   assert(ism >= 1 && ism <= 36);
0175   int iz = 1;
0176   if (ism > 18) {
0177     iz = -1;
0178     ism -= 18;
0179   }
0180   if (iz == -1)
0181     y = 19 - y;
0182 
0183   float eta = x + 1;
0184   eta *= iz;
0185   //  float phi = -9 + y + 20*(ism-1);
0186   float phi = 1 + y + 20 * (ism - 1);
0187 
0188   return std::pair<float, float>(eta, phi);
0189 }
0190 
0191 std::pair<MEEBGeom::EBGlobalCoord, MEEBGeom::EBGlobalCoord> MEEBGeom::globalCoord(int ism, int icr) {
0192   assert(ism >= 1 && ism <= 36);
0193   assert(icr >= 1 && icr <= 1700);
0194 
0195   int ix = (icr - 1) / 20;
0196   int iy = 19 - (icr - 1) % 20;
0197 
0198   return globalCoord(ism, ix, iy);
0199 }
0200 
0201 int MEEBGeom::lm_channel(EBTTLocalCoord iX, EBTTLocalCoord iY) {
0202   static const int idx_[] = {
0203       // 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16
0204       1, 2, 2, 2, 2, 4, 4, 4, 4,
0205       6, 6, 6, 6, 8, 8, 8, 8,  // 3
0206       1, 2, 2, 2, 2, 4, 4, 4, 4,
0207       6, 6, 6, 6, 8, 8, 8, 8,  // 2
0208       1, 3, 3, 3, 3, 5, 5, 5, 5,
0209       7, 7, 7, 7, 9, 9, 9, 9,  // 1
0210       1, 3, 3, 3, 3, 5, 5, 5, 5,
0211       7, 7, 7, 7, 9, 9, 9, 9  // 0
0212                               // 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16
0213   };
0214 
0215   int iym, ixm, il, ic, ii;
0216   iym = 4;
0217   ixm = 17;
0218   int iX_ = iX + 1;
0219   int iY_ = iY + 1;
0220   il = iym - iY_;
0221   ic = iX_ - 1;
0222   ii = il * ixm + ic;
0223   if (ii < 0 || ii > (int)(sizeof(idx_) / sizeof(int))) {
0224     return -1;
0225   };
0226   return idx_[ii];
0227 }
0228 
0229 int MEEBGeom::tt_type(EBTTLocalCoord iX, EBTTLocalCoord iY) {
0230   static const int idx_[] = {
0231       // 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16
0232       1, 1, 1, 2, 2, 1, 1, 2, 2,
0233       1, 1, 2, 2, 1, 1, 2, 2,  // 3
0234       1, 1, 1, 2, 2, 1, 1, 2, 2,
0235       1, 1, 2, 2, 1, 1, 2, 2,  // 2
0236       1, 1, 1, 2, 2, 1, 1, 2, 2,
0237       1, 1, 2, 2, 1, 1, 2, 2,  // 1
0238       1, 1, 1, 2, 2, 1, 1, 2, 2,
0239       1, 1, 2, 2, 1, 1, 2, 2  // 0
0240                               // 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16
0241   };
0242 
0243   int iym, ixm, il, ic, ii;
0244   iym = 4;
0245   ixm = 17;
0246   int iX_ = iX + 1;
0247   int iY_ = iY + 1;
0248   il = iym - iY_;
0249   ic = iX_ - 1;
0250   ii = il * ixm + ic;
0251   if (ii < 0 || ii > (int)(sizeof(idx_) / sizeof(int))) {
0252     return -1;
0253   };
0254   return idx_[ii];
0255 }
0256 
0257 int MEEBGeom::hv_channel(EBTTLocalCoord iX, EBTTLocalCoord iY) {
0258   static const int idx_[] = {
0259       // 0  1  2  3   4   5   6   7   8   9  10  11  12  13  14  15  16
0260       1,  3,  5,  7,  9,  11, 13, 15, 17,
0261       19, 21, 23, 25, 27, 29, 31, 33,  // 3
0262       1,  3,  5,  7,  9,  11, 13, 15, 17,
0263       19, 21, 23, 25, 27, 29, 31, 33,  // 2
0264       2,  4,  6,  8,  10, 12, 14, 16, 18,
0265       20, 22, 24, 26, 28, 30, 32, 34,  // 1
0266       2,  4,  6,  8,  10, 12, 14, 16, 18,
0267       20, 22, 24, 26, 28, 30, 32, 34  // 0
0268                                       // 0  1  2  3   4   5   6   7   8   9  10  11  12  13  14  15  16
0269   };
0270 
0271   int iym, ixm, il, ic, ii;
0272   iym = 4;
0273   ixm = 17;
0274   int iX_ = iX + 1;
0275   int iY_ = iY + 1;
0276   il = iym - iY_;
0277   ic = iX_ - 1;
0278   ii = il * ixm + ic;
0279   if (ii < 0 || ii > (int)(sizeof(idx_) / sizeof(int))) {
0280     return -1;
0281   };
0282   return idx_[ii];
0283 }
0284 
0285 int MEEBGeom::lv_channel(EBTTLocalCoord iX, EBTTLocalCoord iY) {
0286   static const int idx_[] = {
0287       // 0  1  2  3  4  5  6  7  8   9  10  11  12  13  14  15  16
0288       1,  2,  2,  4,  4,  6,  6,  8,  8,
0289       10, 10, 12, 12, 14, 14, 16, 16,  // 3
0290       1,  2,  2,  4,  4,  6,  6,  8,  8,
0291       10, 10, 12, 12, 14, 14, 16, 16,  // 2
0292       1,  3,  3,  5,  5,  7,  7,  9,  9,
0293       11, 11, 13, 13, 15, 15, 17, 17,  // 1
0294       1,  3,  3,  5,  5,  7,  7,  9,  9,
0295       11, 11, 13, 13, 15, 15, 17, 17  // 0
0296                                       // 0  1  2  3  4  5  6  7  8   9  10  11  12  13  14  15  16
0297   };
0298 
0299   int iym, ixm, il, ic, ii;
0300   iym = 4;
0301   ixm = 17;
0302   int iX_ = iX + 1;
0303   int iY_ = iY + 1;
0304   il = iym - iY_;
0305   ic = iX_ - 1;
0306   ii = il * ixm + ic;
0307   if (ii < 0 || ii > (int)(sizeof(idx_) / sizeof(int))) {
0308     return -1;
0309   };
0310   return idx_[ii];
0311 }
0312 
0313 int MEEBGeom::tt_channel(EBTTLocalCoord iX, EBTTLocalCoord iY) {
0314   int itt = 4 * iX + 4 - iY;  // :)
0315 
0316   return itt;
0317 }
0318 
0319 int MEEBGeom::crystal_channel(EBLocalCoord ix, EBLocalCoord iy) {
0320   // "Test beam numbering"
0321   int icr = 20 * ix + 19 - iy + 1;  // :)
0322 
0323   return icr;
0324 }
0325 
0326 int MEEBGeom::electronic_channel(EBLocalCoord ix, EBLocalCoord iy) {
0327   int iX = ix / 5;
0328   int iY = iy / 5;
0329   int itt = tt_channel(iX, iY);
0330   int type = tt_type(iX, iY);
0331 
0332   int iVFE = ix % 5 + 1;
0333   int islot = iy % 5 + 1;
0334   if (iVFE % 2 == 1)
0335     islot = 6 - islot;
0336   int icr = 5 * (iVFE - 1) + (islot - 1);
0337   // rotate for type-1 towers
0338   if (type == 1) {
0339     icr = 24 - icr;
0340   }
0341   icr += 25 * (itt - 1);
0342 
0343   return icr;
0344 }
0345 
0346 TGraph* MEEBGeom::getGraphBoundary(int type, int num, bool global) {
0347   int ism_ = 0;
0348   if (type == iSuperModule) {
0349     ism_ = num;
0350   } else if (type == iLMRegion) {
0351     ism_ = (num - 1) / 2 + 1;
0352     if (ism_ > 18)
0353       ism_ -= 18;
0354     else
0355       ism_ += 18;
0356   } else
0357     abort();
0358 
0359   int ism = 1;
0360   if (global)
0361     ism = ism_;
0362 
0363   //  std::list< std::pair< float, float > > l;
0364   // getBoundary( l, type, num, global, ism );
0365   //  int n = l.size();
0366   //  if( n==0 ) return 0;
0367 
0368   float ix[100];
0369   float iy[100];
0370   int ixmin = 0;
0371   int ixmax = 84;
0372   int iymin = 0;
0373   int iymax = 19;
0374 
0375   int n(0);
0376   if (type == iSuperModule) {
0377     n = 5;
0378     ix[0] = ixmin - 0.5;
0379     iy[0] = iymin - 0.5;
0380     ix[1] = ixmin - 0.5;
0381     iy[1] = iymax + 0.5;
0382     ix[2] = ixmax + 0.5;
0383     iy[2] = iymax + 0.5;
0384     ix[3] = ixmax + 0.5;
0385     iy[3] = iymin - 0.5;
0386     ix[4] = ix[0];
0387     iy[4] = iy[0];
0388   } else if (type == iLMRegion) {
0389     int iside = num;
0390     if (global) {
0391       iside = (num - 1) % 2;
0392     }
0393 
0394     if (iside == 1) {
0395       n = 5;
0396       ix[0] = ixmin + 5 - 0.5;
0397       iy[0] = iymin + 10 - 0.5;
0398       ix[1] = ixmin + 5 - 0.5;
0399       iy[1] = iymax + 0.5;
0400       ix[2] = ixmax + 0.5;
0401       iy[2] = iymax + 0.5;
0402       ix[3] = ixmax + 0.5;
0403       iy[3] = iymin + 10 - 0.5;
0404       ix[4] = ix[0];
0405       iy[4] = iy[0];
0406     } else {
0407       n = 7;
0408       ix[0] = ixmin - 0.5;
0409       iy[0] = iymin - 0.5;
0410       ix[1] = ixmin - 0.5;
0411       iy[1] = iymax + 0.5;
0412       ix[2] = ixmin + 5 - 0.5;
0413       iy[2] = iymax + 0.5;
0414       ix[3] = ixmin + 5 - 0.5;
0415       iy[3] = iymax - 10 + 0.5;
0416       ix[4] = ixmax + 0.5;
0417       iy[4] = iymax - 10 + 0.5;
0418       ix[5] = ixmax + 0.5;
0419       iy[5] = iymin - 0.5;
0420       ix[6] = ix[0];
0421       iy[6] = iy[0];
0422     }
0423   }
0424 
0425   if (global) {
0426     for (int ii = 0; ii < n; ii++) {
0427       std::pair<float, float> xy = globalCoord(ism, ix[ii], iy[ii]);
0428       ix[ii] = xy.first;
0429       iy[ii] = xy.second;
0430     }
0431   }
0432 
0433   //   int ii=0;
0434   //   std::list< std::pair< float, float > >::const_iterator l_it;
0435   //   for( l_it=l.begin(); l_it!=l.end(); l_it++ )
0436   //     {
0437   //       //      std::cout << "[" << l_it->first << "," << l_it->second << "]" << std::endl;
0438   //       ix[ii] = l_it->first;
0439   //       iy[ii] = l_it->second;
0440   //       ii++;
0441   //     }
0442 
0443   //  assert( ii==n );
0444   return new TGraph(n, ix, iy);
0445 }
0446 
0447 std::pair<int, int> MEEBGeom::pn(int ilmmod) {
0448   switch (ilmmod) {
0449     case 1:
0450       return std::pair<int, int>(0, 5);
0451     case 2:
0452       return std::pair<int, int>(1, 6);
0453     case 3:
0454       return std::pair<int, int>(1, 6);
0455     case 4:
0456       return std::pair<int, int>(2, 7);
0457     case 5:
0458       return std::pair<int, int>(2, 7);
0459     case 6:
0460       return std::pair<int, int>(3, 8);
0461     case 7:
0462       return std::pair<int, int>(3, 8);
0463     case 8:
0464       return std::pair<int, int>(4, 9);
0465     case 9:
0466       return std::pair<int, int>(4, 9);
0467     default:
0468       abort();
0469   }
0470   return std::pair<int, int>(-1, -1);
0471 }
0472 
0473 std::pair<int, int> MEEBGeom::memFromLmr(int ilmr) {
0474   std::pair<int, int> dccAndSide_ = ME::dccAndSide(ilmr);
0475   int idcc = dccAndSide_.first;
0476   return std::pair<int, int>(idcc, idcc);
0477 }
0478 
0479 std::vector<int> MEEBGeom::lmmodFromLmr(int ilmr) {
0480   std::pair<int, int> dccAndSide_ = ME::dccAndSide(ilmr);
0481   int iside = dccAndSide_.second;
0482   std::vector<int> vec;
0483   for (int ilmmod = 1; ilmmod <= 9; ilmmod++) {
0484     if ((ilmmod + iside) % 2 == 1)
0485       vec.push_back(ilmmod);
0486   }
0487   return vec;
0488 }
0489 
0490 int MEEBGeom::apdRefTower(int ilmmod) {
0491   switch (ilmmod) {
0492       /* case   1: return 1;
0493     case   2: return 5; 
0494     case   3: return 7;
0495     case   4: return 21; 
0496     case   5: return 23;
0497     case   6: return 37;
0498     case   7: return 39;
0499     case   8: return 53;
0500     case   9: return 55;
0501       */
0502     case 1:
0503       return 2;
0504     case 2:
0505       return 6;
0506     case 3:
0507       return 8;
0508     case 4:
0509       return 22;
0510     case 5:
0511       return 24;
0512     case 6:
0513       return 38;
0514     case 7:
0515       return 40;
0516     case 8:
0517       return 54;
0518     case 9:
0519       return 56;
0520     default:
0521       abort();
0522   }
0523   return 0;
0524 }
0525 
0526 std::vector<int> MEEBGeom::apdRefChannels(int ilmmod) {
0527   std::vector<int> vec;
0528   switch (ilmmod) {
0529     case 1:
0530       vec.push_back(0);
0531       vec.push_back(24);
0532       break;
0533     case 2:
0534       vec.push_back(0);
0535       vec.push_back(24);
0536       break;
0537     case 3:
0538       vec.push_back(0);
0539       vec.push_back(24);
0540       break;
0541     case 4:
0542       vec.push_back(0);
0543       vec.push_back(24);
0544       break;
0545     case 5:
0546       vec.push_back(0);
0547       vec.push_back(24);
0548       break;
0549     case 6:
0550       vec.push_back(0);
0551       vec.push_back(24);
0552       break;
0553     case 7:
0554       vec.push_back(0);
0555       vec.push_back(24);
0556       break;
0557     case 8:
0558       vec.push_back(0);
0559       vec.push_back(24);
0560       break;
0561     case 9:
0562       vec.push_back(0);
0563       vec.push_back(24);
0564       break;
0565     default:
0566       abort();
0567   }
0568   return vec;
0569 }