Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:14:44

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 #ifdef EDM_ML_DEBUG
0669     int nsec = 2;
0670 #endif
0671     std::vector<double> pgonZ, pgonRmin, pgonRmax;
0672     // index 0
0673     pgonZ.emplace_back(0);
0674     pgonRmin.emplace_back(rin);
0675     pgonRmax.emplace_back(rout);
0676     // index 1
0677     pgonZ.emplace_back(zout);
0678     pgonRmin.emplace_back(rin);
0679     pgonRmax.emplace_back(rout);
0680     if (in == out) {
0681       if (in <= 3) {
0682         //index 2
0683         pgonZ.emplace_back(getZoff(in) + rout * getTanTheta(in));
0684         pgonRmin.emplace_back(pgonRmax[1]);
0685         pgonRmax.emplace_back(pgonRmax[1]);
0686 #ifdef EDM_ML_DEBUG
0687         nsec++;
0688 #endif
0689       }
0690     } else {
0691       if (in == 3) {
0692         //redo index 1, add index 2
0693         pgonZ[1] = (getZoff(out) + getRmax(out) * getTanTheta(out));
0694         pgonZ.emplace_back(pgonZ[1] + deltaz);
0695         pgonRmin.emplace_back(pgonRmin[1]);
0696         pgonRmax.emplace_back(getRmax(in));
0697         //index 3
0698         pgonZ.emplace_back(getZoff(in) + getRmax(in) * getTanTheta(in));
0699         pgonRmin.emplace_back(pgonRmin[2]);
0700         pgonRmax.emplace_back(pgonRmax[2]);
0701 #ifdef EDM_ML_DEBUG
0702         nsec += 2;
0703 #endif
0704       } else {
0705         //index 2
0706         pgonZ.emplace_back(getZoff(in) + getRmax(in) * getTanTheta(in));
0707         pgonRmin.emplace_back(getRmax(in));
0708         pgonRmax.emplace_back(pgonRmax[1]);
0709 #ifdef EDM_ML_DEBUG
0710         nsec++;
0711 #endif
0712         if (in == 0) {
0713           pgonZ.emplace_back(getZoff(out) + getRmax(in) * getTanTheta(out));
0714           pgonRmin.emplace_back(pgonRmin[2]);
0715           pgonRmax.emplace_back(pgonRmax[2]);
0716 #ifdef EDM_ML_DEBUG
0717           nsec++;
0718 #endif
0719         }
0720         if (in <= 1) {
0721           pgonZ.emplace_back(getZoff(out) + rout * getTanTheta(out));
0722           pgonRmin.emplace_back(rout);
0723           pgonRmax.emplace_back(rout);
0724 #ifdef EDM_ML_DEBUG
0725           nsec++;
0726 #endif
0727         }
0728       }
0729     }
0730     //Solid & volume
0731     DDSolid solid;
0732     double alpha1 = alpha;
0733     if (getLayerGap(i) > 1.e-6) {
0734       double rmid = 0.5 * (rin + rout);
0735       double width = rmid * tan(alpha) - getLayerGap(i);
0736       alpha1 = atan(width / rmid);
0737 #ifdef EDM_ML_DEBUG
0738       edm::LogVerbatim("HCalGeom") << "\t"
0739                                    << "Alpha_1 modified from " << convertRadToDeg(alpha) << " to "
0740                                    << convertRadToDeg(alpha1) << " Rmid " << rmid << " Reduced width " << width;
0741 #endif
0742     }
0743 #ifdef EDM_ML_DEBUG
0744     edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << name << " (Layer " << i << ") Polyhedra made of "
0745                                  << getLayerMaterial(i) << " with 1 sector from " << convertRadToDeg(-alpha1) << " to "
0746                                  << convertRadToDeg(alpha1) << " and with " << nsec << " sections";
0747     for (unsigned int k = 0; k < pgonZ.size(); k++)
0748       edm::LogVerbatim("HCalGeom") << "\t"
0749                                    << "\t" << pgonZ[k] << "\t" << pgonRmin[k] << "\t" << pgonRmax[k];
0750 #endif
0751     solid = DDSolidFactory::polyhedra(DDName(name, idNameSpace), 1, -alpha1, 2 * alpha1, pgonZ, pgonRmin, pgonRmax);
0752     DDLogicalPart glog(DDName(name, idNameSpace), matter, solid);
0753 
0754     cpv.position(glog, sector, getLayerId(i), DDTranslation(0.0, 0.0, 0.0), DDRotation());
0755 #ifdef EDM_ML_DEBUG
0756     edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << glog.name() << " number " << getLayerId(i)
0757                                  << " positioned in " << sector.name() << " at (0,0,0) with no rotation";
0758 #endif
0759     constructInsideLayers(glog,
0760                           getLayerLabel(i),
0761                           getLayerId(i),
0762                           getLayerAbsorb(i),
0763                           rin,
0764                           getLayerD1(i),
0765                           alpha1,
0766                           getLayerD2(i),
0767                           getLayerAlpha(i),
0768                           getLayerT1(i),
0769                           getLayerT2(i),
0770                           cpv);
0771     rin = rout;
0772   }
0773 }
0774 
0775 void DDHCalBarrelAlgo::constructInsideLayers(const DDLogicalPart& laylog,
0776                                              const std::string& nm,
0777                                              int id,
0778                                              int nAbs,
0779                                              double rin,
0780                                              double d1,
0781                                              double alpha1,
0782                                              double d2,
0783                                              double alpha2,
0784                                              double t1,
0785                                              double t2,
0786                                              DDCompactView& cpv) {
0787 #ifdef EDM_ML_DEBUG
0788   edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: \t\tInside layer " << id << "...";
0789 #endif
0790   ///////////////////////////////////////////////////////////////
0791   //Pointers to the Rotation Matrices and to the Materials
0792   DDRotation rot(DDName(detRot, rotns));
0793 
0794   std::string nam0 = nm + "In";
0795   std::string name = idName + nam0;
0796   DDName matName(DDSplit(getDetMat()).first, DDSplit(getDetMat()).second);
0797   DDMaterial matter(matName);
0798 
0799   DDSolid solid;
0800   DDLogicalPart glog, mother;
0801   double rsi, dx, dy, dz, x, y;
0802   int i, in;
0803   //Two lower volumes
0804   if (alpha1 > 0) {
0805     rsi = rin + d1;
0806     in = 0;
0807     for (i = 0; i < getRzones() - 1; i++) {
0808       if (rsi >= getRmax(i))
0809         in = i + 1;
0810     }
0811     dx = 0.5 * t1;
0812     dy = 0.5 * rsi * (tan(alpha1) - tan(alpha2));
0813     dz = 0.5 * (getZoff(in) + rsi * getTanTheta(in));
0814     x = rsi + dx;
0815     y = 0.5 * rsi * (tan(alpha1) + tan(alpha2));
0816     DDTranslation r11(x, y, dz);
0817     DDTranslation r12(x, -y, dz);
0818 
0819     solid = DDSolidFactory::box(DDName(name + "1", idNameSpace), dx, dy, dz);
0820 #ifdef EDM_ML_DEBUG
0821     edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << solid.name() << " Box made of " << getDetMat()
0822                                  << " of dimensions " << dx << ", " << dy << ", " << dz;
0823 #endif
0824     glog = DDLogicalPart(solid.ddname(), matter, solid);
0825 
0826     if (nAbs != 0) {
0827       mother = constructSideLayer(laylog, name, nAbs, rin, alpha1, cpv);
0828     } else {
0829       mother = laylog;
0830     }
0831     cpv.position(glog, mother, idOffset + 1, r11, DDRotation());
0832     cpv.position(glog, mother, idOffset + 2, r12, rot);
0833 #ifdef EDM_ML_DEBUG
0834     edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << glog.name() << " Number " << idOffset + 1
0835                                  << " positioned in " << mother.name() << " at " << r11 << " with no rotation\n"
0836                                  << "DDHCalBarrelAlgo: " << glog.name() << " Number " << idOffset + 2
0837                                  << " positioned in " << mother.name() << " at " << r12 << " with " << rot;
0838 #endif
0839     //Constructin the plastics and scintillators inside
0840     constructInsideDetectors(glog, nam0 + "1", id, dx, dy, dz, 1, cpv);
0841   }
0842 
0843   //Upper volume
0844   rsi = rin + d2;
0845   in = 0;
0846   for (i = 0; i < getRzones() - 1; i++) {
0847     if (rsi >= getRmax(i))
0848       in = i + 1;
0849   }
0850   dx = 0.5 * t2;
0851   dy = 0.5 * rsi * tan(alpha2);
0852   dz = 0.5 * (getZoff(in) + rsi * getTanTheta(in));
0853   x = rsi + dx;
0854   DDTranslation r21(x, dy, dz);
0855   DDTranslation r22(x, -dy, dz);
0856 
0857   solid = DDSolidFactory::box(DDName(name + "2", idNameSpace), dx, dy, dz);
0858 #ifdef EDM_ML_DEBUG
0859   edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << solid.name() << " Box made of " << getDetMat()
0860                                << " of dimensions " << dx << ", " << dy << ", " << dz;
0861 #endif
0862   glog = DDLogicalPart(solid.ddname(), matter, solid);
0863 
0864   if (nAbs < 0) {
0865     mother = constructMidLayer(laylog, name, rin, alpha1, cpv);
0866   } else {
0867     mother = laylog;
0868   }
0869   cpv.position(glog, mother, idOffset + 3, r21, DDRotation());
0870   cpv.position(glog, mother, idOffset + 4, r22, rot);
0871 #ifdef EDM_ML_DEBUG
0872   edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << glog.name() << " Number " << idOffset + 3 << " positioned in "
0873                                << mother.name() << " at " << r21
0874                                << " with no rotation\nDDHCalBarrelAlgo: " << glog.name() << " Number " << idOffset + 4
0875                                << " positioned in " << mother.name() << " at " << r22 << " with " << rot;
0876 #endif
0877   //Constructin the plastics and scintillators inside
0878   constructInsideDetectors(glog, nam0 + "2", id, dx, dy, dz, 2, cpv);
0879 }
0880 
0881 DDLogicalPart DDHCalBarrelAlgo::constructSideLayer(
0882     const DDLogicalPart& laylog, const std::string& nm, int nAbs, double rin, double alpha, DDCompactView& cpv) {
0883   //Extra absorber layer
0884   int k = abs(nAbs) - 1;
0885   std::string namek = nm + "Side";
0886   double rsi = rin + getSideD(k);
0887   int in = 0;
0888   for (int i = 0; i < getRzones() - 1; i++) {
0889     if (rsi >= getRmax(i))
0890       in = i + 1;
0891   }
0892   std::vector<double> pgonZ, pgonRmin, pgonRmax;
0893   // index 0
0894   pgonZ.emplace_back(0.0);
0895   pgonRmin.emplace_back(rsi);
0896   pgonRmax.emplace_back(rsi + getSideT(k));
0897   // index 1
0898   pgonZ.emplace_back(getZoff(in) + rsi * getTanTheta(in));
0899   pgonRmin.emplace_back(rsi);
0900   pgonRmax.emplace_back(pgonRmax[0]);
0901   // index 2
0902   pgonZ.emplace_back(getZoff(in) + pgonRmax[0] * getTanTheta(in));
0903   pgonRmin.emplace_back(pgonRmax[1]);
0904   pgonRmax.emplace_back(pgonRmax[1]);
0905   DDSolid solid =
0906       DDSolidFactory::polyhedra(DDName(namek, idNameSpace), 1, -alpha, 2 * alpha, pgonZ, pgonRmin, pgonRmax);
0907 #ifdef EDM_ML_DEBUG
0908   edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << solid.name() << " Polyhedra made of " << getSideMat(k)
0909                                << " with 1 sector from " << convertRadToDeg(-alpha) << " to " << convertRadToDeg(alpha)
0910                                << " and with " << pgonZ.size() << " sections";
0911   for (unsigned int ii = 0; ii < pgonZ.size(); ii++)
0912     edm::LogVerbatim("HCalGeom") << "\t\tZ = " << pgonZ[ii] << "\tRmin = " << pgonRmin[ii]
0913                                  << "\tRmax = " << pgonRmax[ii];
0914 #endif
0915 
0916   DDName matName(DDSplit(getSideMat(k)).first, DDSplit(getSideMat(k)).second);
0917   DDMaterial matter(matName);
0918   DDLogicalPart glog = DDLogicalPart(solid.ddname(), matter, solid);
0919 
0920   cpv.position(glog, laylog, 1, DDTranslation(), DDRotation());
0921 #ifdef EDM_ML_DEBUG
0922   edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << glog.name() << " Number 1 positioned in " << laylog.name()
0923                                << " at (0,0,0) with no rotation";
0924 #endif
0925   if (nAbs < 0) {
0926     DDLogicalPart mother = glog;
0927     double rmid = pgonRmax[0];
0928     for (int i = 0; i < getSideAbsorber(); i++) {
0929       double alpha1 = atan(getSideAbsW(i) / rmid);
0930       if (alpha1 > 0) {
0931         std::string name = namek + getSideAbsName(i);
0932         solid = DDSolidFactory::polyhedra(DDName(name, idNameSpace), 1, -alpha1, 2 * alpha1, pgonZ, pgonRmin, pgonRmax);
0933 #ifdef EDM_ML_DEBUG
0934         edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << solid.name() << " Polyhedra made of "
0935                                      << getSideAbsMat(i) << " with 1 sector from " << convertRadToDeg(-alpha1) << " to "
0936                                      << convertRadToDeg(alpha1) << " and with " << pgonZ.size() << " sections";
0937         for (unsigned int ii = 0; ii < pgonZ.size(); ii++)
0938           edm::LogVerbatim("HCalGeom") << "\t\tZ = " << pgonZ[ii] << "\tRmin = " << pgonRmin[ii]
0939                                        << "\tRmax = " << pgonRmax[ii];
0940 #endif
0941 
0942         DDName matName(DDSplit(getSideAbsMat(i)).first, DDSplit(getSideAbsMat(i)).second);
0943         DDMaterial matter(matName);
0944         DDLogicalPart log = DDLogicalPart(solid.ddname(), matter, solid);
0945 
0946         cpv.position(log, mother, 1, DDTranslation(), DDRotation());
0947 #ifdef EDM_ML_DEBUG
0948         edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << log.name() << " Number 1 positioned in "
0949                                      << mother.name() << " at (0,0,0) with no rotation";
0950 #endif
0951         mother = log;
0952       }
0953     }
0954   }
0955   return glog;
0956 }
0957 
0958 DDLogicalPart DDHCalBarrelAlgo::constructMidLayer(
0959     const DDLogicalPart& laylog, const std::string& nm, double rin, double alpha, DDCompactView& cpv) {
0960   DDSolid solid;
0961   DDLogicalPart log, glog;
0962   std::string name = nm + "Mid";
0963   for (int k = 0; k < getAbsorberN(); k++) {
0964     std::string namek = name + getAbsorbName(k);
0965     double rsi = rin + getAbsorbD(k);
0966     int in = 0;
0967     for (int i = 0; i < getRzones() - 1; i++) {
0968       if (rsi >= getRmax(i))
0969         in = i + 1;
0970     }
0971     std::vector<double> pgonZ, pgonRmin, pgonRmax;
0972     // index 0
0973     pgonZ.emplace_back(0.0);
0974     pgonRmin.emplace_back(rsi);
0975     pgonRmax.emplace_back(rsi + getAbsorbT(k));
0976     // index 1
0977     pgonZ.emplace_back(getZoff(in) + rsi * getTanTheta(in));
0978     pgonRmin.emplace_back(rsi);
0979     pgonRmax.emplace_back(pgonRmax[0]);
0980     // index 2
0981     pgonZ.emplace_back(getZoff(in) + pgonRmax[0] * getTanTheta(in));
0982     pgonRmin.emplace_back(pgonRmax[1]);
0983     pgonRmax.emplace_back(pgonRmax[1]);
0984     solid = DDSolidFactory::polyhedra(DDName(namek, idNameSpace), 1, -alpha, 2 * alpha, pgonZ, pgonRmin, pgonRmax);
0985 #ifdef EDM_ML_DEBUG
0986     edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << solid.name() << " Polyhedra made of " << getAbsorbMat(k)
0987                                  << " with 1 sector from " << convertRadToDeg(-alpha) << " to "
0988                                  << convertRadToDeg(alpha) << " and with " << pgonZ.size() << " sections";
0989     for (unsigned int ii = 0; ii < pgonZ.size(); ii++)
0990       edm::LogVerbatim("HCalGeom") << "\t\tZ = " << pgonZ[ii] << "\tRmin = " << pgonRmin[ii]
0991                                    << "\tRmax = " << pgonRmax[ii];
0992 #endif
0993 
0994     DDName matName(DDSplit(getAbsorbMat(k)).first, DDSplit(getAbsorbMat(k)).second);
0995     DDMaterial matter(matName);
0996     log = DDLogicalPart(solid.ddname(), matter, solid);
0997 
0998     cpv.position(log, laylog, 1, DDTranslation(), DDRotation());
0999 #ifdef EDM_ML_DEBUG
1000     edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << log.name() << " Number 1 positioned in " << laylog.name()
1001                                  << " at (0,0,0) with no rotation";
1002 #endif
1003     if (k == 0) {
1004       double rmin = pgonRmin[0];
1005       double rmax = pgonRmax[0];
1006       DDLogicalPart mother = log;
1007       for (int i = 0; i < 1; i++) {
1008         double alpha1 = atan(getMidAbsW(i) / rmin);
1009         std::string namek = name + getMidAbsName(i);
1010         solid =
1011             DDSolidFactory::polyhedra(DDName(namek, idNameSpace), 1, -alpha1, 2 * alpha1, pgonZ, pgonRmin, pgonRmax);
1012 #ifdef EDM_ML_DEBUG
1013         edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << solid.name() << " Polyhedra made of " << getMidAbsMat(i)
1014                                      << " with 1 sector from " << convertRadToDeg(-alpha1) << " to "
1015                                      << convertRadToDeg(alpha1) << " and with " << pgonZ.size() << " sections";
1016         for (unsigned int ii = 0; ii < pgonZ.size(); ii++)
1017           edm::LogVerbatim("HCalGeom") << "\t\tZ = " << pgonZ[ii] << "\tRmin = " << pgonRmin[ii]
1018                                        << "\tRmax = " << pgonRmax[ii];
1019 #endif
1020 
1021         DDName matNam1(DDSplit(getMidAbsMat(i)).first, DDSplit(getMidAbsMat(i)).second);
1022         DDMaterial matter1(matNam1);
1023         log = DDLogicalPart(solid.ddname(), matter1, solid);
1024 
1025         cpv.position(log, mother, 1, DDTranslation(), DDRotation());
1026 #ifdef EDM_ML_DEBUG
1027         edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << log.name() << " Number 1 positioned in "
1028                                      << mother.name() << " at (0,0,0) with no rotation";
1029 #endif
1030         mother = log;
1031       }
1032 
1033       // Now the layer with detectors
1034       double rmid = rmin + getMiddleD();
1035       pgonRmin[0] = rmid;
1036       pgonRmax[0] = rmax;
1037       pgonRmin[1] = rmid;
1038       pgonRmax[1] = rmax;
1039       pgonZ[1] = getZoff(in) + rmid * getTanTheta(in);
1040       pgonRmin[2] = rmax;
1041       pgonRmax[2] = rmax;
1042       pgonZ[2] = getZoff(in) + rmax * getTanTheta(in);
1043       double alpha1 = atan(getMiddleW() / rmin);
1044       solid = DDSolidFactory::polyhedra(DDName(name, idNameSpace), 1, -alpha1, 2 * alpha1, pgonZ, pgonRmin, pgonRmax);
1045 #ifdef EDM_ML_DEBUG
1046       edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << solid.name() << " Polyhedra made of " << getMiddleMat()
1047                                    << " with 1 sector from " << convertRadToDeg(-alpha1) << " to "
1048                                    << convertRadToDeg(alpha1) << " and with " << pgonZ.size() << " sections";
1049       for (unsigned int ii = 0; ii < pgonZ.size(); ii++)
1050         edm::LogVerbatim("HCalGeom") << "\t\tZ = " << pgonZ[ii] << "\tRmin = " << pgonRmin[ii]
1051                                      << "\tRmax = " << pgonRmax[ii];
1052 #endif
1053 
1054       DDName matNam1(DDSplit(getMiddleMat()).first, DDSplit(getMiddleMat()).second);
1055       DDMaterial matter1(matNam1);
1056       glog = DDLogicalPart(solid.ddname(), matter1, solid);
1057 
1058       cpv.position(glog, mother, 1, DDTranslation(), DDRotation());
1059 #ifdef EDM_ML_DEBUG
1060       edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << glog.name() << " Number 1 positioned in " << mother.name()
1061                                    << " at (0,0,0) with no rotation";
1062 #endif
1063       // Now the remaining absorber layers
1064       for (int i = 1; i < getMidAbsorber(); i++) {
1065         namek = name + getMidAbsName(i);
1066         rmid = rmin + getMidAbsT(i);
1067         pgonRmin[0] = rmin;
1068         pgonRmax[0] = rmid;
1069         pgonRmin[1] = rmin;
1070         pgonRmax[1] = rmid;
1071         pgonZ[1] = getZoff(in) + rmin * getTanTheta(in);
1072         pgonRmin[2] = rmid;
1073         pgonRmax[2] = rmid;
1074         pgonZ[2] = getZoff(in) + rmid * getTanTheta(in);
1075         alpha1 = atan(getMidAbsW(i) / rmin);
1076         solid =
1077             DDSolidFactory::polyhedra(DDName(namek, idNameSpace), 1, -alpha1, 2 * alpha1, pgonZ, pgonRmin, pgonRmax);
1078 #ifdef EDM_ML_DEBUG
1079         edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << solid.name() << " Polyhedra made of " << getMidAbsMat(i)
1080                                      << " with 1 sector from " << convertRadToDeg(-alpha1) << " to "
1081                                      << convertRadToDeg(alpha1) << " and with " << pgonZ.size() << " sections";
1082         for (unsigned int ii = 0; ii < pgonZ.size(); ii++)
1083           edm::LogVerbatim("HCalGeom") << "\t\tZ = " << pgonZ[ii] << "\tRmin = " << pgonRmin[ii]
1084                                        << "\tRmax = " << pgonRmax[ii];
1085 #endif
1086 
1087         DDName matName2(DDSplit(getMidAbsMat(i)).first, DDSplit(getMidAbsMat(i)).second);
1088         DDMaterial matter2(matName2);
1089         log = DDLogicalPart(solid.ddname(), matter2, solid);
1090 
1091         cpv.position(log, mother, i, DDTranslation(), DDRotation());
1092 #ifdef EDM_ML_DEBUG
1093         edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << log.name() << " Number " << i << " positioned in "
1094                                      << mother.name() << " at (0,0,0) with no "
1095                                      << "rotation";
1096 #endif
1097         mother = log;
1098       }
1099     }
1100   }
1101   return glog;
1102 }
1103 
1104 void DDHCalBarrelAlgo::constructInsideDetectors(const DDLogicalPart& detector,
1105                                                 const std::string& name,
1106                                                 int id,
1107                                                 double dx,
1108                                                 double dy,
1109                                                 double dz,
1110                                                 int type,
1111                                                 DDCompactView& cpv) {
1112 #ifdef EDM_ML_DEBUG
1113   edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: \t\tInside detector " << id << "...";
1114 #endif
1115 
1116   DDName plmatname(DDSplit(getDetMatPl()).first, DDSplit(getDetMatPl()).second);
1117   DDMaterial plmatter(plmatname);
1118   DDName scmatname(DDSplit(getDetMatSc()).first, DDSplit(getDetMatSc()).second);
1119   DDMaterial scmatter(scmatname);
1120 
1121   std::string plname = detector.name().name() + "Plastic_";
1122   std::string scname = idName + "Scintillator" + name;
1123 
1124   id--;
1125   DDSolid solid;
1126   DDLogicalPart glog;
1127   double wid, y = 0;
1128   double dx1, dx2, shiftX;
1129 
1130   if (type == 1) {
1131     wid = 0.5 * getDetWidth1(id);
1132     if (getDetPosY(id) > 0)
1133       y = -dy + wid;
1134     dx1 = 0.5 * getDetT11(id);
1135     dx2 = 0.5 * getDetT21(id);
1136     shiftX = getDetdP1(id);
1137   } else {
1138     wid = 0.5 * getDetWidth2(id);
1139     dx1 = 0.5 * getDetT12(id);
1140     dx2 = 0.5 * getDetT22(id);
1141     shiftX = getDetdP2(id);
1142   }
1143 
1144   solid = DDSolidFactory::box(DDName(plname + "1", idNameSpace), dx1, wid, dz);
1145 #ifdef EDM_ML_DEBUG
1146   edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << solid.name() << " Box made of " << getDetMatPl()
1147                                << " of dimensions " << dx1 << ", " << wid << ", " << dz;
1148 #endif
1149   glog = DDLogicalPart(solid.ddname(), plmatter, solid);
1150 
1151   double x = shiftX + dx1 - dx;
1152   cpv.position(glog, detector, 1, DDTranslation(x, y, 0), DDRotation());
1153 #ifdef EDM_ML_DEBUG
1154   edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << glog.name() << " Number 1 positioned in " << detector.name()
1155                                << " at (" << x << "," << y << ",0) with no rotation";
1156 #endif
1157   solid = DDSolidFactory::box(DDName(scname, idNameSpace), 0.5 * getDetTsc(id), wid, dz);
1158 #ifdef EDM_ML_DEBUG
1159   edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << solid.name() << " Box made of " << getDetMatSc()
1160                                << " of dimensions " << 0.5 * getDetTsc(id) << ", " << wid << ", " << dz;
1161 #endif
1162   glog = DDLogicalPart(solid.ddname(), scmatter, solid);
1163 
1164   x += dx1 + 0.5 * getDetTsc(id);
1165   int copyNo = id * 10 + getDetType(id);
1166   cpv.position(glog, detector, copyNo, DDTranslation(x, y, 0), DDRotation());
1167 #ifdef EDM_ML_DEBUG
1168   edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << glog.name() << " Number " << copyNo << " positioned in "
1169                                << detector.name() << " at (" << x << "," << y << ",0) with no rotation";
1170 #endif
1171   solid = DDSolidFactory::box(DDName(plname + "2", idNameSpace), dx2, wid, dz);
1172 #ifdef EDM_ML_DEBUG
1173   edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << solid.name() << " Box made of " << getDetMatPl()
1174                                << " of dimensions " << dx2 << ", " << wid << ", " << dz;
1175 #endif
1176   glog = DDLogicalPart(solid.ddname(), plmatter, solid);
1177 
1178   x += 0.5 * getDetTsc(id) + dx2;
1179   cpv.position(glog, detector, 1, DDTranslation(x, y, 0), DDRotation());
1180 #ifdef EDM_ML_DEBUG
1181   edm::LogVerbatim("HCalGeom") << "DDHCalBarrelAlgo: " << glog.name() << " Number 1 positioned in " << detector.name()
1182                                << " at (" << x << "," << y << ",0) with no rotation";
1183 #endif
1184 }
1185 
1186 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHCalBarrelAlgo, "hcal:DDHCalBarrelAlgo");