File indexing completed on 2023-03-17 13:03:07
0001
0002
0003
0004
0005
0006 #include <cmath>
0007 #include <algorithm>
0008 #include <map>
0009 #include <string>
0010 #include <vector>
0011
0012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0013 #include "DataFormats/Math/interface/angle_units.h"
0014 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0015 #include "DetectorDescription/Core/interface/DDSolid.h"
0016 #include "DetectorDescription/Core/interface/DDMaterial.h"
0017 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
0018 #include "DetectorDescription/Core/interface/DDSplit.h"
0019 #include "DetectorDescription/Core/interface/DDTypes.h"
0020 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0021 #include "FWCore/PluginManager/interface/PluginFactory.h"
0022 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0023
0024
0025 using namespace angle_units::operators;
0026
0027 class DDHCalTBCableAlgo : public DDAlgorithm {
0028 public:
0029
0030 DDHCalTBCableAlgo();
0031 ~DDHCalTBCableAlgo() override;
0032
0033 void initialize(const DDNumericArguments& nArgs,
0034 const DDVectorArguments& vArgs,
0035 const DDMapArguments& mArgs,
0036 const DDStringArguments& sArgs,
0037 const DDStringVectorArguments& vsArgs) override;
0038
0039 void execute(DDCompactView& cpv) override;
0040
0041 private:
0042 std::string genMat;
0043 int nsectors;
0044 int nsectortot;
0045 int nhalf;
0046 double rin;
0047 std::vector<double> theta;
0048 std::vector<double> rmax;
0049 std::vector<double> zoff;
0050 std::string absMat;
0051 double thick;
0052 double width1, length1;
0053 double width2, length2;
0054 double gap2;
0055
0056 std::string idName;
0057 std::string idNameSpace;
0058 std::string rotns;
0059 };
0060
0061 DDHCalTBCableAlgo::DDHCalTBCableAlgo() : theta(0), rmax(0), zoff(0) {
0062 #ifdef EDM_ML_DEBUG
0063 edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: Creating an instance";
0064 #endif
0065 }
0066
0067 DDHCalTBCableAlgo::~DDHCalTBCableAlgo() {}
0068
0069 void DDHCalTBCableAlgo::initialize(const DDNumericArguments& nArgs,
0070 const DDVectorArguments& vArgs,
0071 const DDMapArguments&,
0072 const DDStringArguments& sArgs,
0073 const DDStringVectorArguments&) {
0074 genMat = sArgs["MaterialName"];
0075 nsectors = int(nArgs["NSector"]);
0076 nsectortot = int(nArgs["NSectorTot"]);
0077 nhalf = int(nArgs["NHalf"]);
0078 rin = nArgs["RIn"];
0079 theta = vArgs["Theta"];
0080 rmax = vArgs["RMax"];
0081 zoff = vArgs["ZOff"];
0082
0083 absMat = sArgs["AbsMatName"];
0084 thick = nArgs["Thickness"];
0085 width1 = nArgs["Width1"];
0086 length1 = nArgs["Length1"];
0087 width2 = nArgs["Width2"];
0088 length2 = nArgs["Length2"];
0089 gap2 = nArgs["Gap2"];
0090
0091 #ifdef EDM_ML_DEBUG
0092 edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: General material " << genMat << "\tSectors " << nsectors << ", "
0093 << nsectortot << "\tHalves " << nhalf << "\tRin " << rin;
0094 for (unsigned int i = 0; i < theta.size(); i++)
0095 edm::LogVerbatim("HCalGeom") << "\t" << i << " Theta " << theta[i] << " rmax " << rmax[i] << " zoff " << zoff[i];
0096 edm::LogVerbatim("HCalGeom") << "\tCable mockup made of " << absMat << "\tThick " << thick << "\tLength and width "
0097 << length1 << ", " << width1 << " and " << length2 << ", " << width2 << " Gap " << gap2;
0098 #endif
0099 idName = sArgs["MotherName"];
0100 idNameSpace = DDCurrentNamespace::ns();
0101 rotns = sArgs["RotNameSpace"];
0102 #ifdef EDM_ML_DEBUG
0103 edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: Parent " << parent().name() << " idName " << idName
0104 << " NameSpace " << idNameSpace << " for solids etc. and " << rotns << " for rotations";
0105 #endif
0106 }
0107
0108 void DDHCalTBCableAlgo::execute(DDCompactView& cpv) {
0109 #ifdef EDM_ML_DEBUG
0110 edm::LogVerbatim("HCalGeom") << "==>> Constructing DDHCalTBCableAlgo...";
0111 #endif
0112
0113 double alpha = 1._pi / nsectors;
0114 double dphi = nsectortot * 2._pi / nsectors;
0115
0116 double zstep0 = zoff[1] + rmax[1] * tan(theta[1]) + (rin - rmax[1]) * tan(theta[2]);
0117 double zstep1 = zstep0 + thick / cos(theta[2]);
0118 double zstep2 = zoff[3];
0119
0120 double rstep0 = rin + (zstep2 - zstep1) / tan(theta[2]);
0121 double rstep1 = rin + (zstep1 - zstep0) / tan(theta[2]);
0122
0123 std::vector<double> pgonZ = {zstep0, zstep1, zstep2, zstep2 + thick / cos(theta[2])};
0124
0125 std::vector<double> pgonRmin = {rin, rin, rstep0, rmax[2]};
0126 std::vector<double> pgonRmax = {rin, rstep1, rmax[2], rmax[2]};
0127
0128 std::string name("Null");
0129 DDSolid solid;
0130 solid = DDSolidFactory::polyhedra(DDName(idName, idNameSpace), nsectortot, -alpha, dphi, pgonZ, pgonRmin, pgonRmax);
0131 #ifdef EDM_ML_DEBUG
0132 edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << DDName(idName, idNameSpace) << " Polyhedra made of "
0133 << genMat << " with " << nsectortot << " sectors from " << convertRadToDeg(-alpha)
0134 << " to " << convertRadToDeg(-alpha + dphi) << " and with " << pgonZ.size()
0135 << " sections";
0136 for (unsigned int i = 0; i < pgonZ.size(); i++)
0137 edm::LogVerbatim("HCalGeom") << "\t\tZ = " << pgonZ[i] << "\tRmin = " << pgonRmin[i] << "\tRmax = " << pgonRmax[i];
0138 #endif
0139 DDName matname(DDSplit(genMat).first, DDSplit(genMat).second);
0140 DDMaterial matter(matname);
0141 DDLogicalPart genlogic(solid.ddname(), matter, solid);
0142
0143 DDName parentName = parent().name();
0144 DDTranslation r0(0.0, 0.0, 0.0);
0145 DDRotation rot;
0146 cpv.position(DDName(idName, idNameSpace), parentName, 1, r0, rot);
0147 #ifdef EDM_ML_DEBUG
0148 edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << DDName(idName, idNameSpace) << " number 1 positioned in "
0149 << parentName << " at " << r0 << " with " << rot;
0150 #endif
0151 if (nhalf != 1) {
0152 rot = DDRotation(DDName("180D", rotns));
0153 cpv.position(DDName(idName, idNameSpace), parentName, 2, r0, rot);
0154 #ifdef EDM_ML_DEBUG
0155 edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << DDName(idName, idNameSpace) << " number 2 positioned in "
0156 << parentName << " at " << r0 << " with " << rot;
0157 #endif
0158 }
0159
0160
0161 name = idName + "Module";
0162 #ifdef EDM_ML_DEBUG
0163 edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << DDName(name, idNameSpace) << " Polyhedra made of " << genMat
0164 << " with 1 sector from " << convertRadToDeg(-alpha) << " to " << convertRadToDeg(alpha)
0165 << " and with " << pgonZ.size() << " sections";
0166 for (unsigned int i = 0; i < pgonZ.size(); i++)
0167 edm::LogVerbatim("HCalGeom") << "\t\tZ = " << pgonZ[i] << "\tRmin = " << pgonRmin[i] << "\tRmax = " << pgonRmax[i];
0168 #endif
0169 solid = DDSolidFactory::polyhedra(DDName(name, idNameSpace), 1, -alpha, 2 * alpha, pgonZ, pgonRmin, pgonRmax);
0170 DDLogicalPart seclogic(solid.ddname(), matter, solid);
0171
0172 for (int ii = 0; ii < nsectortot; ii++) {
0173 double phi = ii * 2 * alpha;
0174 DDRotation rotation;
0175 std::string rotstr("NULL");
0176 if (phi != 0) {
0177 rotstr = "R" + formatAsDegreesInInteger(phi);
0178 rotation = DDRotation(DDName(rotstr, rotns));
0179 if (!rotation) {
0180 #ifdef EDM_ML_DEBUG
0181 edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: Creating a new "
0182 << "rotation " << rotstr << "\t90," << convertRadToDeg(phi) << ",90,"
0183 << (90 + convertRadToDeg(phi)) << ", 0, 0";
0184 #endif
0185 rotation = DDrot(DDName(rotstr, idNameSpace), 90._deg, phi, 90._deg, (90._deg + phi), 0, 0);
0186 }
0187 }
0188
0189 cpv.position(seclogic, genlogic, ii + 1, DDTranslation(0.0, 0.0, 0.0), rotation);
0190 #ifdef EDM_ML_DEBUG
0191 edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << seclogic.name() << " number " << ii + 1
0192 << " positioned in " << genlogic.name() << " at (0,0,0) with " << rotation;
0193 #endif
0194 }
0195
0196
0197 double rinl = pgonRmin[0] + thick * sin(theta[2]);
0198 double routl = pgonRmax[2] - thick * sin(theta[2]);
0199 double dx1 = rinl * tan(alpha);
0200 double dx2 = 0.90 * routl * tan(alpha);
0201 double dy = 0.50 * thick;
0202 double dz = 0.50 * (routl - rinl);
0203 name = idName + "Trap";
0204 solid = DDSolidFactory::trap(DDName(name, idNameSpace), dz, 0, 0, dy, dx1, dx1, 0, dy, dx2, dx2, 0);
0205 #ifdef EDM_ML_DEBUG
0206 edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << solid.name() << " Trap made of " << genMat
0207 << " of dimensions " << dz << ", 0, 0, " << dy << ", " << dx1 << ", " << dx1 << ", 0, "
0208 << dy << ", " << dx2 << ", " << dx2 << ", 0";
0209 #endif
0210 DDLogicalPart glog(solid.ddname(), matter, solid);
0211
0212 std::string rotstr = name;
0213 #ifdef EDM_ML_DEBUG
0214 edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: Creating a rotation: " << rotstr << "\t90, 270, "
0215 << (180 - convertRadToDeg(theta[2])) << ", 0, " << (90 - convertRadToDeg(theta[2]))
0216 << ", 0";
0217 #endif
0218 rot = DDrot(DDName(rotstr, idNameSpace), 90._deg, 270._deg, (180._deg - theta[2]), 0, (90._deg - theta[2]), 0);
0219 DDTranslation r1(0.5 * (rinl + routl), 0, 0.5 * (pgonZ[1] + pgonZ[2]));
0220 cpv.position(glog, seclogic, 1, r1, rot);
0221 #ifdef EDM_ML_DEBUG
0222 edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << glog.name() << " number 1 positioned in " << seclogic.name()
0223 << " at " << r1 << " with " << rot;
0224 #endif
0225
0226 name = idName + "Cable1";
0227 double phi = atan((dx2 - dx1) / (2 * dz));
0228 double xmid = 0.5 * (dx1 + dx2) - 1.0;
0229 solid = DDSolidFactory::box(DDName(name, idNameSpace), 0.5 * width1, 0.5 * thick, 0.5 * length1);
0230 #ifdef EDM_ML_DEBUG
0231 edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << solid.name() << " Box made of " << absMat << " of dimension "
0232 << 0.5 * width1 << ", " << 0.5 * thick << ", " << 0.5 * length1;
0233 #endif
0234 DDName absname(DDSplit(absMat).first, DDSplit(absMat).second);
0235 DDMaterial absmatter(absname);
0236 DDLogicalPart cablog1(solid.ddname(), absmatter, solid);
0237
0238 rotstr = idName + "Left";
0239 #ifdef EDM_ML_DEBUG
0240 edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: Creating a rotation " << rotstr << "\t"
0241 << (90 + convertRadToDeg(phi)) << ", 0, 90, 90, " << convertRadToDeg(phi) << ", 0";
0242 #endif
0243 DDRotation rot2 = DDrot(DDName(rotstr, idNameSpace), (90._deg + phi), 0.0, 90._deg, 90._deg, phi, 0.0);
0244 DDTranslation r2((xmid - 0.5 * width1 * cos(phi)), 0, 0);
0245 cpv.position(cablog1, glog, 1, r2, rot2);
0246 #ifdef EDM_ML_DEBUG
0247 edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << cablog1.name() << " number 1 positioned in " << glog.name()
0248 << " at " << r2 << " with " << rot2;
0249 #endif
0250 rotstr = idName + "Right";
0251 #ifdef EDM_ML_DEBUG
0252 edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: Creating a rotation " << rotstr << "\t"
0253 << (90 - convertRadToDeg(phi)) << ", 0, 90, 90, " << convertRadToDeg(-phi) << ", 0";
0254 #endif
0255 DDRotation rot3 = DDrot(DDName(rotstr, idNameSpace), (90._deg - phi), 0, 90._deg, 90._deg, -phi, 0);
0256 DDTranslation r3(-(xmid - 0.5 * width1 * cos(phi)), 0, 0);
0257 cpv.position(cablog1, glog, 2, r3, rot3);
0258 #ifdef EDM_ML_DEBUG
0259 edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << cablog1.name() << " number 2 positioned in " << glog.name()
0260 << " at " << r3 << " with " << rot3;
0261 #endif
0262
0263 name = idName + "Cable2";
0264 solid = DDSolidFactory::box(DDName(name, idNameSpace), 0.5 * width2, 0.5 * thick, 0.5 * length2);
0265 #ifdef EDM_ML_DEBUG
0266 edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << solid.name() << " Box made of " << absMat << " of dimension "
0267 << 0.5 * width2 << ", " << 0.5 * thick << ", " << 0.5 * length2;
0268 #endif
0269 DDLogicalPart cablog2(solid.ddname(), absmatter, solid);
0270
0271 double xpos = 0.5 * (width2 + gap2);
0272 cpv.position(cablog2, glog, 1, DDTranslation(xpos, 0.0, 0.0), DDRotation());
0273 #ifdef EDM_ML_DEBUG
0274 edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << cablog2.name() << " number 1 positioned in " << glog.name()
0275 << " at (" << xpos << ", 0, 0) with no "
0276 << "rotation";
0277 #endif
0278 cpv.position(cablog2, glog, 2, DDTranslation(-xpos, 0.0, 0.0), DDRotation());
0279 #ifdef EDM_ML_DEBUG
0280 edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << cablog2.name() << " number 2 positioned in " << glog.name()
0281 << " at (" << -xpos << ", 0, 0) with no "
0282 << "rotation";
0283
0284 edm::LogVerbatim("HCalGeom") << "<<== End of DDHCalTBCableAlgo construction";
0285 #endif
0286 }
0287
0288 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHCalTBCableAlgo, "hcal:DDHCalTBCableAlgo");