CMS 3D CMS Logo

DDMTDLinear.cc
Go to the documentation of this file.
1 #include "DD4hep/DetFactoryHelper.h"
5 #include <Math/Cartesian3D.h>
6 #include <Math/DisplacementVector3D.h>
8 
9 using namespace std;
10 using namespace dd4hep;
11 using namespace cms;
12 using namespace cms_units::operators;
13 
14 using DD3Vector = ROOT::Math::DisplacementVector3D<ROOT::Math::Cartesian3D<double> >;
15 
16 static long algorithm(Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
17  cms::DDNamespace ns(ctxt, e, true);
18  DDAlgoArguments args(ctxt, e);
19 
20  int n = args.value<int>("N");
21  int startCopyNo = args.find("StartCopyNo") ? args.value<int>("StartCopyNo") : 1;
22  int incrCopyNo = args.find("IncrCopyNo") ? args.value<int>("IncrCopyNo") : 1;
23  double theta = args.find("Theta") ? args.value<double>("Theta") : 0.;
24  double phi = args.find("Phi") ? args.value<double>("Phi") : 0.;
25  double theta_obj = args.find("Theta_obj") ? args.value<double>("Theta_obj") : 0.;
26  double phi_obj = args.find("Phi_obj") ? args.value<double>("Phi_obj") : 0.;
27  double delta = args.find("Delta") ? args.value<double>("Delta") : 0.;
28  vector<double> base = args.value<vector<double> >("Base");
29  Volume mother = ns.volume(args.parentName());
30  Volume child = ns.volume(args.value<string>("ChildName"));
31  int copy = startCopyNo;
32 
33  LogDebug("DDAlgorithm") << "DDMTDLinear: Parameters for positioning:: n " << n << " Direction Theta, Phi, Delta "
34  << convertRadToDeg(theta) << " " << convertRadToDeg(phi) << " " << convertRadToDeg(delta)
35  << " Base " << base[0] << ", " << base[1] << ", " << base[2] << convertRadToDeg(theta_obj)
36  << " " << convertRadToDeg(phi_obj);
37 
38  LogDebug("DDAlgorithm") << "DDMTDLinear: Parent " << mother.name() << "\tChild " << child.name() << " NameSpace "
39  << ns.name();
40 
41  Position direction(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta));
42 
43  Position basetr(base[0], base[1], base[2]);
44 
45  //rotation is in xy plane
46  double thetaZ = theta_obj - 0.5_pi;
47  double phiZ = phi_obj;
48  double thetaX = theta_obj;
49  double thetaY = theta_obj;
50  double phiX = phi_obj;
51  double phiY = phi_obj + 0.5_pi;
52 
53  Rotation3D rotation = makeRotation3D(thetaX, phiX, thetaY, phiY, thetaZ, phiZ);
54 
55  for (int i = 0; i < n; ++i) {
56  Position tran = basetr + (double(i) * delta) * direction;
57  mother.placeVolume(child, copy, Transform3D(rotation, tran));
58  LogDebug("DDAlgorithm") << "DDMTDLinear: " << child.name() << " number " << copy << " positioned in "
59  << mother.name() << " at " << tran << " with " << rotation;
60 
61  copy += incrCopyNo;
62  }
63 
64  return 1;
65 }
66 
67 // first argument is the type from the xml file
68 DECLARE_DDCMS_DETELEMENT(DDCMS_mtd_DDMTDLinear, algorithm)
static long algorithm(Detector &, cms::DDParsingContext &ctxt, xml_h e)
Definition: DDMTDLinear.cc:16
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
base
Main Program
Definition: newFWLiteAna.py:92
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
DDRotationMatrix makeRotation3D(double thetaX, double phiX, double thetaY, double phiY, double thetaZ, double phiZ)
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DD3Vector
#define DECLARE_DDCMS_DETELEMENT(name, func)
Definition: DDPlugins.h:25
std::string_view name() const
Definition: DDNamespace.h:79
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
dd4hep::Volume Volume
Namespace of DDCMS conversion namespace.
Geom::Theta< T > theta() const
dd4hep::Volume volume(const std::string &name, bool exc=true) const
Definition: DDNamespace.cc:276
#define LogDebug(id)