Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:49:42

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 "DD4hep/DetFactoryHelper.h"
0007 #include "DetectorDescription/DDCMS/interface/DDPlugins.h"
0008 #include "DetectorDescription/DDCMS/interface/DDutils.h"
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 #include "Geometry/HGCalCommonData/interface/HGCalTypes.h"
0011 #include "Geometry/HGCalCommonData/interface/HGCalCell.h"
0012 
0013 #include <string>
0014 #include <vector>
0015 #include <sstream>
0016 
0017 //#define EDM_ML_DEBUG
0018 
0019 static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
0020 #ifdef EDM_ML_DEBUG
0021   edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: Creating an instance";
0022 #endif
0023   cms::DDNamespace ns(ctxt, e, true);
0024   cms::DDAlgoArguments args(ctxt, e);
0025 
0026   const auto& material = args.value<std::string>("ModuleMaterial");
0027   const auto& thick = args.value<double>("ModuleThickness");
0028   const auto& waferSize = args.value<double>("WaferSize");
0029   const auto& waferThick = args.value<double>("WaferThickness");
0030   const auto& waferTag = args.value<std::string>("WaferTag");
0031 #ifdef EDM_ML_DEBUG
0032   const auto& waferSepar = args.value<double>("SensorSeparation");
0033   edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: Module " << args.parentName() << " made of " << material
0034                                 << " T " << thick << " Wafer 2r " << waferSize << " Half Separation " << waferSepar
0035                                 << " T " << waferThick;
0036 #endif
0037   const auto& orient = args.value<std::vector<int> >("WaferOrient");
0038   const auto& face = args.value<std::vector<int> >("WaferFace");
0039   const auto& tag = args.value<std::vector<std::string> >("WaferPlacementIndex");
0040   const auto& layerNames = args.value<std::vector<std::string> >("LayerNames");
0041   const auto& materials = args.value<std::vector<std::string> >("LayerMaterials");
0042   const auto& layerThick = args.value<std::vector<double> >("LayerThickness");
0043   const auto& layerSizeOff = args.value<std::vector<double> >("LayerSizeOffset");
0044   const auto& layerType = args.value<std::vector<int> >("LayerTypes");
0045   std::vector<int> copyNumber;
0046   copyNumber.resize(materials.size(), 1);
0047 #ifdef EDM_ML_DEBUG
0048   edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << layerNames.size() << " types of volumes";
0049   for (unsigned int i = 0; i < layerNames.size(); ++i)
0050     edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << layerNames[i] << " of thickness " << layerThick[i]
0051                                   << " size offset " << layerSizeOff[i] << " filled with " << materials[i] << " type "
0052                                   << layerType[i];
0053 #endif
0054   const auto& layers = args.value<std::vector<int> >("Layers");
0055 #ifdef EDM_ML_DEBUG
0056   std::ostringstream st1;
0057   for (unsigned int i = 0; i < layers.size(); ++i)
0058     st1 << " [" << i << "] " << layers[i];
0059   edm::LogVerbatim("HGCalGeom") << "There are " << layers.size() << " blocks" << st1.str();
0060 #endif
0061   const auto& nCells = args.value<int>("NCells");
0062   int cellType(-1);
0063   std::vector<std::string> cellNames;
0064   std::vector<int> cellOffset;
0065   if (nCells > 0) {
0066     cellType = args.value<int>("CellType");
0067     cellNames = args.value<std::vector<std::string> >("CellNames");
0068     cellOffset = args.value<std::vector<int> >("CellOffset");
0069   }
0070 #ifdef EDM_ML_DEBUG
0071   edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: Cells/Wafer " << nCells << " Cell Type " << cellType
0072                                 << " NameSpace " << ns.name() << " # of cells " << cellNames.size();
0073   std::ostringstream st2;
0074   for (unsigned int i = 0; i < cellOffset.size(); ++i)
0075     st2 << " [" << i << "] " << cellOffset[i];
0076   edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << cellOffset.size() << " types of cells with offsets "
0077                                 << st2.str();
0078   for (unsigned int k = 0; k < cellNames.size(); ++k)
0079     edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: Cell[" << k << "] " << cellNames[k];
0080 
0081   edm::LogVerbatim("HGCalGeom") << "==>> Executing DDHGCalWaferFullRotated...";
0082 #endif
0083 
0084   static constexpr double tol = 0.00001;
0085   static const double sqrt3 = std::sqrt(3.0);
0086   double rM = 0.5 * waferSize;
0087   double RM2 = rM / sqrt3;
0088   const int nFine(nCells), nCoarse(nCells);
0089   HGCalCell wafer(waferSize, nFine, nCoarse);
0090   for (unsigned int k = 0; k < tag.size(); ++k) {
0091     // First the mother
0092     std::vector<double> xM = {rM, 0, -rM, -rM, 0, rM};
0093     std::vector<double> yM = {RM2, 2 * RM2, RM2, -RM2, -2 * RM2, -RM2};
0094     std::vector<double> zw = {-0.5 * thick, 0.5 * thick};
0095     std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
0096     std::string parentName = args.parentName() + tag[k] + waferTag;
0097     dd4hep::Material matter = ns.material(material);
0098     dd4hep::Solid solid = dd4hep::ExtrudedPolygon(xM, yM, zw, zx, zy, scale);
0099     ns.addSolidNS(ns.prepend(parentName), solid);
0100     dd4hep::Volume glogM = dd4hep::Volume(solid.name(), solid, matter);
0101     ns.addVolumeNS(glogM);
0102 #ifdef EDM_ML_DEBUG
0103     edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << solid.name() << " extruded polygon made of "
0104                                   << material << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":"
0105                                   << scale[0] << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":"
0106                                   << scale[1] << " and " << xM.size() << " edges";
0107     for (unsigned int kk = 0; kk < xM.size(); ++kk)
0108       edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xM[kk] << ":" << yM[kk];
0109 #endif
0110 
0111     // Then the layers
0112     std::vector<dd4hep::Volume> glogs(materials.size());
0113     for (unsigned int ii = 0; ii < copyNumber.size(); ii++) {
0114       copyNumber[ii] = 1;
0115     }
0116     double zi(-0.5 * thick), thickTot(0.0);
0117     for (unsigned int l = 0; l < layers.size(); l++) {
0118       unsigned int i = layers[l];
0119       double r2 = 0.5 * (waferSize - layerSizeOff[i]);
0120       double R2 = r2 / sqrt3;
0121       std::vector<double> xL = {r2, 0, -r2, -r2, 0, r2};
0122       std::vector<double> yL = {R2, 2 * R2, R2, -R2, -2 * R2, -R2};
0123       if (copyNumber[i] == 1) {
0124         if (layerType[i] > 0) {
0125           zw[0] = -0.5 * waferThick;
0126           zw[1] = 0.5 * waferThick;
0127         } else {
0128           zw[0] = -0.5 * layerThick[i];
0129           zw[1] = 0.5 * layerThick[i];
0130         }
0131         std::string layerName = layerNames[i] + tag[k] + waferTag;
0132 #ifdef EDM_ML_DEBUG
0133         edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: Layer " << l << ": " << i << ":" << layerName << " "
0134                                       << layerSizeOff[i] << " r " << r2 << ":" << R2;
0135 #endif
0136         solid = dd4hep::ExtrudedPolygon(xL, yL, zw, zx, zy, scale);
0137         ns.addSolidNS(ns.prepend(layerName), solid);
0138         matter = ns.material(materials[i]);
0139         glogs[i] = dd4hep::Volume(solid.name(), solid, matter);
0140         ns.addVolumeNS(glogs[i]);
0141 #ifdef EDM_ML_DEBUG
0142         edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << solid.name() << " extruded polygon made of "
0143                                       << materials[i] << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":"
0144                                       << scale[0] << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":"
0145                                       << scale[1] << " and " << xL.size() << " edges";
0146         for (unsigned int kk = 0; kk < xL.size(); ++kk)
0147           edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xL[kk] << ":" << yL[kk];
0148 #endif
0149       }
0150       dd4hep::Position tran0(0, 0, (zi + 0.5 * layerThick[i]));
0151       glogM.placeVolume(glogs[i], copyNumber[i], tran0);
0152 #ifdef EDM_ML_DEBUG
0153       edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << glogs[i].name() << " number " << copyNumber[i]
0154                                     << " positioned in " << glogM.name() << " at " << tran0 << " with no rotation";
0155 #endif
0156       ++copyNumber[i];
0157       zi += layerThick[i];
0158       thickTot += layerThick[i];
0159       if ((layerType[i] > 0) && (nCells > 0)) {
0160         for (int u = 0; u < 2 * nCells; ++u) {
0161           for (int v = 0; v < 2 * nCells; ++v) {
0162             if (((v - u) < nCells) && ((u - v) <= nCells)) {
0163               int placeIndex = wafer.cellPlacementIndex(1, HGCalTypes::waferFrontBack(face[k]), orient[k]);
0164               std::pair<double, double> xy1 = wafer.cellUV2XY1(u, v, placeIndex, cellType);
0165               double yp = xy1.second;
0166               double xp = xy1.first;
0167               int cell(0);
0168               std::pair<int, int> cell1 = wafer.cellUV2Cell(u, v, placeIndex, cellType);
0169               cell = cell1.first + cellOffset[cell1.second];
0170               dd4hep::Position tran(xp, yp, 0);
0171               int copy = HGCalTypes::packCellTypeUV(cellType, u, v);
0172               glogs[i].placeVolume(ns.volume(cellNames[cell]), copy, tran);
0173 #ifdef EDM_ML_DEBUG
0174               edm::LogVerbatim("HGCalGeom")
0175                   << "DDHGCalWaferFullRotated: " << cellNames[cell] << " number " << copy << " positioned in "
0176                   << glogs[i].name() << " at " << tran << " with no rotation";
0177 #endif
0178             }
0179           }
0180         }
0181       }
0182     }
0183     if (std::abs(thickTot - thick) >= tol) {
0184       if (thickTot > thick) {
0185         edm::LogError("HGCalGeom") << "Thickness of the partition " << thick << " is smaller than " << thickTot
0186                                    << ": thickness of all its components **** ERROR ****";
0187       } else {
0188         edm::LogWarning("HGCalGeom") << "Thickness of the partition " << thick << " does not match with " << thickTot
0189                                      << " of the components";
0190       }
0191     }
0192   }
0193   return cms::s_executed;
0194 }
0195 
0196 DECLARE_DDCMS_DETELEMENT(DDCMS_hgcal_DDHGCalWaferFullRotated, algorithm);