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
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
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
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;
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
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
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
00168 int iz=1;
00169 if( ism>18 )
00170 {
00171 iz=-1;
00172 ism -= 18;
00173 }
00174 if( iz==-1 ) iy = 19-iy;
00175
00176
00177 int ieta = ix+1;
00178 ieta *= iz;
00179
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
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 string
00221 str_
00222 (
00223
00224 "-01-02-02-02-02-04-04-04-04-06-06-06-06-08-08-08-08"
00225 "-01-02-02-02-02-04-04-04-04-06-06-06-06-08-08-08-08"
00226 "-01-03-03-03-03-05-05-05-05-07-07-07-07-09-09-09-09"
00227 "-01-03-03-03-03-05-05-05-05-07-07-07-07-09-09-09-09"
00228
00229 );
00230
00231 int iym, ixm, nc, il, ic, ii;
00232 iym=4;
00233 ixm=17;
00234 int iX_ = iX+1;
00235 int iY_ = iY+1;
00236 nc=3;
00237 il=iym-iY_;
00238 ic=nc*(iX_-1);
00239 ii=il*nc*ixm+ic;
00240 if( str_.substr(ii,1).find("-")==string::npos ) return -1;
00241 return atoi( str_.substr(ii+1,2).c_str() );
00242 }
00243
00244 int
00245 MEEBGeom::tt_type( EBTTLocalCoord iX, EBTTLocalCoord iY )
00246 {
00247 string
00248 str_
00249 (
00250
00251 "-01-01-01-02-02-01-01-02-02-01-01-02-02-01-01-02-02"
00252 "-01-01-01-02-02-01-01-02-02-01-01-02-02-01-01-02-02"
00253 "-01-01-01-02-02-01-01-02-02-01-01-02-02-01-01-02-02"
00254 "-01-01-01-02-02-01-01-02-02-01-01-02-02-01-01-02-02"
00255
00256 );
00257
00258 int iym, ixm, nc, il, ic, ii;
00259 iym=4;
00260 ixm=17;
00261 int iX_ = iX+1;
00262 int iY_ = iY+1;
00263 nc=3;
00264 il=iym-iY_;
00265 ic=nc*(iX_-1);
00266 ii=il*nc*ixm+ic;
00267 if( str_.substr(ii,1).find("-")==string::npos ) return -1;
00268 return atoi( str_.substr(ii+1,2).c_str() );
00269 }
00270
00271 int
00272 MEEBGeom::hv_channel( EBTTLocalCoord iX, EBTTLocalCoord iY )
00273 {
00274 string
00275 str_
00276 (
00277
00278 "-01-03-05-07-09-11-13-15-17-19-21-23-25-27-29-31-33"
00279 "-01-03-05-07-09-11-13-15-17-19-21-23-25-27-29-31-33"
00280 "-02-04-06-08-10-12-14-16-18-20-22-24-26-28-30-32-34"
00281 "-02-04-06-08-10-12-14-16-18-20-22-24-26-28-30-32-34"
00282
00283 );
00284
00285 int iym, ixm, nc, il, ic, ii;
00286 iym=4;
00287 ixm=17;
00288 int iX_ = iX+1;
00289 int iY_ = iY+1;
00290 nc=3;
00291 il=iym-iY_;
00292 ic=nc*(iX_-1);
00293 ii=il*nc*ixm+ic;
00294 if( str_.substr(ii,1).find("-")==string::npos ) return -1;
00295 return atoi( str_.substr(ii+1,2).c_str() );
00296 }
00297
00298 int
00299 MEEBGeom::lv_channel( EBTTLocalCoord iX, EBTTLocalCoord iY )
00300 {
00301 string
00302 str_
00303 (
00304
00305 "-01-02-02-04-04-06-06-08-08-10-10-12-12-14-14-16-16"
00306 "-01-02-02-04-04-06-06-08-08-10-10-12-12-14-14-16-16"
00307 "-01-03-03-05-05-07-07-09-09-11-11-13-13-15-15-17-17"
00308 "-01-03-03-05-05-07-07-09-09-11-11-13-13-15-15-17-17"
00309
00310 );
00311
00312 int iym, ixm, nc, il, ic, ii;
00313 iym=4;
00314 ixm=17;
00315 int iX_ = iX+1;
00316 int iY_ = iY+1;
00317 nc=3;
00318 il=iym-iY_;
00319 ic=nc*(iX_-1);
00320 ii=il*nc*ixm+ic;
00321 if( str_.substr(ii,1).find("-")==string::npos ) return -1;
00322 return atoi( str_.substr(ii+1,2).c_str() );
00323 }
00324
00325 int
00326 MEEBGeom::tt_channel( EBTTLocalCoord iX, EBTTLocalCoord iY )
00327 {
00328
00329 int itt = 4*iX+4-iY;
00330
00331 return itt;
00332
00333 }
00334
00335 int
00336 MEEBGeom::crystal_channel( EBLocalCoord ix, EBLocalCoord iy )
00337 {
00338
00339 int icr = 20*ix + 19-iy + 1;
00340
00341 return icr;
00342 }
00343
00344 int
00345 MEEBGeom::electronic_channel( EBLocalCoord ix, EBLocalCoord iy )
00346 {
00347 int iX = ix/5;
00348 int iY = iy/5;
00349 int itt = tt_channel( iX, iY );
00350 int type = tt_type( iX, iY );
00351
00352 int iVFE = ix%5+1;
00353 int islot = iy%5+1;
00354 if( iVFE%2==1 ) islot = 6-islot;
00355 int icr = 5*(iVFE-1)+(islot-1);
00356
00357 if( type==1 )
00358 {
00359 icr = 24-icr;
00360 }
00361 icr += 25*(itt-1);
00362
00363 return icr;
00364 }
00365
00366 TGraph*
00367 MEEBGeom::getGraphBoundary( int type, int num, bool global )
00368 {
00369 int ism_=0;
00370 if( type==iSuperModule )
00371 {
00372 ism_ = num;
00373 }
00374 else if( type==iLMRegion )
00375 {
00376 ism_ = (num-1)/2+1;
00377 if( ism_>18 )
00378 ism_-=18;
00379 else
00380 ism_+=18;
00381 }
00382 else
00383 abort();
00384
00385 int ism=1;
00386 if( global ) ism = ism_;
00387
00388
00389
00390
00391
00392
00393 float ix[100];
00394 float iy[100];
00395 int ixmin = 0;
00396 int ixmax = 84;
00397 int iymin = 0;
00398 int iymax = 19;
00399
00400 int n(0);
00401 if( type==iSuperModule )
00402 {
00403 n=5;
00404 ix[0] = ixmin-0.5;
00405 iy[0] = iymin-0.5;
00406 ix[1] = ixmin-0.5;
00407 iy[1] = iymax+0.5;
00408 ix[2] = ixmax+0.5;
00409 iy[2] = iymax+0.5;
00410 ix[3] = ixmax+0.5;
00411 iy[3] = iymin-0.5;
00412 ix[4] = ix[0];
00413 iy[4] = iy[0];
00414 }
00415 else if( type==iLMRegion )
00416 {
00417 int iside = num;
00418 if( global )
00419 {
00420 iside = (num-1)%2;
00421 }
00422
00423 if( iside==1 )
00424 {
00425 n=5;
00426 ix[0] = ixmin+5-0.5;
00427 iy[0] = iymin+10-0.5;
00428 ix[1] = ixmin+5-0.5;
00429 iy[1] = iymax+0.5;
00430 ix[2] = ixmax+0.5;
00431 iy[2] = iymax+0.5;
00432 ix[3] = ixmax+0.5;
00433 iy[3] = iymin+10-0.5;
00434 ix[4] = ix[0];
00435 iy[4] = iy[0];
00436 }
00437 else
00438 {
00439 n=7;
00440 ix[0] = ixmin-0.5;
00441 iy[0] = iymin-0.5;
00442 ix[1] = ixmin-0.5;
00443 iy[1] = iymax+0.5;
00444 ix[2] = ixmin+5-0.5;
00445 iy[2] = iymax+0.5;
00446 ix[3] = ixmin+5-0.5;
00447 iy[3] = iymax-10+0.5;
00448 ix[4] = ixmax+0.5;
00449 iy[4] = iymax-10+0.5;
00450 ix[5] = ixmax+0.5;
00451 iy[5] = iymin-0.5;
00452 ix[6] = ix[0];
00453 iy[6] = iy[0];
00454 }
00455 }
00456
00457 if( global )
00458 {
00459 for( int ii=0; ii<n; ii ++ )
00460 {
00461 std::pair<float,float> xy = globalCoord( ism, ix[ii], iy[ii] );
00462 ix[ii] = xy.first;
00463 iy[ii] = xy.second;
00464 }
00465 }
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479 return new TGraph( n, ix, iy );
00480 }
00481
00482 std::pair< int, int >
00483 MEEBGeom::pn( int ilmmod )
00484 {
00485 switch( ilmmod )
00486 {
00487 case 1: return std::pair<int,int>( 0, 5 );
00488 case 2: return std::pair<int,int>( 1, 6 );
00489 case 3: return std::pair<int,int>( 1, 6 );
00490 case 4: return std::pair<int,int>( 2, 7 );
00491 case 5: return std::pair<int,int>( 2, 7 );
00492 case 6: return std::pair<int,int>( 3, 8 );
00493 case 7: return std::pair<int,int>( 3, 8 );
00494 case 8: return std::pair<int,int>( 4, 9 );
00495 case 9: return std::pair<int,int>( 4, 9 );
00496 default:
00497 abort();
00498 }
00499 return std::pair<int,int>(-1,-1);
00500 }
00501
00502 std::pair<int,int>
00503 MEEBGeom::memFromLmr( int ilmr )
00504 {
00505 std::pair< int, int > dccAndSide_ = ME::dccAndSide( ilmr );
00506 int idcc = dccAndSide_.first;
00507 return std::pair<int,int>( idcc, idcc );
00508 }
00509
00510 std::vector<int>
00511 MEEBGeom::lmmodFromLmr( int ilmr )
00512 {
00513 std::pair< int, int > dccAndSide_ = ME::dccAndSide( ilmr );
00514 int iside = dccAndSide_.second;
00515 std::vector< int > vec;
00516 for( int ilmmod=1; ilmmod<=9; ilmmod++ )
00517 {
00518 if( (ilmmod+iside)%2==1 ) vec.push_back(ilmmod);
00519 }
00520 return vec;
00521 }
00522
00523 int
00524 MEEBGeom::apdRefTower( int ilmmod )
00525 {
00526 switch( ilmmod )
00527 {
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538 case 1: return 2;
00539 case 2: return 6;
00540 case 3: return 8;
00541 case 4: return 22;
00542 case 5: return 24;
00543 case 6: return 38;
00544 case 7: return 40;
00545 case 8: return 54;
00546 case 9: return 56;
00547 default:
00548 abort();
00549 }
00550 return 0;
00551 }
00552
00553
00554 std::vector< int >
00555 MEEBGeom::apdRefChannels( int ilmmod )
00556 {
00557
00558 std::vector< int > vec;
00559 switch( ilmmod )
00560 {
00561 case 1: vec.push_back(0); vec.push_back(24); break;
00562 case 2: vec.push_back(0); vec.push_back(24); break;
00563 case 3: vec.push_back(0); vec.push_back(24); break;
00564 case 4: vec.push_back(0); vec.push_back(24); break;
00565 case 5: vec.push_back(0); vec.push_back(24); break;
00566 case 6: vec.push_back(0); vec.push_back(24); break;
00567 case 7: vec.push_back(0); vec.push_back(24); break;
00568 case 8: vec.push_back(0); vec.push_back(24); break;
00569 case 9: vec.push_back(0); vec.push_back(24); break;
00570 default:
00571 abort();
00572 }
00573 return vec;
00574 }
00575