Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:08:11

0001 /////////////////////////////////////////////////////////////////////////////
0002 // File: DDHCalBarrelAlgo.cc
0003 //   adapted from CCal(G4)HcalBarrel.cc
0004 // Description: Geometry factory class for Hcal Barrel
0005 ///////////////////////////////////////////////////////////////////////////////
0006 
0007 #include <cmath>
0008 #include <algorithm>
0009 #include <map>
0010 #include <string>
0011 #include <vector>
0012 
0013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0014 #include "FWCore/PluginManager/interface/PluginFactory.h"
0015 #include "DataFormats/Math/interface/angle_units.h"
0016 #include "DetectorDescription/Core/interface/DDutils.h"
0017 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0018 #include "DetectorDescription/Core/interface/DDSolid.h"
0019 #include "DetectorDescription/Core/interface/DDMaterial.h"
0020 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
0021 #include "DetectorDescription/Core/interface/DDSplit.h"
0022 #include "DetectorDescription/Core/interface/DDTypes.h"
0023 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0024 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0025 
0026 //#define EDM_ML_DEBUG
0027 using namespace angle_units::operators;
0028 
0029 class DDHCalBarrelAlgo : public DDAlgorithm {
0030 public:
0031   //Constructor and Destructor
0032   DDHCalBarrelAlgo();
0033   ~DDHCalBarrelAlgo() override;
0034 
0035   //Get Methods
0036   const std::string& getGenMaterial() const { return genMaterial; }
0037   int getNsectors() const { return nsectors; }
0038   int getNsectortot() const { return nsectortot; }
0039   int getNhalf() const { return nhalf; }
0040   double getRin() const { return rin; }
0041   double getRout() const { return rout; }
0042   int getRzones() const { return rzones; }
0043   double getTanTheta(unsigned int i) const { return ttheta[i]; }
0044   double getTheta(unsigned int i) const { return theta[i]; }
0045   double getRmax(unsigned int i) const { return rmax[i]; }
0046   double getZoff(unsigned int i) const { return zoff[i]; }
0047 
0048   int getNLayers() const { return nLayers; }
0049   int getLayerId(unsigned i) const { return layerId[i]; }
0050   const std::string& getLayerLabel(unsigned i) const { return layerLabel[i]; }
0051   const std::string& getLayerMaterial(unsigned i) const { return layerMat[i]; }
0052   double getLayerWidth(unsigned i) const { return layerWidth[i]; }
0053   double getLayerD1(unsigned i) const { return layerD1[i]; }
0054   double getLayerD2(unsigned i) const { return layerD2[i]; }
0055   double getLayerAlpha(unsigned i) const { return layerAlpha[i]; }
0056   double getLayerT1(unsigned i) const { return layerT1[i]; }
0057   double getLayerT2(unsigned i) const { return layerT2[i]; }
0058   int getLayerAbsorb(unsigned int i) const { return layerAbsorb[i]; }
0059   double getLayerGap(unsigned int i) const { return layerGap[i]; }
0060 
0061   const std::string& getSideMat(unsigned int i) const { return sideMat[i]; }
0062   double getSideD(unsigned int i) const { return sideD[i]; }
0063   double getSideT(unsigned int i) const { return sideT[i]; }
0064   int getSideAbsorber() const { return nSideAbs; }
0065   const std::string& getSideAbsName(unsigned int i) const { return sideAbsName[i]; }
0066   const std::string& getSideAbsMat(unsigned int i) const { return sideAbsMat[i]; }
0067   double getSideAbsW(unsigned int i) const { return sideAbsW[i]; }
0068 
0069   int getAbsorberN() const { return nAbsorber; }
0070   const std::string& getAbsorbName(unsigned int i) const { return absorbName[i]; }
0071   const std::string& getAbsorbMat(unsigned int i) const { return absorbMat[i]; }
0072   double getAbsorbD(unsigned int i) const { return absorbD[i]; }
0073   double getAbsorbT(unsigned int i) const { return absorbT[i]; }
0074   const std::string& getMiddleMat() const { return middleMat; }
0075   double getMiddleD() const { return middleD; }
0076   double getMiddleW() const { return middleW; }
0077   int getMidAbsorber() const { return nMidAbs; }
0078   const std::string& getMidAbsName(unsigned int i) const { return midName[i]; }
0079   const std::string& getMidAbsMat(unsigned int i) const { return midMat[i]; }
0080   double getMidAbsW(unsigned int i) const { return midW[i]; }
0081   double getMidAbsT(unsigned int i) const { return midT[i]; }
0082 
0083   const std::string& getDetMat() const { return detMat; }
0084   const std::string& getDetMatPl() const { return detMatPl; }
0085   const std::string& getDetMatSc() const { return detMatSc; }
0086   int getDetType(unsigned int i) const { return detType[i]; }
0087   double getDetdP1(unsigned int i) const { return detdP1[i]; }
0088   double getDetdP2(unsigned int i) const { return detdP2[i]; }
0089   double getDetT11(unsigned int i) const { return detT11[i]; }
0090   double getDetT12(unsigned int i) const { return detT12[i]; }
0091   double getDetTsc(unsigned int i) const { return detTsc[i]; }
0092   double getDetT21(unsigned int i) const { return detT21[i]; }
0093   double getDetT22(unsigned int i) const { return detT22[i]; }
0094   double getDetWidth1(unsigned int i) const { return detWidth1[i]; }
0095   double getDetWidth2(unsigned int i) const { return detWidth2[i]; }
0096   int getDetPosY(unsigned int i) const { return detPosY[i]; }
0097 
0098   void initialize(const DDNumericArguments& nArgs,
0099                   const DDVectorArguments& vArgs,
0100                   const DDMapArguments& mArgs,
0101                   const DDStringArguments& sArgs,
0102                   const DDStringVectorArguments& vsArgs) override;
0103 
0104   void execute(DDCompactView& cpv) override;
0105 
0106 private:
0107   void constructGeneralVolume(DDCompactView& cpv);
0108   void constructInsideSector(const DDLogicalPart& sector, DDCompactView& cpv);
0109   void constructInsideLayers(const DDLogicalPart& laylog,
0110                              const std::string& name,
0111                              int id,
0112                              int nAbs,
0113                              double rin,
0114                              double d1,
0115                              double alpha1,
0116                              double d2,
0117                              double alpha2,
0118                              double t1,
0119                              double t2,
0120                              DDCompactView& cpv);
0121   DDLogicalPart constructSideLayer(
0122       const DDLogicalPart& laylog, const std::string& nm, int nAbs, double rin, double alpha, DDCompactView& cpv);
0123   DDLogicalPart constructMidLayer(
0124       const DDLogicalPart& laylog, const std::string& nm, double rin, double alpha, DDCompactView& cpv);
0125   void constructInsideDetectors(const DDLogicalPart& detector,
0126                                 const std::string& name,
0127                                 int id,
0128                                 double dx,
0129                                 double dy,
0130                                 double dz,
0131                                 int type,
0132                                 DDCompactView& cpv);
0133 
0134   //General Volume
0135   //      <----- Zmax ------>
0136   // Rout ************************-------
0137   //      *                      *Rstep2|        Theta angle w.r.t. vertical
0138   //      *                      *---------------
0139   //      *                     *               |
0140   //      *                    *Theta[i]        Rmax[i]
0141   //      *                   *---------------  |
0142   //                        *Theta[0] Rmax[0]|  |
0143   // Rin  *****************----------------------
0144 
0145   std::string genMaterial;     //General material
0146   int nsectors;                //Number of potenital straight edges
0147   int nsectortot;              //Number of straight edges (actual)
0148   int nhalf;                   //Number of half modules
0149   double rin, rout;            //See picture
0150   int rzones;                  //  ....
0151   std::vector<double> theta;   //  .... (in degrees)
0152   std::vector<double> rmax;    //  ....
0153   std::vector<double> zoff;    //  ....
0154   std::vector<double> ttheta;  //tan(theta)
0155   std::string rotHalf;         //Rotation matrix of the second half
0156   std::string rotns;           //Name space for Rotation matrices
0157 
0158   //Upper layers inside general volume
0159   //     <---- Zout ---->
0160   //  |  ****************     |
0161   //  |  *              *     Wstep
0162   //  W  *              ***** |
0163   //  |  *                  *
0164   //  |  ********************
0165   //     <------ Zin ------->
0166   // Middle layers inside general volume
0167   //     <------ Zout ------>         Zout = Full sector Z at position
0168   //  |  ********************         Zin  = Full sector Z at position
0169   //  |  *                 *
0170   //  W  *                * Angle = Theta sector
0171   //  |  *               *  )
0172   //  |  ****************--------
0173   //     <------ Zin ------->
0174 
0175   // Lower layers
0176   //     <------ Zout ------>         Zin(i)=Zout(i-1)
0177   //  |  ********************         Zout(i)=Zin(i)+W(i)/tan(Theta(i))
0178   //  |  *                 *
0179   //  W  *                *  Theta
0180   //  |  *               *
0181   //  |  ****************--------
0182   //     <--- Zin ------>
0183 
0184   int nLayers;                          //Number of layers
0185   std::vector<int> layerId;             //Number identification
0186   std::vector<std::string> layerLabel;  //String identification
0187   std::vector<std::string> layerMat;    //Material
0188   std::vector<double> layerWidth;       //W in picture
0189   std::vector<double> layerD1;          //d1 in front picture
0190   std::vector<double> layerD2;          //d2 in front picture
0191   std::vector<double> layerAlpha;       //Angular width of the middle tiles
0192   std::vector<double> layerT1;          //t in front picture (side)
0193   std::vector<double> layerT2;          //t in front picture (front)
0194   std::vector<int> layerAbsorb;         //Absorber flag
0195   std::vector<double> layerGap;         //Gap at the edge
0196 
0197   int nAbsorber;                        //Number of absorber layers in middle
0198   std::vector<std::string> absorbName;  //Absorber name
0199   std::vector<std::string> absorbMat;   //Absorber material
0200   std::vector<double> absorbD;          //Distance from the bottom surface
0201   std::vector<double> absorbT;          //Thickness
0202   std::string middleMat;                //Material of the detector layer
0203   double middleD;                       //Distance from the bottom surface
0204   double middleW;                       //Half width
0205   int nMidAbs;                          //Number of absorbers in front part
0206   std::vector<std::string> midName;     //Absorber names in the front part
0207   std::vector<std::string> midMat;      //Absorber material
0208   std::vector<double> midW;             //Half width
0209   std::vector<double> midT;             //Thickness
0210 
0211   std::vector<std::string> sideMat;      //Material for special side layers
0212   std::vector<double> sideD;             //Depth from bottom surface
0213   std::vector<double> sideT;             //Thickness
0214   int nSideAbs;                          //Number of absorbers in special side
0215   std::vector<std::string> sideAbsName;  //Absorber name
0216   std::vector<std::string> sideAbsMat;   //Absorber material
0217   std::vector<double> sideAbsW;          //Half width
0218 
0219   // Detectors. Each volume inside the layer has the shape:
0220   //
0221   // ******************************* |
0222   // *\\\\\\\Plastic\\\\\\\\\\\\\\\* T2
0223   // ******************************* |
0224   // *////Scintillator/////////////* Tsc
0225   // ******************************* |
0226   // *\\\\\\\Plastic\\\\\\\\\\\\\\\* T1
0227   // ******************************* |   |
0228   // *         Air                 *     dP1
0229   // *******************************     |
0230   //
0231   std::string detMat;    //fill material
0232   std::string detRot;    //Rotation matrix for the 2nd
0233   std::string detMatPl;  //Plastic material
0234   std::string detMatSc;  //Scintillator material
0235   std::vector<int> detType;
0236   std::vector<double> detdP1;     //Air gap (side)
0237   std::vector<double> detdP2;     //Air gap (centre)
0238   std::vector<double> detT11;     //Back plastic thickness (side)
0239   std::vector<double> detT12;     //Back plastic thickness (centre)
0240   std::vector<double> detTsc;     //Scintillator
0241   std::vector<double> detT21;     //Front plastic thickness (side)
0242   std::vector<double> detT22;     //Front plastic thickness (centre)
0243   std::vector<double> detWidth1;  //Width of phi(1,4) megatiles
0244   std::vector<double> detWidth2;  //Width of phi(2,3) megatiles
0245   std::vector<int> detPosY;       //Positioning of phi(1,4) tiles - 0 centre
0246 
0247   std::string idName;       //Name of the "parent" volume.
0248   std::string idNameSpace;  //Namespace of this and ALL sub-parts
0249   int idOffset;             // Geant4 ID's...    = 3000;
0250 };
0251 
0252 DDHCalBarrelAlgo::DDHCalBarrelAlgo()
0253     : theta(0),
0254       rmax(0),
0255       zoff(0),
0256       ttheta(0),
0257       layerId(0),
0258       layerLabel(0),
0259       layerMat(0),
0260       layerWidth(0),
0261       layerD1(0),
0262       layerD2(0),
0263       layerAlpha(0),
0264       layerT1(0),
0265       layerT2(0),
0266       layerAbsorb(0),
0267       layerGap(0),
0268       absorbName(0),
0269       absorbMat(0),
0270       absorbD(0),
0271       absorbT(0),
0272       midName(0),
0273       midMat(0),
0274       midW(0),
0275       midT(0),
0276       sideMat(0),
0277       sideD(0),
0278       sideT(0),
0279       sideAbsName(0),
0280       sideAbsMat(0),
0281       sideAbsW(0),
0282       detType(0),
0283       detdP1(0),
0284       detdP2(0),
0285       detT11(0),
0286       detT12(0),
0287       detTsc(0),
0288       detT21(0),
0289       detT22(0),
0290       detWidth1(0),
0291       detWidth2(0),
0292       detPosY(0) {
0293 #ifdef EDM_ML_DEBUG
0294   edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: Creating an instance";
0295 #endif
0296 }
0297 
0298 DDHCalBarrelAlgo::~DDHCalBarrelAlgo() {}
0299 
0300 void DDHCalBarrelAlgo::initialize(const DDNumericArguments& nArgs,
0301                                   const DDVectorArguments& vArgs,
0302                                   const DDMapArguments&,
0303                                   const DDStringArguments& sArgs,
0304                                   const DDStringVectorArguments& vsArgs) {
0305   genMaterial = sArgs["MaterialName"];
0306   nsectors = int(nArgs["NSector"]);
0307   nsectortot = int(nArgs["NSectorTot"]);
0308   nhalf = int(nArgs["NHalf"]);
0309   rin = nArgs["RIn"];
0310   rout = nArgs["ROut"];
0311   rzones = int(nArgs["RZones"]);
0312   rotHalf = sArgs["RotHalf"];
0313   rotns = sArgs["RotNameSpace"];
0314 
0315   theta = vArgs["Theta"];
0316   rmax = vArgs["RMax"];
0317   zoff = vArgs["ZOff"];
0318   for (int i = 0; i < rzones; i++) {
0319     ttheta.emplace_back(tan(theta[i]));  //*deg already done in XML
0320   }
0321   if (rzones > 3)
0322     rmax[2] = (zoff[3] - zoff[2]) / ttheta[2];
0323 
0324 #ifdef EDM_ML_DEBUG
0325   edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: General material " << genMaterial << "\tSectors " << nsectors
0326                                << ", " << nsectortot << "\tHalves " << nhalf << "\tRotation matrix " << rotns << ":"
0327                                << rotHalf << "\n\t\t" << rin << "\t" << rout << "\t" << rzones;
0328   for (int i = 0; i < rzones; i++)
0329     edm::LogVerbatim("HCalGeom") << "\tTheta[" << i << "] = " << theta[i] << "\trmax[" << i << "] = " << rmax[i]
0330                                  << "\tzoff[" << i << "] = " << zoff[i];
0331 #endif
0332   ///////////////////////////////////////////////////////////////
0333   //Layers
0334   nLayers = int(nArgs["NLayers"]);
0335 #ifdef EDM_ML_DEBUG
0336   edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: Layer\t" << nLayers;
0337 #endif
0338   layerId = dbl_to_int(vArgs["Id"]);
0339   layerLabel = vsArgs["LayerLabel"];
0340   layerMat = vsArgs["LayerMat"];
0341   layerWidth = vArgs["LayerWidth"];
0342   layerD1 = vArgs["D1"];
0343   layerD2 = vArgs["D2"];
0344   layerAlpha = vArgs["Alpha2"];
0345   layerT1 = vArgs["T1"];
0346   layerT2 = vArgs["T2"];
0347   layerAbsorb = dbl_to_int(vArgs["AbsL"]);
0348   layerGap = vArgs["Gap"];
0349 #ifdef EDM_ML_DEBUG
0350   for (int i = 0; i < nLayers; i++)
0351     edm::LogVerbatim("HCalGeom") << layerLabel[i] << "\t" << layerId[i] << "\t" << layerMat[i] << "\t" << layerWidth[i]
0352                                  << "\t" << layerD1[i] << "\t" << layerD2[i] << "\t" << layerAlpha[i] << "\t"
0353                                  << layerT1[i] << "\t" << layerT2[i] << "\t" << layerAbsorb[i] << "\t" << layerGap[i];
0354 #endif
0355 
0356   ///////////////////////////////////////////////////////////////
0357   //Absorber Layers and middle part
0358   absorbName = vsArgs["AbsorbName"];
0359   absorbMat = vsArgs["AbsorbMat"];
0360   absorbD = vArgs["AbsorbD"];
0361   absorbT = vArgs["AbsorbT"];
0362   nAbsorber = absorbName.size();
0363 #ifdef EDM_ML_DEBUG
0364   for (int i = 0; i < nAbsorber; i++)
0365     edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << absorbName[i] << " Material " << absorbMat[i] << " d "
0366                                  << absorbD[i] << " t " << absorbT[i];
0367 #endif
0368   middleMat = sArgs["MiddleMat"];
0369   middleD = nArgs["MiddleD"];
0370   middleW = nArgs["MiddleW"];
0371 #ifdef EDM_ML_DEBUG
0372   edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: Middle material " << middleMat << " d " << middleD << " w "
0373                                << middleW;
0374 #endif
0375   midName = vsArgs["MidAbsName"];
0376   midMat = vsArgs["MidAbsMat"];
0377   midW = vArgs["MidAbsW"];
0378   midT = vArgs["MidAbsT"];
0379   nMidAbs = midName.size();
0380 #ifdef EDM_ML_DEBUG
0381   for (int i = 0; i < nMidAbs; i++)
0382     edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << midName[i] << " Material " << midMat[i] << " W " << midW[i]
0383                                  << " T " << midT[i];
0384 #endif
0385 
0386   //Absorber layers in the side part
0387   sideMat = vsArgs["SideMat"];
0388   sideD = vArgs["SideD"];
0389   sideT = vArgs["SideT"];
0390 #ifdef EDM_ML_DEBUG
0391   for (unsigned int i = 0; i < sideMat.size(); i++)
0392     edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: Side material " << sideMat[i] << " d " << sideD[i] << " t "
0393                                  << sideT[i];
0394 #endif
0395   sideAbsName = vsArgs["SideAbsName"];
0396   sideAbsMat = vsArgs["SideAbsMat"];
0397   sideAbsW = vArgs["SideAbsW"];
0398   nSideAbs = sideAbsName.size();
0399 #ifdef EDM_ML_DEBUG
0400   for (int i = 0; i < nSideAbs; i++)
0401     edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << sideAbsName[i] << " Material " << sideAbsMat[i] << " W "
0402                                  << sideAbsW[i];
0403 #endif
0404 
0405   ///////////////////////////////////////////////////////////////
0406   // Detectors
0407 
0408   detMat = sArgs["DetMat"];
0409   detRot = sArgs["DetRot"];
0410   detMatPl = sArgs["DetMatPl"];
0411   detMatSc = sArgs["DetMatSc"];
0412 #ifdef EDM_ML_DEBUG
0413   edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: Detector (" << nLayers << ") Rotation matrix " << rotns << ":"
0414                                << detRot << "\n\t\t" << detMat << "\t" << detMatPl << "\t" << detMatSc;
0415 #endif
0416   detType = dbl_to_int(vArgs["DetType"]);
0417   detdP1 = vArgs["DetdP1"];
0418   detdP2 = vArgs["DetdP2"];
0419   detT11 = vArgs["DetT11"];
0420   detT12 = vArgs["DetT12"];
0421   detTsc = vArgs["DetTsc"];
0422   detT21 = vArgs["DetT21"];
0423   detT22 = vArgs["DetT22"];
0424   detWidth1 = vArgs["DetWidth1"];
0425   detWidth2 = vArgs["DetWidth2"];
0426   detPosY = dbl_to_int(vArgs["DetPosY"]);
0427 #ifdef EDM_ML_DEBUG
0428   for (int i = 0; i < nLayers; i++)
0429     edm::LogVerbatim("HCalGeom") << i + 1 << "\t" << detType[i] << "\t" << detdP1[i] << ", " << detdP2[i] << "\t"
0430                                  << detT11[i] << ", " << detT12[i] << "\t" << detTsc[i] << "\t" << detT21[i] << ", "
0431                                  << detT22[i] << "\t" << detWidth1[i] << "\t" << detWidth2[i] << "\t" << detPosY[i];
0432 #endif
0433 
0434   //  idName = parentName.name();
0435   idName = sArgs["MotherName"];
0436   idNameSpace = DDCurrentNamespace::ns();
0437   idOffset = int(nArgs["IdOffset"]);
0438 #ifdef EDM_ML_DEBUG
0439   edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: Parent " << parent().name() << " idName " << idName
0440                                << " NameSpace " << idNameSpace << " Offset " << idOffset;
0441 #endif
0442 }
0443 
0444 ////////////////////////////////////////////////////////////////////
0445 // DDHCalBarrelAlgo methods...
0446 ////////////////////////////////////////////////////////////////////
0447 
0448 void DDHCalBarrelAlgo::execute(DDCompactView& cpv) {
0449 #ifdef EDM_ML_DEBUG
0450   edm::LogVerbatim("HCalGeom") << "==>> Constructing DDHCalBarrelAlgo...";
0451 #endif
0452   constructGeneralVolume(cpv);
0453 #ifdef EDM_ML_DEBUG
0454   edm::LogVerbatim("HCalGeom") << "<<== End of DDHCalBarrelAlgo construction";
0455 #endif
0456 }
0457 
0458 //----------------------start here for DDD work!!! ---------------
0459 
0460 void DDHCalBarrelAlgo::constructGeneralVolume(DDCompactView& cpv) {
0461 #ifdef EDM_ML_DEBUG
0462   edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: General volume...";
0463 #endif
0464 
0465   DDRotation rot = DDRotation();
0466 
0467   double alpha = (1._pi) / getNsectors();
0468   double dphi = getNsectortot() * (2._pi) / getNsectors();
0469   int nsec, ntot = 15;
0470   if (getNhalf() == 1)
0471     nsec = 8;
0472   else
0473     nsec = 15;
0474   int nf = ntot - nsec;
0475 
0476   //Calculate zmin... see HCalBarrel.hh picture. For polyhedra
0477   //Rmin and Rmax are distances to vertex
0478   double zmax = getZoff(3);
0479   double zstep5 = getZoff(4);
0480   double zstep4 = (getZoff(1) + getRmax(1) * getTanTheta(1));
0481   if ((getZoff(2) + getRmax(1) * getTanTheta(2)) > zstep4)
0482     zstep4 = (getZoff(2) + getRmax(1) * getTanTheta(2));
0483   double zstep3 = (getZoff(1) + getRmax(0) * getTanTheta(1));
0484   double zstep2 = (getZoff(0) + getRmax(0) * getTanTheta(0));
0485   double zstep1 = (getZoff(0) + getRin() * getTanTheta(0));
0486   double rout = getRout();
0487   double rout1 = getRmax(3);
0488   double rin = getRin();
0489   double rmid1 = getRmax(0);
0490   double rmid2 = getRmax(1);
0491   double rmid3 = (getZoff(4) - getZoff(2)) / getTanTheta(2);
0492   double rmid4 = getRmax(2);
0493 
0494   std::vector<double> pgonZ = {-zmax,
0495                                -zstep5,
0496                                -zstep5,
0497                                -zstep4,
0498                                -zstep3,
0499                                -zstep2,
0500                                -zstep1,
0501                                0,
0502                                zstep1,
0503                                zstep2,
0504                                zstep3,
0505                                zstep4,
0506                                zstep5,
0507                                zstep5,
0508                                zmax};
0509 
0510   std::vector<double> pgonRmin = {
0511       rmid4, rmid3, rmid3, rmid2, rmid1, rmid1, rin, rin, rin, rmid1, rmid1, rmid2, rmid3, rmid3, rmid4};
0512 
0513   std::vector<double> pgonRmax = {
0514       rout1, rout1, rout, rout, rout, rout, rout, rout, rout, rout, rout, rout, rout, rout1, rout1};
0515 
0516   std::vector<double> pgonZHalf = {0, zstep1, zstep2, zstep3, zstep4, zstep5, zstep5, zmax};
0517 
0518   std::vector<double> pgonRminHalf = {rin, rin, rmid1, rmid1, rmid2, rmid3, rmid3, rmid4};
0519 
0520   std::vector<double> pgonRmaxHalf = {rout, rout, rout, rout, rout, rout, rout1, rout1};
0521 
0522   std::string name("Null");
0523   DDSolid solid;
0524   if (nf == 0) {
0525     solid = DDSolidFactory::polyhedra(
0526         DDName(idName, idNameSpace), getNsectortot(), -alpha, dphi, pgonZ, pgonRmin, pgonRmax);
0527 #ifdef EDM_ML_DEBUG
0528     edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << DDName(idName, idNameSpace) << " Polyhedra made of "
0529                                  << getGenMaterial() << " with " << getNsectortot() << " sectors from "
0530                                  << convertRadToDeg(-alpha) << " to " << convertRadToDeg(-alpha + dphi) << " and with "
0531                                  << nsec << " sections ";
0532     for (unsigned int i = 0; i < pgonZ.size(); i++)
0533       edm::LogVerbatim("HCalGeom") << "\t"
0534                                    << "\tZ = " << pgonZ[i] << "\tRmin = " << pgonRmin[i] << "\tRmax = " << pgonRmax[i];
0535 #endif
0536   } else {
0537     solid = DDSolidFactory::polyhedra(
0538         DDName(idName, idNameSpace), getNsectortot(), -alpha, dphi, pgonZHalf, pgonRminHalf, pgonRmaxHalf);
0539 #ifdef EDM_ML_DEBUG
0540     edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << DDName(idName, idNameSpace) << " Polyhedra made of "
0541                                  << getGenMaterial() << " with " << getNsectortot() << " sectors from "
0542                                  << convertRadToDeg(-alpha) << " to " << convertRadToDeg(-alpha + dphi) << " and with "
0543                                  << nsec << " sections ";
0544     for (unsigned int i = 0; i < pgonZHalf.size(); i++)
0545       edm::LogVerbatim("HCalGeom") << "\t"
0546                                    << "\tZ = " << pgonZHalf[i] << "\tRmin = " << pgonRminHalf[i]
0547                                    << "\tRmax = " << pgonRmaxHalf[i];
0548 #endif
0549   }
0550 
0551   DDName matname(DDSplit(getGenMaterial()).first, DDSplit(getGenMaterial()).second);
0552   DDMaterial matter(matname);
0553   DDLogicalPart genlogic(DDName(idName, idNameSpace), matter, solid);
0554 
0555   DDName parentName = parent().name();
0556   DDTranslation r0(0, 0, 0);
0557   cpv.position(DDName(idName, idNameSpace), parentName, 1, r0, rot);
0558 #ifdef EDM_ML_DEBUG
0559   edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << DDName(idName, idNameSpace) << " number 1 positioned in "
0560                                << parentName << " at (0, 0, 0) with no rotation";
0561 #endif
0562   //Forward and backwards halfs
0563   name = idName + "Half";
0564   nf = (ntot + 1) / 2;
0565 #ifdef EDM_ML_DEBUG
0566   edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << DDName(name, idNameSpace) << " Polyhedra made of "
0567                                << getGenMaterial() << " with " << getNsectortot() << " sectors from "
0568                                << convertRadToDeg(-alpha) << " to " << convertRadToDeg(-alpha + dphi) << " and with "
0569                                << nf << " sections ";
0570   for (unsigned int i = 0; i < pgonZHalf.size(); i++)
0571     edm::LogVerbatim("HCalGeom") << "\t"
0572                                  << "\tZ = " << pgonZHalf[i] << "\tRmin = " << pgonRminHalf[i]
0573                                  << "\tRmax = " << pgonRmaxHalf[i];
0574 #endif
0575 
0576   solid = DDSolidFactory::polyhedra(
0577       DDName(name, idNameSpace), getNsectortot(), -alpha, dphi, pgonZHalf, pgonRminHalf, pgonRmaxHalf);
0578   DDLogicalPart genlogich(DDName(name, idNameSpace), matter, solid);
0579 
0580   cpv.position(genlogich, genlogic, 1, r0, rot);
0581 #ifdef EDM_ML_DEBUG
0582   edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << genlogich.name() << " number 1 positioned in "
0583                                << genlogic.name() << " at (0, 0, 0) with no rotation";
0584 #endif
0585   if (getNhalf() != 1) {
0586     rot = DDRotation(DDName(rotHalf, rotns));
0587     cpv.position(genlogich, genlogic, 2, r0, rot);
0588 #ifdef EDM_ML_DEBUG
0589     edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << genlogich.name() << " number 2 positioned in "
0590                                  << genlogic.name() << " at " << r0 << " with " << rot;
0591 #endif
0592   }  //end if (getNhalf...
0593 
0594   //Construct sector (from -alpha to +alpha)
0595   name = idName + "Module";
0596 #ifdef EDM_ML_DEBUG
0597   edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << DDName(name, idNameSpace) << " Polyhedra made of "
0598                                << getGenMaterial() << " with 1 sector from " << convertRadToDeg(-alpha) << " to "
0599                                << convertRadToDeg(alpha) << " and with " << nf << " sections";
0600   for (unsigned int i = 0; i < pgonZHalf.size(); i++)
0601     edm::LogVerbatim("HCalGeom") << "\t"
0602                                  << "\tZ = " << pgonZHalf[i] << "\tRmin = " << pgonRminHalf[i]
0603                                  << "\tRmax = " << pgonRmaxHalf[i];
0604 #endif
0605 
0606   solid =
0607       DDSolidFactory::polyhedra(DDName(name, idNameSpace), 1, -alpha, 2 * alpha, pgonZHalf, pgonRminHalf, pgonRmaxHalf);
0608   DDLogicalPart seclogic(DDName(name, idNameSpace), matter, solid);
0609 
0610   double theta = 90._deg;
0611   for (int ii = 0; ii < getNsectortot(); ii++) {
0612     double phi = ii * 2 * alpha;
0613     double phiy = phi + 90._deg;
0614 
0615     DDRotation rotation;
0616     std::string rotstr("NULL");
0617     if (phi != 0) {
0618       rotstr = "R" + formatAsDegreesInInteger(phi);
0619       rotation = DDRotation(DDName(rotstr, rotns));
0620       if (!rotation) {
0621 #ifdef EDM_ML_DEBUG
0622         edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: Creating a new "
0623                                      << "rotation " << rotstr << "\t 90," << convertRadToDeg(phi) << ",90,"
0624                                      << (90 + convertRadToDeg(phi)) << ", 0, 0";
0625 #endif
0626         rotation = DDrot(DDName(rotstr, rotns), theta, phi, theta, phiy, 0, 0);
0627       }  //if !rotation
0628     }    //if phideg!=0
0629 
0630     cpv.position(seclogic, genlogich, ii + 1, r0, rotation);
0631 #ifdef EDM_ML_DEBUG
0632     edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << seclogic.name() << " number " << ii + 1 << " positioned in "
0633                                  << genlogich.name() << " at " << r0 << " with " << rotation;
0634 #endif
0635   }
0636 
0637   //Construct the things inside the sector
0638   constructInsideSector(seclogic, cpv);
0639 }
0640 
0641 void DDHCalBarrelAlgo::constructInsideSector(const DDLogicalPart& sector, DDCompactView& cpv) {
0642 #ifdef EDM_ML_DEBUG
0643   edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: Layers (" << getNLayers() << ") ...";
0644 #endif
0645   double alpha = (1._pi) / getNsectors();
0646   double rin = getRin();
0647   for (int i = 0; i < getNLayers(); i++) {
0648     std::string name = idName + getLayerLabel(i);
0649     DDName matname(DDSplit(getLayerMaterial(i)).first,
0650                    DDSplit(getLayerMaterial(i)).second);  //idNameSpace);
0651     DDMaterial matter(matname);
0652 
0653     double width = getLayerWidth(i);
0654     double rout = rin + width;
0655 
0656     int in = 0, out = 0;
0657     for (int j = 0; j < getRzones() - 1; j++) {
0658       if (rin >= getRmax(j))
0659         in = j + 1;
0660       if (rout > getRmax(j))
0661         out = j + 1;
0662     }
0663     double zout = getZoff(in) + rin * getTanTheta(in);
0664 
0665     //!!!!!!!!!!!!!!!!!Should be zero. And removed as soon as
0666     //vertical walls are allowed in SolidPolyhedra
0667     double deltaz = 0;
0668     int nsec = 2;
0669     std::vector<double> pgonZ, pgonRmin, pgonRmax;
0670     // index 0
0671     pgonZ.emplace_back(0);
0672     pgonRmin.emplace_back(rin);
0673     pgonRmax.emplace_back(rout);
0674     // index 1
0675     pgonZ.emplace_back(zout);
0676     pgonRmin.emplace_back(rin);
0677     pgonRmax.emplace_back(rout);
0678     if (in == out) {
0679       if (in <= 3) {
0680         //index 2
0681         pgonZ.emplace_back(getZoff(in) + rout * getTanTheta(in));
0682         pgonRmin.emplace_back(pgonRmax[1]);
0683         pgonRmax.emplace_back(pgonRmax[1]);
0684         nsec++;
0685       }
0686     } else {
0687       if (in == 3) {
0688         //redo index 1, add index 2
0689         pgonZ[1] = (getZoff(out) + getRmax(out) * getTanTheta(out));
0690         pgonZ.emplace_back(pgonZ[1] + deltaz);
0691         pgonRmin.emplace_back(pgonRmin[1]);
0692         pgonRmax.emplace_back(getRmax(in));
0693         //index 3
0694         pgonZ.emplace_back(getZoff(in) + getRmax(in) * getTanTheta(in));
0695         pgonRmin.emplace_back(pgonRmin[2]);
0696         pgonRmax.emplace_back(pgonRmax[2]);
0697         nsec += 2;
0698       } else {
0699         //index 2
0700         pgonZ.emplace_back(getZoff(in) + getRmax(in) * getTanTheta(in));
0701         pgonRmin.emplace_back(getRmax(in));
0702         pgonRmax.emplace_back(pgonRmax[1]);
0703         nsec++;
0704         if (in == 0) {
0705           pgonZ.emplace_back(getZoff(out) + getRmax(in) * getTanTheta(out));
0706           pgonRmin.emplace_back(pgonRmin[2]);
0707           pgonRmax.emplace_back(pgonRmax[2]);
0708           nsec++;
0709         }
0710         if (in <= 1) {
0711           pgonZ.emplace_back(getZoff(out) + rout * getTanTheta(out));
0712           pgonRmin.emplace_back(rout);
0713           pgonRmax.emplace_back(rout);
0714           nsec++;
0715         }
0716       }
0717     }
0718     //Solid & volume
0719     DDSolid solid;
0720     double alpha1 = alpha;
0721     if (getLayerGap(i) > 1.e-6) {
0722       double rmid = 0.5 * (rin + rout);
0723       double width = rmid * tan(alpha) - getLayerGap(i);
0724       alpha1 = atan(width / rmid);
0725 #ifdef EDM_ML_DEBUG
0726       edm::LogVerbatim("HCalGeom") << "\t"
0727                                    << "Alpha_1 modified from " << convertRadToDeg(alpha) << " to "
0728                                    << convertRadToDeg(alpha1) << " Rmid " << rmid << " Reduced width " << width;
0729 #endif
0730     }
0731 #ifdef EDM_ML_DEBUG
0732     edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << name << " (Layer " << i << ") Polyhedra made of "
0733                                  << getLayerMaterial(i) << " with 1 sector from " << convertRadToDeg(-alpha1) << " to "
0734                                  << convertRadToDeg(alpha1) << " and with " << nsec << " sections";
0735     for (unsigned int k = 0; k < pgonZ.size(); k++)
0736       edm::LogVerbatim("HCalGeom") << "\t"
0737                                    << "\t" << pgonZ[k] << "\t" << pgonRmin[k] << "\t" << pgonRmax[k];
0738 #endif
0739     solid = DDSolidFactory::polyhedra(DDName(name, idNameSpace), 1, -alpha1, 2 * alpha1, pgonZ, pgonRmin, pgonRmax);
0740     DDLogicalPart glog(DDName(name, idNameSpace), matter, solid);
0741 
0742     cpv.position(glog, sector, getLayerId(i), DDTranslation(0.0, 0.0, 0.0), DDRotation());
0743 #ifdef EDM_ML_DEBUG
0744     edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << glog.name() << " number " << getLayerId(i)
0745                                  << " positioned in " << sector.name() << " at (0,0,0) with no rotation";
0746 #endif
0747     constructInsideLayers(glog,
0748                           getLayerLabel(i),
0749                           getLayerId(i),
0750                           getLayerAbsorb(i),
0751                           rin,
0752                           getLayerD1(i),
0753                           alpha1,
0754                           getLayerD2(i),
0755                           getLayerAlpha(i),
0756                           getLayerT1(i),
0757                           getLayerT2(i),
0758                           cpv);
0759     rin = rout;
0760   }
0761 }
0762 
0763 void DDHCalBarrelAlgo::constructInsideLayers(const DDLogicalPart& laylog,
0764                                              const std::string& nm,
0765                                              int id,
0766                                              int nAbs,
0767                                              double rin,
0768                                              double d1,
0769                                              double alpha1,
0770                                              double d2,
0771                                              double alpha2,
0772                                              double t1,
0773                                              double t2,
0774                                              DDCompactView& cpv) {
0775 #ifdef EDM_ML_DEBUG
0776   edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: \t\tInside layer " << id << "...";
0777 #endif
0778   ///////////////////////////////////////////////////////////////
0779   //Pointers to the Rotation Matrices and to the Materials
0780   DDRotation rot(DDName(detRot, rotns));
0781 
0782   std::string nam0 = nm + "In";
0783   std::string name = idName + nam0;
0784   DDName matName(DDSplit(getDetMat()).first, DDSplit(getDetMat()).second);
0785   DDMaterial matter(matName);
0786 
0787   DDSolid solid;
0788   DDLogicalPart glog, mother;
0789   double rsi, dx, dy, dz, x, y;
0790   int i, in;
0791   //Two lower volumes
0792   if (alpha1 > 0) {
0793     rsi = rin + d1;
0794     in = 0;
0795     for (i = 0; i < getRzones() - 1; i++) {
0796       if (rsi >= getRmax(i))
0797         in = i + 1;
0798     }
0799     dx = 0.5 * t1;
0800     dy = 0.5 * rsi * (tan(alpha1) - tan(alpha2));
0801     dz = 0.5 * (getZoff(in) + rsi * getTanTheta(in));
0802     x = rsi + dx;
0803     y = 0.5 * rsi * (tan(alpha1) + tan(alpha2));
0804     DDTranslation r11(x, y, dz);
0805     DDTranslation r12(x, -y, dz);
0806 
0807     solid = DDSolidFactory::box(DDName(name + "1", idNameSpace), dx, dy, dz);
0808 #ifdef EDM_ML_DEBUG
0809     edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << solid.name() << " Box made of " << getDetMat()
0810                                  << " of dimensions " << dx << ", " << dy << ", " << dz;
0811 #endif
0812     glog = DDLogicalPart(solid.ddname(), matter, solid);
0813 
0814     if (nAbs != 0) {
0815       mother = constructSideLayer(laylog, name, nAbs, rin, alpha1, cpv);
0816     } else {
0817       mother = laylog;
0818     }
0819     cpv.position(glog, mother, idOffset + 1, r11, DDRotation());
0820     cpv.position(glog, mother, idOffset + 2, r12, rot);
0821 #ifdef EDM_ML_DEBUG
0822     edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << glog.name() << " Number " << idOffset + 1
0823                                  << " positioned in " << mother.name() << " at " << r11 << " with no rotation\n"
0824                                  << "DDHCalBarrelAlgo: " << glog.name() << " Number " << idOffset + 2
0825                                  << " positioned in " << mother.name() << " at " << r12 << " with " << rot;
0826 #endif
0827     //Constructin the plastics and scintillators inside
0828     constructInsideDetectors(glog, nam0 + "1", id, dx, dy, dz, 1, cpv);
0829   }
0830 
0831   //Upper volume
0832   rsi = rin + d2;
0833   in = 0;
0834   for (i = 0; i < getRzones() - 1; i++) {
0835     if (rsi >= getRmax(i))
0836       in = i + 1;
0837   }
0838   dx = 0.5 * t2;
0839   dy = 0.5 * rsi * tan(alpha2);
0840   dz = 0.5 * (getZoff(in) + rsi * getTanTheta(in));
0841   x = rsi + dx;
0842   DDTranslation r21(x, dy, dz);
0843   DDTranslation r22(x, -dy, dz);
0844 
0845   solid = DDSolidFactory::box(DDName(name + "2", idNameSpace), dx, dy, dz);
0846 #ifdef EDM_ML_DEBUG
0847   edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << solid.name() << " Box made of " << getDetMat()
0848                                << " of dimensions " << dx << ", " << dy << ", " << dz;
0849 #endif
0850   glog = DDLogicalPart(solid.ddname(), matter, solid);
0851 
0852   if (nAbs < 0) {
0853     mother = constructMidLayer(laylog, name, rin, alpha1, cpv);
0854   } else {
0855     mother = laylog;
0856   }
0857   cpv.position(glog, mother, idOffset + 3, r21, DDRotation());
0858   cpv.position(glog, mother, idOffset + 4, r22, rot);
0859 #ifdef EDM_ML_DEBUG
0860   edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << glog.name() << " Number " << idOffset + 3 << " positioned in "
0861                                << mother.name() << " at " << r21
0862                                << " with no rotation\nDDHCalBarrelAlgo: " << glog.name() << " Number " << idOffset + 4
0863                                << " positioned in " << mother.name() << " at " << r22 << " with " << rot;
0864 #endif
0865   //Constructin the plastics and scintillators inside
0866   constructInsideDetectors(glog, nam0 + "2", id, dx, dy, dz, 2, cpv);
0867 }
0868 
0869 DDLogicalPart DDHCalBarrelAlgo::constructSideLayer(
0870     const DDLogicalPart& laylog, const std::string& nm, int nAbs, double rin, double alpha, DDCompactView& cpv) {
0871   //Extra absorber layer
0872   int k = abs(nAbs) - 1;
0873   std::string namek = nm + "Side";
0874   double rsi = rin + getSideD(k);
0875   int in = 0;
0876   for (int i = 0; i < getRzones() - 1; i++) {
0877     if (rsi >= getRmax(i))
0878       in = i + 1;
0879   }
0880   std::vector<double> pgonZ, pgonRmin, pgonRmax;
0881   // index 0
0882   pgonZ.emplace_back(0.0);
0883   pgonRmin.emplace_back(rsi);
0884   pgonRmax.emplace_back(rsi + getSideT(k));
0885   // index 1
0886   pgonZ.emplace_back(getZoff(in) + rsi * getTanTheta(in));
0887   pgonRmin.emplace_back(rsi);
0888   pgonRmax.emplace_back(pgonRmax[0]);
0889   // index 2
0890   pgonZ.emplace_back(getZoff(in) + pgonRmax[0] * getTanTheta(in));
0891   pgonRmin.emplace_back(pgonRmax[1]);
0892   pgonRmax.emplace_back(pgonRmax[1]);
0893   DDSolid solid =
0894       DDSolidFactory::polyhedra(DDName(namek, idNameSpace), 1, -alpha, 2 * alpha, pgonZ, pgonRmin, pgonRmax);
0895 #ifdef EDM_ML_DEBUG
0896   edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << solid.name() << " Polyhedra made of " << getSideMat(k)
0897                                << " with 1 sector from " << convertRadToDeg(-alpha) << " to " << convertRadToDeg(alpha)
0898                                << " and with " << pgonZ.size() << " sections";
0899   for (unsigned int ii = 0; ii < pgonZ.size(); ii++)
0900     edm::LogVerbatim("HCalGeom") << "\t\tZ = " << pgonZ[ii] << "\tRmin = " << pgonRmin[ii]
0901                                  << "\tRmax = " << pgonRmax[ii];
0902 #endif
0903 
0904   DDName matName(DDSplit(getSideMat(k)).first, DDSplit(getSideMat(k)).second);
0905   DDMaterial matter(matName);
0906   DDLogicalPart glog = DDLogicalPart(solid.ddname(), matter, solid);
0907 
0908   cpv.position(glog, laylog, 1, DDTranslation(), DDRotation());
0909 #ifdef EDM_ML_DEBUG
0910   edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << glog.name() << " Number 1 positioned in " << laylog.name()
0911                                << " at (0,0,0) with no rotation";
0912 #endif
0913   if (nAbs < 0) {
0914     DDLogicalPart mother = glog;
0915     double rmid = pgonRmax[0];
0916     for (int i = 0; i < getSideAbsorber(); i++) {
0917       double alpha1 = atan(getSideAbsW(i) / rmid);
0918       if (alpha1 > 0) {
0919         std::string name = namek + getSideAbsName(i);
0920         solid = DDSolidFactory::polyhedra(DDName(name, idNameSpace), 1, -alpha1, 2 * alpha1, pgonZ, pgonRmin, pgonRmax);
0921 #ifdef EDM_ML_DEBUG
0922         edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << solid.name() << " Polyhedra made of "
0923                                      << getSideAbsMat(i) << " with 1 sector from " << convertRadToDeg(-alpha1) << " to "
0924                                      << convertRadToDeg(alpha1) << " and with " << pgonZ.size() << " sections";
0925         for (unsigned int ii = 0; ii < pgonZ.size(); ii++)
0926           edm::LogVerbatim("HCalGeom") << "\t\tZ = " << pgonZ[ii] << "\tRmin = " << pgonRmin[ii]
0927                                        << "\tRmax = " << pgonRmax[ii];
0928 #endif
0929 
0930         DDName matName(DDSplit(getSideAbsMat(i)).first, DDSplit(getSideAbsMat(i)).second);
0931         DDMaterial matter(matName);
0932         DDLogicalPart log = DDLogicalPart(solid.ddname(), matter, solid);
0933 
0934         cpv.position(log, mother, 1, DDTranslation(), DDRotation());
0935 #ifdef EDM_ML_DEBUG
0936         edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << log.name() << " Number 1 positioned in "
0937                                      << mother.name() << " at (0,0,0) with no rotation";
0938 #endif
0939         mother = log;
0940       }
0941     }
0942   }
0943   return glog;
0944 }
0945 
0946 DDLogicalPart DDHCalBarrelAlgo::constructMidLayer(
0947     const DDLogicalPart& laylog, const std::string& nm, double rin, double alpha, DDCompactView& cpv) {
0948   DDSolid solid;
0949   DDLogicalPart log, glog;
0950   std::string name = nm + "Mid";
0951   for (int k = 0; k < getAbsorberN(); k++) {
0952     std::string namek = name + getAbsorbName(k);
0953     double rsi = rin + getAbsorbD(k);
0954     int in = 0;
0955     for (int i = 0; i < getRzones() - 1; i++) {
0956       if (rsi >= getRmax(i))
0957         in = i + 1;
0958     }
0959     std::vector<double> pgonZ, pgonRmin, pgonRmax;
0960     // index 0
0961     pgonZ.emplace_back(0.0);
0962     pgonRmin.emplace_back(rsi);
0963     pgonRmax.emplace_back(rsi + getAbsorbT(k));
0964     // index 1
0965     pgonZ.emplace_back(getZoff(in) + rsi * getTanTheta(in));
0966     pgonRmin.emplace_back(rsi);
0967     pgonRmax.emplace_back(pgonRmax[0]);
0968     // index 2
0969     pgonZ.emplace_back(getZoff(in) + pgonRmax[0] * getTanTheta(in));
0970     pgonRmin.emplace_back(pgonRmax[1]);
0971     pgonRmax.emplace_back(pgonRmax[1]);
0972     solid = DDSolidFactory::polyhedra(DDName(namek, idNameSpace), 1, -alpha, 2 * alpha, pgonZ, pgonRmin, pgonRmax);
0973 #ifdef EDM_ML_DEBUG
0974     edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << solid.name() << " Polyhedra made of " << getAbsorbMat(k)
0975                                  << " with 1 sector from " << convertRadToDeg(-alpha) << " to "
0976                                  << convertRadToDeg(alpha) << " and with " << pgonZ.size() << " sections";
0977     for (unsigned int ii = 0; ii < pgonZ.size(); ii++)
0978       edm::LogVerbatim("HCalGeom") << "\t\tZ = " << pgonZ[ii] << "\tRmin = " << pgonRmin[ii]
0979                                    << "\tRmax = " << pgonRmax[ii];
0980 #endif
0981 
0982     DDName matName(DDSplit(getAbsorbMat(k)).first, DDSplit(getAbsorbMat(k)).second);
0983     DDMaterial matter(matName);
0984     log = DDLogicalPart(solid.ddname(), matter, solid);
0985 
0986     cpv.position(log, laylog, 1, DDTranslation(), DDRotation());
0987 #ifdef EDM_ML_DEBUG
0988     edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << log.name() << " Number 1 positioned in " << laylog.name()
0989                                  << " at (0,0,0) with no rotation";
0990 #endif
0991     if (k == 0) {
0992       double rmin = pgonRmin[0];
0993       double rmax = pgonRmax[0];
0994       DDLogicalPart mother = log;
0995       for (int i = 0; i < 1; i++) {
0996         double alpha1 = atan(getMidAbsW(i) / rmin);
0997         std::string namek = name + getMidAbsName(i);
0998         solid =
0999             DDSolidFactory::polyhedra(DDName(namek, idNameSpace), 1, -alpha1, 2 * alpha1, pgonZ, pgonRmin, pgonRmax);
1000 #ifdef EDM_ML_DEBUG
1001         edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << solid.name() << " Polyhedra made of " << getMidAbsMat(i)
1002                                      << " with 1 sector from " << convertRadToDeg(-alpha1) << " to "
1003                                      << convertRadToDeg(alpha1) << " and with " << pgonZ.size() << " sections";
1004         for (unsigned int ii = 0; ii < pgonZ.size(); ii++)
1005           edm::LogVerbatim("HCalGeom") << "\t\tZ = " << pgonZ[ii] << "\tRmin = " << pgonRmin[ii]
1006                                        << "\tRmax = " << pgonRmax[ii];
1007 #endif
1008 
1009         DDName matNam1(DDSplit(getMidAbsMat(i)).first, DDSplit(getMidAbsMat(i)).second);
1010         DDMaterial matter1(matNam1);
1011         log = DDLogicalPart(solid.ddname(), matter1, solid);
1012 
1013         cpv.position(log, mother, 1, DDTranslation(), DDRotation());
1014 #ifdef EDM_ML_DEBUG
1015         edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << log.name() << " Number 1 positioned in "
1016                                      << mother.name() << " at (0,0,0) with no rotation";
1017 #endif
1018         mother = log;
1019       }
1020 
1021       // Now the layer with detectors
1022       double rmid = rmin + getMiddleD();
1023       pgonRmin[0] = rmid;
1024       pgonRmax[0] = rmax;
1025       pgonRmin[1] = rmid;
1026       pgonRmax[1] = rmax;
1027       pgonZ[1] = getZoff(in) + rmid * getTanTheta(in);
1028       pgonRmin[2] = rmax;
1029       pgonRmax[2] = rmax;
1030       pgonZ[2] = getZoff(in) + rmax * getTanTheta(in);
1031       double alpha1 = atan(getMiddleW() / rmin);
1032       solid = DDSolidFactory::polyhedra(DDName(name, idNameSpace), 1, -alpha1, 2 * alpha1, pgonZ, pgonRmin, pgonRmax);
1033 #ifdef EDM_ML_DEBUG
1034       edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << solid.name() << " Polyhedra made of " << getMiddleMat()
1035                                    << " with 1 sector from " << convertRadToDeg(-alpha1) << " to "
1036                                    << convertRadToDeg(alpha1) << " and with " << pgonZ.size() << " sections";
1037       for (unsigned int ii = 0; ii < pgonZ.size(); ii++)
1038         edm::LogVerbatim("HCalGeom") << "\t\tZ = " << pgonZ[ii] << "\tRmin = " << pgonRmin[ii]
1039                                      << "\tRmax = " << pgonRmax[ii];
1040 #endif
1041 
1042       DDName matNam1(DDSplit(getMiddleMat()).first, DDSplit(getMiddleMat()).second);
1043       DDMaterial matter1(matNam1);
1044       glog = DDLogicalPart(solid.ddname(), matter1, solid);
1045 
1046       cpv.position(glog, mother, 1, DDTranslation(), DDRotation());
1047 #ifdef EDM_ML_DEBUG
1048       edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << glog.name() << " Number 1 positioned in " << mother.name()
1049                                    << " at (0,0,0) with no rotation";
1050 #endif
1051       // Now the remaining absorber layers
1052       for (int i = 1; i < getMidAbsorber(); i++) {
1053         namek = name + getMidAbsName(i);
1054         rmid = rmin + getMidAbsT(i);
1055         pgonRmin[0] = rmin;
1056         pgonRmax[0] = rmid;
1057         pgonRmin[1] = rmin;
1058         pgonRmax[1] = rmid;
1059         pgonZ[1] = getZoff(in) + rmin * getTanTheta(in);
1060         pgonRmin[2] = rmid;
1061         pgonRmax[2] = rmid;
1062         pgonZ[2] = getZoff(in) + rmid * getTanTheta(in);
1063         alpha1 = atan(getMidAbsW(i) / rmin);
1064         solid =
1065             DDSolidFactory::polyhedra(DDName(namek, idNameSpace), 1, -alpha1, 2 * alpha1, pgonZ, pgonRmin, pgonRmax);
1066 #ifdef EDM_ML_DEBUG
1067         edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << solid.name() << " Polyhedra made of " << getMidAbsMat(i)
1068                                      << " with 1 sector from " << convertRadToDeg(-alpha1) << " to "
1069                                      << convertRadToDeg(alpha1) << " and with " << pgonZ.size() << " sections";
1070         for (unsigned int ii = 0; ii < pgonZ.size(); ii++)
1071           edm::LogVerbatim("HCalGeom") << "\t\tZ = " << pgonZ[ii] << "\tRmin = " << pgonRmin[ii]
1072                                        << "\tRmax = " << pgonRmax[ii];
1073 #endif
1074 
1075         DDName matName2(DDSplit(getMidAbsMat(i)).first, DDSplit(getMidAbsMat(i)).second);
1076         DDMaterial matter2(matName2);
1077         log = DDLogicalPart(solid.ddname(), matter2, solid);
1078 
1079         cpv.position(log, mother, i, DDTranslation(), DDRotation());
1080 #ifdef EDM_ML_DEBUG
1081         edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << log.name() << " Number " << i << " positioned in "
1082                                      << mother.name() << " at (0,0,0) with no "
1083                                      << "rotation";
1084 #endif
1085         mother = log;
1086       }
1087     }
1088   }
1089   return glog;
1090 }
1091 
1092 void DDHCalBarrelAlgo::constructInsideDetectors(const DDLogicalPart& detector,
1093                                                 const std::string& name,
1094                                                 int id,
1095                                                 double dx,
1096                                                 double dy,
1097                                                 double dz,
1098                                                 int type,
1099                                                 DDCompactView& cpv) {
1100 #ifdef EDM_ML_DEBUG
1101   edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: \t\tInside detector " << id << "...";
1102 #endif
1103 
1104   DDName plmatname(DDSplit(getDetMatPl()).first, DDSplit(getDetMatPl()).second);
1105   DDMaterial plmatter(plmatname);
1106   DDName scmatname(DDSplit(getDetMatSc()).first, DDSplit(getDetMatSc()).second);
1107   DDMaterial scmatter(scmatname);
1108 
1109   std::string plname = detector.name().name() + "Plastic_";
1110   std::string scname = idName + "Scintillator" + name;
1111 
1112   id--;
1113   DDSolid solid;
1114   DDLogicalPart glog;
1115   double wid, y = 0;
1116   double dx1, dx2, shiftX;
1117 
1118   if (type == 1) {
1119     wid = 0.5 * getDetWidth1(id);
1120     if (getDetPosY(id) > 0)
1121       y = -dy + wid;
1122     dx1 = 0.5 * getDetT11(id);
1123     dx2 = 0.5 * getDetT21(id);
1124     shiftX = getDetdP1(id);
1125   } else {
1126     wid = 0.5 * getDetWidth2(id);
1127     dx1 = 0.5 * getDetT12(id);
1128     dx2 = 0.5 * getDetT22(id);
1129     shiftX = getDetdP2(id);
1130   }
1131 
1132   solid = DDSolidFactory::box(DDName(plname + "1", idNameSpace), dx1, wid, dz);
1133 #ifdef EDM_ML_DEBUG
1134   edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << solid.name() << " Box made of " << getDetMatPl()
1135                                << " of dimensions " << dx1 << ", " << wid << ", " << dz;
1136 #endif
1137   glog = DDLogicalPart(solid.ddname(), plmatter, solid);
1138 
1139   double x = shiftX + dx1 - dx;
1140   cpv.position(glog, detector, 1, DDTranslation(x, y, 0), DDRotation());
1141 #ifdef EDM_ML_DEBUG
1142   edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << glog.name() << " Number 1 positioned in " << detector.name()
1143                                << " at (" << x << "," << y << ",0) with no rotation";
1144 #endif
1145   solid = DDSolidFactory::box(DDName(scname, idNameSpace), 0.5 * getDetTsc(id), wid, dz);
1146 #ifdef EDM_ML_DEBUG
1147   edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << solid.name() << " Box made of " << getDetMatSc()
1148                                << " of dimensions " << 0.5 * getDetTsc(id) << ", " << wid << ", " << dz;
1149 #endif
1150   glog = DDLogicalPart(solid.ddname(), scmatter, solid);
1151 
1152   x += dx1 + 0.5 * getDetTsc(id);
1153   int copyNo = id * 10 + getDetType(id);
1154   cpv.position(glog, detector, copyNo, DDTranslation(x, y, 0), DDRotation());
1155 #ifdef EDM_ML_DEBUG
1156   edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << glog.name() << " Number " << copyNo << " positioned in "
1157                                << detector.name() << " at (" << x << "," << y << ",0) with no rotation";
1158 #endif
1159   solid = DDSolidFactory::box(DDName(plname + "2", idNameSpace), dx2, wid, dz);
1160 #ifdef EDM_ML_DEBUG
1161   edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << solid.name() << " Box made of " << getDetMatPl()
1162                                << " of dimensions " << dx2 << ", " << wid << ", " << dz;
1163 #endif
1164   glog = DDLogicalPart(solid.ddname(), plmatter, solid);
1165 
1166   x += 0.5 * getDetTsc(id) + dx2;
1167   cpv.position(glog, detector, 1, DDTranslation(x, y, 0), DDRotation());
1168 #ifdef EDM_ML_DEBUG
1169   edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << glog.name() << " Number 1 positioned in " << detector.name()
1170                                << " at (" << x << "," << y << ",0) with no rotation";
1171 #endif
1172 }
1173 
1174 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHCalBarrelAlgo, "hcal:DDHCalBarrelAlgo");