File indexing completed on 2024-04-06 12:14:57
0001 #include "DD4hep/DetFactoryHelper.h"
0002 #include "DataFormats/Math/interface/angle_units.h"
0003 #include "DetectorDescription/DDCMS/interface/DDPlugins.h"
0004 #include "DetectorDescription/DDCMS/interface/DDutils.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include "Geometry/HGCalCommonData/interface/HGCalTypes.h"
0007
0008
0009 using namespace angle_units::operators;
0010
0011 static long algorithm(dd4hep::Detector& , cms::DDParsingContext& ctxt, xml_h e) {
0012 cms::DDNamespace ns(ctxt, e, true);
0013 cms::DDAlgoArguments args(ctxt, e);
0014
0015
0016 const auto& cellSize = args.value<double>("CellSize");
0017 const auto& cellType = args.value<int>("CellType");
0018 const auto& childNames = args.value<std::vector<std::string> >("ChildNames");
0019 const auto& positionX = args.value<std::vector<int> >("PositionX");
0020 const auto& positionY = args.value<std::vector<int> >("PositionY");
0021 const auto& angles = args.value<std::vector<double> >("Angles");
0022 const auto& detectorType = args.value<std::vector<int> >("DetectorType");
0023 #ifdef EDM_ML_DEBUG
0024 edm::LogVerbatim("HGCalGeom") << childNames.size() << " children: " << childNames[0] << "; " << childNames[1]
0025 << " positioned " << positionX.size() << " times with cell size " << cellSize;
0026 for (unsigned int k = 0; k < positionX.size(); ++k)
0027 edm::LogVerbatim("HGCalGeom") << "[" << k << "] x " << cms::convert2mm(positionX[k]) << " y "
0028 << cms::convert2mm(positionY[k]) << " angle " << angles[k] << " detector "
0029 << detectorType[k];
0030
0031 std::string idName = args.parentName();
0032 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferAlgo debug: Parent " << idName << " NameSpace " << ns.name();
0033 #endif
0034
0035 dd4hep::Volume mother = ns.volume(args.parentName());
0036 double dx = 0.5 * cellSize;
0037 double dy = 0.5 * dx * tan(30._deg);
0038
0039 for (unsigned int k = 0; k < positionX.size(); ++k) {
0040 std::string name(childNames[detectorType[k]]);
0041 name = ns.prepend(name);
0042 dd4hep::Rotation3D rotation;
0043 if (angles[k] != 0) {
0044 double phi = convertDegToRad(angles[k]);
0045 #ifdef EDM_ML_DEBUG
0046 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferAlgo: Creating new rotation \t90, " << angles[k] << ", 90, "
0047 << (angles[k] + 90) << ", 0, 0";
0048 #endif
0049 rotation = cms::makeRotation3D(90._deg, phi, 90._deg, (90._deg + phi), 0, 0);
0050 }
0051 double xpos = dx * positionX[k];
0052 double ypos = dy * positionY[k];
0053 dd4hep::Position tran(xpos, ypos, 0);
0054 int copy = HGCalTypes::packCellType6(cellType, k);
0055 mother.placeVolume(ns.volume(name), copy, dd4hep::Transform3D(rotation, tran));
0056 #ifdef EDM_ML_DEBUG
0057 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferAlgo: " << name << " number " << copy << " positioned in " << idName
0058 << " at (" << cms::convert2mm(xpos) << "," << cms::convert2mm(ypos) << ",0) with "
0059 << rotation;
0060 #endif
0061 }
0062
0063 return cms::s_executed;
0064 }
0065
0066
0067 DECLARE_DDCMS_DETELEMENT(DDCMS_hgcal_DDHGCalWaferAlgo, algorithm)