Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /*
0002  * DDHGCalWaferP.cc
0003  *
0004  *  Created on: 09-Jan-2021
0005  */
0006 
0007 #include "DD4hep/DetFactoryHelper.h"
0008 #include "DetectorDescription/DDCMS/interface/DDPlugins.h"
0009 #include "DetectorDescription/DDCMS/interface/DDutils.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 #include "FWCore/Utilities/interface/Exception.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 static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
0022   cms::DDNamespace ns(ctxt, e, true);
0023   cms::DDAlgoArguments args(ctxt, e);
0024   std::string parentName = args.parentName();
0025   const auto& material = args.value<std::string>("ModuleMaterial");
0026   const auto& thick = args.value<double>("ModuleThickness");
0027   const auto& waferSize = args.value<double>("WaferSize");
0028   const auto& waferThick = args.value<double>("WaferThickness");
0029 #ifdef EDM_ML_DEBUG
0030   const auto& waferSepar = args.value<double>("SensorSeparation");
0031   edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: Module " << parentName << " made of " << material << " T "
0032                                 << cms::convert2mm(thick) << " Wafer 2r " << cms::convert2mm(waferSize)
0033                                 << " Half Separation " << cms::convert2mm(waferSepar) << " T "
0034                                 << cms::convert2mm(waferThick);
0035 #endif
0036   const auto& tags = args.value<std::vector<std::string>>("Tags");
0037   const auto& partialTypes = args.value<std::vector<int>>("PartialTypes");
0038   const auto& orientations = args.value<std::vector<int>>("Orientations");
0039 #ifdef EDM_ML_DEBUG
0040   edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << tags.size() << " variations of wafer types";
0041   for (unsigned int k = 0; k < tags.size(); ++k)
0042     edm::LogVerbatim("HGCalGeom") << "Type[" << k << "] " << tags[k] << " Partial " << partialTypes[k]
0043                                   << " Orientation " << orientations[k];
0044 #endif
0045   const auto& layerNames = args.value<std::vector<std::string>>("LayerNames");
0046   const auto& materials = args.value<std::vector<std::string>>("LayerMaterials");
0047   const auto& layerThick = args.value<std::vector<double>>("LayerThickness");
0048   const auto& layerType = args.value<std::vector<int>>("LayerTypes");
0049 #ifdef EDM_ML_DEBUG
0050   edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << layerNames.size() << " types of volumes";
0051   for (unsigned int i = 0; i < layerNames.size(); ++i)
0052     edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << layerNames[i] << " of thickness "
0053                                   << cms::convert2mm(layerThick[i]) << " filled with " << materials[i] << " type "
0054                                   << layerType[i];
0055 #endif
0056   const auto& layers = args.value<std::vector<int>>("Layers");
0057 #ifdef EDM_ML_DEBUG
0058   std::ostringstream st1;
0059   for (unsigned int i = 0; i < layers.size(); ++i)
0060     st1 << " [" << i << "] " << layers[i];
0061   edm::LogVerbatim("HGCalGeom") << "There are " << layers.size() << " blocks" << st1.str();
0062 #endif
0063   const auto& senseName = args.value<std::string>("SenseName");
0064   const auto& senseT = args.value<double>("SenseThick");
0065   const auto& senseType = args.value<int>("SenseType");
0066   const auto& posSense = args.value<int>("PosSensitive");
0067 #ifdef EDM_ML_DEBUG
0068   edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: NameSpace " << ns.name() << " Sensitive Layer Name " << senseName
0069                                 << " Thickness " << senseT << " Type " << senseType << " Position " << posSense;
0070 #endif
0071 
0072   static constexpr double tol = 0.00001 * dd4hep::mm;
0073   static const double sqrt3 = std::sqrt(3.0);
0074   double r = 0.5 * waferSize;
0075   double R = 2.0 * r / sqrt3;
0076 
0077   // Loop over all types
0078   for (unsigned int k = 0; k < tags.size(); ++k) {
0079     // First the mother
0080     std::string mother = parentName + tags[k];
0081     std::vector<std::pair<double, double>> wxy =
0082         HGCalWaferMask::waferXY(partialTypes[k], orientations[k], 1, r, R, 0.0, 0.0);
0083     std::vector<double> xM, yM;
0084     for (unsigned int i = 0; i < (wxy.size() - 1); ++i) {
0085       xM.emplace_back(wxy[i].first);
0086       yM.emplace_back(wxy[i].second);
0087     }
0088     std::vector<double> zw = {-0.5 * thick, 0.5 * thick};
0089     std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
0090 
0091     dd4hep::Material matter = ns.material(material);
0092     dd4hep::Solid solid = dd4hep::ExtrudedPolygon(xM, yM, zw, zx, zy, scale);
0093     ns.addSolidNS(ns.prepend(mother), solid);
0094     dd4hep::Volume glogM = dd4hep::Volume(solid.name(), solid, matter);
0095     ns.addVolumeNS(glogM);
0096 #ifdef EDM_ML_DEBUG
0097     edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << solid.name() << " extruded polygon made of " << material
0098                                   << " z|x|y|s (0) " << cms::convert2mm(zw[0]) << ":" << cms::convert2mm(zx[0]) << ":"
0099                                   << cms::convert2mm(zy[0]) << ":" << scale[0] << " z|x|y|s (1) "
0100                                   << cms::convert2mm(zw[1]) << ":" << cms::convert2mm(zx[1]) << ":"
0101                                   << cms::convert2mm(zy[1]) << ":" << scale[1] << " partial " << partialTypes[k]
0102                                   << " orientation " << orientations[k] << " and " << xM.size() << " edges";
0103     for (unsigned int j = 0; j < xM.size(); ++j)
0104       edm::LogVerbatim("HGCalGeom") << "[" << j << "] " << cms::convert2mm(xM[j]) << ":" << cms::convert2mm(yM[j]);
0105 #endif
0106 
0107     // Then the layers
0108     dd4hep::Rotation3D rotation;
0109     wxy = HGCalWaferMask::waferXY(partialTypes[k], orientations[k], 1, r, R, 0.0, 0.0);
0110     std::vector<double> xL, yL;
0111     for (unsigned int i = 0; i < (wxy.size() - 1); ++i) {
0112       xL.emplace_back(wxy[i].first);
0113       yL.emplace_back(wxy[i].second);
0114     }
0115     std::vector<dd4hep::Volume> glogs(materials.size());
0116     std::vector<int> copyNumber(materials.size(), 1);
0117     double zi(-0.5 * thick), thickTot(0.0);
0118     for (unsigned int l = 0; l < layers.size(); l++) {
0119       unsigned int i = layers[l];
0120       if (copyNumber[i] == 1) {
0121         if (layerType[i] > 0) {
0122           zw[0] = -0.5 * waferThick;
0123           zw[1] = 0.5 * waferThick;
0124         } else {
0125           zw[0] = -0.5 * layerThick[i];
0126           zw[1] = 0.5 * layerThick[i];
0127         }
0128         solid = dd4hep::ExtrudedPolygon(xL, yL, zw, zx, zy, scale);
0129         std::string lname = layerNames[i] + tags[k];
0130         ns.addSolidNS(ns.prepend(lname), solid);
0131         matter = ns.material(materials[i]);
0132         glogs[i] = dd4hep::Volume(solid.name(), solid, matter);
0133         ns.addVolumeNS(glogs[i]);
0134 #ifdef EDM_ML_DEBUG
0135         edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << solid.name() << " extruded polygon made of "
0136                                       << materials[i] << " z|x|y|s (0) " << cms::convert2mm(zw[0]) << ":"
0137                                       << cms::convert2mm(zx[0]) << ":" << cms::convert2mm(zy[0]) << ":" << scale[0]
0138                                       << " z|x|y|s (1) " << cms::convert2mm(zw[1]) << ": partial " << partialTypes[k]
0139                                       << " orientation " << orientations[k] << cms::convert2mm(zx[1]) << ":"
0140                                       << cms::convert2mm(zy[1]) << ":" << scale[1] << " and " << xM.size() << " edges";
0141         for (unsigned int j = 0; j < xL.size(); ++j)
0142           edm::LogVerbatim("HGCalGeom") << "[" << j << "] " << cms::convert2mm(xL[j]) << ":" << cms::convert2mm(yL[j]);
0143 #endif
0144       }
0145       if (layerType[i] > 0) {
0146         std::string sname = senseName + tags[k];
0147         zw[0] = -0.5 * senseT;
0148         zw[1] = 0.5 * senseT;
0149         solid = dd4hep::ExtrudedPolygon(xL, yL, zw, zx, zy, scale);
0150         ns.addSolidNS(ns.prepend(sname), solid);
0151         dd4hep::Volume glog = dd4hep::Volume(solid.name(), solid, matter);
0152         ns.addVolumeNS(glog);
0153 #ifdef EDM_ML_DEBUG
0154         edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << solid.name() << " extruded polygon made of "
0155                                       << materials[i] << " z|x|y|s (0) " << cms::convert2mm(zw[0]) << ":"
0156                                       << cms::convert2mm(zx[0]) << ":" << cms::convert2mm(zy[0]) << ":" << scale[0]
0157                                       << " z|x|y|s (1) " << cms::convert2mm(zw[1]) << ":" << cms::convert2mm(zx[1])
0158                                       << ":" << cms::convert2mm(zy[1]) << ":" << scale[1] << " partial "
0159                                       << partialTypes[k] << " orientation " << orientations[k] << " and " << xL.size()
0160                                       << " edges";
0161         for (unsigned int j = 0; j < xL.size(); ++j)
0162           edm::LogVerbatim("HGCalGeom") << "[" << j << "] " << cms::convert2mm(xL[j]) << ":" << cms::convert2mm(yL[j]);
0163 #endif
0164         double zpos = (posSense == 0) ? -0.5 * (waferThick - senseT) : 0.5 * (waferThick - senseT);
0165         dd4hep::Position tran(0, 0, zpos);
0166         int copy = 10 + senseType;
0167         glogs[i].placeVolume(glog, copy, tran);
0168 #ifdef EDM_ML_DEBUG
0169         edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << glog.name() << " number " << copy << " positioned in "
0170                                       << glogs[i].name() << " at (0, 0," << cms::convert2mm(zpos)
0171                                       << ") with no rotation";
0172 #endif
0173       }
0174       dd4hep::Position tran0(0, 0, (zi + 0.5 * layerThick[i]));
0175       glogM.placeVolume(glogs[i], copyNumber[i], tran0);
0176 #ifdef EDM_ML_DEBUG
0177       edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << glogs[i].name() << " number " << copyNumber[i]
0178                                     << " positioned in " << glogM.name() << " at (0,0,"
0179                                     << cms::convert2mm(zi + 0.5 * layerThick[i]) << " with no rotation";
0180 #endif
0181       ++copyNumber[i];
0182       zi += layerThick[i];
0183       thickTot += layerThick[i];
0184     }
0185     if (std::abs(thickTot - thick) >= tol) {
0186       if (thickTot > thick) {
0187         edm::LogError("HGCalGeom") << "Thickness of the partition " << cms::convert2mm(thick) << " is smaller than "
0188                                    << cms::convert2mm(thickTot) << ": thickness of all its components **** ERROR ****";
0189       } else {
0190         edm::LogWarning("HGCalGeom") << "Thickness of the partition " << cms::convert2mm(thick)
0191                                      << " does not match with " << cms::convert2mm(thickTot) << " of the components";
0192       }
0193     }
0194   }
0195 
0196   return cms::s_executed;
0197 }
0198 
0199 // first argument is the type from the xml file
0200 DECLARE_DDCMS_DETELEMENT(DDCMS_hgcal_DDHGCalWaferP, algorithm)