CMS 3D CMS Logo

EcalScDetId.cc

Go to the documentation of this file.
00001 #include "DataFormats/EcalDetId/interface/EcalScDetId.h"
00002 #include "FWCore/Utilities/interface/Exception.h"
00003 
00004 #include <iostream>
00005 const int EcalScDetId::QuadColLimits[EcalScDetId::nCols+1] = { 0, 8,17,27,36,45,54,62,70,76,79 };
00006 const int EcalScDetId::iYoffset[EcalScDetId::nCols+1]      = { 0, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0 };
00007 
00008 EcalScDetId::EcalScDetId() : DetId() {
00009 }
00010 EcalScDetId::EcalScDetId(uint32_t rawid) : DetId(rawid) {
00011 }
00012 EcalScDetId::EcalScDetId(int ix, int iy, int iz) : DetId(Ecal,EcalEndcap) 
00013 {
00014   if(!validDetId(ix,iy,iz))
00015     {
00016       throw cms::Exception("InvalidDetId") << "EcalScDetId:  Cannot create object.  Indexes out of bounds \n" 
00017                                            << "x = " << ix << " y = " << iy << " z = " << iz;
00018     }
00019   const int scBit = 1<<15; //bit set to 1 to distinguish from crystal id (EEDetId)
00020   //                         and for a reasonale behaviour of DetId ccomparison operators.
00021   id_|=(iy&0x7f)|((ix&0x7f)<<7)|((iz>0)?(1<<14):(0))|scBit;
00022 }
00023   
00024 EcalScDetId::EcalScDetId(const DetId& gen) {
00025   if (!gen.null() && (gen.det()!=Ecal || gen.subdetId()!=EcalEndcap)) {
00026     throw cms::Exception("InvalidDetId"); 
00027   }
00028   id_=gen.rawId();
00029 }
00030   
00031 EcalScDetId& EcalScDetId::operator=(const DetId& gen) {
00032   if (!gen.null() && ( gen.det()!=Ecal || gen.subdetId()!=EcalEndcap )) {
00033     throw cms::Exception("InvalidDetId"); 
00034   }
00035   id_=gen.rawId();
00036   return *this;
00037 }
00038   
00039 int EcalScDetId::hashedIndex() const {
00040   return ((zside()>0)?(IX_MAX*IY_MAX):(0))+(iy()-1)*IX_MAX+(ix()-1);
00041 }
00042 
00043 int EcalScDetId::ixQuadrantOne() const
00044 { 
00045   int iQuadrant = iquadrant();
00046   if ( iQuadrant == 1 || iQuadrant == 4)
00047     return (ix() - 10);
00048   else if ( iQuadrant == 2 || iQuadrant == 3)
00049     return (11 - ix());
00050   //Should never be reached
00051   return -1;
00052 }
00053 
00054 int EcalScDetId::iyQuadrantOne() const
00055 { 
00056   int iQuadrant = iquadrant();
00057   if ( iQuadrant == 1 || iQuadrant == 2)
00058     return (iy() - 10);
00059   else if ( iQuadrant == 3 || iQuadrant == 4)
00060     return 11 - iy();
00061   //Should never be reached
00062   return -1;
00063 }
00064 
00065 int EcalScDetId::iquadrant() const {
00066   if (ix()>10)
00067     {
00068       if(iy()>10)
00069         return 1;
00070       else
00071         return 4;
00072     }
00073   else
00074     {
00075       if(iy()>10)
00076         return 2;
00077       else
00078         return 3;
00079     }
00080   //Should never be reached
00081   return -1;
00082 }  
00083 
00084 int EcalScDetId::isc() const 
00085 {
00086   /*
00087    *  Return SC number from (x,y) coordinates.
00088    *
00089    *  Copied from code originally written by B W Kennedy
00090    */
00091   
00092   int iCol = ix();
00093   int iRow = iy();
00094   int nSCinQuadrant = QuadColLimits[nCols];
00095   int iSC;
00096   
00097   if (iRow <= iYoffset[iCol]) 
00098     return -1;
00099   else 
00100     iSC = QuadColLimits[iCol-1] + iRow - iYoffset[iCol];
00101 
00102   if (iSC > QuadColLimits[iCol]) 
00103     return -2;
00104   
00105   if (iSC>0) 
00106       iSC += nSCinQuadrant*(iquadrant()-1);
00107   
00108   return iSC;
00109 }  
00110 
00111 bool EcalScDetId::validDetId(int iX, int iY, int iZ) {
00112   static const char endcapMap[401] = {
00113     "       XXXXXX       "
00114     "    XXXXXXXXXXXX    "
00115     "   XXXXXXXXXXXXXX   "
00116     "  XXXXXXXXXXXXXXXX  "
00117     " XXXXXXXXXXXXXXXXXX "
00118     " XXXXXXXXXXXXXXXXXX "             //    Z
00119     " XXXXXXXXXXXXXXXXXX "             //     x-----> X
00120     "XXXXXXXXXXXXXXXXXXXX"             //     |
00121     "XXXXXXXXX  XXXXXXXXX"             //     |
00122     "XXXXXXXX    XXXXXXXX"//_          //     |
00123     "XXXXXXXX    XXXXXXXX"             //     V Y
00124     "XXXXXXXXX  XXXXXXXXX"
00125     "XXXXXXXXXXXXXXXXXXXX"
00126     " XXXXXXXXXXXXXXXXXX "
00127     " XXXXXXXXXXXXXXXXXX "
00128     " XXXXXXXXXXXXXXXXXX "
00129     "  XXXXXXXXXXXXXXXX  "
00130     "   XXXXXXXXXXXXXX   "
00131     "    XXXXXXXXXXXX    "
00132     "       XXXXXX       "};
00133 
00134   return abs(iZ)==1 && endcapMap[iX-1+(iY-1)*20]!=' ';
00135 }
00136 
00137 std::ostream& operator<<(std::ostream& s,const EcalScDetId& id) {
00138   return s << "(EE iz " << ((id.zside()>0)?("+ "):("- ")) << " ix " << id.ix() << " , iy " << id.iy() << ')';
00139 }

Generated on Tue Jun 9 17:30:41 2009 for CMSSW by  doxygen 1.5.4