Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-01 02:45:08

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 std;
0007 using namespace dd4hep;
0008 using namespace cms;
0009 using namespace cms_units::operators;
0010 
0011 static long algorithm(Detector& description, cms::DDParsingContext& ctxt, xml_h e) {
0012   PlacedVolume pv;
0013   cms::DDNamespace ns(ctxt, e, true);
0014   DDAlgoArguments args(ctxt, e);
0015   string parentName = args.parentName();
0016 
0017   edm::LogVerbatim("PixelGeom") << "+++ Parsing arguments for Algorithm:" << args.name << " rParent:" << parentName;
0018   string genMat = args.value<string>("GeneralMaterial");
0019   int number = args.value<int>("Ladders");
0020   double layerDz = args.value<double>("LayerDz");
0021   double sensorEdge = args.value<double>("SensorEdge");
0022   double coolDz = args.value<double>("CoolDz");
0023   double coolWidth = args.value<double>("CoolWidth");
0024   double coolSide = args.value<double>("CoolSide");
0025   double coolThick = args.value<double>("CoolThick");
0026   double coolDist = args.value<double>("CoolDist");
0027   string coolMat = args.value<string>("CoolMaterial");
0028   string tubeMat = args.value<string>("CoolTubeMaterial");
0029   edm::LogVerbatim("PixelGeom") << "Parent " << parentName << " NameSpace " << ns.name() << "\n"
0030                                 << "\tLadders " << number << "\tGeneral Material " << genMat << "\tLength " << layerDz
0031                                 << "\tSensorEdge " << sensorEdge << "\tSpecification of Cooling Pieces:\n"
0032                                 << "\tLength " << coolDz << " Width " << coolWidth << " Side " << coolSide
0033                                 << " Thickness of Shell " << coolThick << " Radial distance " << coolDist
0034                                 << " Materials " << coolMat << ", " << tubeMat;
0035   vector<string> ladder = args.value<vector<string> >("LadderName");
0036   vector<double> ladderWidth = args.value<vector<double> >("LadderWidth");
0037   vector<double> ladderThick = args.value<vector<double> >("LadderThick");
0038   edm::LogVerbatim("PixelGeom") << "Full Ladder " << ladder[0] << " width/thickness " << ladderWidth[0] << ", "
0039                                 << ladderThick[0] << "\tHalf Ladder " << ladder[1] << " width/thickness "
0040                                 << ladderWidth[1] << ", " << ladderThick[1];
0041 
0042   const std::string idName = ns.objName(parentName);
0043   double dphi = 2_pi / number;
0044   double d2 = 0.5 * coolWidth;
0045   double d1 = d2 - coolSide * sin(0.5 * dphi);
0046   double x1 = (d1 + d2) / (2. * sin(0.5 * dphi));
0047   double x2 = coolDist * sin(0.5 * dphi);
0048   double rmin = (coolDist - 0.5 * (d1 + d2)) * cos(0.5 * dphi) - 0.5 * ladderThick[0];
0049   double rmax = (coolDist + 0.5 * (d1 + d2)) * cos(0.5 * dphi) + 0.5 * ladderThick[0];
0050   double rmxh = rmax - 0.5 * ladderThick[0] + ladderThick[1];
0051   edm::LogVerbatim("PixelGeom") << "Rmin/Rmax " << rmin << ", " << rmax << " d1/d2 " << d1 << ", " << d2 << " x1/x2 "
0052                                 << x1 << ", " << x2;
0053 
0054   double rtmi = rmin + 0.5 * ladderThick[0] - ladderThick[1];
0055   double rtmx = sqrt(rmxh * rmxh + ladderWidth[1] * ladderWidth[1]);
0056   Solid solid = ns.addSolid(ns.prepend(idName), Tube(rtmi, rtmx, 0.5 * layerDz, 0, 2_pi));
0057   edm::LogVerbatim("PixelGeom") << "IDname " << solid.name() << " Tubs made of " << genMat << " from 0 to "
0058                                 << convertRadToDeg(2_pi) << " with Rin " << rtmi << " Rout " << rtmx << " ZHalf "
0059                                 << 0.5 * layerDz;
0060 
0061   Volume layer = ns.addVolume(Volume(solid.name(), solid, ns.material(genMat)));
0062   double rr = 0.5 * (rmax + rmin);
0063   double dr = 0.5 * (rmax - rmin);
0064   double h1 = 0.5 * coolSide * cos(0.5 * dphi);
0065   std::string name = idName + "CoolTube";
0066   solid = ns.addSolid(ns.prepend(name), Trap(0.5 * coolDz, 0, 0, h1, d2, d1, 0, h1, d2, d1, 0));
0067   edm::LogVerbatim("PixelGeom") << "Solid " << solid.name() << " Trap made of " << tubeMat << " of dimensions "
0068                                 << 0.5 * coolDz << ", 0, 0, " << h1 << ", " << d2 << ", " << d1 << ", 0, " << h1 << ", "
0069                                 << d2 << ", " << d1 << ", 0";
0070 
0071   Volume coolTube = ns.addVolume(Volume(solid.name(), solid, description.material(tubeMat)));
0072   h1 -= coolThick;
0073   d1 -= coolThick;
0074   d2 -= coolThick;
0075   name = idName + "Coolant";
0076   solid = ns.addSolid(ns.prepend(name), Trap(0.5 * coolDz, 0, 0, h1, d2, d1, 0, h1, d2, d1, 0));
0077   edm::LogVerbatim("PixelGeom") << "Solid " << solid.name() << " Trap made of " << coolMat << " of dimensions "
0078                                 << 0.5 * coolDz << ", 0, 0, " << h1 << ", " << d2 << ", " << d1 << ", 0, " << h1 << ", "
0079                                 << d2 << ", " << d1 << ", 0";
0080 
0081   Volume cool = ns.addVolume(Volume(solid.name(), solid, description.material(coolMat)));
0082   pv = coolTube.placeVolume(cool, 1);
0083   edm::LogVerbatim("PixelGeom") << "Cool " << cool.name() << " number 1 positioned in " << coolTube.name()
0084                                 << " at (0,0,0) with no rotation";
0085 
0086   string ladderFull = ladder[0];
0087   string ladderHalf = ladder[1];
0088   int nphi = number / 2, copy = 1, iup = -1;
0089   double phi0 = 90_deg;
0090   Volume ladderHalfVol = ns.volume(ladderHalf);
0091   Volume ladderFullVol = ns.volume(ladderFull);
0092 
0093   for (int i = 0; i < number; i++) {
0094     double phi = phi0 + i * dphi;
0095     double phix, phiy, rrr, xx;
0096     std::string rots;
0097     Position tran;
0098     Rotation3D rot;
0099     if (i == 0 || i == nphi) {
0100       rrr = rr + dr + 0.5 * (ladderThick[1] - ladderThick[0]);
0101       xx = (0.5 * ladderWidth[1] - sensorEdge) * sin(phi);
0102       tran = Position(xx, rrr * sin(phi), 0);
0103       rots = idName + std::to_string(copy);
0104       phix = phi - 90_deg;
0105       phiy = 90_deg + phix;
0106       edm::LogVerbatim("PixelGeom") << "Creating a new "
0107                                     << "rotation: " << rots << "\t90., " << convertRadToDeg(phix) << ", 90.,"
0108                                     << convertRadToDeg(phiy) << ", 0, 0";
0109       rot = makeRotation3D(90_deg, phix, 90_deg, phiy, 0., 0.);
0110 
0111       //cpv.position(ladderHalf, layer, copy, tran, rot);
0112       pv = layer.placeVolume(ladderHalfVol, copy, Transform3D(rot, tran));
0113       if (!pv.isValid()) {
0114       }
0115       edm::LogVerbatim("PixelGeom") << "ladderHalfVol: " << ladderHalfVol.name() << " number " << copy
0116                                     << " positioned in " << layer.name() << " at " << tran << " with " << rot;
0117       copy++;
0118       iup = -1;
0119       rrr = rr - dr - 0.5 * (ladderThick[1] - ladderThick[0]);
0120       tran = Position(-xx, rrr * sin(phi), 0);
0121       rots = idName + std::to_string(copy);
0122       phix = phi + 90_deg;
0123       phiy = 90_deg + phix;
0124       edm::LogVerbatim("PixelGeom") << "Creating a new rotation: " << rots << "\t90., " << convertRadToDeg(phix)
0125                                     << ", 90.," << convertRadToDeg(phiy) << ", 0, 0";
0126       rot = makeRotation3D(90_deg, phix, 90_deg, phiy, 0., 0.);
0127       //cpv.position(ladderHalf, layer, copy, tran, rot);
0128       pv = layer.placeVolume(ladderHalfVol, copy, Transform3D(rot, tran));
0129       if (!pv.isValid()) {
0130       }
0131       edm::LogVerbatim("PixelGeom") << "ladderHalfVol: " << ladderHalfVol.name() << " number " << copy
0132                                     << " positioned in " << layer.name() << " at " << tran << " with " << rot;
0133       copy++;
0134     } else {
0135       iup = -iup;
0136       rrr = rr + iup * dr;
0137       tran = Position(rrr * cos(phi), rrr * sin(phi), 0);
0138       rots = idName + std::to_string(copy);
0139       if (iup > 0)
0140         phix = phi - 90_deg;
0141       else
0142         phix = phi + 90_deg;
0143       phiy = phix + 90._deg;
0144       edm::LogVerbatim("PixelGeom") << "DDPixBarLayerAlgo test: Creating a new "
0145                                     << "rotation: " << rots << "\t90., " << convertRadToDeg(phix) << ", 90.,"
0146                                     << convertRadToDeg(phiy) << ", 0, 0";
0147       rot = makeRotation3D(90_deg, phix, 90_deg, phiy, 0., 0.);
0148 
0149       //cpv.position(ladderFull, layer, copy, tran, rot);
0150       pv = layer.placeVolume(ladderFullVol, copy, Transform3D(rot, tran));
0151       if (!pv.isValid()) {
0152       }
0153       edm::LogVerbatim("PixelGeom") << "test: " << ladderFullVol.name() << " number " << copy << " positioned in "
0154                                     << layer.name() << " at " << tran << " with " << rot;
0155       copy++;
0156     }
0157     rrr = coolDist * cos(0.5 * dphi);
0158     tran = Position(rrr * cos(phi) - x2 * sin(phi), rrr * sin(phi) + x2 * cos(phi), 0);
0159     rots = idName + std::to_string(i + 100);
0160     phix = phi + 0.5 * dphi;
0161     if (iup > 0)
0162       phix += 180_deg;
0163     phiy = phix + 90._deg;
0164     edm::LogVerbatim("PixelGeom") << "Creating a new rotation: " << rots << "\t90., " << convertRadToDeg(phix)
0165                                   << ", 90.," << convertRadToDeg(phiy) << ", 0, 0";
0166 
0167     rot = makeRotation3D(90_deg, phix, 90_deg, phiy, 0., 0.);
0168     pv = layer.placeVolume(coolTube, i + 1, Transform3D(rot, tran));
0169     if (!pv.isValid()) {
0170     }
0171     edm::LogVerbatim("PixelGeom") << "coolTube: " << coolTube.name() << " number " << i + 1 << " positioned in "
0172                                   << layer.name() << " at " << tran << " with " << rot;
0173   }
0174   edm::LogVerbatim("PixelGeom") << "Layer: " << layer.name();
0175   return 1;
0176 }
0177 
0178 // first argument is the type from the xml file
0179 DECLARE_DDCMS_DETELEMENT(DDCMS_track_DDPixBarLayerAlgo, algorithm)