CMS 3D CMS Logo

DDPixFwdDiskAlgo.cc
Go to the documentation of this file.
1 // File: DDPixFwdDiskAlgo.cc
3 // Description: Position n copies at given z-values
5 
8 #include "DD4hep/DetFactoryHelper.h"
9 #include "DD4hep/Printout.h"
10 
12 
13 #include <sstream>
14 
15 using namespace cms_units::operators; // _deg and convertRadToDeg
16 
17 static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
18  cms::DDNamespace ns(ctxt, e, true);
20 
21  int nBlades; //Number of blades
22  int startCopyNo; //Start Copy number
23  double bladeAngle; //Angle of blade rotation aroung y-axis
24  double bladeTilt; //Tilt of the blade around x-axis
25  double zPlane; //Common shift in z for all blades
26  std::vector<double> bladeZShift; //Shift in Z of individual blades
27  double anchorR; //Distance of beam line to anchor point
28 
29  std::string childName; //Child name
30  std::string rotName; //Name of the base rotation matrix
31  std::string flagString; //Flag if a blade is present
32 
33  dd4hep::Volume mother = ns.volume(args.parentName());
35 
36  startCopyNo = args.find("StartCopyNo") ? args.value<int>("StartCopyNo") : 0;
37  nBlades = args.value<int>("NumberOfBlades");
38  bladeAngle = args.value<double>("BladeAngle");
39  bladeTilt = args.value<double>("BladeTilt");
40  zPlane = args.value<double>("BladeCommonZ");
41  anchorR = args.value<double>("AnchorRadius");
42 
43  bladeZShift = args.value<std::vector<double> >("BladeZShift");
44 
45  childName = args.value<std::string>("ChildName");
46  rotName = args.value<std::string>("RotationName");
47  flagString = args.value<std::string>("FlagString");
48 
49  if (strchr(childName.c_str(), NAMESPACE_SEP) == nullptr)
50  childName = ns.prepend(childName);
51 
52  dd4hep::Volume child = ns.volume(childName);
53 
54  edm::LogVerbatim("PixelGeom") << "DDPixFwdDiskAlgo debug: Parent " << mother.name() << "\tChild " << child.name()
55  << " NameSpace " << ns.name() << "\tRot Name " << rotName << "\tCopyNo (Start/Total) "
56  << startCopyNo << ", " << nBlades << "\tAngles " << convertRadToDeg(bladeAngle) << ", "
57  << convertRadToDeg(bladeTilt) << "\tZshifts " << zPlane << "\tAnchor Radius "
58  << anchorR;
59 
60  for (int iBlade = 0; iBlade < nBlades; ++iBlade) {
61  edm::LogVerbatim("PixelGeom") << "DDPixFwdDiskAlgo: Blade " << iBlade << " flag " << flagString[iBlade]
62  << " zshift " << bladeZShift[iBlade];
63  }
64 
65  double deltaPhi = 360.0_deg / (double)nBlades;
66  int copyNo = startCopyNo;
67  std::string flagSelector = "Y";
68 
69  for (int iBlade = 0; iBlade < nBlades; ++iBlade) {
70  if (flagString[iBlade] == flagSelector[0]) {
71  std::string rotstr = rotName[0] + std::to_string(double(copyNo));
72  double phi = (iBlade + 0.5) * deltaPhi;
73  double phix = atan2(sin(phi) * cos(bladeAngle), cos(phi) * cos(bladeAngle));
74  double thetx = acos(-sin(bladeAngle));
75  double phiy = atan2((cos(phi) * cos(bladeTilt) + sin(phi) * sin(bladeAngle) * sin(bladeTilt)),
76  (-sin(phi) * cos(bladeTilt) + cos(phi) * sin(bladeAngle) * sin(bladeTilt)));
77 
78  double thety = acos(cos(bladeAngle) * sin(bladeTilt));
79  double phiz = atan2((-cos(phi) * sin(bladeTilt) + sin(phi) * sin(bladeAngle) * cos(bladeTilt)),
80  (sin(phi) * sin(bladeTilt) + cos(phi) * sin(bladeAngle) * cos(bladeTilt)));
81 
82  double thetz = acos(cos(bladeAngle) * cos(bladeTilt));
83 
84  auto rot = dd4hep::Rotation3D();
85 
86  auto irot = ctxt.rotations.find(ns.prepend(rotstr));
87 
88  if (irot != ctxt.rotations.end()) {
89  edm::LogVerbatim("PixelGeom") << "DDPixFwdDiskAlgo test: Creating a new "
90  << "rotation: " << rotstr << "\t" << convertRadToDeg(thetx) << ", "
91  << convertRadToDeg(phix) << ", " << convertRadToDeg(thety) << ", "
92  << convertRadToDeg(phiy) << ", " << convertRadToDeg(thetz) << ", "
93  << convertRadToDeg(phiz);
94 
95  edm::LogVerbatim("PixelGeom") << "Rotation Matrix (" << convertRadToDeg(phi) << ", "
96  << convertRadToDeg(bladeAngle) << ", " << convertRadToDeg(bladeTilt) << ") "
97  << cos(phi) * cos(bladeAngle) << ", "
98  << (-sin(phi) * cos(bladeTilt) + cos(phi) * sin(bladeAngle) * sin(bladeTilt))
99  << ", "
100  << (sin(phi) * sin(bladeTilt) + cos(phi) * sin(bladeAngle) * cos(bladeTilt))
101  << ", " << sin(phi) * cos(bladeAngle) << ", "
102  << (cos(phi) * cos(bladeTilt) + sin(phi) * sin(bladeAngle) * sin(bladeTilt))
103  << ", "
104  << (-cos(phi) * sin(bladeTilt) + sin(phi) * sin(bladeAngle) * cos(bladeTilt))
105  << ", " << -sin(bladeAngle) << ", " << cos(bladeAngle) * sin(bladeTilt) << ", "
106  << cos(bladeAngle) * cos(bladeTilt);
107  rot = cms::makeRotation3D(thetx, phix, thety, phiy, thetz, phiz);
108  }
109  double xpos = anchorR * (-sin(phi) * cos(bladeTilt) + cos(phi) * sin(bladeAngle) * sin(bladeTilt));
110  double ypos = anchorR * (cos(phi) * cos(bladeTilt) + sin(phi) * sin(bladeAngle) * sin(bladeTilt));
111  double zpos = anchorR * (cos(bladeAngle) * sin(bladeTilt)) + zPlane + bladeZShift[iBlade];
112 
113  dd4hep::Position tran(xpos, ypos, zpos);
114  pv = mother.placeVolume(child, copyNo, dd4hep::Transform3D(rot, tran));
115  edm::LogVerbatim("PixelGeom") << "DDPixFwdDiskAlgo test: " << pv.name() << ": " << childName << " number "
116  << copyNo << " positioned in " << mother.name() << " at " << tran << " with "
117  << rot;
118  }
119  copyNo++;
120  }
121 
122  edm::LogVerbatim("PixelGeom") << "Finished....";
123  return cms::s_executed;
124 }
125 
126 DECLARE_DDCMS_DETELEMENT(DDCMS_track_DDPixFwdDiskAlgo, algorithm)
Log< level::Info, true > LogVerbatim
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
std::unordered_map< std::string, dd4hep::Rotation3D > rotations
static long algorithm(dd4hep::Detector &, cms::DDParsingContext &ctxt, xml_h e)
DDRotationMatrix makeRotation3D(double thetaX, double phiX, double thetaY, double phiY, double thetaZ, double phiZ)
static std::string to_string(const XMLCh *ch)
static const std::string & rotName(const T &rot, const cms::DDParsingContext &context)
#define DECLARE_DDCMS_DETELEMENT(name, func)
Definition: DDPlugins.h:25
static constexpr long s_executed
dd4hep::PlacedVolume PlacedVolume
std::string_view name() const
Definition: DDNamespace.h:79
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
def pv(vc)
Definition: MetAnalyzer.py:7
dd4hep::Volume Volume
dd4hep::Volume volume(const std::string &name, bool exc=true) const
Definition: DDNamespace.cc:276
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:99
#define NAMESPACE_SEP
Definition: DDNamespace.h:92