Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-24 22:52:01

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // File: DDHGCalWaferFullRotated.cc
0003 // Description: Geometry factory class for a full silicon Wafer
0004 // Created by Sunanda Banerjee, Pruthvi Suryadevara, Indranil Das
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 #include "Geometry/HGCalCommonData/interface/HGCalTypes.h"
0018 #include "Geometry/HGCalCommonData/interface/HGCalCell.h"
0019 
0020 #include <string>
0021 #include <vector>
0022 #include <sstream>
0023 
0024 //#define EDM_ML_DEBUG
0025 
0026 class DDHGCalWaferFullRotated : public DDAlgorithm {
0027 public:
0028   // Constructor and Destructor
0029   DDHGCalWaferFullRotated();
0030   ~DDHGCalWaferFullRotated() override = default;
0031 
0032   void initialize(const DDNumericArguments& nArgs,
0033                   const DDVectorArguments& vArgs,
0034                   const DDMapArguments& mArgs,
0035                   const DDStringArguments& sArgs,
0036                   const DDStringVectorArguments& vsArgs) override;
0037   void execute(DDCompactView& cpv) override;
0038 
0039 private:
0040   std::string material_;                 // Material name for module with gap
0041   std::string waferTag_;                 // Tag for type pf wafer
0042   double thick_;                         // Module thickness
0043   double waferSize_;                     // Wafer size
0044   double waferSepar_;                    // Sensor separation
0045   double waferThick_;                    // Wafer thickness
0046   std::vector<std::string> layerNames_;  // Names of the layers
0047   std::vector<std::string> materials_;   // Materials of the layers
0048   std::vector<std::string> tag_;         // Tag of placement index
0049   std::vector<double> layerThick_;       // Thickness of layers
0050   std::vector<int> layerType_;           // Layer types
0051   std::vector<int> copyNumber_;          // Initial copy numbers
0052   std::vector<int> layers_;              // Number of layers in a section
0053   std::vector<int> orient_;              // Orientation of wafer
0054   std::vector<int> face_;                // Front or back of cooling layer
0055   int nCells_;                           // Half number of cells along u-v axis
0056   int cellType_;                         // Cell Type (0,1,2: Fine, Course 2/3)
0057   std::vector<int> cellOffset_;          // Offset of cells of each type
0058   std::vector<std::string> cellNames_;   // Name of the cells
0059   std::string nameSpace_;                // Namespace to be used
0060 };
0061 
0062 DDHGCalWaferFullRotated::DDHGCalWaferFullRotated() {
0063 #ifdef EDM_ML_DEBUG
0064   edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: Creating an instance";
0065 #endif
0066 }
0067 
0068 void DDHGCalWaferFullRotated::initialize(const DDNumericArguments& nArgs,
0069                                          const DDVectorArguments& vArgs,
0070                                          const DDMapArguments&,
0071                                          const DDStringArguments& sArgs,
0072                                          const DDStringVectorArguments& vsArgs) {
0073   material_ = sArgs["ModuleMaterial"];
0074   thick_ = nArgs["ModuleThickness"];
0075   waferSize_ = nArgs["WaferSize"];
0076   waferSepar_ = nArgs["SensorSeparation"];
0077   waferThick_ = nArgs["WaferThickness"];
0078   waferTag_ = sArgs["WaferTag"];
0079 #ifdef EDM_ML_DEBUG
0080   edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: Module " << parent().name() << " made of " << material_
0081                                 << " T " << thick_ << " Wafer 2r " << waferSize_ << " Half Separation " << waferSepar_
0082                                 << " T " << waferThick_;
0083 #endif
0084   orient_ = dbl_to_int(vArgs["WaferOrient"]);
0085   face_ = dbl_to_int(vArgs["WaferFace"]);
0086   tag_ = vsArgs["WaferPlacementIndex"];
0087   layerNames_ = vsArgs["LayerNames"];
0088   materials_ = vsArgs["LayerMaterials"];
0089   layerThick_ = vArgs["LayerThickness"];
0090   layerType_ = dbl_to_int(vArgs["LayerTypes"]);
0091   copyNumber_.resize(materials_.size(), 1);
0092 #ifdef EDM_ML_DEBUG
0093   edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << layerNames_.size() << " types of volumes";
0094   for (unsigned int i = 0; i < layerNames_.size(); ++i)
0095     edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << layerNames_[i] << " of thickness " << layerThick_[i]
0096                                   << " filled with " << materials_[i] << " type " << layerType_[i];
0097 #endif
0098   layers_ = dbl_to_int(vArgs["Layers"]);
0099 #ifdef EDM_ML_DEBUG
0100   std::ostringstream st1;
0101   for (unsigned int i = 0; i < layers_.size(); ++i)
0102     st1 << " [" << i << "] " << layers_[i];
0103   edm::LogVerbatim("HGCalGeom") << "There are " << layers_.size() << " blocks" << st1.str();
0104 #endif
0105   nCells_ = static_cast<int>(nArgs["NCells"]);
0106   if (nCells_ > 0) {
0107     cellType_ = static_cast<int>(nArgs["CellType"]);
0108     cellNames_ = vsArgs["CellNames"];
0109     cellOffset_ = dbl_to_int(vArgs["CellOffset"]);
0110   } else {
0111     cellType_ = -1;
0112   }
0113   nameSpace_ = DDCurrentNamespace::ns();
0114 #ifdef EDM_ML_DEBUG
0115   edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: Cells/Wafer " << nCells_ << " Cell Type " << cellType_
0116                                 << " NameSpace " << nameSpace_ << ": # of cells " << cellNames_.size();
0117   std::ostringstream st2;
0118   for (unsigned int i = 0; i < cellOffset_.size(); ++i)
0119     st2 << " [" << i << "] " << cellOffset_[i];
0120   edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << cellOffset_.size() << " types of cells with offsets "
0121                                 << st2.str();
0122   for (unsigned int k = 0; k < cellNames_.size(); ++k)
0123     edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: Cell[" << k << "] " << cellNames_[k];
0124 #endif
0125 }
0126 
0127 void DDHGCalWaferFullRotated::execute(DDCompactView& cpv) {
0128 #ifdef EDM_ML_DEBUG
0129   edm::LogVerbatim("HGCalGeom") << "==>> Executing DDHGCalWaferFullRotated...";
0130 #endif
0131 
0132   static constexpr double tol = 0.00001;
0133   static const double sqrt3 = std::sqrt(3.0);
0134   double rM = 0.5 * waferSize_;
0135   double RM2 = rM / sqrt3;
0136   double r2 = 0.5 * waferSize_;
0137   double R2 = r2 / sqrt3;
0138   const int nFine(nCells_), nCoarse(nCells_);
0139   HGCalCell wafer((waferSize_ + waferSepar_), nFine, nCoarse);
0140   for (unsigned int k = 0; k < tag_.size(); ++k) {
0141     // First the mother
0142     std::vector<double> xM = {rM, 0, -rM, -rM, 0, rM};
0143     std::vector<double> yM = {RM2, 2 * RM2, RM2, -RM2, -2 * RM2, -RM2};
0144     std::vector<double> zw = {-0.5 * thick_, 0.5 * thick_};
0145     std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
0146     std::string parentName = parent().name().name();
0147     parentName = parentName + tag_[k] + waferTag_;
0148     DDSolid solid = DDSolidFactory::extrudedpolygon(parentName, xM, yM, zw, zx, zy, scale);
0149     DDName matName(DDSplit(material_).first, DDSplit(material_).second);
0150     DDMaterial matter(matName);
0151     DDLogicalPart glogM = DDLogicalPart(solid.ddname(), matter, solid);
0152 #ifdef EDM_ML_DEBUG
0153     edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << solid.name() << " extruded polygon made of "
0154                                   << matName << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":"
0155                                   << scale[0] << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":"
0156                                   << scale[1] << " and " << xM.size() << " edges";
0157     for (unsigned int kk = 0; kk < xM.size(); ++kk)
0158       edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xM[kk] << ":" << yM[kk];
0159 #endif
0160 
0161     // Then the layers
0162     std::vector<double> xL = {r2, 0, -r2, -r2, 0, r2};
0163     std::vector<double> yL = {R2, 2 * R2, R2, -R2, -2 * R2, -R2};
0164     std::vector<DDLogicalPart> glogs(materials_.size());
0165     for (unsigned int ii = 0; ii < copyNumber_.size(); ii++) {
0166       copyNumber_[ii] = 1;
0167     }
0168     double zi(-0.5 * thick_), thickTot(0.0);
0169     for (unsigned int l = 0; l < layers_.size(); l++) {
0170       unsigned int i = layers_[l];
0171       if (copyNumber_[i] == 1) {
0172         if (layerType_[i] > 0) {
0173           zw[0] = -0.5 * waferThick_;
0174           zw[1] = 0.5 * waferThick_;
0175         } else {
0176           zw[0] = -0.5 * layerThick_[i];
0177           zw[1] = 0.5 * layerThick_[i];
0178         }
0179         std::string layerName = layerNames_[i] + tag_[k] + waferTag_;
0180         solid = DDSolidFactory::extrudedpolygon(layerName, xL, yL, zw, zx, zy, scale);
0181         DDName matN(DDSplit(materials_[i]).first, DDSplit(materials_[i]).second);
0182         DDMaterial matter(matN);
0183         glogs[i] = DDLogicalPart(solid.ddname(), matter, solid);
0184 
0185 #ifdef EDM_ML_DEBUG
0186         edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << solid.name() << " extruded polygon made of "
0187                                       << matN << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":"
0188                                       << scale[0] << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":"
0189                                       << scale[1] << " and " << xL.size() << " edges";
0190         for (unsigned int kk = 0; kk < xL.size(); ++kk)
0191           edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xL[kk] << ":" << yL[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") << "DDHGCalWaferFullRotated: " << 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       if ((layerType_[i] > 0) && (nCells_ > 0)) {
0205         for (int u = 0; u < 2 * nCells_; ++u) {
0206           for (int v = 0; v < 2 * nCells_; ++v) {
0207             if (((v - u) < nCells_) && ((u - v) <= nCells_)) {
0208               int placeIndex = wafer.cellPlacementIndex(1, HGCalTypes::waferFrontBack(face_[k]), orient_[k]);
0209               std::pair<double, double> xy1 = wafer.cellUV2XY1(u, v, placeIndex, cellType_);
0210               double yp = xy1.second;
0211               double xp = xy1.first;
0212               int cell(0);
0213               std::pair<int, int> cell1 = wafer.cellUV2Cell(u, v, placeIndex, cellType_);
0214               cell = cell1.first + cellOffset_[cell1.second];
0215               DDTranslation tran(xp, yp, 0);
0216               int copy = HGCalTypes::packCellTypeUV(cellType_, u, v);
0217               cpv.position(DDName(cellNames_[cell]), glogs[i], copy, tran, rot);
0218 #ifdef EDM_ML_DEBUG
0219               edm::LogVerbatim("HGCalGeom")
0220                   << "DDHGCalWaferFullRotated: " << cellNames_[cell] << " number " << copy << " positioned in "
0221                   << glogs[i].name() << " at " << tran << " with no rotation";
0222 #endif
0223             }
0224           }
0225         }
0226       }
0227     }
0228     if (std::abs(thickTot - thick_) >= tol) {
0229       if (thickTot > thick_) {
0230         edm::LogError("HGCalGeom") << "Thickness of the partition " << thick_ << " is smaller than " << thickTot
0231                                    << ": thickness of all its components **** ERROR ****";
0232       } else {
0233         edm::LogWarning("HGCalGeom") << "Thickness of the partition " << thick_ << " does not match with " << thickTot
0234                                      << " of the components";
0235       }
0236     }
0237   }
0238 }
0239 
0240 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHGCalWaferFullRotated, "hgcal:DDHGCalWaferFullRotated");