Go to the documentation of this file.00001 #include "DataFormats/EcalDetId/interface/EcalScDetId.h"
00002 #include "FWCore/Utilities/interface/Exception.h"
00003
00004 #include <ostream>
00005 #include <cassert>
00006
00007 short EcalScDetId::xyz2HashedIndex[EcalScDetId::IX_MAX][EcalScDetId::IY_MAX][EcalScDetId::nEndcaps];
00008
00009 EcalScDetId EcalScDetId::hashedIndex2DetId[kSizeForDenseIndexing];
00010
00011
00012 EcalScDetId::EcalScDetId() : DetId() {
00013 }
00014
00015 EcalScDetId::EcalScDetId(uint32_t rawid) : DetId(rawid) {
00016 }
00017
00018 EcalScDetId::EcalScDetId(int ix, int iy, int iz) : DetId(Ecal,EcalEndcap)
00019 {
00020 if(!validDetId(ix,iy,iz))
00021 {
00022 throw cms::Exception("InvalidDetId") << "EcalScDetId: Cannot create object. Indexes out of bounds \n"
00023 << "x = " << ix << " y = " << iy << " z = " << iz;
00024 }
00025 const int scBit = 1<<15;
00026
00027 id_|=(iy&0x7f)|((ix&0x7f)<<7)|((iz>0)?(1<<14):(0))|scBit;
00028 }
00029
00030 EcalScDetId::EcalScDetId(const DetId& gen) {
00031 if (!gen.null() && (gen.det()!=Ecal || gen.subdetId()!=EcalEndcap)) {
00032 throw cms::Exception("InvalidDetId");
00033 }
00034 id_=gen.rawId();
00035 }
00036
00037 EcalScDetId& EcalScDetId::operator=(const DetId& gen) {
00038 if (!gen.null() && ( gen.det()!=Ecal || gen.subdetId()!=EcalEndcap )) {
00039 throw cms::Exception("InvalidDetId");
00040 }
00041 id_=gen.rawId();
00042 return *this;
00043 }
00044
00045 int EcalScDetId::iquadrant() const {
00046 const int xMiddle = IX_MAX/2;
00047 const int yMiddle = IY_MAX/2;
00048 if (iy()>yMiddle){
00049 if(ix()>xMiddle)
00050 return 1;
00051 else
00052 return 2;
00053 } else{
00054 if(ix()>xMiddle)
00055 return 4;
00056 else
00057 return 3;
00058 }
00059
00060 return -1;
00061 }
00062
00063 bool EcalScDetId::validDetId(int iX, int iY, int iZ) {
00064 static const char endcapMap[401] = {
00065 " XXXXXX "
00066 " XXXXXXXXXXXX "
00067 " XXXXXXXXXXXXXX "
00068 " XXXXXXXXXXXXXXXX "
00069 " XXXXXXXXXXXXXXXXXX "
00070 " XXXXXXXXXXXXXXXXXX "
00071 " XXXXXXXXXXXXXXXXXX "
00072 "XXXXXXXXXXXXXXXXXXXX"
00073 "XXXXXXXXX XXXXXXXXX"
00074 "XXXXXXXX XXXXXXXX"
00075 "XXXXXXXX XXXXXXXX"
00076 "XXXXXXXXX XXXXXXXXX"
00077 "XXXXXXXXXXXXXXXXXXXX"
00078 " XXXXXXXXXXXXXXXXXX "
00079 " XXXXXXXXXXXXXXXXXX "
00080 " XXXXXXXXXXXXXXXXXX "
00081 " XXXXXXXXXXXXXXXX "
00082 " XXXXXXXXXXXXXX "
00083 " XXXXXXXXXXXX "
00084 " XXXXXX "};
00085
00086 return abs(iZ)==1 && endcapMap[iX-1+(iY-1)*20]!=' ';
00087 }
00088
00089 std::ostream& operator<<(std::ostream& s,const EcalScDetId& id) {
00090 return s << "(EE iz " << ((id.zside()>0)?("+ "):("- ")) << " ix " << id.ix() << " , iy " << id.iy() << ')';
00091 }
00092
00093 void EcalScDetId::checkHashedIndexMap(){
00094 static bool initialized = false;
00095 if(initialized) return;
00096 int hashedIndex = -1;
00097 for(int iZ = -1; iZ <= +1; iZ+=2){
00098 for(int iY = IY_MIN; iY <= IY_MAX; ++iY){
00099 for(int iX = IX_MIN; iX <= IX_MAX; ++iX){
00100 if(validDetId(iX,iY,iZ)){
00101 xyz2HashedIndex[iX-IX_MIN][iY-IY_MIN][iZ>0?1:0] = ++hashedIndex;
00102 assert((unsigned)hashedIndex < sizeof(hashedIndex2DetId)/sizeof(hashedIndex2DetId[0]));
00103 hashedIndex2DetId[hashedIndex] = EcalScDetId(iX, iY, iZ);
00104 }
00105 }
00106 }
00107 }
00108 initialized = true;
00109 }