CMS 3D CMS Logo

HGCalParametersFromDD.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 
17 namespace {
18  HGCalGeometryMode::GeometryMode getGeometryMode(const char* s,
19  const DDsvalues_type & sv) {
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("HGCalGeom") << "Failed to get " << s << " tag.";
25  }
26 
29  return result;
30  } else {
31  throw cms::Exception("HGCalGeom") << "Failed to get "<< s << " tag";
32  }
33  }
34  HGCalGeometryMode::WaferMode getGeometryWaferMode(const char* s,
35  const DDsvalues_type & sv){
36  DDValue val(s);
37  if (DDfetch(&sv, val)) {
38  const std::vector<std::string> & fvec = val.strings();
39  if (fvec.empty()) {
40  throw cms::Exception("HGCalGeom") << "Failed to get " << s << " tag.";
41  }
42 
45  return result;
46  } else {
47  throw cms::Exception("HGCalGeom") << "Failed to get "<< s << " tag";
48  }
49  }
50 }
51 
53  HGCalParameters& php,
54  const std::string& name,
55  const std::string& namew,
56  const std::string& namec,
57  const std::string& namet) {
58 
59 #ifdef EDM_ML_DEBUG
60  edm::LogVerbatim("HGCalGeom") << "HGCalParametersFromDD::build called with "
61  << "names " << name << ":" << namew << ":"
62  << namec;
63 #endif
64 
65  //Special parameters at simulation level
66  std::string attribute = "Volume";
68  DDValue val(attribute, value, 0.0);
70  DDFilteredView fv(*cpv,filter);
71  bool ok = fv.firstChild();
73 
74  if (ok) {
76  php.mode_ = getGeometryMode("GeometryMode", sv);
77 #ifdef EDM_ML_DEBUG
78  edm::LogVerbatim("HGCalGeom") << "GeometryMode " << php.mode_
79  << ":" << HGCalGeometryMode::Hexagon << ":"
81  << ":" << HGCalGeometryMode::Hexagon8 << ":"
84 #endif
86  if ((php.mode_ == HGCalGeometryMode::Hexagon) ||
88  attribute = "OnlyForHGCalNumbering";
89  value = namet;
90  DDValue val2(attribute, value, 0.0);
91  DDSpecificsMatchesValueFilter filter2{val2};
92  DDFilteredView fv2(*cpv,filter2);
93  bool ok2 = fv2.firstChild();
94  if (ok2) {
96  mode = getGeometryWaferMode("WaferMode", sv2);
97 #ifdef EDM_ML_DEBUG
98  edm::LogVerbatim("HGCalGeom") << "WaferMode " << mode << ":"
101 #endif
102  }
103  }
104  if ((php.mode_ == HGCalGeometryMode::Hexagon8) ||
106  php.levelT_ = dbl_to_int(getDDDArray("LevelTop",sv));
107  php.nCellsFine_ = php.nCellsCoarse_ = 0;
108 #ifdef EDM_ML_DEBUG
109  edm::LogVerbatim("HGCalGeom") << "Top levels " << php.levelT_[0] << ":"
110  << php.levelT_[1];
111 #endif
112  attribute = "OnlyForHGCalNumbering";
113  value = namet;
114  DDValue val2(attribute, value, 0.0);
115  DDSpecificsMatchesValueFilter filter2{val2};
116  DDFilteredView fv2(*cpv,filter2);
117  bool ok2 = fv2.firstChild();
118  if (ok2) {
119  DDsvalues_type sv2(fv2.mergedSpecifics());
120  mode = getGeometryWaferMode("WaferMode", sv2);
121  php.nCellsFine_ = (int)(getDDDValue("NumberOfCellsFine", sv2));
122  php.nCellsCoarse_ = (int)(getDDDValue("NumberOfCellsCoarse",sv2));
124  php.waferThick_ = HGCalParameters::k_ScaleFromDDD*getDDDValue("WaferThickness", sv2);
125  php.sensorSeparation_ = HGCalParameters::k_ScaleFromDDD*getDDDValue("SensorSeparation", sv2);
127  php.waferR_ = 0.5*HGCalParameters::k_ScaleToDDD*php.waferSize_/std::cos(30.0*CLHEP::deg);
128  php.etaMinBH_ = 0;
131 #ifdef EDM_ML_DEBUG
132  edm::LogVerbatim("HGCalGeom") << "WaferMode " << mode << ":"
135  << " # of cells|size for fine/coarse "
136  << php.nCellsFine_ << ":"
137  << php.cellSize_[0] << ":"
138  << php.nCellsCoarse_ << ":"
139  << php.cellSize_[1] << " wafer Params "
140  << php.waferSize_ << ":"
141  << php.waferR_ << ":"
142  << php.waferThick_ << ":"
143  << php.sensorSeparation_ << ":"
144  << php.mouseBite_ << ":" << php.waferR_;
145 #endif
146  for (int k=0; k<2; ++k) getCellPosition(php, k);
147  }
148  }
149  if (php.mode_ == HGCalGeometryMode::Hexagon) {
150  //Load the SpecPars
151  php.firstLayer_ = 1;
152  geom->loadSpecParsHexagon(fv, php, cpv, namew, namec);
153  //Load the Geometry parameters
154  geom->loadGeometryHexagon(fv, php, name, cpv, namew, namec, mode);
155  //Load cell parameters
156  geom->loadCellParsHexagon(cpv, php);
157  //Set complete fill mode
158  php.defineFull_ = false;
159  } else if (php.mode_ == HGCalGeometryMode::HexagonFull) {
160  //Load the SpecPars
161  php.firstLayer_ = 1;
162  geom->loadSpecParsHexagon(fv, php, cpv, namew, namec);
163  //Load the Geometry parameters
164  geom->loadGeometryHexagon(fv, php, name, cpv, namew, namec, mode);
165  //Modify some constants
166  geom->loadWaferHexagon(php);
167  //Load cell parameters
168  geom->loadCellParsHexagon(cpv, php);
169  //Set complete fill mode
170  php.defineFull_ = true;
171  } else if (php.mode_ == HGCalGeometryMode::Hexagon8) {
172  //Load the SpecPars
173  php.firstLayer_ = 1;
174  geom->loadSpecParsHexagon8(fv, php);
175  //Load Geometry parameters
176  geom->loadGeometryHexagon8(fv, php, 1);
177  //Set complete fill mode
178  php.defineFull_ = false;
179  //Load wafer positions
180  geom->loadWaferHexagon8(php);
181  } else if (php.mode_ == HGCalGeometryMode::Hexagon8Full) {
182  //Load the SpecPars
183  php.firstLayer_ = 1;
184  geom->loadSpecParsHexagon8(fv, php);
185  //Load Geometry parameters
186  geom->loadGeometryHexagon8(fv, php, 1);
187  //Set complete fill mode
188  php.defineFull_ = true;
189  //Load wafer positions
190  geom->loadWaferHexagon8(php);
191  } else if (php.mode_ == HGCalGeometryMode::Trapezoid) {
192  //Load maximum eta & top level
193  php.etaMinBH_ = getDDDValue("etaMinBH", sv);
194  php.levelT_ = dbl_to_int(getDDDArray("LevelTop",sv));
195  php.firstLayer_ = (int)(getDDDValue("FirstLayer", sv));
196  php.waferThick_ = HGCalParameters::k_ScaleFromDDD*getDDDValue("WaferThickness", sv);
197  php.waferSize_ = php.waferR_ = 0;
198  php.waferThick_ = php.sensorSeparation_= php.mouseBite_ = 0;
199 #ifdef EDM_ML_DEBUG
200  edm::LogVerbatim("HGCalGeom") << "Top levels " << php.levelT_[0] << ":"
201  << php.levelT_[1] << " EtaMinBH "
202  << php.etaMinBH_ << " first layer "
203  << php.firstLayer_ << " thickenss "
204  << php.waferThick_;
205 #endif
206  //Load the SpecPars
207  geom->loadSpecParsTrapezoid(fv, php);
208  //Load Geometry parameters
209  geom->loadGeometryHexagon8(fv, php, php.firstLayer_);
210  //Load cell positions
211  geom->loadCellTrapezoid(php);
212  } else {
213  edm::LogError("HGCalGeom") << "Unknown Geometry type " << php.mode_
214  << " for HGCal " << name << ":" << namew
215  << ":" << namec;
216  throw cms::Exception("DDException")
217  << "Unknown Geometry type " << php.mode_ << " for HGCal " << name
218  << ":" << namew << ":" << namec;
219  }
220  } else {
221  edm::LogError("HGCalGeom") << " Attribute " << val
222  << " not found but needed.";
223  throw cms::Exception("DDException") << "Attribute " << val
224  << " not found but needed.";
225  }
226 #ifdef EDM_ML_DEBUG
227  edm::LogVerbatim("HGCalGeom") << "Return from HGCalParametersFromDD::build"
228  << " with flag " << ok;
229 #endif
230  return ok;
231 }
232 
234  if (type == 1) {
235  php.cellCoarseX_.clear();
236  php.cellCoarseY_.clear();
237  } else {
238  php.cellFineX_.clear();
239  php.cellFineY_.clear();
240  }
241  HGCalParameters::wafer_map cellIndex;
242 #ifdef EDM_ML_DEBUG
243  std::vector<int> indtypes;
244 #endif
245  int N = (type == 1) ? php.nCellsCoarse_ : php.nCellsFine_;
246  double R = php.waferSize_/(3*N);
247  double r = 0.5*R*sqrt(3.0);
248  int n2 = N/2;
249  int ipos(0);
250  for (int u=0; u<2*N; ++u) {
251  for (int v=0; v<2*N; ++v) {
252  if (((v-u) < N) && (u-v) <= N) {
253  double yp = (u-0.5*v-n2)*2*r;
254  double xp = (1.5*(v-N)+1.0)*R;
255  int id = v*100 + u;
256 #ifdef EDM_ML_DEBUG
257  indtypes.emplace_back(id);
258 #endif
259  if (type == 1) {
260  php.cellCoarseX_.emplace_back(xp);
261  php.cellCoarseY_.emplace_back(yp);
262  } else {
263  php.cellFineX_.emplace_back(xp);
264  php.cellFineY_.emplace_back(yp);
265  }
266  cellIndex[id] = ipos;
267  ++ipos;
268  }
269  }
270  }
271  if (type == 1) php.cellCoarseIndex_ = cellIndex;
272  else php.cellFineIndex_ = cellIndex;
273 #ifdef EDM_ML_DEBUG
274  if (type == 1) {
275  edm::LogVerbatim("HGCalGeom") << "CellPosition for type " << type
276  << " for " << php.cellCoarseX_.size()
277  << " cells";
278  for (unsigned int k=0; k<php.cellCoarseX_.size(); ++k) {
279  int id = indtypes[k];
280  edm::LogVerbatim("HGCalGeom") << "[" << k << "] ID " << id << ":"
281  << php.cellCoarseIndex_[id] << " X "
282  << php.cellCoarseX_[k] << " Y "
283  << php.cellCoarseY_[k];
284  }
285  } else {
286  edm::LogVerbatim("HGCalGeom") << "CellPosition for type " << type
287  << " for " << php.cellFineX_.size()
288  << " cells";
289  for (unsigned int k=0; k<php.cellCoarseX_.size(); ++k) {
290  int id = indtypes[k];
291  edm::LogVerbatim("HGCalGeom") << "[" << k << "] ID " << id << ":"
292  << php.cellFineIndex_[k] << " X "
293  << php.cellFineX_[k] << " Y "
294  << php.cellFineY_[k];
295  }
296  }
297 #endif
298 }
299 
301  const DDsvalues_type& sv) {
302  DDValue val(s);
303  if (DDfetch(&sv, val)) {
304  const std::vector<double> & fvec = val.doubles();
305  if (fvec.empty()) {
306  throw cms::Exception("HGCalGeom") << "Failed to get " << s << " tag.";
307  }
308  return fvec[0];
309  } else {
310  throw cms::Exception("HGCalGeom") << "Failed to get "<< s << " tag";
311  }
312 }
313 
314 std::vector<double> HGCalParametersFromDD::getDDDArray(const char* s,
315  const DDsvalues_type& sv) {
316  DDValue val(s);
317  if (DDfetch(&sv, val)) {
318  const std::vector<double> & fvec = val.doubles();
319  if (fvec.empty()) {
320  throw cms::Exception("HGCalGeom") << "Failed to get " << s << " tag.";
321  }
322  return fvec;
323  } else {
324  throw cms::Exception("HGCalGeom") << "Failed to get "<< s << " tag";
325  }
326 }
type
Definition: HCALResponse.h:21
const std::vector< double > & doubles() const
a reference to the double-valued values stored in the given instance of DDValue
Definition: DDValue.cc:140
wafer_map cellFineIndex_
T parseString(const std::string &value)
bool build(const DDCompactView *, HGCalParameters &, const std::string &, const std::string &, const std::string &, const std::string &)
void loadSpecParsHexagon(const DDFilteredView &, HGCalParameters &, const DDCompactView *, const std::string &, const std::string &)
std::vector< double > cellFineY_
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:83
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:81
HGCalGeometryMode::GeometryMode mode_
void loadSpecParsHexagon8(const DDFilteredView &, HGCalParameters &)
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< double > cellCoarseX_
void loadCellTrapezoid(HGCalParameters &php)
std::vector< double > cellSize_
void loadCellParsHexagon(const DDCompactView *cpv, HGCalParameters &php)
T sqrt(T t)
Definition: SSEVec.h:18
static double k_ScaleFromDDD
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
std::vector< std::pair< unsigned int, DDValue > > DDsvalues_type
std::maps an index to a DDValue. The index corresponds to the index assigned to the name of the std::...
Definition: DDsvalues.h:20
Definition: value.py:1
void loadSpecParsTrapezoid(const DDFilteredView &, HGCalParameters &)
void loadGeometryHexagon8(const DDFilteredView &, HGCalParameters &, int)
void loadWaferHexagon(HGCalParameters &php)
int k[5][pyjets_maxn]
#define N
Definition: blowfish.cc:9
std::unordered_map< int32_t, int32_t > wafer_map
static double k_ScaleToDDD
double getDDDValue(const char *s, const DDsvalues_type &sv)
wafer_map cellCoarseIndex_
DDsvalues_type mergedSpecifics() const
std::vector< double > cellFineX_
bool firstChild()
set the current node to the first child ...
std::vector< int > levelT_
std::vector< double > cellCoarseY_
std::vector< double > getDDDArray(const char *s, const DDsvalues_type &sv)
void loadWaferHexagon8(HGCalParameters &php)
void loadGeometryHexagon(const DDFilteredView &, HGCalParameters &, const std::string &, const DDCompactView *, const std::string &, const std::string &, HGCalGeometryMode::WaferMode)
void getCellPosition(HGCalParameters &php, int type)