CMS 3D CMS Logo

EcalSimParametersFromDD.cc
Go to the documentation of this file.
9 #include <iostream>
10 #include <iomanip>
11 
12 //#define EDM_ML_DEBUG
13 
14 using namespace geant_units::operators;
15 
16 template <typename T>
17 void myPrint(std::string value, const std::vector<T>& vec) {
18  edm::LogVerbatim("EcalGeom") << "EcalSimParametersFromDD: " << vec.size() << " entries for " << value << ":";
19  unsigned int i(0);
20  for (const auto& e : vec) {
21  edm::LogVerbatim("EcalGeom") << " (" << i << ") " << e;
22  ++i;
23  }
24 }
25 
27 #ifdef EDM_ML_DEBUG
28  edm::LogVerbatim("EcalGeom")
29  << "Inside EcalSimParametersFromDD::build(const DDCompactView*, const std::string&, EcalSimulationParameters&)";
30 #endif
31  // Get the filtered view
32  std::string attribute = "ReadOutName";
33  DDSpecificsMatchesValueFilter filter{DDValue(attribute, name, 0)};
34  DDFilteredView fv(*cpv, filter);
35  bool dodet = fv.firstChild();
37 
38  //First the specpars
39  php.useWeight_ = true;
40  std::vector<double> tempD = getDDDArray("EnergyWeight", sv);
41  if (!tempD.empty()) {
42  if (tempD[0] < 0.1)
43  php.useWeight_ = false;
44  }
45  tempD = getDDDArray("nxtalEta", sv);
46  if (tempD.empty())
47  php.nxtalEta_ = 0;
48  else
49  php.nxtalEta_ = static_cast<int>(tempD[0]);
50  tempD = getDDDArray("nxtalPhi", sv);
51  if (tempD.empty())
52  php.nxtalPhi_ = 0;
53  else
54  php.nxtalPhi_ = static_cast<int>(tempD[0]);
55  tempD = getDDDArray("PhiBaskets", sv);
56  if (tempD.empty())
57  php.phiBaskets_ = 0;
58  else
59  php.phiBaskets_ = static_cast<int>(tempD[0]);
60  php.etaBaskets_ = dbl_to_int(getDDDArray("EtaBaskets", sv));
61  tempD = getDDDArray("ncrys", sv);
62  if (tempD.empty())
63  php.ncrys_ = 0;
64  else
65  php.ncrys_ = static_cast<int>(tempD[0]);
66  tempD = getDDDArray("nmods", sv);
67  if (tempD.empty())
68  php.nmods_ = 0;
69  else
70  php.nmods_ = static_cast<int>(tempD[0]);
71 
72  std::vector<std::string> tempS = getStringArray("Depth1Name", sv);
73  if (!tempS.empty())
74  php.depth1Name_ = tempS[0];
75  else
76  php.depth1Name_ = " ";
77  tempS = getStringArray("Depth2Name", sv);
78  if (!tempS.empty())
79  php.depth2Name_ = tempS[0];
80  else
81  php.depth2Name_ = " ";
82 
83  //Then the logical volumes
84  while (dodet) {
85  if (std::find(php.lvNames_.begin(), php.lvNames_.end(), fv.logicalPart().name().name()) == php.lvNames_.end()) {
86  php.matNames_.emplace_back(fv.logicalPart().material().name().name());
87  php.lvNames_.emplace_back(fv.logicalPart().name().name());
88  const DDSolid& sol = fv.logicalPart().solid();
89  const std::vector<double>& paras = sol.parameters();
90  double dz = (sol.shape() == DDSolidShape::ddtrap) ? (2 * paras[0]) : 0.0;
91  php.dzs_.emplace_back(dz);
92  }
93  dodet = fv.next();
94  }
95  return this->buildParameters(php);
96 }
97 
99  const std::string& name,
101 #ifdef EDM_ML_DEBUG
102  edm::LogVerbatim("EcalGeom") << "Inside EcalSimParametersFromDD::build(const cms::DDCompactView*, const std::string, "
103  "EcalSimulationParameters&)";
104 #endif
105  // Get the filtered view
106  std::string attribute = "ReadOutName";
107  cms::DDFilteredView fv(cpv->detector(), cpv->detector()->worldVolume());
108 
109  //First the specpars
110  std::string specName = ((name == "EcalHitsEE") ? "ecal_ee" : ((name == "EcalHitsES") ? "ecal_sf" : "ecal_eb"));
111 
112  php.useWeight_ = true;
113  std::vector<double> tempD = fv.get<std::vector<double> >(specName, "EnergyWeight");
114  if (!tempD.empty()) {
115  if (tempD[0] < 0.1)
116  php.useWeight_ = false;
117  }
118  tempD = fv.get<std::vector<double> >(specName, "nxtalEta");
119  if (tempD.empty())
120  php.nxtalEta_ = 0;
121  else
122  php.nxtalEta_ = static_cast<int>(tempD[0]);
123  tempD = fv.get<std::vector<double> >(specName, "nxtalPhi");
124  if (tempD.empty())
125  php.nxtalPhi_ = 0;
126  else
127  php.nxtalPhi_ = static_cast<int>(tempD[0]);
128  tempD = fv.get<std::vector<double> >(specName, "PhiBaskets");
129  if (tempD.empty())
130  php.phiBaskets_ = 0;
131  else
132  php.phiBaskets_ = static_cast<int>(tempD[0]);
133  php.etaBaskets_ = dbl_to_int(fv.get<std::vector<double> >(specName, "EtaBaskets"));
134  tempD = fv.get<std::vector<double> >(specName, "ncrys");
135  if (tempD.empty())
136  php.ncrys_ = 0;
137  else
138  php.ncrys_ = static_cast<int>(tempD[0]);
139  tempD = fv.get<std::vector<double> >(specName, "nmods");
140  if (tempD.empty())
141  php.nmods_ = 0;
142  else
143  php.nmods_ = static_cast<int>(tempD[0]);
144 
145  std::vector<std::string> tempS = fv.get<std::vector<std::string> >(specName, "Depth1Name");
146  if (!tempS.empty())
147  php.depth1Name_ = tempS[0];
148  else
149  php.depth1Name_ = " ";
150  tempS = fv.get<std::vector<std::string> >(specName, "Depth2Name");
151  if (!tempS.empty())
152  php.depth2Name_ = tempS[0];
153  else
154  php.depth2Name_ = " ";
155 
156  //Then the logical volumes
157  cms::DDSpecParRefs refs;
158  const cms::DDSpecParRegistry& mypar = cpv->specpars();
159  mypar.filter(refs, attribute, name);
160  fv.mergedSpecifics(refs);
161  while (fv.firstChild()) {
162  const std::string name{fv.name().data(), fv.name().size()};
163  const std::string matName{cms::dd::noNamespace(fv.materialName()).data(),
164  cms::dd::noNamespace(fv.materialName()).size()};
165  if (std::find(php.lvNames_.begin(), php.lvNames_.end(), name) == php.lvNames_.end()) {
166  php.matNames_.emplace_back(matName);
167  php.lvNames_.emplace_back(name);
168  const std::vector<double>& paras = fv.parameters();
169  double dz = (fv.isATrapezoid()) ? convertCmToMm(2 * paras[0]) : 0.0;
170  php.dzs_.emplace_back(dz);
171  }
172  };
173 
174  return this->buildParameters(php);
175 }
176 
178 #ifdef EDM_ML_DEBUG
179  edm::LogVerbatim("EcalGeom") << "EcalSimParametersFromDD:: nxtalEta:" << php.nxtalEta_
180  << " nxtalPhi:" << php.nxtalPhi_ << " phiBaskets:" << php.phiBaskets_
181  << " ncrys:" << php.ncrys_ << " nmods: " << php.nmods_ << " useWeight:" << php.useWeight_
182  << " DeothNames:" << php.depth1Name_ << ":" << php.depth2Name_;
183  myPrint("etaBaskets", php.etaBaskets_);
184  edm::LogVerbatim("EcalGeom") << "EcalSimParametersFromDD:: " << php.lvNames_.size() << " lvNames, "
185  << php.matNames_.size() << " matNames and " << php.dzs_.size() << "dzs";
186 #endif
187 
188  return true;
189 }
190 
192 #ifdef EDM_ML_DEBUG
193  edm::LogVerbatim("EcalGeom") << "EcalSimParametersFromDD:getDDDArray called for " << str;
194 #endif
195  DDValue value(str);
196  if (DDfetch(&sv, value)) {
197 #ifdef EDM_ML_DEBUG
198  edm::LogVerbatim("EcalGeom") << value;
199 #endif
200  const std::vector<double>& fvec = value.doubles();
201  return fvec;
202  } else {
203  std::vector<double> fvec;
204  return fvec;
205  }
206 }
207 
208 std::vector<std::string> EcalSimParametersFromDD::getStringArray(const std::string& str, const DDsvalues_type& sv) {
209 #ifdef EDM_ML_DEBUG
210  edm::LogVerbatim("EcalGeom") << "EcalSimParametersFromDD:getStringArray called for " << str;
211 #endif
212  DDValue value(str);
213  if (DDfetch(&sv, value)) {
214 #ifdef EDM_ML_DEBUG
215  edm::LogVerbatim("EcalGeom") << value;
216 #endif
217  const std::vector<std::string>& fvec = value.strings();
218  return fvec;
219  } else {
220  std::vector<std::string> fvec;
221  return fvec;
222  }
223 }
size
Write out results.
const std::vector< double > & parameters(void) const
Give the parameters of the solid.
Definition: DDSolid.cc:121
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< std::string > lvNames_
std::vector< std::string > getStringArray(const std::string &, const DDsvalues_type &)
Volume worldVolume() const
Handle to the world volume containing everything.
Definition: DDDetector.cc:41
void filter(DDSpecParRefs &, std::string_view, std::string_view) const
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
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
void myPrint(std::string value, const std::vector< T > &vec)
A DDSolid represents the shape of a part.
Definition: DDSolid.h:39
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::string > matNames_
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
DDSolidShape shape(void) const
The type of the solid.
Definition: DDSolid.cc:119
bool build(const DDCompactView *, const std::string &name, EcalSimulationParameters &)
Definition: value.py:1
constexpr NumType convertCmToMm(NumType centimeters)
Definition: GeantUnits.h:68
const std::vector< std::string > & strings() const
a reference to the std::string-valued values stored in the given instance of DDValue ...
Definition: DDValue.h:60
std::vector< double > getDDDArray(const std::string &, const DDsvalues_type &)
std::vector< const DDSpecPar * > DDSpecParRefs
DDsvalues_type mergedSpecifics() const
DDSpecParRegistry const & specpars() const
Definition: DDCompactView.h:33
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
bool firstChild()
set the current node to the first child ...
#define str(s)
const std::string & name() const
Returns the name.
Definition: DDName.cc:40
bool buildParameters(const EcalSimulationParameters &)
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