CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/CalibCalorimetry/EcalLaserAnalyzer/src/MEEEGeom.cc

Go to the documentation of this file.
00001 #include <assert.h>
00002 #include <iostream>
00003 #include <stdlib.h>
00004 #include <string>
00005 using namespace std;
00006 
00007 #include "CalibCalorimetry/EcalLaserAnalyzer/interface/ME.h"
00008 #include "CalibCalorimetry/EcalLaserAnalyzer/interface/MEEEGeom.h"
00009 
00010 //GHM ClassImp(MEEEGeom)
00011 
00012 bool 
00013 MEEEGeom::pnTheory = true;
00014 
00015 int 
00016 MEEEGeom::quadrant( SuperCrysCoord iX, SuperCrysCoord iY )
00017 {
00018   bool near = iX>=11;  bool far  = !near;
00019   bool top  = iY>=11;  bool bot  = !top;
00020   
00021   int iquad=0;
00022   if( near && top ) iquad=1;
00023   if( far  && top ) iquad=2;
00024   if( far  && bot ) iquad=3;
00025   if( near && bot ) iquad=4;
00026   
00027   return iquad;
00028 }
00029 
00030 int 
00031 MEEEGeom::sector( SuperCrysCoord iX, SuperCrysCoord iY )
00032 {
00033  
00034   //  Y (towards the surface)
00035   //  T
00036   //  |
00037   //  |
00038   //  |
00039   //  o---------| X  (towards center of LHC)
00040   //
00041   static const int 
00042     idx_[] =
00043     {
00044      // 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 
00045      0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 9, 9, 9, 0, 0, 0, 0, 0, 0, 0, // 20
00046      0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 9, 0, 0, 0, 0, // 19
00047      0, 0, 0, 2, 1, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 9, 8, 0, 0, 0, // 18
00048      0, 0, 2, 2, 2, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 8, 8, 8, 0, 0, // 17
00049      0, 2, 2, 2, 2, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 8, 8, 8, 8, 0, // 16
00050      0, 2, 2, 2, 2, 2, 1, 1, 1, 1, 9, 9, 9, 9, 8, 8, 8, 8, 8, 0, // 15
00051      0, 2, 2, 2, 2, 2, 2, 1, 1, 1, 9, 9, 9, 8, 8, 8, 8, 8, 8, 0, // 14
00052      2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, // 13
00053      3, 3, 2, 2, 2, 2, 2, 2, 2, 0, 0, 8, 8, 8, 8, 8, 8, 8, 7, 7, // 12
00054      3, 3, 3, 3, 3, 3, 3, 2, 0, 0, 0, 0, 8, 7, 7, 7, 7, 7, 7, 7, // 11
00055      3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, // 10
00056      3, 3, 3, 3, 3, 3, 3, 4, 4, 0, 0, 6, 6, 7, 7, 7, 7, 7, 7, 7, // 9
00057      3, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7, // 8
00058      0, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 0, // 7
00059      0, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 0, // 6
00060      0, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 0, // 5
00061      0, 0, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 0, 0, // 4
00062      0, 0, 0, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 0, 0, 0, // 3
00063      0, 0, 0, 0, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 0, 0, 0, 0, // 2
00064      0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0  // 1
00065      // 1  2  3  4  5  6  7  8  9 10   11 12 13 14 15 16 17 18 19 20 
00066      };
00067 
00068 
00069   int iym, ixm, il, ic, ii;
00070   iym=20;
00071   ixm=20;
00072   int iX_ = iX;
00073   int iY_ = iY;
00074   il=iym-iY_;
00075   ic=iX_-1;
00076   ii=il*ixm+ic;
00077 
00078   if(ii < 0 || ii > (int)(sizeof(idx_)/sizeof(int)) || idx_[ii] == 0) { return -1; };
00079   return idx_[ii];
00080 }
00081 
00082 int 
00083 MEEEGeom::sm( SuperCrysCoord iX, SuperCrysCoord iY, int iz )
00084 {
00085   // this is *my* convention. To be consistent with the barrel
00086   // sm goes from 1 to 9 for iz+ and from 10 to 18 for iz-
00087   int ism_ = sector( iX, iY );
00088   if( ism_<0 ) return ism_;
00089   if( iz<0 ) ism_+=9;
00090   return ism_;
00091 }
00092 
00093 int 
00094 MEEEGeom::lmmod( SuperCrysCoord iX, SuperCrysCoord iY )
00095 {
00096   //
00097   // laser monitoring modules for EE-F and EE+F
00098   // for EE-N and EE+N :  iX ---> 20-iX+1
00099   //  
00100 
00101   static const int 
00102     idx_[] =
00103     {
00104      // 1  2  3   4   5   6   7   8   9   A 
00105      //------------------------------
00106       0,  0,  0,  0,  0,  0,  0,  1,  1,  1,
00107       0,  0,  0,  0,  2,  1,  1,  1,  1,  1,
00108       0,  0,  0,  5,  2,  2,  2,  2,  2,  1,
00109       0,  0,  5,  5,  5,  3,  3,  2,  2,  2,
00110       0,  8,  5,  5,  5,  3,  3,  3,  3,  3,
00111       0,  8,  8,  5,  6,  6,  4,  4,  4,  3,
00112       0,  8,  8,  5,  6,  6,  7,  4,  4,  4,
00113       8,  8,  8,  6,  6,  7,  7,  7,  4,  4,
00114       9,  9,  8,  6,  6,  7,  7,  7,  7,  0,
00115       9,  9,  9, 10, 10, 11, 11,  7,  0,  0,
00116      12,  9,  9, 10, 10, 11, 11, 11,  0,  0,
00117      12, 12, 13, 10, 10, 11, 11, 17, 17,  0,
00118      12, 12, 13, 13, 13, 11, 17, 17, 17, 19,
00119       0, 12, 13, 13, 14, 15, 17, 17, 17, 19,
00120       0, 12, 14, 14, 14, 15, 16, 17, 19, 19,
00121       0, 14, 14, 14, 14, 15, 16, 16, 19, 19,
00122       0,  0, 14, 15, 15, 15, 16, 16, 19, 19,
00123       0,  0,  0, 15, 15, 15, 16, 18, 18, 18,
00124       0,  0,  0,  0, 16, 16, 16, 18, 18, 18,
00125       0,  0,  0,  0,  0,  0,  0, 18, 18, 18
00126      };
00127 
00128   int iym, ixm, il, ic, ii;
00129   iym=20;
00130   ixm=10;
00131   int iX_ = iX;
00132   if( iX>=11 ) iX_ = 20-iX+1;
00133   int iY_ = iY;
00134   il=iym-iY_;
00135   ic=iX_-1;
00136   ii=il*ixm+ic;
00137   if(ii < 0 || ii > (int)(sizeof(idx_)/sizeof(int)) || idx_[ii] == 0) { return -1; };
00138   return idx_[ii];
00139 }
00140 
00141 int 
00142 MEEEGeom::sc_in_quad( SuperCrysCoord iX, SuperCrysCoord iY )
00143 {
00144   static const int 
00145     idx_[] =
00146     {
00147      // 1  2  3  4  5  6  7  8  9  A 
00148      //-----------------------------------
00149        77, 71, 63, 55, 46, 37, 28, 18,  0,  0, // A
00150        78, 72, 64, 56, 47, 38, 29, 19,  9,  0, // 9
00151        79, 73, 65, 57, 48, 39, 30, 20, 10,  1, // 8
00152         0, 74, 66, 58, 49, 40, 31, 21, 11,  2, // 7
00153         0, 75, 67, 59, 50, 41, 32, 22, 12,  3, // 6
00154         0, 76, 68, 60, 51, 42, 33, 23, 13,  4, // 5
00155         0,  0, 69, 61, 52, 43, 34, 24, 14,  5, // 4
00156         0,  0, 70, 62, 53, 44, 35, 25, 15,  6, // 3
00157         0,  0,  0,  0, 54, 45, 36, 26, 16,  7, // 2
00158         0,  0,  0,  0,  0,  0,  0, 27, 17,  8, // 1
00159      //-----------------------------------
00160      };
00161   int iym, ixm, il, ic, ii;
00162   iym=10;
00163   ixm=10;
00164   int iX_ = iX;
00165   if( iX>=11 ) iX_ = 20-iX+1;
00166   int iY_ = iY;
00167   if( iY>=11 ) iY_ = 20-iY+1;
00168   il=iym-iY_;
00169   ic=iX_-1;
00170   ii=il*ixm+ic;
00171   if(ii < 0 || ii > (int)(sizeof(idx_)/sizeof(int)) || idx_[ii] == 0) { return -1; };
00172   return idx_[ii];
00173 }
00174 
00175 int 
00176 MEEEGeom::sc_type( SuperCrysCoord iX, SuperCrysCoord iY )
00177 {
00178   static const int 
00179     idx_[] =
00180     {
00181      // there are seven types of super-crystals
00182      // 1  2  3  4  5  6  7  8  9 10 
00183      //-----------------------------------
00184         0,  0,  0,  0,  0,  0,  0,  3, -1, -1, // 10
00185         0,  0,  0,  0,  0,  0,  0,  0,  2, -1, //  9
00186         6,  0,  0,  0,  0,  0,  0,  0,  0,  1, //  8
00187        -1,  0,  0,  0,  0,  0,  0,  0,  0,  0, //  7
00188        -1,  0,  0,  0,  0,  0,  0,  0,  0,  0, //  6
00189        -1,  6,  0,  0,  0,  0,  0,  0,  0,  0, //  5
00190        -1, -1,  6,  0,  0,  0,  0,  0,  0,  0, //  4
00191        -1, -1,  5,  4,  0,  0,  0,  0,  0,  0, //  3
00192        -1, -1, -1, -1,  4,  0,  0,  0,  0,  0, //  2
00193        -1, -1, -1, -1, -1, -1, -1,  4,  0,  0, //  1
00194      //-----------------------------------
00195      };
00196   int iym, ixm, il, ic, ii;
00197   iym=10;
00198   ixm=10;
00199   int iX_ = iX;
00200   if( iX>=11 ) iX_ = 20-iX+1;
00201   int iY_ = iY;
00202   if( iY>=11 ) iY_ = 20-iY+1;
00203   il=iym-iY_;
00204   ic=iX_-1;
00205   ii=il*ixm+ic;
00206   if(ii < 0 || ii > (int)(sizeof(idx_)/sizeof(int)) || idx_[ii] == -1) { return -1; };
00207   return idx_[ii];
00208 }
00209 
00210 int 
00211 MEEEGeom::sc( SuperCrysCoord iX, SuperCrysCoord iY )
00212 {
00213   int isc_in_quad = sc_in_quad( iX, iY );
00214   assert( isc_in_quad!=0 );
00215   if( isc_in_quad<0 ) return -1;
00216 
00217   int iquad = quadrant( iX, iY );
00218   return 79*(iquad-1)+isc_in_quad;
00219 }
00220 
00221 int 
00222 MEEEGeom::dcc( SuperCrysCoord iX, SuperCrysCoord iY, int iz )
00223 {
00224   // end-cap minus:
00225   // S7  --> DCC-1 (N)
00226   // S8  --> DCC-2 (N)
00227   // S9  --> DCC-3 (N)
00228   // S1  --> DCC-4 (F) 
00229   // S2  --> DCC-5 (F)
00230   // S3  --> DCC-6 (F)
00231   // S4  --> DCC-7 (F)
00232   // S5  --> DCC-8 (F and N)
00233   // S6  --> DCC-9 (N)
00234   // for the end-cap plus, add 45 to the DCC number
00235   int isect = sector( iX, iY );
00236   assert( isect!=0 );
00237   assert( abs(iz)==1 );
00238   if( isect<0 ) return -1;
00239 
00240   int idcc=0;
00241   
00242   idcc = isect-6;
00243   if( idcc<=0 ) idcc+=9;
00244   if( iz==+1 )  idcc+=45;
00245 
00246   return idcc;
00247 }
00248 
00249 int 
00250 MEEEGeom::lmr( SuperCrysCoord iX, SuperCrysCoord iY, int iz )
00251 {
00252   // laser monitoring regions
00253   // end-cap minus:
00254   // S7  --> LM-1
00255   // S8  --> LM-2
00256   // S9  --> LM-3
00257   // S1  --> LM-4 
00258   // S2  --> LM-5 
00259   // S3  --> LM-6 
00260   // S4  --> LM-7 
00261   // S5  --> LM-8 (F) and LM-9 (N)
00262   // S6  --> LM-10
00263   // for the end-cap plus,  add 72 to the LM number
00264   // for the end-cap minus, add 82 to the LM number
00265   
00266   int iquad = quadrant( iX, iY );
00267   int isect = sector( iX, iY );
00268   assert( isect!=0 );
00269   assert( abs(iz)==1 );
00270   if( isect<0 ) return -1;
00271 
00272   int ilmr=0;
00273   ilmr = isect-6;
00274   if( ilmr<=0 ) ilmr+=9;
00275   if( ilmr==9 ) ilmr++;
00276   if( ilmr==8 && iquad==4 ) ilmr++;
00277   if( iz==+1 )  ilmr+=72;
00278   else          ilmr+=82;
00279 
00280   return ilmr;
00281 }
00282 
00283 int 
00284 MEEEGeom::dee( SuperCrysCoord iX, SuperCrysCoord iY, int iz )
00285 {
00286   int iquad = quadrant( iX, iY );
00287   int idee=0;
00288   bool far = ( iquad==2 || iquad==3 );  bool near = !far;
00289   bool plus = (iz>0); bool minus = !plus;
00290   if( far  && plus  ) idee=1;
00291   if( near && plus  ) idee=2;
00292   if( near && minus ) idee=3;
00293   if( far  && minus ) idee=4; 
00294 
00295   return idee;
00296 }
00297 
00298 int 
00299 MEEEGeom::crystal_in_sc( CrysCoord ix, CrysCoord iy )
00300 {
00301   // the seven types of super-crystals
00302   static const int 
00303     idx_[7][25] =
00304     {
00305             {
00306       21, 16, 11,  6,  1,
00307       22, 17, 12,  7,  2,
00308       23, 18, 13,  8,  3,
00309       24, 19, 14,  9,  4,
00310       25, 20, 15, 10,  5
00311             }, { 
00312       -1, -1, -1, -1, -1,
00313       22, 17, 12,  7,  2,
00314       23, 18, 13,  8,  3,
00315       24, 19, 14,  9,  4,
00316       25, 20, 15, 10,  5,
00317             }, {
00318       -1, -1, -1, -1, -1,
00319       -1, -1, -1, -1, -1,
00320       23, -1, -1, -1, -1,          
00321       24, 19, -1, -1, -1,
00322       25, 20, 15, -1, -1
00323             }, {
00324       21, 16, 11,  6, -1,
00325       22, 17, 12,  7, -1,
00326       23, 18, 13,  8, -1,
00327       24, 19, 14,  9, -1,
00328       25, 20, 15, 10, -1
00329             }, {
00330       21, 16, 11,  6,  1,
00331       22, 17, 12,  7,  2,
00332       -1, -1, -1, -1, -1,
00333       -1, -1, -1, -1, -1,
00334       -1, -1, -1, -1, -1,
00335             }, {
00336       -1, -1, -1, -1, -1,
00337       -1, -1, -1, -1, -1,
00338       -1, -1, -1, -1, -1,
00339       -1, -1, -1, -1, -1,
00340       -1, -1, -1, -1, -1,
00341             }, {
00342       -1, -1, -1,  6,  1,
00343       -1, -1, -1,  7,  2,
00344       -1, -1, -1,  8,  3,
00345       -1, -1, -1,  9,  4,
00346       -1, -1, -1, 10,  5
00347             }
00348     };
00349   
00350   int iX, iY, jx, jy;
00351   int iX_ = (ix-1)/5+1;
00352   int iY_ = (iy-1)/5+1;
00353   int jx_ = ix - 5*(iX_-1);
00354   int jy_ = iy - 5*(iY_-1);
00355 
00356   int iquad = quadrant( iX_, iY_ );
00357   if( iX_>=11 ) 
00358     {
00359       iX_ = 20-iX_+1;
00360       jx_ =  5-jx_+1;
00361     }
00362   if( iY_>=11 ) 
00363     {
00364       iY_ = 20-iY_+1;
00365       jy_ =  5-jy_+1;
00366     }
00367 
00368   // FIXME : this is stupid !!!
00369   if( iquad==1 || iquad==3 )
00370     {
00371       iX = iX_;
00372       iY = iY_;
00373       jx = jx_;
00374       jy = jy_;
00375     }
00376   else
00377     {
00378       iX = iY_;
00379       iY = iX_;
00380       jx = jy_;
00381       jy = jx_;
00382     }
00383 
00384   int isc_type = sc_type( iX, iY );
00385   assert( isc_type>=0 && isc_type<7 );
00386   
00387   int iym, ixm, il, ic, ii;
00388   iym=5;
00389   ixm=5;
00390   il=iym-jy;
00391   ic=jx-1;
00392   ii=il*ixm+ic;
00393   if(ii < 0 || ii > (int)(sizeof(idx_)/sizeof(int)) || idx_[isc_type][ii] == -1) { return -1; };
00394   return idx_[isc_type][ii];
00395 }
00396 
00397 int 
00398 MEEEGeom::crystal( CrysCoord ix, CrysCoord iy )
00399 {
00400 
00401   int iX = (ix-1)/5+1;
00402   int iY = (iy-1)/5+1;
00403   int isc = sc( iX, iY );
00404   assert( isc!=0 );
00405   if( isc<0 ) return -2;
00406 
00407   int icr_in_sc = crystal_in_sc( ix, iy );
00408   assert( icr_in_sc!=0 );
00409   if( icr_in_sc<0 ) return -1;
00410   
00411   return 25*(isc-1) + icr_in_sc;
00412 }
00413 
00414 TString
00415 MEEEGeom::smName( int ism )
00416 {
00417   assert( ism>=1 && ism<=18 );
00418   TString out = "EE+";
00419   if( ism>9 )
00420     {
00421       out = "EE-";
00422       ism -= 9;
00423     }
00424   out += ism;
00425   return out;
00426 }
00427 
00428 int
00429 MEEEGeom::dccFromSm( int ism )
00430 {
00431   assert( ism>=1 && ism<=18 );
00432   int dcc_[18] = 
00433     { 49, 50, 51, 52, 53, 54, 46, 47, 48, 
00434        4,  5,  6,  7,  8,  9,  1,  2,  3 };
00435   return dcc_[ism-1];
00436 }
00437 
00438 int
00439 MEEEGeom::smFromDcc( int idcc )
00440 {
00441   if( idcc>600 ) idcc-=600;  // also works with FEDids
00442   int ism(0);
00443   if( idcc>=1 && idcc<=9 )
00444     {
00445       ism = 6+idcc;
00446       if( ism>9 ) ism-=9;
00447       ism+=9;
00448     }
00449   else if( idcc>=46 && idcc<=54 )
00450     {
00451       ism = idcc-46+7;
00452       if( ism>9 ) ism-=9;
00453     }
00454   else
00455     abort();
00456   return ism;
00457 }
00458 
00459 TGraph*
00460 MEEEGeom::getGraphBoundary(  int type, int num, int iz, int xside )
00461 {
00462   std::list< std::pair< float, float > > l;
00463   getBoundary( l, type, num, iz, xside );
00464   int n = l.size();
00465   if( n==0 ) return 0;
00466   
00467   // GHM : changed to comply to CMSSW compilator options
00468   float ix[1000];
00469   float iy[1000];
00470   assert( n<1000 );
00471 
00472   int ii=0;
00473   std::list< std::pair< float, float > >::const_iterator l_it;      
00474   for( l_it=l.begin(); l_it!=l.end(); l_it++ )
00475     {
00476       //      std::cout << "[" << l_it->first << "," << l_it->second << "]" << std::endl;
00477       ix[ii] = l_it->first;
00478       iy[ii] = l_it->second;
00479       ii++;
00480     }
00481   assert( ii==n );
00482   return new TGraph( n, ix, iy );
00483 }
00484 
00485 void
00486 MEEEGeom::getBoundary(  std::list< std::pair< float, float > >& l, int type, int num, int iz, int xside )
00487 {
00488   // for each iy, get first and last ix for <whatever>
00489   std::multimap< int, std::pair< int, int > > map_;
00490 
00491   int iymin=1;
00492   int iymax=100;
00493   int ixmin=1;
00494   int ixmax=100;
00495   if( xside==1 ) 
00496     {
00497       ixmin=1; ixmax=50;
00498     } 
00499   if( xside==2 ) 
00500     {
00501       ixmin=51; ixmax=100;
00502     } 
00503 
00504   for( int iy=iymin; iy<=iymax; iy++ )
00505     {
00506       bool in=false;
00507       int firstix(0);
00508       int lastix(0);
00509       for( int ix=ixmin; ix<=ixmax; ix++ )
00510         {
00511           
00512           int icr = crystal( ix, iy );
00513           bool ok = icr>0;
00514 
00515           int iX = (ix-1)/5+1;
00516           int iY = (iy-1)/5+1;
00517 
00518           int num_(0);
00519           switch( type )
00520             {
00521             case iDee:
00522               num_ = dee( iX, iY, iz );   break;
00523             case iQuadrant:
00524               num_ = quadrant( iX, iY );  break;
00525             case iSector: 
00526               num_ = sector( iX, iY );    break;
00527             case iLMRegion:
00528               num_ = lmr( iX, iY, iz );   break;
00529             case iLMModule:
00530               num_ = lmmod( iX, iY );     break;
00531             case iDCC:
00532               num_ = dcc( iX, iY, iz );   break;
00533             case iSuperCrystal:
00534               num_ = sc( iX, iY );        break;
00535             case iCrystal:
00536               num_ = crystal( ix, iy );   break;
00537             default:
00538               abort();
00539             };
00540           ok &= num_==num;
00541 
00542           if( !in && !ok ) continue;
00543           if(  in &&  ok ) 
00544             {
00545               lastix = ix;
00546               continue;
00547             }
00548           if( !in &&  ok )
00549             {
00550               in = true;
00551               firstix = ix;
00552             }
00553           else if(  in && !ok )
00554             {
00555               in = false;
00556               map_.insert( std::pair< int, std::pair<int, int> >( iy, std::pair<int,int>( firstix, lastix ) ) );
00557             }
00558         }
00559       if( in ) map_.insert( std::pair< int, std::pair<int, int> >( iy, std::pair<int,int>( firstix, lastix ) ) );
00560         
00561     }
00562 
00563   // clean the list
00564   l.clear();
00565 
00566   std::multimap< int, std::pair< int, int > >::const_iterator it;
00567   std::multimap< int, std::pair< int, int > >::const_iterator lastelement;
00568   std::list< std::pair< float, float > > rightl;
00569   for( int iy=1; iy<=100; iy++ )
00570     {
00571       it = map_.find(iy);
00572       if( it==map_.end() ) continue;
00573       int n_ =  map_.count( iy );
00574       //      std::cout << "n[" << iy << "]=" << n_ << std::endl;
00575       assert( n_==1 );  // fixme !
00576       
00577       lastelement = map_.upper_bound(iy);
00578       for( ; it!=lastelement; ++it )
00579         {
00580           std::pair<float,float> p_ = it->second;
00581           l.push_back(   std::pair<float,float>(   p_.first-0.5, iy-0.5 ) );
00582           l.push_back(   std::pair<float,float>(   p_.first-0.5, iy+0.5 )   );
00583           rightl.push_back( std::pair<float,float>(   p_.second+0.5, iy-0.5 )   );
00584           rightl.push_back( std::pair<float,float>(   p_.second+0.5, iy+0.5 )     );
00585           
00586         }
00587     }
00588   l.unique();
00589   rightl.unique();
00590   rightl.reverse();
00591 
00592   std::list< std::pair< float, float > >::const_iterator rightl_it;  
00593   for( rightl_it=rightl.begin(); rightl_it!=rightl.end(); rightl_it++ )
00594     {
00595       l.push_back( std::pair<float,float>( rightl_it->first, rightl_it->second ) );
00596     }
00597   l.push_back( *l.begin() );
00598 
00599 }
00600 
00601 int
00602 MEEEGeom::deeFromMem( int imem )
00603 {
00604   int imem_ = imem%600;
00605   int dee_(0);
00606   if( imem_==50 || imem_==51 ) dee_=1;
00607   else if( imem_==47 || imem_==46 ) dee_=2;
00608   else if( imem_==1  || imem_==2  ) dee_=3;
00609   else if( imem_==5  || imem_==6  ) dee_=4;
00610   else abort();
00611   return dee_;
00612 }
00613 
00614 std::pair< int, int > 
00615 MEEEGeom::pn( int dee, int ilmmod )
00616 {
00617   // table below
00618   // convention to be consistent with Marc's numbering
00619   // PNA = 100 + pn + 1
00620   // PNB = 200 + pn + 1
00621 
00622   // LMR=73 EE+7(646/0)
00623   // -- module 9     PNA=(647)106    PNB=(646)201
00624   // -- module 10    PNA=(647)103    PNB=(646)208
00625   // -- module 11    PNA=(647)103    PNB=(646)203
00626   // -- module 12    PNA=(647)101    PNB=(646)206
00627   // -- module 13    PNA=(647)104    PNB=(646)209
00628   // LMR=74 EE+8(647/0)
00629   // -- module 5     PNA=(647)105    PNB=(646)210
00630   // -- module 6     PNA=(647)110    PNB=(646)205
00631   // -- module 7     PNA=(647)107    PNB=(646)202
00632   // -- module 8     PNA=(647)105    PNB=(646)210
00633   // LMR=75 EE+9(648/0)
00634   // -- module 1     PNA=(647)110    PNB=(646)205
00635   // -- module 2     PNA=(647)107    PNB=(646)202
00636   // -- module 3     PNA=(647)105    PNB=(646)210
00637   // -- module 4     PNA=(647)105    PNB=(646)210
00638   // LMR=76 EE+1(649/0)
00639   // -- module 1     PNA=(650)102    PNB=(651)206
00640   // -- module 2     PNA=(650)102    PNB=(651)207
00641   // -- module 3     PNA=(650)103    PNB=(651)208
00642   // -- module 4     PNA=(650)104    PNB=(651)209
00643   // LMR=77 EE+2(650/0)
00644   // -- module 5     PNA=(650)103    PNB=(651)208
00645   // -- module 6     PNA=(650)102    PNB=(651)206
00646   // -- module 7     PNA=(650)102    PNB=(651)207
00647   // -- module 8     PNA=(650)104    PNB=(651)209
00648   // LMR=78 EE+3(651/0)
00649   // -- module 9     PNA=(650)106    PNB=(651)201
00650   // -- module 10    PNA=(650)107    PNB=(651)202
00651   // -- module 11    PNA=(650)108    PNB=(651)203
00652   // -- module 12    PNA=(650)109    PNB=(651)204
00653   // -- module 13    PNA=(650)110    PNB=(651)205
00654   // LMR=79 EE+4(652/0)
00655   // -- module 14    PNA=(650)108    PNB=(651)203
00656   // -- module 15    PNA=(650)106    PNB=(651)201
00657   // -- module 16    PNA=(650)107    PNB=(651)202
00658   // -- module 17    PNA=(650)110    PNB=(651)205
00659   // LMR=80 EE+5(653/0)
00660   // -- module 18    PNA=(650)105    PNB=(651)210
00661   // -- module 19    PNA=(650)109    PNB=(651)204
00662   // LMR=81 EE+5(653/1)
00663   // -- module 18    PNA=(647)101    PNB=(646)206
00664   // -- module 19    PNA=(647)101    PNB=(646)206
00665   // LMR=82 EE+6(654/0)
00666   // -- module 14    PNA=(647)108    PNB=(646)203
00667   // -- module 15    PNA=(647)106    PNB=(646)201
00668   // -- module 16    PNA=(647)103    PNB=(646)208
00669   // -- module 17    PNA=(647)104    PNB=(646)209
00670   // LMR=83 EE-7(601/0)
00671   // -- module 9     PNA=(601)108    PNB=(602)203
00672   // -- module 10    PNA=(601)105    PNB=(602)210
00673   // -- module 11    PNA=(601)106    PNB=(602)201
00674   // -- module 12    PNA=(601)110    PNB=(602)205
00675   // -- module 13    PNA=(601)110    PNB=(602)205
00676   // LMR=84 EE-8(602/0)
00677   // -- module 5     PNA=(601)103    PNB=(602)208
00678   // -- module 6     PNA=(601)101    PNB=(602)206
00679   // -- module 7     PNA=(601)101    PNB=(602)206
00680   // -- module 8     PNA=(601)103    PNB=(602)209
00681   // LMR=85 EE-9(603/0)
00682   // -- module 1     PNA=(601)101    PNB=(602)206
00683   // -- module 2     PNA=(601)101    PNB=(602)206
00684   // -- module 3     PNA=(601)103    PNB=(602)208
00685   // -- module 4     PNA=(601)103    PNB=(602)209
00686   // LMR=86 EE-1(604/0)
00687   // -- module 1     PNA=(605)105    PNB=(606)210
00688   // -- module 2     PNA=(605)102    PNB=(606)207
00689   // -- module 3     PNA=(605)102    PNB=(606)207
00690   // -- module 4     PNA=(605)110    PNB=(606)205
00691   // LMR=87 EE-2(605/0)
00692   // -- module 5     PNA=(605)105    PNB=(606)210
00693   // -- module 6     PNA=(605)105    PNB=(606)210
00694   // -- module 7     PNA=(605)102    PNB=(606)207
00695   // -- module 8     PNA=(605)110    PNB=(606)205
00696   // LMR=88 EE-3(606/0)
00697   // -- module 9     PNA=(605)101    PNB=(606)206
00698   // -- module 10    PNA=(605)108    PNB=(606)203
00699   // -- module 11    PNA=(605)103    PNB=(606)208
00700   // -- module 12    PNA=(605)106    PNB=(606)201
00701   // -- module 13    PNA=(605)109    PNB=(606)204
00702   // LMR=89 EE-4(607/0)
00703   // -- module 14    PNA=(605)103    PNB=(606)208
00704   // -- module 15    PNA=(605)101    PNB=(606)206
00705   // -- module 16    PNA=(605)108    PNB=(606)203
00706   // -- module 17    PNA=(605)109    PNB=(606)204
00707   // LMR=90 EE-5(608/0)
00708   // -- module 18    PNA=(605)106    PNB=(606)201
00709   // -- module 19    PNA=(605)106    PNB=(606)201
00710   // LMR=91 EE-5(608/1)
00711   // -- module 18    PNA=(601)107    PNB=(602)202
00712   // -- module 19    PNA=(601)110    PNB=(602)205
00713   // LMR=92 EE-6(609/0)
00714   // -- module 14    PNA=(601)106    PNB=(602)201
00715   // -- module 15    PNA=(601)108    PNB=(602)203
00716   // -- module 16    PNA=(601)105    PNB=(602)210
00717   // -- module 17    PNA=(601)105    PNB=(602)210
00718 
00719   if( ilmmod==20 ) ilmmod=18;
00720   if( ilmmod==21 ) ilmmod=19;
00721 
00722   std::pair<int,int> pns(0,0);
00723 
00724   if( pnTheory )
00725     {
00726       switch( ilmmod )
00727         {
00728         case   1: pns.first=0; pns.second=5; break;
00729         case   2: pns.first=1; pns.second=6; break;
00730         case   3: pns.first=2; pns.second=7; break;
00731         case   4: pns.first=3; pns.second=8; break;
00732         case   5: pns.first=2; pns.second=7; break;
00733         case   6: pns.first=0; pns.second=5; break;
00734         case   7: pns.first=1; pns.second=6; break;
00735         case   8: pns.first=3; pns.second=8; break;
00736         case   9: pns.first=5; pns.second=0; break;
00737         case  10: pns.first=6; pns.second=1; break;
00738         case  11: pns.first=7; pns.second=2; break;
00739         case  12: pns.first=8; pns.second=3; break;
00740         case  13: pns.first=9; pns.second=4; break;
00741         case  14: pns.first=7; pns.second=2; break;
00742         case  15: pns.first=5; pns.second=0; break;
00743         case  16: pns.first=6; pns.second=1; break;
00744         case  17: pns.first=9; pns.second=4; break; 
00745         case  18: pns.first=4; pns.second=9; break;
00746         case  19: pns.first=8; pns.second=3; break;
00747         default:
00748           abort();
00749         };
00750     }
00751   else
00752     {
00753       // theoretical ~ dee 1
00754       if( dee==1 )
00755         {
00756           switch( ilmmod )
00757             {
00758               //        case   1: pns.first=0; pns.second=5; break;
00759             case   1: pns.first=1; pns.second=5; break; // missing PNA
00760             case   2: pns.first=1; pns.second=6; break;
00761             case   3: pns.first=2; pns.second=7; break;
00762             case   4: pns.first=3; pns.second=8; break;
00763             case   5: pns.first=2; pns.second=7; break;
00764               //        case   6: pns.first=0; pns.second=5; break;
00765             case   6: pns.first=1; pns.second=5; break; // missing PNA
00766             case   7: pns.first=1; pns.second=6; break;
00767             case   8: pns.first=3; pns.second=8; break;
00768             case   9: pns.first=5; pns.second=0; break;
00769             case  10: pns.first=6; pns.second=1; break;
00770             case  11: pns.first=7; pns.second=2; break;
00771             case  12: pns.first=8; pns.second=3; break;
00772             case  13: pns.first=9; pns.second=4; break;
00773             case  14: pns.first=7; pns.second=2; break;
00774             case  15: pns.first=5; pns.second=0; break;
00775             case  16: pns.first=6; pns.second=1; break;
00776             case  17: pns.first=9; pns.second=4; break; 
00777             case  18: pns.first=4; pns.second=9; break;
00778             case  19: pns.first=8; pns.second=3; break;
00779             default:
00780               abort();
00781             };
00782         }
00783       else if( dee==2 )
00784         {
00785           switch( ilmmod )
00786             {
00787             case   1: pns.first=9; pns.second=4; break;
00788             case   2: pns.first=6; pns.second=1; break;
00789               //        case   3: pns.first=2; pns.second=7; break;
00790             case   3: pns.first=4; pns.second=9; break;  // missing PNA & PNB
00791             case   4: pns.first=4; pns.second=9; break;
00792               //        case   5: pns.first=2; pns.second=7; break;
00793             case   5: pns.first=4; pns.second=9; break;  // missing PNA & PNB
00794             case   6: pns.first=9; pns.second=4; break;
00795             case   7: pns.first=6; pns.second=1; break;
00796             case   8: pns.first=4; pns.second=9; break;
00797             case   9: pns.first=5; pns.second=0; break;
00798             case  10: pns.first=2; pns.second=7; break;
00799               //        case  11: pns.first=7; pns2second=2; break;
00800             case  11: pns.first=2; pns.second=2; break;  // PNA - fibre cassee
00801             case  12: pns.first=0; pns.second=5; break;
00802             case  13: pns.first=3; pns.second=8; break;
00803             case  14: pns.first=7; pns.second=2; break;
00804             case  15: pns.first=5; pns.second=0; break;
00805             case  16: pns.first=2; pns.second=7; break;
00806             case  17: pns.first=3; pns.second=8; break; 
00807               //        case  18: pns.first=4; pns.second=9; break;
00808             case  18: pns.first=0; pns.second=5; break; // missing PNA & PNB
00809             case  19: pns.first=0; pns.second=5; break;
00810             default:
00811               abort();
00812             };
00813         }
00814       else if( dee==3 )
00815         {
00816           switch( ilmmod )
00817             {
00818             case   1: pns.first=0; pns.second=5; break;
00819               //        case   2: pns.first=0; pns.second=1; break;
00820             case   2: pns.first=0; pns.second=5; break;  // missing PNA & PNB
00821             case   3: pns.first=2; pns.second=7; break;
00822               //        case   4: pns.first=4; pns.second=9; break;
00823             case   4: pns.first=2; pns.second=8; break; // missing PNA
00824             case   5: pns.first=2; pns.second=7; break;
00825             case   6: pns.first=0; pns.second=5; break;
00826               //        case   7: pns.first=6; pns.second=1; break;
00827             case   7: pns.first=0; pns.second=5; break;  // missing PNA & PNB 
00828               //        case   8: pns.first=4; pns.second=9; break;
00829             case   8: pns.first=2; pns.second=8; break;  // missing PNA
00830             case   9: pns.first=7; pns.second=2; break;
00831             case  10: pns.first=4; pns.second=9; break;
00832             case  11: pns.first=5; pns.second=0; break;
00833             case  12: pns.first=9; pns.second=4; break;
00834               //        case  13: pns.first=3; pns.second=8; break;
00835             case  13: pns.first=9; pns.second=4; break;  // missing PNA & PNB 
00836             case  14: pns.first=5; pns.second=0; break;
00837             case  15: pns.first=7; pns.second=2; break;
00838             case  16: pns.first=4; pns.second=9; break;
00839               //        case  17: pns.first=3; pns.second=8; break; 
00840             case  17: pns.first=4; pns.second=9; break;  // missing PNA & PNB 
00841             case  18: pns.first=6; pns.second=1; break;
00842             case  19: pns.first=9; pns.second=4; break;
00843             default:
00844               abort();
00845             };
00846         }
00847       else if( dee==4 )
00848         {
00849           switch( ilmmod )
00850             {
00851             case   1: pns.first=4; pns.second=9; break;
00852             case   2: pns.first=1; pns.second=6; break;
00853               //        case   3: pns.first=6; pns.second=1; break;
00854             case   3: pns.first=1; pns.second=6; break;  // missing PNA & PNB
00855             case   4: pns.first=9; pns.second=4; break;
00856               //        case   5: pns.first=4; pns.second=9; break;
00857             case   5: pns.first=4; pns.second=9; break;  // missing PNA & PNB
00858             case   6: pns.first=4; pns.second=9; break;
00859             case   7: pns.first=1; pns.second=6; break;
00860             case   8: pns.first=9; pns.second=4; break;
00861             case   9: pns.first=0; pns.second=5; break;
00862             case  10: pns.first=7; pns.second=2; break;
00863             case  11: pns.first=2; pns.second=7; break;
00864             case  12: pns.first=5; pns.second=0; break;
00865             case  13: pns.first=8; pns.second=3; break;
00866             case  14: pns.first=2; pns.second=7; break;
00867             case  15: pns.first=0; pns.second=5; break;
00868             case  16: pns.first=7; pns.second=2; break;
00869             case  17: pns.first=8; pns.second=3; break; 
00870               //        case  18: pns.first=9; pns.second=4; break;
00871             case  18: pns.first=5; pns.second=0; break; // missing PNA & PNB
00872             case  19: pns.first=5; pns.second=0; break;
00873             default:
00874               abort();
00875             };
00876         }
00877     }  
00878   return pns;
00879 }
00880 
00881 int
00882 MEEEGeom::dee( int ilmr )
00883 { 
00884   int dee_(0);
00885   int i_[7] = { 73 , 76 , 81 , 83 , 86 , 91 , 93 };
00886   int d_[6] = {    2 ,  1 ,  2 ,  3 ,  4 ,  3    };  
00887   for( int ii=0; ii<6; ii ++ )
00888   {
00889     if( ilmr>=i_[ii] && ilmr <i_[ii+1] ) 
00890       {
00891         dee_=d_[ii];
00892         break;
00893       }
00894   }
00895   if( dee_==0 )
00896     {
00897       std::cout << "ilmr=" << ilmr << std::endl;
00898     }
00899   assert( dee_!=0 );
00900   return dee_;
00901 }
00902 
00903 std::pair< int, int >
00904 MEEEGeom::memFromLmr( int ilmr )
00905 {
00906   std::pair< int, int > out_;
00907   int dee_ = dee( ilmr );
00908   if( dee_==1 )    // EE+F
00909     {
00910       out_.first  = 50;
00911       out_.second = 51;
00912     }
00913   else if( dee_==2 )  // EE+N
00914     {
00915       out_.first  = 47;  // JM: warning -- inverted !!
00916       out_.second = 46;
00917     }
00918   else if( dee_==3 )  // EE-N
00919     {
00920       out_.first   = 1;
00921       out_.second  = 2;
00922     }
00923   else if( dee_==4 )
00924     {
00925       out_.first   = 5;
00926       out_.second  = 6;
00927     }
00928   return out_;
00929 }
00930 
00931 bool
00932 MEEEGeom::near( int ilmr )
00933 {
00934   int idee  = dee( ilmr );
00935   return ( idee==2 || idee==3 );  
00936 }
00937 
00938 int 
00939 MEEEGeom::side( SuperCrysCoord iX, SuperCrysCoord iY, int iz )
00940 {
00941   int side = 0;
00942   int ilmr = lmr( iX, iY, iz );
00943   if ( ilmr == 81 || ilmr == 91 ) side=1;
00944 
00945   return side;
00946 }
00947 std::vector<int>
00948 MEEEGeom::lmmodFromLmr( int ilmr )
00949 {
00950  
00951   std::vector<int> vec;
00952  
00953   std::pair<int, int> dccAndSide_ = ME::dccAndSide( ilmr );
00954   int idcc  = dccAndSide_.first;
00955   int iside = dccAndSide_.second;
00956   bool near_ = near(ilmr);
00957   int ism   = smFromDcc( idcc );
00958   if( ism>9 ) ism-=9;
00959   assert( iside==0 || ism==5 );
00960   if ( ism==5 || (ism<5 && !near_) || (ism>5 && near_) )
00961     {}
00962   else
00963     {
00964       std::cout << "ism/near " <<  ism << "/" << near_ << std::endl;
00965     }
00966 
00967   if( ism==1 || ism==9 )
00968     {
00969       vec.push_back(1);
00970       vec.push_back(2);
00971       vec.push_back(3);
00972       vec.push_back(4);
00973     }
00974   else if( ism==2 || ism==8 )
00975     {
00976       vec.push_back(5);
00977       vec.push_back(6);
00978       vec.push_back(7);
00979       vec.push_back(8);
00980     }
00981   else if( ism==3 || ism==7 )
00982     {
00983       vec.push_back(9);
00984       vec.push_back(10);
00985       vec.push_back(11);
00986       vec.push_back(12);
00987       vec.push_back(13);
00988     }
00989   else if( ism==4 || ism==6 )
00990     {
00991       vec.push_back(14);
00992       vec.push_back(15);
00993       vec.push_back(16);
00994       vec.push_back(17);
00995     }
00996   else
00997     {
00998       assert( ism==5 );
00999       vec.push_back(18);
01000       vec.push_back(19);
01001     }
01002   return vec;
01003 }
01004 
01005 int
01006 MEEEGeom::apdRefTower( int ilmr, int ilmmod )
01007 {
01008   int ilmr10=ilmr%10;
01009   int tower=0;
01010 
01011   if( ilmr10==3 ){      
01012     switch( ilmmod ){
01013     case   9:  tower=77; break;
01014     case   10: tower=55; break;
01015     case   11: tower=37; break;
01016     case   12: tower=310; break;
01017     case   13: tower=294; break;
01018     default:
01019       abort();
01020     }
01021   }else if( ilmr10==4 ){
01022     switch( ilmmod ){
01023     case   5: tower=52; break;
01024     case   6: tower=41; break;
01025     case   7: tower=18; break;
01026     case   8: tower=65; break;
01027     default:
01028       abort();
01029     }
01030   }else if( ilmr10==5 ){
01031     
01032     switch( ilmmod ){
01033     case   1: tower=45; break;
01034     case   2: tower=53; break; 
01035     case   3: tower=42; break;
01036     case   4: tower=32; break; 
01037     default:
01038       abort();
01039     }
01040   }else if( ilmr10==6 ){ 
01041     switch( ilmmod ){
01042     case   1: tower=124; break;
01043     case   2: tower=132; break;
01044     case   3: tower=121; break;
01045     case   4: tower=111; break;
01046     default:
01047       abort();
01048     }
01049   }else if( ilmr10==7 ){ 
01050     switch( ilmmod ){
01051     case   5: tower=147; break;
01052     case   6: tower=135; break;
01053     case   7: tower=117; break;
01054     case   8: tower=158; break; 
01055     default:
01056       abort();
01057     }
01058     
01059   }else if( ilmr10==8 ){ 
01060     switch( ilmmod ){
01061     case   9: tower=156; break;
01062     case  10: tower=214; break;
01063     case  11: tower=197; break;
01064     case  12: tower=237; break; 
01065     case  13: tower=224; break; 
01066     default:
01067       abort();
01068     }  
01069   }else if( ilmr10==9 ){ 
01070     switch( ilmmod ){
01071     case  14: tower=234; break; 
01072     case  15: tower=220; break;
01073     case  16: tower=212; break; 
01074     case  17: tower=189; break;
01075     default:
01076       abort();
01077     } 
01078   }else if( ilmr10==0 ){ 
01079     switch( ilmmod ){
01080     case  18: tower=185; break; 
01081     case  19: tower=172; break;
01082     default:
01083       abort();
01084     }
01085   }else if( ilmr10==1 ){ 
01086     switch( ilmmod ){
01087     case  18: tower=264; break; 
01088     case  19: tower=251; break;
01089     default:
01090       abort();
01091     }
01092   }
01093   return tower; 
01094 }
01095 
01096 std::vector< int>
01097 MEEEGeom::apdRefChannels( int ilmmod )
01098 {
01099 
01100   std::vector< int> vec;
01101   switch( ilmmod )
01102     {
01103     case   1: vec.push_back(0); vec.push_back(1); break;
01104     case   2: vec.push_back(0); vec.push_back(1); break;
01105     case   3: vec.push_back(0); vec.push_back(1); break;
01106     case   4: vec.push_back(0); vec.push_back(1); break;
01107     case   5: vec.push_back(0); vec.push_back(1); break;
01108     case   6: vec.push_back(0); vec.push_back(1); break;
01109     case   7: vec.push_back(0); vec.push_back(1); break;
01110     case   8: vec.push_back(0); vec.push_back(1); break;
01111     case   9: vec.push_back(0); vec.push_back(1); break;
01112     case  10: vec.push_back(0); vec.push_back(1); break;
01113     case  11: vec.push_back(0); vec.push_back(1); break;
01114     case  12: vec.push_back(0); vec.push_back(1); break;
01115     case  13: vec.push_back(0); vec.push_back(1); break;
01116     case  14: vec.push_back(0); vec.push_back(1); break;
01117     case  15: vec.push_back(0); vec.push_back(1); break;
01118     case  16: vec.push_back(0); vec.push_back(1); break;
01119     case  17: vec.push_back(0); vec.push_back(1); break;
01120     case  18: vec.push_back(0); vec.push_back(1); break;
01121     case  19: vec.push_back(0); vec.push_back(1); break;
01122     case  20: vec.push_back(0); vec.push_back(1); break;
01123     case  21: vec.push_back(0); vec.push_back(1); break;
01124 
01125     default:
01126       abort();
01127     }
01128   return vec;
01129 }
01130