CMS 3D CMS Logo

HcalDetId.cc

Go to the documentation of this file.
00001 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00002 #include "FWCore/Utilities/interface/Exception.h"
00003 
00004 const HcalDetId HcalDetId::Undefined(HcalEmpty,0,0,0);
00005 
00006 HcalDetId::HcalDetId() : DetId() {
00007 }
00008 
00009 HcalDetId::HcalDetId(uint32_t rawid) : DetId(rawid) {
00010 }
00011 
00012 HcalDetId::HcalDetId(HcalSubdetector subdet, int tower_ieta, int tower_iphi, int depth) : DetId(Hcal,subdet) {
00013   // (no checking at this point!)
00014   id_ |= ((depth&0x7)<<14) |
00015     ((tower_ieta>0)?(0x2000|(tower_ieta<<7)):((-tower_ieta)<<7)) |
00016     (tower_iphi&0x7F);
00017 }
00018 
00019 HcalDetId::HcalDetId(const DetId& gen) {
00020   if (!gen.null()) {
00021     HcalSubdetector subdet=(HcalSubdetector(gen.subdetId()));
00022     if (gen.det()!=Hcal || 
00023         (subdet!=HcalBarrel && subdet!=HcalEndcap && 
00024          subdet!=HcalOuter && subdet!=HcalForward ))
00025       {
00026         throw cms::Exception("Invalid DetId") << "Cannot initialize HcalDetId from " << std::hex << gen.rawId() << std::dec; 
00027       }  
00028   }
00029   id_=gen.rawId();
00030 }
00031 
00032 HcalDetId& HcalDetId::operator=(const DetId& gen) {
00033   if (!gen.null()) {
00034     HcalSubdetector subdet=(HcalSubdetector(gen.subdetId()));
00035     if (gen.det()!=Hcal || 
00036         (subdet!=HcalBarrel && subdet!=HcalEndcap && 
00037          subdet!=HcalOuter && subdet!=HcalForward ))
00038       {
00039         throw cms::Exception("Invalid DetId") << "Cannot assign HcalDetId from " << std::hex << gen.rawId() << std::dec; 
00040       }  
00041   }
00042   id_=gen.rawId();
00043   return (*this);
00044 }
00045 
00046 int HcalDetId::crystal_iphi_low() const { 
00047   int simple_iphi=((iphi()-1)*5)+1; 
00048   simple_iphi+=10;
00049   return ((simple_iphi>360)?(simple_iphi-360):(simple_iphi));
00050 }
00051 
00052 int HcalDetId::crystal_iphi_high() const { 
00053   int simple_iphi=((iphi()-1)*5)+5; 
00054   simple_iphi+=10;
00055   return ((simple_iphi>360)?(simple_iphi-360):(simple_iphi));
00056 }
00057 
00058 std::ostream& operator<<(std::ostream& s,const HcalDetId& id) {
00059   switch (id.subdet()) {
00060   case(HcalBarrel) : return s << "(HB " << id.ieta() << ',' << id.iphi() << ',' << id.depth() << ')';
00061   case(HcalEndcap) : return s << "(HE " << id.ieta() << ',' << id.iphi() << ',' << id.depth() << ')';
00062   case(HcalForward) : return s << "(HF " << id.ieta() << ',' << id.iphi() << ',' << id.depth() << ')';
00063   case(HcalOuter) : return s << "(HO " << id.ieta() << ',' << id.iphi() << ')';
00064   default : return s << id.rawId();
00065   }
00066 }
00067 
00068 bool 
00069 HcalDetId::validDetId( HcalSubdetector sd,
00070                        int             ies,
00071                        int             ip,
00072                        int             dp      ) 
00073 {
00074    const int ie ( abs( ies ) ) ;
00075 
00076    return ( ( ip >=  1         ) &&
00077             ( ip <= 72         ) &&
00078             ( dp >=  1         ) &&
00079             ( ie >=  1         ) &&
00080             ( ( ( sd == HcalBarrel ) &&
00081                 ( ( ( ie <= 14         ) &&
00082                     ( dp ==  1         )    ) ||
00083                   ( ( ( ie == 15 ) || ( ie == 16 ) ) && 
00084                     ( dp <= 2          )                ) ) ) ||
00085               (  ( sd == HcalEndcap ) &&
00086                  ( ( ( ie == 16 ) &&
00087                      ( dp ==  3 )          ) ||
00088                    ( ( ie == 17 ) &&
00089                      ( dp ==  1 )          ) ||
00090                    ( ( ie >= 18 ) &&
00091                      ( ie <= 20 ) &&
00092                      ( dp <=  2 )          ) ||
00093                    ( ( ie >= 21 ) &&
00094                      ( ie <= 26 ) &&
00095                      ( dp <=  2 ) &&
00096                      ( ip%2 == 1 )         ) ||
00097                    ( ( ie >= 27 ) &&
00098                      ( ie <= 28 ) &&
00099                      ( dp <=  3 ) &&
00100                      ( ip%2 == 1 )         ) ||
00101                    ( ( ie == 29 ) &&
00102                      ( dp <=  2 ) &&
00103                      ( ip%2 == 1 )         )          )      ) ||
00104               (  ( sd == HcalOuter ) &&
00105                  ( ie <= 15 ) &&
00106                  ( dp ==  4 )           ) ||
00107               (  ( sd == HcalForward ) &&
00108                  ( dp <=  2 )          &&
00109                  ( ( ( ie >= 29 ) &&
00110                      ( ie <= 39 ) &&
00111                      ( ip%2 == 1 )    ) ||
00112                    ( ( ie >= 40 ) &&
00113                      ( ie <= 41 ) &&
00114                      ( ip%4 == 3 )         )  ) ) ) ) ;
00115 }
00116 
00117 int 
00118 HcalDetId::hashed_index() const 
00119 {
00120    const HcalSubdetector sd ( subdet()  ) ;
00121    const int             ip ( iphi()    ) ;
00122    const int             ie ( ietaAbs() ) ;
00123    const int             dp ( depth()   ) ;
00124    const int             zn ( zside() < 0 ? 1 : 0 ) ;
00125 
00126    // HB valid DetIds: phi=1-72,eta=1-14,depth=1; phi=1-72,eta=15-16,depth=1-2
00127   
00128    // HE valid DetIds: phi=1-72,eta=16-17,depth=1; phi=1-72,eta=18-20,depth=1-2; 
00129    //                  phi=1-71(in steps of 2),eta=21-26,depth=1-2; phi=1-71(in steps of 2),eta=27-28,depth=1-3
00130    //                  phi=1-71(in steps of 2),eta=29,depth=1-2
00131 
00132    // HO valid DetIds: phi=1-72,eta=1-15,depth=4!
00133 
00134    // HF valid DetIds: phi=1-71(in steps of 2),eta=29-39,depth=1-2; phi=3-71(in steps of 4),eta=40-41,depth=1-2
00135 
00136    return ( ( sd == HcalBarrel ) ?
00137             ( ip - 1 )*18 + dp - 1 + ie - ( ie<16 ? 1 : 0 ) + zn*kHBhalf :
00138             ( ( sd == HcalEndcap ) ?
00139               2*kHBhalf + ( ip - 1 )*8 + ( ip/2 )*20 +
00140               ( ( ie==16 || ie==17 ) ? ie - 16 :
00141                 ( ( ie>=18 && ie<=20 ) ? 2 + 2*( ie - 18 ) + dp - 1 :
00142                   ( ( ie>=21 && ie<=26 ) ? 8 + 2*( ie - 21 ) + dp - 1 :
00143                     ( ( ie>=27 && ie<=28 ) ? 20 + 3*( ie - 27 ) + dp - 1 :
00144                       26 + 2*( ie - 29 ) + dp - 1 ) ) ) ) + zn*kHEhalf :
00145               ( ( sd == HcalOuter ) ?
00146                 2*kHBhalf + 2*kHEhalf + ( ip - 1 )*15 + ( ie - 1 ) + zn*kHOhalf :
00147                 ( ( sd == HcalForward ) ?
00148                   2*kHBhalf + 2*kHEhalf + 2*kHOhalf + 
00149                   ( ( ip - 1 )/4 )*4 + ( ( ip - 1 )/2 )*22 + 
00150                   2*( ie - 29 ) + ( dp - 1 ) + zn*kHFhalf : -1 ) ) ) ) ; 
00151 }
00152 
00153 HcalDetId 
00154 HcalDetId::detIdFromDenseIndex( uint32_t di )
00155 {
00156     if( validDenseIndex( di ) )
00157     {
00158       HcalSubdetector sd ( HcalBarrel ) ;
00159       int ie ( 0 ) ;
00160       int ip ( 0 ) ;
00161       int dp ( 0 ) ;
00162       int in ( di ) ;
00163       int iz ( 1 ) ;
00164       if( in > 2*( kHBhalf + kHEhalf + kHOhalf ) - 1 )
00165       {
00166          sd  = HcalForward ;
00167          in -= 2*( kHBhalf + kHEhalf + kHOhalf ) ; 
00168          iz  = ( in<kHFhalf ? 1 : -1 ) ;
00169          in %= kHFhalf ; 
00170          ip  = 4*( in/48 ) ;
00171          in %= 48 ;
00172          ip += 1 + ( in>21 ? 2 : 0 ) ;
00173          if( 3 == ip%4 ) in -= 22 ;
00174          ie  = 29 + in/2 ;
00175          dp  = 1 + in%2 ;
00176       }
00177       else
00178       {
00179          if( in > 2*( kHBhalf + kHEhalf ) - 1 )
00180          {
00181             sd  = HcalOuter ;
00182             in -= 2*( kHBhalf + kHEhalf ) ; 
00183             iz  = ( in<kHOhalf ? 1 : -1 ) ;
00184             in %= kHOhalf ; 
00185             dp  = 4 ;
00186             ip  = 1 + in/15 ;
00187             ie  = 1 + ( in - 15*( ip - 1 ) ) ;
00188          }
00189          else
00190          {
00191             if( in > 2*kHBhalf - 1 )
00192             {
00193                sd  = HcalEndcap ;
00194                in -= 2*kHBhalf ;
00195                iz  = ( in<kHEhalf ? 1 : -1 ) ;
00196                in %= kHEhalf ; 
00197                ip  = 2*( in/36 ) ;
00198                in %= 36 ;
00199                ip += 1 + in/28 ;
00200                if( 0 == ip%2 ) in %= 28 ;
00201                ie  = 15 + ( in<2 ? 1 + in : 2 + 
00202                             ( in<20 ? 1 + ( in - 2 )/2 : 9 +
00203                               ( in<26 ? 1 + ( in - 20 )/3 : 3 ) ) ) ;
00204                dp  = ( in<1 ? 3 :
00205                        ( in<2 ? 1 : 
00206                          ( in<20 ? 1 + ( in - 2 )%2 : 
00207                            ( in<26 ? 1 + ( in - 20 )%3 : 
00208                              ( 1 + ( in - 26 )%2 ) ) ) ) ) ;
00209             }
00210             else // barrel
00211             {
00212                iz  = ( di<kHBhalf ? 1 : -1 ) ;
00213                in %= kHBhalf ; 
00214                ip = in/18 + 1 ;
00215                in %= 18 ;
00216                if( in < 14 )
00217                {
00218                   dp = 1 ;
00219                   ie = in + 1 ;
00220                }
00221                else
00222                {
00223                   in %= 14 ;
00224                   dp =  1 + in%2 ;
00225                   ie = 15 + in/2 ;
00226                }
00227             }
00228          }
00229       }
00230       return HcalDetId( sd, iz*int(ie), ip, dp ) ;
00231    }
00232    else
00233    {
00234       return HcalDetId() ;
00235    }
00236 }

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