CMS 3D CMS Logo

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 
19 class EBDetId : public DetId {
20  public:
21  enum { Subdet=EcalBarrel};
23  EBDetId() {}
25  EBDetId(uint32_t rawid) : DetId(rawid) {}
28  // fast
29  EBDetId( int crystal_ieta, int crystal_iphi) : DetId(Ecal,EcalBarrel) {
30  id_|=((crystal_ieta>0)?(0x10000|(crystal_ieta<<9)):((-crystal_ieta)<<9))|(crystal_iphi&0x1FF);
31  }
32  // slow
33  EBDetId(int index1, int index2, int mode);
35  EBDetId(const DetId& id) : DetId(id){}
37  EBDetId& operator=(const DetId& id) {
38  id_=id.rawId();
39  return *this;
40  }
41 
43  // EcalSubdetector subdet() const { return EcalSubdetector(subdetId()); }
44  static EcalSubdetector subdet() { return EcalBarrel;}
45 
47  int zside() const { return (id_&0x10000)?(1):(-1); }
49  int ietaAbs() const { return (id_>>9)&0x7F; }
51  int ieta() const { return zside()*ietaAbs(); }
53  int iphi() const { return id_&0x1FF; }
55  int tower_ieta() const { return ((ietaAbs()-1)/5+1)*zside(); }
57  int tower_iphi() const;
61  int ism() const {
62  int id = ( iphi() - 1 ) / kCrystalsInPhi + 1;
63  return positiveZ() ? id : id+18;
64  }
66  int im() const {
67  int ii = (ietaAbs()-26);
68  return ii<0 ? 1 : (ii/20 +2);
69  }
71  int ic() const;
73  int ietaSM() const { return ietaAbs(); }
75  int iphiSM() const { return (( ic() -1 ) % kCrystalsInPhi ) + 1; }
76 
77  // is z positive?
78  bool positiveZ() const { return id_&0x10000;}
79  // crystal number in eta-phi grid
80  int numberByEtaPhi() const {
81  return (MAX_IETA + (positiveZ() ? ietaAbs()-1 : -ietaAbs()) )*MAX_IPHI+ iphi()-1;
82  }
83  // index numbering crystal by SM
84  int numberBySM() const;
86  int hashedIndex() const { return numberByEtaPhi(); }
87 
88  uint32_t denseIndex() const { return hashedIndex() ; }
89 
92  EBDetId offsetBy( int nrStepsEta, int nrStepsPhi ) const;
93 
96  EBDetId switchZSide() const;
97 
101  static DetId offsetBy( const DetId startId, int nrStepsEta, int nrStepsPhi );
102  static DetId switchZSide( const DetId startId );
103 
106  float approxEta() const { return ieta() * crystalUnitToEta; }
107  static float approxEta( const DetId id );
108 
109  static bool validDenseIndex( uint32_t din ) { return ( din < kSizeForDenseIndexing ) ; }
110 
111  static EBDetId detIdFromDenseIndex( uint32_t di ) { return unhashIndex( di ) ; }
112 
114  static EBDetId unhashIndex( int hi ) {
115  const int pseudo_eta = hi/MAX_IPHI - MAX_IETA;
116  return ( validHashIndex( hi ) ?
117  EBDetId(pseudo_eta<0 ? pseudo_eta : pseudo_eta+1, hi%MAX_IPHI+1) :
118  EBDetId() ) ;
119  }
120 
121  static bool validHashIndex(int i) { return !(i<MIN_HASH || i>MAX_HASH); }
122 
124  static bool validDetId(int i, int j) {
125  return i!=0 && (std::abs(i) <= MAX_IETA)
126  && (j>=MIN_IPHI) && (j <= MAX_IPHI);
127  }
128 
129  static bool isNextToBoundary(EBDetId id);
130 
131  static bool isNextToEtaBoundary(EBDetId id);
132 
133  static bool isNextToPhiBoundary(EBDetId id);
134 
135  //return the distance in eta units between two EBDetId
136  static int distanceEta(const EBDetId& a,const EBDetId& b);
137  //return the distance in phi units between two EBDetId
138  static int distancePhi(const EBDetId& a,const EBDetId& b);
139 
141  static const int MIN_IETA = 1;
142  static const int MIN_IPHI = 1;
143  static const int MAX_IETA = 85;
144  static const int MAX_IPHI = 360;
145  static const int kChannelsPerCard = 5;
146  static const int kTowersInPhi = 4; // per SM
147  static const int kModulesPerSM = 4;
148  static const int kModuleBoundaries[4] ;
149  static const int kCrystalsInPhi = 20; // per SM
150  static const int kCrystalsInEta = 85; // per SM
151  static const int kCrystalsPerSM = 1700;
152  static const int MIN_SM = 1;
153  static const int MAX_SM = 36;
154  static const int MIN_C = 1;
155  static const int MAX_C = kCrystalsPerSM;
156  static const int MIN_HASH = 0; // always 0 ...
157  static const int MAX_HASH = 2*MAX_IPHI*MAX_IETA-1;
158 
159  // eta coverage of one crystal (approximate)
160  static const float crystalUnitToEta;
161 
162  enum { kSizeForDenseIndexing = MAX_HASH + 1 } ;
163 
164 
165  // function modes for (int, int) constructor
166  static const int ETAPHIMODE = 0;
167  static const int SMCRYSTALMODE = 1;
168 };
169 
170 std::ostream& operator<<(std::ostream& s,const EBDetId& id);
171 
172 
173 #endif
float approxEta() const
Definition: EBDetId.h:106
int hashedIndex() const
get a compact index for arrays
Definition: EBDetId.h:86
static const int MIN_IPHI
Definition: EBDetId.h:142
static bool isNextToEtaBoundary(EBDetId id)
Definition: EBDetId.cc:125
static EcalSubdetector subdet()
get the subdetector .i.e EcalBarrel (what else?)
Definition: EBDetId.h:44
static const int kCrystalsInEta
Definition: EBDetId.h:150
static const int MAX_HASH
Definition: EBDetId.h:157
int tower_ieta() const
get the HCAL/trigger ieta of this crystal
Definition: EBDetId.h:55
int tower_iphi() const
get the HCAL/trigger iphi of this crystal
Definition: EBDetId.cc:114
EBDetId switchZSide() const
Definition: EBDetId.cc:82
static const int MIN_IETA
range constants
Definition: EBDetId.h:141
int numberBySM() const
Definition: EBDetId.cc:57
static const int kTowersInPhi
Definition: EBDetId.h:146
static const int kCrystalsPerSM
Definition: EBDetId.h:151
EBDetId()
Definition: EBDetId.h:23
int ism() const
get the ECAL/SM id
Definition: EBDetId.h:61
int iphiSM() const
get the crystal iphi (1-20)
Definition: EBDetId.h:75
static bool validDetId(int i, int j)
check if a valid index combination
Definition: EBDetId.h:124
static const int MIN_C
Definition: EBDetId.h:154
static const int MIN_SM
Definition: EBDetId.h:152
int iphi() const
get the crystal iphi
Definition: EBDetId.h:53
static EBDetId detIdFromDenseIndex(uint32_t di)
Definition: EBDetId.h:111
EBDetId(const DetId &id)
Definition: EBDetId.h:35
EBDetId(uint32_t rawid)
Definition: EBDetId.h:25
int im() const
get the number of module inside the SM (1-4)
Definition: EBDetId.h:66
static const int kCrystalsInPhi
Definition: EBDetId.h:149
static const int MAX_C
Definition: EBDetId.h:155
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:156
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:147
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static const int kModuleBoundaries[4]
Definition: EBDetId.h:148
static const float crystalUnitToEta
Definition: EBDetId.h:160
EcalTrigTowerDetId tower() const
get the HCAL/trigger iphi of this crystal
Definition: EBDetId.h:59
EBDetId offsetBy(int nrStepsEta, int nrStepsPhi) const
Definition: EBDetId.cc:61
int ieta() const
get the crystal ieta
Definition: EBDetId.h:51
EBDetId(int crystal_ieta, int crystal_iphi)
Definition: EBDetId.h:29
static const int ETAPHIMODE
Definition: EBDetId.h:166
int ic() const
get ECAL/crystal number inside SM
Definition: EBDetId.cc:46
ii
Definition: cuy.py:588
std::ostream & operator<<(std::ostream &s, const EBDetId &id)
Definition: EBDetId.cc:164
int numberByEtaPhi() const
Definition: EBDetId.h:80
Definition: DetId.h:18
bool positiveZ() const
Definition: EBDetId.h:78
static const int MAX_IPHI
Definition: EBDetId.h:144
uint32_t id_
Definition: DetId.h:56
static const int MAX_IETA
Definition: EBDetId.h:143
double b
Definition: hdecay.h:120
static const int kChannelsPerCard
Definition: EBDetId.h:145
static bool validHashIndex(int i)
Definition: EBDetId.h:121
int ietaSM() const
get the crystal ieta in the SM convention (1-85)
Definition: EBDetId.h:73
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:114
double a
Definition: hdecay.h:121
EBDetId & operator=(const DetId &id)
Definition: EBDetId.h:37
static const int MAX_SM
Definition: EBDetId.h:153
static const int SMCRYSTALMODE
Definition: EBDetId.h:167
EcalSubdetector
int ietaAbs() const
get the absolute value of the crystal ieta
Definition: EBDetId.h:49
uint32_t denseIndex() const
Definition: EBDetId.h:88
static bool validDenseIndex(uint32_t din)
Definition: EBDetId.h:109
int zside() const
get the z-side of the crystal (1/-1)
Definition: EBDetId.h:47