Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-10 02:51:09

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