From a46c3d07e22420935abacb8b7c85e60b3d36d4d9 Mon Sep 17 00:00:00 2001 From: Fabio Cossutti Date: Mon, 27 Jan 2020 16:50:51 +0100 Subject: [PATCH] Initial import of DDMTDLinear for DD4hep --- Geometry/MTDCommonData/plugins/BuildFile.xml | 9 +++ .../plugins/dd4hep/DDMTDLinear.cc | 68 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 Geometry/MTDCommonData/plugins/dd4hep/DDMTDLinear.cc diff --git a/Geometry/MTDCommonData/plugins/BuildFile.xml b/Geometry/MTDCommonData/plugins/BuildFile.xml index 68c97743eca7b..5ada6c0fd3306 100644 --- a/Geometry/MTDCommonData/plugins/BuildFile.xml +++ b/Geometry/MTDCommonData/plugins/BuildFile.xml @@ -5,3 +5,12 @@ + + + + + + + + + diff --git a/Geometry/MTDCommonData/plugins/dd4hep/DDMTDLinear.cc b/Geometry/MTDCommonData/plugins/dd4hep/DDMTDLinear.cc new file mode 100644 index 0000000000000..e445405f7e431 --- /dev/null +++ b/Geometry/MTDCommonData/plugins/dd4hep/DDMTDLinear.cc @@ -0,0 +1,68 @@ +#include "DD4hep/DetFactoryHelper.h" +#include "DataFormats/Math/interface/CMSUnits.h" +#include "DetectorDescription/DDCMS/interface/DDPlugins.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include +#include +#include "DataFormats/Math/interface/GeantUnits.h" + +using namespace std; +using namespace dd4hep; +using namespace cms; +using namespace cms_units::operators; + +using DD3Vector = ROOT::Math::DisplacementVector3D >; + +static long algorithm(Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e, SensitiveDetector& /* sens */) { + cms::DDNamespace ns(ctxt, e, true); + DDAlgoArguments args(ctxt, e); + + int n = args.value("N"); + int startCopyNo = args.find("StartCopyNo") ? args.value("StartCopyNo") : 1; + int incrCopyNo = args.find("IncrCopyNo") ? args.value("IncrCopyNo") : 1; + double theta = args.find("Theta") ? args.value("Theta") : 0.; + double phi = args.find("Phi") ? args.value("Phi") : 0.; + double theta_obj = args.find("Theta_obj") ? args.value("Theta_obj") : 0.; + double phi_obj = args.find("Phi_obj") ? args.value("Phi_obj") : 0.; + double delta = args.find("Delta") ? args.value("Delta") : 0.; + vector base = args.value >("Base"); + Volume mother = ns.volume(args.parentName()); + Volume child = ns.volume(args.value("ChildName")); + int copy = startCopyNo; + + LogDebug("DDAlgorithm") << "DDMTDLinear: Parameters for positioning:: n " << n << " Direction Theta, Phi, Delta " + << convertRadToDeg(theta) << " " << convertRadToDeg(phi) << " " << convertRadToDeg(delta) + << " Base " << base[0] << ", " << base[1] << ", " << base[2] << convertRadToDeg(theta_obj) << " " << convertRadToDeg(phi_obj); + + LogDebug("DDAlgorithm") << "DDMTDLinear: Parent " << mother.name() << "\tChild " << child.name() << " NameSpace " + << ns.name(); + + Position direction(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta)); + + Position basetr(base[0], base[1], base[2]); + + //rotation is in xy plane + //double thetaZ = theta_obj - 0.5_pi; + //double phiZ = phi_obj; + //double thetaX = theta_obj; + //double thetaY = theta_obj; + //double phiX = phi_obj; + //double phiY = phi_obj + 0.5_pi; + + //Rotation3D rotation = Rotation3D(thetaX, phiX, thetaY, phiY, thetaZ, phiZ); + Rotation3D rotation = Rotation3D(RotationZYX(phi_obj,theta_obj,0.)); + + for (int i = 0; i < n; ++i) { + Position tran = basetr + (double(i) * delta) * direction; + mother.placeVolume(child, copy, Transform3D(rotation, tran)); + LogDebug("DDAlgorithm") << "DDMTDLinear: " << child.name() << " number " << copy << " positioned in " << mother.name() + << " at " << tran << " with " << rotation; + + copy += incrCopyNo; + } + + return 1; +} + +// first argument is the type from the xml file +DECLARE_DDCMS_DETELEMENT(DDCMS_mtd_DDMTDLinear, algorithm)