CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/CalibCalorimetry/EcalLaserAnalyzer/src/MEEBGeom.cc

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <stdlib.h>
00003 #include <string>
00004 #include <assert.h>
00005 using namespace std;
00006 
00007 #include "CalibCalorimetry/EcalLaserAnalyzer/interface/ME.h"
00008 #include "CalibCalorimetry/EcalLaserAnalyzer/interface/MEEBGeom.h"
00009 
00010 #include <TGraph.h>
00011 
00012 //GHM ClassImp(MEEBGeom)
00013 
00014 int 
00015 MEEBGeom::barrel( EBGlobalCoord ieta, EBGlobalCoord iphi )
00016 {
00017   int iz=1;
00018   if( ieta<0 ) iz=-1;
00019   ieta *= iz;
00020   assert( ieta>0 && ieta<=85 );
00021   if( iphi<0 ) iphi+=360;
00022   assert( iphi>0 && iphi<=360 );
00023   return iz;
00024 }
00025 
00026 int 
00027 MEEBGeom::sm( EBGlobalCoord ieta, EBGlobalCoord iphi )
00028 {
00029   int iz=1;
00030   if( ieta<0 ) iz=-1;
00031   ieta *= iz;
00032   assert( ieta>0 && ieta<=85 );
00033 
00034   //  int iphi_ = iphi+10;
00035   int iphi_ = iphi;
00036   if( iphi_>360 ) iphi_-=360;
00037   assert( iphi_>0 && iphi_<=360 );
00038 
00039   int ism = (iphi_-1)/20 + 1;
00040   assert( ism>=1 && ism<=18 );
00041   //  if( iz==1 ) ism += 18;
00042   if( iz==-1 ) ism += 18;
00043 
00044   return ism;
00045 }
00046 
00047 int 
00048 MEEBGeom::dcc( EBGlobalCoord ieta, EBGlobalCoord iphi )
00049 {
00050   int ism = sm( ieta, iphi );
00051   return dccFromSm( ism );
00052 }
00053 
00054 int
00055 MEEBGeom::dccFromSm( int ism )
00056 {
00057   assert( ism>=1 && ism<=36 );
00058   int iz=1;
00059   if( ism>18 ) iz=-1;
00060   if( iz==-1  ) ism-=18;
00061   assert( ism>=1 && ism<=18 );
00062   int idcc = 9+ism;
00063   if( iz==+1  ) idcc+=18;
00064   return idcc;
00065 }
00066 
00067 int
00068 MEEBGeom::smFromDcc( int idcc )
00069 {
00070   if( idcc>600 ) idcc-=600;  // also works with FEDids
00071   assert( idcc>=10 && idcc<=45 );
00072   int ism=idcc-9;
00073   if( ism>18 ) ism-=18;
00074   else         ism+=18;
00075   return ism;
00076 }
00077 
00078 TString
00079 MEEBGeom::smName( int ism )
00080 {
00081   assert( ism>=1 && ism<=36 );
00082   TString out = "EB+";
00083   if( ism>18 )
00084     {
00085       out = "EB-";
00086       ism -= 18;
00087     }
00088   out += ism;
00089   return out;
00090 }
00091 
00092 int 
00093 MEEBGeom::lmmod( EBGlobalCoord ieta, EBGlobalCoord iphi )
00094 {
00095   std::pair<EBLocalCoord,EBLocalCoord> ixy = localCoord( ieta, iphi );
00096   return lm_channel( ixy.first/5, ixy.second/5 );
00097 }
00098 
00099 int 
00100 MEEBGeom::tt( EBGlobalCoord ieta, EBGlobalCoord iphi )
00101 {
00102   std::pair<EBLocalCoord,EBLocalCoord> ixy = localCoord( ieta, iphi );
00103   return tt_channel( ixy.first/5, ixy.second/5 );
00104 }
00105 
00106 int 
00107 MEEBGeom::crystal( EBGlobalCoord ieta, EBGlobalCoord iphi )
00108 {
00109   std::pair<EBLocalCoord,EBLocalCoord> ixy = localCoord( ieta, iphi );
00110   return crystal_channel( ixy.first, ixy.second );
00111 }
00112 
00113 int 
00114 MEEBGeom::side( EBGlobalCoord ieta, EBGlobalCoord iphi )
00115 {
00116   int ilmmod = lmmod( ieta, iphi );
00117   return (ilmmod%2==0)?1:0;
00118 }
00119 
00120 int 
00121 MEEBGeom::lmr( EBGlobalCoord ieta, EBGlobalCoord iphi )
00122 {
00123   int idcc  = dcc( ieta, iphi );
00124   int ism   = idcc-9;
00125   int iside = side( ieta, iphi );
00126   int ilmr = 1 + 2*(ism-1) + iside;
00127   return ilmr;
00128 }
00129 
00130 std::pair< MEEBGeom::EBLocalCoord, MEEBGeom::EBLocalCoord >    
00131 MEEBGeom::localCoord( MEEBGeom::EBGlobalCoord ieta, MEEBGeom::EBGlobalCoord iphi )
00132 {
00133   int iz=1;
00134   if( ieta<0 ) iz=-1;
00135   ieta *= iz;
00136   assert( ieta>0 && ieta<=85 );
00137 
00138   //  int iphi_ = iphi+10;
00139   int iphi_ = iphi;
00140   if( iphi_>360 ) iphi_-=360;
00141   assert( iphi_>0 && iphi_<=360 );
00142 
00143   int ix = ieta-1;
00144   
00145   int iy = (iphi_-1)%20;
00146   if( iz==-1 ) iy = 19-iy;
00147   // if( iz==1 ) iy = 19-iy;
00148 
00149   return std::pair< EBLocalCoord, EBLocalCoord >(ix,iy);  
00150 }
00151 
00152 std::pair< MEEBGeom::EBLocalCoord, MEEBGeom::EBLocalCoord >    
00153 MEEBGeom::localCoord( int icr )
00154 {
00155   assert( icr>=1 && icr<=1700 );
00156   int ix = (icr-1)/20;
00157   int iy = 19 - (icr-1)%20;
00158   return std::pair< EBLocalCoord, EBLocalCoord >(ix,iy);  
00159 }
00160 
00161 std::pair< MEEBGeom::EBGlobalCoord, MEEBGeom::EBGlobalCoord >    
00162 MEEBGeom::globalCoord( int ism, MEEBGeom::EBLocalCoord ix, MEEBGeom::EBLocalCoord iy )
00163 {
00164   assert( ism>=1 && ism<=36 );
00165   assert( ix>=0 && ix<85 );
00166   assert( iy>=0 && iy<20 );
00167   //  int iz=-1;
00168   int iz=1;
00169   if( ism>18 ) 
00170     {
00171       iz=-1;
00172       ism -= 18;
00173     }
00174   if( iz==-1 ) iy = 19-iy;
00175   // if( iz==1 ) iy = 19-iy;
00176 
00177   int ieta = ix+1;
00178   ieta *= iz;
00179   //  int iphi = -9 + iy + 20*(ism-1);
00180   int iphi = 1 + iy + 20*(ism-1);
00181 
00182   return std::pair< EBGlobalCoord, EBGlobalCoord >(ieta,iphi);  
00183 }
00184 
00185 std::pair< float, float >    
00186 MEEBGeom::globalCoord( int ism, float x, float y )
00187 {
00188   assert( ism>=1 && ism<=36 );
00189   int iz=1;
00190   if( ism>18 ) 
00191     {
00192       iz=-1;
00193       ism -= 18;
00194     }
00195   if( iz==-1 ) y = 19-y;
00196 
00197   float eta = x+1;
00198   eta *= iz;
00199   //  float phi = -9 + y + 20*(ism-1);
00200   float phi = 1 + y + 20*(ism-1);
00201 
00202   return std::pair< float, float >(eta,phi);  
00203 }
00204 
00205 std::pair< MEEBGeom::EBGlobalCoord, MEEBGeom::EBGlobalCoord >    
00206 MEEBGeom::globalCoord( int ism, int icr )
00207 {
00208   assert( ism>=1 && ism<=36 );
00209   assert( icr>=1 && icr<=1700 );
00210 
00211   int ix = (icr-1)/20;
00212   int iy = 19 - (icr-1)%20;
00213 
00214   return globalCoord( ism, ix, iy );  
00215 }
00216 
00217 int 
00218 MEEBGeom::lm_channel( EBTTLocalCoord iX, EBTTLocalCoord iY )
00219 {
00220   static const int 
00221     idx_[] = 
00222     {
00223      // 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16
00224         1, 2, 2, 2, 2, 4, 4, 4, 4, 6, 6, 6, 6, 8, 8, 8, 8, // 3
00225         1, 2, 2, 2, 2, 4, 4, 4, 4, 6, 6, 6, 6, 8, 8, 8, 8, // 2
00226         1, 3, 3, 3, 3, 5, 5, 5, 5, 7, 7, 7, 7, 9, 9, 9, 9, // 1
00227         1, 3, 3, 3, 3, 5, 5, 5, 5, 7, 7, 7, 7, 9, 9, 9, 9  // 0
00228      // 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16
00229      };
00230 
00231   int iym, ixm, il, ic, ii;
00232   iym=4;
00233   ixm=17;
00234   int iX_ = iX+1;
00235   int iY_ = iY+1;
00236   il=iym-iY_;
00237   ic=iX_-1;
00238   ii=il*ixm+ic;
00239   if(ii < 0 || ii > (int)(sizeof(idx_)/sizeof(int))) { return -1; };
00240   return idx_[ii];
00241 }
00242 
00243 int 
00244 MEEBGeom::tt_type( EBTTLocalCoord iX, EBTTLocalCoord iY )
00245 {
00246   static const int 
00247     idx_[] =
00248     {
00249      // 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16
00250         1, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, // 3
00251         1, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, // 2
00252         1, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, // 1
00253         1, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2  // 0
00254      // 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16
00255      };
00256 
00257   int iym, ixm, il, ic, ii;
00258   iym=4;
00259   ixm=17;
00260   int iX_ = iX+1;
00261   int iY_ = iY+1;
00262   il=iym-iY_;
00263   ic=iX_-1;
00264   ii=il*ixm+ic;
00265   if(ii < 0 || ii > (int)(sizeof(idx_)/sizeof(int))) { return -1; };
00266   return idx_[ii];
00267 }
00268 
00269 int
00270 MEEBGeom::hv_channel( EBTTLocalCoord iX, EBTTLocalCoord iY )
00271 {
00272   static const int 
00273     idx_[] = 
00274     {
00275      // 0  1  2  3   4   5   6   7   8   9  10  11  12  13  14  15  16
00276         1, 3, 5, 7,  9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, // 3
00277         1, 3, 5, 7,  9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, // 2
00278         2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, // 1
00279         2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34  // 0
00280      // 0  1  2  3   4   5   6   7   8   9  10  11  12  13  14  15  16
00281      };
00282 
00283   int iym, ixm, il, ic, ii;
00284   iym=4;
00285   ixm=17;
00286   int iX_ = iX+1;
00287   int iY_ = iY+1;
00288   il=iym-iY_;
00289   ic=iX_-1;
00290   ii=il*ixm+ic;
00291   if(ii < 0 || ii > (int)(sizeof(idx_)/sizeof(int))) { return -1; };
00292   return idx_[ii];
00293 }
00294 
00295 int
00296 MEEBGeom::lv_channel( EBTTLocalCoord iX, EBTTLocalCoord iY )
00297 {
00298   static const int
00299     idx_[] =
00300     {
00301      // 0  1  2  3  4  5  6  7  8   9  10  11  12  13  14  15  16
00302         1, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14, 16, 16, // 3
00303         1, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14, 16, 16, // 2
00304         1, 3, 3, 5, 5, 7, 7, 9, 9, 11, 11, 13, 13, 15, 15, 17, 17, // 1
00305         1, 3, 3, 5, 5, 7, 7, 9, 9, 11, 11, 13, 13, 15, 15, 17, 17  // 0
00306      // 0  1  2  3  4  5  6  7  8   9  10  11  12  13  14  15  16
00307      };
00308 
00309   int iym, ixm, il, ic, ii;
00310   iym=4;
00311   ixm=17;
00312   int iX_ = iX+1;
00313   int iY_ = iY+1;
00314   il=iym-iY_;
00315   ic=iX_-1;
00316   ii=il*ixm+ic;
00317   if(ii < 0 || ii > (int)(sizeof(idx_)/sizeof(int))) { return -1; };
00318   return idx_[ii];
00319 }
00320 
00321 int 
00322 MEEBGeom::tt_channel( EBTTLocalCoord iX, EBTTLocalCoord iY )
00323 {
00324 
00325   int itt =  4*iX+4-iY;  // :)
00326 
00327   return itt;
00328 
00329 }
00330 
00331 int 
00332 MEEBGeom::crystal_channel( EBLocalCoord ix, EBLocalCoord iy )
00333 {
00334   // "Test beam numbering"
00335   int icr =  20*ix + 19-iy + 1;  // :)
00336 
00337   return icr;
00338 }
00339 
00340 int 
00341 MEEBGeom::electronic_channel( EBLocalCoord ix, EBLocalCoord iy )
00342 {
00343   int iX = ix/5;
00344   int iY = iy/5;
00345   int itt  = tt_channel( iX, iY );
00346   int type = tt_type( iX, iY );
00347 
00348   int iVFE = ix%5+1;
00349   int islot = iy%5+1;
00350   if( iVFE%2==1 ) islot = 6-islot;
00351   int icr = 5*(iVFE-1)+(islot-1);
00352   // rotate for type-1 towers
00353   if( type==1 )
00354     {
00355       icr = 24-icr;
00356     }
00357   icr += 25*(itt-1);
00358 
00359   return icr;
00360 }
00361 
00362 TGraph*
00363 MEEBGeom::getGraphBoundary(  int type, int num, bool global )
00364 {
00365   int ism_=0;
00366   if( type==iSuperModule )
00367     {
00368       ism_ = num; 
00369     }
00370   else if( type==iLMRegion )
00371     {
00372       ism_ = (num-1)/2+1;
00373       if( ism_>18 ) 
00374         ism_-=18;
00375       else
00376         ism_+=18;
00377     }
00378   else
00379       abort();
00380 
00381   int ism=1;
00382   if( global ) ism = ism_;
00383 
00384   //  std::list< std::pair< float, float > > l;
00385   // getBoundary( l, type, num, global, ism );
00386   //  int n = l.size();
00387   //  if( n==0 ) return 0;
00388   
00389   float ix[100];
00390   float iy[100];
00391   int ixmin =  0;
00392   int ixmax = 84;
00393   int iymin =  0;
00394   int iymax = 19;
00395 
00396   int n(0);
00397   if( type==iSuperModule )
00398     {
00399       n=5;
00400       ix[0] = ixmin-0.5;
00401       iy[0] = iymin-0.5;
00402       ix[1] = ixmin-0.5;
00403       iy[1] = iymax+0.5;
00404       ix[2] = ixmax+0.5;
00405       iy[2] = iymax+0.5;
00406       ix[3] = ixmax+0.5;
00407       iy[3] = iymin-0.5;
00408       ix[4] = ix[0];
00409       iy[4] = iy[0];
00410     }
00411   else if( type==iLMRegion )
00412     {
00413       int iside = num;
00414       if( global )
00415         {
00416           iside = (num-1)%2;
00417         }
00418       
00419       if( iside==1 )
00420         {
00421           n=5;
00422           ix[0] = ixmin+5-0.5;
00423           iy[0] = iymin+10-0.5;
00424           ix[1] = ixmin+5-0.5;
00425           iy[1] = iymax+0.5;
00426           ix[2] = ixmax+0.5;
00427           iy[2] = iymax+0.5;
00428           ix[3] = ixmax+0.5;
00429           iy[3] = iymin+10-0.5;
00430           ix[4] = ix[0];
00431           iy[4] = iy[0];
00432         }
00433       else
00434         {
00435           n=7;
00436           ix[0] = ixmin-0.5;
00437           iy[0] = iymin-0.5;
00438           ix[1] = ixmin-0.5;
00439           iy[1] = iymax+0.5;
00440           ix[2] = ixmin+5-0.5;
00441           iy[2] = iymax+0.5;
00442           ix[3] = ixmin+5-0.5;
00443           iy[3] = iymax-10+0.5;
00444           ix[4] = ixmax+0.5;
00445           iy[4] = iymax-10+0.5;
00446           ix[5] = ixmax+0.5;
00447           iy[5] = iymin-0.5;
00448           ix[6] = ix[0];
00449           iy[6] = iy[0];
00450         }
00451     }
00452 
00453   if( global )
00454     {
00455       for( int ii=0; ii<n; ii ++ )
00456         {
00457           std::pair<float,float> xy = globalCoord( ism, ix[ii], iy[ii] ); 
00458           ix[ii] = xy.first;
00459           iy[ii] = xy.second;
00460         }
00461     }
00462 
00463 //   int ii=0;
00464 //   std::list< std::pair< float, float > >::const_iterator l_it;      
00465 //   for( l_it=l.begin(); l_it!=l.end(); l_it++ )
00466 //     {
00467 //       //      std::cout << "[" << l_it->first << "," << l_it->second << "]" << std::endl;
00468 //       ix[ii] = l_it->first;
00469 //       iy[ii] = l_it->second;
00470 //       ii++;
00471 //     }
00472 
00473 
00474 //  assert( ii==n );
00475   return new TGraph( n, ix, iy );
00476 }
00477 
00478 std::pair< int, int >
00479 MEEBGeom::pn( int ilmmod )
00480 {
00481   switch( ilmmod )
00482     {
00483     case   1: return std::pair<int,int>(  0,  5 );
00484     case   2: return std::pair<int,int>(  1,  6 );
00485     case   3: return std::pair<int,int>(  1,  6 );
00486     case   4: return std::pair<int,int>(  2,  7 );
00487     case   5: return std::pair<int,int>(  2,  7 );
00488     case   6: return std::pair<int,int>(  3,  8 );
00489     case   7: return std::pair<int,int>(  3,  8 );
00490     case   8: return std::pair<int,int>(  4,  9 );
00491     case   9: return std::pair<int,int>(  4,  9 );
00492     default:
00493       abort();
00494     }
00495   return std::pair<int,int>(-1,-1);
00496 }
00497 
00498 std::pair<int,int> 
00499 MEEBGeom::memFromLmr( int ilmr )
00500 {
00501   std::pair< int, int > dccAndSide_ = ME::dccAndSide( ilmr );
00502   int idcc  = dccAndSide_.first;
00503   return std::pair<int,int>( idcc, idcc );
00504 }
00505 
00506 std::vector<int> 
00507 MEEBGeom::lmmodFromLmr( int ilmr )
00508 {
00509   std::pair< int, int > dccAndSide_ = ME::dccAndSide( ilmr );
00510   int iside = dccAndSide_.second;
00511   std::vector< int > vec;
00512   for( int ilmmod=1; ilmmod<=9; ilmmod++ )
00513     {
00514       if( (ilmmod+iside)%2==1 )  vec.push_back(ilmmod);
00515     }
00516   return vec;
00517 }
00518 
00519 int
00520 MEEBGeom::apdRefTower( int ilmmod )
00521 {
00522   switch( ilmmod )
00523     {
00524       /* case   1: return 1;
00525     case   2: return 5; 
00526     case   3: return 7;
00527     case   4: return 21; 
00528     case   5: return 23;
00529     case   6: return 37;
00530     case   7: return 39;
00531     case   8: return 53;
00532     case   9: return 55;
00533       */
00534     case   1: return 2;
00535     case   2: return 6; 
00536     case   3: return 8;
00537     case   4: return 22; 
00538     case   5: return 24;
00539     case   6: return 38;
00540     case   7: return 40;
00541     case   8: return 54;
00542     case   9: return 56;
00543     default:
00544       abort();
00545     }
00546   return 0;
00547 }
00548 
00549 
00550 std::vector< int >
00551 MEEBGeom::apdRefChannels( int ilmmod )
00552 {
00553   
00554   std::vector< int > vec;
00555   switch( ilmmod )
00556     {
00557     case   1:  vec.push_back(0); vec.push_back(24); break;
00558     case   2:  vec.push_back(0); vec.push_back(24); break;
00559     case   3:  vec.push_back(0); vec.push_back(24); break;
00560     case   4:  vec.push_back(0); vec.push_back(24); break;
00561     case   5:  vec.push_back(0); vec.push_back(24); break;
00562     case   6:  vec.push_back(0); vec.push_back(24); break;
00563     case   7:  vec.push_back(0); vec.push_back(24); break;
00564     case   8:  vec.push_back(0); vec.push_back(24); break;
00565     case   9:  vec.push_back(0); vec.push_back(24); break;
00566     default:
00567       abort();
00568     }
00569   return vec;
00570 }
00571