CMS 3D CMS Logo

DDHGCalTBModule.cc
Go to the documentation of this file.
1 #include <algorithm>
2 #include <cmath>
3 
13 
14 //#define EDM_ML_DEBUG
15 using namespace geant_units::operators;
16 
18 #ifdef EDM_ML_DEBUG
19  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule info: Creating an 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 #ifdef EDM_ML_DEBUG
33  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule: " << wafer_.size()
34  << " wafers";
35  unsigned int i(0);
36  for (auto wafer : wafer_) {
37  edm::LogVerbatim("HGCalGeom") << "Wafer[" << i << "] " << wafer;
38  ++i;
39  }
40  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule: " << covers_.size()
41  << " covers";
42  i = 0;
43  for (auto cover : covers_) {
44  edm::LogVerbatim("HGCalGeom") << "Cover[" << i << "] " << cover;
45  ++i;
46  }
47 #endif
48  materials_ = vsArgs["MaterialNames"];
49  names_ = vsArgs["VolumeNames"];
50  thick_ = vArgs["Thickness"];
51  for (unsigned int i = 0; i < materials_.size(); ++i) {
52  copyNumber_.emplace_back(1);
53  }
54 #ifdef EDM_ML_DEBUG
55  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule: " << materials_.size()
56  << " types of volumes";
57  for (unsigned int i = 0; i < names_.size(); ++i)
58  edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << names_[i]
59  << " of thickness " << thick_[i]
60  << " filled with " << materials_[i]
61  << " first copy number " << copyNumber_[i];
62 #endif
63  layers_ = dbl_to_int(vArgs["Layers"]);
64  layerThick_ = vArgs["LayerThick"];
65 #ifdef EDM_ML_DEBUG
66  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule: " << layers_.size()
67  << " blocks";
68  for (unsigned int i = 0; i < layers_.size(); ++i)
69  edm::LogVerbatim("HGCalGeom") << "Block [" << i << "] of thickness "
70  << layerThick_[i] << " with " << layers_[i]
71  << " layers";
72 #endif
73  layerType_ = dbl_to_int(vArgs["LayerType"]);
74  layerSense_ = dbl_to_int(vArgs["LayerSense"]);
75 #ifdef EDM_ML_DEBUG
76  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule: " << layerType_.size()
77  << " layers";
78  for (unsigned int i = 0; i < layerType_.size(); ++i)
79  edm::LogVerbatim("HGCalGeom") << "Layer [" << i << "] with material type "
80  << layerType_[i] << " sensitive class "
81  << layerSense_[i];
82 #endif
83  zMinBlock_ = nArgs["zMinBlock"];
84  rMaxFine_ = nArgs["rMaxFine"];
85  waferW_ = nArgs["waferW"];
86  waferGap_ = nArgs["waferGap"];
87  absorbW_ = nArgs["absorberW"];
88  absorbH_ = nArgs["absorberH"];
89  sectors_ = (int)(nArgs["Sectors"]);
90 #ifdef EDM_ML_DEBUG
91  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule: zStart " << zMinBlock_
92  << " rFineCoarse " << rMaxFine_ << " wafer width "
93  << waferW_ << " gap among wafers "
94  << waferGap_ << " absorber width " << absorbW_
95  << " absorber height " << absorbH_ << " sectors "
96  << sectors_;
97 #endif
98  slopeB_ = vArgs["SlopeBottom"];
99  slopeT_ = vArgs["SlopeTop"];
100  zFront_ = vArgs["ZFront"];
101  rMaxFront_ = vArgs["RMaxFront"];
102 #ifdef EDM_ML_DEBUG
103  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule: Bottom slopes " << slopeB_[0]
104  << ":" << slopeB_[1] << " and " << slopeT_.size()
105  << " slopes for top";
106  for (unsigned int i = 0; i < slopeT_.size(); ++i)
107  edm::LogVerbatim("HGCalGeom") << "Block [" << i << "] Zmin " << zFront_[i]
108  << " Rmax " << rMaxFront_[i] << " Slope "
109  << slopeT_[i];
110 #endif
111  idNameSpace_ = DDCurrentNamespace::ns();
112 #ifdef EDM_ML_DEBUG
113  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule: NameSpace " << idNameSpace_;
114 #endif
115 }
116 
118 // DDHGCalTBModule methods...
120 
122 #ifdef EDM_ML_DEBUG
123  edm::LogVerbatim("HGCalGeom") << "==>> Constructing DDHGCalTBModule...";
124 #endif
125  copies_.clear();
126  constructLayers(parent(), cpv);
127 #ifdef EDM_ML_DEBUG
128  edm::LogVerbatim("HGCalGeom") << copies_.size() << " different wafer copy numbers";
129 #endif
130  copies_.clear();
131 #ifdef EDM_ML_DEBUG
132  edm::LogVerbatim("HGCalGeom") << "<<== End of DDHGCalTBModule construction ...";
133 #endif
134 }
135 
137  DDCompactView& cpv) {
138 #ifdef EDM_ML_DEBUG
139  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule test: \t\tInside Layers";
140 #endif
141  double zi(zMinBlock_);
142  int laymin(0);
143  for (unsigned int i = 0; i < layers_.size(); i++) {
144  double zo = zi + layerThick_[i];
145  double routF = rMax(zi);
146  int laymax = laymin + layers_[i];
147  double zz = zi;
148  double thickTot(0);
149  for (int ly = laymin; ly < laymax; ++ly) {
150  int ii = layerType_[ly];
151  int copy = copyNumber_[ii];
152  double rinB =
153  (layerSense_[ly] == 0) ? (zo * slopeB_[0]) : (zo * slopeB_[1]);
154  zz += (0.5 * thick_[ii]);
155  thickTot += thick_[ii];
156 
157  std::string name = "HGCal" + names_[ii] + std::to_string(copy);
158 #ifdef EDM_ML_DEBUG
159  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule: Layer " << ly << ":"
160  << ii << " Front " << zi << ", " << routF
161  << " Back " << zo << ", " << rinB
162  << " superlayer thickness " << layerThick_[i];
163 #endif
164  DDName matName(DDSplit(materials_[ii]).first,
165  DDSplit(materials_[ii]).second);
166  DDMaterial matter(matName);
167  DDLogicalPart glog;
168  if (layerSense_[ly] == 0) {
170  DDName(name, idNameSpace_), absorbW_, absorbH_, 0.5 * thick_[ii]);
171  glog = DDLogicalPart(solid.ddname(), matter, solid);
172 #ifdef EDM_ML_DEBUG
173  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule test: " << solid.name()
174  << " box of dimension " << absorbW_ << ":"
175  << absorbH_ << ":" << 0.5 * thick_[ii];
176 #endif
177  } else {
178  DDSolid solid =
179  DDSolidFactory::tubs(DDName(name, idNameSpace_), 0.5 * thick_[ii],
180  rinB, routF, 0.0, 2*geant_units::piRadians);
181  glog = DDLogicalPart(solid.ddname(), matter, solid);
182 #ifdef EDM_ML_DEBUG
183  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule: " << solid.name()
184  << " Tubs made of " << matName
185  << " of dimensions " << rinB << ", "
186  << routF << ", " << 0.5 * thick_[ii]
187  << ", 0.0, 360.0";
188 #endif
189  positionSensitive(glog, layerSense_[ly], rinB, routF, cpv);
190  }
191  DDTranslation r1(0, 0, zz);
192  DDRotation rot;
193  cpv.position(glog, module, copy, r1, rot);
194  ++copyNumber_[ii];
195 #ifdef EDM_ML_DEBUG
196  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule test: " << glog.name()
197  << " number " << copy << " positioned in "
198  << module.name() << " at " << r1
199  << " with " << rot;
200 #endif
201  zz += (0.5 * thick_[ii]);
202  } // End of loop over layers in a block
203  zi = zo;
204  laymin = laymax;
205  if (fabs(thickTot - layerThick_[i]) < 0.00001) {
206  } else if (thickTot > layerThick_[i]) {
207  edm::LogError("HGCalGeom")
208  << "Thickness of the partition " << layerThick_[i]
209  << " is smaller than thickness " << thickTot
210  << " of all its components **** ERROR ****\n";
211  } else if (thickTot < layerThick_[i]) {
212  edm::LogWarning("HGCalGeom")
213  << "Thickness of the partition " << layerThick_[i]
214  << " does not match with " << thickTot << " of the components\n";
215  }
216  } // End of loop over blocks
217 }
218 
219 double DDHGCalTBModule::rMax(double z) {
220  double r(0);
221 #ifdef EDM_ML_DEBUG
222  unsigned int ik(0);
223 #endif
224  for (unsigned int k = 0; k < slopeT_.size(); ++k) {
225  if (z < zFront_[k]) break;
226  r = rMaxFront_[k] + (z - zFront_[k]) * slopeT_[k];
227 #ifdef EDM_ML_DEBUG
228  ik = k;
229 #endif
230  }
231 #ifdef EDM_ML_DEBUG
232  edm::LogVerbatim("HGCalGeom") << "rMax : " << z << ":" << ik << ":" << r;
233 #endif
234  return r;
235 }
236 
238  double rin, double rout,
239  DDCompactView& cpv) {
240  double ww = (waferW_ + waferGap_);
241  double dx = 0.5 * ww;
242  double dy = 3.0 * dx * tan(30._deg);
243  double rr = 2.0 * dx * tan(30._deg);
244  int ncol = (int)(2.0 * rout / ww) + 1;
245  int nrow = (int)(rout / (ww * tan(30._deg))) + 1;
246  int incm(0), inrm(0), kount(0);
247  double xc[6], yc[6];
248 #ifdef EDM_ML_DEBUG
249  edm::LogVerbatim("HGCalGeom") << glog.ddname() << " rout " << rout << " Row "
250  << nrow << " Column " << ncol;
251 #endif
252  for (int nr = -nrow; nr <= nrow; ++nr) {
253  int inr = (nr >= 0) ? nr : -nr;
254  for (int nc = -ncol; nc <= ncol; ++nc) {
255  int inc = (nc >= 0) ? nc : -nc;
256  if (inr % 2 == inc % 2) {
257  double xpos = nc * dx;
258  double ypos = nr * dy;
259  xc[0] = xpos + dx;
260  yc[0] = ypos - 0.5 * rr;
261  xc[1] = xpos + dx;
262  yc[1] = ypos + 0.5 * rr;
263  xc[2] = xpos;
264  yc[2] = ypos + rr;
265  xc[3] = xpos - dx;
266  yc[3] = ypos + 0.5 * rr;
267  xc[4] = xpos + dx;
268  yc[4] = ypos - 0.5 * rr;
269  xc[5] = xpos;
270  yc[5] = ypos - rr;
271  bool cornerAll(true);
272  for (int k = 0; k < 6; ++k) {
273  double rpos = std::sqrt(xc[k] * xc[k] + yc[k] * yc[k]);
274  if (rpos < rin || rpos > rout) cornerAll = false;
275  }
276  if (cornerAll) {
277  double rpos = std::sqrt(xpos * xpos + ypos * ypos);
278  DDTranslation tran(xpos, ypos, 0.0);
280  int copy = inr * 100 + inc;
281  if (nc < 0) copy += 10000;
282  if (nr < 0) copy += 100000;
283  DDName name;
284  if (type == 1) {
285  name = (rpos < rMaxFine_) ? DDName(DDSplit(wafer_[0]).first,
286  DDSplit(wafer_[0]).second)
287  : DDName(DDSplit(wafer_[1]).first,
288  DDSplit(wafer_[1]).second);
289  } else {
290  name = DDName(DDSplit(covers_[type - 2]).first,
291  DDSplit(covers_[type - 2]).second);
292  }
293  cpv.position(name, glog.ddname(), copy, tran, rotation);
294  if (inc > incm) incm = inc;
295  if (inr > inrm) inrm = inr;
296  kount++;
297  if (copies_.count(copy) == 0 && type == 1) copies_.insert(copy);
298 #ifdef EDM_ML_DEBUG
299  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule: " << name
300  << " number " << copy << " positioned in "
301  << glog.ddname() << " at " << tran
302  << " with " << rotation;
303 #endif
304  }
305  }
306  }
307  }
308 #ifdef EDM_ML_DEBUG
309  edm::LogVerbatim("HGCalGeom") << "DDHGCalTBModule: # of columns " << incm
310  << " # of rows " << inrm << " and " << kount
311  << " wafers for " << glog.ddname();
312 #endif
313 }
type
Definition: HCALResponse.h:21
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override
const N & name() const
Definition: DDBase.h:74
def copy(args, dbName)
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:43
~DDHGCalTBModule() override
void positionSensitive(DDLogicalPart &glog, int type, double rin, double rout, DDCompactView &cpv)
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:15
static std::string & ns()
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:80
constexpr long double piRadians(M_PI)
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)
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
T sqrt(T t)
Definition: SSEVec.h:18
Tan< T >::type tan(const T &t)
Definition: Tan.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
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 constructLayers(const DDLogicalPart &, DDCompactView &cpv)
void execute(DDCompactView &cpv) override
void position(const DDLogicalPart &self, const DDLogicalPart &parent, const std::string &copyno, const DDTranslation &trans, const DDRotation &rot, const DDDivision *div=0)
std::pair< std::string, std::string > DDSplit(const std::string &n)
split into (name,namespace), separator = &#39;:&#39;
Definition: DDSplit.cc:3
Definition: vlib.h:208
double rMax(double z)
const N & ddname() const
Definition: DDBase.h:76