Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-06-13 03:23:46

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // File: DDHGCalPassive.cc
0003 // Description: Makes layers of passive in the size of cassette
0004 // Created by Sunanda Banerjee
0005 ///////////////////////////////////////////////////////////////////////////////
0006 #include "DataFormats/Math/interface/angle_units.h"
0007 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0008 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0009 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
0010 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0011 #include "DetectorDescription/Core/interface/DDMaterial.h"
0012 #include "DetectorDescription/Core/interface/DDSolid.h"
0013 #include "DetectorDescription/Core/interface/DDSplit.h"
0014 #include "DetectorDescription/Core/interface/DDTypes.h"
0015 #include "DetectorDescription/Core/interface/DDutils.h"
0016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0017 #include "FWCore/PluginManager/interface/PluginFactory.h"
0018 #include "Geometry/HGCalCommonData/interface/HGCalGeomTools.h"
0019 
0020 #include <string>
0021 #include <vector>
0022 #include <sstream>
0023 
0024 // #define EDM_ML_DEBUG
0025 
0026 using namespace angle_units::operators;
0027 
0028 class DDHGCalPassive : public DDAlgorithm {
0029 public:
0030   // Constructor and Destructor
0031   DDHGCalPassive();
0032   ~DDHGCalPassive() override = default;
0033 
0034   void initialize(const DDNumericArguments& nArgs,
0035                   const DDVectorArguments& vArgs,
0036                   const DDMapArguments& mArgs,
0037                   const DDStringArguments& sArgs,
0038                   const DDStringVectorArguments& vsArgs) override;
0039   void execute(DDCompactView& cpv) override;
0040 
0041 private:
0042   std::string material_;                 // Material name for mother volume
0043   double thick_;                         // Thickness of the section
0044   double zMinBlock_;                     // z-position of the first layer
0045   double moduleThick_;                   // Thickness of the overall module
0046   std::vector<std::string> tagLayer_;    // Tag of the layer (to be added to name)
0047   int sectors_;                          // Number of phi sectors (cassettes)
0048   int parts_;                            // number of parts in units of 30 degree
0049   std::vector<std::string> tagSector_;   // Tag of the sector (to be added to name)
0050   double phi0_;                          // Start phi of the first cassette
0051   double dphi_;                          // delta phi of the cassette
0052   double shiftTop_;                      // Tolerance at the top
0053   double shiftBot_;                      // Tolerance at the bottom
0054   std::vector<std::string> layerNames_;  // Names of the layers
0055   std::vector<std::string> materials_;   // Materials of the layers
0056   std::vector<double> layerThick_;       // Thickness of layers
0057   std::vector<int> layerType_;           // Layer types
0058   std::vector<double> slopeB_;           // Slope at the lower R
0059   std::vector<double> zFrontB_;          // Starting Z values for the slopes
0060   std::vector<double> rMinFront_;        // Corresponding rMin's
0061   std::vector<double> slopeT_;           // Slopes at the larger R
0062   std::vector<double> zFrontT_;          // Starting Z values for the slopes
0063   std::vector<double> rMaxFront_;        // Corresponding rMax's
0064 };
0065 
0066 DDHGCalPassive::DDHGCalPassive() {
0067 #ifdef EDM_ML_DEBUG
0068   edm::LogVerbatim("HGCalGeom") << "DDHGCalPassive: Creating an instance";
0069 #endif
0070 }
0071 
0072 void DDHGCalPassive::initialize(const DDNumericArguments& nArgs,
0073                                 const DDVectorArguments& vArgs,
0074                                 const DDMapArguments&,
0075                                 const DDStringArguments& sArgs,
0076                                 const DDStringVectorArguments& vsArgs) {
0077   material_ = sArgs["ModuleMaterial"];
0078   thick_ = nArgs["Thickness"];
0079   zMinBlock_ = nArgs["zMinBlock"];
0080   moduleThick_ = nArgs["ModuleThick"];
0081   tagLayer_ = vsArgs["TagLayer"];
0082   tagSector_ = vsArgs["TagSector"];
0083   parts_ = static_cast<int>(nArgs["Parts"]);
0084   phi0_ = convertDegToRad(nArgs["PhiStart"]);
0085   dphi_ = (2._pi) / tagSector_.size();
0086 #ifdef EDM_ML_DEBUG
0087   edm::LogVerbatim("HGCalGeom") << "DDHGCalPassive: " << tagLayer_.size() << " Modules with base name "
0088                                 << parent().name() << " made of " << material_ << " T " << thick_ << " Sectors "
0089                                 << tagSector_.size() << " Parts " << parts_ << " phi0 " << convertRadToDeg(phi0_);
0090   for (unsigned int i = 0; i < tagLayer_.size(); ++i)
0091     edm::LogVerbatim("HGCalGeom") << "Layer " << i << " Tag " << tagLayer_[i] << " T " << moduleThick_;
0092   for (unsigned int i = 0; i < tagSector_.size(); ++i)
0093     edm::LogVerbatim("HGCalGeom") << "Sector " << i << " Tag " << tagSector_[i] << " W " << convertRadToDeg(dphi_);
0094 #endif
0095 
0096   layerNames_ = vsArgs["LayerNames"];
0097   materials_ = vsArgs["LayerMaterials"];
0098   layerThick_ = vArgs["LayerThickness"];
0099 #ifdef EDM_ML_DEBUG
0100   edm::LogVerbatim("HGCalGeom") << "DDHGCalPassive: " << layerNames_.size() << " types of volumes";
0101   for (unsigned int i = 0; i < layerNames_.size(); ++i)
0102     edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << layerNames_[i] << " of thickness " << layerThick_[i]
0103                                   << " filled with " << materials_[i];
0104 #endif
0105   layerType_ = dbl_to_int(vArgs["LayerType"]);
0106 #ifdef EDM_ML_DEBUG
0107   std::ostringstream st1;
0108   for (unsigned int i = 0; i < layerType_.size(); ++i)
0109     st1 << " [" << i << "] " << layerType_[i];
0110   edm::LogVerbatim("HGCalGeom") << "There are " << layerType_.size() << " blocks" << st1.str();
0111 #endif
0112 
0113   shiftTop_ = nArgs["ShiftTop"];
0114   shiftBot_ = nArgs["ShiftBottom"];
0115 #ifdef EDM_ML_DEBUG
0116   edm::LogVerbatim("HGCalGeom") << "Shifts st the top " << shiftTop_ << " and at the bottom " << shiftBot_;
0117 #endif
0118   slopeB_ = vArgs["SlopeBottom"];
0119   zFrontB_ = vArgs["ZFrontBottom"];
0120   rMinFront_ = vArgs["RMinFront"];
0121   slopeT_ = vArgs["SlopeTop"];
0122   zFrontT_ = vArgs["ZFrontTop"];
0123   rMaxFront_ = vArgs["RMaxFront"];
0124 #ifdef EDM_ML_DEBUG
0125   for (unsigned int i = 0; i < slopeB_.size(); ++i)
0126     edm::LogVerbatim("HGCalGeom") << "Bottom Block [" << i << "] Zmin " << zFrontB_[i] << " Rmin " << rMinFront_[i]
0127                                   << " Slope " << slopeB_[i];
0128   for (unsigned int i = 0; i < slopeT_.size(); ++i)
0129     edm::LogVerbatim("HGCalGeom") << "Top Block [" << i << "] Zmin " << zFrontT_[i] << " Rmax " << rMaxFront_[i]
0130                                   << " Slope " << slopeT_[i];
0131 #endif
0132 }
0133 
0134 void DDHGCalPassive::execute(DDCompactView& cpv) {
0135 #ifdef EDM_ML_DEBUG
0136   edm::LogVerbatim("HGCalGeom") << "==>> Executing DDHGCalPassive...";
0137 #endif
0138 
0139   static constexpr double tol = 0.00001;
0140 
0141   // Loop over Layers
0142   double zim(zMinBlock_);
0143   //Loop over layers
0144   for (unsigned int j = 0; j < tagLayer_.size(); ++j) {
0145     double routF = HGCalGeomTools::radius(zim, zFrontT_, rMaxFront_, slopeT_) - shiftTop_;
0146     double zo = zim + moduleThick_;
0147     double rinB = HGCalGeomTools::radius(zo, zFrontB_, rMinFront_, slopeB_) + shiftBot_;
0148     zim += moduleThick_;
0149     for (unsigned int k = 0; k < tagSector_.size(); ++k) {
0150       std::string parentName = parent().name().name() + tagLayer_[j] + tagSector_[k];
0151       double phi1 = phi0_ + k * dphi_;
0152       double phi2 = phi1 + dphi_;
0153       double phi0 = phi1 + 0.5 * dphi_;
0154       // First the mother
0155       std::vector<double> xM, yM;
0156       if (parts_ == 1) {
0157         xM = {rinB * cos(phi1), routF * cos(phi1), routF * cos(phi2), rinB * cos(phi2)};
0158         yM = {rinB * sin(phi1), routF * sin(phi1), routF * sin(phi2), rinB * sin(phi2)};
0159       } else {
0160         xM = {rinB * cos(phi1),
0161               routF * cos(phi1),
0162               routF * cos(phi0),
0163               routF * cos(phi2),
0164               rinB * cos(phi2),
0165               rinB * cos(phi0)};
0166         yM = {rinB * sin(phi1),
0167               routF * sin(phi1),
0168               routF * sin(phi0),
0169               routF * sin(phi2),
0170               rinB * sin(phi2),
0171               rinB * sin(phi0)};
0172       }
0173       std::vector<double> zw = {-0.5 * thick_, 0.5 * thick_};
0174       std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
0175       DDSolid solid = DDSolidFactory::extrudedpolygon(parentName, xM, yM, zw, zx, zy, scale);
0176       DDName matName(DDSplit(material_).first, DDSplit(material_).second);
0177       DDMaterial matter(matName);
0178       DDLogicalPart glogM = DDLogicalPart(solid.ddname(), matter, solid);
0179 #ifdef EDM_ML_DEBUG
0180       edm::LogVerbatim("HGCalGeom") << "DDHGCalPassive: " << solid.name() << " extruded polygon made of " << matName
0181                                     << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
0182                                     << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
0183                                     << " and " << xM.size() << " edges";
0184       for (unsigned int kk = 0; kk < xM.size(); ++kk)
0185         edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xM[kk] << ":" << yM[kk];
0186 #endif
0187 
0188       // Then the layers
0189       std::vector<DDLogicalPart> glogs(materials_.size());
0190       std::vector<int> copyNumber(materials_.size(), 1);
0191       double zi(-0.5 * thick_), thickTot(0.0);
0192       for (unsigned int l = 0; l < layerType_.size(); l++) {
0193         unsigned int i = layerType_[l];
0194         if (copyNumber[i] == 1) {
0195           zw[0] = -0.5 * layerThick_[i];
0196           zw[1] = 0.5 * layerThick_[i];
0197           std::string layerName = parentName + layerNames_[i];
0198           solid = DDSolidFactory::extrudedpolygon(layerName, xM, yM, zw, zx, zy, scale);
0199           DDName matN(DDSplit(materials_[i]).first, DDSplit(materials_[i]).second);
0200           DDMaterial matter(matN);
0201           glogs[i] = DDLogicalPart(solid.ddname(), matter, solid);
0202 #ifdef EDM_ML_DEBUG
0203           edm::LogVerbatim("HGCalGeom") << "DDHGCalPassive: Layer " << i << ":" << l << ":" << solid.name()
0204                                         << " extruded polygon made of " << matN << " z|x|y|s (0) " << zw[0] << ":"
0205                                         << zx[0] << ":" << zy[0] << ":" << scale[0] << " z|x|y|s (1) " << zw[1] << ":"
0206                                         << zx[1] << ":" << zy[1] << ":" << scale[1] << " and " << xM.size() << " edges";
0207           for (unsigned int kk = 0; kk < xM.size(); ++kk)
0208             edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xM[kk] << ":" << yM[kk];
0209 #endif
0210         }
0211         DDTranslation tran0(0, 0, (zi + 0.5 * layerThick_[i]));
0212         DDRotation rot;
0213         cpv.position(glogs[i], glogM, copyNumber[i], tran0, rot);
0214 #ifdef EDM_ML_DEBUG
0215         edm::LogVerbatim("HGCalGeom") << "DDHGCalPassive: " << glogs[i].name() << " number " << copyNumber[i]
0216                                       << " positioned in " << glogM.name() << " at " << tran0 << " with no rotation";
0217 #endif
0218         ++copyNumber[i];
0219         zi += layerThick_[i];
0220         thickTot += layerThick_[i];
0221       }
0222       if ((std::abs(thickTot - thick_) >= tol) && (!layerType_.empty())) {
0223         if (thickTot > thick_) {
0224           edm::LogError("HGCalGeom") << "Thickness of the partition " << thick_ << " is smaller than " << thickTot
0225                                      << ": thickness of all its components **** ERROR ****";
0226         } else {
0227           edm::LogWarning("HGCalGeom") << "Thickness of the partition " << thick_ << " does not match with " << thickTot
0228                                        << " of the components";
0229         }
0230       }
0231     }
0232   }
0233 }
0234 
0235 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHGCalPassive, "hgcal:DDHGCalPassive");