CMS 3D CMS Logo

DDHGCalTBModuleX.cc
Go to the documentation of this file.
1 #include <algorithm>
2 #include <cmath>
3 
11 
12 //#define EDM_ML_DEBUG
13 using namespace geant_units::operators;
14 
16  : factor_(0.5 * sqrt(2.0)), tan30deg_(tan(30._deg)) {
17 #ifdef EDM_ML_DEBUG
18  edm::LogVerbatim("HGCalGeom")
19  << "DDHGCalTBModuleX info: Creating instance";
20 #endif
21 }
22 
24 
26  const DDVectorArguments& vArgs,
27  const DDMapArguments&,
28  const DDStringArguments& sArgs,
29  const DDStringVectorArguments& vsArgs) {
30  wafer_ = vsArgs["WaferName"];
31  covers_ = vsArgs["CoverName"];
32  genMat_ = sArgs["GeneralMaterial"];
33 #ifdef EDM_ML_DEBUG
34  edm::LogVerbatim("HGCalGeom")
35  << "DDHGCalTBModuleX: Material " << genMat_ << " with " << wafer_.size()
36  << " wafers";
37  unsigned int i(0);
38  for (auto wafer : wafer_) {
39  edm::LogVerbatim("HGCalGeom") << "Wafer[" << i << "] " << wafer;
40  ++i;
41  }
42  edm::LogVerbatim("HGCalGeom")
43  << "DDHGCalTBModuleX: " << covers_.size() << " covers";
44  i = 0;
45  for (auto cover : covers_) {
46  edm::LogVerbatim("HGCalGeom") << "Cover[" << i << "] " << cover;
47  ++i;
48  }
49 #endif
50  materials_ = vsArgs["MaterialNames"];
51  names_ = vsArgs["VolumeNames"];
52  layerThick_ = vArgs["Thickness"];
53  for (unsigned int k = 0; k < layerThick_.size(); ++k)
54  copyNumber_.emplace_back(1);
55 #ifdef EDM_ML_DEBUG
56  edm::LogVerbatim("HGCalGeom")
57  << "DDHGCalTBModuleX: " << materials_.size() << " types of volumes";
58  for (unsigned int i = 0; i < names_.size(); ++i)
59  edm::LogVerbatim("HGCalGeom")
60  << "Volume [" << i << "] " << names_[i] << " of thickness "
61  << layerThick_[i] << " filled with " << materials_[i]
62  << " first copy number " << copyNumber_[i];
63 #endif
64  inOut_ = nArgs["InOut"];
65  blockThick_ = vArgs["BlockThick"];
66  layerFrontIn_ = dbl_to_int(vArgs["LayerFrontIn"]);
67  layerBackIn_ = dbl_to_int(vArgs["LayerBackIn"]);
68  if (inOut_ > 1) {
69  layerFrontOut_ = dbl_to_int(vArgs["LayerFrontOut"]);
70  layerBackOut_ = dbl_to_int(vArgs["LayerBackOut"]);
71  }
72 #ifdef EDM_ML_DEBUG
73  edm::LogVerbatim("HGCalGeom")
74  << "DDHGCalTBModuleX: " << blockThick_.size() << " blocks with in/out "
75  << inOut_;
76  for (unsigned int i = 0; i < blockThick_.size(); ++i) {
77  if (inOut_ > 1)
78  edm::LogVerbatim("HGCalGeom")
79  << "Block [" << i << "] of thickness " << blockThick_[i]
80  << " with inner layers " << layerFrontIn_[i] << ":"
81  << layerBackIn_[i] << " and outer layers " << layerFrontOut_[i]
82  << ":" << layerBackOut_[i];
83  else
84  edm::LogVerbatim("HGCalGeom")
85  << "Block [" << i << "] of thickness " << blockThick_[i]
86  << " with inner layers " << layerFrontIn_[i] << ":" << layerBackIn_[i];
87  }
88 #endif
89  layerType_ = dbl_to_int(vArgs["LayerType"]);
90  layerSense_ = dbl_to_int(vArgs["LayerSense"]);
91  maxModule_ = dbl_to_int(vArgs["MaxModule"]);
92 #ifdef EDM_ML_DEBUG
93  edm::LogVerbatim("HGCalGeom")
94  << "DDHGCalTBModuleX: " << layerType_.size() << " layers";
95  for (unsigned int i = 0; i < layerType_.size(); ++i)
96  edm::LogVerbatim("HGCalGeom")
97  << "Layer [" << i << "] with material type " << layerType_[i]
98  << " sensitive class " << layerSense_[i] << " and " << maxModule_[i]
99  << " maximum row/columns";
100 #endif
101  zMinBlock_ = nArgs["zMinBlock"];
102  rMaxFine_ = nArgs["rMaxFine"];
103  waferW_ = nArgs["waferW"];
104  waferGap_ = nArgs["waferGap"];
105  absorbW_ = nArgs["absorberW"];
106  absorbH_ = nArgs["absorberH"];
107  rMax_ = nArgs["rMax"];
108  rMaxB_ = nArgs["rMaxB"];
109 #ifdef EDM_ML_DEBUG
110  edm::LogVerbatim("HGCalGeom")
111  << "DDHGCalTBModuleX: zStart " << zMinBlock_ << " rFineCoarse "
112  << rMaxFine_ << " wafer width " << waferW_ << " gap among wafers "
113  << waferGap_ << " absorber width " << absorbW_ << " absorber height "
114  << absorbH_ << " rMax " << rMax_ << ":" << rMaxB_;
115 #endif
117 #ifdef EDM_ML_DEBUG
118  edm::LogVerbatim("HGCalGeom")
119  << "DDHGCalTBModuleX: NameSpace " << idNameSpace_ << " Parent Name "
120  << parent().name().name();
121 #endif
122 }
123 
125 // DDHGCalTBModuleX methods...
127 
129 #ifdef EDM_ML_DEBUG
130  edm::LogVerbatim("HGCalGeom") << "==>> Constructing DDHGCalTBModuleX...";
131 #endif
132  copies_.clear();
133  constructBlocks(parent(), cpv);
134 #ifdef EDM_ML_DEBUG
135  edm::LogVerbatim("HGCalGeom")
136  << copies_.size() << " different wafer copy numbers";
137 #endif
138  copies_.clear();
139 #ifdef EDM_ML_DEBUG
140  edm::LogVerbatim("HGCalGeom") << "<<== End of DDHGCalTBModuleX construction";
141 #endif
142 }
143 
145  DDCompactView& cpv) {
146 #ifdef EDM_ML_DEBUG
147  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModuleX: Inside constructBlock";
148 #endif
149  double zi(zMinBlock_);
150  for (unsigned int i = 0; i < blockThick_.size(); i++) {
151  double zo = zi + blockThick_[i];
152  std::string name = parent.ddname().name() + "Block" + std::to_string(i);
153 #ifdef EDM_ML_DEBUG
154  edm::LogVerbatim("HGCalGeom")
155  << "DDHGCalTBModuleX: Block " << i << ":" << name << " z " << zi << ":"
156  << zo << " R " << rMaxB_ << " T " << blockThick_[i];
157 #endif
159  DDMaterial matter(matName);
160  DDSolid solid =
161  DDSolidFactory::tubs(DDName(name, idNameSpace_), 0.5 * blockThick_[i],
162  0, rMaxB_, 0.0, 2._pi);
163  DDLogicalPart glog = DDLogicalPart(solid.ddname(), matter, solid);
164  double zz = zi + 0.5 * blockThick_[i];
165  DDTranslation r1(0, 0, zz);
166  DDRotation rot;
167  cpv.position(glog, parent, i, r1, rot);
168 #ifdef EDM_ML_DEBUG
169  edm::LogVerbatim("HGCalGeom")
170  << "DDHGCalTBModuleX: " << glog.name() << " number " << i
171  << " positioned in " << parent.name() << " at " << r1 << " with "
172  << rot;
173 #endif
174  constructLayers(i, layerFrontIn_[i], layerBackIn_[i], -0.5*blockThick_[i],
175  blockThick_[i], false, glog, cpv);
176  if (inOut_ > 1)
178  -0.5 * blockThick_[i], blockThick_[i], true, glog, cpv);
179  zi = zo;
180  }
181 #ifdef EDM_ML_DEBUG
182  edm::LogVerbatim("HGCalGeom")
183  << "DDHGCalTBModuleX: All blocks are " << "placed in " << zMinBlock_
184  << ":" << zi;
185 #endif
186 }
187 
188 void DDHGCalTBModuleX::constructLayers(int block, int firstLayer,
189  int lastLayer, double zFront,
190  double totalWidth, bool ignoreCenter,
191  const DDLogicalPart& module,
192  DDCompactView& cpv) {
193 #ifdef EDM_ML_DEBUG
194  edm::LogVerbatim("HGCalGeom")
195  << "DDHGCalTBModuleX: \t\tInside Block " << block << " Layers "
196  << firstLayer << ":" << lastLayer << " zFront " << zFront
197  << " thickness " << totalWidth << " ignore Center " << ignoreCenter;
198 #endif
199  double zi(zFront), thickTot(0);
200  for (int ly = firstLayer; ly <= lastLayer; ++ly) {
201  int ii = layerType_[ly];
202  int copy = copyNumber_[ii];
203  double zz = zi + (0.5 * layerThick_[ii]);
204  double zo = zi + layerThick_[ii];
205  thickTot += layerThick_[ii];
206 
207  std::string name = "HGCal" + names_[ii] + std::to_string(copy);
208 #ifdef EDM_ML_DEBUG
209  edm::LogVerbatim("HGCalGeom")
210  << "DDHGCalTBModuleX: " << name << " Layer " << ly << ":" << ii
211  << " Z " << zi << ":" << zo << " Thick " << layerThick_[ii]
212  << " Sense " << layerSense_[ly];
213 #endif
214  DDName matName(DDSplit(materials_[ii]).first,
215  DDSplit(materials_[ii]).second);
216  DDMaterial matter(matName);
217  DDLogicalPart glog;
218  if (layerSense_[ly] == 0) {
220  absorbH_, 0.5*layerThick_[ii]);
221  glog = DDLogicalPart(solid.ddname(), matter, solid);
222 #ifdef EDM_ML_DEBUG
223  edm::LogVerbatim("HGCalGeom")
224  << "DDHGCalTBModuleX: " << solid.name() << " box of dimension "
225  << absorbW_ << ":" << absorbH_ << ":" << 0.5*layerThick_[ii];
226 #endif
227  DDTranslation r1(0, 0, zz);
228  DDRotation rot;
229  cpv.position(glog, module, copy, r1, rot);
230 #ifdef EDM_ML_DEBUG
231  edm::LogVerbatim("HGCalGeom")
232  << "DDHGCalTBModuleX: " << glog.name() << " number " << copy
233  << " positioned in " << module.name() << " at " << r1 << " with "
234  << rot;
235 #endif
236  } else if (layerSense_[ly] > 0) {
237  positionSensitive(zz, copy, layerSense_[ly], rMax_, maxModule_[ly],
238  ignoreCenter, name, matter, module, cpv);
239  }
240  ++copyNumber_[ii];
241  zi = zo;
242  } // End of loop over layers in a block
243 
244  if (fabs(thickTot - totalWidth) < tolerance_) {
245  } else if (thickTot > totalWidth) {
246  edm::LogError("HGCalGeom")
247  << "Thickness of the partition " << totalWidth << " is smaller than "
248  << thickTot << ": total thickness of all its components in "
249  << module.name() << " Layers " << firstLayer << ":" << lastLayer << ":"
250  << ignoreCenter << "**** ERROR ****";
251  } else if (thickTot < totalWidth) {
252  edm::LogWarning("HGCalGeom")
253  << "Thickness of the partition " << totalWidth << " does not match with "
254  << thickTot << " of the components in " << module.name() << " Layers "
255  << firstLayer << ":" << lastLayer << ":" << ignoreCenter;
256  }
257 }
258 
260  double zpos, int copyIn, int type, double rout, int ncrMax,
261  bool ignoreCenter, const std::string& nameIn, const DDMaterial& matter,
262  const DDLogicalPart& glog, DDCompactView& cpv) {
263  double ww = (waferW_ + waferGap_);
264  double dx = 0.5 * ww;
265  double dy = 3.0 * dx * tan30deg_;
266  double rr = 2.0 * dx * tan30deg_;
267  int ncol = (int)(2.0 * rout / ww) + 1;
268  int nrow = (int)(rout / (ww * tan30deg_)) + 1;
269 #ifdef EDM_ML_DEBUG
270  int incm(0), inrm(0);
271  edm::LogVerbatim("HGCalGeom")
272  << glog.ddname() << " Copy " << copyIn << " Type " << type << " rout "
273  << rout << " Row " << nrow << " column " << ncol << " ncrMax " << ncrMax
274  << " Z " << zpos << " Center " << ignoreCenter << " name " << nameIn
275  << " matter " << matter.name();
276  int kount(0);
277 #endif
278  if (ncrMax >= 0) {
279  nrow = std::min(nrow, ncrMax);
280  ncol = std::min(ncol, ncrMax);
281  }
282  for (int nr = -nrow; nr <= nrow; ++nr) {
283  int inr = std::abs(nr);
284  for (int nc = -ncol; nc <= ncol; ++nc) {
285  int inc = std::abs(nc);
286  if ((inr % 2 == inc % 2) && (!ignoreCenter || nc != 0 || nr != 0)) {
287  double xpos = nc * dx;
288  double ypos = nr * dy;
289  double xc[6], yc[6];
290  xc[0] = xpos + dx;
291  yc[0] = ypos - 0.5 * rr;
292  xc[1] = xpos + dx;
293  yc[1] = ypos + 0.5 * rr;
294  xc[2] = xpos;
295  yc[2] = ypos + rr;
296  xc[3] = xpos - dx;
297  yc[3] = ypos + 0.5 * rr;
298  xc[4] = xpos + dx;
299  yc[4] = ypos - 0.5 * rr;
300  xc[5] = xpos;
301  yc[5] = ypos - rr;
302  bool cornerAll(true);
303  for (int k = 0; k < 6; ++k) {
304  double rpos = std::sqrt(xc[k] * xc[k] + yc[k] * yc[k]);
305  if (rpos > rout) cornerAll = false;
306  }
307  if (cornerAll) {
308  double rpos = std::sqrt(xpos * xpos + ypos * ypos);
309  DDTranslation tran(xpos, ypos, zpos);
311  int copy = inr * 100 + inc;
312  if (nc < 0) copy += 10000;
313  if (nr < 0) copy += 100000;
314  DDName name, nameX;
315  if (type == 1) {
316  nameX =
318  std::string name0 = nameIn + "M" + std::to_string(copy);
319  DDLogicalPart glog1 =
320  DDLogicalPart(DDName(name0, idNameSpace_), matter, nameX);
321  cpv.position(glog1.ddname(), glog.ddname(), copyIn, tran, rotation);
322 #ifdef EDM_ML_DEBUG
323  edm::LogVerbatim("HGCalGeom")
324  << "DDHGCalTBModuleX: " << glog1.ddname() << " number "
325  << copyIn << " positioned in " << glog.ddname() << " at "
326  << tran << " with " << rotation;
327 #endif
328  name = (rpos < rMaxFine_) ? DDName(DDSplit(wafer_[0]).first,
329  DDSplit(wafer_[0]).second)
330  : DDName(DDSplit(wafer_[1]).first,
331  DDSplit(wafer_[1]).second);
332  DDTranslation tran1;
333  cpv.position(name, glog1.ddname(), copy, tran1, rotation);
334 #ifdef EDM_ML_DEBUG
335  edm::LogVerbatim("HGCalGeom")
336  << "DDHGCalTBModuleX: " << name << " number " << copy
337  << " positioned in " << glog1.ddname() << " at " << tran1
338  << " with " << rotation;
339 #endif
340  if (copies_.count(copy) == 0 && type == 1) copies_.insert(copy);
341  } else {
342  name = DDName(DDSplit(covers_[type - 1]).first,
343  DDSplit(covers_[type - 1]).second);
344  copy += copyIn * 1000000;
345  cpv.position(name, glog.ddname(), copy, tran, rotation);
346 #ifdef EDM_ML_DEBUG
347  edm::LogVerbatim("HGCalGeom")
348  << "DDHGCalTBModuleX: " << name << " number " << copy
349  << " positioned in " << glog.ddname() << " at " << tran
350  << " with " << rotation;
351 #endif
352  }
353 #ifdef EDM_ML_DEBUG
354  if (inc > incm) incm = inc;
355  if (inr > inrm) inrm = inr;
356  kount++;
357 #endif
358  }
359  }
360  }
361  }
362 #ifdef EDM_ML_DEBUG
363  edm::LogVerbatim("HGCalGeom")
364  << "DDHGCalTBModuleX: # of columns " << incm << " # of rows " << inrm
365  << " and " << kount << " wafers for " << glog.ddname();
366 #endif
367 }
type
Definition: HCALResponse.h:21
const N & name() const
Definition: DDBase.h:74
std::vector< std::string > wafer_
def copy(args, dbName)
std::vector< int > layerFrontOut_
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:43
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override
std::vector< std::string > names_
std::vector< std::string > materials_
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:15
std::vector< int > layerFrontIn_
static std::string & ns()
std::unordered_set< int > copies_
std::vector< int > layerBackIn_
void constructLayers(int block, int layerFront, int layerBack, double zFront, double thick, bool ignore, const DDLogicalPart &, DDCompactView &)
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:80
A DDSolid represents the shape of a part.
Definition: DDSolid.h:39
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:68
U second(std::pair< T, U > const &p)
void constructBlocks(const DDLogicalPart &, DDCompactView &cpv)
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
const double tan30deg_
std::vector< double > blockThick_
std::vector< int > layerType_
std::vector< std::string > covers_
T sqrt(T t)
Definition: SSEVec.h:18
std::vector< int > layerSense_
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:93
static DDSolid tubs(const DDName &name, double zhalf, double rIn, double rOut, double startPhi, double deltaPhi)
Definition: DDSolid.cc:865
T min(T a, T b)
Definition: MathUtil.h:58
std::vector< int > copyNumber_
static DDSolid box(const DDName &name, double xHalf, double yHalf, double zHalf)
Creates a box with side length 2*xHalf, 2*yHalf, 2*zHalf.
Definition: DDSolid.cc:704
ii
Definition: cuy.py:590
int k[5][pyjets_maxn]
void execute(DDCompactView &cpv) override
static double tolerance_
std::vector< int > layerBackOut_
~DDHGCalTBModuleX() override
void positionSensitive(double zpos, int copyIn, int type, double rmax, int ncrMax, bool ignoreCenter, const std::string &, const DDMaterial &, const DDLogicalPart &, DDCompactView &cpv)
void position(const DDLogicalPart &self, const DDLogicalPart &parent, const std::string &copyno, const DDTranslation &trans, const DDRotation &rot, const DDDivision *div=0)
std::string idNameSpace_
std::vector< int > maxModule_
std::pair< std::string, std::string > DDSplit(const std::string &n)
split into (name,namespace), separator = &#39;:&#39;
Definition: DDSplit.cc:3
std::string genMat_
Definition: vlib.h:208
const std::string & name() const
Returns the name.
Definition: DDName.cc:53
std::vector< double > layerThick_
const N & ddname() const
Definition: DDBase.h:76