CMS 3D CMS Logo

DDHCalFibreBundle.cc
Go to the documentation of this file.
5 #include "DD4hep/DetFactoryHelper.h"
6 
7 //#define EDM_ML_DEBUG
8 using namespace angle_units::operators;
9 
10 static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
11  cms::DDNamespace ns(ctxt, e, true);
13  // Header section
14  double deltaPhi = args.value<double>("DeltaPhi");
15  double deltaZ = args.value<double>("DeltaZ");
16  int numberPhi = args.value<int>("NumberPhi");
17  std::string material = args.value<std::string>("Material");
18  std::vector<double> areaSection = args.value<std::vector<double> >("AreaSection");
19  std::vector<double> rStart = args.value<std::vector<double> >("RadiusStart");
20  std::vector<double> rEnd = args.value<std::vector<double> >("RadiusEnd");
21  std::vector<int> bundle = args.value<std::vector<int> >("Bundles");
22  double tilt = args.value<double>("TiltAngle");
23  std::string childPrefix = args.value<std::string>("Child");
24 #ifdef EDM_ML_DEBUG
25  edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: Parent " << args.parentName() << " with " << bundle.size()
26  << " children with prefix " << childPrefix << ", material " << material << " with "
27  << numberPhi << " bundles along phi; width of"
28  << " mother " << cms::convert2mm(deltaZ) << " along Z, " << convertRadToDeg(deltaPhi)
29  << " along phi and with " << rStart.size() << " different bundle types";
30  for (unsigned int i = 0; i < areaSection.size(); ++i)
31  edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: Child[" << i << "] Area "
32  << cms::convert2mm(areaSection[i] / dd4hep::mm) << " R at Start "
33  << cms::convert2mm(rStart[i]) << " R at End " << cms::convert2mm(rEnd[i]);
34  edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: NameSpace " << ns.name() << " Tilt Angle "
35  << convertRadToDeg(tilt) << " Bundle type at different positions";
36  for (unsigned int i = 0; i < bundle.size(); ++i) {
37  edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: Position[" << i << "] "
38  << " with Type " << bundle[i];
39  }
40 #endif
41 
42  dd4hep::Volume mother = ns.volume(args.parentName());
43  dd4hep::Material matter = ns.material(material);
44 
45  // Create the rotation matrices
46  double dPhi = deltaPhi / numberPhi;
47  std::vector<dd4hep::Rotation3D> rotation;
48  dd4hep::Rotation3D rot;
49  for (int i = 0; i < numberPhi; ++i) {
50  double phi = -0.5 * deltaPhi + (i + 0.5) * dPhi;
51  rot = dd4hep::RotationZ(phi);
52 #ifdef EDM_ML_DEBUG
53  double phideg = convertRadToDeg(phi);
54  edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: Creating a new rotation " << 90 << "," << phideg << "," << 90
55  << "," << (phideg + 90) << ", 0, 0";
56 #endif
57  rotation.emplace_back(rot);
58  }
59 
60  // Create the solids and logical parts
61  std::vector<dd4hep::Volume> logs;
62  for (unsigned int i = 0; i < areaSection.size(); ++i) {
63  double r0 = rEnd[i] / std::cos(tilt);
64  double dStart = areaSection[i] / (2 * dPhi * rStart[i]);
65  double dEnd = areaSection[i] / (2 * dPhi * r0);
66  std::string name = childPrefix + std::to_string(i);
67  dd4hep::Solid solid = dd4hep::ConeSegment(
68  name, 0.5 * deltaZ, rStart[i] - dStart, rStart[i] + dStart, r0 - dEnd, r0 + dEnd, -0.5 * dPhi, 0.5 * dPhi);
69 #ifdef EDM_ML_DEBUG
70  edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: Creating a new solid " << name << " a cons with dZ "
71  << cms::convert2mm(deltaZ) << " rStart " << cms::convert2mm(rStart[i] - dStart) << ":"
72  << cms::convert2mm(rStart[i] + dStart) << " rEnd " << cms::convert2mm(r0 - dEnd) << ":"
73  << cms::convert2mm(r0 + dEnd) << " Phi " << convertRadToDeg(-0.5 * dPhi) << ":"
74  << convertRadToDeg(0.5 * dPhi);
75 #endif
76  dd4hep::Volume log(name, solid, matter);
77  logs.emplace_back(log);
78  }
79 
80  // Now posiiton them
81  int copy = 0;
82  int nY = static_cast<int>(bundle.size()) / numberPhi;
83  for (unsigned int i = 0; i < bundle.size(); i++) {
84  int ir = static_cast<int>(i) / nY;
85  if (ir >= numberPhi)
86  ir = numberPhi - 1;
87  int ib = bundle[i];
88  copy++;
89  if (ib >= 0 && ib < (int)(logs.size())) {
90  mother.placeVolume(logs[ib], copy, rotation[ir]);
91 #ifdef EDM_ML_DEBUG
92  edm::LogVerbatim("HCalGeom") << "DDHCalFibreBundle: " << logs[ib].name() << " number " << copy
93  << " positioned in " << mother.name() << " at (0, 0, 0) with " << rotation[ir];
94 #endif
95  }
96  }
97  return cms::s_executed;
98 }
99 
100 // first argument is the type from the xml file
101 DECLARE_DDCMS_DETELEMENT(DDCMS_hcal_DDHCalFibreBundle, algorithm);
Log< level::Info, true > LogVerbatim
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
constexpr NumType convert2mm(NumType length)
Definition: DDutils.h:7
std::string to_string(const V &value)
Definition: OMSAccess.h:71
dd4hep::Material material(const std::string &name) const
Definition: DDNamespace.cc:166
#define DECLARE_DDCMS_DETELEMENT(name, func)
Definition: DDPlugins.h:25
static constexpr long s_executed
std::string_view name() const
Definition: DDNamespace.h:79
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
dd4hep::Volume Volume
static long algorithm(dd4hep::Detector &, cms::DDParsingContext &ctxt, xml_h e)
dd4hep::Volume volume(const std::string &name, bool exc=true) const
Definition: DDNamespace.cc:276
ib
Definition: cuy.py:661