CMS 3D CMS Logo

DDTrackerPhiAltAlgo.cc
Go to the documentation of this file.
1 #include "DD4hep/DetFactoryHelper.h"
5 
6 using namespace std;
7 using namespace dd4hep;
8 using namespace cms;
9 using namespace cms_units::operators;
10 
11 static long algorithm(Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
12  cms::DDNamespace ns(ctxt, e, true);
13  DDAlgoArguments args(ctxt, e);
14  Volume mother = ns.volume(args.parentName());
15  Volume child = ns.volume(args.childName());
16  double tilt = args.value<double>("Tilt"); //Tilt of the module
17  double startAngle = args.value<double>("StartAngle"); //offset in phi
18  double rangeAngle = args.value<double>("RangeAngle"); //Maximum range in phi
19  double radiusIn = args.value<double>("RadiusIn"); //Inner radius
20  double radiusOut = args.value<double>("RadiusOut"); //Outer radius
21  double zpos = args.value<double>("ZPosition"); //z position
22  int number = args.value<int>("Number"); //Number of copies
23  int startCopyNo = args.find("StartCopyNo") ? args.value<int>("StartCopyNo") : 1; //Start copy number
24  int incrCopyNo = args.find("IncrCopyNo") ? args.value<int>("IncrCopyNo") : 1; //Increment in copy number
25 
26  edm::LogVerbatim("TrackerGeom") << "Parent " << mother.name() << "\tChild " << child.name() << " NameSpace "
27  << ns.name();
28  edm::LogVerbatim("TrackerGeom") << "Parameters for positioning-- Tilt " << tilt << "\tStartAngle "
29  << convertRadToDeg(startAngle) << "\tRangeAngle " << convertRadToDeg(rangeAngle)
30  << "\tRin " << radiusIn << "\tRout " << radiusOut << "\t ZPos " << zpos
31  << "\tCopy Numbers " << number << " Start/Increment " << startCopyNo << ", "
32  << incrCopyNo;
33 
34  if (number > 0) {
35  double theta = 90._deg;
36  double dphi;
37  if (number == 1 || fabs(rangeAngle - 360.0_deg) < 0.001_deg)
38  dphi = rangeAngle / number;
39  else
40  dphi = rangeAngle / (number - 1);
41  int copyNo = startCopyNo;
42 
43  for (int i = 0; i < number; i++) {
44  double phi = startAngle + i * dphi;
45  double phix = phi - tilt + 90._deg;
46  double phiy = phix + 90._deg;
47  double phideg = convertRadToDeg(phix);
48 
49  Rotation3D rotation;
50  if (phideg != 0) {
51  rotation = makeRotation3D(theta, phix, theta, phiy, 0., 0.);
52  }
53 
54  double xpos, ypos;
55  if (i % 2 == 0) {
56  xpos = radiusIn * cos(phi);
57  ypos = radiusIn * sin(phi);
58  } else {
59  xpos = radiusOut * cos(phi);
60  ypos = radiusOut * sin(phi);
61  }
62  Position tran(xpos, ypos, zpos);
63  /* PlacedVolume pv = */ mother.placeVolume(child, copyNo, Transform3D(rotation, tran));
64  edm::LogVerbatim("TrackerGeom") << "" << child.name() << " number " << copyNo << " positioned in "
65  << mother.name() << " at " << tran << " with " << rotation;
66  copyNo += incrCopyNo;
67  }
68  }
69  return 1;
70 }
71 
72 // first argument is the type from the xml file
73 DECLARE_DDCMS_DETELEMENT(DDCMS_track_DDTrackerPhiAltAlgo, algorithm)
Log< level::Info, true > LogVerbatim
static long algorithm(Detector &, cms::DDParsingContext &ctxt, xml_h e)
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
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)
#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