CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/DataFormats/EcalDetId/interface/EBDetId.h

Go to the documentation of this file.
00001 #ifndef ECALDETID_EBDETID_H
00002 #define ECALDETID_EBDETID_H
00003 
00004 #include <iosfwd>
00005 #include <cmath>
00006 #include <cstdlib>
00007 #include "DataFormats/DetId/interface/DetId.h"
00008 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
00009 #include "DataFormats/EcalDetId/interface/EcalTrigTowerDetId.h"
00010 
00011 
00020 class EBDetId : public DetId {
00021  public:
00022   enum { Subdet=EcalBarrel};
00024   EBDetId() {}
00026   EBDetId(uint32_t rawid) : DetId(rawid) {}
00029   // fast
00030   EBDetId(  int crystal_ieta, int crystal_iphi) : DetId(Ecal,EcalBarrel) {
00031     id_|=((crystal_ieta>0)?(0x10000|(crystal_ieta<<9)):((-crystal_ieta)<<9))|(crystal_iphi&0x1FF);
00032   }
00033   // slow
00034   EBDetId(int index1, int index2, int mode);
00036   EBDetId(const DetId& id) : DetId(id){}
00038   EBDetId& operator=(const DetId& id) {
00039     id_=id.rawId();
00040   return *this;
00041   }
00042 
00044   // EcalSubdetector subdet() const { return EcalSubdetector(subdetId()); }
00045   static EcalSubdetector subdet() { return EcalBarrel;}
00046 
00048   int zside() const { return (id_&0x10000)?(1):(-1); }
00050   int ietaAbs() const { return (id_>>9)&0x7F; }
00052   int ieta() const { return zside()*ietaAbs(); }
00054   int iphi() const { return id_&0x1FF; }
00056   int tower_ieta() const { return ((ietaAbs()-1)/5+1)*zside(); }
00058   int tower_iphi() const;
00060   EcalTrigTowerDetId tower() const { return EcalTrigTowerDetId(zside(),EcalBarrel,abs(tower_ieta()),tower_iphi()); }
00062   int ism() const  {
00063     int id = ( iphi() - 1 ) / kCrystalsInPhi + 1;
00064     return positiveZ() ? id : id+18;
00065   }
00067   int im() const {
00068     int ii = (ietaAbs()-26);
00069     return ii<0 ? 1 : (ii/20 +2);
00070   }
00072   int ic() const;
00074   int ietaSM() const { return ietaAbs(); }
00076   int iphiSM() const { return (( ic() -1 ) % kCrystalsInPhi ) + 1; }
00077   
00078   // is z positive?
00079   bool positiveZ() const { return id_&0x10000;}
00080   // crystal number in eta-phi grid
00081   int numberByEtaPhi() const { 
00082     return (MAX_IETA + (positiveZ() ? ietaAbs()-1 : -ietaAbs()) )*MAX_IPHI+ iphi()-1;
00083   }
00084   // index numbering crystal by SM
00085   int numberBySM() const; 
00087   int hashedIndex() const { return numberByEtaPhi(); }
00088 
00089   uint32_t denseIndex() const { return hashedIndex() ; }
00090 
00093   EBDetId offsetBy( int nrStepsEta, int nrStepsPhi ) const;
00094 
00097   EBDetId switchZSide() const;
00098  
00102   static DetId offsetBy( const DetId startId, int nrStepsEta, int nrStepsPhi );
00103   static DetId switchZSide( const DetId startId );
00104 
00107   float approxEta() const { return ieta() * crystalUnitToEta; }
00108   static float approxEta( const DetId id );
00109 
00110   static bool validDenseIndex( uint32_t din ) { return ( din < kSizeForDenseIndexing ) ; }
00111 
00112   static EBDetId detIdFromDenseIndex( uint32_t di ) { return unhashIndex( di ) ; }
00113 
00115   static EBDetId unhashIndex( int hi ) {
00116     const int pseudo_eta = hi/MAX_IPHI - MAX_IETA;
00117     return ( validHashIndex( hi ) ?
00118              EBDetId(pseudo_eta<0 ? pseudo_eta :  pseudo_eta+1, hi%MAX_IPHI+1) :
00119              EBDetId() ) ;
00120   }
00121 
00122   static bool validHashIndex(int i) { return !(i<MIN_HASH || i>MAX_HASH); }
00123 
00125   static bool validDetId(int i, int j) {
00126     return i!=0 && (std::abs(i) <= MAX_IETA)
00127       && (j>=MIN_IPHI) && (j <= MAX_IPHI); 
00128   }
00129 
00130   static bool isNextToBoundary(EBDetId id);
00131 
00132   static bool isNextToEtaBoundary(EBDetId id);
00133 
00134   static bool isNextToPhiBoundary(EBDetId id);
00135 
00136   //return the distance in eta units between two EBDetId
00137   static int distanceEta(const EBDetId& a,const EBDetId& b); 
00138   //return the distance in phi units between two EBDetId
00139   static int distancePhi(const EBDetId& a,const EBDetId& b); 
00140 
00142   static const int MIN_IETA = 1;
00143   static const int MIN_IPHI = 1;
00144   static const int MAX_IETA = 85;
00145   static const int MAX_IPHI = 360;
00146   static const int kChannelsPerCard = 5;
00147   static const int kTowersInPhi = 4;  // per SM
00148   static const int kModulesPerSM = 4;
00149   static const int kModuleBoundaries[4] ;
00150   static const int kCrystalsInPhi = 20; // per SM
00151   static const int kCrystalsInEta = 85; // per SM
00152   static const int kCrystalsPerSM = 1700;
00153   static const int MIN_SM = 1;
00154   static const int MAX_SM = 36;
00155   static const int MIN_C = 1;
00156   static const int MAX_C = kCrystalsPerSM;
00157   static const int MIN_HASH =  0; // always 0 ...
00158   static const int MAX_HASH =  2*MAX_IPHI*MAX_IETA-1;
00159 
00160   // eta coverage of one crystal (approximate)
00161   static const float crystalUnitToEta;
00162 
00163   enum { kSizeForDenseIndexing = MAX_HASH + 1 } ;
00164   
00165 
00166   // function modes for (int, int) constructor
00167   static const int ETAPHIMODE = 0;
00168   static const int SMCRYSTALMODE = 1;
00169 };
00170 
00171 std::ostream& operator<<(std::ostream& s,const EBDetId& id);
00172 
00173 
00174 #endif