Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-05-10 02:20:48

0001 
0002 //////////////////////////////////////////////////////////////////////////////
0003 // File: DDEcalEndcapAlgo.cc
0004 // Description: Geometry factory class for Ecal Barrel
0005 ///////////////////////////////////////////////////////////////////////////////
0006 
0007 #include <cmath>
0008 #include <algorithm>
0009 
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0012 #include "DetectorDescription/Core/interface/DDSolid.h"
0013 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
0014 #include <CLHEP/Units/SystemOfUnits.h>
0015 
0016 #include <CLHEP/Geometry/Transform3D.h>
0017 
0018 // Header files for endcap supercrystal geometry
0019 #include "Geometry/EcalCommonData/interface/DDEcalEndcapTrap.h"
0020 
0021 #include <map>
0022 #include <string>
0023 #include <vector>
0024 #include "DetectorDescription/Core/interface/DDTypes.h"
0025 #include "DetectorDescription/Core/interface/DDName.h"
0026 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0027 #include "DetectorDescription/Core/interface/DDMaterial.h"
0028 #include "DetectorDescription/Core/interface/DDSplit.h"
0029 #include "DetectorDescription/Core/interface/DDTransform.h"
0030 #include "Geometry/CaloGeometry/interface/EcalTrapezoidParameters.h"
0031 #include <CLHEP/Geometry/Transform3D.h>
0032 
0033 using CLHEP::deg;
0034 using CLHEP::mm;
0035 //#define EDM_ML_DEBUG
0036 
0037 class DDEcalEndcapAlgo : public DDAlgorithm {
0038 public:
0039   typedef EcalTrapezoidParameters Trap;
0040   typedef HepGeom::Point3D<double> Pt3D;
0041   typedef HepGeom::Transform3D Tf3D;
0042   typedef HepGeom::ReflectZ3D RfZ3D;
0043   typedef HepGeom::Translate3D Tl3D;
0044   typedef HepGeom::Rotate3D Ro3D;
0045   typedef HepGeom::RotateZ3D RoZ3D;
0046   typedef HepGeom::RotateY3D RoY3D;
0047   typedef HepGeom::RotateX3D RoX3D;
0048 
0049   typedef CLHEP::Hep3Vector Vec3;
0050   typedef CLHEP::HepRotation Rota;
0051 
0052   //Constructor and Destructor
0053   DDEcalEndcapAlgo();
0054   ~DDEcalEndcapAlgo() override;
0055 
0056   void initialize(const DDNumericArguments& nArgs,
0057                   const DDVectorArguments& vArgs,
0058                   const DDMapArguments& mArgs,
0059                   const DDStringArguments& sArgs,
0060                   const DDStringVectorArguments& vsArgs) override;
0061   void execute(DDCompactView& cpv) override;
0062 
0063   //  New methods for SC geometry
0064   void EEPositionCRs(const DDName& pName, const DDTranslation& offset, const int iSCType, DDCompactView& cpv);
0065 
0066   void EECreateSC(const unsigned int iSCType, DDCompactView& cpv);
0067 
0068   void EECreateCR();
0069 
0070   void EEPosSC(const int iCol, const int iRow, DDName EEDeeName);
0071 
0072   unsigned int EEGetSCType(const unsigned int iCol, const unsigned int iRow);
0073 
0074   DDName EEGetSCName(const int iCol, const int iRow);
0075 
0076   std::vector<double> EEGetSCCtrs(const int iCol, const int iRow);
0077 
0078   DDMaterial ddmat(const std::string& s) const;
0079   DDName ddname(const std::string& s) const;
0080   DDRotation myrot(const std::string& s, const DDRotationMatrix& r) const;
0081 
0082   const std::string& idNameSpace() const { return m_idNameSpace; }
0083 
0084   // endcap parent volume
0085   DDMaterial eeMat() const { return ddmat(m_EEMat); }
0086   double eezOff() const { return m_EEzOff; }
0087 
0088   DDName eeQuaName() const { return ddname(m_EEQuaName); }
0089   DDMaterial eeQuaMat() const { return ddmat(m_EEQuaMat); }
0090 
0091   DDMaterial eeCrysMat() const { return ddmat(m_EECrysMat); }
0092   DDMaterial eeWallMat() const { return ddmat(m_EEWallMat); }
0093 
0094   double eeCrysLength() const { return m_EECrysLength; }
0095   double eeCrysRear() const { return m_EECrysRear; }
0096   double eeCrysFront() const { return m_EECrysFront; }
0097   double eeSCELength() const { return m_EESCELength; }
0098   double eeSCERear() const { return m_EESCERear; }
0099   double eeSCEFront() const { return m_EESCEFront; }
0100   double eeSCALength() const { return m_EESCALength; }
0101   double eeSCARear() const { return m_EESCARear; }
0102   double eeSCAFront() const { return m_EESCAFront; }
0103   double eeSCAWall() const { return m_EESCAWall; }
0104   double eeSCHLength() const { return m_EESCHLength; }
0105   double eeSCHSide() const { return m_EESCHSide; }
0106 
0107   double eenSCTypes() const { return m_EEnSCTypes; }
0108   double eenColumns() const { return m_EEnColumns; }
0109   double eenSCCutaway() const { return m_EEnSCCutaway; }
0110   double eenSCquad() const { return m_EEnSCquad; }
0111   double eenCRSC() const { return m_EEnCRSC; }
0112   const std::vector<double>& eevecEESCProf() const { return m_vecEESCProf; }
0113   const std::vector<double>& eevecEEShape() const { return m_vecEEShape; }
0114   const std::vector<double>& eevecEESCCutaway() const { return m_vecEESCCutaway; }
0115   const std::vector<double>& eevecEESCCtrs() const { return m_vecEESCCtrs; }
0116   const std::vector<double>& eevecEECRCtrs() const { return m_vecEECRCtrs; }
0117 
0118   DDName cutBoxName() const { return ddname(m_cutBoxName); }
0119   double eePFHalf() const { return m_PFhalf; }
0120   double eePFFifth() const { return m_PFfifth; }
0121   double eePF45() const { return m_PF45; }
0122 
0123   DDName envName(unsigned int i) const { return ddname(m_envName + std::to_string(i)); }
0124   DDName alvName(unsigned int i) const { return ddname(m_alvName + std::to_string(i)); }
0125   DDName intName(unsigned int i) const { return ddname(m_intName + std::to_string(i)); }
0126   DDName cryName() const { return ddname(m_cryName); }
0127 
0128   DDName addTmp(DDName aName) const { return ddname(aName.name() + "Tmp"); }
0129 
0130   const DDTranslation& cryFCtr(unsigned int iRow, unsigned int iCol) const { return m_cryFCtr[iRow - 1][iCol - 1]; }
0131 
0132   const DDTranslation& cryRCtr(unsigned int iRow, unsigned int iCol) const { return m_cryRCtr[iRow - 1][iCol - 1]; }
0133 
0134   const DDTranslation& scrFCtr(unsigned int iRow, unsigned int iCol) const { return m_scrFCtr[iRow - 1][iCol - 1]; }
0135 
0136   const DDTranslation& scrRCtr(unsigned int iRow, unsigned int iCol) const { return m_scrRCtr[iRow - 1][iCol - 1]; }
0137 
0138   const std::vector<double>& vecEESCLims() const { return m_vecEESCLims; }
0139 
0140   double iLength() const { return m_iLength; }
0141   double iXYOff() const { return m_iXYOff; }
0142 
0143 protected:
0144 private:
0145   std::string m_idNameSpace;  //Namespace of this and ALL sub-parts
0146 
0147   // Barrel volume
0148   std::string m_EEMat;
0149   double m_EEzOff;
0150 
0151   std::string m_EEQuaName;
0152   std::string m_EEQuaMat;
0153 
0154   std::string m_EECrysMat;
0155   std::string m_EEWallMat;
0156 
0157   double m_EECrysLength;
0158   double m_EECrysRear;
0159   double m_EECrysFront;
0160   double m_EESCELength;
0161   double m_EESCERear;
0162   double m_EESCEFront;
0163   double m_EESCALength;
0164   double m_EESCARear;
0165   double m_EESCAFront;
0166   double m_EESCAWall;
0167   double m_EESCHLength;
0168   double m_EESCHSide;
0169 
0170   double m_EEnSCTypes;
0171   std::vector<double> m_vecEESCProf;
0172   double m_EEnColumns;
0173   std::vector<double> m_vecEEShape;
0174   double m_EEnSCCutaway;
0175   std::vector<double> m_vecEESCCutaway;
0176   double m_EEnSCquad;
0177   std::vector<double> m_vecEESCCtrs;
0178   double m_EEnCRSC;
0179   std::vector<double> m_vecEECRCtrs;
0180 
0181   const std::vector<double>* m_cutParms;
0182   std::string m_cutBoxName;
0183 
0184   std::string m_envName;
0185   std::string m_alvName;
0186   std::string m_intName;
0187   std::string m_cryName;
0188 
0189   DDTranslation m_cryFCtr[5][5];
0190   DDTranslation m_cryRCtr[5][5];
0191 
0192   DDTranslation m_scrFCtr[10][10];
0193   DDTranslation m_scrRCtr[10][10];
0194 
0195   double m_PFhalf;
0196   double m_PFfifth;
0197   double m_PF45;
0198 
0199   std::vector<double> m_vecEESCLims;
0200 
0201   double m_iLength;
0202 
0203   double m_iXYOff;
0204 
0205   double m_cryZOff;
0206 
0207   double m_zFront;
0208 };
0209 
0210 namespace std {}
0211 using namespace std;
0212 
0213 DDEcalEndcapAlgo::DDEcalEndcapAlgo()
0214     : m_idNameSpace(""),
0215       m_EEMat(""),
0216       m_EEzOff(0),
0217       m_EEQuaName(""),
0218       m_EEQuaMat(""),
0219       m_EECrysMat(""),
0220       m_EEWallMat(""),
0221       m_EECrysLength(0),
0222       m_EECrysRear(0),
0223       m_EECrysFront(0),
0224       m_EESCELength(0),
0225       m_EESCERear(0),
0226       m_EESCEFront(0),
0227       m_EESCALength(0),
0228       m_EESCARear(0),
0229       m_EESCAFront(0),
0230       m_EESCAWall(0),
0231       m_EESCHLength(0),
0232       m_EESCHSide(0),
0233       m_EEnSCTypes(0),
0234       m_vecEESCProf(),
0235       m_EEnColumns(0),
0236       m_vecEEShape(),
0237       m_EEnSCCutaway(0),
0238       m_vecEESCCutaway(),
0239       m_EEnSCquad(0),
0240       m_vecEESCCtrs(),
0241       m_EEnCRSC(0),
0242       m_vecEECRCtrs(),
0243       m_cutParms(nullptr),
0244       m_cutBoxName(""),
0245       m_envName(""),
0246       m_alvName(""),
0247       m_intName(""),
0248       m_cryName(""),
0249       m_PFhalf(0),
0250       m_PFfifth(0),
0251       m_PF45(0),
0252       m_vecEESCLims(),
0253       m_iLength(0),
0254       m_iXYOff(0),
0255       m_cryZOff(0),
0256       m_zFront(0) {
0257   edm::LogVerbatim("EcalGeomX") << "DDEcalEndcapAlgo info: Creating an instance";
0258 }
0259 
0260 DDEcalEndcapAlgo::~DDEcalEndcapAlgo() {}
0261 
0262 void DDEcalEndcapAlgo::initialize(const DDNumericArguments& nArgs,
0263                                   const DDVectorArguments& vArgs,
0264                                   const DDMapArguments& /*mArgs*/,
0265                                   const DDStringArguments& sArgs,
0266                                   const DDStringVectorArguments& /*vsArgs*/) {
0267 #ifdef EDM_ML_DEBUG
0268   edm::LogVerbatim("EcalGeomX") << "DDEcalEndcapAlgo info: Initialize";
0269 #endif
0270   m_idNameSpace = DDCurrentNamespace::ns();
0271   // TRICK!
0272   m_idNameSpace = parent().name().ns();
0273   // barrel parent volume
0274   m_EEMat = sArgs["EEMat"];
0275   m_EEzOff = nArgs["EEzOff"];
0276 
0277   m_EEQuaName = sArgs["EEQuaName"];
0278   m_EEQuaMat = sArgs["EEQuaMat"];
0279   m_EECrysMat = sArgs["EECrysMat"];
0280   m_EEWallMat = sArgs["EEWallMat"];
0281   m_EECrysLength = nArgs["EECrysLength"];
0282   m_EECrysRear = nArgs["EECrysRear"];
0283   m_EECrysFront = nArgs["EECrysFront"];
0284   m_EESCELength = nArgs["EESCELength"];
0285   m_EESCERear = nArgs["EESCERear"];
0286   m_EESCEFront = nArgs["EESCEFront"];
0287   m_EESCALength = nArgs["EESCALength"];
0288   m_EESCARear = nArgs["EESCARear"];
0289   m_EESCAFront = nArgs["EESCAFront"];
0290   m_EESCAWall = nArgs["EESCAWall"];
0291   m_EESCHLength = nArgs["EESCHLength"];
0292   m_EESCHSide = nArgs["EESCHSide"];
0293   m_EEnSCTypes = nArgs["EEnSCTypes"];
0294   m_EEnColumns = nArgs["EEnColumns"];
0295   m_EEnSCCutaway = nArgs["EEnSCCutaway"];
0296   m_EEnSCquad = nArgs["EEnSCquad"];
0297   m_EEnCRSC = nArgs["EEnCRSC"];
0298   m_vecEESCProf = vArgs["EESCProf"];
0299   m_vecEEShape = vArgs["EEShape"];
0300   m_vecEESCCutaway = vArgs["EESCCutaway"];
0301   m_vecEESCCtrs = vArgs["EESCCtrs"];
0302   m_vecEECRCtrs = vArgs["EECRCtrs"];
0303 
0304   m_cutBoxName = sArgs["EECutBoxName"];
0305 
0306   m_envName = sArgs["EEEnvName"];
0307   m_alvName = sArgs["EEAlvName"];
0308   m_intName = sArgs["EEIntName"];
0309   m_cryName = sArgs["EECryName"];
0310 
0311   m_PFhalf = nArgs["EEPFHalf"];
0312   m_PFfifth = nArgs["EEPFFifth"];
0313   m_PF45 = nArgs["EEPF45"];
0314 
0315   m_vecEESCLims = vArgs["EESCLims"];
0316 
0317   m_iLength = nArgs["EEiLength"];
0318 
0319   m_iXYOff = nArgs["EEiXYOff"];
0320 
0321   m_cryZOff = nArgs["EECryZOff"];
0322 
0323   m_zFront = nArgs["EEzFront"];
0324 }
0325 
0326 ////////////////////////////////////////////////////////////////////
0327 // DDEcalEndcapAlgo methods...
0328 ////////////////////////////////////////////////////////////////////
0329 
0330 DDRotation DDEcalEndcapAlgo::myrot(const std::string& s, const DDRotationMatrix& r) const {
0331   return DDrot(ddname(m_idNameSpace + ":" + s), std::make_unique<DDRotationMatrix>(r));
0332 }
0333 
0334 DDMaterial DDEcalEndcapAlgo::ddmat(const std::string& s) const { return DDMaterial(ddname(s)); }
0335 
0336 DDName DDEcalEndcapAlgo::ddname(const std::string& s) const {
0337   const pair<std::string, std::string> temp(DDSplit(s));
0338   if (temp.second.empty()) {
0339     return DDName(temp.first, m_idNameSpace);
0340   } else {
0341     return DDName(temp.first, temp.second);
0342   }
0343 }
0344 
0345 //-------------------- Endcap SC geometry methods ---------------------
0346 
0347 void DDEcalEndcapAlgo::execute(DDCompactView& cpv) {
0348   //  Position supercrystals in EE Quadrant
0349   //  Version:    1.00
0350   //  Created:    30 July 2007
0351   //  Last Mod:
0352   //---------------------------------------------------------------------
0353 
0354   //********************************* cutbox for trimming edge SCs
0355   const double cutWid(eeSCERear() / sqrt(2.));
0356   const DDSolid eeCutBox(DDSolidFactory::box(cutBoxName(), cutWid, cutWid, eeSCELength() / sqrt(2.)));
0357   m_cutParms = &eeCutBox.parameters();
0358   //**************************************************************
0359 
0360   const double zFix(m_zFront - 3172.0 * mm);  // fix for changing z offset
0361 
0362   //** fill supercrystal front and rear center positions from xml input
0363   for (unsigned int iC(0); iC != (unsigned int)eenSCquad(); ++iC) {
0364     const unsigned int iOff(8 * iC);
0365     const unsigned int ix((unsigned int)eevecEESCCtrs()[iOff + 0]);
0366     const unsigned int iy((unsigned int)eevecEESCCtrs()[iOff + 1]);
0367 
0368     assert(ix > 0 && ix < 11 && iy > 0 && iy < 11);
0369 
0370     m_scrFCtr[ix - 1][iy - 1] =
0371         DDTranslation(eevecEESCCtrs()[iOff + 2], eevecEESCCtrs()[iOff + 4], eevecEESCCtrs()[iOff + 6] + zFix);
0372 
0373     m_scrRCtr[ix - 1][iy - 1] =
0374         DDTranslation(eevecEESCCtrs()[iOff + 3], eevecEESCCtrs()[iOff + 5], eevecEESCCtrs()[iOff + 7] + zFix);
0375   }
0376 
0377   //** fill crystal front and rear center positions from xml input
0378   for (unsigned int iC(0); iC != 25; ++iC) {
0379     const unsigned int iOff(8 * iC);
0380     const unsigned int ix((unsigned int)eevecEECRCtrs()[iOff + 0]);
0381     const unsigned int iy((unsigned int)eevecEECRCtrs()[iOff + 1]);
0382 
0383     assert(ix > 0 && ix < 6 && iy > 0 && iy < 6);
0384 
0385     m_cryFCtr[ix - 1][iy - 1] =
0386         DDTranslation(eevecEECRCtrs()[iOff + 2], eevecEECRCtrs()[iOff + 4], eevecEECRCtrs()[iOff + 6]);
0387 
0388     m_cryRCtr[ix - 1][iy - 1] =
0389         DDTranslation(eevecEECRCtrs()[iOff + 3], eevecEECRCtrs()[iOff + 5], eevecEECRCtrs()[iOff + 7]);
0390   }
0391 
0392   EECreateCR();  // make a single crystal just once here
0393 
0394   for (unsigned int isc(0); isc < eenSCTypes(); ++isc) {
0395     EECreateSC(isc + 1, cpv);
0396   }
0397 
0398   const std::vector<double>& colLimits(eevecEEShape());
0399   //** Loop over endcap columns
0400   for (int icol = 1; icol <= int(eenColumns()); icol++) {
0401     //**  Loop over SCs in column, using limits from xml input
0402     for (int irow = int(colLimits[2 * icol - 2]); irow <= int(colLimits[2 * icol - 1]); ++irow) {
0403       if (vecEESCLims()[0] <= icol && vecEESCLims()[1] >= icol && vecEESCLims()[2] <= irow &&
0404           vecEESCLims()[3] >= irow) {
0405         // Find SC type (complete or partial) for this location
0406         const unsigned int isctype(EEGetSCType(icol, irow));
0407 
0408         // Create SC as a DDEcalEndcapTrap object and calculate rotation and
0409         // translation required to position it in the endcap.
0410         DDEcalEndcapTrap scrys(1, eeSCEFront(), eeSCERear(), eeSCELength());
0411 
0412         scrys.moveto(scrFCtr(icol, irow), scrRCtr(icol, irow));
0413         scrys.translate(DDTranslation(0., 0., -eezOff()));
0414 
0415         DDName rname(envName(isctype).name() + std::to_string(icol) + "R" + std::to_string(irow));
0416 
0417 #ifdef EDM_ML_DEBUG
0418         edm::LogVerbatim("EcalGeoXm") << "Quadrant, SC col/row " << eeQuaName() << " " << icol << " / " << irow
0419                                       << std::endl
0420                                       << "   Limits " << int(colLimits[2 * icol - 2]) << "->"
0421                                       << int(colLimits[2 * icol - 1]) << std::endl
0422                                       << "   SC type = " << isctype << std::endl
0423                                       << "   Zoff = " << eezOff() << std::endl
0424                                       << "   Rotation " << rname << " " << scrys.rotation() << std::endl
0425                                       << "   Position " << scrys.centrePos();
0426 #endif
0427         // Position SC in endcap
0428         cpv.position(envName(isctype),
0429                      eeQuaName(),
0430                      100 * isctype + 10 * (icol - 1) + (irow - 1),
0431                      scrys.centrePos(),
0432                      myrot(rname.fullname(), scrys.rotation()));
0433 #ifdef EDM_ML_DEBUG
0434         edm::LogVerbatim("EEGeom") << envName(isctype) << " " << (100 * isctype + 10 * (icol - 1) + (irow - 1))
0435                                    << " in " << eeQuaName();
0436         edm::LogVerbatim("EcalGeom") << envName(isctype) << " " << (100 * isctype + 10 * (icol - 1) + (irow - 1))
0437                                      << " in " << eeQuaName() << " at " << scrys.centrePos();
0438 #endif
0439       }
0440     }
0441   }
0442 }
0443 
0444 void DDEcalEndcapAlgo::EECreateSC(const unsigned int iSCType,
0445                                   DDCompactView& cpv) {  //  EECreateSCType   Create SC logical volume of the given type
0446 
0447   DDRotation noRot;
0448   DDLogicalPart eeSCELog;
0449   DDLogicalPart eeSCALog;
0450   DDLogicalPart eeSCILog;
0451 
0452 #ifdef EDM_ML_DEBUG
0453   edm::LogVerbatim("EcalGeomX") << "EECreateSC: Creating SC envelope";
0454 #endif
0455   const string anum(std::to_string(iSCType));
0456 
0457   const double eFront(0.5 * eeSCEFront());
0458   const double eRear(0.5 * eeSCERear());
0459   const double eAng(atan((eeSCERear() - eeSCEFront()) / (sqrt(2.) * eeSCELength())));
0460   const double ffived(45 * deg);
0461   const double zerod(0 * deg);
0462   DDSolid eeSCEnv(DDSolidFactory::trap((1 == iSCType ? envName(iSCType) : addTmp(envName(iSCType))),
0463                                        0.5 * eeSCELength(),
0464                                        eAng,
0465                                        ffived,
0466                                        eFront,
0467                                        eFront,
0468                                        eFront,
0469                                        zerod,
0470                                        eRear,
0471                                        eRear,
0472                                        eRear,
0473                                        zerod));
0474 #ifdef EDM_ML_DEBUG
0475   edm::LogVerbatim("EcalGeom") << eeSCEnv.name() << " Trap with parameters: " << 0.5 * eeSCELength() << ":" << eAng
0476                                << ffived << ":" << eFront << ":" << eFront << ":" << eFront << ":" << zerod << ":"
0477                                << eRear << ":" << eRear << ":" << eRear << ":" << zerod;
0478 #endif
0479 
0480   const double aFront(0.5 * eeSCAFront());
0481   const double aRear(0.5 * eeSCARear());
0482   const double aAng(atan((eeSCARear() - eeSCAFront()) / (sqrt(2.) * eeSCALength())));
0483   const DDSolid eeSCAlv(DDSolidFactory::trap((1 == iSCType ? alvName(iSCType) : addTmp(alvName(iSCType))),
0484                                              0.5 * eeSCALength(),
0485                                              aAng,
0486                                              ffived,
0487                                              aFront,
0488                                              aFront,
0489                                              aFront,
0490                                              zerod,
0491                                              aRear,
0492                                              aRear,
0493                                              aRear,
0494                                              zerod));
0495 #ifdef EDM_ML_DEBUG
0496   edm::LogVerbatim("EcalGeom") << eeSCAlv.name() << " Trap with parameters: " << 0.5 * eeSCALength() << ":" << aAng
0497                                << ":" << ffived << ":" << aFront << ":" << aFront << ":" << aFront << ":" << zerod
0498                                << ":" << aRear << ":" << aRear << ":" << aRear << ":" << zerod;
0499 #endif
0500   const double dwall(eeSCAWall());
0501   const double iFront(aFront - dwall);
0502   const double iRear(iFront);    //aRear  - dwall ) ;
0503   const double iLen(iLength());  //0.075*eeSCALength() ) ;
0504   const DDSolid eeSCInt(DDSolidFactory::trap((1 == iSCType ? intName(iSCType) : addTmp(intName(iSCType))),
0505                                              iLen / 2.,
0506                                              atan((eeSCARear() - eeSCAFront()) / (sqrt(2.) * eeSCALength())),
0507                                              ffived,
0508                                              iFront,
0509                                              iFront,
0510                                              iFront,
0511                                              zerod,
0512                                              iRear,
0513                                              iRear,
0514                                              iRear,
0515                                              zerod));
0516 #ifdef EDM_ML_DEBUG
0517   edm::LogVerbatim("EcalGeom") << eeSCInt.name() << " Trap with parameters: " << iLen / 2. << ":"
0518                                << (atan((eeSCARear() - eeSCAFront()) / (sqrt(2.) * eeSCALength()))) << ":" << ffived
0519                                << ":" << iFront << ":" << iFront << ":" << iFront << ":" << zerod << ":" << iRear << ":"
0520                                << iRear << ":" << iRear << ":" << zerod;
0521 #endif
0522   const double dz(-0.5 * (eeSCELength() - eeSCALength()));
0523   const double dxy(0.5 * dz * (eeSCERear() - eeSCEFront()) / eeSCELength());
0524   const double zIOff(-(eeSCALength() - iLen) / 2.);
0525   const double xyIOff(iXYOff());
0526 
0527   if (1 == iSCType)  // standard SC in this block
0528   {
0529     eeSCELog = DDLogicalPart(envName(iSCType), eeMat(), eeSCEnv);
0530     eeSCALog = DDLogicalPart(alvName(iSCType), eeWallMat(), eeSCAlv);
0531     eeSCILog = DDLogicalPart(intName(iSCType), eeMat(), eeSCInt);
0532   } else  // partial SCs this block: create subtraction volumes as appropriate
0533   {
0534     const double half((*m_cutParms)[0] - eePFHalf() * eeCrysRear());
0535     const double fifth((*m_cutParms)[0] + eePFFifth() * eeCrysRear());
0536     const double fac(eePF45());
0537 
0538     const double zmm(0 * mm);
0539 
0540     DDTranslation cutTra(
0541         2 == iSCType ? DDTranslation(zmm, half, zmm)
0542                      : (3 == iSCType ? DDTranslation(half, zmm, zmm)
0543                                      : (4 == iSCType ? DDTranslation(zmm, -fifth, zmm)
0544                                                      : (5 == iSCType ? DDTranslation(-half * fac, -half * fac, zmm)
0545                                                                      : DDTranslation(-fifth, zmm, zmm)))));
0546 
0547     const CLHEP::HepRotationZ cutm(ffived);
0548 
0549     DDRotation cutRot(5 != iSCType ? noRot
0550                                    : myrot("EECry5Rot",
0551                                            DDRotationMatrix(cutm.xx(),
0552                                                             cutm.xy(),
0553                                                             cutm.xz(),
0554                                                             cutm.yx(),
0555                                                             cutm.yy(),
0556                                                             cutm.yz(),
0557                                                             cutm.zx(),
0558                                                             cutm.zy(),
0559                                                             cutm.zz())));
0560 
0561     DDSolid eeCutEnv(
0562         DDSolidFactory::subtraction(envName(iSCType), addTmp(envName(iSCType)), cutBoxName(), cutTra, cutRot));
0563 #ifdef EDM_ML_DEBUG
0564     edm::LogVerbatim("EcalGeom") << eeCutEnv.name() << " Subtracted by " << (eeSCERear() / sqrt(2.)) << ":"
0565                                  << (eeSCERear() / sqrt(2.)) << ":" << (eeSCELength() / sqrt(2.));
0566 #endif
0567     const DDTranslation extra(dxy, dxy, dz);
0568 
0569     DDSolid eeCutAlv(
0570         DDSolidFactory::subtraction(alvName(iSCType), addTmp(alvName(iSCType)), cutBoxName(), cutTra - extra, cutRot));
0571 
0572 #ifdef EDM_ML_DEBUG
0573     edm::LogVerbatim("EcalGeom") << eeCutAlv.name() << " Subtracted by " << (eeSCERear() / sqrt(2.)) << ":"
0574                                  << (eeSCERear() / sqrt(2.)) << ":" << (eeSCELength() / sqrt(2.));
0575 #endif
0576     const double mySign(iSCType < 4 ? +1. : -1.);
0577 
0578     const DDTranslation extraI(xyIOff + mySign * 2 * mm, xyIOff + mySign * 2 * mm, zIOff);
0579 
0580     DDSolid eeCutInt(
0581         DDSolidFactory::subtraction(intName(iSCType), addTmp(intName(iSCType)), cutBoxName(), cutTra - extraI, cutRot));
0582 #ifdef EDM_ML_DEBUG
0583     edm::LogVerbatim("EcalGeom") << eeCutInt.name() << " Subtracted by " << (eeSCERear() / sqrt(2.)) << ":"
0584                                  << (eeSCERear() / sqrt(2.)) << ":" << (eeSCELength() / sqrt(2.));
0585 #endif
0586 
0587     eeSCELog = DDLogicalPart(envName(iSCType), eeMat(), eeCutEnv);
0588     eeSCALog = DDLogicalPart(alvName(iSCType), eeWallMat(), eeCutAlv);
0589     eeSCILog = DDLogicalPart(intName(iSCType), eeMat(), eeCutInt);
0590   }
0591 
0592   cpv.position(eeSCALog, envName(iSCType), iSCType * 100 + 1, DDTranslation(dxy, dxy, dz), noRot);
0593   cpv.position(eeSCILog, alvName(iSCType), iSCType * 100 + 1, DDTranslation(xyIOff, xyIOff, zIOff), noRot);
0594 #ifdef EDM_ML_DEBUG
0595   edm::LogVerbatim("EEGeom") << eeSCALog.name() << " " << (iSCType * 100 + 1) << " in " << envName(iSCType);
0596   edm::LogVerbatim("EEGeom") << eeSCILog.name() << " " << (iSCType * 100 + 1) << " in " << alvName(iSCType);
0597   edm::LogVerbatim("EcalGeom") << eeSCALog.name() << " " << (iSCType * 100 + 1) << " in " << envName(iSCType) << " at ("
0598                                << dxy << ", " << dxy << ", " << dz << ")";
0599   edm::LogVerbatim("EcalGeom") << eeSCILog.name() << " " << (iSCType * 100 + 1) << " in " << alvName(iSCType) << " at ("
0600                                << xyIOff << ", " << xyIOff << ", " << zIOff << ")";
0601 #endif
0602   DDTranslation croffset(0., 0., 0.);
0603   EEPositionCRs(alvName(iSCType), croffset, iSCType, cpv);
0604 }
0605 
0606 unsigned int DDEcalEndcapAlgo::EEGetSCType(const unsigned int iCol, const unsigned int iRow) {
0607   unsigned int iType = 1;
0608   for (unsigned int ii = 0; ii < (unsigned int)(eenSCCutaway()); ++ii) {
0609     if ((eevecEESCCutaway()[3 * ii] == iCol) && (eevecEESCCutaway()[3 * ii + 1] == iRow)) {
0610       iType = int(eevecEESCCutaway()[3 * ii + 2]);
0611 #ifdef EDM_ML_DEBUG
0612       edm::LogVerbatim("EcalGeomX") << "EEGetSCType: col, row, type = " << iCol << " " << iRow << " " << iType;
0613 #endif
0614     }
0615   }
0616   return iType;
0617 }
0618 
0619 void DDEcalEndcapAlgo::EECreateCR() {
0620   //  EECreateCR   Create endcap crystal logical volume
0621 
0622 #ifdef EDM_ML_DEBUG
0623   edm::LogVerbatim("EcalGeomX") << "EECreateCR:  = ";
0624 #endif
0625   DDSolid EECRSolid(DDSolidFactory::trap(cryName(),
0626                                          0.5 * eeCrysLength(),
0627                                          atan((eeCrysRear() - eeCrysFront()) / (sqrt(2.) * eeCrysLength())),
0628                                          45. * deg,
0629                                          0.5 * eeCrysFront(),
0630                                          0.5 * eeCrysFront(),
0631                                          0.5 * eeCrysFront(),
0632                                          0. * deg,
0633                                          0.5 * eeCrysRear(),
0634                                          0.5 * eeCrysRear(),
0635                                          0.5 * eeCrysRear(),
0636                                          0. * deg));
0637 #ifdef EDM_ML_DEBUG
0638   edm::LogVerbatim("EcalGeom") << EECRSolid.name() << " Trap with parameters: " << 0.5 * eeCrysLength() << ":"
0639                                << (atan((eeCrysRear() - eeCrysFront()) / (sqrt(2.) * eeCrysLength()))) << ":"
0640                                << 45. * deg << ":" << 0.5 * eeCrysFront() << ":" << 0.5 * eeCrysFront() << ":"
0641                                << 0.5 * eeCrysFront() << ":" << 0. * deg << ":" << 0.5 * eeCrysRear() << ":"
0642                                << 0.5 * eeCrysRear() << ":" << 0.5 * eeCrysRear() << ":" << 0. * deg;
0643 #endif
0644 
0645   DDLogicalPart part(cryName(), eeCrysMat(), EECRSolid);
0646 }
0647 
0648 void DDEcalEndcapAlgo::EEPositionCRs(const DDName& pName,
0649                                      const DDTranslation& /*offset*/,
0650                                      const int iSCType,
0651                                      DDCompactView& cpv) {
0652   //  EEPositionCRs Position crystals within parent supercrystal interior volume
0653 
0654 #ifdef EDM_ML_DEBUG
0655   edm::LogVerbatim("EcalGeomX") << "EEPositionCRs called ";
0656 #endif
0657   static const unsigned int ncol(5);
0658 
0659   if (iSCType > 0 && iSCType <= eenSCTypes()) {
0660     const unsigned int icoffset((iSCType - 1) * ncol - 1);
0661 
0662     // Loop over columns of SC
0663     for (unsigned int icol(1); icol <= ncol; ++icol) {
0664       // Get column limits for this SC type from xml input
0665       const int ncrcol((int)eevecEESCProf()[icoffset + icol]);
0666 
0667       const int imin(0 < ncrcol ? 1 : (0 > ncrcol ? ncol + ncrcol + 1 : 0));
0668       const int imax(0 < ncrcol ? ncrcol : (0 > ncrcol ? ncol : 0));
0669 
0670       if (imax > 0) {
0671         // Loop over crystals in this row
0672         for (int irow(imin); irow <= imax; ++irow) {
0673 #ifdef EDM_ML_DEBUG
0674           edm::LogVerbatim("EcalGeomX") << " type, col, row " << iSCType << " " << icol << " " << irow;
0675 #endif
0676           // Create crystal as a DDEcalEndcapTrap object and calculate rotation and
0677           // translation required to position it in the SC.
0678           DDEcalEndcapTrap crystal(1, eeCrysFront(), eeCrysRear(), eeCrysLength());
0679 
0680           crystal.moveto(cryFCtr(icol, irow), cryRCtr(icol, irow));
0681 
0682           DDName rname("EECrRoC" + std::to_string(icol) + "R" + std::to_string(irow));
0683 
0684           cpv.position(cryName(),
0685                        pName,
0686                        100 * iSCType + 10 * (icol - 1) + (irow - 1),
0687                        crystal.centrePos() - DDTranslation(0, 0, m_cryZOff),
0688                        myrot(rname.fullname(), crystal.rotation()));
0689 #ifdef EDM_ML_DEBUG
0690           edm::LogVerbatim("EEGeom") << cryName() << " " << (100 * iSCType + 10 * (icol - 1) + (irow - 1)) << " in "
0691                                      << pName;
0692           edm::LogVerbatim("EcalGeom") << cryName() << " " << (100 * iSCType + 10 * (icol - 1) + (irow - 1)) << " in "
0693                                        << pName << " at " << (crystal.centrePos() - DDTranslation(0, 0, m_cryZOff));
0694 #endif
0695         }
0696       }
0697     }
0698   }
0699 }
0700 
0701 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0702 
0703 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDEcalEndcapAlgo, "ecal:DDEcalEndcapAlgo");