Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0002 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0003 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
0004 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0005 #include "DetectorDescription/Core/interface/DDMaterial.h"
0006 #include "DetectorDescription/Core/interface/DDSolid.h"
0007 #include "DetectorDescription/Core/interface/DDSplit.h"
0008 #include "DetectorDescription/Core/interface/DDTypes.h"
0009 #include "DetectorDescription/Core/interface/DDutils.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 #include "FWCore/PluginManager/interface/PluginFactory.h"
0012 #include "Geometry/HGCalCommonData/interface/HGCalTypes.h"
0013 #include "Geometry/HGCalCommonData/interface/HGCalWaferMask.h"
0014 
0015 #include <string>
0016 #include <vector>
0017 #include <sstream>
0018 
0019 //#define EDM_ML_DEBUG
0020 
0021 class DDHGCalPassivePartial : public DDAlgorithm {
0022 public:
0023   // Constructor and Destructor
0024   DDHGCalPassivePartial() = default;
0025   ~DDHGCalPassivePartial() override = default;
0026 
0027   void initialize(const DDNumericArguments& nArgs,
0028                   const DDVectorArguments& vArgs,
0029                   const DDMapArguments& mArgs,
0030                   const DDStringArguments& sArgs,
0031                   const DDStringVectorArguments& vsArgs) override;
0032   void execute(DDCompactView& cpv) override;
0033 
0034 private:
0035   std::string material_;           // Material name for module with gap
0036   double thick_;                   // Module thickness
0037   double waferSize_;               // Wafer size
0038   double waferSepar_;              // Sensor separation
0039   std::vector<std::string> tags_;  // Tags to be added to each name
0040   std::vector<int> partialTypes_;  // Type of partial wafer
0041   std::vector<int> placementIndex_;
0042   std::vector<std::string> placementIndexTags_;  // Plaement index of the wafers
0043   std::vector<std::string> layerNames_;          // Names of the layers
0044   std::vector<std::string> materials_;           // Materials of the layers
0045   std::vector<double> layerThick_;               // Thickness of layers
0046   std::vector<int> layerType_;                   // Types of layers
0047 };
0048 
0049 void DDHGCalPassivePartial::initialize(const DDNumericArguments& nArgs,
0050                                        const DDVectorArguments& vArgs,
0051                                        const DDMapArguments&,
0052                                        const DDStringArguments& sArgs,
0053                                        const DDStringVectorArguments& vsArgs) {
0054   material_ = sArgs["ModuleMaterial"];
0055   thick_ = nArgs["ModuleThickness"];
0056   waferSize_ = nArgs["WaferSize"];
0057 #ifdef EDM_ML_DEBUG
0058   waferSepar_ = nArgs["SensorSeparation"];
0059   edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: Module " << parent().name() << " made of " << material_
0060                                 << " T " << thick_ << " Wafer 2r " << waferSize_ << " Half Separation " << waferSepar_;
0061 #endif
0062   tags_ = vsArgs["Tags"];
0063   partialTypes_ = dbl_to_int(vArgs["PartialTypes"]);
0064   placementIndex_ = dbl_to_int(vArgs["PlacementIndex"]);
0065   placementIndexTags_ = vsArgs["PlacementIndexTags"];
0066 #ifdef EDM_ML_DEBUG
0067   edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: " << tags_.size() << " variations of wafer types";
0068   for (unsigned int k = 0; k < tags_.size(); ++k) {
0069     for (unsigned int m = 0; m < placementIndex_.size(); ++m) {
0070       edm::LogVerbatim("HGCalGeom") << "Type[" << k << "] " << tags_[k] << " Partial " << partialTypes_[k]
0071                                     << " Placement Index " << placementIndex_[m] << " Tag " << placementIndexTags_[m];
0072     }
0073   }
0074 #endif
0075   layerNames_ = vsArgs["LayerNames"];
0076   materials_ = vsArgs["LayerMaterials"];
0077   layerThick_ = vArgs["LayerThickness"];
0078 #ifdef EDM_ML_DEBUG
0079   edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: " << layerNames_.size() << " types of volumes";
0080   for (unsigned int i = 0; i < layerNames_.size(); ++i)
0081     edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << layerNames_[i] << " of thickness " << layerThick_[i]
0082                                   << " filled with " << materials_[i];
0083 #endif
0084   layerType_ = dbl_to_int(vArgs["LayerType"]);
0085 #ifdef EDM_ML_DEBUG
0086   std::ostringstream st1;
0087   for (unsigned int i = 0; i < layerType_.size(); ++i)
0088     st1 << " [" << i << "] " << layerType_[i];
0089   edm::LogVerbatim("HGCalGeom") << "There are " << layerType_.size() << " blocks" << st1.str();
0090 #endif
0091 }
0092 
0093 void DDHGCalPassivePartial::execute(DDCompactView& cpv) {
0094 #ifdef EDM_ML_DEBUG
0095   edm::LogVerbatim("HGCalGeom") << "==>> Executing DDHGCalPassivePartial...";
0096 #endif
0097 
0098   static constexpr double tol = 0.00001;
0099   std::string parentName = parent().name().name();
0100 
0101   // Loop over all types
0102   for (unsigned int k = 0; k < tags_.size(); ++k) {
0103     for (unsigned int m = 0; m < placementIndex_.size(); ++m) {
0104       // First the mother
0105       std::string mother = parentName + placementIndexTags_[m] + tags_[k];
0106       std::vector<std::pair<double, double> > wxy =
0107           HGCalWaferMask::waferXY(partialTypes_[k], placementIndex_[m], waferSize_, 0.0, 0.0, 0.0, false);
0108       std::vector<double> xM, yM;
0109       for (unsigned int i = 0; i < (wxy.size() - 1); ++i) {
0110         xM.emplace_back(wxy[i].first);
0111         yM.emplace_back(wxy[i].second);
0112       }
0113       std::vector<double> zw = {-0.5 * thick_, 0.5 * thick_};
0114       std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
0115       DDSolid solid = DDSolidFactory::extrudedpolygon(mother, xM, yM, zw, zx, zy, scale);
0116       DDName matName(DDSplit(material_).first, DDSplit(material_).second);
0117       DDMaterial matter(matName);
0118       DDLogicalPart glogM = DDLogicalPart(solid.ddname(), matter, solid);
0119 #ifdef EDM_ML_DEBUG
0120       edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: " << solid.name() << " extruded polygon made of "
0121                                     << matName << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":"
0122                                     << scale[0] << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":"
0123                                     << scale[1] << " partial " << partialTypes_[k] << " placement index "
0124                                     << placementIndex_[m] << " and " << xM.size() << " edges";
0125       for (unsigned int j = 0; j < xM.size(); ++j)
0126         edm::LogVerbatim("HGCalGeom") << "[" << j << "] " << xM[j] << ":" << yM[j];
0127 #endif
0128 
0129       // Then the layers
0130       std::vector<DDLogicalPart> glogs(materials_.size());
0131       std::vector<int> copyNumber(materials_.size(), 1);
0132       double zi(-0.5 * thick_), thickTot(0.0);
0133       for (unsigned int l = 0; l < layerType_.size(); l++) {
0134         unsigned int i = layerType_[l];
0135         wxy = HGCalWaferMask::waferXY(partialTypes_[k], placementIndex_[m], waferSize_, 0.0, 0.0, 0.0, false);
0136         std::vector<double> xL, yL;
0137         for (unsigned int i0 = 0; i0 < (wxy.size() - 1); ++i0) {
0138           xL.emplace_back(wxy[i0].first);
0139           yL.emplace_back(wxy[i0].second);
0140         }
0141 #ifdef EDM_ML_DEBUG
0142         edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial:Layer " << l << ":" << i << " T " << layerThick_[i]
0143                                       << " Copy " << copyNumber[i] << " Partial type " << partialTypes_[k];
0144 #endif
0145         DDRotation rot;
0146         if (copyNumber[i] == 1) {
0147           zw[0] = -0.5 * layerThick_[i];
0148           zw[1] = 0.5 * layerThick_[i];
0149           std::string lname = mother + layerNames_[i];
0150           solid = DDSolidFactory::extrudedpolygon(lname, xL, yL, zw, zx, zy, scale);
0151           DDName matN(DDSplit(materials_[i]).first, DDSplit(materials_[i]).second);
0152           DDMaterial matter(matN);
0153           glogs[i] = DDLogicalPart(solid.ddname(), matter, solid);
0154 #ifdef EDM_ML_DEBUG
0155           edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: " << solid.name() << " extruded polygon made of "
0156                                         << matN << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":"
0157                                         << scale[0] << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":"
0158                                         << scale[1] << " partial " << partialTypes_[k] << " placement index "
0159                                         << placementIndex_[m] << " and " << xL.size() << " edges";
0160           for (unsigned int j = 0; j < xL.size(); ++j)
0161             edm::LogVerbatim("HGCalGeom") << "[" << j << "] " << xL[j] << ":" << yL[j];
0162 #endif
0163         }
0164         DDTranslation tran(0, 0, (zi + 0.5 * layerThick_[i]));
0165         cpv.position(glogs[i], glogM, copyNumber[i], tran, rot);
0166 #ifdef EDM_ML_DEBUG
0167         edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: " << glogs[i].name() << " number " << copyNumber[i]
0168                                       << " positioned in " << glogM.name() << " at " << tran << " with no rotation";
0169 #endif
0170         ++copyNumber[i];
0171         zi += layerThick_[i];
0172         thickTot += layerThick_[i];
0173       }
0174       if ((std::abs(thickTot - thick_) >= tol) && (!layerType_.empty())) {
0175         if (thickTot > thick_) {
0176           edm::LogError("HGCalGeom") << "Thickness of the partition " << thick_ << " is smaller than " << thickTot
0177                                      << ": thickness of all its components **** ERROR ****";
0178         } else {
0179           edm::LogWarning("HGCalGeom") << "Thickness of the partition " << thick_ << " does not match with " << thickTot
0180                                        << " of the components";
0181         }
0182       }
0183     }
0184   }
0185 }
0186 
0187 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHGCalPassivePartial, "hgcal:DDHGCalPassivePartial");