CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EBDetId.h
Go to the documentation of this file.
1 #ifndef ECALDETID_EBDETID_H
2 #define ECALDETID_EBDETID_H
3 
4 #include <iosfwd>
5 #include <cmath>
6 #include <cstdlib>
10 
11 
20 class EBDetId : public DetId {
21  public:
22  enum { Subdet=EcalBarrel};
24  EBDetId() {}
26  EBDetId(uint32_t rawid) : DetId(rawid) {}
29  // fast
30  EBDetId( int crystal_ieta, int crystal_iphi) : DetId(Ecal,EcalBarrel) {
31  id_|=((crystal_ieta>0)?(0x10000|(crystal_ieta<<9)):((-crystal_ieta)<<9))|(crystal_iphi&0x1FF);
32  }
33  // slow
34  EBDetId(int index1, int index2, int mode);
36  EBDetId(const DetId& id) : DetId(id){}
38  EBDetId& operator=(const DetId& id) {
39  id_=id.rawId();
40  return *this;
41  }
42 
44  // EcalSubdetector subdet() const { return EcalSubdetector(subdetId()); }
45  static EcalSubdetector subdet() { return EcalBarrel;}
46 
48  int zside() const { return (id_&0x10000)?(1):(-1); }
50  int ietaAbs() const { return (id_>>9)&0x7F; }
52  int ieta() const { return zside()*ietaAbs(); }
54  int iphi() const { return id_&0x1FF; }
56  int tower_ieta() const { return ((ietaAbs()-1)/5+1)*zside(); }
58  int tower_iphi() const;
62  int ism() const {
63  int id = ( iphi() - 1 ) / kCrystalsInPhi + 1;
64  return positiveZ() ? id : id+18;
65  }
67  int im() const {
68  int ii = (ietaAbs()-26);
69  return ii<0 ? 1 : (ii/20 +2);
70  }
72  int ic() const;
74  int ietaSM() const { return ietaAbs(); }
76  int iphiSM() const { return (( ic() -1 ) % kCrystalsInPhi ) + 1; }
77 
78  // is z positive?
79  bool positiveZ() const { return id_&0x10000;}
80  // crystal number in eta-phi grid
81  int numberByEtaPhi() const {
82  return (MAX_IETA + (positiveZ() ? ietaAbs()-1 : -ietaAbs()) )*MAX_IPHI+ iphi()-1;
83  }
84  // index numbering crystal by SM
85  int numberBySM() const;
87  int hashedIndex() const { return numberByEtaPhi(); }
88 
89  uint32_t denseIndex() const { return hashedIndex() ; }
90 
93  EBDetId offsetBy( int nrStepsEta, int nrStepsPhi ) const;
94 
97  EBDetId switchZSide() const;
98 
102  static DetId offsetBy( const DetId startId, int nrStepsEta, int nrStepsPhi );
103  static DetId switchZSide( const DetId startId );
104 
107  float approxEta() const { return ieta() * crystalUnitToEta; }
108  static float approxEta( const DetId id );
109 
110  static bool validDenseIndex( uint32_t din ) { return ( din < kSizeForDenseIndexing ) ; }
111 
112  static EBDetId detIdFromDenseIndex( uint32_t di ) { return unhashIndex( di ) ; }
113 
115  static EBDetId unhashIndex( int hi ) {
116  const int pseudo_eta = hi/MAX_IPHI - MAX_IETA;
117  return ( validHashIndex( hi ) ?
118  EBDetId(pseudo_eta<0 ? pseudo_eta : pseudo_eta+1, hi%MAX_IPHI+1) :
119  EBDetId() ) ;
120  }
121 
122  static bool validHashIndex(int i) { return !(i<MIN_HASH || i>MAX_HASH); }
123 
125  static bool validDetId(int i, int j) {
126  return i!=0 && (std::abs(i) <= MAX_IETA)
127  && (j>=MIN_IPHI) && (j <= MAX_IPHI);
128  }
129 
130  static bool isNextToBoundary(EBDetId id);
131 
132  static bool isNextToEtaBoundary(EBDetId id);
133 
134  static bool isNextToPhiBoundary(EBDetId id);
135 
136  //return the distance in eta units between two EBDetId
137  static int distanceEta(const EBDetId& a,const EBDetId& b);
138  //return the distance in phi units between two EBDetId
139  static int distancePhi(const EBDetId& a,const EBDetId& b);
140 
142  static const int MIN_IETA = 1;
143  static const int MIN_IPHI = 1;
144  static const int MAX_IETA = 85;
145  static const int MAX_IPHI = 360;
146  static const int kChannelsPerCard = 5;
147  static const int kTowersInPhi = 4; // per SM
148  static const int kModulesPerSM = 4;
149  static const int kModuleBoundaries[4] ;
150  static const int kCrystalsInPhi = 20; // per SM
151  static const int kCrystalsInEta = 85; // per SM
152  static const int kCrystalsPerSM = 1700;
153  static const int MIN_SM = 1;
154  static const int MAX_SM = 36;
155  static const int MIN_C = 1;
156  static const int MAX_C = kCrystalsPerSM;
157  static const int MIN_HASH = 0; // always 0 ...
158  static const int MAX_HASH = 2*MAX_IPHI*MAX_IETA-1;
159 
160  // eta coverage of one crystal (approximate)
161  static const float crystalUnitToEta;
162 
164 
165 
166  // function modes for (int, int) constructor
167  static const int ETAPHIMODE = 0;
168  static const int SMCRYSTALMODE = 1;
169 };
170 
171 std::ostream& operator<<(std::ostream& s,const EBDetId& id);
172 
173 
174 #endif
float approxEta() const
Definition: EBDetId.h:107
int i
Definition: DBlmapReader.cc:9
int hashedIndex() const
get a compact index for arrays
Definition: EBDetId.h:87
static const int MIN_IPHI
Definition: EBDetId.h:143
static bool isNextToEtaBoundary(EBDetId id)
Definition: EBDetId.cc:125
static EcalSubdetector subdet()
get the subdetector .i.e EcalBarrel (what else?)
Definition: EBDetId.h:45
static const int kCrystalsInEta
Definition: EBDetId.h:151
static const int MAX_HASH
Definition: EBDetId.h:158
int tower_ieta() const
get the HCAL/trigger ieta of this crystal
Definition: EBDetId.h:56
int tower_iphi() const
get the HCAL/trigger iphi of this crystal
Definition: EBDetId.cc:114
EBDetId switchZSide() const
Definition: EBDetId.cc:82
#define abs(x)
Definition: mlp_lapack.h:159
static const int MIN_IETA
range constants
Definition: EBDetId.h:142
int numberBySM() const
Definition: EBDetId.cc:57
static const int kTowersInPhi
Definition: EBDetId.h:147
static const int kCrystalsPerSM
Definition: EBDetId.h:152
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
int ii
Definition: cuy.py:588
EBDetId()
Definition: EBDetId.h:24
int ism() const
get the ECAL/SM id
Definition: EBDetId.h:62
int iphiSM() const
get the crystal iphi (1-20)
Definition: EBDetId.h:76
static bool validDetId(int i, int j)
check if a valid index combination
Definition: EBDetId.h:125
static const int MIN_C
Definition: EBDetId.h:155
static const int MIN_SM
Definition: EBDetId.h:153
int iphi() const
get the crystal iphi
Definition: EBDetId.h:54
static EBDetId detIdFromDenseIndex(uint32_t di)
Definition: EBDetId.h:112
EBDetId(const DetId &id)
Definition: EBDetId.h:36
EBDetId(uint32_t rawid)
Definition: EBDetId.h:26
int im() const
get the number of module inside the SM (1-4)
Definition: EBDetId.h:67
static const int kCrystalsInPhi
Definition: EBDetId.h:150
static const int MAX_C
Definition: EBDetId.h:156
static int distanceEta(const EBDetId &a, const EBDetId &b)
Definition: EBDetId.cc:135
static bool isNextToBoundary(EBDetId id)
Definition: EBDetId.cc:121
static const int MIN_HASH
Definition: EBDetId.h:157
static int distancePhi(const EBDetId &a, const EBDetId &b)
Definition: EBDetId.cc:143
static bool isNextToPhiBoundary(EBDetId id)
Definition: EBDetId.cc:130
static const int kModulesPerSM
Definition: EBDetId.h:148
int j
Definition: DBlmapReader.cc:9
static const int kModuleBoundaries[4]
Definition: EBDetId.h:149
static const float crystalUnitToEta
Definition: EBDetId.h:161
EcalTrigTowerDetId tower() const
get the HCAL/trigger iphi of this crystal
Definition: EBDetId.h:60
EBDetId offsetBy(int nrStepsEta, int nrStepsPhi) const
Definition: EBDetId.cc:61
int ieta() const
get the crystal ieta
Definition: EBDetId.h:52
EBDetId(int crystal_ieta, int crystal_iphi)
Definition: EBDetId.h:30
static const int ETAPHIMODE
Definition: EBDetId.h:167
int ic() const
get ECAL/crystal number inside SM
Definition: EBDetId.cc:46
int numberByEtaPhi() const
Definition: EBDetId.h:81
Definition: DetId.h:20
bool positiveZ() const
Definition: EBDetId.h:79
static const int MAX_IPHI
Definition: EBDetId.h:145
uint32_t id_
Definition: DetId.h:57
static const int MAX_IETA
Definition: EBDetId.h:144
double b
Definition: hdecay.h:120
static const int kChannelsPerCard
Definition: EBDetId.h:146
static bool validHashIndex(int i)
Definition: EBDetId.h:122
int ietaSM() const
get the crystal ieta in the SM convention (1-85)
Definition: EBDetId.h:74
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:115
double a
Definition: hdecay.h:121
EBDetId & operator=(const DetId &id)
Definition: EBDetId.h:38
static const int MAX_SM
Definition: EBDetId.h:154
static const int SMCRYSTALMODE
Definition: EBDetId.h:168
EcalSubdetector
int ietaAbs() const
get the absolute value of the crystal ieta
Definition: EBDetId.h:50
uint32_t denseIndex() const
Definition: EBDetId.h:89
static bool validDenseIndex(uint32_t din)
Definition: EBDetId.h:110
int zside() const
get the z-side of the crystal (1/-1)
Definition: EBDetId.h:48