Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-14 04:15:36

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 moduleMaterial_;              // Material name for mother volume
0043   double moduleThick_;                      // Thickness of the overall moduled
0044   int sectors_;                             // Number of phi sectors (cassettes)
0045   std::vector<std::string> tagsector_;      // Tags of the sectors
0046   int position_;                            // 0 if -z; 1 if +z;
0047   std::vector<std::string> tagpos_;         // Tags for the modules
0048   std::vector<int> xsignpos_;               // sign of the x-value;
0049   double phi0_;                             // Start phi of the first cassette
0050   double dphi_;                             // Delta phi between cassettes
0051   std::vector<std::string> absNames_;       // Names of the absorber layers
0052   std::vector<int> absN_;                   // Number of point in each layer
0053   std::vector<double> absX_;                // x coordinates of abs layers
0054   std::vector<double> absY_;                // x coordinates of abs layers
0055   std::vector<std::string> layerNames_;     // Names of layers within abs layer
0056   std::vector<std::string> layerMaterial_;  // Materials of the layers
0057   std::vector<double> layerThick_;          // Thickness of layers
0058   std::vector<int> layerType_;              // Layer types
0059 };
0060 
0061 DDHGCalPassive::DDHGCalPassive() {
0062 #ifdef EDM_ML_DEBUG
0063   edm::LogVerbatim("HGCalGeom") << "DDHGCalPassive: Creating an instance";
0064 #endif
0065 }
0066 
0067 void DDHGCalPassive::initialize(const DDNumericArguments& nArgs,
0068                                 const DDVectorArguments& vArgs,
0069                                 const DDMapArguments&,
0070                                 const DDStringArguments& sArgs,
0071                                 const DDStringVectorArguments& vsArgs) {
0072   moduleMaterial_ = sArgs["ModuleMaterial"];
0073   moduleThick_ = nArgs["ModuleThick"];
0074   sectors_ = static_cast<int>(nArgs["Sectors"]);
0075   position_ = static_cast<int>(nArgs["Position"]);
0076   phi0_ = convertDegToRad(nArgs["PhiStart"]);
0077   dphi_ = (2._pi) / sectors_;
0078   if (position_ == 0) {
0079     tagpos_.emplace_back("PN");
0080     xsignpos_.emplace_back(-1);
0081   } else {
0082     tagpos_.emplace_back("PP");
0083     xsignpos_.emplace_back(1);
0084   }
0085   for (int k = 0; k < sectors_; ++k)
0086     tagsector_.emplace_back("F" + std::to_string(k));
0087 #ifdef EDM_ML_DEBUG
0088   std::ostringstream st0, st1;
0089   for (unsigned int k = 0; k < tagsector_.size(); ++k)
0090     st0 << ": " << tagsector_[k];
0091   for (unsigned int k = 0; k < tagpos_.size(); ++k)
0092     st1 << " " << tagpos_[k] << ":" << xsignpos_[k];
0093   edm::LogVerbatim("HGCalGeom") << "DDHGCalPassive: " << tagpos_.size() << " Modules with base name " << parent().name()
0094                                 << " made of " << moduleMaterial_ << " T " << moduleThick_ << " having " << sectors_
0095                                 << " sectors" << st0.str() << " phi0 " << convertRadToDeg(phi0_) << " dphi "
0096                                 << convertRadToDeg(dphi_) << " Tags:" << st1.str();
0097 #endif
0098 
0099   layerNames_ = vsArgs["LayerNames"];
0100   layerMaterial_ = vsArgs["LayerMaterials"];
0101   layerThick_ = vArgs["LayerThickness"];
0102   layerType_ = dbl_to_int(vArgs["LayerType"]);
0103 #ifdef EDM_ML_DEBUG
0104   edm::LogVerbatim("HGCalGeom") << "DDHGCalPassive: " << layerNames_.size() << " types of volumes";
0105   for (unsigned int i = 0; i < layerNames_.size(); ++i)
0106     edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << layerNames_[i] << " of thickness " << layerThick_[i]
0107                                   << " filled with " << layerMaterial_[i];
0108   std::ostringstream st2;
0109   for (unsigned int i = 0; i < layerType_.size(); ++i)
0110     st2 << " [" << i << "] " << layerType_[i];
0111   edm::LogVerbatim("HGCalGeom") << "There are " << layerType_.size() << " blocks" << st2.str();
0112 #endif
0113 
0114   absNames_ = vsArgs["AbsorberName"];
0115   absN_ = dbl_to_int(vArgs["AbsorberN"]);
0116   absX_ = vArgs["AbsorberX"];
0117   absY_ = vArgs["AbsorberY"];
0118 #ifdef EDM_ML_DEBUG
0119   edm::LogVerbatim("HGCalGeom") << "There are " << absNames_.size() << " basic absorber shapes:";
0120   unsigned int j(0);
0121   for (unsigned int k = 0; k < absNames_.size(); ++k) {
0122     std::ostringstream st3;
0123     st3 << absNames_[k] << " with " << absN_[k] << " points:";
0124     for (int i = 0; i < absN_[k]; ++i)
0125       st3 << " (" << absX_[j + i] << ", " << absY_[j + i] << ")";
0126     j += absN_[k];
0127     edm::LogVerbatim("HGCalGeom") << st3.str();
0128   }
0129 #endif
0130 }
0131 
0132 void DDHGCalPassive::execute(DDCompactView& cpv) {
0133 #ifdef EDM_ML_DEBUG
0134   edm::LogVerbatim("HGCalGeom") << "==>> Executing DDHGCalPassive...";
0135 #endif
0136   static constexpr double tol = 0.00001;
0137 
0138   // Loop over positions
0139   for (unsigned int i1 = 0; i1 < tagpos_.size(); ++i1) {
0140     // Loop over sectors
0141     for (int i2 = 0; i2 < sectors_; ++i2) {
0142       double phi = phi0_ + i2 * dphi_;
0143       double cphi = std::cos(phi);
0144       double sphi = std::sin(phi);
0145       // Loop over passive volumes
0146       int j(0);
0147       for (unsigned i3 = 0; i3 < absNames_.size(); ++i3) {
0148         //First make the mother
0149         std::string parentName = parent().name().name() + absNames_[i3] + tagsector_[i2] + tagpos_[i1];
0150         std::vector<double> zw = {-0.5 * moduleThick_, 0.5 * moduleThick_};
0151         std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
0152         std::vector<double> xM(absN_[i3], 0), yM(absN_[i3], 0);
0153         for (int k = 0; k < absN_[i3]; ++k) {
0154           xM[k] = xsignpos_[i1] * (cphi * absX_[j + k] + sphi * absY_[j + k]);
0155           yM[k] = -sphi * absX_[j + k] + cphi * absY_[j + k];
0156         }
0157         j += absN_[i3];
0158         DDSolid solid = DDSolidFactory::extrudedpolygon(parentName, xM, yM, zw, zx, zy, scale);
0159         DDName matName(DDSplit(moduleMaterial_).first, DDSplit(moduleMaterial_).second);
0160         DDMaterial matter(matName);
0161         DDLogicalPart glogM = DDLogicalPart(solid.ddname(), matter, solid);
0162 #ifdef EDM_ML_DEBUG
0163         edm::LogVerbatim("HGCalGeom") << "DDHGCalPassive: " << solid.name() << " extruded polygon made of " << matName
0164                                       << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
0165                                       << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
0166                                       << " and " << xM.size() << " edges";
0167         for (unsigned int kk = 0; kk < xM.size(); ++kk)
0168           edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xM[kk] << ":" << yM[kk];
0169 #endif
0170         // Then the layers
0171         std::vector<DDLogicalPart> glogs(layerMaterial_.size());
0172         std::vector<int> copyNumber(layerMaterial_.size(), 1);
0173         double zi(-0.5 * moduleThick_), thickTot(0.0);
0174         for (unsigned int l = 0; l < layerType_.size(); l++) {
0175           unsigned int i = layerType_[l];
0176           if (copyNumber[i] == 1) {
0177             zw[0] = -0.5 * layerThick_[i];
0178             zw[1] = 0.5 * layerThick_[i];
0179             std::string layerName = parentName + layerNames_[i];
0180             solid = DDSolidFactory::extrudedpolygon(layerName, xM, yM, zw, zx, zy, scale);
0181             DDName matN(DDSplit(layerMaterial_[i]).first, DDSplit(layerMaterial_[i]).second);
0182             DDMaterial matter(matN);
0183             glogs[i] = DDLogicalPart(solid.ddname(), matter, solid);
0184 #ifdef EDM_ML_DEBUG
0185             edm::LogVerbatim("HGCalGeom")
0186                 << "DDHGCalPassive: Layer " << i << ":" << l << ":" << solid.name() << " extruded polygon made of "
0187                 << matN << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
0188                 << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1] << " and " << xM.size()
0189                 << " edges";
0190             for (unsigned int kk = 0; kk < xM.size(); ++kk)
0191               edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xM[kk] << ":" << yM[kk];
0192 #endif
0193           }
0194           DDTranslation tran0(0, 0, (zi + 0.5 * layerThick_[i]));
0195           DDRotation rot;
0196           cpv.position(glogs[i], glogM, copyNumber[i], tran0, rot);
0197 #ifdef EDM_ML_DEBUG
0198           edm::LogVerbatim("HGCalGeom") << "DDHGCalPassive: " << glogs[i].name() << " number " << copyNumber[i]
0199                                         << " positioned in " << glogM.name() << " at " << tran0 << " with no rotation";
0200 #endif
0201           ++copyNumber[i];
0202           zi += layerThick_[i];
0203           thickTot += layerThick_[i];
0204         }
0205         if ((std::abs(thickTot - moduleThick_) >= tol) && (!layerType_.empty())) {
0206           if (thickTot > moduleThick_) {
0207             edm::LogError("HGCalGeom") << "Thickness of the partition " << moduleThick_ << " is smaller than "
0208                                        << thickTot << ": thickness of all its components **** ERROR ****";
0209           } else {
0210             edm::LogWarning("HGCalGeom") << "Thickness of the partition " << moduleThick_ << " does not match with "
0211                                          << thickTot << " of the components";
0212           }
0213         }
0214       }
0215     }
0216   }
0217 }
0218 
0219 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHGCalPassive, "hgcal:DDHGCalPassive");