File indexing completed on 2024-04-06 12:15:21
0001
0002
0003
0004
0005
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include "DetectorDescription/DDCMS/interface/DDPlugins.h"
0008 #include "DD4hep/DetFactoryHelper.h"
0009 #include "DD4hep/Printout.h"
0010
0011 #include "DataFormats/Math/interface/CMSUnits.h"
0012
0013 #include <sstream>
0014
0015 using namespace cms_units::operators;
0016
0017 static long algorithm(dd4hep::Detector& , cms::DDParsingContext& ctxt, xml_h e) {
0018 cms::DDNamespace ns(ctxt, e, true);
0019 cms::DDAlgoArguments args(ctxt, e);
0020
0021 int nBlades;
0022 int startCopyNo;
0023 double bladeAngle;
0024 double bladeTilt;
0025 double zPlane;
0026 std::vector<double> bladeZShift;
0027 double anchorR;
0028
0029 std::string childName;
0030 std::string rotName;
0031 std::string flagString;
0032
0033 dd4hep::Volume mother = ns.volume(args.parentName());
0034 dd4hep::PlacedVolume pv;
0035
0036 startCopyNo = args.find("StartCopyNo") ? args.value<int>("StartCopyNo") : 0;
0037 nBlades = args.value<int>("NumberOfBlades");
0038 bladeAngle = args.value<double>("BladeAngle");
0039 bladeTilt = args.value<double>("BladeTilt");
0040 zPlane = args.value<double>("BladeCommonZ");
0041 anchorR = args.value<double>("AnchorRadius");
0042
0043 bladeZShift = args.value<std::vector<double> >("BladeZShift");
0044
0045 childName = args.value<std::string>("ChildName");
0046 rotName = args.value<std::string>("RotationName");
0047 flagString = args.value<std::string>("FlagString");
0048
0049 if (strchr(childName.c_str(), NAMESPACE_SEP) == nullptr)
0050 childName = ns.prepend(childName);
0051
0052 dd4hep::Volume child = ns.volume(childName);
0053
0054 edm::LogVerbatim("PixelGeom") << "DDPixFwdDiskAlgo debug: Parent " << mother.name() << "\tChild " << child.name()
0055 << " NameSpace " << ns.name() << "\tRot Name " << rotName << "\tCopyNo (Start/Total) "
0056 << startCopyNo << ", " << nBlades << "\tAngles " << convertRadToDeg(bladeAngle) << ", "
0057 << convertRadToDeg(bladeTilt) << "\tZshifts " << zPlane << "\tAnchor Radius "
0058 << anchorR;
0059
0060 for (int iBlade = 0; iBlade < nBlades; ++iBlade) {
0061 edm::LogVerbatim("PixelGeom") << "DDPixFwdDiskAlgo: Blade " << iBlade << " flag " << flagString[iBlade]
0062 << " zshift " << bladeZShift[iBlade];
0063 }
0064
0065 double deltaPhi = 360.0_deg / (double)nBlades;
0066 int copyNo = startCopyNo;
0067 std::string flagSelector = "Y";
0068
0069 for (int iBlade = 0; iBlade < nBlades; ++iBlade) {
0070 if (flagString[iBlade] == flagSelector[0]) {
0071 std::string rotstr = rotName[0] + std::to_string(double(copyNo));
0072 double phi = (iBlade + 0.5) * deltaPhi;
0073 double phix = atan2(sin(phi) * cos(bladeAngle), cos(phi) * cos(bladeAngle));
0074 double thetx = acos(-sin(bladeAngle));
0075 double phiy = atan2((cos(phi) * cos(bladeTilt) + sin(phi) * sin(bladeAngle) * sin(bladeTilt)),
0076 (-sin(phi) * cos(bladeTilt) + cos(phi) * sin(bladeAngle) * sin(bladeTilt)));
0077
0078 double thety = acos(cos(bladeAngle) * sin(bladeTilt));
0079 double phiz = atan2((-cos(phi) * sin(bladeTilt) + sin(phi) * sin(bladeAngle) * cos(bladeTilt)),
0080 (sin(phi) * sin(bladeTilt) + cos(phi) * sin(bladeAngle) * cos(bladeTilt)));
0081
0082 double thetz = acos(cos(bladeAngle) * cos(bladeTilt));
0083
0084 auto rot = dd4hep::Rotation3D();
0085
0086 auto irot = ctxt.rotations.find(ns.prepend(rotstr));
0087
0088 if (irot != ctxt.rotations.end()) {
0089 edm::LogVerbatim("PixelGeom") << "DDPixFwdDiskAlgo test: Creating a new "
0090 << "rotation: " << rotstr << "\t" << convertRadToDeg(thetx) << ", "
0091 << convertRadToDeg(phix) << ", " << convertRadToDeg(thety) << ", "
0092 << convertRadToDeg(phiy) << ", " << convertRadToDeg(thetz) << ", "
0093 << convertRadToDeg(phiz);
0094
0095 edm::LogVerbatim("PixelGeom") << "Rotation Matrix (" << convertRadToDeg(phi) << ", "
0096 << convertRadToDeg(bladeAngle) << ", " << convertRadToDeg(bladeTilt) << ") "
0097 << cos(phi) * cos(bladeAngle) << ", "
0098 << (-sin(phi) * cos(bladeTilt) + cos(phi) * sin(bladeAngle) * sin(bladeTilt))
0099 << ", "
0100 << (sin(phi) * sin(bladeTilt) + cos(phi) * sin(bladeAngle) * cos(bladeTilt))
0101 << ", " << sin(phi) * cos(bladeAngle) << ", "
0102 << (cos(phi) * cos(bladeTilt) + sin(phi) * sin(bladeAngle) * sin(bladeTilt))
0103 << ", "
0104 << (-cos(phi) * sin(bladeTilt) + sin(phi) * sin(bladeAngle) * cos(bladeTilt))
0105 << ", " << -sin(bladeAngle) << ", " << cos(bladeAngle) * sin(bladeTilt) << ", "
0106 << cos(bladeAngle) * cos(bladeTilt);
0107 rot = cms::makeRotation3D(thetx, phix, thety, phiy, thetz, phiz);
0108 }
0109 double xpos = anchorR * (-sin(phi) * cos(bladeTilt) + cos(phi) * sin(bladeAngle) * sin(bladeTilt));
0110 double ypos = anchorR * (cos(phi) * cos(bladeTilt) + sin(phi) * sin(bladeAngle) * sin(bladeTilt));
0111 double zpos = anchorR * (cos(bladeAngle) * sin(bladeTilt)) + zPlane + bladeZShift[iBlade];
0112
0113 dd4hep::Position tran(xpos, ypos, zpos);
0114 pv = mother.placeVolume(child, copyNo, dd4hep::Transform3D(rot, tran));
0115 edm::LogVerbatim("PixelGeom") << "DDPixFwdDiskAlgo test: " << pv.name() << ": " << childName << " number "
0116 << copyNo << " positioned in " << mother.name() << " at " << tran << " with "
0117 << rot;
0118 }
0119 copyNo++;
0120 }
0121
0122 edm::LogVerbatim("PixelGeom") << "Finished....";
0123 return cms::s_executed;
0124 }
0125
0126 DECLARE_DDCMS_DETELEMENT(DDCMS_track_DDPixFwdDiskAlgo, algorithm)