CMS 3D CMS Logo

DDHCalAngular.cc
Go to the documentation of this file.
4 #include "DD4hep/DetFactoryHelper.h"
5 
6 //#define EDM_ML_DEBUG
7 using namespace geant_units::operators;
8 
9 static long algorithm(dd4hep::Detector& /* description */,
11  xml_h e,
12  dd4hep::SensitiveDetector& /* sens */) {
13  cms::DDNamespace ns(ctxt, e, true);
14  cms::DDAlgoArguments args(ctxt, e);
15  // Header section of original DDHCalAngular.h
16  int n = args.value<int>("n");
17  int startCopyNo = args.value<int>("startCopyNo");
18  int incrCopyNo = args.value<int>("incrCopyNo");
19  double rangeAngle = args.value<double>("rangeAngle"); //Angular range
20  double startAngle = args.value<double>("startAngle"); //Start anle
21  double shiftX = args.value<double>("shiftX"); //x Shift
22  double shiftY = args.value<double>("shiftY"); //y Shift
23  double zoffset = args.value<double>("zoffset"); //z offset
24  dd4hep::Volume mother = ns.volume(args.parentName());
25  std::string childName = args.value<std::string>("ChildName");
26  if (strchr(childName.c_str(), NAMESPACE_SEP) == nullptr)
27  childName = ns.name() + childName;
28  dd4hep::Volume child = ns.volume(childName);
29 
30  // Increment
31  double dphi = rangeAngle / n;
32 #ifdef EDM_ML_DEBUG
33  edm::LogVerbatim("HCalGeom") << "DDHCalAngular: Parameters for positioning::"
34  << " n " << n << " Start, Range, Delta " << convertRadToDeg(startAngle) << " "
35  << convertRadToDeg(rangeAngle) << " " << convertRadToDeg(dphi) << " Shift "
36  << convertCmToMm(shiftX) << ":" << convertCmToMm(shiftY) << "\n Parent " << mother.name()
37  << "\tChild " << child.name() << " NameSpace " << ns.name();
38 #endif
39  int copy = startCopyNo;
40  double phix = startAngle;
41  for (int ii = 0; ii < n; ++ii) {
42  if (phix >= 2._pi)
43  phix -= 2._pi;
44  else if (phix < 0)
45  phix += 2._pi;
46  dd4hep::Rotation3D rotation;
47  if (std::abs(phix) >= 0.1_deg) {
48 #ifdef EDM_ML_DEBUG
49  edm::LogVerbatim("HCalGeom") << "DDHCalAngular::Creating a rotation:"
50  << "\t90., " << convertRadToDeg(phix) << ", 90.," << (90.0 + convertRadToDeg(phix))
51  << ", 0, 0";
52 #endif
53  rotation = dd4hep::RotationZ(phix);
54  }
55 
56  double xpos = shiftX * cos(phix) - shiftY * sin(phix);
57  double ypos = shiftX * sin(phix) + shiftY * cos(phix);
58  dd4hep::Position tran(xpos, ypos, zoffset);
59  mother.placeVolume(child, copy, dd4hep::Transform3D(rotation, tran));
60 #ifdef EDM_ML_DEBUG
61  edm::LogVerbatim("HCalGeom") << "DDHCalAngular:: " << child.name() << " number " << copy << " positioned in "
62  << mother.name() << " at (" << convertCmToMm(xpos) << ", " << convertCmToMm(ypos)
63  << ", " << convertCmToMm(zoffset) << ") with rotation matrix: " << rotation;
64 #endif
65  copy += incrCopyNo;
66  phix += dphi;
67  }
68  return 1;
69 }
70 
71 // first argument is the type from the xml file
72 DECLARE_DDCMS_DETELEMENT(DDCMS_hcal_DDHCalAngular, algorithm)
dd4hep::Volume volume(const std::string &name, bool exc=true) const
Definition: DDNamespace.cc:184
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
T value(const std::string &name) const
std::string_view name() const
Definition: DDNamespace.h:68
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
static long algorithm(dd4hep::Detector &, cms::DDParsingContext &ctxt, xml_h e, dd4hep::SensitiveDetector &)
Definition: DDHCalAngular.cc:9
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
constexpr NumType convertCmToMm(NumType centimeters)
Definition: GeantUnits.h:68
dd4hep::Volume Volume
ii
Definition: cuy.py:590
#define DECLARE_DDCMS_DETELEMENT(name, func)
Definition: DDPlugins.h:30
std::string parentName() const
Access value of rParent child node.
#define NAMESPACE_SEP
Definition: DDNamespace.h:79