CMS 3D CMS Logo

DDHGCalModule.cc
Go to the documentation of this file.
1 // File: DDHGCalModule.cc
3 // Description: Geometry factory class for HGCal (EE and HESil)
5 
6 #include <algorithm>
7 #include <cmath>
8 
20 
21 //#define EDM_ML_DEBUG
22 using namespace geant_units::operators;
23 
25 #ifdef EDM_ML_DEBUG
26  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: Creating an instance";
27 #endif
28 }
29 
31 
33  const DDVectorArguments& vArgs,
34  const DDMapArguments&,
35  const DDStringArguments& sArgs,
36  const DDStringVectorArguments& vsArgs) {
37  wafer = vsArgs["WaferName"];
38 #ifdef EDM_ML_DEBUG
39  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: " << wafer.size() << " wafers";
40  for (unsigned int i = 0; i < wafer.size(); ++i)
41  edm::LogVerbatim("HGCalGeom") << "Wafer[" << i << "] " << wafer[i];
42 #endif
43  materials = vsArgs["MaterialNames"];
44  names = vsArgs["VolumeNames"];
45  thick = vArgs["Thickness"];
46  for (unsigned int i = 0; i < materials.size(); ++i) {
47  copyNumber.emplace_back(1);
48  }
49 #ifdef EDM_ML_DEBUG
50  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: " << materials.size()
51  << " types of volumes";
52  for (unsigned int i = 0; i < names.size(); ++i)
53  edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << names[i]
54  << " of thickness " << thick[i]
55  << " filled with " << materials[i]
56  << " first copy number " << copyNumber[i];
57 #endif
58  layers = dbl_to_int(vArgs["Layers"]);
59  layerThick = vArgs["LayerThick"];
60 #ifdef EDM_ML_DEBUG
61  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: " << layers.size() <<" blocks";
62  for (unsigned int i = 0; i < layers.size(); ++i)
63  edm::LogVerbatim("HGCalGeom") << "Block [" << i << "] of thickness "
64  << layerThick[i] << " with " << layers[i]
65  << " layers";
66 #endif
67  layerType = dbl_to_int(vArgs["LayerType"]);
68  layerSense = dbl_to_int(vArgs["LayerSense"]);
69 #ifdef EDM_ML_DEBUG
70  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: " << layerType.size()
71  << " layers";
72  for (unsigned int i = 0; i < layerType.size(); ++i)
73  edm::LogVerbatim("HGCalGeom") << "Layer [" << i << "] with material type "
74  << layerType[i] << " sensitive class "
75  << layerSense[i];
76 #endif
77  zMinBlock = nArgs["zMinBlock"];
78  rMaxFine = nArgs["rMaxFine"];
79  waferW = nArgs["waferW"];
80  sectors = (int)(nArgs["Sectors"]);
81 #ifdef EDM_ML_DEBUG
82  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: zStart " << zMinBlock
83  << " rFineCoarse " << rMaxFine << " wafer width "
84  << waferW << " sectors " << sectors;
85 #endif
86  slopeB = vArgs["SlopeBottom"];
87  slopeT = vArgs["SlopeTop"];
88  zFront = vArgs["ZFront"];
89  rMaxFront = vArgs["RMaxFront"];
90 #ifdef EDM_ML_DEBUG
91  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: Bottom slopes " << slopeB[0]
92  << ":" << slopeB[1] << " and " << slopeT.size()
93  << " slopes for top";
94  for (unsigned int i = 0; i < slopeT.size(); ++i)
95  edm::LogVerbatim("HGCalGeom") << "Block [" << i << "] Zmin " << zFront[i]
96  << " Rmax " << rMaxFront[i] << " Slope "
97  << slopeT[i];
98 #endif
99  idNameSpace = DDCurrentNamespace::ns();
100 #ifdef EDM_ML_DEBUG
101  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: NameSpace " << idNameSpace;
102 #endif
103 }
104 
106 // DDHGCalModule methods...
108 
110 #ifdef EDM_ML_DEBUG
111  edm::LogVerbatim("HGCalGeom") << "==>> Constructing DDHGCalModule...";
112 #endif
113  copies.clear();
114  constructLayers(parent(), cpv);
115 #ifdef EDM_ML_DEBUG
116  edm::LogVerbatim("HGCalGeom") << copies.size() << " different wafer copy numbers";
117  int k(0);
118  for (std::unordered_set<int>::const_iterator itr = copies.begin();
119  itr != copies.end(); ++itr, ++k)
120  edm::LogVerbatim("HGCalGeom") << "Copy[" << k << "] : " << (*itr);
121 #endif
122  copies.clear();
123 #ifdef EDM_ML_DEBUG
124  edm::LogVerbatim("HGCalGeom") << "<<== End of DDHGCalModule construction ...";
125 #endif
126 }
127 
129  DDCompactView& cpv) {
130 #ifdef EDM_ML_DEBUG
131  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: \t\tInside Layers";
132 #endif
133  double zi(zMinBlock);
134  int laymin(0);
135  const double tol(0.01);
136  for (unsigned int i = 0; i < layers.size(); i++) {
137  double zo = zi + layerThick[i];
138  double routF = rMax(zi);
139  int laymax = laymin + layers[i];
140  double zz = zi;
141  double thickTot(0);
142  for (int ly = laymin; ly < laymax; ++ly) {
143  int ii = layerType[ly];
144  int copy = copyNumber[ii];
145  double rinB = (layerSense[ly] == 0) ? (zo * slopeB[0]) : (zo * slopeB[1]);
146  zz += (0.5 * thick[ii]);
147  thickTot += thick[ii];
148 
149  std::string name = "HGCal" + names[ii] + std::to_string(copy);
150 #ifdef EDM_ML_DEBUG
151  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: Layer " << ly << ":" << ii
152  << " Front " << zi << ", " << routF
153  << " Back " << zo << ", " << rinB
154  << " superlayer thickness " << layerThick[i];
155 #endif
156  DDName matName(DDSplit(materials[ii]).first,
157  DDSplit(materials[ii]).second);
158  DDMaterial matter(matName);
159  DDLogicalPart glog;
160  if (layerSense[ly] == 0) {
161  double alpha = geant_units::piRadians / sectors;
162  double rmax = routF * cos(alpha) - tol;
163  std::vector<double> pgonZ, pgonRin, pgonRout;
164  pgonZ.emplace_back(-0.5 * thick[ii]);
165  pgonZ.emplace_back(0.5 * thick[ii]);
166  pgonRin.emplace_back(rinB);
167  pgonRin.emplace_back(rinB);
168  pgonRout.emplace_back(rmax);
169  pgonRout.emplace_back(rmax);
170  DDSolid solid = DDSolidFactory::polyhedra(DDName(name, idNameSpace),
171  sectors, -alpha,
173  pgonZ, pgonRin, pgonRout);
174  glog = DDLogicalPart(solid.ddname(), matter, solid);
175 #ifdef EDM_ML_DEBUG
176  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: " << solid.name()
177  << " polyhedra of " << sectors
178  << " sectors covering "
179  << convertRadToDeg(-alpha)
180  << ":" << (360.0+convertRadToDeg(-alpha))
181  << " with " << pgonZ.size() << " sections";
182  for (unsigned int k = 0; k < pgonZ.size(); ++k)
183  edm::LogVerbatim("HGCalGeom") << "[" << k << "] z " << pgonZ[k]
184  << " R " << pgonRin[k]
185  << ":" << pgonRout[k];
186 #endif
187  } else {
188  DDSolid solid =
189  DDSolidFactory::tubs(DDName(name, idNameSpace), 0.5 * thick[ii],
190  rinB, routF, 0.0, 2*geant_units::piRadians);
191  glog = DDLogicalPart(solid.ddname(), matter, solid);
192 #ifdef EDM_ML_DEBUG
193  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: " << solid.name()
194  << " Tubs made of " << matName
195  << " of dimensions " << rinB << ", "
196  << routF << ", " << 0.5 * thick[ii]
197  << ", 0.0, 360.0";
198  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule test position in: "
199  << glog.name() << " number " << copy;
200 #endif
201  positionSensitive(glog, rinB, routF, cpv);
202  }
203  DDTranslation r1(0, 0, zz);
204  DDRotation rot;
205  cpv.position(glog, module, copy, r1, rot);
206  ++copyNumber[ii];
207 #ifdef EDM_ML_DEBUG
208  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: " << glog.name()
209  << " number " << copy << " positioned in "
210  << module.name() << " at " << r1
211  << " with " << rot;
212 #endif
213  zz += (0.5 * thick[ii]);
214  } // End of loop over layers in a block
215  zi = zo;
216  laymin = laymax;
217  if (fabs(thickTot - layerThick[i]) < 0.00001) {
218  } else if (thickTot > layerThick[i]) {
219  edm::LogError("HGCalGeom")
220  << "Thickness of the partition " << layerThick[i]
221  << " is smaller than thickness " << thickTot
222  << " of all its components **** ERROR ****\n";
223  } else if (thickTot < layerThick[i]) {
224  edm::LogWarning("HGCalGeom")
225  << "Thickness of the partition " << layerThick[i]
226  << " does not match with " << thickTot << " of the components\n";
227  }
228  } // End of loop over blocks
229 }
230 
231 double DDHGCalModule::rMax(double z) {
232  double r(0);
233 #ifdef EDM_ML_DEBUG
234  unsigned int ik(0);
235 #endif
236  for (unsigned int k = 0; k < slopeT.size(); ++k) {
237  if (z < zFront[k]) break;
238  r = rMaxFront[k] + (z - zFront[k]) * slopeT[k];
239 #ifdef EDM_ML_DEBUG
240  ik = k;
241 #endif
242  }
243 #ifdef EDM_ML_DEBUG
244  edm::LogVerbatim("HGCalGeom") << "rMax : " << z << ":" << ik << ":" << r;
245 #endif
246  return r;
247 }
248 
250  double rout, DDCompactView& cpv) {
251  double dx = 0.5 * waferW;
252  double dy = 3.0 * dx * tan(30._deg);
253  double rr = 2.0 * dx * tan(30._deg);
254  int ncol = (int)(2.0 * rout / waferW) + 1;
255  int nrow = (int)(rout / (waferW * tan(30._deg))) + 1;
256  int incm(0), inrm(0), kount(0), ntot(0), nin(0), nfine(0), ncoarse(0);
257 #ifdef EDM_ML_DEBUG
258  edm::LogVerbatim("HGCalGeom") << glog.ddname() << " rout " << rout << " Row "
259  << nrow << " Column " << ncol;
260 #endif
261  for (int nr = -nrow; nr <= nrow; ++nr) {
262  int inr = (nr >= 0) ? nr : -nr;
263  for (int nc = -ncol; nc <= ncol; ++nc) {
264  int inc = (nc >= 0) ? nc : -nc;
265  if (inr % 2 == inc % 2) {
266  double xpos = nc * dx;
267  double ypos = nr * dy;
268  std::pair<int, int> corner =
269  HGCalGeomTools::waferCorner(xpos, ypos, dx, rr, rin, rout, true);
270  ++ntot;
271  if (corner.first > 0) {
272  int copy = inr * 100 + inc;
273  if (nc < 0) copy += 10000;
274  if (nr < 0) copy += 100000;
275  if (inc > incm) incm = inc;
276  if (inr > inrm) inrm = inr;
277  kount++;
278  if (copies.count(copy) == 0) copies.insert(copy);
279  if (corner.first == (int)(HGCalParameters::k_CornerSize)) {
280  double rpos = std::sqrt(xpos * xpos + ypos * ypos);
281  DDTranslation tran(xpos, ypos, 0.0);
283  ++nin;
284  DDName name =
285  (rpos < rMaxFine)
286  ? DDName(DDSplit(wafer[0]).first, DDSplit(wafer[0]).second)
287  : DDName(DDSplit(wafer[1]).first, DDSplit(wafer[1]).second);
288  cpv.position(name, glog.ddname(), copy, tran, rotation);
289  if (rpos < rMaxFine)
290  ++nfine;
291  else
292  ++ncoarse;
293 #ifdef EDM_ML_DEBUG
294  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: " << name
295  << " number " << copy
296  << " positioned in " << glog.ddname()
297  << " at " << tran << " with "
298  << rotation;
299 #endif
300  }
301  }
302  }
303  }
304  }
305 #ifdef EDM_ML_DEBUG
306  edm::LogVerbatim("HGCalGeom") << "DDHGCalModule: # of columns " << incm
307  << " # of rows " << inrm << " and " << nin << ":"
308  << kount << ":" << ntot << " wafers ("
309  << nfine << ":" << ncoarse << ") for "
310  << glog.ddname() << " R " << rin << ":" << rout;
311 #endif
312 }
float alpha
Definition: AMPTWrapper.h:95
std::vector< LayerSetAndLayers > layers(const SeedingLayerSetsHits &sets)
Definition: LayerTriplets.cc:4
const N & name() const
Definition: DDBase.h:74
def copy(args, dbName)
double rMax(double z)
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:43
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:15
constexpr NumType convertRadToDeg(NumType radians)
Definition: GeantUnits.h:98
static std::string & ns()
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:80
constexpr long double piRadians(M_PI)
const std::string names[nVars_]
A DDSolid represents the shape of a part.
Definition: DDSolid.h:39
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
int nin
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
static std::pair< int32_t, int32_t > waferCorner(double xpos, double ypos, double r, double R, double rMin, double rMax, bool oldBug=false)
T sqrt(T t)
Definition: SSEVec.h:18
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
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
void execute(DDCompactView &cpv) override
ii
Definition: cuy.py:590
int k[5][pyjets_maxn]
static uint32_t k_CornerSize
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override
void position(const DDLogicalPart &self, const DDLogicalPart &parent, const std::string &copyno, const DDTranslation &trans, const DDRotation &rot, const DDDivision *div=0)
void positionSensitive(DDLogicalPart &glog, double rin, double rout, DDCompactView &cpv)
~DDHGCalModule() override
void constructLayers(const DDLogicalPart &, DDCompactView &cpv)
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
static DDSolid polyhedra(const DDName &name, int sides, double startPhi, double deltaPhi, const std::vector< double > &z, const std::vector< double > &rmin, const std::vector< double > &rmax)
Creates a polyhedra (refere to Geant3 or Geant4 documentation)
Definition: DDSolid.cc:730
const N & ddname() const
Definition: DDBase.h:76