CMS 3D CMS Logo

HcalSimParametersFromDD.cc
Go to the documentation of this file.
9 
11 #include <iostream>
12 #include <iomanip>
13 
14 //#define EDM_ML_DEBUG
15 
16 using namespace geant_units::operators;
17 
19  // Parameters for the fibers
20  std::string attribute = "Volume";
21  std::string value = "HF";
22  DDSpecificsMatchesValueFilter filter1{DDValue(attribute, value, 0)};
23  DDFilteredView fv1(*cpv, filter1);
24 
25  // Names of sensitive volumes for HF
26  php.hfNames_ = getNames(fv1);
27  int nb(-1);
28 
29  bool dodet = fv1.firstChild();
30  if (dodet) {
32 
33  // The level positions
34  nb = -1;
35  php.hfLevels_ = dbl_to_int(getDDDArray("Levels", sv, nb));
36 
37  // Attenuation length
38  nb = -1;
39  php.attenuationLength_ = getDDDArray("attl", sv, nb);
40 
41  // Limits on Lambda
42  nb = 2;
43  php.lambdaLimits_ = dbl_to_int(getDDDArray("lambLim", sv, nb));
44 
45  // Fibre Lengths
46  nb = 0;
47  php.longFiberLength_ = getDDDArray("LongFL", sv, nb);
48 
49  nb = 0;
50  php.shortFiberLength_ = getDDDArray("ShortFL", sv, nb);
51 
52  } else {
53  throw cms::Exception("HcalSimParametersFromDD") << "Not found " << value << " for " << attribute << " but needed.";
54  }
55 
56  //Parameters for the PMT
57  value = "HFPMT";
58  DDSpecificsMatchesValueFilter filter2{DDValue(attribute, value, 0)};
59  DDFilteredView fv2(*cpv, filter2);
60  if (fv2.firstChild()) {
62  int nb = -1;
63  std::vector<double> neta = getDDDArray("indexPMTR", sv, nb);
64  fillPMTs(neta, false, php);
65  nb = -1;
66  neta = getDDDArray("indexPMTL", sv, nb);
67  fillPMTs(neta, true, php);
68  } else {
69  throw cms::Exception("HcalSimParametersFromDD") << "Not found " << value << " for " << attribute << " but needed.";
70  }
71 
72  //Names of special volumes (HFFibre, HFPMT, HFFibreBundles)
73  fillNameVector(cpv, attribute, "HFFibre", php.hfFibreNames_);
74  fillNameVector(cpv, attribute, "HFPMT", php.hfPMTNames_);
75  fillNameVector(cpv, attribute, "HFFibreBundleStraight", php.hfFibreStraightNames_);
76  fillNameVector(cpv, attribute, "HFFibreBundleConical", php.hfFibreConicalNames_);
77 
78  // HCal materials
79  attribute = "OnlyForHcalSimNumbering";
80  DDSpecificsHasNamedValueFilter filter3{attribute};
81  DDFilteredView fv3(*cpv, filter3);
82  dodet = fv3.firstChild();
83 
84  while (dodet) {
85  const DDLogicalPart& log = fv3.logicalPart();
86  if (!isItHF(log.name().name(), php)) {
87  bool notIn = true;
88  for (unsigned int i = 0; i < php.hcalMaterialNames_.size(); ++i) {
89  if (!strcmp(php.hcalMaterialNames_[i].c_str(), log.material().name().name().c_str())) {
90  notIn = false;
91  break;
92  }
93  }
94  if (notIn)
95  php.hcalMaterialNames_.push_back(log.material().name().name());
96  }
97  dodet = fv2.next();
98  }
99 
100  return buildParameters(php);
101 }
102 
104 #ifdef EDM_ML_DEBUG
105  edm::LogVerbatim("HCalGeom")
106  << "Inside HcalSimParametersFromDD::build(const cms::DDCompactView*, HcalSimulationParameters&)";
107 #endif
108 
109  // HCal materials
110  const cms::DDFilter filter("OnlyForHcalSimNumbering", "HCAL");
111  cms::DDFilteredView fv(cpv, filter);
112 
113  {
114  BenchmarkGrd counter("HcalSimParametersFromDD get all vectors\n");
115 
116  // The level positions
117  php.hfLevels_ = fv.get<std::vector<int> >("hf", "Levels");
118 
119  // Attenuation length
120  php.attenuationLength_ = fv.get<std::vector<double> >("hf", "attl");
121  std::for_each(
122  php.attenuationLength_.begin(), php.attenuationLength_.end(), [](double& n) { n *= k_ScaleFromDD4hepInv; });
123 
124  // Limits on Lambda
125  php.lambdaLimits_ = fv.get<std::vector<int> >("hf", "lambLim");
126 
127  // Fibre Lengths
128  php.longFiberLength_ = fv.get<std::vector<double> >("hf", "LongFL");
129  std::for_each(php.longFiberLength_.begin(), php.longFiberLength_.end(), [](double& n) { n *= k_ScaleFromDD4hep; });
130  php.shortFiberLength_ = fv.get<std::vector<double> >("hf", "ShortFL");
131  std::for_each(
132  php.shortFiberLength_.begin(), php.shortFiberLength_.end(), [](double& n) { n *= k_ScaleFromDD4hep; });
133 
134  //Parameters for the PMT
135  std::vector<double> neta = fv.get<std::vector<double> >("hfpmt", "indexPMTR");
136  fillPMTs(neta, false, php);
137  neta = fv.get<std::vector<double> >("hfpmt", "indexPMTL");
138  fillPMTs(neta, true, php);
139 
140  // Parameters for the fibers
141  fillNameVector(cpv, "HF", php.hfNames_);
142 
143  //Names of special volumes (HFFibre, HFPMT, HFFibreBundles)
144  fillNameVector(cpv, "HFFibre", php.hfFibreNames_);
145  fillNameVector(cpv, "HFPMT", php.hfPMTNames_);
146  fillNameVector(cpv, "HFFibreBundleStraight", php.hfFibreStraightNames_);
147  fillNameVector(cpv, "HFFibreBundleConical", php.hfFibreConicalNames_);
148  }
149  {
150  BenchmarkGrd counter("HcalSimParametersFromDD HCal materials OnlyForHcalSimNumbering, HCAL");
151 
152  while (fv.firstChild()) {
153  std::vector<int> copy = fv.copyNos();
154  // idet = 3 for HB and 4 for HE (convention in the ddalgo code for HB/HE)
155  int idet = (copy.size() > 1) ? (copy[1] / 1000) : 0;
156  if ((idet == 3) || (idet == 4)) {
157  std::string_view matName = dd4hep::dd::noNamespace(fv.materialName());
158  if (std::find(std::begin(php.hcalMaterialNames_), std::end(php.hcalMaterialNames_), matName) ==
159  std::end(php.hcalMaterialNames_)) {
160  php.hcalMaterialNames_.emplace_back(matName);
161  }
162  }
163  }
164  }
165 
166  return buildParameters(php);
167 }
168 
170 #ifdef EDM_ML_DEBUG
171  std::stringstream ss0;
172  for (unsigned int it = 0; it < php.hfNames_.size(); it++) {
173  if (it / 10 * 10 == it)
174  ss0 << "\n";
175  ss0 << " [" << it << "] " << php.hfNames_[it];
176  }
177  edm::LogVerbatim("HCalGeom") << "HFNames: " << php.hfNames_.size() << ": " << ss0.str();
178 
179  std::stringstream ss1;
180  for (unsigned int it = 0; it < php.hfLevels_.size(); it++) {
181  if (it / 10 * 10 == it)
182  ss1 << "\n";
183  ss1 << " [" << it << "] " << php.hfLevels_[it];
184  }
185  edm::LogVerbatim("HCalGeom") << "HF Volume Levels: " << php.hfLevels_.size() << " hfLevels: " << ss1.str();
186 
187  std::stringstream ss2;
188  for (unsigned int it = 0; it < php.attenuationLength_.size(); it++) {
189  if (it / 10 * 10 == it)
190  ss2 << "\n";
191  ss2 << " " << convertMmToCm(php.attenuationLength_[it]);
192  }
193  edm::LogVerbatim("HCalGeom") << "AttenuationLength: " << php.attenuationLength_.size()
194  << " attL(1/cm): " << ss2.str();
195 
196  std::stringstream ss3;
197  for (unsigned int it = 0; it < php.lambdaLimits_.size(); it++) {
198  if (it / 10 * 10 == it)
199  ss3 << "\n";
200  ss3 << " " << php.lambdaLimits_[it];
201  }
202  edm::LogVerbatim("HCalGeom") << php.lambdaLimits_.size() << " Limits on lambda " << ss3.str();
203 
204  std::stringstream ss4;
205  for (unsigned int it = 0; it < php.longFiberLength_.size(); it++) {
206  if (it / 10 * 10 == it)
207  ss4 << "\n";
208  ss4 << " " << convertMmToCm(php.longFiberLength_[it]);
209  }
210  edm::LogVerbatim("HCalGeom") << php.longFiberLength_.size() << " Long Fibre Length(cm):" << ss4.str();
211 
212  std::stringstream ss5;
213  for (unsigned int it = 0; it < php.shortFiberLength_.size(); it++) {
214  if (it / 10 * 10 == it)
215  ss5 << "\n";
216  ss5 << " " << convertMmToCm(php.shortFiberLength_[it]);
217  }
218  edm::LogVerbatim("HCalGeom") << php.shortFiberLength_.size() << " Short Fibre Length(cm):" << ss5.str();
219 
220  edm::LogVerbatim("HCalGeom") << "HcalSimParameters: gets the Index matches for " << php.pmtRight_.size() << " PMTs";
221  for (unsigned int ii = 0; ii < php.pmtRight_.size(); ii++)
222  edm::LogVerbatim("HCalGeom") << "rIndexR[" << ii << "] = " << php.pmtRight_[ii] << " fibreR[" << ii
223  << "] = " << php.pmtFiberRight_[ii] << " rIndexL[" << ii << "] = " << php.pmtLeft_[ii]
224  << " fibreL[" << ii << "] = " << php.pmtFiberLeft_[ii];
225 
226  edm::LogVerbatim("HCalGeom") << "HcalSimParameters: " << php.hfFibreNames_.size() << " names of HFFibre";
227  for (unsigned int k = 0; k < php.hfFibreNames_.size(); ++k)
228  edm::LogVerbatim("HCalGeom") << "[" << k << "] " << php.hfFibreNames_[k];
229 
230  edm::LogVerbatim("HCalGeom") << "HcalSimParameters: " << php.hfPMTNames_.size() << " names of HFPMT";
231  for (unsigned int k = 0; k < php.hfPMTNames_.size(); ++k)
232  edm::LogVerbatim("HCalGeom") << "[" << k << "] " << php.hfPMTNames_[k];
233 
234  edm::LogVerbatim("HCalGeom") << "HcalSimParameters: " << php.hfFibreStraightNames_.size()
235  << " names of HFFibreBundleStraight";
236  for (unsigned int k = 0; k < php.hfFibreStraightNames_.size(); ++k)
237  edm::LogVerbatim("HCalGeom") << "[" << k << "] " << php.hfFibreStraightNames_[k];
238 
239  edm::LogVerbatim("HCalGeom") << "HcalSimParameters: " << php.hfFibreConicalNames_.size()
240  << " names of FibreBundleConical";
241  for (unsigned int k = 0; k < php.hfFibreConicalNames_.size(); ++k)
242  edm::LogVerbatim("HCalGeom") << "[" << k << "] " << php.hfFibreConicalNames_[k];
243 
244  edm::LogVerbatim("HCalGeom") << "HcalSimParameters: " << php.hcalMaterialNames_.size() << " names of HCAL materials";
245  for (unsigned int k = 0; k < php.hcalMaterialNames_.size(); ++k)
246  edm::LogVerbatim("HCalGeom") << "[" << k << "] " << php.hcalMaterialNames_[k];
247 #endif
248 
249  return true;
250 }
251 
253  const std::string& attribute,
254  const std::string& value,
255  std::vector<std::string>& lvnames) {
257  DDFilteredView fv(*cpv, filter);
258  lvnames = getNames(fv);
259 }
260 
262  const std::string& value,
263  std::vector<std::string>& lvnames) {
264  {
265  BenchmarkGrd counter("HcalSimParametersFromDD::fillNameVector");
266  const cms::DDFilter filter("Volume", value);
267  cms::DDFilteredView fv(cpv, filter);
268  lvnames = getNames(fv);
269  }
270 }
271 
272 void HcalSimParametersFromDD::fillPMTs(const std::vector<double>& neta, bool lOrR, HcalSimulationParameters& php) {
273  {
274  BenchmarkGrd counter("HcalSimParametersFromDD::fillPMTs");
275  for (unsigned int ii = 0; ii < neta.size(); ii++) {
276  int index = static_cast<int>(neta[ii]);
277  int ir = -1, ifib = -1;
278  if (index >= 0) {
279  ir = index / 10;
280  ifib = index % 10;
281  }
282  if (lOrR) {
283  php.pmtLeft_.push_back(ir);
284  php.pmtFiberLeft_.push_back(ifib);
285  } else {
286  php.pmtRight_.push_back(ir);
287  php.pmtFiberRight_.push_back(ifib);
288  }
289  }
290  }
291 }
292 
294  if (std::find(std::begin(php.hfNames_), std::end(php.hfNames_), name) != std::end(php.hfNames_))
295  return true;
296  if (std::find(std::begin(php.hfFibreNames_), std::end(php.hfFibreNames_), name) != std::end(php.hfFibreNames_))
297  return true;
298  if (std::find(std::begin(php.hfPMTNames_), std::end(php.hfPMTNames_), name) != std::end(php.hfPMTNames_))
299  return true;
300  if (std::find(std::begin(php.hfFibreStraightNames_), std::end(php.hfFibreStraightNames_), name) !=
301  std::end(php.hfFibreStraightNames_))
302  return true;
303  if (std::find(std::begin(php.hfFibreConicalNames_), std::end(php.hfFibreConicalNames_), name) !=
304  std::end(php.hfFibreConicalNames_))
305  return true;
306 
307  return false;
308 }
309 
310 std::vector<std::string> HcalSimParametersFromDD::getNames(DDFilteredView& fv) {
311  std::vector<std::string> tmp;
312  bool dodet = fv.firstChild();
313  while (dodet) {
314  const DDLogicalPart& log = fv.logicalPart();
315  bool ok = true;
316 
317  for (unsigned int i = 0; i < tmp.size(); ++i) {
318  if (!strcmp(tmp[i].c_str(), log.name().name().c_str())) {
319  ok = false;
320  break;
321  }
322  }
323  if (ok)
324  tmp.push_back(log.name().name());
325  dodet = fv.next();
326  }
327  return tmp;
328 }
329 
331  std::vector<std::string> tmp;
332  while (fv.firstChild()) {
333  if (std::find(std::begin(tmp), std::end(tmp), fv.name()) == std::end(tmp))
334  tmp.emplace_back(fv.name());
335  }
336  return tmp;
337 }
338 
339 std::vector<double> HcalSimParametersFromDD::getDDDArray(const std::string& str, const DDsvalues_type& sv, int& nmin) {
340 #ifdef EDM_ML_DEBUG
341  edm::LogVerbatim("HCalGeom") << "HcalSimParametersFromDD::getDDDArray called for " << str << " with nMin " << nmin;
342 #endif
343  DDValue value(str);
344  if (DDfetch(&sv, value)) {
345 #ifdef EDM_ML_DEBUG
346  edm::LogVerbatim("HCalGeom") << value;
347 #endif
348  const std::vector<double>& fvec = value.doubles();
349  int nval = fvec.size();
350  if (nmin > 0) {
351  if (nval < nmin) {
352  edm::LogError("HCalGeom") << "# of " << str << " bins " << nval << " < " << nmin << " ==> illegal";
353  throw cms::Exception("HcalSimParametersFromDD") << "nval < nmin for array " << str << "\n";
354  }
355  } else {
356  if (nval < 1 && nmin != 0) {
357  edm::LogError("HCalGeom") << "# of " << str << " bins " << nval << " < 1 ==> illegal (nmin=" << nmin << ")";
358  throw cms::Exception("HcalSimParametersFromDD") << "nval < 1 for array " << str << "\n";
359  }
360  }
361  nmin = nval;
362  return fvec;
363  } else {
364  if (nmin != 0) {
365  edm::LogError("HCalGeom") << "Cannot get array " << str;
366  throw cms::Exception("HcalSimParametersFromDD") << "cannot get array " << str << "\n";
367  } else {
368  std::vector<double> fvec;
369  return fvec;
370  }
371  }
372 }
Log< level::Info, true > LogVerbatim
std::vector< std::string > getNames(DDFilteredView &fv)
std::vector< double > getDDDArray(const std::string &str, const DDsvalues_type &sv, int &nmin)
std::vector< double > shortFiberLength_
const std::vector< int > copyNos() const
The list of the volume copy numbers.
std::vector< double > longFiberLength_
std::vector< std::string > hfNames_
std::vector< std::string > hfFibreNames_
Log< level::Error, false > LogError
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
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
bool isItHF(const std::string &, const HcalSimulationParameters &)
std::string_view name() const
std::vector< std::pair< unsigned int, DDValue > > DDsvalues_type
Definition: DDsvalues.h:12
const int neta
bool next()
set current node to the next node in the filtered tree
bool buildParameters(const HcalSimulationParameters &)
std::vector< std::string > hfFibreConicalNames_
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:93
std::string_view materialName() const
Definition: value.py:1
bool firstChild()
set the current node to the first child
ii
Definition: cuy.py:589
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
DDsvalues_type mergedSpecifics() const
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the filtered-view.
T get(const std::string &)
extract attribute value
constexpr NumType convertMmToCm(NumType millimeters)
Definition: angle_units.h:44
std::vector< std::string > hcalMaterialNames_
bool build(const DDCompactView *, HcalSimulationParameters &)
std::vector< std::string > hfPMTNames_
static std::atomic< unsigned int > counter
void fillNameVector(const DDCompactView *, const std::string &, const std::string &, std::vector< std::string > &)
bool firstChild()
set the current node to the first child ...
std::vector< std::string > hfFibreStraightNames_
void getNames(uint8 *from, uint32 from_len, Strings &to)
Definition: MsgTools.h:85
#define str(s)
std::vector< double > attenuationLength_
tmp
align.sh
Definition: createJobs.py:716
void fillPMTs(const std::vector< double > &, bool, HcalSimulationParameters &)