CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CaloTowerDetId.cc
Go to the documentation of this file.
3 #include <iostream>
4 
6 }
7 
8 CaloTowerDetId::CaloTowerDetId(uint32_t rawid) : DetId(rawid&0xFFF0FFFFu) {
9 
10 }
11 
12 CaloTowerDetId::CaloTowerDetId(int ieta, int iphi) : DetId(Calo,SubdetId) {
13  id_|=
14  ((ieta>0)?(0x2000|((ieta&0x3F)<<7)):(((-ieta)&0x3f)<<7)) |
15  (iphi&0x7F);
16 }
17 
19  if (!gen.null() && (gen.det()!=Calo || gen.subdetId()!=SubdetId)) {
20  throw cms::Exception("Invalid DetId") << "Cannot initialize CaloTowerDetId from " << std::hex << gen.rawId() << std::dec;
21  }
22  id_=gen.rawId();
23 }
24 
26  if (!gen.null() && (gen.det()!=Calo || gen.subdetId()!=SubdetId)) {
27  throw cms::Exception("Invalid DetId") << "Cannot assign CaloTowerDetId from " << std::hex << gen.rawId() << std::dec;
28  }
29  id_=gen.rawId();
30  return *this;
31 }
32 
33 int CaloTowerDetId::iphi() const {
34  int retval=id_&0x7F;
35  return retval;
36 }
37 
38 bool
39 CaloTowerDetId::validDetId( int ie , int ip )
40 {
41  const int ia ( abs( ie ) ) ;
42  return ( ( ia >= 1 ) &&
43  ( ip >= 1 ) &&
44  ( ia <= kMaxIEta ) &&
45  ( ip <= kMaxIPhi ) &&
46  ( ( ( ia <= kBarIEta ) &&
47  ( ip <= kBarNPhi ) ) ||
48  ( ( ia > kBarIEta ) &&
49  ( ia <= kEndIEta ) &&
50  ( (ip-1)%2 == 0 ) ) ||
51  ( ( ia > kEndIEta ) &&
52  ( ia <= kForIEta ) &&
53  ( (ip-3)%4 == 0 ) ) ) ) ;
54 }
55 
56 uint32_t
58 {
59  const uint32_t ie ( ietaAbs() ) ;
60  const uint32_t ip ( iphi() - 1 ) ;
61 
62  return ( ( 0 > zside() ? 0 : kAllNTot ) +
63  ( ( kBarIEta >= ie ? ( ie - 1 )*kBarNPhi + ip :
64  ( kEndIEta >= ie ? kBarNTot + ( ie - 1 - kBarIEta )*kEndNPhi + ip/2 :
65  kBarNTot + kEndNTot + ( ie - 1 - kEndIEta )*kForNPhi + ip/4 ) ) ) ) ;
66 }
67 
70 {
71  const int iz ( din < kAllNTot ? -1 : 1 ) ;
72  din %= kAllNTot ;
73  const uint32_t ie ( ( kBarNTot + kEndNTot ) - 1 < din ?
74  kEndIEta + ( din - kBarNTot - kEndNTot )/kForNPhi + 1 :
75  ( kBarNTot - 1 < din ?
76  kBarIEta + ( din - kBarNTot )/kEndNPhi + 1 :
77  din/kBarNPhi + 1 ) ) ;
78 
79  const uint32_t ip ( ( kBarNTot + kEndNTot ) - 1 < din ?
80  ( ( din - kBarNTot - kEndNTot )%kForNPhi )*4 + 3 :
81  ( kBarNTot - 1 < din ?
82  ( ( din - kBarNTot )%kEndNPhi )*2 + 1 :
83  din%kBarNPhi + 1 ) ) ;
84 
85  return ( validDenseIndex( din ) ? CaloTowerDetId( iz*ie, ip ) : CaloTowerDetId() ) ;
86 }
87 
88 std::ostream& operator<<(std::ostream& s, const CaloTowerDetId& id) {
89  return s << "Tower (" << id.ieta() << "," << id.iphi() << ")";
90 }
static bool validDetId(int ie, int ip)
int ietaAbs() const
get the absolute value of the tower ieta
int ieta() const
Definition: CaloTower.h:169
uint32_t denseIndex() const
int iphi() const
Definition: CaloTower.h:171
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
static CaloTowerDetId detIdFromDenseIndex(uint32_t din)
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
CaloTowerDetId & operator=(const DetId &id)
static const int SubdetId
int iphi() const
get the tower iphi
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
Definition: DetId.h:18
uint32_t id_
Definition: DetId.h:55
bool null() const
is this a null id ?
Definition: DetId.h:45
int zside() const
get the z-side of the tower (1/-1)
static bool validDenseIndex(uint32_t din)
Detector det() const
get the detector field from this detid
Definition: DetId.h:35