Go to the documentation of this file.00001 #include "DataFormats/HcalDetId/interface/HcalCastorDetId.h"
00002 #include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
00003 #include "FWCore/Utilities/interface/Exception.h"
00004
00005 HcalCastorDetId::HcalCastorDetId() : DetId() {}
00006
00007 HcalCastorDetId::HcalCastorDetId(uint32_t rawid) : DetId(rawid) {}
00008
00009 void
00010 HcalCastorDetId::buildMe( Section section,
00011 bool true_for_positive_eta,
00012 int sector,
00013 int module )
00014 {
00015 sector -= 1;
00016 id_ |= ( true_for_positive_eta << 8 ) | ( sector << 4 ) | module;
00017 }
00018
00019 HcalCastorDetId::HcalCastorDetId( Section section,
00020 bool true_for_positive_eta,
00021 int sector,
00022 int module )
00023 : DetId(DetId::Calo, SubdetectorId)
00024 {
00025 buildMe( section, true_for_positive_eta, sector, module ) ;
00026 }
00027
00028
00029 HcalCastorDetId::HcalCastorDetId( bool true_for_positive_eta,
00030 int sector,
00031 int module )
00032 : DetId( DetId::Calo, SubdetectorId )
00033 {
00034 buildMe( Section(Unknown), true_for_positive_eta, sector, module ) ;
00035 }
00036
00037 HcalCastorDetId::HcalCastorDetId( const DetId& gen )
00038 {
00039 if( !gen.null() &&
00040 ( gen.det() != DetId::Calo ||
00041 gen.subdetId() != SubdetectorId ) )
00042 {
00043 throw cms::Exception("Invalid DetId") << "Cannot initialize CASTORDetId from " << std::hex << gen.rawId() << std::dec;
00044 }
00045 id_= gen.rawId();
00046 }
00047
00048 HcalCastorDetId&
00049 HcalCastorDetId::operator=( const DetId& gen )
00050 {
00051 if( !gen.null() &&
00052 ( gen.det() != DetId::Calo ||
00053 gen.subdetId() != SubdetectorId ) )
00054 {
00055 throw cms::Exception("Invalid DetId") << "Cannot assign Castor DetId from " << std::hex << gen.rawId() << std::dec;
00056 }
00057
00058 id_ = gen.rawId();
00059
00060 return *this;
00061 }
00062
00063
00064
00065
00066
00067
00068
00069
00070 HcalCastorDetId::Section
00071 HcalCastorDetId::section() const
00072 {
00073 const int mod = module();
00074
00075 Section sect ;
00076 if ( mod <= 2 )
00077 {
00078 sect = HcalCastorDetId::EM ;
00079 }
00080 else
00081 {
00082 if( mod > 2 && mod <= 14 )
00083 {
00084 sect = HcalCastorDetId::HAD ;
00085 }
00086 else
00087 {
00088 sect = HcalCastorDetId::Unknown;
00089 }
00090 }
00091 return sect ;
00092 }
00093
00094 uint32_t
00095 HcalCastorDetId::denseIndex() const
00096 {
00097 return ( kNumberCellsPerEnd*( zside() + 1 )/2 +
00098 kNumberSectorsPerEnd*( module() - 1 ) + sector() - 1 ) ;
00099 }
00100
00101 bool
00102 HcalCastorDetId::validDetId( Section iSection,
00103 bool posEta,
00104 int iSector,
00105 int iModule )
00106 {
00107 return ( 0 < iSector &&
00108 kNumberSectorsPerEnd >= iSector &&
00109 0 < iModule &&
00110 kNumberModulesPerEnd >= iModule ) ;
00111 }
00112
00113 HcalCastorDetId
00114 HcalCastorDetId::detIdFromDenseIndex( uint32_t di )
00115 {
00116 return HcalCastorDetId( kNumberCellsPerEnd <= di ,
00117 di%kNumberSectorsPerEnd + 1 ,
00118 (di%kNumberCellsPerEnd)/kNumberSectorsPerEnd + 1) ;
00119 }
00120
00121 std::ostream& operator<<(std::ostream& s,const HcalCastorDetId& id)
00122 {
00123 s << "(CASTOR" << ((id.zside()==1)?("+"):("-"));
00124
00125 switch (id.section())
00126 {
00127 case(HcalCastorDetId::EM) : s << " EM "; break;
00128 case(HcalCastorDetId::HAD) : s << " HAD "; break;
00129 default : s <<" UNKNOWN ";
00130 }
00131
00132 return s << id.sector() << ',' << id.module() << ',' << ')';
00133 }
00134