Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:05:28

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 
0008 using namespace std;
0009 using namespace dd4hep;
0010 using namespace cms;
0011 using namespace cms_units::operators;
0012 
0013 using DD3Vector = ROOT::Math::DisplacementVector3D<ROOT::Math::Cartesian3D<double> >;
0014 
0015 static long algorithm(Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
0016   cms::DDNamespace ns(ctxt, e, true);
0017   DDAlgoArguments args(ctxt, e);
0018 
0019   int n = args.value<int>("N");
0020   int startCopyNo = args.find("StartCopyNo") ? args.value<int>("StartCopyNo") : 1;
0021   int incrCopyNo = args.find("IncrCopyNo") ? args.value<int>("IncrCopyNo") : 1;
0022   double theta = args.find("Theta") ? args.value<double>("Theta") : 0.;
0023   double phi = args.find("Phi") ? args.value<double>("Phi") : 0.;
0024   double delta = args.find("Delta") ? args.value<double>("Delta") : 0.;
0025   vector<double> base = args.value<vector<double> >("Base");
0026   Volume mother = ns.volume(args.parentName());
0027   Volume child = ns.volume(args.value<string>("ChildName"));
0028   int copy = startCopyNo;
0029 
0030   LogDebug("DDAlgorithm") << "DDLinear: Parameters for positioning:: n " << n << "  Direction Theta, Phi, Delta "
0031                           << convertRadToDeg(theta) << " " << convertRadToDeg(phi) << " " << convertRadToDeg(delta)
0032                           << " Base " << base[0] << ", " << base[1] << ", " << base[2];
0033 
0034   LogDebug("DDAlgorithm") << "DDLinear: Parent " << mother.name() << "\tChild " << child.name() << " NameSpace "
0035                           << ns.name();
0036 
0037   Position direction(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta));
0038 
0039   Position basetr(base[0], base[1], base[2]);
0040 
0041   Rotation3D rotation = Rotation3D();  // Identity rotation
0042 
0043   for (int i = 0; i < n; ++i) {
0044     Position tran = basetr + (double(copy) * delta) * direction;
0045     mother.placeVolume(child, copy, Transform3D(rotation, tran));
0046     LogDebug("DDAlgorithm") << "DDLinear: " << child.name() << " number " << copy << " positioned in " << mother.name()
0047                             << " at " << tran << " with " << rotation;
0048 
0049     copy += incrCopyNo;
0050   }
0051 
0052   return 1;
0053 }
0054 
0055 // first argument is the type from the xml file
0056 DECLARE_DDCMS_DETELEMENT(DDCMS_global_DDLinear, algorithm)