Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-16 03:20:02

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 DDHGCalWaferP : public DDAlgorithm {
0022 public:
0023   // Constructor and Destructor
0024   DDHGCalWaferP();
0025   ~DDHGCalWaferP() override;
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   double waferThick_;                    // Wafer thickness
0040   std::vector<std::string> tags_;        // Tags to be added to each name
0041   std::vector<int> partialTypes_;        // Type of partial wafer
0042   std::vector<int> orientations_;        // Orientations 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_;           // Layer types
0047   std::vector<int> layers_;              // Number of layers in a section
0048   std::string senseName_;                // Name of the sensitive layer
0049   double senseT_;                        // Thickness of sensitive layer
0050   int senseType_;                        // Cell Type (0,1,2: Fine, Course 2/3)
0051   int posSense_;                         // Position depleted layer
0052   std::string nameSpace_;                // Namespace to be used
0053 };
0054 
0055 DDHGCalWaferP::DDHGCalWaferP() {
0056 #ifdef EDM_ML_DEBUG
0057   edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: Creating an instance";
0058 #endif
0059 }
0060 
0061 DDHGCalWaferP::~DDHGCalWaferP() {}
0062 
0063 void DDHGCalWaferP::initialize(const DDNumericArguments& nArgs,
0064                                const DDVectorArguments& vArgs,
0065                                const DDMapArguments&,
0066                                const DDStringArguments& sArgs,
0067                                const DDStringVectorArguments& vsArgs) {
0068   material_ = sArgs["ModuleMaterial"];
0069   thick_ = nArgs["ModuleThickness"];
0070   waferSize_ = nArgs["WaferSize"];
0071   waferThick_ = nArgs["WaferThickness"];
0072 #ifdef EDM_ML_DEBUG
0073   waferSepar_ = nArgs["SensorSeparation"];
0074   edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: Module " << parent().name() << " made of " << material_ << " T "
0075                                 << thick_ << " Wafer 2r " << waferSize_ << " Half Separation " << waferSepar_ << " T "
0076                                 << waferThick_;
0077 #endif
0078   tags_ = vsArgs["Tags"];
0079   partialTypes_ = dbl_to_int(vArgs["PartialTypes"]);
0080   orientations_ = dbl_to_int(vArgs["Orientations"]);
0081 #ifdef EDM_ML_DEBUG
0082   edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << tags_.size() << " variations of wafer types";
0083   for (unsigned int k = 0; k < tags_.size(); ++k)
0084     edm::LogVerbatim("HGCalGeom") << "Type[" << k << "] " << tags_[k] << " Partial " << partialTypes_[k]
0085                                   << " Orientation " << orientations_[k];
0086 #endif
0087   layerNames_ = vsArgs["LayerNames"];
0088   materials_ = vsArgs["LayerMaterials"];
0089   layerThick_ = vArgs["LayerThickness"];
0090   layerType_ = dbl_to_int(vArgs["LayerTypes"]);
0091 #ifdef EDM_ML_DEBUG
0092   edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << layerNames_.size() << " types of volumes";
0093   for (unsigned int i = 0; i < layerNames_.size(); ++i)
0094     edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << layerNames_[i] << " of thickness " << layerThick_[i]
0095                                   << " filled with " << materials_[i] << " type " << layerType_[i];
0096 #endif
0097   layers_ = dbl_to_int(vArgs["Layers"]);
0098 #ifdef EDM_ML_DEBUG
0099   std::ostringstream st1;
0100   for (unsigned int i = 0; i < layers_.size(); ++i)
0101     st1 << " [" << i << "] " << layers_[i];
0102   edm::LogVerbatim("HGCalGeom") << "There are " << layers_.size() << " blocks" << st1.str();
0103 #endif
0104   senseName_ = sArgs["SenseName"];
0105   senseT_ = nArgs["SenseThick"];
0106   senseType_ = static_cast<int>(nArgs["SenseType"]);
0107   posSense_ = static_cast<int>(nArgs["PosSensitive"]);
0108   nameSpace_ = DDCurrentNamespace::ns();
0109 #ifdef EDM_ML_DEBUG
0110   edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: NameSpace " << nameSpace_ << " Sensitive Layer Name " << senseName_
0111                                 << " Thickness " << senseT_ << " Type " << senseType_ << " Position " << posSense_;
0112 #endif
0113 }
0114 
0115 void DDHGCalWaferP::execute(DDCompactView& cpv) {
0116 #ifdef EDM_ML_DEBUG
0117   edm::LogVerbatim("HGCalGeom") << "==>> Executing DDHGCalWaferP...";
0118 #endif
0119 
0120   static constexpr double tol = 0.00001;
0121   static const double sqrt3 = std::sqrt(3.0);
0122   double r = 0.5 * waferSize_;
0123   double R = 2.0 * r / sqrt3;
0124   std::string parentName = parent().name().name();
0125 
0126   // Loop over all types
0127   for (unsigned int k = 0; k < tags_.size(); ++k) {
0128     // First the mother
0129     std::string mother = parentName + tags_[k];
0130     std::vector<std::pair<double, double> > wxy =
0131         HGCalWaferMask::waferXY(partialTypes_[k], orientations_[k], 1, r, R, 0.0, 0.0);
0132     std::vector<double> xM, yM;
0133     for (unsigned int i = 0; i < (wxy.size() - 1); ++i) {
0134       xM.emplace_back(wxy[i].first);
0135       yM.emplace_back(wxy[i].second);
0136     }
0137     std::vector<double> zw = {-0.5 * thick_, 0.5 * thick_};
0138     std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
0139     DDSolid solid = DDSolidFactory::extrudedpolygon(mother, xM, yM, zw, zx, zy, scale);
0140     DDName matName(DDSplit(material_).first, DDSplit(material_).second);
0141     DDMaterial matter(matName);
0142     DDLogicalPart glogM = DDLogicalPart(solid.ddname(), matter, solid);
0143 #ifdef EDM_ML_DEBUG
0144     edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << solid.name() << " extruded polygon made of " << matName
0145                                   << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
0146                                   << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
0147                                   << " partial " << partialTypes_[k] << " orientation " << orientations_[k] << " and "
0148                                   << xM.size() << " edges";
0149     for (unsigned int j = 0; j < xM.size(); ++j)
0150       edm::LogVerbatim("HGCalGeom") << "[" << j << "] " << xM[j] << ":" << yM[j];
0151 #endif
0152 
0153     // Then the layers
0154     wxy = HGCalWaferMask::waferXY(partialTypes_[k], orientations_[k], 1, r, R, 0.0, 0.0);
0155     std::vector<double> xL, yL;
0156     for (unsigned int i = 0; i < (wxy.size() - 1); ++i) {
0157       xL.emplace_back(wxy[i].first);
0158       yL.emplace_back(wxy[i].second);
0159     }
0160     std::vector<DDLogicalPart> glogs(materials_.size());
0161     std::vector<int> copyNumber(materials_.size(), 1);
0162     double zi(-0.5 * thick_), thickTot(0.0);
0163     for (unsigned int l = 0; l < layers_.size(); l++) {
0164       unsigned int i = layers_[l];
0165 #ifdef EDM_ML_DEBUG
0166       edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP:Layer " << l << ":" << i << " T " << layerThick_[i] << " Copy "
0167                                     << copyNumber[i];
0168 #endif
0169       DDRotation rot;
0170       if (copyNumber[i] == 1) {
0171         if (layerType_[i] > 0) {
0172           zw[0] = -0.5 * waferThick_;
0173           zw[1] = 0.5 * waferThick_;
0174         } else {
0175           zw[0] = -0.5 * layerThick_[i];
0176           zw[1] = 0.5 * layerThick_[i];
0177         }
0178         std::string lname = layerNames_[i] + tags_[k];
0179         solid = DDSolidFactory::extrudedpolygon(lname, xL, yL, zw, zx, zy, scale);
0180         DDName matN(DDSplit(materials_[i]).first, DDSplit(materials_[i]).second);
0181         DDMaterial matter(matN);
0182         glogs[i] = DDLogicalPart(solid.ddname(), matter, solid);
0183 #ifdef EDM_ML_DEBUG
0184         edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << solid.name() << " extruded polygon made of " << matN
0185                                       << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
0186                                       << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
0187                                       << " partial " << partialTypes_[k] << " orientation " << orientations_[k]
0188                                       << " and " << xL.size() << " edges";
0189         for (unsigned int j = 0; j < xL.size(); ++j)
0190           edm::LogVerbatim("HGCalGeom") << "[" << j << "] " << xL[j] << ":" << yL[j];
0191 #endif
0192         if (layerType_[i] > 0) {
0193           std::string sname = senseName_ + tags_[k];
0194           zw[0] = -0.5 * senseT_;
0195           zw[1] = 0.5 * senseT_;
0196           solid = DDSolidFactory::extrudedpolygon(sname, xL, yL, zw, zx, zy, scale);
0197           DDLogicalPart glog = DDLogicalPart(solid.ddname(), matter, solid);
0198 #ifdef EDM_ML_DEBUG
0199           edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << solid.name() << " extruded polygon made of " << matN
0200                                         << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
0201                                         << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
0202                                         << " partial " << partialTypes_[k] << " orientation " << orientations_[k]
0203                                         << " and " << xL.size() << " edges";
0204           for (unsigned int j = 0; j < xL.size(); ++j)
0205             edm::LogVerbatim("HGCalGeom") << "[" << j << "] " << xL[j] << ":" << yL[j];
0206 #endif
0207           double zpos = (posSense_ == 0) ? -0.5 * (waferThick_ - senseT_) : 0.5 * (waferThick_ - senseT_);
0208           DDTranslation tran(0, 0, zpos);
0209           int copy = 10 + senseType_;
0210           cpv.position(glog, glogs[i], copy, tran, rot);
0211 #ifdef EDM_ML_DEBUG
0212           edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << glog.name() << " number " << copy << " positioned in "
0213                                         << glogs[i].name() << " at " << tran << " with no rotation";
0214 #endif
0215         }
0216       }
0217       DDTranslation tran0(0, 0, (zi + 0.5 * layerThick_[i]));
0218       cpv.position(glogs[i], glogM, copyNumber[i], tran0, rot);
0219 #ifdef EDM_ML_DEBUG
0220       edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << glogs[i].name() << " number " << copyNumber[i]
0221                                     << " positioned in " << glogM.name() << " at " << tran0 << " with no rotation";
0222 #endif
0223       ++copyNumber[i];
0224       zi += layerThick_[i];
0225       thickTot += layerThick_[i];
0226     }
0227     if (std::abs(thickTot - thick_) >= tol) {
0228       if (thickTot > thick_) {
0229         edm::LogError("HGCalGeom") << "Thickness of the partition " << thick_ << " is smaller than " << thickTot
0230                                    << ": thickness of all its components **** ERROR ****";
0231       } else {
0232         edm::LogWarning("HGCalGeom") << "Thickness of the partition " << thick_ << " does not match with " << thickTot
0233                                      << " of the components";
0234       }
0235     }
0236   }
0237 }
0238 
0239 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHGCalWaferP, "hgcal:DDHGCalWaferP");