CMS 3D CMS Logo

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