CMS 3D CMS Logo

DDHCalXtalAlgo.cc
Go to the documentation of this file.
1 #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
16  std::string idNameSpace = static_cast<std::string>(ns.name()); //Namespace of this and ALL sub-parts
17  double radius = args.value<double>("Radius"); //Pointing distance from front surface
18  double offset = args.value<double>("Offset"); //Offset along Z
19  double dx = args.value<double>("Dx"); //Half size along x
20  double dz = args.value<double>("Dz"); //Half size along z
21  double angwidth = args.value<double>("AngWidth"); //Angular width
22  int iaxis = args.value<int>("Axis"); //Axis of rotation
23  std::vector<std::string> names = args.value<std::vector<std::string> >("Names"); //Names for rotation matrices
24  std::string idName = args.value<std::string>("ChildName"); //Children name
25 #ifdef EDM_ML_DEBUG
26  edm::LogVerbatim("HCalGeom") << "DDHCalXtalAlgo::Parameters for positioning:"
27  << " Axis " << iaxis << "\tRadius " << convertCmToMm(radius) << "\tOffset " << offset
28  << "\tDx " << convertCmToMm(dx) << "\tDz " << convertCmToMm(dz) << "\tAngWidth "
29  << convertRadToDeg(angwidth) << "\tNumbers " << names.size();
30  for (unsigned int i = 0; i < names.size(); i++)
31  edm::LogVerbatim("HCalGeom") << "\tnames[" << i << "] = " << names[i];
32  edm::LogVerbatim("HCalGeom") << "DDHCalXtalAlgo: Parent " << args.parentName() << "\tChild " << idName
33  << " NameSpace " << idNameSpace;
34 #endif
35 
37 
38  double theta[3], phi[3], pos[3];
39  phi[0] = 0;
40  phi[1] = 90._deg;
41  theta[1 - iaxis] = 90._deg;
42  pos[1 - iaxis] = 0;
43  int number = (int)(names.size());
44  for (int i = 0; i < number; i++) {
45  double angle = 0.5 * angwidth * (2 * i + 1 - number);
46  theta[iaxis] = 90._deg + angle;
47  if (angle > 0) {
48  theta[2] = angle;
49  phi[2] = iaxis * 90._deg;
50  } else {
51  theta[2] = -angle;
52  phi[2] = (2 - 3 * iaxis) * 90._deg;
53  }
54  pos[iaxis] = angle * (dz + radius);
55  pos[2] = dx * std::abs(sin(angle)) + offset;
56 
57  if (strchr(idName.c_str(), NAMESPACE_SEP) == nullptr)
58  idName = idNameSpace + idName;
59  dd4hep::Volume glog = ns.volume(idName);
60  dd4hep::Position tran(pos[0], pos[1], pos[2]);
61  dd4hep::Rotation3D rotation;
62 
63  static const double tol = 0.01_deg; // 0.01 degree
64  if (std::abs(angle) > tol) {
65 #ifdef EDM_ML_DEBUG
66  edm::LogVerbatim("HCalGeom") << "DDHCalXtalAlgo: Creating a rotation \t" << convertRadToDeg(theta[0]) << ","
67  << convertRadToDeg(phi[0]) << "," << convertRadToDeg(theta[1]) << ","
68  << convertRadToDeg(phi[1]) << "," << convertRadToDeg(theta[2]) << ","
69  << convertRadToDeg(phi[2]);
70 #endif
71  rotation = cms::makeRotation3D(theta[0], phi[0], theta[1], phi[1], theta[2], phi[2]);
72  }
73  parent.placeVolume(glog, i + 1, dd4hep::Transform3D(rotation, tran));
74 #ifdef EDM_ML_DEBUG
75  edm::LogVerbatim("HCalGeom") << "DDHCalXtalAlgo: " << glog.name() << " number " << i + 1 << " positioned in "
76  << parent.name() << " at " << tran << " with " << rotation;
77 #endif
78  }
79 
80  return 1;
81 }
82 
83 // first argument is the type from the xml file
84 DECLARE_DDCMS_DETELEMENT(DDCMS_hcal_DDHCalXtalAlgo, 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
Geom::Theta< T > theta() const
const std::string names[nVars_]
dd4hep::Rotation3D makeRotation3D(double thetaX, double phiX, double thetaY, double phiY, double thetaZ, double phiZ)
std::string_view name() const
Definition: DDNamespace.h:68
static long algorithm(dd4hep::Detector &, cms::DDParsingContext &ctxt, xml_h e, dd4hep::SensitiveDetector &)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
constexpr NumType convertCmToMm(NumType centimeters)
Definition: GeantUnits.h:68
dd4hep::Volume Volume
#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
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11