Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 23:30:07

0001 #include "DataFormats/Math/interface/angle_units.h"
0002 #include "DetectorDescription/DDCMS/interface/DDPlugins.h"
0003 #include "DetectorDescription/DDCMS/interface/DDutils.h"
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #include "DD4hep/DetFactoryHelper.h"
0006 
0007 //#define EDM_ML_DEBUG
0008 using namespace angle_units::operators;
0009 
0010 static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
0011   cms::DDNamespace ns(ctxt, e, true);
0012   cms::DDAlgoArguments args(ctxt, e);
0013 
0014   // Header section
0015   //     <---- Zout ---->
0016   //  |  ****************     |
0017   //  |  *              *     Wstep
0018   //  W  *              ***** |
0019   //  |  *                  *
0020   //  |  ********************
0021   //     <------ Zin ------->
0022   //     <------ Zout ------>         Zout = Full sector Z at position
0023   //  |  ********************         Zin  = Full sector Z at position
0024   //  |  *                 *
0025   //  W  *                * Angle = Theta sector
0026   //  |  *               *  )
0027   //  |  ****************--------
0028   //     <------ Zin ------->
0029   //     <------ Zout ------>         Zin(i)=Zout(i-1)
0030   //  |  ********************         Zout(i)=Zin(i)+W(i)/tan(Theta(i))
0031   //  |  *                 *
0032   //  W  *                *  Theta
0033   //  |  *               *
0034   //  |  ****************--------
0035   //     <--- Zin ------>
0036   std::string genMat = args.value<std::string>("MaterialName");           //General material
0037   int nsectors = args.value<int>("NSector");                              //Number of potenital straight edges
0038   int nsectortot = args.value<int>("NSectorTot");                         //Number of straight edges (actual)
0039   int nhalf = args.value<int>("NHalf");                                   //Number of half modules
0040   double rin = args.value<double>("RIn");                                 //(see Figure of hcalbarrel)
0041   std::vector<double> theta = args.value<std::vector<double> >("Theta");  //  .... (in degrees)
0042   std::vector<double> rmax = args.value<std::vector<double> >("RMax");    //  ....
0043   std::vector<double> zoff = args.value<std::vector<double> >("ZOff");    //  ....
0044   std::string absMat = args.value<std::string>("AbsMatName");             //Absorber material
0045   double thick = args.value<double>("Thickness");                         //Thickness of absorber
0046   double width1 = args.value<double>("Width1");                           //Width of absorber type 1
0047   double length1 = args.value<double>("Length1");                         //Length of absorber type 1
0048   double width2 = args.value<double>("Width2");                           //Width of absorber type 2
0049   double length2 = args.value<double>("Length2");                         //Length of absorber type 2
0050   double gap2 = args.value<double>("Gap2");                               //Gap between abosrbers of type 2
0051   std::string idName = args.value<std::string>("MotherName");             //Name of the "parent" volume.
0052 #ifdef EDM_ML_DEBUG
0053   edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: General material " << genMat << "\tSectors " << nsectors << ", "
0054                                << nsectortot << "\tHalves " << nhalf << "\tRin " << cms::convert2mm(rin);
0055   for (unsigned int i = 0; i < theta.size(); i++)
0056     edm::LogVerbatim("HCalGeom") << "\t" << i << " Theta " << convertRadToDeg(theta[i]) << " rmax "
0057                                  << cms::convert2mm(rmax[i]) << " zoff " << cms::convert2mm(zoff[i]);
0058   edm::LogVerbatim("HCalGeom") << "\tCable mockup made of " << absMat << "\tThick " << cms::convert2mm(thick)
0059                                << "\tLength and width " << cms::convert2mm(length1) << ", " << cms::convert2mm(width1)
0060                                << " and " << cms::convert2mm(length2) << ", " << cms::convert2mm(width2) << " Gap "
0061                                << cms::convert2mm(gap2);
0062   edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: Parent " << args.parentName() << " idName " << idName
0063                                << " NameSpace " << ns.name() << " for solids";
0064 #endif
0065 
0066   double alpha = 1._pi / nsectors;
0067   double dphi = nsectortot * 2._pi / nsectors;
0068   double zstep0 = zoff[1] + rmax[1] * tan(theta[1]) + (rin - rmax[1]) * tan(theta[2]);
0069   double zstep1 = zstep0 + thick / cos(theta[2]);
0070   double zstep2 = zoff[3];
0071   double rstep0 = rin + (zstep2 - zstep1) / tan(theta[2]);
0072   double rstep1 = rin + (zstep1 - zstep0) / tan(theta[2]);
0073 
0074   std::vector<double> pgonZ = {zstep0, zstep1, zstep2, zstep2 + thick / cos(theta[2])};
0075   std::vector<double> pgonRmin = {rin, rin, rstep0, rmax[2]};
0076   std::vector<double> pgonRmax = {rin, rstep1, rmax[2], rmax[2]};
0077 
0078   dd4hep::Solid solid = dd4hep::Polyhedra(ns.prepend(idName), nsectortot, -alpha, dphi, pgonZ, pgonRmin, pgonRmax);
0079   dd4hep::Material matter = ns.material(genMat);
0080   dd4hep::Volume genlogic(solid.name(), solid, matter);
0081 #ifdef EDM_ML_DEBUG
0082   edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << solid.name() << " Polyhedra made of " << genMat << " with "
0083                                << nsectortot << " sectors from " << convertRadToDeg(-alpha) << " to "
0084                                << convertRadToDeg(-alpha + dphi) << " and with " << pgonZ.size() << " sections";
0085   for (unsigned int i = 0; i < pgonZ.size(); i++)
0086     edm::LogVerbatim("HCalGeom") << "\t\tZ = " << cms::convert2mm(pgonZ[i])
0087                                  << "\tRmin = " << cms::convert2mm(pgonRmin[i])
0088                                  << "\tRmax = " << cms::convert2mm(pgonRmax[i]);
0089 #endif
0090 
0091   dd4hep::Volume parent = ns.volume(args.parentName());
0092   dd4hep::Rotation3D rot;
0093   parent.placeVolume(genlogic, 1);
0094 #ifdef EDM_ML_DEBUG
0095   edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << genlogic.name() << " number 1 positioned in "
0096                                << parent.name() << " at (0, 0, 0) with no rotation";
0097 #endif
0098   if (nhalf != 1) {
0099     rot = cms::makeRotation3D(90._deg, 180._deg, 90._deg, 90._deg, 180._deg, 0);
0100     parent.placeVolume(genlogic, 2, rot);
0101 #ifdef EDM_ML_DEBUG
0102     edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << genlogic.name() << " number 2 positioned in "
0103                                  << parent.name() << " at (0, 0, 0) with rotation: " << rot;
0104 #endif
0105   }
0106 
0107   //Construct sector (from -alpha to +alpha)
0108   std::string name = idName + "Module";
0109   solid = dd4hep::Polyhedra(ns.prepend(name), 1, -alpha, 2 * alpha, pgonZ, pgonRmin, pgonRmax);
0110   dd4hep::Volume seclogic(solid.name(), solid, matter);
0111 #ifdef EDM_ML_DEBUG
0112   edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << solid.name() << " Polyhedra made of " << genMat
0113                                << " with 1 sector from " << convertRadToDeg(-alpha) << " to " << convertRadToDeg(alpha)
0114                                << " and with " << pgonZ.size() << " sections";
0115   for (unsigned int i = 0; i < pgonZ.size(); i++)
0116     edm::LogVerbatim("HCalGeom") << "\t\tZ = " << cms::convert2mm(pgonZ[i])
0117                                  << "\tRmin = " << cms::convert2mm(pgonRmin[i])
0118                                  << "\tRmax = " << cms::convert2mm(pgonRmax[i]);
0119 #endif
0120 
0121   for (int ii = 0; ii < nsectortot; ++ii) {
0122     double phi = ii * 2 * alpha;
0123     dd4hep::Rotation3D rotation;
0124     if (phi != 0) {
0125       rotation = dd4hep::RotationZ(phi);
0126 #ifdef EDM_ML_DEBUG
0127       edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: Creating a new rotation "
0128                                    << "\t90," << convertRadToDeg(phi) << ",90," << (90 + convertRadToDeg(phi))
0129                                    << ", 0, 0";
0130 #endif
0131     }
0132     genlogic.placeVolume(seclogic, ii + 1, rotation);
0133 #ifdef EDM_ML_DEBUG
0134     edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << seclogic.name() << " number " << ii + 1
0135                                  << " positioned in " << genlogic.name() << " at (0, 0, 0) with rotation: " << rotation;
0136 #endif
0137   }
0138 
0139   //Now a trapezoid of air
0140   double rinl = pgonRmin[0] + thick * sin(theta[2]);
0141   double routl = pgonRmax[2] - thick * sin(theta[2]);
0142   double dx1 = rinl * tan(alpha);
0143   double dx2 = 0.90 * routl * tan(alpha);
0144   double dy = 0.50 * thick;
0145   double dz = 0.50 * (routl - rinl);
0146   name = idName + "Trap";
0147   solid = dd4hep::Trap(ns.prepend(name), dz, 0, 0, dy, dx1, dx1, 0, dy, dx2, dx2, 0);
0148   dd4hep::Volume glog(solid.name(), solid, matter);
0149 #ifdef EDM_ML_DEBUG
0150   edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << solid.name() << " Trap made of " << genMat
0151                                << " of dimensions " << cms::convert2mm(dz) << ", 0, 0, " << cms::convert2mm(dy) << ", "
0152                                << cms::convert2mm(dx1) << ", " << cms::convert2mm(dx1) << ", 0, " << cms::convert2mm(dy)
0153                                << ", " << cms::convert2mm(dx2) << ", " << cms::convert2mm(dx2) << ", 0";
0154 #endif
0155 
0156   rot = cms::makeRotation3D(90._deg, 270._deg, (180._deg - theta[2]), 0, (90._deg - theta[2]), 0);
0157 #ifdef EDM_ML_DEBUG
0158   edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: Creating a rotation: \t90, 270, "
0159                                << (180 - convertRadToDeg(theta[2])) << ", 0, " << (90 - convertRadToDeg(theta[2]))
0160                                << ", 0";
0161 #endif
0162   dd4hep::Position r1(0.5 * (rinl + routl), 0, 0.5 * (pgonZ[1] + pgonZ[2]));
0163   seclogic.placeVolume(glog, 1, dd4hep::Transform3D(rot, r1));
0164 #ifdef EDM_ML_DEBUG
0165   edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << glog.name() << " number 1 positioned in " << seclogic.name()
0166                                << " at (" << cms::convert2mm(0.5 * (rinl + routl)) << ", 0, "
0167                                << cms::convert2mm(0.5 * (pgonZ[1] + pgonZ[2])) << " with rotation: " << rot;
0168 #endif
0169   //Now the cable of type 1
0170   name = idName + "Cable1";
0171   double phi = atan((dx2 - dx1) / (2 * dz));
0172   double xmid = 0.5 * (dx1 + dx2) - 1.0;
0173   solid = dd4hep::Box(ns.prepend(name), 0.5 * width1, 0.5 * thick, 0.5 * length1);
0174   dd4hep::Material absmatter = ns.material(absMat);
0175   dd4hep::Volume cablog1(solid.name(), solid, absmatter);
0176 #ifdef EDM_ML_DEBUG
0177   edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << solid.name() << " Box made of " << absMat << " of dimension "
0178                                << cms::convert2mm(0.5 * width1) << ", " << cms::convert2mm(0.5 * thick) << ", "
0179                                << cms::convert2mm(0.5 * length1);
0180 #endif
0181 
0182   dd4hep::Rotation3D rot2 = cms::makeRotation3D((90._deg + phi), 0.0, 90._deg, 90._deg, phi, 0.0);
0183 #ifdef EDM_ML_DEBUG
0184   edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: Creating a rotation \t" << (90 + convertRadToDeg(phi))
0185                                << ", 0, 90, 90, " << convertRadToDeg(phi) << ", 0";
0186 #endif
0187   dd4hep::Position r2((xmid - 0.5 * width1 * cos(phi)), 0, 0);
0188   glog.placeVolume(cablog1, 1, dd4hep::Transform3D(rot2, r2));
0189 #ifdef EDM_ML_DEBUG
0190   edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << cablog1.name() << " number 1 positioned in " << glog.name()
0191                                << " at (" << cms::convert2mm(xmid - 0.5 * width1 * cos(phi))
0192                                << ", 0, 0) with rotation: " << rot2;
0193 #endif
0194   dd4hep::Rotation3D rot3 = cms::makeRotation3D((90._deg - phi), 0, 90._deg, 90._deg, -phi, 0);
0195 #ifdef EDM_ML_DEBUG
0196   edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: Creating a rotation \t" << (90 - convertRadToDeg(phi))
0197                                << ", 0, 90, 90, " << convertRadToDeg(-phi) << ", 0";
0198 #endif
0199   dd4hep::Position r3(-(xmid - 0.5 * width1 * cos(phi)), 0, 0);
0200   glog.placeVolume(cablog1, 2, dd4hep::Transform3D(rot3, r3));
0201 #ifdef EDM_ML_DEBUG
0202   edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << cablog1.name() << " number 2 positioned in " << glog.name()
0203                                << " at (" << cms::convert2mm(xmid - 0.5 * width1 * cos(phi))
0204                                << ", 0, 0) with rotation: " << rot3;
0205 #endif
0206   //Now the cable of type 2
0207   name = idName + "Cable2";
0208   solid = dd4hep::Box(ns.prepend(name), 0.5 * width2, 0.5 * thick, 0.5 * length2);
0209   dd4hep::Volume cablog2(solid.name(), solid, absmatter);
0210 #ifdef EDM_ML_DEBUG
0211   edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << solid.name() << " Box made of " << absMat << " of dimension "
0212                                << cms::convert2mm(0.5 * width2) << ", " << cms::convert2mm(0.5 * thick) << ", "
0213                                << cms::convert2mm(0.5 * length2);
0214 #endif
0215 
0216   glog.placeVolume(cablog2, 1, dd4hep::Position(0.5 * (width2 + gap2), 0, 0));
0217 #ifdef EDM_ML_DEBUG
0218   edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << cablog2.name() << " number 1 positioned in " << glog.name()
0219                                << " at (" << cms::convert2mm(0.5 * (width2 + gap2)) << ", 0, 0) with no rotation";
0220 #endif
0221   glog.placeVolume(cablog2, 2, dd4hep::Position(-0.5 * (width2 + gap2), 0, 0));
0222 #ifdef EDM_ML_DEBUG
0223   edm::LogVerbatim("HCalGeom") << "DDHCalTBCableAlgo: " << cablog2.name() << " number 2 positioned in " << glog.name()
0224                                << " at " << cms::convert2mm(-0.5 * (width2 + gap2)) << ", 0, 0) with no rotation";
0225 
0226   edm::LogVerbatim("HCalGeom") << "<<== End of DDHCalTBCableAlgo construction";
0227 #endif
0228 
0229   return cms::s_executed;
0230 }
0231 
0232 // first argument is the type from the xml file
0233 DECLARE_DDCMS_DETELEMENT(DDCMS_hcal_DDHCalTBCableAlgo, algorithm);