8 #include <unordered_set> 11 #include "DD4hep/DetFactoryHelper.h" 22 const std::vector<std::string>& wafers,
23 const std::vector<std::string>& covers,
24 const std::vector<int>& layerType,
25 const std::vector<int>& layerSense,
26 const std::vector<int>& maxModule,
27 const std::vector<std::string>&
names,
28 const std::vector<std::string>& materials,
29 std::vector<int>& copyNumber,
30 const std::vector<double>& layerThick,
31 const double& absorbW,
32 const double& absorbH,
33 const double& waferTot,
35 const double& rMaxFine,
36 std::unordered_set<int>& copies,
44 static const double tan30deg =
tan(30._deg);
45 double zi(zFront), thickTot(0);
46 for (
int ly = firstLayer; ly <= lastLayer; ++ly) {
47 int ii = layerType[ly];
49 double zz = zi + (0.5 * layerThick[
ii]);
50 double zo = zi + layerThick[
ii];
51 thickTot += layerThick[
ii];
55 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalTBModuleX: " << name <<
" Layer " << ly <<
":" << ii <<
" Z " 57 <<
convertCmToMm(layerThick[ii]) <<
" Sense " << layerSense[ly];
61 if (layerSense[ly] == 0) {
62 dd4hep::Solid solid = dd4hep::Box(absorbW, absorbH, 0.5 * layerThick[ii]);
66 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalTBModuleX: " << solid.name() <<
" box of dimension " 70 dd4hep::Position
r1(0, 0, zz);
71 module.placeVolume(glog, copy, r1);
73 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalTBModuleX: " << glog.name() <<
" number " << copy <<
" positioned in " 74 << module.name() <<
" at " << r1 <<
" with no rotation";
76 }
else if (layerSense[ly] > 0) {
77 double dx = 0.5 * waferTot;
78 double dy = 3.0 * dx * tan30deg;
79 double rr = 2.0 * dx * tan30deg;
80 int ncol = (
int)(2.0 * rMax / waferTot) + 1;
81 int nrow = (
int)(rMax / (waferTot * tan30deg)) + 1;
84 edm::LogVerbatim(
"HGCalGeom") << module.name() <<
" Copy " << copy <<
" Type " << layerSense[ly] <<
" rout " 85 <<
convertCmToMm(rMax) <<
" Row " << nrow <<
" column " << ncol <<
" ncrMax " 86 << maxModule[ly] <<
" Z " <<
convertCmToMm(zz) <<
" Center " << ignoreCenter
87 <<
" name " << name <<
" matter " << matter.name();
90 if (maxModule[ly] >= 0) {
91 nrow =
std::min(nrow, maxModule[ly]);
92 ncol =
std::min(ncol, maxModule[ly]);
94 for (
int nr = -nrow;
nr <= nrow; ++
nr) {
96 for (
int nc = -ncol; nc <= ncol; ++nc) {
98 if ((inr % 2 == inc % 2) && (!ignoreCenter || nc != 0 ||
nr != 0)) {
99 double xpos = nc *
dx;
100 double ypos =
nr *
dy;
103 yc[0] = ypos - 0.5 *
rr;
105 yc[1] = ypos + 0.5 *
rr;
109 yc[3] = ypos + 0.5 *
rr;
111 yc[4] = ypos - 0.5 *
rr;
114 bool cornerAll(
true);
115 for (
int k = 0;
k < 6; ++
k) {
121 double rpos =
std::sqrt(xpos * xpos + ypos * ypos);
122 dd4hep::Position tran(xpos, ypos, zz);
123 int copyx = inr * 100 + inc;
128 if (layerSense[ly] == 1) {
129 dd4hep::Solid solid = ns.
solid(covers[0]);
130 std::string name0 = name +
"M" + std::to_string(copyx);
132 name0 = ns.
name() + name0;
134 module.placeVolume(glog1, copy, tran);
137 <<
"DDHGCalTBModuleX: " << glog1.name() <<
" number " << copy <<
" positioned in " 138 << module.name() <<
" at " << tran <<
" with no rotation";
141 glog1.placeVolume(glog2, copyx);
144 <<
"DDHGCalTBModuleX: " << glog2.name() <<
" number " << copyx <<
" positioned in " 145 << glog1.name() <<
" at (0, 0, 0) with no rotation";
147 if (layerSense[ly] == 1)
151 copyx += (copy * 1000000);
152 module.placeVolume(glog2, copyx, tran);
155 <<
"DDHGCalTBModuleX: " << glog2.name() <<
" number " << copyx <<
" positioned in " 156 << module.name() <<
" at " << tran <<
" with no rotation";
171 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalTBModuleX: # of columns " << incm <<
" # of rows " << inrm <<
" and " 172 << kount <<
" wafers for " << module.name();
179 if (fabs(thickTot - totalWidth) < tolerance) {
180 }
else if (thickTot > totalWidth) {
181 edm::LogError(
"HGCalGeom") <<
"Thickness of the partition " << totalWidth <<
" is smaller than " << thickTot
182 <<
": total thickness of all its components in " << module.name() <<
" Layers " 183 << firstLayer <<
":" << lastLayer <<
":" << ignoreCenter <<
"**** ERROR ****";
184 }
else if (thickTot < totalWidth) {
185 edm::LogWarning(
"HGCalGeom") <<
"Thickness of the partition " << totalWidth <<
" does not match with " << thickTot
186 <<
" of the components in " << module.name() <<
" Layers " << firstLayer <<
":" 187 << lastLayer <<
":" << ignoreCenter;
195 dd4hep::SensitiveDetector& ) {
199 const auto& wafers = args.
value<std::vector<std::string> >(
"WaferName");
200 const auto& covers = args.
value<std::vector<std::string> >(
"CoverName");
203 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalTBModuleX: Material " << genMat <<
" with " << wafers.size() <<
" wafers";
205 for (
auto wafer : wafers) {
209 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalTBModuleX: " << covers.size() <<
" covers";
211 for (
auto cover : covers) {
216 const auto& materials = args.
value<std::vector<std::string> >(
"MaterialNames");
217 const auto&
names = args.
value<std::vector<std::string> >(
"VolumeNames");
218 const auto& layerThick = args.
value<std::vector<double> >(
"Thickness");
219 std::vector<int> copyNumber;
220 for (
unsigned int k = 0;
k < layerThick.size(); ++
k) {
221 copyNumber.emplace_back(1);
224 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalTBModuleX: " << materials.size() <<
" types of volumes";
225 for (
unsigned int i = 0; i < names.size(); ++
i)
226 edm::LogVerbatim(
"HGCalGeom") <<
"Volume [" << i <<
"] " << names[
i] <<
" of thickness " 227 <<
convertCmToMm(layerThick[i]) <<
" filled with " << materials[
i]
228 <<
" first copy number " << copyNumber[
i];
230 const auto& blockThick = args.
value<std::vector<double> >(
"BlockThick");
231 const auto& inOut = args.
value<
int>(
"InOut");
232 const auto& layerFrontIn = args.
value<std::vector<int> >(
"LayerFrontIn");
233 const auto& layerBackIn = args.
value<std::vector<int> >(
"LayerBackIn");
234 std::vector<int> layerFrontOut;
235 std::vector<int> layerBackOut;
237 layerFrontOut = args.
value<std::vector<int> >(
"LayerFrontOut");
238 layerBackOut = args.
value<std::vector<int> >(
"LayerBackOut");
241 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalTBModuleX: " << blockThick.size() <<
" blocks with in/out " << inOut;
242 for (
unsigned int i = 0; i < blockThick.size(); ++
i) {
245 <<
" with inner layers " << layerFrontIn[
i] <<
":" << layerBackIn[
i]
246 <<
" and outer layers " << layerFrontOut[
i] <<
":" << layerBackOut[
i];
249 <<
" with inner layers " << layerFrontIn[
i] <<
":" << layerBackIn[
i];
252 const auto& layerType = args.
value<std::vector<int> >(
"LayerType");
253 const auto& layerSense = args.
value<std::vector<int> >(
"LayerSense");
254 const auto& maxModule = args.
value<std::vector<int> >(
"MaxModule");
256 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalTBModuleX: " << layerType.size() <<
" layers";
257 for (
unsigned int i = 0; i < layerType.size(); ++
i)
258 edm::LogVerbatim(
"HGCalGeom") <<
"Layer [" << i <<
"] with material type " << layerType[
i] <<
" sensitive class " 259 << layerSense[
i] <<
" and " << maxModule[
i] <<
" maximum row/columns";
261 const auto& zMinBlock = args.
value<
double>(
"zMinBlock");
262 const auto& rMaxFine = args.
value<
double>(
"rMaxFine");
263 const auto& waferW = args.
value<
double>(
"waferW");
264 const auto& waferGap = args.
value<
double>(
"waferGap");
265 const auto& absorbW = args.
value<
double>(
"absorberW");
266 const auto& absorbH = args.
value<
double>(
"absorberH");
267 const auto&
rMax = args.
value<
double>(
"rMax");
268 const auto& rMaxB = args.
value<
double>(
"rMaxB");
269 double waferTot = waferW + waferGap;
274 <<
" gap among wafers " <<
convertCmToMm(waferGap) <<
" absorber width " 279 std::unordered_set<int> copies;
283 double zi(zMinBlock);
284 for (
unsigned int i = 0; i < blockThick.size(); i++) {
285 double zo = zi + blockThick[
i];
293 dd4hep::Solid solid = dd4hep::Tube(0, rMaxB, 0.5 * blockThick[i], 0.0, 2._pi);
296 double zz = zi + 0.5 * blockThick[
i];
297 dd4hep::Position
r1(0, 0, zz);
298 parent.placeVolume(glog, i, r1);
300 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalTBModuleX: " << glog.name() <<
" number " << i <<
" positioned in " 301 << args.
parentName() <<
" at " << r1 <<
" with no rotation";
302 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalTBModuleX: \t\tInside Block " << i <<
" Layers " << layerFrontIn[
i] <<
":" 303 << layerBackIn[
i] <<
" zFront " <<
convertCmToMm(-0.5 * blockThick[i])
304 <<
" thickness " <<
convertCmToMm(blockThick[i]) <<
" ignore Center 0";
324 -0.5 * blockThick[i],
330 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalTBModuleX: \t\tInside Block " << i <<
" Layers " << layerFrontOut[
i]
331 <<
":" << layerBackOut[
i] <<
" zFront " <<
convertCmToMm(-0.5 * blockThick[i])
332 <<
" thickness " <<
convertCmToMm(blockThick[i]) <<
" ignore Center 1";
352 -0.5 * blockThick[i],
361 <<
convertCmToMm(zi) <<
" with " << copies.size() <<
" different wafer copy numbers";
dd4hep::Solid addSolidNS(const std::string &name, dd4hep::Solid solid) const
dd4hep::Volume volume(const std::string &name, bool exc=true) const
T value(const std::string &name) const
dd4hep::Solid solid(const std::string &name) const
const std::string names[nVars_]
std::string_view name() const
static long algorithm(dd4hep::Detector &, cms::DDParsingContext &ctxt, xml_h e, dd4hep::SensitiveDetector &)
Tan< T >::type tan(const T &t)
Abs< T >::type abs(const T &t)
void constructLayers(const cms::DDNamespace &ns, const std::vector< std::string > &wafers, const std::vector< std::string > &covers, const std::vector< int > &layerType, const std::vector< int > &layerSense, const std::vector< int > &maxModule, const std::vector< std::string > &names, const std::vector< std::string > &materials, std::vector< int > ©Number, const std::vector< double > &layerThick, const double &absorbW, const double &absorbH, const double &waferTot, const double &rMax, const double &rMaxFine, std::unordered_set< int > &copies, int firstLayer, int lastLayer, double zFront, double totalWidth, bool ignoreCenter, dd4hep::Volume &module)
dd4hep::Material material(const std::string &name) const
std::string prepend(const std::string &) const
constexpr NumType convertCmToMm(NumType centimeters)
#define DECLARE_DDCMS_DETELEMENT(name, func)
std::pair< std::string, std::string > DDSplit(const std::string &n)
split into (name,namespace), separator = ':'
std::string parentName() const
Access value of rParent child node.