Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:49:03

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // File: DDPixBarLayerAlgo.cc
0003 // Description: Make one layer of pixel barrel detector
0004 ///////////////////////////////////////////////////////////////////////////////
0005 
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0008 #include "DetectorDescription/Core/interface/DDSolid.h"
0009 #include "DetectorDescription/Core/interface/DDMaterial.h"
0010 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
0011 #include "DetectorDescription/Core/interface/DDSplit.h"
0012 #include "DetectorDescription/Core/interface/DDTypes.h"
0013 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0014 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0015 #include "CLHEP/Units/GlobalPhysicalConstants.h"
0016 #include "CLHEP/Units/GlobalSystemOfUnits.h"
0017 
0018 #include <cmath>
0019 #include <algorithm>
0020 #include <map>
0021 #include <string>
0022 #include <vector>
0023 
0024 using namespace std;
0025 
0026 class DDPixBarLayerAlgo : public DDAlgorithm {
0027 public:
0028   //Constructor and Destructor
0029   DDPixBarLayerAlgo();
0030   ~DDPixBarLayerAlgo() override;
0031 
0032   void initialize(const DDNumericArguments& nArgs,
0033                   const DDVectorArguments& vArgs,
0034                   const DDMapArguments& mArgs,
0035                   const DDStringArguments& sArgs,
0036                   const DDStringVectorArguments& vsArgs) override;
0037 
0038   void execute(DDCompactView& cpv) override;
0039 
0040 private:
0041   string idNameSpace;          //Namespace of this and ALL sub-parts
0042   string genMat;               //Name of general material
0043   int number;                  //Number of ladders in phi
0044   double layerDz;              //Length of the layer
0045   double sensorEdge;           //Distance from edge for a half sensor
0046   double coolDz;               //Length of the cooling piece
0047   double coolWidth;            //Width
0048   double coolSide;             //Side length
0049   double coolThick;            //Thickness of the shell
0050   double coolDist;             //Radial distance between centres of 2
0051   string coolMat;              //Cooling fluid material name
0052   string tubeMat;              //Cooling piece material name
0053   vector<string> ladder;       //Names     of ladders
0054   vector<double> ladderWidth;  //Widths         ...
0055   vector<double> ladderThick;  //Thickness      ...
0056 };
0057 
0058 DDPixBarLayerAlgo::DDPixBarLayerAlgo() { LogDebug("PixelGeom") << "DDPixBarLayerAlgo info: Creating an instance"; }
0059 
0060 DDPixBarLayerAlgo::~DDPixBarLayerAlgo() {}
0061 
0062 void DDPixBarLayerAlgo::initialize(const DDNumericArguments& nArgs,
0063                                    const DDVectorArguments& vArgs,
0064                                    const DDMapArguments&,
0065                                    const DDStringArguments& sArgs,
0066                                    const DDStringVectorArguments& vsArgs) {
0067   idNameSpace = DDCurrentNamespace::ns();
0068   DDName parentName = parent().name();
0069 
0070   genMat = sArgs["GeneralMaterial"];
0071   number = int(nArgs["Ladders"]);
0072   layerDz = nArgs["LayerDz"];
0073   sensorEdge = nArgs["SensorEdge"];
0074   coolDz = nArgs["CoolDz"];
0075   coolWidth = nArgs["CoolWidth"];
0076   coolSide = nArgs["CoolSide"];
0077   coolThick = nArgs["CoolThick"];
0078   coolDist = nArgs["CoolDist"];
0079   coolMat = sArgs["CoolMaterial"];
0080   tubeMat = sArgs["CoolTubeMaterial"];
0081 
0082   LogDebug("PixelGeom") << "DDPixBarLayerAlgo debug: Parent " << parentName << " NameSpace " << idNameSpace << "\n"
0083                         << "\tLadders " << number << "\tGeneral Material " << genMat << "\tLength " << layerDz
0084                         << "\tSensorEdge " << sensorEdge << "\tSpecification of Cooling Pieces:\n"
0085                         << "\tLength " << coolDz << " Width " << coolWidth << " Side " << coolSide
0086                         << " Thickness of Shell " << coolThick << " Radial distance " << coolDist << " Materials "
0087                         << coolMat << ", " << tubeMat;
0088 
0089   ladder = vsArgs["LadderName"];
0090   ladderWidth = vArgs["LadderWidth"];
0091   ladderThick = vArgs["LadderThick"];
0092 
0093   LogDebug("PixelGeom") << "DDPixBarLayerAlgo debug: Full Ladder " << ladder[0] << " width/thickness " << ladderWidth[0]
0094                         << ", " << ladderThick[0] << "\tHalf Ladder " << ladder[1] << " width/thickness "
0095                         << ladderWidth[1] << ", " << ladderThick[1];
0096 }
0097 
0098 void DDPixBarLayerAlgo::execute(DDCompactView& cpv) {
0099   DDName mother = parent().name();
0100   const string& idName = mother.name();
0101 
0102   double dphi = CLHEP::twopi / number;
0103   double d2 = 0.5 * coolWidth;
0104   double d1 = d2 - coolSide * sin(0.5 * dphi);
0105   double x1 = (d1 + d2) / (2. * sin(0.5 * dphi));
0106   double x2 = coolDist * sin(0.5 * dphi);
0107   double rmin = (coolDist - 0.5 * (d1 + d2)) * cos(0.5 * dphi) - 0.5 * ladderThick[0];
0108   double rmax = (coolDist + 0.5 * (d1 + d2)) * cos(0.5 * dphi) + 0.5 * ladderThick[0];
0109   double rmxh = rmax - 0.5 * ladderThick[0] + ladderThick[1];
0110   LogDebug("PixelGeom") << "DDPixBarLayerAlgo test: Rmin/Rmax " << rmin << ", " << rmax << " d1/d2 " << d1 << ", " << d2
0111                         << " x1/x2 " << x1 << ", " << x2;
0112 
0113   double rtmi = rmin + 0.5 * ladderThick[0] - ladderThick[1];
0114   double rtmx = sqrt(rmxh * rmxh + ladderWidth[1] * ladderWidth[1]);
0115   DDSolid solid = DDSolidFactory::tubs(DDName(idName, idNameSpace), 0.5 * layerDz, rtmi, rtmx, 0, CLHEP::twopi);
0116   LogDebug("PixelGeom") << "DDPixBarLayerAlgo test: " << DDName(idName, idNameSpace) << " Tubs made of " << genMat
0117                         << " from 0 to " << CLHEP::twopi / CLHEP::deg << " with Rin " << rtmi << " Rout " << rtmx
0118                         << " ZHalf " << 0.5 * layerDz;
0119   DDName matname(DDSplit(genMat).first, DDSplit(genMat).second);
0120   DDMaterial matter(matname);
0121   DDLogicalPart layer(solid.ddname(), matter, solid);
0122 
0123   double rr = 0.5 * (rmax + rmin);
0124   double dr = 0.5 * (rmax - rmin);
0125   double h1 = 0.5 * coolSide * cos(0.5 * dphi);
0126   string name = idName + "CoolTube";
0127   solid = DDSolidFactory::trap(DDName(name, idNameSpace), 0.5 * coolDz, 0, 0, h1, d2, d1, 0, h1, d2, d1, 0);
0128   LogDebug("PixelGeom") << "DDPixBarLayerAlgo test: " << solid.name() << " Trap made of " << tubeMat
0129                         << " of dimensions " << 0.5 * coolDz << ", 0, 0, " << h1 << ", " << d2 << ", " << d1 << ", 0, "
0130                         << h1 << ", " << d2 << ", " << d1 << ", 0";
0131   matter = DDMaterial(DDName(DDSplit(tubeMat).first, DDSplit(tubeMat).second));
0132   DDLogicalPart coolTube(solid.ddname(), matter, solid);
0133 
0134   name = idName + "Coolant";
0135   h1 -= coolThick;
0136   d1 -= coolThick;
0137   d2 -= coolThick;
0138   solid = DDSolidFactory::trap(DDName(name, idNameSpace), 0.5 * coolDz, 0, 0, h1, d2, d1, 0, h1, d2, d1, 0);
0139   LogDebug("PixelGeom") << "DDPixBarLayerAlgo test: " << solid.name() << " Trap made of " << coolMat
0140                         << " of dimensions " << 0.5 * coolDz << ", 0, 0, " << h1 << ", " << d2 << ", " << d1 << ", 0, "
0141                         << h1 << ", " << d2 << ", " << d1 << ", 0";
0142   matter = DDMaterial(DDName(DDSplit(coolMat).first, DDSplit(coolMat).second));
0143   DDLogicalPart cool(solid.ddname(), matter, solid);
0144   cpv.position(cool, coolTube, 1, DDTranslation(0.0, 0.0, 0.0), DDRotation());
0145   LogDebug("PixelGeom") << "DDPixBarLayerAlgo test: " << cool.name() << " number 1 positioned in " << coolTube.name()
0146                         << " at (0,0,0) with no rotation";
0147 
0148   DDName ladderFull(DDSplit(ladder[0]).first, DDSplit(ladder[0]).second);
0149   DDName ladderHalf(DDSplit(ladder[1]).first, DDSplit(ladder[1]).second);
0150 
0151   int nphi = number / 2, copy = 1, iup = -1;
0152   double phi0 = 90 * CLHEP::deg;
0153   for (int i = 0; i < number; i++) {
0154     double phi = phi0 + i * dphi;
0155     double phix, phiy, rrr, xx;
0156     string rots;
0157     DDTranslation tran;
0158     DDRotation rot;
0159     if (i == 0 || i == nphi) {
0160       rrr = rr + dr + 0.5 * (ladderThick[1] - ladderThick[0]);
0161       xx = (0.5 * ladderWidth[1] - sensorEdge) * sin(phi);
0162       tran = DDTranslation(xx, rrr * sin(phi), 0);
0163       rots = idName + to_string(copy);
0164       phix = phi - 90 * CLHEP::deg;
0165       phiy = 90 * CLHEP::deg + phix;
0166       LogDebug("PixelGeom") << "DDPixBarLayerAlgo test: Creating a new "
0167                             << "rotation: " << rots << "\t90., " << phix / CLHEP::deg << ", 90.," << phiy / CLHEP::deg
0168                             << ", 0, 0";
0169       rot = DDrot(DDName(rots, idNameSpace), 90 * CLHEP::deg, phix, 90 * CLHEP::deg, phiy, 0., 0.);
0170       cpv.position(ladderHalf, layer, copy, tran, rot);
0171       LogDebug("PixelGeom") << "DDPixBarLayerAlgo test: " << ladderHalf << " number " << copy << " positioned in "
0172                             << layer.name() << " at " << tran << " with " << rot;
0173       copy++;
0174       iup = -1;
0175       rrr = rr - dr - 0.5 * (ladderThick[1] - ladderThick[0]);
0176       tran = DDTranslation(-xx, rrr * sin(phi), 0);
0177       rots = idName + to_string(copy);
0178       phix = phi + 90 * CLHEP::deg;
0179       phiy = 90 * CLHEP::deg + phix;
0180       LogDebug("PixelGeom") << "DDPixBarLayerAlgo test: Creating a new "
0181                             << "rotation: " << rots << "\t90., " << phix / CLHEP::deg << ", 90.," << phiy / CLHEP::deg
0182                             << ", 0, 0";
0183       rot = DDrot(DDName(rots, idNameSpace), 90 * CLHEP::deg, phix, 90 * CLHEP::deg, phiy, 0., 0.);
0184       cpv.position(ladderHalf, layer, copy, tran, rot);
0185       LogDebug("PixelGeom") << "DDPixBarLayerAlgo test: " << ladderHalf << " number " << copy << " positioned in "
0186                             << layer.name() << " at " << tran << " with " << rot;
0187       copy++;
0188     } else {
0189       iup = -iup;
0190       rrr = rr + iup * dr;
0191       tran = DDTranslation(rrr * cos(phi), rrr * sin(phi), 0);
0192       rots = idName + to_string(copy);
0193       if (iup > 0)
0194         phix = phi - 90 * CLHEP::deg;
0195       else
0196         phix = phi + 90 * CLHEP::deg;
0197       phiy = phix + 90. * CLHEP::deg;
0198       LogDebug("PixelGeom") << "DDPixBarLayerAlgo test: Creating a new "
0199                             << "rotation: " << rots << "\t90., " << phix / CLHEP::deg << ", 90.," << phiy / CLHEP::deg
0200                             << ", 0, 0";
0201       rot = DDrot(DDName(rots, idNameSpace), 90 * CLHEP::deg, phix, 90 * CLHEP::deg, phiy, 0., 0.);
0202       cpv.position(ladderFull, layer, copy, tran, rot);
0203       LogDebug("PixelGeom") << "DDPixBarLayerAlgo test: " << ladderFull << " number " << copy << " positioned in "
0204                             << layer.name() << " at " << tran << " with " << rot;
0205       copy++;
0206     }
0207     rrr = coolDist * cos(0.5 * dphi);
0208     tran = DDTranslation(rrr * cos(phi) - x2 * sin(phi), rrr * sin(phi) + x2 * cos(phi), 0);
0209     rots = idName + to_string(i + 100);
0210     phix = phi + 0.5 * dphi;
0211     if (iup > 0)
0212       phix += 180 * CLHEP::deg;
0213     phiy = phix + 90. * CLHEP::deg;
0214     LogDebug("PixelGeom") << "DDPixBarLayerAlgo test: Creating a new "
0215                           << "rotation: " << rots << "\t90., " << phix / CLHEP::deg << ", 90.," << phiy / CLHEP::deg
0216                           << ", 0, 0";
0217     rot = DDrot(DDName(rots, idNameSpace), 90 * CLHEP::deg, phix, 90 * CLHEP::deg, phiy, 0., 0.);
0218     cpv.position(coolTube, layer, i + 1, tran, rot);
0219     LogDebug("PixelGeom") << "DDPixBarLayerAlgo test: " << coolTube.name() << " number " << i + 1 << " positioned in "
0220                           << layer.name() << " at " << tran << " with " << rot;
0221   }
0222 }
0223 
0224 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDPixBarLayerAlgo, "track:DDPixBarLayerAlgo");