File indexing completed on 2024-04-06 12:14:43
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
0007
0008 using namespace angle_units::operators;
0009
0010 static long algorithm(dd4hep::Detector& , cms::DDParsingContext& ctxt, xml_h e) {
0011 cms::DDNamespace ns(ctxt, e, true);
0012 cms::DDAlgoArguments args(ctxt, e);
0013
0014 std::string idNameSpace = static_cast<std::string>(ns.name());
0015 double eta = args.value<double>("Eta");
0016 double theta = 2.0 * atan(exp(-eta));
0017 double shiftY = args.value<double>("ShiftX");
0018 double shiftX = args.value<double>("ShiftY");
0019 double zoffset = args.value<double>("Zoffset");
0020 double dist = args.value<double>("Distance");
0021 double tilt = args.value<double>("TiltAngle");
0022 int copyNumber = args.value<int>("Number");
0023 std::string childName = args.value<std::string>("ChildName");
0024 if (strchr(childName.c_str(), NAMESPACE_SEP) == nullptr)
0025 childName = idNameSpace + childName;
0026 #ifdef EDM_ML_DEBUG
0027 edm::LogVerbatim("HCalGeom") << "DDHCalTBZposAlgo: Parameters for positioning-- Eta " << eta << "\tTheta "
0028 << convertRadToDeg(theta) << "\tShifts " << cms::convert2mm(shiftX) << ", "
0029 << cms::convert2mm(shiftY) << " along x, y axes; \tZoffest " << cms::convert2mm(zoffset)
0030 << "\tRadial Distance " << cms::convert2mm(dist) << "\tTilt angle "
0031 << convertRadToDeg(tilt) << "\tcopyNumber " << copyNumber;
0032 edm::LogVerbatim("HCalGeom") << "DDHCalTBZposAlgo: Parent " << args.parentName() << "\tChild " << childName
0033 << " NameSpace " << idNameSpace;
0034 #endif
0035
0036 dd4hep::Volume mother = ns.volume(args.parentName());
0037 dd4hep::Volume child = ns.volume(childName);
0038
0039
0040 double thetax = 90._deg - theta;
0041 double z = zoffset + dist * tan(thetax);
0042 double x = shiftX - shiftY * sin(tilt);
0043 double y = shiftY * cos(tilt);
0044 dd4hep::Position tran(x, y, z);
0045 dd4hep::Rotation3D rot;
0046 if (tilt != 0) {
0047 #ifdef EDM_ML_DEBUG
0048 edm::LogVerbatim("HCalGeom") << "DDHCalZposAlgo: Creating a rotation \t90, " << convertRadToDeg(tilt) << ",90,"
0049 << (90 + convertRadToDeg(tilt)) << ", 0, 0";
0050 #endif
0051 rot = dd4hep::RotationZ(tilt);
0052 }
0053 mother.placeVolume(child, copyNumber, dd4hep::Transform3D(rot, tran));
0054 #ifdef EDM_ML_DEBUG
0055 edm::LogVerbatim("HCalGeom") << "DDHCalTBZposAlgo: " << child.name() << " number " << copyNumber << " positioned in "
0056 << mother.name() << " at (" << cms::convert2mm(x) << ", " << cms::convert2mm(y) << ", "
0057 << cms::convert2mm(z) << ") with " << rot;
0058 #endif
0059
0060 return cms::s_executed;
0061 }
0062
0063
0064 DECLARE_DDCMS_DETELEMENT(DDCMS_hcal_DDHCalTBZposAlgo, algorithm);