File indexing completed on 2024-04-06 12:15:21
0001 #include "DD4hep/DetFactoryHelper.h"
0002 #include "DataFormats/Math/interface/CMSUnits.h"
0003 #include "DetectorDescription/DDCMS/interface/DDPlugins.h"
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005
0006 using namespace cms_units::operators;
0007
0008 static long algorithm(dd4hep::Detector&, cms::DDParsingContext& ctxt, xml_h e) {
0009 cms::DDNamespace ns(ctxt, e, true);
0010 cms::DDAlgoArguments args(ctxt, e);
0011 std::string parentName = args.parentName();
0012
0013 std::string genMat = args.value<std::string>("GeneralMaterial");
0014 int number = args.value<int>("Ladders");
0015 double layerDz = args.value<double>("LayerDz");
0016 double coolDz = args.value<double>("CoolDz");
0017 double coolThick = args.value<double>("CoolThick");
0018 double coolRadius = args.value<double>("CoolRadius");
0019 double coolDist = args.value<double>("CoolDist");
0020 double cool1Offset = args.value<double>("Cool1Offset");
0021 double cool2Offset = args.value<double>("Cool2Offset");
0022 std::string coolMat = args.value<std::string>("CoolMaterial");
0023 std::string tubeMat = args.value<std::string>("CoolTubeMaterial");
0024 std::string coolMatHalf = args.value<std::string>("CoolMaterialHalf");
0025 std::string tubeMatHalf = args.value<std::string>("CoolTubeMaterialHalf");
0026 double phiFineTune = args.value<double>("PitchFineTune");
0027 double rOuterFineTune = args.value<double>("OuterOffsetFineTune");
0028 double rInnerFineTune = args.value<double>("InnerOffsetFineTune");
0029
0030
0031 std::string ladder = args.value<std::string>("LadderName");
0032
0033 double ladderWidth = args.value<double>("LadderWidth");
0034 double ladderThick = args.value<double>("LadderThick");
0035 double ladderOffset = args.value<double>("LadderOffset");
0036 int outerFirst = args.value<int>("OuterFirst");
0037
0038 edm::LogVerbatim("PixelGeom") << "DDPixBarLayerUpgradeAlgo debug: Parent " << parentName << " NameSpace "
0039 << ns.objName(parentName) << "\n\tLadders " << number << "\tGeneral Material " << genMat
0040 << "\tLength " << layerDz << "\tSpecification of Cooling Pieces:\n"
0041 << "\tLength " << coolDz << "\tThickness of Shell " << coolThick << "\tRadial distance "
0042 << coolDist << "\tMaterials " << coolMat << ", " << tubeMat << std::endl;
0043
0044 edm::LogVerbatim("PixelGeom") << "DDPixBarLayerUpgradeAlgo debug: Full Ladder " << ladder << " width/thickness "
0045 << ladderWidth << ", " << ladderThick;
0046
0047 double dphi = 2_pi / (double)number;
0048 double x2 = coolDist * sin(0.5 * dphi);
0049 double rtmi = coolDist * cos(0.5 * dphi) - (coolRadius + ladderThick) + rInnerFineTune;
0050 double rmxh = coolDist * cos(0.5 * dphi) + (coolRadius + ladderThick + ladderOffset) + rOuterFineTune;
0051 double rtmx = sqrt(rmxh * rmxh + ladderWidth * ladderWidth / 4.);
0052
0053 std::string name = ns.objName(parentName);
0054
0055 dd4hep::Solid solid = ns.addSolid(ns.prepend(name), dd4hep::Tube(rtmi, rtmx, 0.5 * layerDz, 0., 2._pi));
0056
0057 edm::LogVerbatim("PixelGeom") << "DDPixBarLayerUpgradeAlgo test: " << solid.name() << " Tubs made of " << genMat
0058 << " from 0. to " << convertRadToDeg(2_pi) << " with Rin " << rtmi << " Rout " << rtmx
0059 << " ZHalf " << 0.5 * layerDz;
0060
0061 dd4hep::Volume layer = ns.addVolume(dd4hep::Volume(solid.name(), solid, ns.material(genMat)));
0062
0063
0064 solid = ns.addSolid(ns.prepend(name + "CoolTube"), dd4hep::Tube(0., coolRadius, 0.5 * coolDz, 0., 2_pi));
0065
0066 edm::LogVerbatim("PixelGeom") << "DDPixBarLayerUpgradeAlgo test: " << solid.name() << " Tubs made of " << tubeMat
0067 << " from 0 to " << convertRadToDeg(2_pi) << " with Rout " << coolRadius << " ZHalf "
0068 << 0.5 * coolDz;
0069
0070 dd4hep::Volume coolTube = ns.addVolume(dd4hep::Volume(solid.name(), solid, ns.material(tubeMat)));
0071
0072
0073 solid = ns.addSolid(ns.prepend(name + "CoolTubeHalf"), dd4hep::Tube(0., coolRadius, 0.5 * coolDz, 0, 1_pi));
0074
0075 edm::LogVerbatim("PixelGeom") << "DDPixBarLayerUpgradeAlgo test: " << solid.name() << " Tubs made of " << tubeMatHalf
0076 << " from 0 to " << convertRadToDeg(2_pi) << " with Rout " << coolRadius << " ZHalf "
0077 << 0.5 * coolDz;
0078
0079 dd4hep::Volume coolTubeHalf = ns.addVolume(dd4hep::Volume(solid.name(), solid, ns.material(tubeMatHalf)));
0080
0081
0082 name = ns.objName(parentName);
0083
0084 solid = ns.addSolid(ns.prepend(name + "Coolant"), dd4hep::Tube(0., coolRadius - coolThick, 0.5 * coolDz, 0., 2_pi));
0085
0086 edm::LogVerbatim("PixelGeom") << "DDPixBarLayerUpgradeAlgo test: " << solid.name() << " Tubs made of " << tubeMat
0087 << " from 0 to " << convertRadToDeg(2._pi) << " with Rout " << coolRadius - coolThick
0088 << " ZHalf " << 0.5 * coolDz;
0089
0090 dd4hep::Volume cool = ns.addVolume(dd4hep::Volume(solid.name(), solid, ns.material(coolMat)));
0091
0092 coolTube.placeVolume(cool, 1, dd4hep::Transform3D(dd4hep::Rotation3D(), dd4hep::Position(0., 0., 0.)));
0093
0094 edm::LogVerbatim("PixelGeom") << "DDPixBarLayerUpgradeAlgo test: " << cool.name() << " number 1 positioned in "
0095 << coolTube.name() << " at (0,0,0) with no rotation";
0096
0097
0098
0099 solid =
0100 ns.addSolid(ns.prepend(name + "CoolantHalf"), dd4hep::Tube(0., coolRadius - coolThick, 0.5 * coolDz, 0., 1._pi));
0101
0102 edm::LogVerbatim("PixelGeom") << "DDPixBarLayerUpgradeAlgo test: " << solid.name() << " Tubs made of " << tubeMatHalf
0103 << " from 0 to " << convertRadToDeg(2._pi) << " with Rout " << coolRadius - coolThick
0104 << " ZHalf " << 0.5 * coolDz;
0105
0106 dd4hep::Volume coolHalf = ns.addVolume(dd4hep::Volume(solid.name(), solid, ns.material(coolMatHalf)));
0107
0108 coolTubeHalf.placeVolume(coolHalf, 1, dd4hep::Transform3D(dd4hep::Rotation3D(), dd4hep::Position(0., 0., 0.)));
0109
0110 edm::LogVerbatim("PixelGeom") << "DDPixBarLayerUpgradeAlgo test: " << cool.name() << " number 1 positioned in "
0111 << coolTube.name() << " at (0,0,0) with no rotation";
0112 int copy = 1, iup = (-1) * outerFirst;
0113 int copyoffset = number + 2;
0114
0115 for (int i = 1; i < number + 1; i++) {
0116 double phi = i * dphi + 90._deg - 0.5 * dphi + phiFineTune;
0117 double phix, phiy, rrr, rrroffset;
0118 std::string rots;
0119
0120 auto tran = dd4hep::Position();
0121 auto rot = dd4hep::Rotation3D();
0122
0123 iup = -iup;
0124
0125 double dr;
0126
0127 if ((i == 1) || (i == number / 2 + 1)) {
0128 dr = coolRadius + 0.5 * ladderThick + ladderOffset;
0129 } else {
0130 dr = coolRadius + 0.5 * ladderThick;
0131 }
0132
0133 if (i % 2 == 1) {
0134 rrr = coolDist * cos(0.5 * dphi) + iup * dr + rOuterFineTune;
0135 } else {
0136 rrr = coolDist * cos(0.5 * dphi) + iup * dr + rInnerFineTune;
0137 }
0138
0139 tran = dd4hep::Position(rrr * cos(phi), rrr * sin(phi), 0);
0140 rots = name + std::to_string(copy);
0141
0142 if (iup > 0) {
0143 phix = phi - 90._deg;
0144 } else {
0145 phix = phi + 90._deg;
0146 }
0147
0148 phiy = phix + 90._deg;
0149
0150 edm::LogVerbatim("PixelGeom") << "DDPixBarLayerUpgradeAlgo test: Creating a new "
0151 << "rotation: " << rots << "\t90., " << convertRadToDeg(phix) << ", 90.,"
0152 << convertRadToDeg(phiy) << ", 0, 0";
0153
0154 rot = cms::makeRotation3D(90._deg, phix, 90._deg, phiy, 0., 0.);
0155
0156
0157 layer.placeVolume(ns.volume(ladder), copy, dd4hep::Transform3D(rot, tran));
0158
0159 edm::LogVerbatim("PixelGeom") << "DDPixBarLayerUpgradeAlgo test: " << ladder << " number " << copy
0160 << " positioned in " << layer.name() << " at " << tran << " with " << rot;
0161
0162 copy++;
0163
0164 rrr = coolDist * cos(0.5 * dphi) + coolRadius / 2.;
0165
0166 rots = name + std::to_string(i + 100);
0167 phix = phi + 90._deg;
0168
0169 if (iup < 0)
0170 phix += dphi;
0171
0172 phiy = phix + 90._deg;
0173
0174 edm::LogVerbatim("PixelGeom") << "DDPixBarLayerUpgradeAlgo test: Creating a new "
0175 << "rotation: " << rots << "\t90., " << convertRadToDeg(phix) << ", 90.,"
0176 << convertRadToDeg(phiy) << ", 0, 0";
0177
0178 tran = dd4hep::Position(rrr * cos(phi) - x2 * sin(phi), rrr * sin(phi) + x2 * cos(phi), 0.);
0179
0180 rot = cms::makeRotation3D(90._deg, phix, 90._deg, phiy, 0., 0.);
0181
0182 layer.placeVolume(coolTubeHalf, i + 1, dd4hep::Transform3D(rot, tran));
0183
0184 if ((i == 1) || (i == number / 2 + 1)) {
0185 rrroffset = coolDist * cos(0.5 * dphi) + iup * ladderOffset + rOuterFineTune;
0186 tran = dd4hep::Position(
0187 rrroffset * cos(phi) - cool1Offset * sin(phi), rrroffset * sin(phi) + cool1Offset * cos(phi), 0.);
0188
0189 layer.placeVolume(coolTube, copyoffset, dd4hep::Transform3D(dd4hep::Rotation3D(), tran));
0190 ;
0191
0192 copyoffset++;
0193 tran = dd4hep::Position(
0194 rrroffset * cos(phi) - cool2Offset * sin(phi), rrroffset * sin(phi) + cool2Offset * cos(phi), 0.);
0195
0196 layer.placeVolume(coolTube, copyoffset, dd4hep::Transform3D(dd4hep::Rotation3D(), tran));
0197 copyoffset++;
0198 }
0199
0200 edm::LogVerbatim("PixelGeom") << "DDPixBarLayerUpgradeAlgo test: " << coolTube.name() << " number " << i + 1
0201 << " positioned in " << layer.name() << " at " << tran << " with " << rot;
0202 }
0203
0204 return cms::s_executed;
0205 }
0206
0207 DECLARE_DDCMS_DETELEMENT(DDCMS_track_DDPixBarLayerUpgradeAlgo, algorithm);