Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:15:22

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // File: DDTIDAxialCableAlgo.cc
0003 // Description: Create and position TID axial cables at prescribed phi values
0004 ///////////////////////////////////////////////////////////////////////////////
0005 
0006 #include <algorithm>
0007 #include <cmath>
0008 #include "DataFormats/Math/interface/CMSUnits.h"
0009 #include "DD4hep/DetFactoryHelper.h"
0010 #include "DetectorDescription/DDCMS/interface/DDPlugins.h"
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 
0013 using namespace edm;
0014 using namespace dd4hep;
0015 using namespace cms;
0016 using namespace cms_units::operators;
0017 
0018 namespace {
0019   long algorithm(dd4hep::Detector &description, cms::DDParsingContext &ctxt, xml_h e) {
0020     cms::DDNamespace ns(ctxt, e, true);
0021     cms::DDAlgoArguments args(ctxt, e);
0022 
0023     LogVerbatim("TIDGeom") << "DDTIDAxialCableAlgo info: Creating an instance...";
0024 
0025     double zBend = args.value<double>("ZBend");                                    // Start z (at bending)........
0026     double zEnd = args.value<double>("ZEnd");                                      // End   z             ........
0027     double rMin = args.value<double>("RMin");                                      // Minimum radius      ........
0028     double rMax = args.value<double>("RMax");                                      // Maximum radius      ........
0029     double rTop = args.value<double>("RTop");                                      // Maximum radius (top)........
0030     double width = args.value<double>("Width");                                    // Angular width
0031     double thick = args.value<double>("Thick");                                    // Thickness
0032     std::vector<double> angles = args.value<std::vector<double>>("Angles");        // Phi Angles
0033     std::vector<double> zposWheel = args.value<std::vector<double>>("ZPosWheel");  // Z position of wheels
0034     std::vector<double> zposRing = args.value<std::vector<double>>("ZPosRing");    // Z position of rings inside wheels
0035 
0036     std::string childName = args.value<std::string>("ChildName");  // Child name
0037     std::string matIn = args.value<std::string>("MaterialIn");     // Material name (for inner parts)
0038     std::string matOut = args.value<std::string>("MaterialOut");   // Material name (for outer part)
0039 
0040     LogVerbatim("TIDGeom") << "DDTIDAxialCableAlgo debug: Parameters for creating " << (zposWheel.size() + 2)
0041                            << " axial cables and positioning" << angles.size() << "copies in Service volume"
0042                            << "\nzBend " << zBend << "\nzEnd " << zEnd << "\nrMin " << rMin << "\nrMax " << rMax
0043                            << "\nCable width " << convertRadToDeg(width) << "\nthickness " << thick << " with Angles";
0044 
0045     for (int i = 0; i < (int)(angles.size()); i++)
0046       LogVerbatim("TIDGeom") << "\n\tangles[" << i << "] = " << convertRadToDeg(angles[i]);
0047 
0048     LogVerbatim("TIDGeom") << "\nWheels " << zposWheel.size() << " at Z";
0049 
0050     for (int i = 0; i < (int)(zposWheel.size()); i++)
0051       LogVerbatim("TIDGeom") << "\n\tzposWheel[" << i << "] = " << zposWheel[i];
0052 
0053     LogVerbatim("TIDGeom") << "\neach with " << zposRing.size() << " Rings at Z";
0054 
0055     for (int i = 0; i < (int)(zposRing.size()); i++)
0056       LogVerbatim("TIDGeom") << "\tzposRing[" << i << "] = " << zposRing[i];
0057 
0058     Volume mother = ns.volume(args.parentName());
0059 
0060     LogVerbatim("TIDGeom") << "DDTIDAxialCableAlgo debug: Parent " << mother.name() << "\tChild " << childName
0061                            << " NameSpace " << ns.name() << "\tMaterial " << matIn << " and " << matOut;
0062 
0063     std::vector<Volume> logs;
0064     const double thk = thick / zposRing.size();
0065     double r = rMin;
0066     double thktot = 0;
0067     double z;
0068 
0069     // Cables between the wheels
0070     for (int k = 0; k < (int)(zposWheel.size()); k++) {
0071       std::vector<double> pconZ, pconRmin, pconRmax;
0072 
0073       for (int i = 0; i < (int)(zposRing.size()); i++) {
0074         thktot += thk;
0075         z = zposWheel[k] + zposRing[i] - 0.5 * thk;
0076 
0077         if (i != 0) {
0078           pconZ.emplace_back(z);
0079           pconRmin.emplace_back(r);
0080           pconRmax.emplace_back(rMax);
0081         }
0082 
0083         r = rMin;
0084         pconZ.emplace_back(z);
0085         pconRmin.emplace_back(r);
0086         pconRmax.emplace_back(rMax);
0087 
0088         z += thk;
0089         pconZ.emplace_back(z);
0090         pconRmin.emplace_back(r);
0091         pconRmax.emplace_back(rMax);
0092 
0093         r = rMax - thktot;
0094         pconZ.emplace_back(z);
0095         pconRmin.emplace_back(r);
0096         pconRmax.emplace_back(rMax);
0097       }
0098 
0099       if (k >= ((int)(zposWheel.size()) - 1))
0100         z = zBend;
0101       else
0102         z = zposWheel[k + 1] + zposRing[0] - 0.5 * thk;
0103 
0104       pconZ.emplace_back(z);
0105       pconRmin.emplace_back(r);
0106       pconRmax.emplace_back(rMax);
0107 
0108       std::string name = childName + std::to_string(k);
0109 
0110       Solid solid = ns.addSolid(ns.prepend(name), Polycone(-0.5 * width, width, pconRmin, pconRmax, pconZ));
0111 
0112       LogVerbatim("TIDGeom") << "DDTIDAxialCableAlgo test: " << solid.name() << " Polycone made of " << matIn
0113                              << " from " << convertRadToDeg(-0.5 * width) << " to " << convertRadToDeg(0.5 * width)
0114                              << " and with " << pconZ.size() << " sections ";
0115 
0116       for (int i = 0; i < (int)(pconZ.size()); i++)
0117         LogVerbatim("TIDGeom") << "\t[" << i << "]\tZ = " << pconZ[i] << "\tRmin = " << pconRmin[i]
0118                                << "\tRmax = " << pconRmax[i];
0119 
0120       logs.emplace_back(Volume(solid.name(), solid, ns.material("materials:Air")));
0121     }
0122 
0123     // Cable in the vertical part
0124     std::vector<double> pconZ, pconRmin, pconRmax;
0125     r = thktot * rMax / rTop;
0126     z = zBend - thktot;
0127     LogVerbatim("TIDGeom") << "DDTIDAxialCableAlgo test: Thk " << thk << " Total " << thktot << " rMax " << rMax
0128                            << " rTop " << rTop << " dR " << r << " z " << z;
0129 
0130     pconZ.emplace_back(z);
0131     pconRmin.emplace_back(rMax);
0132     pconRmax.emplace_back(rMax);
0133 
0134     z = zBend - r;
0135     pconZ.emplace_back(z);
0136     pconRmin.emplace_back(rMax);
0137     pconRmax.emplace_back(rTop);
0138 
0139     pconZ.emplace_back(zBend);
0140     pconRmin.emplace_back(rMax);
0141     pconRmax.emplace_back(rTop);
0142 
0143     std::string name = childName + std::to_string(zposWheel.size());
0144 
0145     Solid solid = ns.addSolid(ns.prepend(name), Polycone(-0.5 * width, width, pconRmin, pconRmax, pconZ));
0146 
0147     LogVerbatim("TIDGeom") << "DDTIDAxialCableAlgo test: " << solid.name() << " Polycone made of " << matIn << " from "
0148                            << convertRadToDeg(-0.5 * width) << " to " << convertRadToDeg(0.5 * width) << " and with "
0149                            << pconZ.size() << " sections ";
0150 
0151     for (int i = 0; i < (int)(pconZ.size()); i++)
0152       LogVerbatim("TIDGeom") << "\t[" << i << "]\tZ = " << pconZ[i] << "\tRmin = " << pconRmin[i]
0153                              << "\tRmax = " << pconRmax[i];
0154 
0155     logs.emplace_back(Volume(solid.name(), solid, ns.material(matIn)));
0156 
0157     // Cable in the outer part
0158     name = childName + std::to_string(zposWheel.size() + 1);
0159     r = rTop - r;
0160     solid = ns.addSolid(ns.prepend(name), Tube(r, rTop, 0.5 * (zEnd - zBend), -0.5 * width, width));
0161 
0162     LogVerbatim("TIDGeom") << "DDTIDAxialCableAlgo test: " << solid.name() << " Tubs made of " << matOut << " from "
0163                            << convertRadToDeg(-0.5 * width) << " to " << convertRadToDeg(0.5 * width) << " with Rin "
0164                            << r << " Rout " << rTop << " ZHalf " << 0.5 * (zEnd - zBend);
0165 
0166     logs.emplace_back(Volume(solid.name(), solid, ns.material(matOut)));
0167 
0168     // Position the cables
0169     constexpr double theta = 90_deg;
0170 
0171     for (int i = 0; i < (int)(angles.size()); i++) {
0172       double phix = angles[i];
0173       double phiy = phix + 90_deg;
0174 
0175       Rotation3D rotation = cms::makeRotation3D(theta, phix, theta, phiy, 0., 0.);
0176       LogVerbatim("TIDGeom") << "DDTIDAxialCableAlgo test: Creating a new "
0177                              << "rotation: " << convertRadToDeg(theta) << ", " << convertRadToDeg(phix) << ", "
0178                              << convertRadToDeg(theta) << ", " << convertRadToDeg(phiy) << ", 0, 0";
0179 
0180       for (int k = 0; k < (int)(logs.size()); k++) {
0181         Position tran = Position(0., 0., 0.);
0182 
0183         if (k == ((int)(logs.size()) - 1))
0184           tran = Position(0., 0., 0.5 * (zEnd + zBend));
0185 
0186         mother.placeVolume(logs[k], i + 1, Transform3D(rotation, tran));
0187 
0188         LogVerbatim("TIDGeom") << "DDTIDAxialCableAlgo test " << logs[k].name() << " number " << i + 1
0189                                << " positioned in " << mother.name() << " at " << tran << " with " << rotation;
0190       }
0191     }
0192     return s_executed;
0193   }
0194 }  // namespace
0195 
0196 // first argument is the type from the xml file
0197 DECLARE_DDCMS_DETELEMENT(DDCMS_track_DDTIDAxialCableAlgo, algorithm)