CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DDHCalAngular.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);
12  cms::DDAlgoArguments args(ctxt, e);
13  // Header section of original DDHCalAngular.h
14  int n = args.value<int>("n");
15  int startCopyNo = args.value<int>("startCopyNo");
16  int incrCopyNo = args.value<int>("incrCopyNo");
17  double rangeAngle = args.value<double>("rangeAngle"); //Angular range
18  double startAngle = args.value<double>("startAngle"); //Start anle
19  double shiftX = args.value<double>("shiftX"); //x Shift
20  double shiftY = args.value<double>("shiftY"); //y Shift
21  double zoffset = args.value<double>("zoffset"); //z offset
22  dd4hep::Volume mother = ns.volume(args.parentName());
23  std::string childName = args.value<std::string>("ChildName");
24  childName = ns.prepend(childName);
25  dd4hep::Volume child = ns.volume(childName);
26 
27  // Increment
28  double dphi = rangeAngle / n;
29 #ifdef EDM_ML_DEBUG
30  edm::LogVerbatim("HCalGeom") << "DDHCalAngular: Parameters for positioning::"
31  << " n " << n << " Start, Range, Delta " << convertRadToDeg(startAngle) << " "
32  << convertRadToDeg(rangeAngle) << " " << convertRadToDeg(dphi) << " Shift "
33  << cms::convert2mm(shiftX) << ":" << cms::convert2mm(shiftY) << "\n Parent "
34  << mother.name() << "\tChild " << child.name() << " NameSpace " << ns.name();
35 #endif
36  int copy = startCopyNo;
37  double phix = startAngle;
38  for (int ii = 0; ii < n; ++ii) {
39  if (phix >= 2._pi)
40  phix -= 2._pi;
41  else if (phix < 0)
42  phix += 2._pi;
43  dd4hep::Rotation3D rotation;
44  if (std::abs(phix) >= 0.1_deg) {
45 #ifdef EDM_ML_DEBUG
46  edm::LogVerbatim("HCalGeom") << "DDHCalAngular::Creating a rotation:"
47  << "\t90., " << convertRadToDeg(phix) << ", 90.," << (90.0 + convertRadToDeg(phix))
48  << ", 0, 0";
49 #endif
50  rotation = dd4hep::RotationZ(phix);
51  }
52 
53  double xpos = shiftX * cos(phix) - shiftY * sin(phix);
54  double ypos = shiftX * sin(phix) + shiftY * cos(phix);
55  dd4hep::Position tran(xpos, ypos, zoffset);
56  mother.placeVolume(child, copy, dd4hep::Transform3D(rotation, tran));
57 #ifdef EDM_ML_DEBUG
58  edm::LogVerbatim("HCalGeom") << "DDHCalAngular:: " << child.name() << " number " << copy << " positioned in "
59  << mother.name() << " at (" << cms::convert2mm(xpos) << ", " << cms::convert2mm(ypos)
60  << ", " << cms::convert2mm(zoffset) << ") with rotation matrix: " << rotation;
61 #endif
62  copy += incrCopyNo;
63  phix += dphi;
64  }
65  return cms::s_executed;
66 }
67 
68 // first argument is the type from the xml file
69 DECLARE_DDCMS_DETELEMENT(DDCMS_hcal_DDHCalAngular, algorithm)
Log< level::Info, true > LogVerbatim
dd4hep::Volume volume(const std::string &name, bool exc=true) const
Definition: DDNamespace.cc:276
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
constexpr NumType convert2mm(NumType length)
Definition: DDutils.h:7
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
T value(const std::string &name) const
int ii
Definition: cuy.py:589
std::string_view name() const
Definition: DDNamespace.h:79
#define DECLARE_DDCMS_DETELEMENT(name, func)
Definition: DDPlugins.h:25
static constexpr long s_executed
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:99
dd4hep::Volume Volume
std::string parentName() const
Access value of rParent child node.