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
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
00035
00036
00037
00038
00039
00040
00041 string
00042 str_
00043 (
00044
00045 " -01-01-01""-09-09-09 "
00046 " -01-01-01-01-01-01""-09-09-09-09-09-09 "
00047 " -02-01-01-01-01-01-01""-09-09-09-09-09-09-08 "
00048 " -02-02-02-01-01-01-01-01""-09-09-09-09-09-08-08-08 "
00049 " -02-02-02-02-01-01-01-01-01""-09-09-09-09-09-08-08-08-08 "
00050 " -02-02-02-02-02-01-01-01-01""-09-09-09-09-08-08-08-08-08 "
00051 " -02-02-02-02-02-02-01-01-01""-09-09-09-08-08-08-08-08-08 "
00052 "-02-02-02-02-02-02-02-02-01-01""-09-09-08-08-08-08-08-08-08-08"
00053 "-03-03-02-02-02-02-02-02-02 "" -08-08-08-08-08-08-08-07-07"
00054 "-03-03-03-03-03-03-03-02 "" -08-07-07-07-07-07-07-07"
00055 "-03-03-03-03-03-03-03-03 "" -07-07-07-07-07-07-07-07"
00056 "-03-03-03-03-03-03-03-04-04 "" -06-06-07-07-07-07-07-07-07"
00057 "-03-03-03-03-03-03-04-04-04-05""-05-06-06-06-07-07-07-07-07-07"
00058 " -03-03-03-04-04-04-04-04-05""-05-06-06-06-06-06-07-07-07 "
00059 " -03-04-04-04-04-04-04-05-05""-05-05-06-06-06-06-06-06-07 "
00060 " -04-04-04-04-04-04-04-05-05""-05-05-06-06-06-06-06-06-06 "
00061 " -04-04-04-04-04-04-05-05""-05-05-06-06-06-06-06-06 "
00062 " -04-04-04-04-05-05-05""-05-05-05-06-06-06-06 "
00063 " -04-04-04-05-05-05""-05-05-05-06-06-06 "
00064 " -05-05-05""-05-05-05 "
00065
00066 );
00067
00068 int iym, ixm, nc, il, ic, ii;
00069 iym=20;
00070 ixm=20;
00071 int iX_ = iX;
00072 int iY_ = iY;
00073 nc=3;
00074 il=iym-iY_;
00075 ic=nc*(iX_-1);
00076 ii=il*nc*ixm+ic;
00077 if( str_.substr(ii,1).find("-")==string::npos ) return -1;
00078 return atoi( str_.substr(ii+1,2).c_str() );
00079 }
00080
00081 int
00082 MEEEGeom::sm( SuperCrysCoord iX, SuperCrysCoord iY, int iz )
00083 {
00084
00085
00086 int ism_ = sector( iX, iY );
00087 if( ism_<0 ) return ism_;
00088 if( iz<0 ) ism_+=9;
00089 return ism_;
00090 }
00091
00092 int
00093 MEEEGeom::lmmod( SuperCrysCoord iX, SuperCrysCoord iY )
00094 {
00095
00096
00097
00098
00099 string
00100 str_
00101 (
00102
00103
00104 " -01-01-01"
00105 " -02-01-01-01-01-01"
00106 " -05-02-02-02-02-02-01"
00107 " -05-05-05-03-03-02-02-02"
00108 " -08-05-05-05-03-03-03-03-03"
00109 " -08-08-05-06-06-04-04-04-03"
00110 " -08-08-05-06-06-07-04-04-04"
00111 "-08-08-08-06-06-07-07-07-04-04"
00112 "-09-09-08-06-06-07-07-07-07 "
00113 "-09-09-09-10-10-11-11-07 "
00114 "-12-09-09-10-10-11-11-11 "
00115 "-12-12-13-10-10-11-11-17-17 "
00116 "-12-12-13-13-13-11-17-17-17-19"
00117 " -12-13-13-14-15-17-17-17-19"
00118 " -12-14-14-14-15-16-17-19-19"
00119 " -14-14-14-14-15-16-16-19-19"
00120 " -14-15-15-15-16-16-19-19"
00121 " -15-15-15-16-18-18-18"
00122 " -16-16-16-18-18-18"
00123 " -18-18-18"
00124 );
00125
00126 int iym, ixm, nc, il, ic, ii;
00127 iym=20;
00128 ixm=10;
00129 int iX_ = iX;
00130 if( iX>=11 ) iX_ = 20-iX+1;
00131 int iY_ = iY;
00132 nc=3;
00133 il=iym-iY_;
00134 ic=nc*(iX_-1);
00135 ii=il*nc*ixm+ic;
00136 if( str_.substr(ii,1).find("-")==string::npos ) return -1;
00137 return atoi( str_.substr(ii+1,2).c_str() );
00138 }
00139
00140 int
00141 MEEEGeom::sc_in_quad( SuperCrysCoord iX, SuperCrysCoord iY )
00142 {
00143 string
00144 str_
00145 (
00146
00147
00148 "-77-71-63-55-46-37-28-18 "
00149 "-78-72-64-56-47-38-29-19-09 "
00150 "-79-73-65-57-48-39-30-20-10-01"
00151 " -74-66-58-49-40-31-21-11-02"
00152 " -75-67-59-50-41-32-22-12-03"
00153 " -76-68-60-51-42-33-23-13-04"
00154 " -69-61-52-43-34-24-14-05"
00155 " -70-62-53-44-35-25-15-06"
00156 " -54-45-36-26-16-07"
00157 " -27-17-08"
00158
00159 );
00160 int iym, ixm, nc, il, ic, ii;
00161 iym=10;
00162 ixm=10;
00163 int iX_ = iX;
00164 if( iX>=11 ) iX_ = 20-iX+1;
00165 int iY_ = iY;
00166 if( iY>=11 ) iY_ = 20-iY+1;
00167 nc=3;
00168 il=iym-iY_;
00169 ic=nc*(iX_-1);
00170 ii=il*nc*ixm+ic;
00171 if( str_.substr(ii,1).find("-")==string::npos ) return -1;
00172 return atoi( str_.substr(ii+1,2).c_str() );
00173 }
00174
00175 int
00176 MEEEGeom::sc_type( SuperCrysCoord iX, SuperCrysCoord iY )
00177 {
00178 string
00179 str_
00180 (
00181
00182
00183
00184 "-00-00-00-00-00-00-00-03 "
00185 "-00-00-00-00-00-00-00-00-02 "
00186 "-06-00-00-00-00-00-00-00-00-01"
00187 " -00-00-00-00-00-00-00-00-00"
00188 " -00-00-00-00-00-00-00-00-00"
00189 " -06-00-00-00-00-00-00-00-00"
00190 " -06-00-00-00-00-00-00-00"
00191 " -05-04-00-00-00-00-00-00"
00192 " -04-00-00-00-00-00"
00193 " -04-00-00"
00194
00195 );
00196 int iym, ixm, nc, 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 nc=3;
00204 il=iym-iY_;
00205 ic=nc*(iX_-1);
00206 ii=il*nc*ixm+ic;
00207 if( str_.substr(ii,1).find("-")==string::npos ) return -1;
00208 return atoi( str_.substr(ii+1,2).c_str() );
00209 }
00210
00211 int
00212 MEEEGeom::sc( SuperCrysCoord iX, SuperCrysCoord iY )
00213 {
00214 int isc_in_quad = sc_in_quad( iX, iY );
00215 assert( isc_in_quad!=0 );
00216 if( isc_in_quad<0 ) return -1;
00217
00218 int iquad = quadrant( iX, iY );
00219 return 79*(iquad-1)+isc_in_quad;
00220 }
00221
00222 int
00223 MEEEGeom::dcc( SuperCrysCoord iX, SuperCrysCoord iY, int iz )
00224 {
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236 int isect = sector( iX, iY );
00237 assert( isect!=0 );
00238 assert( abs(iz)==1 );
00239 if( isect<0 ) return -1;
00240
00241 int idcc=0;
00242
00243 idcc = isect-6;
00244 if( idcc<=0 ) idcc+=9;
00245 if( iz==+1 ) idcc+=45;
00246
00247 return idcc;
00248 }
00249
00250 int
00251 MEEEGeom::lmr( SuperCrysCoord iX, SuperCrysCoord iY, int iz )
00252 {
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267 int iquad = quadrant( iX, iY );
00268 int isect = sector( iX, iY );
00269 assert( isect!=0 );
00270 assert( abs(iz)==1 );
00271 if( isect<0 ) return -1;
00272
00273 int ilmr=0;
00274 ilmr = isect-6;
00275 if( ilmr<=0 ) ilmr+=9;
00276 if( ilmr==9 ) ilmr++;
00277 if( ilmr==8 && iquad==4 ) ilmr++;
00278 if( iz==+1 ) ilmr+=72;
00279 else ilmr+=82;
00280
00281 return ilmr;
00282 }
00283
00284 int
00285 MEEEGeom::dee( SuperCrysCoord iX, SuperCrysCoord iY, int iz )
00286 {
00287 int iquad = quadrant( iX, iY );
00288 int idee=0;
00289 bool far = ( iquad==2 || iquad==3 ); bool near = !far;
00290 bool plus = (iz>0); bool minus = !plus;
00291 if( far && plus ) idee=1;
00292 if( near && plus ) idee=2;
00293 if( near && minus ) idee=3;
00294 if( far && minus ) idee=4;
00295
00296 return idee;
00297 }
00298
00299 int
00300 MEEEGeom::crystal_in_sc( CrysCoord ix, CrysCoord iy )
00301 {
00302
00303 string
00304 str_[7] =
00305 {
00306 "+21+16+11+06+01"
00307 "+22+17+12+07+02"
00308 "+23+18+13+08+03"
00309 "+24+19+14+09+04"
00310 "+25+20+15+10+05"
00311 ,
00312 " "
00313 "+22+17+12+07+02"
00314 "+23+18+13+08+03"
00315 "+24+19+14+09+04"
00316 "+25+20+15+10+05"
00317 ,
00318 " "
00319 " "
00320 "+23 "
00321 "+24+19 "
00322 "+25+20+15 "
00323 ,
00324 "+21+16+11+06 "
00325 "+22+17+12+07 "
00326 "+23+18+13+08 "
00327 "+24+19+14+09 "
00328 "+25+20+15+10 "
00329 ,
00330 "+21+16+11+06+01"
00331 "+22+17+12+07+02"
00332 " "
00333 " "
00334 " "
00335 ,
00336 " "
00337 " "
00338 " "
00339 " "
00340 " "
00341 ,
00342 " +06+01"
00343 " +07+02"
00344 " +08+03"
00345 " +09+04"
00346 " +10+05"
00347 };
00348
00349 int iX, iY, jx, jy;
00350 int iX_ = (ix-1)/5+1;
00351 int iY_ = (iy-1)/5+1;
00352 int jx_ = ix - 5*(iX_-1);
00353 int jy_ = iy - 5*(iY_-1);
00354
00355 int iquad = quadrant( iX_, iY_ );
00356 if( iX_>=11 )
00357 {
00358 iX_ = 20-iX_+1;
00359 jx_ = 5-jx_+1;
00360 }
00361 if( iY_>=11 )
00362 {
00363 iY_ = 20-iY_+1;
00364 jy_ = 5-jy_+1;
00365 }
00366
00367
00368 if( iquad==1 || iquad==3 )
00369 {
00370 iX = iX_;
00371 iY = iY_;
00372 jx = jx_;
00373 jy = jy_;
00374 }
00375 else
00376 {
00377 iX = iY_;
00378 iY = iX_;
00379 jx = jy_;
00380 jy = jx_;
00381 }
00382
00383 int isc_type = sc_type( iX, iY );
00384 assert( isc_type>=0 && isc_type<7 );
00385
00386 int iym, ixm, nc, il, ic, ii;
00387 iym=5;
00388 ixm=5;
00389 nc=3;
00390 il=iym-jy;
00391 ic=nc*(jx-1);
00392 ii=il*nc*ixm+ic;
00393 if( str_[isc_type].substr(ii,1).find("+")==string::npos ) return -1;
00394 return atoi( str_[isc_type].substr(ii+1,2).c_str() );
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;
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
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
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
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
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
00575 assert( n_==1 );
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
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
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
00754 if( dee==1 )
00755 {
00756 switch( ilmmod )
00757 {
00758
00759 case 1: pns.first=1; pns.second=5; break;
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
00765 case 6: pns.first=1; pns.second=5; break;
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
00790 case 3: pns.first=4; pns.second=9; break;
00791 case 4: pns.first=4; pns.second=9; break;
00792
00793 case 5: pns.first=4; pns.second=9; break;
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
00800 case 11: pns.first=2; pns.second=2; break;
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
00808 case 18: pns.first=0; pns.second=5; break;
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
00820 case 2: pns.first=0; pns.second=5; break;
00821 case 3: pns.first=2; pns.second=7; break;
00822
00823 case 4: pns.first=2; pns.second=8; break;
00824 case 5: pns.first=2; pns.second=7; break;
00825 case 6: pns.first=0; pns.second=5; break;
00826
00827 case 7: pns.first=0; pns.second=5; break;
00828
00829 case 8: pns.first=2; pns.second=8; break;
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
00835 case 13: pns.first=9; pns.second=4; break;
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
00840 case 17: pns.first=4; pns.second=9; break;
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
00854 case 3: pns.first=1; pns.second=6; break;
00855 case 4: pns.first=9; pns.second=4; break;
00856
00857 case 5: pns.first=4; pns.second=9; break;
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
00871 case 18: pns.first=5; pns.second=0; break;
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 )
00909 {
00910 out_.first = 50;
00911 out_.second = 51;
00912 }
00913 else if( dee_==2 )
00914 {
00915 out_.first = 47;
00916 out_.second = 46;
00917 }
00918 else if( dee_==3 )
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