CMS 3D CMS Logo

DDHCalTBZposAlgo.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 eta = args.value<double>("Eta"); //Eta at which beam is focussed
18  double theta = 2.0 * atan(exp(-eta)); //Corresponding theta value
19  double shiftY = args.value<double>("ShiftX"); //Shift along Y
20  double shiftX = args.value<double>("ShiftY"); //Shift along X
21  double zoffset = args.value<double>("Zoffset"); //Offset in z
22  double dist = args.value<double>("Distance"); //Radial distance
23  double tilt = args.value<double>("TiltAngle"); //Tilt with respect to y-axis
24  int copyNumber = args.value<int>("Number"); //Copy Number
25  std::string childName = args.value<std::string>("ChildName"); //Children name
26  if (strchr(childName.c_str(), NAMESPACE_SEP) == nullptr)
27  childName = idNameSpace + childName;
28 #ifdef EDM_ML_DEBUG
29  edm::LogVerbatim("HCalGeom") << "DDHCalTBZposAlgo: Parameters for position"
30  << "ing--"
31  << " Eta " << eta << "\tTheta " << convertRadToDeg(theta) << "\tShifts "
32  << convertCmToMm(shiftX) << ", " << convertCmToMm(shiftY) << " along x, y "
33  << "axes; \tZoffest " << convertCmToMm(zoffset) << "\tRadial Distance "
34  << convertCmToMm(dist) << "\tTilt angle " << convertRadToDeg(tilt) << "\tcopyNumber "
35  << copyNumber;
36  edm::LogVerbatim("HCalGeom") << "DDHCalTBZposAlgo: Parent " << args.parentName() << "\tChild " << childName
37  << " NameSpace " << idNameSpace;
38 #endif
39 
40  dd4hep::Volume mother = ns.volume(args.parentName());
41  dd4hep::Volume child = ns.volume(childName);
42 
43  // Create the rotation matrices
44  double thetax = 90._deg - theta;
45  double z = zoffset + dist * tan(thetax);
46  double x = shiftX - shiftY * sin(tilt);
47  double y = shiftY * cos(tilt);
48  dd4hep::Position tran(x, y, z);
49  dd4hep::Rotation3D rot;
50  if (tilt != 0) {
51 #ifdef EDM_ML_DEBUG
52  edm::LogVerbatim("HCalGeom") << "DDHCalZposAlgo: Creating a rotation \t90, " << convertRadToDeg(tilt) << ",90,"
53  << (90 + convertRadToDeg(tilt)) << ", 0, 0";
54 #endif
55  rot = dd4hep::RotationZ(tilt);
56  }
57  mother.placeVolume(child, copyNumber, dd4hep::Transform3D(rot, tran));
58 #ifdef EDM_ML_DEBUG
59  edm::LogVerbatim("HCalGeom") << "DDHCalTBZposAlgo: " << child.name() << " number " << copyNumber << " positioned in "
60  << mother.name() << " at (" << convertCmToMm(x) << ", " << convertCmToMm(y) << ", "
61  << convertCmToMm(z) << ") with " << rot;
62 #endif
63 
64  return 1;
65 }
66 
67 // first argument is the type from the xml file
68 DECLARE_DDCMS_DETELEMENT(DDCMS_hcal_DDHCalTBZposAlgo, algorithm);
dd4hep::Volume volume(const std::string &name, bool exc=true) const
Definition: DDNamespace.cc:184
static long algorithm(dd4hep::Detector &, cms::DDParsingContext &ctxt, xml_h e, dd4hep::SensitiveDetector &)
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
std::string_view name() const
Definition: DDNamespace.h:68
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Tan< T >::type tan(const T &t)
Definition: Tan.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