Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:15:00

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // File: DDHGCalPassiveFull.cc
0003 // Description: Geometry factory class for a full silicon Wafer
0004 // Created by Sunanda Banerjee
0005 ///////////////////////////////////////////////////////////////////////////////
0006 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0007 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0008 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
0009 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0010 #include "DetectorDescription/Core/interface/DDMaterial.h"
0011 #include "DetectorDescription/Core/interface/DDSolid.h"
0012 #include "DetectorDescription/Core/interface/DDSplit.h"
0013 #include "DetectorDescription/Core/interface/DDTypes.h"
0014 #include "DetectorDescription/Core/interface/DDutils.h"
0015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0016 #include "FWCore/PluginManager/interface/PluginFactory.h"
0017 
0018 #include <string>
0019 #include <vector>
0020 #include <sstream>
0021 
0022 //#define EDM_ML_DEBUG
0023 
0024 class DDHGCalPassiveFull : public DDAlgorithm {
0025 public:
0026   // Constructor and Destructor
0027   DDHGCalPassiveFull();
0028   ~DDHGCalPassiveFull() override = default;
0029 
0030   void initialize(const DDNumericArguments& nArgs,
0031                   const DDVectorArguments& vArgs,
0032                   const DDMapArguments& mArgs,
0033                   const DDStringArguments& sArgs,
0034                   const DDStringVectorArguments& vsArgs) override;
0035   void execute(DDCompactView& cpv) override;
0036 
0037 private:
0038   std::string material_;                 // Material name for module
0039   double thick_;                         // Module thickness
0040   double waferSize_;                     // Wafer size
0041   double waferSepar_;                    // Sensor separation
0042   std::vector<std::string> layerNames_;  // Names of the layers
0043   std::vector<std::string> materials_;   // Materials of the layers
0044   std::vector<double> layerThick_;       // Thickness of layers
0045   std::vector<int> copyNumber_;          // Initial copy numbers
0046   std::vector<int> layerType_;           // Layer types
0047 };
0048 
0049 DDHGCalPassiveFull::DDHGCalPassiveFull() {
0050 #ifdef EDM_ML_DEBUG
0051   edm::LogVerbatim("HGCalGeom") << "DDHGCalPassiveFull: Creating an instance";
0052 #endif
0053 }
0054 
0055 void DDHGCalPassiveFull::initialize(const DDNumericArguments& nArgs,
0056                                     const DDVectorArguments& vArgs,
0057                                     const DDMapArguments&,
0058                                     const DDStringArguments& sArgs,
0059                                     const DDStringVectorArguments& vsArgs) {
0060   material_ = sArgs["ModuleMaterial"];
0061   thick_ = nArgs["ModuleThickness"];
0062   waferSize_ = nArgs["WaferSize"];
0063 #ifdef EDM_ML_DEBUG
0064   waferSepar_ = nArgs["SensorSeparation"];
0065   edm::LogVerbatim("HGCalGeom") << "DDHGCalPassiveFull: Module " << parent().name() << " made of " << material_ << " T "
0066                                 << thick_ << " Wafer 2r " << waferSize_ << " Half Separation " << waferSepar_;
0067 #endif
0068   layerNames_ = vsArgs["LayerNames"];
0069   materials_ = vsArgs["LayerMaterials"];
0070   layerThick_ = vArgs["LayerThickness"];
0071   copyNumber_.resize(materials_.size(), 1);
0072 #ifdef EDM_ML_DEBUG
0073   edm::LogVerbatim("HGCalGeom") << "DDHGCalPassiveFull: " << layerNames_.size() << " types of volumes";
0074   for (unsigned int i = 0; i < layerNames_.size(); ++i)
0075     edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << layerNames_[i] << " of thickness " << layerThick_[i]
0076                                   << " filled with " << materials_[i];
0077 #endif
0078   layerType_ = dbl_to_int(vArgs["LayerType"]);
0079 #ifdef EDM_ML_DEBUG
0080   std::ostringstream st1;
0081   for (unsigned int i = 0; i < layerType_.size(); ++i)
0082     st1 << " [" << i << "] " << layerType_[i];
0083   edm::LogVerbatim("HGCalGeom") << "There are " << layerType_.size() << " blocks" << st1.str();
0084 #endif
0085 }
0086 
0087 void DDHGCalPassiveFull::execute(DDCompactView& cpv) {
0088 #ifdef EDM_ML_DEBUG
0089   edm::LogVerbatim("HGCalGeom") << "==>> Executing DDHGCalPassiveFull...";
0090 #endif
0091 
0092   static constexpr double tol = 0.00001;
0093   static const double sqrt3 = std::sqrt(3.0);
0094   double rM = 0.5 * waferSize_;
0095   double RM2 = rM / sqrt3;
0096 
0097   // First the mother
0098   std::vector<double> xM = {rM, 0, -rM, -rM, 0, rM};
0099   std::vector<double> yM = {RM2, 2 * RM2, RM2, -RM2, -2 * RM2, -RM2};
0100   std::vector<double> zw = {-0.5 * thick_, 0.5 * thick_};
0101   std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
0102   std::string parentName = parent().name().name();
0103   DDSolid solid = DDSolidFactory::extrudedpolygon(parentName, xM, yM, zw, zx, zy, scale);
0104   DDName matName(DDSplit(material_).first, DDSplit(material_).second);
0105   DDMaterial matter(matName);
0106   DDLogicalPart glogM = DDLogicalPart(solid.ddname(), matter, solid);
0107 #ifdef EDM_ML_DEBUG
0108   edm::LogVerbatim("HGCalGeom") << "DDHGCalPassiveFull: " << solid.name() << " extruded polygon made of " << matName
0109                                 << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
0110                                 << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
0111                                 << " and " << xM.size() << " edges";
0112   for (unsigned int kk = 0; kk < xM.size(); ++kk)
0113     edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xM[kk] << ":" << yM[kk];
0114 #endif
0115 
0116   // Then the layers
0117   std::vector<DDLogicalPart> glogs(materials_.size());
0118   double zi(-0.5 * thick_), thickTot(0.0);
0119   for (unsigned int l = 0; l < layerType_.size(); l++) {
0120     unsigned int i = layerType_[l];
0121     if (copyNumber_[i] == 1) {
0122       zw[0] = -0.5 * layerThick_[i];
0123       zw[1] = 0.5 * layerThick_[i];
0124       std::string layerName = parentName + layerNames_[i];
0125       solid = DDSolidFactory::extrudedpolygon(layerName, xM, yM, zw, zx, zy, scale);
0126       DDName matN(DDSplit(materials_[i]).first, DDSplit(materials_[i]).second);
0127       DDMaterial matter(matN);
0128       glogs[i] = DDLogicalPart(solid.ddname(), matter, solid);
0129 #ifdef EDM_ML_DEBUG
0130       edm::LogVerbatim("HGCalGeom") << "DDHGCalPassiveFull: Layer " << i << ":" << l << ":" << solid.name()
0131                                     << " extruded polygon made of " << matN << " z|x|y|s (0) " << zw[0] << ":" << zx[0]
0132                                     << ":" << zy[0] << ":" << scale[0] << " z|x|y|s (1) " << zw[1] << ":" << zx[1]
0133                                     << ":" << zy[1] << ":" << scale[1] << " and " << xM.size() << " edges";
0134       for (unsigned int kk = 0; kk < xM.size(); ++kk)
0135         edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xM[kk] << ":" << yM[kk];
0136 #endif
0137     }
0138     DDTranslation tran0(0, 0, (zi + 0.5 * layerThick_[i]));
0139     DDRotation rot;
0140     cpv.position(glogs[i], glogM, copyNumber_[i], tran0, rot);
0141 #ifdef EDM_ML_DEBUG
0142     edm::LogVerbatim("HGCalGeom") << "DDHGCalPassiveFull: " << glogs[i].name() << " number " << copyNumber_[i]
0143                                   << " positioned in " << glogM.name() << " at " << tran0 << " with no rotation";
0144 #endif
0145     ++copyNumber_[i];
0146     zi += layerThick_[i];
0147     thickTot += layerThick_[i];
0148   }
0149   if ((std::abs(thickTot - thick_) >= tol) && (!layerType_.empty())) {
0150     if (thickTot > thick_) {
0151       edm::LogError("HGCalGeom") << "Thickness of the partition " << thick_ << " is smaller than " << thickTot
0152                                  << ": thickness of all its components **** ERROR ****";
0153     } else {
0154       edm::LogWarning("HGCalGeom") << "Thickness of the partition " << thick_ << " does not match with " << thickTot
0155                                    << " of the components";
0156     }
0157   }
0158 }
0159 
0160 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHGCalPassiveFull, "hgcal:DDHGCalPassiveFull");