File indexing completed on 2024-04-06 12:14:43
0001 #include "DataFormats/Math/interface/angle_units.h"
0002 #include "DetectorDescription/DDCMS/interface/DDPlugins.h"
0003 #include "DetectorDescription/DDCMS/interface/DDutils.h"
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #include "DD4hep/DetFactoryHelper.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 double deltaPhi = args.value<double>("DeltaPhi");
0015 double deltaZ = args.value<double>("DeltaZ");
0016 int numberPhi = args.value<int>("NumberPhi");
0017 std::string material = args.value<std::string>("Material");
0018 std::vector<double> areaSection = args.value<std::vector<double> >("AreaSection");
0019 std::vector<double> rStart = args.value<std::vector<double> >("RadiusStart");
0020 std::vector<double> rEnd = args.value<std::vector<double> >("RadiusEnd");
0021 std::vector<int> bundle = args.value<std::vector<int> >("Bundles");
0022 double tilt = args.value<double>("TiltAngle");
0023 std::string childPrefix = args.value<std::string>("Child");
0024 #ifdef EDM_ML_DEBUG
0025 edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: Parent " << args.parentName() << " with " << bundle.size()
0026 << " children with prefix " << childPrefix << ", material " << material << " with "
0027 << numberPhi << " bundles along phi; width of"
0028 << " mother " << cms::convert2mm(deltaZ) << " along Z, " << convertRadToDeg(deltaPhi)
0029 << " along phi and with " << rStart.size() << " different bundle types";
0030 for (unsigned int i = 0; i < areaSection.size(); ++i)
0031 edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: Child[" << i << "] Area "
0032 << cms::convert2mm(areaSection[i] / dd4hep::mm) << " R at Start "
0033 << cms::convert2mm(rStart[i]) << " R at End " << cms::convert2mm(rEnd[i]);
0034 edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: NameSpace " << ns.name() << " Tilt Angle "
0035 << convertRadToDeg(tilt) << " Bundle type at different positions";
0036 for (unsigned int i = 0; i < bundle.size(); ++i) {
0037 edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: Position[" << i << "] "
0038 << " with Type " << bundle[i];
0039 }
0040 #endif
0041
0042 dd4hep::Volume mother = ns.volume(args.parentName());
0043 dd4hep::Material matter = ns.material(material);
0044
0045
0046 double dPhi = deltaPhi / numberPhi;
0047 std::vector<dd4hep::Rotation3D> rotation;
0048 dd4hep::Rotation3D rot;
0049 for (int i = 0; i < numberPhi; ++i) {
0050 double phi = -0.5 * deltaPhi + (i + 0.5) * dPhi;
0051 rot = dd4hep::RotationZ(phi);
0052 #ifdef EDM_ML_DEBUG
0053 double phideg = convertRadToDeg(phi);
0054 edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: Creating a new rotation " << 90 << "," << phideg << "," << 90
0055 << "," << (phideg + 90) << ", 0, 0";
0056 #endif
0057 rotation.emplace_back(rot);
0058 }
0059
0060
0061 std::vector<dd4hep::Volume> logs;
0062 for (unsigned int i = 0; i < areaSection.size(); ++i) {
0063 double r0 = rEnd[i] / std::cos(tilt);
0064 double dStart = areaSection[i] / (2 * dPhi * rStart[i]);
0065 double dEnd = areaSection[i] / (2 * dPhi * r0);
0066 std::string name = childPrefix + std::to_string(i);
0067 dd4hep::Solid solid = dd4hep::ConeSegment(
0068 name, 0.5 * deltaZ, rStart[i] - dStart, rStart[i] + dStart, r0 - dEnd, r0 + dEnd, -0.5 * dPhi, 0.5 * dPhi);
0069 #ifdef EDM_ML_DEBUG
0070 edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: Creating a new solid " << name << " a cons with dZ "
0071 << cms::convert2mm(deltaZ) << " rStart " << cms::convert2mm(rStart[i] - dStart) << ":"
0072 << cms::convert2mm(rStart[i] + dStart) << " rEnd " << cms::convert2mm(r0 - dEnd) << ":"
0073 << cms::convert2mm(r0 + dEnd) << " Phi " << convertRadToDeg(-0.5 * dPhi) << ":"
0074 << convertRadToDeg(0.5 * dPhi);
0075 #endif
0076 dd4hep::Volume log(name, solid, matter);
0077 logs.emplace_back(log);
0078 }
0079
0080
0081 int copy = 0;
0082 int nY = static_cast<int>(bundle.size()) / numberPhi;
0083 for (unsigned int i = 0; i < bundle.size(); i++) {
0084 int ir = static_cast<int>(i) / nY;
0085 if (ir >= numberPhi)
0086 ir = numberPhi - 1;
0087 int ib = bundle[i];
0088 copy++;
0089 if (ib >= 0 && ib < (int)(logs.size())) {
0090 mother.placeVolume(logs[ib], copy, rotation[ir]);
0091 #ifdef EDM_ML_DEBUG
0092 edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: " << logs[ib].name() << " number " << copy
0093 << " positioned in " << mother.name() << " at (0, 0, 0) with " << rotation[ir];
0094 #endif
0095 }
0096 }
0097 return cms::s_executed;
0098 }
0099
0100
0101 DECLARE_DDCMS_DETELEMENT(DDCMS_hcal_DDHCalFibreBundle, algorithm);