CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HcalParametersFromDD.cc
Go to the documentation of this file.
8 
10 #include <iostream>
11 #include <iomanip>
12 
13 //#define EDM_ML_DEBUG
14 using namespace geant_units::operators;
15 
16 namespace {
17  int getTopologyMode(const char* s, const DDsvalues_type& sv, bool type) {
18  DDValue val(s);
19  if (DDfetch(&sv, val)) {
20  const std::vector<std::string>& fvec = val.strings();
21  if (fvec.empty()) {
22  throw cms::Exception("HcalParametersFromDD") << "Failed to get " << s << " tag.";
23  }
24 
25  int result(-1);
26  if (type) {
29  result = static_cast<int>(mode);
30  } else {
33  result = static_cast<int>(mode);
34  }
35  return result;
36  } else {
37  throw cms::Exception("HcalParametersFromDD") << "Failed to get " << s << " tag.";
38  }
39  }
40 
41  int getTopologyMode(const std::string& s, bool type) {
42  int result(-1);
43  if (type) {
46  result = static_cast<int>(mode);
47  } else {
50  result = static_cast<int>(mode);
51  }
52  return result;
53  }
54 } // namespace
55 
57 #ifdef EDM_ML_DEBUG
58  edm::LogVerbatim("HCalGeom") << "HcalParametersFromDD::build(const DDCompactView*, HcalParameters&) is called";
59 #endif
60  //Special parameters at simulation level
61  std::string attribute = "OnlyForHcalSimNumbering";
62  DDSpecificsHasNamedValueFilter filter1{attribute};
63  DDFilteredView fv1(*cpv, filter1);
64  bool ok = fv1.firstChild();
65 
66  const int nEtaMax = 100;
67 
68  if (ok) {
69  std::unique_ptr<HcalGeomParameters> geom = std::make_unique<HcalGeomParameters>();
70  geom->loadGeometry(fv1, php);
71  php.modHB = geom->getModHalfHBHE(0);
72  php.modHE = geom->getModHalfHBHE(1);
73  php.dzVcal = geom->getConstDzHF();
74  geom->getConstRHO(php.rHO);
75 
76  php.phioff = cpv->vector("phioff");
77  php.etaTable = cpv->vector("etaTable");
78  php.rTable = cpv->vector("rTable");
80  php.phibin = cpv->vector("phibin");
81  php.phitable = cpv->vector("phitable");
82  for (unsigned int i = 1; i <= nEtaMax; ++i) {
83  std::stringstream sstm;
84  sstm << "layerGroupSimEta" << i;
85  std::string tempName = sstm.str();
86  auto const& v = cpv->vector(tempName);
87  if (!v.empty()) {
88  HcalParameters::LayerItem layerGroupEta;
89  layerGroupEta.layer = i;
90  layerGroupEta.layerGroup = dbl_to_int(v);
91  php.layerGroupEtaSim.emplace_back(layerGroupEta);
92  }
93  }
94  php.etaMin = dbl_to_int(cpv->vector("etaMin"));
95  php.etaMax = dbl_to_int(cpv->vector("etaMax"));
96  php.etaRange = cpv->vector("etaRange");
97  php.gparHF = cpv->vector("gparHF");
99  php.noff = dbl_to_int(cpv->vector("noff"));
100  php.Layer0Wt = cpv->vector("Layer0Wt");
101  php.HBGains = cpv->vector("HBGains");
102  php.HBShift = dbl_to_int(cpv->vector("HBShift"));
103  php.HEGains = cpv->vector("HEGains");
104  php.HEShift = dbl_to_int(cpv->vector("HEShift"));
105  php.HFGains = cpv->vector("HFGains");
106  php.HFShift = dbl_to_int(cpv->vector("HFShift"));
107  php.maxDepth = dbl_to_int(cpv->vector("MaxDepth"));
108  } else {
109  throw cms::Exception("HcalParametersFromDD") << "Not found " << attribute.c_str() << " but needed.";
110  }
111  //Special parameters at reconstruction level
112  attribute = "OnlyForHcalRecNumbering";
113  DDSpecificsHasNamedValueFilter filter2{attribute};
114  DDFilteredView fv2(*cpv, filter2);
115  ok = fv2.firstChild();
116  if (ok) {
118  int topoMode = getTopologyMode("TopologyMode", sv, true);
119  int trigMode = getTopologyMode("TriggerMode", sv, false);
120  php.topologyMode = ((trigMode & 0xFF) << 8) | (topoMode & 0xFF);
121  php.etagroup = dbl_to_int(cpv->vector("etagroup"));
122  php.phigroup = dbl_to_int(cpv->vector("phigroup"));
123  for (unsigned int i = 1; i <= nEtaMax; ++i) {
124  std::stringstream sstm;
125  sstm << "layerGroupRecEta" << i;
126  std::string tempName = sstm.str();
127  auto const& v = cpv->vector(tempName);
128  if (!v.empty()) {
129  HcalParameters::LayerItem layerGroupEta;
130  layerGroupEta.layer = i;
131  layerGroupEta.layerGroup = dbl_to_int(v);
132  php.layerGroupEtaRec.emplace_back(layerGroupEta);
133  }
134  }
135  } else {
136  throw cms::Exception("HcalParametersFromDD") << "Not found " << attribute.c_str() << " but needed.";
137  }
138 
139  return build(php);
140 }
141 
143 #ifdef EDM_ML_DEBUG
144  edm::LogVerbatim("HCalGeom") << "HcalParametersFromDD::build(const cms::DDCompactView*, HcalParameters&) is called";
145 #endif
146  const int nEtaMax = 100;
147 
148  std::unique_ptr<HcalGeomParameters> geom = std::make_unique<HcalGeomParameters>();
149  geom->loadGeometry(cpv, php);
150  php.modHB = geom->getModHalfHBHE(0);
151  php.modHE = geom->getModHalfHBHE(1);
152  php.dzVcal = geom->getConstDzHF();
153  geom->getConstRHO(php.rHO);
154 
155  php.phioff = cpv.get<std::vector<double>>("phioff");
156  php.etaTable = cpv.get<std::vector<double>>("etaTable");
157  php.rTable = cpv.get<std::vector<double>>("rTable");
158  php.phibin = cpv.get<std::vector<double>>("phibin");
159  php.phitable = cpv.get<std::vector<double>>("phitable");
160  php.etaMin = cpv.getVector<int>("etaMin");
161  php.etaMax = cpv.getVector<int>("etaMax");
162  php.etaRange = cpv.get<std::vector<double>>("etaRange");
163  php.gparHF = cpv.get<std::vector<double>>("gparHF");
164  php.noff = cpv.getVector<int>("noff");
165  php.Layer0Wt = cpv.get<std::vector<double>>("Layer0Wt");
166  php.HBGains = cpv.get<std::vector<double>>("HBGains");
167  php.HBShift = cpv.getVector<int>("HBShift");
168  php.HEGains = cpv.get<std::vector<double>>("HEGains");
169  php.HEShift = cpv.getVector<int>("HEShift");
170  php.HFGains = cpv.get<std::vector<double>>("HFGains");
171  php.HFShift = cpv.getVector<int>("HFShift");
172  php.maxDepth = cpv.getVector<int>("MaxDepth");
173 
176  for (unsigned int i = 1; i <= nEtaMax; ++i) {
177  HcalParameters::LayerItem layerGroupEta;
178  layerGroupEta.layer = i;
179  layerGroupEta.layerGroup = cpv.getVector<int>(std::string("layerGroupSimEta") + std::to_string(i));
180  if (!layerGroupEta.layerGroup.empty()) {
181  php.layerGroupEtaSim.emplace_back(layerGroupEta);
182  }
183  }
184 
185  //Special parameters at reconstruction level
186  const cms::DDFilter filter("OnlyForHcalRecNumbering", "HCAL");
187  cms::DDFilteredView fv(cpv, filter);
188 
189  std::vector<std::string> tempS = fv.get<std::vector<std::string>>("hcal", "TopologyMode");
190  std::string sv = (!tempS.empty()) ? tempS[0] : "HcalTopologyMode::SLHC";
191  int topoMode = getTopologyMode(sv, true);
192  tempS = fv.get<std::vector<std::string>>("hcal", "TriggerMode");
193  sv = (!tempS.empty()) ? tempS[0] : "HcalTopologyMode::TriggerMode_2021";
194  int trigMode = getTopologyMode(sv, false);
195  php.topologyMode = ((trigMode & 0xFF) << 8) | (topoMode & 0xFF);
196 
197  php.etagroup = cpv.getVector<int>("etagroup");
198  php.phigroup = cpv.getVector<int>("phigroup");
199 
200  for (unsigned int i = 1; i <= nEtaMax; ++i) {
201  HcalParameters::LayerItem layerGroupEta;
202  layerGroupEta.layer = i;
203  layerGroupEta.layerGroup = cpv.getVector<int>(std::string("layerGroupRecEta") + std::to_string(i));
204  if (!layerGroupEta.layerGroup.empty()) {
205  php.layerGroupEtaRec.emplace_back(layerGroupEta);
206  }
207  }
208 
209  return build(php);
210 }
211 
213  php.etaMin[0] = 1;
214  if (php.etaMax[1] >= php.etaMin[1])
215  php.etaMax[1] = static_cast<int>(php.etaTable.size()) - 1;
216  php.etaMax[2] = php.etaMin[2] + static_cast<int>(php.rTable.size()) - 2;
217 
218  for (unsigned int i = 0; i < php.rTable.size(); ++i) {
219  unsigned int k = php.rTable.size() - i - 1;
220  php.etaTableHF.emplace_back(-log(tan(0.5 * atan(php.rTable[k] / php.gparHF[4]))));
221  }
222 
223 #ifdef EDM_ML_DEBUG
224  int i(0);
225  std::stringstream ss0;
226  ss0 << "HcalParametersFromDD: MaxDepth[" << php.maxDepth.size() << "]: ";
227  for (const auto& it : php.maxDepth)
228  ss0 << it << ", ";
229  edm::LogVerbatim("HCalGeom") << ss0.str();
230  std::stringstream ss1;
231  ss1 << "HcalParametersFromDD: ModHB [" << php.modHB.size() << "]: ";
232  for (const auto& it : php.modHB)
233  ss1 << it << ", ";
234  edm::LogVerbatim("HCalGeom") << ss1.str();
235  std::stringstream ss2;
236  ss2 << "HcalParametersFromDD: ModHE [" << php.modHE.size() << "]: ";
237  for (const auto& it : php.modHE)
238  ss2 << it << ", ";
239  edm::LogVerbatim("HCalGeom") << ss2.str();
240  std::stringstream ss3;
241  ss3 << "HcalParametersFromDD: " << php.phioff.size() << " phioff values:";
242  std::vector<double>::const_iterator it;
243  for (it = php.phioff.begin(), i = 0; it != php.phioff.end(); ++it)
244  ss3 << " [" << ++i << "] = " << convertRadToDeg(*it);
245  edm::LogVerbatim("HCalGeom") << ss3.str();
246  std::stringstream ss4;
247  ss4 << "HcalParametersFromDD: " << php.etaTable.size() << " entries for etaTable:";
248  for (it = php.etaTable.begin(), i = 0; it != php.etaTable.end(); ++it)
249  ss4 << " [" << ++i << "] = " << (*it);
250  edm::LogVerbatim("HCalGeom") << ss4.str();
251  std::stringstream ss5;
252  ss5 << "HcalParametersFromDD: " << php.rTable.size() << " entries for rTable:";
253  for (it = php.rTable.begin(), i = 0; it != php.rTable.end(); ++it)
254  ss5 << " [" << ++i << "] = " << convertMmToCm(*it);
255  edm::LogVerbatim("HCalGeom") << ss5.str();
256  std::stringstream ss6;
257  ss6 << "HcalParametersFromDD: " << php.phibin.size() << " phibin values:";
258  for (it = php.phibin.begin(), i = 0; it != php.phibin.end(); ++it)
259  ss6 << " [" << ++i << "] = " << convertRadToDeg(*it);
260  edm::LogVerbatim("HCalGeom") << ss6.str();
261  std::stringstream ss7;
262  ss7 << "HcalParametersFromDD: " << php.phitable.size() << " phitable values:";
263  for (it = php.phitable.begin(), i = 0; it != php.phitable.end(); ++it)
264  ss7 << " [" << ++i << "] = " << convertRadToDeg(*it);
265  edm::LogVerbatim("HCalGeom") << ss7.str();
266  edm::LogVerbatim("HCalGeom") << "HcalParametersFromDD: " << php.layerGroupEtaSim.size() << " layerGroupEtaSim blocks"
267  << std::endl;
268  std::vector<int>::const_iterator kt;
269  for (unsigned int k = 0; k < php.layerGroupEtaSim.size(); ++k) {
270  std::stringstream ss8;
271  ss8 << "layerGroupEtaSim[" << k << "] Layer " << php.layerGroupEtaSim[k].layer;
272  for (kt = php.layerGroupEtaSim[k].layerGroup.begin(), i = 0; kt != php.layerGroupEtaSim[k].layerGroup.end(); ++kt)
273  ss8 << " " << ++i << ":" << (*kt);
274  edm::LogVerbatim("HCalGeom") << ss8.str();
275  }
276  std::stringstream ss8;
277  ss8 << "HcalParametersFromDD: " << php.etaMin.size() << " etaMin values:";
278  for (kt = php.etaMin.begin(), i = 0; kt != php.etaMin.end(); ++kt)
279  ss8 << " [" << ++i << "] = " << (*kt);
280  edm::LogVerbatim("HCalGeom") << ss8.str();
281  std::stringstream ss9;
282  ss9 << "HcalParametersFromDD: " << php.etaMax.size() << " etaMax values:";
283  for (kt = php.etaMax.begin(), i = 0; kt != php.etaMax.end(); ++kt)
284  ss9 << " [" << ++i << "] = " << (*kt);
285  edm::LogVerbatim("HCalGeom") << ss9.str();
286  std::stringstream ss10;
287  ss10 << "HcalParametersFromDD: " << php.etaRange.size() << " etaRange values:";
288  for (it = php.etaRange.begin(), i = 0; it != php.etaRange.end(); ++it)
289  ss10 << " [" << ++i << "] = " << (*it);
290  edm::LogVerbatim("HCalGeom") << ss10.str();
291  std::stringstream ss11;
292  ss11 << "HcalParametersFromDD: " << php.gparHF.size() << " gparHF values:";
293  for (it = php.gparHF.begin(), i = 0; it != php.gparHF.end(); ++it)
294  ss11 << " [" << ++i << "] = " << convertMmToCm(*it);
295  edm::LogVerbatim("HCalGeom") << ss11.str();
296  std::stringstream ss12;
297  ss12 << "HcalParametersFromDD: " << php.noff.size() << " noff values:";
298  for (kt = php.noff.begin(), i = 0; kt != php.noff.end(); ++kt)
299  ss12 << " [" << ++i << "] = " << (*kt);
300  edm::LogVerbatim("HCalGeom") << ss12.str();
301  std::stringstream ss13;
302  ss13 << "HcalParametersFromDD: " << php.Layer0Wt.size() << " Layer0Wt values:";
303  for (it = php.Layer0Wt.begin(), i = 0; it != php.Layer0Wt.end(); ++it)
304  ss13 << " [" << ++i << "] = " << (*it);
305  edm::LogVerbatim("HCalGeom") << ss13.str();
306  std::stringstream ss14;
307  ss14 << "HcalParametersFromDD: " << php.HBGains.size() << " Shift/Gains values for HB:";
308  for (unsigned k = 0; k < php.HBGains.size(); ++k)
309  ss14 << " [" << k << "] = " << php.HBShift[k] << ":" << php.HBGains[k];
310  edm::LogVerbatim("HCalGeom") << ss14.str();
311  std::stringstream ss15;
312  ss15 << "HcalParametersFromDD: " << php.HEGains.size() << " Shift/Gains values for HE:";
313  for (unsigned k = 0; k < php.HEGains.size(); ++k)
314  ss15 << " [" << k << "] = " << php.HEShift[k] << ":" << php.HEGains[k];
315  edm::LogVerbatim("HCalGeom") << ss15.str();
316  std::stringstream ss16;
317  ss16 << "HcalParametersFromDD: " << php.HFGains.size() << " Shift/Gains values for HF:";
318  for (unsigned k = 0; k < php.HFGains.size(); ++k)
319  ss16 << " [" << k << "] = " << php.HFShift[k] << ":" << php.HFGains[k];
320  edm::LogVerbatim("HCalGeom") << ss16.str();
321  std::stringstream ss17;
322  ss17 << "HcalParametersFromDD: " << php.etagroup.size() << " etagroup values:";
323  for (kt = php.etagroup.begin(), i = 0; kt != php.etagroup.end(); ++kt)
324  ss17 << " [" << ++i << "] = " << (*kt);
325  edm::LogVerbatim("HCalGeom") << ss17.str();
326  std::stringstream ss18;
327  ss18 << "HcalParametersFromDD: " << php.phigroup.size() << " phigroup values:";
328  for (kt = php.phigroup.begin(), i = 0; kt != php.phigroup.end(); ++kt)
329  ss18 << " [" << ++i << "] = " << (*kt);
330  edm::LogVerbatim("HCalGeom") << ss18.str();
331  edm::LogVerbatim("HCalGeom") << "HcalParametersFromDD: " << php.layerGroupEtaRec.size() << " layerGroupEtaRec blocks";
332  for (unsigned int k = 0; k < php.layerGroupEtaRec.size(); ++k) {
333  std::stringstream ss19;
334  ss19 << "layerGroupEtaRec[" << k << "] Layer " << php.layerGroupEtaRec[k].layer;
335  for (kt = php.layerGroupEtaRec[k].layerGroup.begin(), i = 0; kt != php.layerGroupEtaRec[k].layerGroup.end(); ++kt)
336  ss19 << " " << ++i << ":" << (*kt);
337  edm::LogVerbatim("HCalGeom") << ss19.str();
338  }
339  edm::LogVerbatim("HCalGeom") << "HcalParametersFromDD: (topology|trigger)Mode " << std::hex << php.topologyMode
340  << std::dec;
341 #endif
342 
343  return true;
344 }
345 
346 void HcalParametersFromDD::rescale(std::vector<double>& v, const double s) {
347  std::for_each(v.begin(), v.end(), [s](double& n) { n *= s; });
348 }
Log< level::Info, true > LogVerbatim
std::vector< double > etaTable
std::vector< int > etagroup
static std::vector< std::string > checklist log
bool build(const DDCompactView *, HcalParameters &)
std::vector< double > etaRange
T const & get(const std::string &) const
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
std::vector< double > HBGains
std::vector< int > HEShift
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::vector< double > etaTableHF
std::vector< int > etaMax
tuple result
Definition: mps_fire.py:311
std::vector< int > modHB
static constexpr double k_ScaleFromDDDToG4
void rescale(std::vector< double > &, const double s)
std::vector< LayerItem > layerGroupEtaSim
std::vector< std::pair< unsigned int, DDValue > > DDsvalues_type
Definition: DDsvalues.h:12
std::vector< double > rHO
std::vector< int > layerGroup
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
std::vector< double > const & vector(std::string_view iKey) const
returns an empty container if not found
std::vector< int > modHE
std::vector< int > HFShift
std::vector< int > dbl_to_int(const std::vector< double > &vecdbl)
Converts a std::vector of doubles to a std::vector of int.
Definition: DDutils.h:7
std::vector< double > HEGains
T get(const std::string &)
extract attribute value
std::vector< double > phioff
std::vector< double > gparHF
DDsvalues_type mergedSpecifics() const
std::vector< double > Layer0Wt
std::vector< double > rTable
std::vector< double > phitable
std::vector< double > phibin
std::vector< LayerItem > layerGroupEtaRec
bool firstChild()
set the current node to the first child ...
std::vector< T > getVector(const std::string &) const
std::vector< double > HFGains
constexpr NumType convertMmToCm(NumType millimeters)
Definition: GeantUnits.h:63
std::vector< int > noff
std::vector< int > HBShift
std::vector< int > maxDepth
std::vector< int > phigroup
static constexpr double k_ScaleFromDD4hepToG4
std::vector< int > etaMin
T parseString(const std::string &value)