CMS 3D CMS Logo

HGCalTBParametersFromDD.cc
Go to the documentation of this file.
2 
10 
11 //#define EDM_ML_DEBUG
12 using namespace geant_units::operators;
13 
15  HGCalTBParameters& php,
16  const std::string& name,
17  const std::string& namew,
18  const std::string& namec,
19  const std::string& namet) {
20 #ifdef EDM_ML_DEBUG
21  edm::LogVerbatim("HGCalGeom") << "HGCalTBParametersFromDD (DDD)::build called with "
22  << "names " << name << ":" << namew << ":" << namec << ":" << namet;
23 #endif
24 
25  // Special parameters at simulation level
26  std::string attribute = "Volume";
28  DDValue val(attribute, value, 0.0);
30  DDFilteredView fv(*cpv, filter);
31  bool ok = fv.firstChild();
33 #ifdef EDM_ML_DEBUG
34  edm::LogVerbatim("HGCalGeom") << "Volume " << name << " GeometryMode ";
35 #endif
36  if (ok) {
38  php.mode_ = HGCalGeometryMode::getGeometryMode("GeometryMode", sv);
39 #ifdef EDM_ML_DEBUG
40  edm::LogVerbatim("HGCalGeom") << "Volume " << name << " GeometryMode " << php.mode_ << ":"
42 #endif
43  php.levelZSide_ = 3; // Default level for ZSide
44  php.detectorType_ = 0; // These two parameters are
45  php.useSimWt_ = 1; // energy weighting for SimHits
46  std::unique_ptr<HGCalTBGeomParameters> geom = std::make_unique<HGCalTBGeomParameters>();
48  attribute = "OnlyForHGCalNumbering";
49  value = namet;
50  DDValue val2(attribute, value, 0.0);
51  DDSpecificsMatchesValueFilter filter2{val2};
52  DDFilteredView fv2(*cpv, filter2);
53  bool ok2 = fv2.firstChild();
54  if (ok2) {
57 #ifdef EDM_ML_DEBUG
58  edm::LogVerbatim("HGCalGeom") << "WaferMode " << mode << ":" << HGCalGeometryMode::Polyhedra << ":"
60 #endif
61  }
62  }
63  php.firstLayer_ = 1;
64  if (php.mode_ == HGCalGeometryMode::Hexagon) {
65  // Load the SpecPars
66  geom->loadSpecParsHexagon(fv, php, cpv, namew, namec);
67  // Load the Geometry parameters
68  geom->loadGeometryHexagon(fv, php, name, cpv, namew, namec, mode);
69  // Load cell parameters
70  geom->loadCellParsHexagon(cpv, php);
71  // Set complete fill mode
72  php.defineFull_ = false;
73  } else if (php.mode_ == HGCalGeometryMode::HexagonFull) {
74  // Load the SpecPars
75  geom->loadSpecParsHexagon(fv, php, cpv, namew, namec);
76  // Load the Geometry parameters
77  geom->loadGeometryHexagon(fv, php, name, cpv, namew, namec, mode);
78  // Modify some constants
79  geom->loadWaferHexagon(php);
80  // Load cell parameters
81  geom->loadCellParsHexagon(cpv, php);
82  // Set complete fill mode
83  php.defineFull_ = true;
84  } else {
85  edm::LogError("HGCalGeom") << "Unknown Geometry type " << php.mode_ << " for HGCal " << name << ":" << namew
86  << ":" << namec;
87  throw cms::Exception("DDException")
88  << "Unknown Geometry type " << php.mode_ << " for HGCal " << name << ":" << namew << ":" << namec;
89  }
90  } else {
91  edm::LogError("HGCalGeom") << " Attribute " << val << " not found but needed.";
92  throw cms::Exception("DDException") << "Attribute " << val << " not found but needed.";
93  }
94 #ifdef EDM_ML_DEBUG
95  edm::LogVerbatim("HGCalGeom") << "Return from HGCalTBParametersFromDD::build"
96  << " with flag " << ok;
97 #endif
98  return ok;
99 }
100 
102  HGCalTBParameters& php,
103  const std::string& name,
104  const std::string& namew,
105  const std::string& namec,
106  const std::string& namet,
107  const std::string& name2) {
108 #ifdef EDM_ML_DEBUG
109  edm::LogVerbatim("HGCalGeom") << "HGCalTBParametersFromDD (DD4hep)::build called with "
110  << "names " << name << ":" << namew << ":" << namec << ":" << namet << ":" << name2;
111 #endif
112  cms::DDVectorsMap vmap = cpv->detector()->vectors();
113  const cms::DDFilter filter("Volume", name);
114  cms::DDFilteredView fv((*cpv), filter);
115  std::vector<std::string> tempS;
116  std::vector<double> tempD;
117  bool ok = fv.firstChild();
118  tempS = fv.get<std::vector<std::string> >(name2, "GeometryMode");
119  if (tempS.empty()) {
120  tempS = fv.get<std::vector<std::string> >(name, "GeometryMode");
121  }
122  std::string sv = (!tempS.empty()) ? tempS[0] : "HGCalGeometryMode::Hexagon8Full";
124 #ifdef EDM_ML_DEBUG
125  edm::LogVerbatim("HGCalGeom") << "Volume " << name << " GeometryMode ";
126 #endif
127 
128  if (ok) {
130 #ifdef EDM_ML_DEBUG
131  edm::LogVerbatim("HGCalGeom") << "Volume " << name << " GeometryMode " << php.mode_ << ":"
133 #endif
134  php.levelZSide_ = 3; // Default level for ZSide
135  php.detectorType_ = 0; // These two parameters are
136  php.useSimWt_ = 1; // energy weighting for SimHits
137  std::unique_ptr<HGCalTBGeomParameters> geom = std::make_unique<HGCalTBGeomParameters>();
139  tempS = fv.get<std::vector<std::string> >(namet, "WaferMode");
140  std::string sv2 = (!tempS.empty()) ? tempS[0] : "HGCalGeometryMode::Polyhedra";
142 #ifdef EDM_ML_DEBUG
143  edm::LogVerbatim("HGCalGeom") << "WaferMode " << mode << ":" << HGCalGeometryMode::Polyhedra << ":"
145 #endif
146  }
147  if (php.mode_ == HGCalGeometryMode::Hexagon) {
148  // Load the SpecPars
149  php.firstLayer_ = 1;
150  geom->loadSpecParsHexagon(fv, php, name, namew, namec, name2);
151  // Load the Geometry parameters
152  geom->loadGeometryHexagon(cpv, php, name, namew, namec, mode);
153  // Load cell parameters
154  geom->loadCellParsHexagon(vmap, php);
155  // Set complete fill mode
156  php.defineFull_ = false;
157  } else if (php.mode_ == HGCalGeometryMode::HexagonFull) {
158  // Load the SpecPars
159  php.firstLayer_ = 1;
160  geom->loadSpecParsHexagon(fv, php, name, namew, namec, name2);
161  // Load the Geometry parameters
162  geom->loadGeometryHexagon(cpv, php, name, namew, namec, mode);
163  // Modify some constants
164  geom->loadWaferHexagon(php);
165  // Load cell parameters
166  geom->loadCellParsHexagon(vmap, php);
167  // Set complete fill mode
168  php.defineFull_ = true;
169  }
170  } else {
171  edm::LogError("HGCalGeom") << " Attribute Volume:" << name << " not found but needed.";
172  throw cms::Exception("DDException") << "Attribute Volume:" << name << " not found but needed.";
173  }
174 #ifdef EDM_ML_DEBUG
175  edm::LogVerbatim("HGCalGeom") << "Return from HGCalTBParametersFromDD::build"
176  << " with flag " << ok;
177 #endif
178  return ok;
179 }
180 
182  DDValue val(s);
183  if (DDfetch(&sv, val)) {
184  const std::vector<double>& fvec = val.doubles();
185  if (fvec.empty()) {
186  throw cms::Exception("HGCalGeom") << "getDDDValue::Failed to get " << s << " tag.";
187  }
188  return fvec[0];
189  } else {
190  throw cms::Exception("HGCalGeom") << "getDDDValue::Failed to fetch " << s << " tag";
191  }
192 }
193 
194 std::vector<double> HGCalTBParametersFromDD::getDDDArray(const char* s, const DDsvalues_type& sv) {
195  DDValue val(s);
196  if (DDfetch(&sv, val)) {
197  const std::vector<double>& fvec = val.doubles();
198  if (fvec.empty()) {
199  throw cms::Exception("HGCalGeom") << "getDDDArray::Failed to get " << s << " tag.";
200  }
201  return fvec;
202  } else {
203  throw cms::Exception("HGCalGeom") << "getDDDArray:Failed to fetch " << s << " tag";
204  }
205 }
Log< level::Info, true > LogVerbatim
bool build(const DDCompactView *cpv, HGCalTBParameters &php, const std::string &name, const std::string &namew, const std::string &namec, const std::string &namet)
double getDDDValue(const char *s, const DDsvalues_type &sv)
const cms::DDDetector * detector() const
Definition: DDCompactView.h:34
Log< level::Error, false > LogError
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:79
std::unordered_map< std::string, std::vector< double > > DDVectorsMap
Definition: DDNamespace.h:20
WaferMode getGeometryWaferMode(const char *s, const DDsvalues_type &sv)
std::vector< double > getDDDArray(const char *s, const DDsvalues_type &sv)
std::vector< std::pair< unsigned int, DDValue > > DDsvalues_type
Definition: DDsvalues.h:12
GeometryMode getGeometryMode(const char *s, const DDsvalues_type &sv)
Definition: value.py:1
HGCalGeometryMode::GeometryMode mode_
bool firstChild()
set the current node to the first child
DDsvalues_type mergedSpecifics() const
T get(const std::string &)
extract attribute value
bool firstChild()
set the current node to the first child ...
cms::DDVectorsMap const & vectors() const
Definition: DDDetector.h:17