CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalParametersFromDD.cc
Go to the documentation of this file.
9 
11 #include "CLHEP/Units/GlobalSystemOfUnits.h"
12 #include <iostream>
13 #include <iomanip>
14 
15 //#define EDM_ML_DEBUG
16 using namespace geant_units::operators;
17 
18 namespace {
19  int getTopologyMode(const char* s, const DDsvalues_type& sv, bool type) {
20  DDValue val(s);
21  if (DDfetch(&sv, val)) {
22  const std::vector<std::string>& fvec = val.strings();
23  if (fvec.empty()) {
24  throw cms::Exception("HcalParametersFromDD") << "Failed to get " << s << " tag.";
25  }
26 
27  int result(-1);
28  if (type) {
31  result = static_cast<int>(mode);
32  } else {
35  result = static_cast<int>(mode);
36  }
37  return result;
38  } else {
39  throw cms::Exception("HcalParametersFromDD") << "Failed to get " << s << " tag.";
40  }
41  }
42 } // namespace
43 
45  //Special parameters at simulation level
46  std::string attribute = "OnlyForHcalSimNumbering";
47  DDSpecificsHasNamedValueFilter filter1{attribute};
48  DDFilteredView fv1(*cpv, filter1);
49  bool ok = fv1.firstChild();
50 
51  const int nEtaMax = 100;
52 
53  if (ok) {
54  std::unique_ptr<HcalGeomParameters> geom = std::make_unique<HcalGeomParameters>();
55  geom->loadGeometry(fv1, php);
56  php.modHB = geom->getModHalfHBHE(0);
57  php.modHE = geom->getModHalfHBHE(1);
58  php.dzVcal = geom->getConstDzHF();
59  geom->getConstRHO(php.rHO);
60 
61  php.phioff = DDVectorGetter::get("phioff");
62  php.etaTable = DDVectorGetter::get("etaTable");
63  php.rTable = DDVectorGetter::get("rTable");
64  php.phibin = DDVectorGetter::get("phibin");
65  php.phitable = DDVectorGetter::get("phitable");
66  for (unsigned int i = 1; i <= nEtaMax; ++i) {
67  std::stringstream sstm;
68  sstm << "layerGroupSimEta" << i;
69  std::string tempName = sstm.str();
70  if (DDVectorGetter::check(tempName)) {
71  HcalParameters::LayerItem layerGroupEta;
72  layerGroupEta.layer = i;
73  layerGroupEta.layerGroup = dbl_to_int(DDVectorGetter::get(tempName));
74  php.layerGroupEtaSim.emplace_back(layerGroupEta);
75  }
76  }
77  php.etaMin = dbl_to_int(DDVectorGetter::get("etaMin"));
78  php.etaMax = dbl_to_int(DDVectorGetter::get("etaMax"));
79  php.etaMin[0] = 1;
80  if (php.etaMax[1] >= php.etaMin[1])
81  php.etaMax[1] = static_cast<int>(php.etaTable.size()) - 1;
82  php.etaMax[2] = php.etaMin[2] + static_cast<int>(php.rTable.size()) - 2;
83  php.etaRange = DDVectorGetter::get("etaRange");
84  php.gparHF = DDVectorGetter::get("gparHF");
85  php.noff = dbl_to_int(DDVectorGetter::get("noff"));
86  php.Layer0Wt = DDVectorGetter::get("Layer0Wt");
87  php.HBGains = DDVectorGetter::get("HBGains");
88  php.HBShift = dbl_to_int(DDVectorGetter::get("HBShift"));
89  php.HEGains = DDVectorGetter::get("HEGains");
90  php.HEShift = dbl_to_int(DDVectorGetter::get("HEShift"));
91  php.HFGains = DDVectorGetter::get("HFGains");
92  php.HFShift = dbl_to_int(DDVectorGetter::get("HFShift"));
93  php.maxDepth = dbl_to_int(DDVectorGetter::get("MaxDepth"));
94  } else {
95  throw cms::Exception("HcalParametersFromDD") << "Not found " << attribute.c_str() << " but needed.";
96  }
97  for (unsigned int i = 0; i < php.rTable.size(); ++i) {
98  unsigned int k = php.rTable.size() - i - 1;
99  php.etaTableHF.emplace_back(-log(tan(0.5 * atan(php.rTable[k] / php.gparHF[4]))));
100  }
101  //Special parameters at reconstruction level
102  attribute = "OnlyForHcalRecNumbering";
103  DDSpecificsHasNamedValueFilter filter2{attribute};
104  DDFilteredView fv2(*cpv, filter2);
105  ok = fv2.firstChild();
106  if (ok) {
108  int topoMode = getTopologyMode("TopologyMode", sv, true);
109  int trigMode = getTopologyMode("TriggerMode", sv, false);
110  php.topologyMode = ((trigMode & 0xFF) << 8) | (topoMode & 0xFF);
111  php.etagroup = dbl_to_int(DDVectorGetter::get("etagroup"));
112  php.phigroup = dbl_to_int(DDVectorGetter::get("phigroup"));
113  for (unsigned int i = 1; i <= nEtaMax; ++i) {
114  std::stringstream sstm;
115  sstm << "layerGroupRecEta" << i;
116  std::string tempName = sstm.str();
117  if (DDVectorGetter::check(tempName)) {
118  HcalParameters::LayerItem layerGroupEta;
119  layerGroupEta.layer = i;
120  layerGroupEta.layerGroup = dbl_to_int(DDVectorGetter::get(tempName));
121  php.layerGroupEtaRec.emplace_back(layerGroupEta);
122  }
123  }
124  } else {
125  throw cms::Exception("HcalParametersFromDD") << "Not found " << attribute.c_str() << " but needed.";
126  }
127 
128  return build(php);
129 }
130 
132 #ifdef EDM_ML_DEBUG
133  int i(0);
134  std::stringstream ss0;
135  for (unsigned int it = 0; it < php.maxDepth.size(); it++) {
136  if (it / 10 * 10 == it) {
137  ss0 << "\n";
138  }
139  ss0 << " [" << it << "] " << php.maxDepth[it];
140  }
141  edm::LogVerbatim("HCalGeom") << "HcalParametersFromDD::maxDepth: " << php.maxDepth.size() << ": " << ss0.str();
142  std::stringstream ss1;
143  for (unsigned int it = 0; it < php.modHB.size(); it++) {
144  if (it / 10 * 10 == it) {
145  ss1 << "\n";
146  }
147  ss1 << " [" << it << "] " << php.modHB[it];
148  }
149  edm::LogVerbatim("HCalGeom") << "HcalParametersFromDD::modHB: " << php.modHB.size() << ": " << ss1.str();
150  std::stringstream ss2;
151  for (unsigned int it = 0; it < php.modHE.size(); it++) {
152  if (it / 10 * 10 == it) {
153  ss2 << "\n";
154  }
155  ss2 << " [" << it << "] " << php.modHE[it];
156  }
157  edm::LogVerbatim("HCalGeom") << "HcalParametersFromDD::modHE: " << php.modHE.size() << ": " << ss2.str();
158  std::stringstream ss3;
159  for (unsigned int it = 0; it < php.phioff.size(); it++) {
160  if (it / 10 * 10 == it) {
161  ss3 << "\n";
162  }
163  ss3 << " [" << it << "] " << convertRadToDeg(php.phioff[it]);
164  }
165  edm::LogVerbatim("HCalGeom") << "HcalParametersFromDD::phiOff: " << php.phioff.size() << ": " << ss3.str();
166  std::stringstream ss4;
167  for (unsigned int it = 0; it < php.etaTable.size(); it++) {
168  if (it / 10 * 10 == it) {
169  ss4 << "\n";
170  }
171  ss4 << " [" << it << "] " << php.etaTable[it];
172  }
173  edm::LogVerbatim("HCalGeom") << "HcalParametersFromDD::etaTable: " << php.etaTable.size() << ": " << ss4.str();
174  std::stringstream ss5;
175  for (unsigned int it = 0; it < php.rTable.size(); it++) {
176  if (it / 10 * 10 == it) {
177  ss5 << "\n";
178  }
179  ss5 << " [" << it << "] " << convertMmToCm(php.rTable[it]);
180  }
181  edm::LogVerbatim("HCalGeom") << "HcalParametersFromDD::rTable: " << php.rTable.size() << ": " << ss5.str();
182  std::stringstream ss6;
183  for (unsigned int it = 0; it < php.phibin.size(); it++) {
184  if (it / 10 * 10 == it) {
185  ss6 << "\n";
186  }
187  ss6 << " [" << it << "] " << convertRadToDeg(php.phibin[it]);
188  }
189  edm::LogVerbatim("HCalGeom") << "HcalParametersFromDD:phibin: " << php.phibin.size() << ": " << ss6.str();
190  std::stringstream ss7;
191  for (unsigned int it = 0; it < php.phitable.size(); it++) {
192  if (it / 10 * 10 == it) {
193  ss7 << "\n";
194  }
195  ss7 << " [" << it << "] " << convertRadToDeg(php.phitable[it]);
196  }
197  edm::LogVerbatim("HCalGeom") << "HcalParametersFromDD:phitable: " << php.phitable.size() << ": " << ss7.str();
198  std::cout << "HcalParametersFromDD: " << php.layerGroupEtaSim.size() << " layerGroupEtaSim blocks" << std::endl;
199  std::vector<int>::const_iterator kt;
200  std::vector<double>::const_iterator it;
201  for (unsigned int k = 0; k < php.layerGroupEtaSim.size(); ++k) {
202  std::cout << "layerGroupEtaSim[" << k << "] Layer " << php.layerGroupEtaSim[k].layer;
203  for (kt = php.layerGroupEtaSim[k].layerGroup.begin(), i = 0; kt != php.layerGroupEtaSim[k].layerGroup.end(); ++kt)
204  std::cout << " " << ++i << ":" << (*kt);
205  std::cout << std::endl;
206  }
207  std::cout << "HcalParametersFromDD: " << php.etaMin.size() << " etaMin values";
208  for (kt = php.etaMin.begin(), i = 0; kt != php.etaMin.end(); ++kt)
209  std::cout << " [" << ++i << "] = " << (*kt);
210  std::cout << std::endl;
211  std::cout << "HcalParametersFromDD: " << php.etaMax.size() << " etaMax values";
212  for (kt = php.etaMax.begin(), i = 0; kt != php.etaMax.end(); ++kt)
213  std::cout << " [" << ++i << "] = " << (*kt);
214  std::cout << std::endl;
215  std::cout << "HcalParametersFromDD: " << php.etaRange.size() << " etaRange values";
216  for (it = php.etaRange.begin(), i = 0; it != php.etaRange.end(); ++it)
217  std::cout << " [" << ++i << "] = " << (*it);
218  std::cout << std::endl;
219  std::cout << "HcalParametersFromDD: " << php.gparHF.size() << " gparHF values";
220  for (it = php.gparHF.begin(), i = 0; it != php.gparHF.end(); ++it)
221  std::cout << " [" << ++i << "] = " << (*it) / CLHEP::cm;
222  std::cout << std::endl;
223  std::cout << "HcalParametersFromDD: " << php.noff.size() << " noff values";
224  for (kt = php.noff.begin(), i = 0; kt != php.noff.end(); ++kt)
225  std::cout << " [" << ++i << "] = " << (*kt);
226  std::cout << std::endl;
227  std::cout << "HcalParametersFromDD: " << php.Layer0Wt.size() << " Layer0Wt values";
228  for (it = php.Layer0Wt.begin(), i = 0; it != php.Layer0Wt.end(); ++it)
229  std::cout << " [" << ++i << "] = " << (*it);
230  std::cout << std::endl;
231  std::cout << "HcalParametersFromDD: " << php.HBGains.size() << " Shift/Gains values for HB";
232  for (unsigned k = 0; k < php.HBGains.size(); ++k)
233  std::cout << " [" << k << "] = " << php.HBShift[k] << ":" << php.HBGains[k];
234  std::cout << std::endl;
235  std::cout << "HcalParametersFromDD: " << php.HEGains.size() << " Shift/Gains values for HE";
236  for (unsigned k = 0; k < php.HEGains.size(); ++k)
237  std::cout << " [" << k << "] = " << php.HEShift[k] << ":" << php.HEGains[k];
238  std::cout << std::endl;
239  std::cout << "HcalParametersFromDD: " << php.HFGains.size() << " Shift/Gains values for HF";
240  for (unsigned k = 0; k < php.HFGains.size(); ++k)
241  std::cout << " [" << k << "] = " << php.HFShift[k] << ":" << php.HFGains[k];
242  std::cout << std::endl;
243  std::cout << "HcalParametersFromDD: " << php.etagroup.size() << " etagroup values";
244  for (kt = php.etagroup.begin(), i = 0; kt != php.etagroup.end(); ++kt)
245  std::cout << " [" << ++i << "] = " << (*kt);
246  std::cout << std::endl;
247  std::cout << "HcalParametersFromDD: " << php.phigroup.size() << " phigroup values";
248  for (kt = php.phigroup.begin(), i = 0; kt != php.phigroup.end(); ++kt)
249  std::cout << " [" << ++i << "] = " << (*kt);
250  std::cout << std::endl;
251  std::cout << "HcalParametersFromDD: " << php.layerGroupEtaRec.size() << " layerGroupEtaRec blocks" << std::endl;
252  for (unsigned int k = 0; k < php.layerGroupEtaRec.size(); ++k) {
253  std::cout << "layerGroupEtaRec[" << k << "] Layer " << php.layerGroupEtaRec[k].layer;
254  for (kt = php.layerGroupEtaRec[k].layerGroup.begin(), i = 0; kt != php.layerGroupEtaRec[k].layerGroup.end(); ++kt)
255  std::cout << " " << ++i << ":" << (*kt);
256  std::cout << std::endl;
257  }
258  std::cout << "HcalParametersFromDD: (topology|trigger)Mode " << std::hex << php.topologyMode << std::dec << std::endl;
259 #endif
260 
261  return true;
262 }
type
Definition: HCALResponse.h:21
std::vector< double > etaTable
std::vector< int > etagroup
bool build(const DDCompactView *, HcalParameters &)
std::vector< double > etaRange
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:80
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
std::vector< int > modHB
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< LayerItem > layerGroupEtaSim
std::vector< std::pair< unsigned int, DDValue > > DDsvalues_type
Definition: DDsvalues.h:12
bool check(const std::string &)
std::vector< double > rHO
std::vector< int > layerGroup
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
std::vector< int > modHE
std::vector< int > HFShift
std::vector< double > get(const std::string &)
std::vector< double > HEGains
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< double > HFGains
constexpr NumType convertMmToCm(NumType millimeters)
Definition: GeantUnits.h:62
std::vector< int > noff
std::vector< int > HBShift
std::vector< int > maxDepth
std::vector< int > phigroup
std::vector< int > etaMin
T parseString(const std::string &value)