File indexing completed on 2024-04-06 12:15:14
0001 #include "DD4hep/DetFactoryHelper.h"
0002 #include "DataFormats/Math/interface/CMSUnits.h"
0003 #include "DetectorDescription/DDCMS/interface/DDPlugins.h"
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #include <Math/Cartesian3D.h>
0006 #include <Math/DisplacementVector3D.h>
0007 #include "DataFormats/Math/interface/GeantUnits.h"
0008
0009 using namespace std;
0010 using namespace dd4hep;
0011 using namespace cms;
0012 using namespace cms_units::operators;
0013
0014 using DD3Vector = ROOT::Math::DisplacementVector3D<ROOT::Math::Cartesian3D<double> >;
0015
0016 static long algorithm(Detector& , cms::DDParsingContext& ctxt, xml_h e) {
0017 cms::DDNamespace ns(ctxt, e, true);
0018 DDAlgoArguments args(ctxt, e);
0019
0020 int n = args.value<int>("N");
0021 int startCopyNo = args.find("StartCopyNo") ? args.value<int>("StartCopyNo") : 1;
0022 int incrCopyNo = args.find("IncrCopyNo") ? args.value<int>("IncrCopyNo") : 1;
0023 double theta = args.find("Theta") ? args.value<double>("Theta") : 0.;
0024 double phi = args.find("Phi") ? args.value<double>("Phi") : 0.;
0025 double theta_obj = args.find("Theta_obj") ? args.value<double>("Theta_obj") : 0.;
0026 double phi_obj = args.find("Phi_obj") ? args.value<double>("Phi_obj") : 0.;
0027 double delta = args.find("Delta") ? args.value<double>("Delta") : 0.;
0028 vector<double> base = args.value<vector<double> >("Base");
0029 Volume mother = ns.volume(args.parentName());
0030 Volume child = ns.volume(args.value<string>("ChildName"));
0031 int copy = startCopyNo;
0032
0033 LogDebug("DDAlgorithm") << "DDMTDLinear: Parameters for positioning:: n " << n << " Direction Theta, Phi, Delta "
0034 << convertRadToDeg(theta) << " " << convertRadToDeg(phi) << " " << convertRadToDeg(delta)
0035 << " Base " << base[0] << ", " << base[1] << ", " << base[2] << convertRadToDeg(theta_obj)
0036 << " " << convertRadToDeg(phi_obj);
0037
0038 LogDebug("DDAlgorithm") << "DDMTDLinear: Parent " << mother.name() << "\tChild " << child.name() << " NameSpace "
0039 << ns.name();
0040
0041 Position direction(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta));
0042
0043 Position basetr(base[0], base[1], base[2]);
0044
0045
0046 double thetaZ = theta_obj - 0.5_pi;
0047 double phiZ = phi_obj;
0048 double thetaX = theta_obj;
0049 double thetaY = theta_obj;
0050 double phiX = phi_obj;
0051 double phiY = phi_obj + 0.5_pi;
0052
0053 Rotation3D rotation = makeRotation3D(thetaX, phiX, thetaY, phiY, thetaZ, phiZ);
0054
0055 for (int i = 0; i < n; ++i) {
0056 Position tran = basetr + (double(i) * delta) * direction;
0057 mother.placeVolume(child, copy, Transform3D(rotation, tran));
0058 LogDebug("DDAlgorithm") << "DDMTDLinear: " << child.name() << " number " << copy << " positioned in "
0059 << mother.name() << " at " << tran << " with " << rotation;
0060
0061 copy += incrCopyNo;
0062 }
0063
0064 return 1;
0065 }
0066
0067
0068 DECLARE_DDCMS_DETELEMENT(DDCMS_mtd_DDMTDLinear, algorithm)