Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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& waferSepar = args.value<double>("SensorSeparation");
0030   const auto& waferThick = args.value<double>("WaferThickness");
0031   const auto& waferTag = args.value<std::string>("WaferTag");
0032 #ifdef EDM_ML_DEBUG
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& layerType = args.value<std::vector<int> >("LayerTypes");
0044   std::vector<int> copyNumber;
0045   copyNumber.resize(materials.size(), 1);
0046 #ifdef EDM_ML_DEBUG
0047   edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << layerNames.size() << " types of volumes";
0048   for (unsigned int i = 0; i < layerNames.size(); ++i)
0049     edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << layerNames[i] << " of thickness " << layerThick[i]
0050                                   << " filled with " << materials[i] << " type " << layerType[i];
0051 #endif
0052   const auto& layers = args.value<std::vector<int> >("Layers");
0053 #ifdef EDM_ML_DEBUG
0054   std::ostringstream st1;
0055   for (unsigned int i = 0; i < layers.size(); ++i)
0056     st1 << " [" << i << "] " << layers[i];
0057   edm::LogVerbatim("HGCalGeom") << "There are " << layers.size() << " blocks" << st1.str();
0058 #endif
0059   const auto& nCells = args.value<int>("NCells");
0060   int cellType(-1);
0061   std::vector<std::string> cellNames;
0062   std::vector<int> cellOffset;
0063   if (nCells > 0) {
0064     cellType = args.value<int>("CellType");
0065     cellNames = args.value<std::vector<std::string> >("CellNames");
0066     cellOffset = args.value<std::vector<int> >("CellOffset");
0067   }
0068 #ifdef EDM_ML_DEBUG
0069   edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: Cells/Wafer " << nCells << " Cell Type " << cellType
0070                                 << " # of cells " << cellNames.size();
0071   std::ostringstream st2;
0072   for (unsigned int i = 0; i < cellOffset.size(); ++i)
0073     st2 << " [" << i << "] " << cellOffset[i];
0074   edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << cellOffset.size() << " types of cells with offsets "
0075                                 << st2.str();
0076   for (unsigned int k = 0; k < cellNames.size(); ++k)
0077     edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: Cell[" << k << "] " << cellNames[k];
0078 
0079   edm::LogVerbatim("HGCalGeom") << "==>> Executing DDHGCalWaferFullRotated...";
0080 #endif
0081 
0082   static constexpr double tol = 0.00001;
0083   static const double sqrt3 = std::sqrt(3.0);
0084   double rM = 0.5 * waferSize;
0085   double RM2 = rM / sqrt3;
0086   double r2 = 0.5 * waferSize;
0087   double R2 = r2 / sqrt3;
0088   const int nFine(nCells), nCoarse(nCells);
0089   HGCalCell wafer((waferSize + waferSepar), 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<double> xL = {r2, 0, -r2, -r2, 0, r2};
0113     std::vector<double> yL = {R2, 2 * R2, R2, -R2, -2 * R2, -R2};
0114     std::vector<dd4hep::Volume> glogs(materials.size());
0115     for (unsigned int ii = 0; ii < copyNumber.size(); ii++) {
0116       copyNumber[ii] = 1;
0117     }
0118     double zi(-0.5 * thick), thickTot(0.0);
0119     for (unsigned int l = 0; l < layers.size(); l++) {
0120       unsigned int i = layers[l];
0121       if (copyNumber[i] == 1) {
0122         if (layerType[i] > 0) {
0123           zw[0] = -0.5 * waferThick;
0124           zw[1] = 0.5 * waferThick;
0125         } else {
0126           zw[0] = -0.5 * layerThick[i];
0127           zw[1] = 0.5 * layerThick[i];
0128         }
0129         std::string layerName = layerNames[i] + tag[k] + waferTag;
0130         solid = dd4hep::ExtrudedPolygon(xL, yL, zw, zx, zy, scale);
0131         ns.addSolidNS(ns.prepend(layerName), solid);
0132         matter = ns.material(materials[i]);
0133         glogs[i] = dd4hep::Volume(solid.name(), solid, matter);
0134         ns.addVolumeNS(glogs[i]);
0135 #ifdef EDM_ML_DEBUG
0136         edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << solid.name() << " extruded polygon made of "
0137                                       << materials[i] << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":"
0138                                       << scale[0] << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":"
0139                                       << scale[1] << " and " << xL.size() << " edges";
0140         for (unsigned int kk = 0; kk < xL.size(); ++kk)
0141           edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xL[kk] << ":" << yL[kk];
0142 #endif
0143       }
0144       dd4hep::Position tran0(0, 0, (zi + 0.5 * layerThick[i]));
0145       glogM.placeVolume(glogs[i], copyNumber[i], tran0);
0146 #ifdef EDM_ML_DEBUG
0147       edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << glogs[i].name() << " number " << copyNumber[i]
0148                                     << " positioned in " << glogM.name() << " at " << tran0 << " with no rotation";
0149 #endif
0150       ++copyNumber[i];
0151       zi += layerThick[i];
0152       thickTot += layerThick[i];
0153       if ((layerType[i] > 0) && (nCells > 0)) {
0154         for (int u = 0; u < 2 * nCells; ++u) {
0155           for (int v = 0; v < 2 * nCells; ++v) {
0156             if (((v - u) < nCells) && ((u - v) <= nCells)) {
0157               int placeIndex = wafer.cellPlacementIndex(1, HGCalTypes::waferFrontBack(face[k]), orient[k]);
0158               std::pair<double, double> xy1 = wafer.cellUV2XY1(u, v, placeIndex, cellType);
0159               double yp = xy1.second;
0160               double xp = xy1.first;
0161               int cell(0);
0162               std::pair<int, int> cell1 = wafer.cellUV2Cell(u, v, placeIndex, cellType);
0163               cell = cell1.first + cellOffset[cell1.second];
0164               dd4hep::Position tran(xp, yp, 0);
0165               int copy = HGCalTypes::packCellTypeUV(cellType, u, v);
0166               glogs[i].placeVolume(ns.volume(cellNames[cell]), copy, tran);
0167 #ifdef EDM_ML_DEBUG
0168               edm::LogVerbatim("HGCalGeom")
0169                   << "DDHGCalWaferFullRotated: " << cellNames[cell] << " number " << copy << " positioned in "
0170                   << glogs[i].name() << " at " << tran << " with no rotation";
0171 #endif
0172             }
0173           }
0174         }
0175       }
0176     }
0177     if (std::abs(thickTot - thick) >= tol) {
0178       if (thickTot > thick) {
0179         edm::LogError("HGCalGeom") << "Thickness of the partition " << thick << " is smaller than " << thickTot
0180                                    << ": thickness of all its components **** ERROR ****";
0181       } else {
0182         edm::LogWarning("HGCalGeom") << "Thickness of the partition " << thick << " does not match with " << thickTot
0183                                      << " of the components";
0184       }
0185     }
0186   }
0187   return cms::s_executed;
0188 }
0189 
0190 DECLARE_DDCMS_DETELEMENT(DDCMS_hgcal_DDHGCalWaferFullRotated, algorithm);