CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
EcalBarrelNumberingScheme.cc
Go to the documentation of this file.
1 // File: EcalBarrelNumberingScheme.cc
3 // Description: Numbering scheme for barrel electromagnetic calorimeter
7 #include <sstream>
8 
9 //#define EDM_ML_DEBUG
10 
12  edm::LogVerbatim("EcalGeom") << "Creating EcalBarrelNumberingScheme";
13 }
14 
16  edm::LogVerbatim("EcalGeom") << "Deleting EcalBarrelNumberingScheme";
17 }
18 
19 uint32_t EcalBarrelNumberingScheme::getUnitID(const EcalBaseNumber& baseNumber) const {
20  const uint32_t nLevels(baseNumber.getLevels());
21 
22 #ifdef EDM_ML_DEBUG
23  std::ostringstream st1;
24  for (uint32_t k = 0; k < nLevels; ++k)
25  st1 << ", " << baseNumber.getLevelName(k) << ":" << baseNumber.getCopyNumber(k);
26  edm::LogVerbatim("EcalGeom") << "ECalBarrelNumberingScheme geometry levels = " << nLevels << st1.str();
27 #endif
28  if (11 > nLevels) {
29  edm::LogWarning("EcalGeom") << "ECalBarrelNumberingScheme::getUnitID(): "
30  << "Not enough levels found in EcalBaseNumber ( " << nLevels << ") Returning 0";
31  return 0;
32  }
33 
34  const std::string& cryName(baseNumber.getLevelName(0).substr(0, 7)); // name of crystal volume
35 
36  const int cryType(::atoi(cryName.c_str() + 5));
37 
38  uint32_t wallCopy(0), hawCopy(0), fawCopy(0), supmCopy(0);
39  const int off(13 < nLevels ? 3 : 0);
40 
41  if ((nLevels != 11) && (nLevels != 14)) {
42  wallCopy = baseNumber.getCopyNumber(3 + off);
43  hawCopy = baseNumber.getCopyNumber(4 + off);
44  fawCopy = baseNumber.getCopyNumber(5 + off);
45  supmCopy = baseNumber.getCopyNumber(6 + off);
46  } else {
47  auto num1 = numbers(baseNumber.getLevelName(3 + off));
48  wallCopy = num1.second;
49  hawCopy = num1.first;
50  auto num2 = numbers(baseNumber.getLevelName(4 + off));
51  fawCopy = num2.second;
52  supmCopy = num2.first;
53  }
54 #ifdef EDM_ML_DEBUG
55  edm::LogVerbatim("EcalGeom") << nLevels << " off: " << off << " cryType: " << cryType << " wallCopy: " << wallCopy
56  << " hawCopy: " << hawCopy << " fawCopy: " << fawCopy << " supmCopy: " << supmCopy;
57 #endif
58  // error checking
59 
60  if (1 > cryType || 17 < cryType) {
61  edm::LogWarning("EdalGeom") << "ECalBarrelNumberingScheme::getUnitID(): "
62  << "****************** Bad crystal name = " << cryName
63  << ", Volume Name = " << baseNumber.getLevelName(0);
64  return 0;
65  }
66 
67  if (1 > wallCopy || 5 < wallCopy) {
68  edm::LogWarning("EcalGeom") << "ECalBarrelNumberingScheme::getUnitID(): "
69  << "****************** Bad wall copy = " << wallCopy
70  << ", Volume Name = " << baseNumber.getLevelName(3);
71  return 0;
72  }
73 
74  if (1 > hawCopy || 2 < hawCopy) {
75  edm::LogWarning("EcalGeom") << "ECalBarrelNumberingScheme::getUnitID(): "
76  << "****************** Bad haw copy = " << hawCopy
77  << ", Volume Name = " << baseNumber.getLevelName(4);
78  return 0;
79  }
80 
81  if (1 > fawCopy || 10 < fawCopy) {
82  edm::LogWarning("EcalGeom") << "ECalBarrelNumberingScheme::getUnitID(): "
83  << "****************** Bad faw copy = " << fawCopy
84  << ", Volume Name = " << baseNumber.getLevelName(5);
85  return 0;
86  }
87 
88  if (1 > supmCopy || 36 < supmCopy) {
89  edm::LogWarning("EcalGeom") << "ECalBarrelNumberingScheme::getUnitID(): "
90  << "****************** Bad supermodule copy = " << supmCopy
91  << ", Volume Name = " << baseNumber.getLevelName(6);
92  return 0;
93  }
94 
95  // all inputs are fine. Go ahead and decode
96 
97  const int32_t zsign(18 < supmCopy ? -1 : 1);
98 
99  const int32_t eta(5 * (cryType - 1) + wallCopy);
100 
101  const int32_t phi(18 < supmCopy ? 20 * (supmCopy - 19) + 2 * (10 - fawCopy) + 3 - hawCopy
102  : 20 * (supmCopy - 1) + 2 * (fawCopy - 1) + hawCopy);
103 
104  const int32_t intindex(EBDetId(zsign * eta, phi).rawId());
105 
106  /*
107  static int count ( 1 ) ;
108  if( 0==count%1000 )
109  {
110  std::cout<<"************************** NLEVELS="<<nLevels
111  <<", eta="<<eta<<", phi="<<phi<<", zsign="<<zsign<<std::endl;
112  }
113  ++count;
114 */
115 #ifdef EDM_ML_DEBUG
116  edm::LogVerbatim("EcalGeom") << "EcalBarrelNumberingScheme: "
117  << "supmCopy = " << supmCopy << ", fawCopy = " << fawCopy << ", hawCopy = " << hawCopy
118  << ", wallCopy = " << wallCopy << ", cryType = " << cryType
119  << "\n zsign = " << zsign << ", eta = " << eta << ", phi = " << phi
120  << ", packed index = 0x" << std::hex << intindex << std::dec;
121 #endif
122  return intindex;
123 }
124 
125 std::pair<int, int> EcalBarrelNumberingScheme::numbers(const std::string& name) const {
126  int num1(-1), num2(-1);
127  if (name.find('#') != std::string::npos) {
128  uint32_t ip1 = name.find('#');
129  if (name.find('!') != std::string::npos) {
130  uint32_t ip2 = name.find('!');
131  num1 = ::atoi(name.substr(ip1 + 1, ip2 - ip1 - 1).c_str());
132  if (name.find('#', ip2) != std::string::npos) {
133  uint32_t ip3 = name.find('#', ip2);
134  num2 = ::atoi(name.substr(ip3 + 1, name.size() - ip3 - 1).c_str());
135  }
136  }
137  }
138 #ifdef EDM_ML_DEBUG
139  edm::LogVerbatim("EcalGeom") << "EcalBarrelNumberingScheme::Numbers from " << name << " are " << num1 << " and "
140  << num2;
141 #endif
142  return std::make_pair(num1, num2);
143 }
Log< level::Info, true > LogVerbatim
std::string const & getLevelName(int level) const
int getCopyNumber(int level) const
uint32_t getUnitID(const EcalBaseNumber &baseNumber) const override
std::pair< int, int > numbers(const std::string &) const
Log< level::Warning, false > LogWarning
int getLevels() const