CMS 3D CMS Logo

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