CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/DataFormats/EcalDetId/src/EEDetId.cc

Go to the documentation of this file.
00001 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00002 #include "FWCore/Utilities/interface/Exception.h"
00003     
00004 #include <iostream>
00005 #include <algorithm>
00006    
00007 const int EEDetId::QuadColLimits[EEDetId::nCols+1] = { 0, 8,17,27,36,45,54,62,70,76,79 };
00008 
00009 const int EEDetId::iYoffset[EEDetId::nCols+1]      = { 0, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0 };
00010 
00011 const unsigned short EEDetId::kxf[] = {
00012   41,  51,  41,  51,  41,  51,  36,  51,  36,  51,
00013   26,  51,  26,  51,  26,  51,  21,  51,  21,  51,
00014   21,  51,  21,  51,  21,  51,  16,  51,  16,  51,
00015   14,  51,  14,  51,  14,  51,  14,  51,  14,  51,
00016    9,  51,   9,  51,   9,  51,   9,  51,   9,  51,
00017    6,  51,   6,  51,   6,  51,   6,  51,   6,  51,
00018    6,  51,   6,  51,   6,  51,   6,  51,   6,  51,
00019    4,  51,   4,  51,   4,  51,   4,  51,   4,  56,
00020    1,  58,   1,  59,   1,  60,   1,  61,   1,  61,
00021    1,  62,   1,  62,   1,  62,   1,  62,   1,  62,
00022    1,  62,   1,  62,   1,  62,   1,  62,   1,  62,
00023    1,  61,   1,  61,   1,  60,   1,  59,   1,  58,
00024    4,  56,   4,  51,   4,  51,   4,  51,   4,  51,
00025    6,  51,   6,  51,   6,  51,   6,  51,   6,  51,
00026    6,  51,   6,  51,   6,  51,   6,  51,   6,  51,
00027    9,  51,   9,  51,   9,  51,   9,  51,   9,  51,
00028   14,  51,  14,  51,  14,  51,  14,  51,  14,  51,
00029   16,  51,  16,  51,  21,  51,  21,  51,  21,  51,
00030   21,  51,  21,  51,  26,  51,  26,  51,  26,  51,
00031   36,  51,  36,  51,  41,  51,  41,  51,  41,  51
00032 } ;
00033 
00034 const unsigned short EEDetId::kdi[] = {
00035     0,   10,   20,   30,   40,   50,   60,   75,   90,  105,
00036   120,  145,  170,  195,  220,  245,  270,  300,  330,  360,
00037   390,  420,  450,  480,  510,  540,  570,  605,  640,  675,
00038   710,  747,  784,  821,  858,  895,  932,  969, 1006, 1043,
00039  1080, 1122, 1164, 1206, 1248, 1290, 1332, 1374, 1416, 1458,
00040  1500, 1545, 1590, 1635, 1680, 1725, 1770, 1815, 1860, 1905,
00041  1950, 1995, 2040, 2085, 2130, 2175, 2220, 2265, 2310, 2355,
00042  2400, 2447, 2494, 2541, 2588, 2635, 2682, 2729, 2776, 2818,
00043  2860, 2903, 2946, 2988, 3030, 3071, 3112, 3152, 3192, 3232,
00044  3272, 3311, 3350, 3389, 3428, 3467, 3506, 3545, 3584, 3623,
00045  3662, 3701, 3740, 3779, 3818, 3857, 3896, 3935, 3974, 4013,
00046  4052, 4092, 4132, 4172, 4212, 4253, 4294, 4336, 4378, 4421,
00047  4464, 4506, 4548, 4595, 4642, 4689, 4736, 4783, 4830, 4877,
00048  4924, 4969, 5014, 5059, 5104, 5149, 5194, 5239, 5284, 5329,
00049  5374, 5419, 5464, 5509, 5554, 5599, 5644, 5689, 5734, 5779,
00050  5824, 5866, 5908, 5950, 5992, 6034, 6076, 6118, 6160, 6202,
00051  6244, 6281, 6318, 6355, 6392, 6429, 6466, 6503, 6540, 6577,
00052  6614, 6649, 6684, 6719, 6754, 6784, 6814, 6844, 6874, 6904,
00053  6934, 6964, 6994, 7024, 7054, 7079, 7104, 7129, 7154, 7179,
00054  7204, 7219, 7234, 7249, 7264, 7274, 7284, 7294, 7304, 7314
00055 } ;
00056 
00057 EEDetId::EEDetId( int index1, int index2, int iz, int mode ) : DetId( Ecal, EcalEndcap ) 
00058 {
00059    int crystal_ix=0;
00060    int crystal_iy=0;
00061    if (mode == XYMODE) 
00062    {
00063       crystal_ix = index1;
00064       crystal_iy = index2;  
00065    } 
00066    else if (mode == SCCRYSTALMODE) 
00067    {
00068       int SC = index1;
00069       int crystal = index2;
00070       //      std::cout << "iz " << iz << " SC " << index1 << "crystal " << index2  << std::endl;
00071       
00072       crystal_ix=iz*ix(SC,crystal);
00073       if (crystal_ix<0)
00074         crystal_ix++;
00075       crystal_ix+=50;
00076       crystal_iy=iy(SC,crystal);
00077       if (crystal_iy<0)
00078          crystal_iy++;
00079       crystal_iy+=50;
00080 
00081    } 
00082    else 
00083    {
00084       throw cms::Exception("InvalidDetId") << "EEDetId:  Cannot create object.  Unknown mode for (int, int, int) constructor.";
00085    }
00086   
00087    if (!validDetId(crystal_ix,crystal_iy,iz))
00088    {
00089       throw cms::Exception("InvalidDetId") << "EEDetId:  Cannot create object.  Indexes out of bounds \n"
00090                                            << "x = " << crystal_ix << " y = " << crystal_iy << " z = " << iz;
00091    }
00092   
00093    id_|=(crystal_iy&0x7f)|((crystal_ix&0x7f)<<7)|((iz>0)?(0x4000):(0));
00094 }
00095   
00096 EEDetId::EEDetId( const DetId& gen ) 
00097 {
00098    if (!gen.null() && (gen.det()!=Ecal || gen.subdetId()!=EcalEndcap)) {
00099       throw cms::Exception("InvalidDetId"); 
00100    }
00101    id_ = gen.rawId();
00102 }
00103   
00104 EEDetId& EEDetId::operator=( const DetId& gen ) 
00105 {
00106    if (!gen.null() && ( gen.det()!=Ecal || gen.subdetId()!=EcalEndcap )) 
00107    {
00108       throw cms::Exception("InvalidDetId"); 
00109    }
00110    id_ = gen.rawId();
00111    return *this;
00112 }
00113 
00114 EEDetId 
00115 EEDetId::unhashIndex( int hi )
00116 {
00117    if( validHashIndex( hi ) )
00118    {
00119       const int iz ( hi<kEEhalf ? -1 : 1 ) ;
00120       const uint32_t di ( hi%kEEhalf ) ;
00121       const int ii ( ( std::upper_bound( kdi, kdi+(2*IY_MAX), di ) - kdi ) - 1 ) ;
00122       const int iy ( 1 + ii/2 ) ;
00123       const int ix ( kxf[ii] + di - kdi[ii] ) ;
00124       return EEDetId( ix, iy, iz ) ;
00125    }
00126    else
00127    {
00128       return EEDetId() ;
00129    }
00130 }
00131 
00132 int 
00133 EEDetId::ix( int iSC, int iCrys ) const 
00134 {
00135   /*
00136    *  ix() return individual crystal x-coordinate
00137    *
00138    *  Author    : B W Kennedy
00139    *  Version   : 1.00
00140    *  Created   : 21 December 2005
00141    *  Last Mod  : 31 January 2006
00142    *
00143    *  Input     : iSC, iCrys - Supercrystal and crystal ids
00144    */
00145   
00146   
00147    int nSCinQuadrant = QuadColLimits[nCols];
00148 
00149    if (iSC > 4*nSCinQuadrant || iSC < 1) 
00150    {
00151       throw new std::exception();
00152    }
00153   
00154    //  Map SC number into (x>0,y>0) quadrant.
00155    int iSCmap, iqx,iq;
00156    if (iSC > 3*nSCinQuadrant) 
00157    {
00158       iSCmap = iSC - 3*nSCinQuadrant;
00159       iqx =  1;
00160       iq=4;
00161    } 
00162    else if (iSC > 2*nSCinQuadrant) 
00163    {
00164       iSCmap = iSC - 2*nSCinQuadrant;
00165       iqx = -1;
00166       iq=3;
00167    } 
00168    else if (iSC > nSCinQuadrant) 
00169    {
00170       iSCmap = iSC - nSCinQuadrant;
00171       iqx = -1;
00172       iq=2;
00173    } 
00174    else 
00175    {
00176       iSCmap = iSC;
00177       iqx = 1;
00178       iq=1;
00179    }
00180 
00181    // Decide which column the SC is in
00182    int iCol = 0 ;
00183    while (iSCmap > QuadColLimits[iCol++]) ;
00184    iCol-- ;
00185 
00186    int ixCrys=-1;
00187    if (iq == 1 || iq == 3) 
00188       ixCrys = iqx*(5*(iCol-1) + (int)(iCrys+4)/5);
00189    else   if (iq == 2 || iq == 4) 
00190       ixCrys = iqx*(5*(iCol-1) + (iCrys-1)%5 + 1);
00191    
00192    // returning a value from 1 to 100  
00193 
00194    return ixCrys;
00195 }
00196 
00197 int EEDetId::iy( int iSC, int iCrys ) const 
00198 {
00199   /*
00200    *  iy() return individual crystal y-coordinate
00201    *
00202    *  Author    : B W Kennedy
00203    *  Version   : 1.00
00204    *  Created   : 21 December 2005
00205    *  Last Mod  : 31 January 2006
00206    *
00207    *  Input     : iSC, iCrys - Supercrystal and crystal ids
00208    */
00209 
00210    int nSCinQuadrant = QuadColLimits[nCols];
00211    if (iSC > 4*nSCinQuadrant || iSC < 1) 
00212    {
00213       throw new std::exception();
00214    }
00215 
00216    //  Map SC number into (x>0,y>0) quadrant
00217    int iSCmap, iqy,iq;
00218    if (iSC > 3*nSCinQuadrant) 
00219    {
00220       iSCmap = iSC - 3*nSCinQuadrant;
00221       iqy = -1;
00222       iq=4;
00223    } 
00224    else if (iSC > 2*nSCinQuadrant) 
00225    {
00226       iSCmap = iSC - 2*nSCinQuadrant;
00227       iqy = -1;
00228       iq=3;
00229    } 
00230    else if (iSC > nSCinQuadrant) 
00231    {
00232       iSCmap = iSC - nSCinQuadrant;
00233       iqy = 1;
00234       iq=2;
00235    } else 
00236    {
00237       iSCmap = iSC;
00238       iqy = 1;
00239       iq=1;
00240    }
00241 
00242    // Decide which column the SC is in
00243    int iCol = 0;
00244    while (iSCmap > QuadColLimits[iCol++]) ;
00245    iCol--;
00246 
00247    int iSCy = iSCmap - QuadColLimits[iCol-1] + iYoffset[iCol];
00248   
00249    int iyCrys=-1;
00250    if (iq == 1 || iq == 3)
00251       iyCrys = iqy*(5*(iSCy-1) + (iCrys-1)%5 + 1);
00252    else if (iq == 2 || iq == 4)
00253       iyCrys = iqy*(5*(iSCy-1) + (int)(iCrys+4)/5 );
00254    return iyCrys;
00255 }
00256 
00257 int EEDetId::ixQuadrantOne() const
00258 { 
00259    int iQuadrant = iquadrant();
00260    if ( iQuadrant == 1 || iQuadrant == 4)
00261       return (ix() - 50);
00262    else if ( iQuadrant == 2 || iQuadrant == 3)
00263       return (51 - ix());
00264    //Should never be reached
00265    return -1;
00266 }
00267 
00268 int EEDetId::iyQuadrantOne() const
00269 { 
00270    int iQuadrant = iquadrant();
00271    if ( iQuadrant == 1 || iQuadrant == 2)
00272       return (iy() - 50);
00273    else if ( iQuadrant == 3 || iQuadrant == 4)
00274       return 51 - iy();
00275    //Should never be reached
00276    return -1;
00277 }
00278 
00279 int 
00280 EEDetId::iquadrant() const 
00281 {
00282    if (ix()>50)
00283    {
00284       if(iy()>50)
00285          return 1;
00286       else
00287          return 4;
00288    }
00289    else
00290    {
00291       if(iy()>50)
00292          return 2;
00293       else
00294          return 3;
00295    }
00296    //Should never be reached
00297    return -1;
00298 }  
00299 
00300 int 
00301 EEDetId::isc() const
00302 { 
00303    return isc( 1 + ( ix() - 1 )/nCrys,
00304                1 + ( iy() - 1 )/nCrys ) ; 
00305 }
00306 
00307 int 
00308 EEDetId::isc( int jx, int jy ) 
00309 {
00310    if( 0  < jx &&
00311        21 > jx &&
00312        0  < jy &&
00313        21 > jy    )
00314    {
00315       const int iquad (  ( 10<jx && 10<jy ? 1 :
00316                            ( 11>jx && 10<jy ? 2 :
00317                              ( 11>jx && 11>jy ? 3 : 4 ) ) ) ) ;
00318   
00319       const int iCol = ( 1 == iquad || 4 == iquad ? jx - 10 : 11 - jx ) ;
00320       const int iRow = ( 1 == iquad || 2 == iquad ? jy - 10 : 11 - jy ) ;
00321 
00322       static int nSCinQuadrant = ISC_MAX/4;
00323 
00324       const int yOff ( iYoffset[iCol] ) ;
00325 
00326       const int qOff ( nSCinQuadrant*( iquad - 1 ) ) ;
00327 
00328       const int iscOne ( QuadColLimits[iCol-1] + iRow - yOff ) ;
00329 
00330       return ( yOff                >= iRow   ? -1 : 
00331                ( QuadColLimits[iCol] <  iscOne ? -2 :
00332                  iscOne + qOff ) ) ;
00333    }
00334    else
00335    {
00336       return -3 ; // bad inputs
00337    }
00338 }  
00339 
00340 int EEDetId::ic() const 
00341 {
00342    /*
00343     *  Return crystal number from (x,y) coordinates.
00344     *
00345     *  Author    : B W Kennedy
00346     *  Version   : 1.00
00347     *  Created   : 5 May 2006
00348     *  Last Mod  :
00349     *
00350     *  Input     : ix, iy - (x,y) position of crystal
00351     */
00352    
00353    /*  Useful constants . */
00354    int iQuadrant = iquadrant();
00355    int icrCol=-1;
00356    int icrRow=-1;
00357    
00358    if (iQuadrant == 1 || iQuadrant == 3)
00359    {
00360       icrCol=(ixQuadrantOne()-1) % nCrys;
00361       icrRow=(iyQuadrantOne()-1) % nCrys;
00362    }
00363   
00364    else if (iQuadrant == 2 || iQuadrant == 4)
00365    {
00366       icrRow=(ixQuadrantOne()-1) % nCrys;
00367       icrCol=(iyQuadrantOne()-1) % nCrys;
00368    } 
00369 
00370    int icrys = 5*icrCol + icrRow + 1;
00371   
00372    return icrys;
00373 }  
00374 
00375 
00376 bool 
00377 EEDetId::isNextToBoundary( EEDetId id ) 
00378 {
00379    return isNextToDBoundary( id ) || isNextToRingBoundary( id ) ;
00380 }
00381 
00382 bool 
00383 EEDetId::isNextToDBoundary( EEDetId id ) 
00384 {
00385    // hardcoded values for D boundary
00386    return id.ix() == 50 || id.ix() == 51 ;
00387 }
00388 
00389 
00390 bool 
00391 EEDetId::isNextToRingBoundary(EEDetId id) 
00392 {
00393    for (int i = -1; i <= 1; ++i) {
00394       for (int j = -1; j <= 1; ++j) {
00395          if ( ! validDetId( id.ix() + i, id.iy() + j, id.zside() ) ) {
00396             return true;
00397          }
00398       }
00399    }
00400    return false;
00401 }
00402 
00403 int
00404 EEDetId::iPhiOuterRing() const
00405 {
00406    int returnValue ( 0 ) ;
00407    if( isOuterRing() )
00408    {
00409       const int ax ( abs( ix() - IX_MAX/2 ) ) ;
00410       const int ay ( abs( iy() - IY_MAX/2 ) ) ;
00411       returnValue = ax + 50 - ay ;
00412       if( ay <= 47 ) --returnValue ;
00413       if( ay <= 45 ) --returnValue ;
00414       if( ay <= 42 ) --returnValue ;
00415       if( ay <= 37 ) --returnValue ;
00416       if( ay <= 35 ) --returnValue ;
00417       if( ay <= 30 ) --returnValue ;
00418       if( ay <= 25 ) --returnValue ;
00419       if( ay <= 15 ) --returnValue ;
00420       if( ay <= 10 ) --returnValue ;
00421       const int iq ( iquadrant() ) ;
00422       if( 1==iq )
00423       {
00424          returnValue = 91 - returnValue ;
00425       }
00426       else
00427       {
00428          if( 2==iq )
00429          {
00430             returnValue += 90 ;
00431          }
00432          else
00433          {
00434             if( 3==iq )
00435             {
00436                returnValue = 271 - returnValue ;
00437             }
00438             else
00439             {
00440                returnValue += 270 ;
00441             }
00442          }
00443       }
00444       returnValue = 1 + ( 360 + returnValue - 10 -1 )%360 ;
00445    }
00446 //   if( positiveZ() ) returnValue += 360 ;
00447    return returnValue ;
00448 }
00449 
00450 EEDetId 
00451 EEDetId::idOuterRing( int iPhi , int zEnd )
00452 {
00453    iPhi -= 10 ; // phi=1 in barrel is at -10deg
00454    while( iPhi <   1 ) iPhi+=360 ;
00455    while( iPhi > 360 ) iPhi-=360 ;
00456 
00457    const int index1 ( iPhi - 1 ) ;
00458    const int quad   ( index1/90 ) ;
00459    int       indexq (  index1 - quad*90 + 1 ) ;
00460    if( 0==quad || 2==quad ) indexq = 91 - indexq ;
00461    const int indexh ( indexq > 45 ? 91 - indexq : indexq ) ;
00462    const int axh    ( indexh<=10 ? indexh :
00463                       ( indexh<=12 ? 10 :
00464                         ( indexh<=17 ? indexh - 2 :
00465                           ( indexh<=18 ? 15 :
00466                             ( indexh<=28 ? indexh - 3 :
00467                               ( indexh<=30 ? 25 :
00468                                 ( indexh<=35 ? indexh - 5 :
00469                                   ( indexh<=39 ? 30 :
00470                                     ( indexh<=44 ? indexh - 9 : 35 ))))))))) ;
00471    const int ayh    ( indexh<=10 ? 50 :
00472                       ( indexh<=12 ? 60 - indexh :
00473                         ( indexh<=17 ? 47 :
00474                           ( indexh<=18 ? 64 - indexh : 
00475                             ( indexh<=28 ? 45 :
00476                               ( indexh<=30 ? 73 - indexh :
00477                                 ( indexh<=35 ? 42 :
00478                                   ( indexh<=39 ? 77 - indexh :
00479                                     ( indexh<=44 ? 37 : 36 ))))))))) ;
00480    const int bxh ( indexq>45 ? ayh : axh ) ;
00481    const int byh ( indexq>45 ? axh : ayh ) ;
00482    const int cx  ( ( quad==0 || quad==3 ? bxh : -bxh+1 ) + IX_MAX/2 ) ;
00483    const int cy  ( ( quad==0 || quad==1 ? byh : -byh+1 ) + IY_MAX/2 ) ;
00484 
00485    return EEDetId( cx, cy, ( zEnd > 0 ? 1 : -1 ) ) ;
00486 }
00487 
00488 
00489 EEDetId 
00490 EEDetId::offsetBy(int nrStepsX, int nrStepsY ) const
00491 {
00492         int newX = ix() + nrStepsX;
00493         int newY = iy() + nrStepsY;
00494 
00495         if( validDetId( newX, newY, zside() ) ) {
00496                 return EEDetId( newX, newY, zside() );
00497         } else {
00498                 return EEDetId(0);
00499         }
00500 }
00501 
00502 EEDetId
00503 EEDetId::switchZSide() const
00504 {
00505         int newZSide = -1 * zside();
00506         if( validDetId(ix(), iy(), newZSide ) ) {
00507                 return EEDetId( ix(), iy(), newZSide );
00508         } else {
00509                 return EEDetId(0);
00510         }
00511 }
00512 
00513 DetId 
00514 EEDetId::offsetBy( const DetId startId, int nrStepsX, int nrStepsY )
00515 {
00516         if( startId.det() == DetId::Ecal && startId.subdetId() == EcalEndcap ) {
00517                 EEDetId eeStartId( startId );
00518                 return eeStartId.offsetBy( nrStepsX, nrStepsY ).rawId();
00519         } else {
00520                 return DetId(0);
00521         }
00522 }
00523 
00524 DetId 
00525 EEDetId::switchZSide( const DetId startId )
00526 {
00527         if( startId.det() == DetId::Ecal && startId.subdetId() == EcalEndcap ) {
00528                 EEDetId eeStartId(startId);
00529                 return eeStartId.switchZSide().rawId();
00530         } else {
00531                 return DetId(0);
00532         }
00533 }
00534 
00535 bool 
00536 EEDetId::isOuterRing() const
00537 {
00538    const int kx ( ix() ) ;
00539    const int ky ( iy() ) ;
00540    const int ax ( kx>IX_MAX/2 ? kx-IX_MAX/2 : IX_MAX/2 + 1 - kx ) ;
00541    const int ay ( ky>IY_MAX/2 ? ky-IY_MAX/2 : IY_MAX/2 + 1 - ky ) ;
00542    return ( isOuterRingXY( ax, ay ) ||
00543             isOuterRingXY( ay, ax )    ) ;
00544 }
00545 
00546 bool 
00547 EEDetId::isOuterRingXY( int ax, int ay )
00548 {
00549    return ( ( ax<=10 &&           ay==50 ) ||
00550             ( ax==10 &&           ay>=48 ) ||
00551             ( ax<=15 && ax>=11 && ay==47 ) ||
00552             ( ax==15 &&           ay==46 ) ||
00553             ( ax<=25 && ax>=16 && ay==45 ) ||
00554             ( ax==25 &&           ay<=44 && ay>=43 ) ||
00555             ( ax<=30 && ax>=26 && ay==42 ) ||
00556             ( ax==30 &&           ay<=41 && ay>=38 ) ||
00557             ( ax<=35 && ax>=31 && ay==37 ) ||
00558             ( ax==35 &&           ay==36 )              ) ;
00559 }
00560 
00561 bool 
00562 EEDetId::validDetId(int crystal_ix, int crystal_iy, int iz) 
00563 {
00564    bool valid = false;
00565    if (crystal_ix < IX_MIN ||  crystal_ix > IX_MAX ||
00566        crystal_iy < IY_MIN || crystal_iy > IY_MAX || abs(iz) != 1 ) 
00567    { 
00568       return valid ; 
00569    }
00570    if ( (crystal_ix >= 1 && crystal_ix <= 3 && (crystal_iy <= 40 || crystal_iy > 60) ) ||
00571         (crystal_ix >= 4 && crystal_ix <= 5 && (crystal_iy <= 35 || crystal_iy > 65) ) || 
00572         (crystal_ix >= 6 && crystal_ix <= 8 && (crystal_iy <= 25 || crystal_iy > 75) ) || 
00573         (crystal_ix >= 9 && crystal_ix <= 13 && (crystal_iy <= 20 || crystal_iy > 80) ) || 
00574         (crystal_ix >= 14 && crystal_ix <= 15 && (crystal_iy <= 15 || crystal_iy > 85) ) || 
00575         (crystal_ix >= 16 && crystal_ix <= 20 && (crystal_iy <= 13 || crystal_iy > 87) ) || 
00576         (crystal_ix >= 21 && crystal_ix <= 25 && (crystal_iy <= 8 || crystal_iy > 92) ) || 
00577         (crystal_ix >= 26 && crystal_ix <= 35 && (crystal_iy <= 5 || crystal_iy > 95) ) || 
00578         (crystal_ix >= 36 && crystal_ix <= 39 && (crystal_iy <= 3 || crystal_iy > 97) ) || 
00579         (crystal_ix >= 98 && crystal_ix <= 100 && (crystal_iy <= 40 || crystal_iy > 60) ) ||
00580         (crystal_ix >= 96 && crystal_ix <= 97 && (crystal_iy <= 35 || crystal_iy > 65) ) || 
00581         (crystal_ix >= 93 && crystal_ix <= 95 && (crystal_iy <= 25 || crystal_iy > 75) ) || 
00582         (crystal_ix >= 88 && crystal_ix <= 92 && (crystal_iy <= 20 || crystal_iy > 80) ) || 
00583         (crystal_ix >= 86 && crystal_ix <= 87 && (crystal_iy <= 15 || crystal_iy > 85) ) || 
00584         (crystal_ix >= 81 && crystal_ix <= 85 && (crystal_iy <= 13 || crystal_iy > 87) ) || 
00585         (crystal_ix >= 76 && crystal_ix <= 80 && (crystal_iy <= 8 || crystal_iy > 92) ) || 
00586         (crystal_ix >= 66 && crystal_ix <= 75 && (crystal_iy <= 5 || crystal_iy > 95) ) || 
00587         (crystal_ix >= 62 && crystal_ix <= 65 && (crystal_iy <= 3 || crystal_iy > 97) ) ||
00588         ( (crystal_ix == 40 || crystal_ix == 61) && ( (crystal_iy >= 46 && crystal_iy <= 55 ) || crystal_iy <= 3 || crystal_iy > 97 )) ||
00589         ( (crystal_ix == 41 || crystal_ix == 60) && crystal_iy >= 44 && crystal_iy <= 57 ) ||
00590         ( (crystal_ix == 42 || crystal_ix == 59) && crystal_iy >= 43 && crystal_iy <= 58 ) ||
00591         ( (crystal_ix == 43 || crystal_ix == 58) && crystal_iy >= 42 && crystal_iy <= 59 ) ||
00592         ( (crystal_ix == 44 || crystal_ix == 45 || crystal_ix == 57 || crystal_ix == 56) && crystal_iy >= 41 && crystal_iy <= 60 ) ||
00593         ( crystal_ix >= 46 && crystal_ix <= 55 && crystal_iy >= 40 && crystal_iy <= 61 ) 
00594       )
00595    { 
00596       return valid; 
00597    }
00598    valid = true;
00599    return valid;
00600 }
00601 
00602 int EEDetId::distanceX(const EEDetId& a,const EEDetId& b)
00603 {
00604     return abs(a.ix()-b.ix());
00605 }
00606 
00607 int EEDetId::distanceY(const EEDetId& a,const EEDetId& b)
00608 {
00609   return abs(a.iy() - b.iy()); 
00610 }
00611 
00612 std::ostream& operator<<(std::ostream& s,const EEDetId& id) 
00613 {
00614    return s << "(EE iz " << ((id.zside()>0)?("+ "):("- ")) 
00615             << " ix " << id.ix() << " , iy " << id.iy() << ')';
00616 }