CMS 3D CMS Logo

DDLinear.cc
Go to the documentation of this file.
1 #include "DD4hep/DetFactoryHelper.h"
5 #include <Math/Cartesian3D.h>
6 #include <Math/DisplacementVector3D.h>
7 
8 using namespace std;
9 using namespace dd4hep;
10 using namespace cms;
11 using namespace geant_units::operators;
12 
13 using DD3Vector = ROOT::Math::DisplacementVector3D<ROOT::Math::Cartesian3D<double> >;
14 
15 static long algorithm( Detector& /* description */,
17  xml_h e,
18  SensitiveDetector& /* sens */)
19 {
20  cms::DDNamespace ns( ctxt, e, true );
21  DDAlgoArguments args( ctxt, e );
22 
23  int n = args.value<int>("N");
24  int startCopyNo = args.find("StartCopyNo") ? args.value<int>("StartCopyNo") : 1;
25  int incrCopyNo = args.find("IncrCopyNo") ? args.value<int>("IncrCopyNo") : 1;
26  double theta = args.find("Theta") ? args.value<double>("Theta") : 0.;
27  double phi = args.find("Phi") ? args.value<double>("Phi") : 0.;
28  double delta = args.find("Delta") ? args.value<double>("Delta") : 0.;
29  vector<double> base = args.value<vector<double> >("Base");
30  Volume mother = ns.volume(args.parentName());
31  Volume child = ns.volume(args.value<string>("ChildName"));
32  int copy = startCopyNo;
33 
34  LogDebug("DDAlgorithm") << "DDLinear: Parameters for positioning:: n "
35  << n << " Direction Theta, Phi, Delta "
36  << convertRadToDeg( theta ) << " "
37  << convertRadToDeg( phi ) << " " << convertRadToDeg( delta )
38  << " Base " << base[0]
39  << ", " << base[1] << ", " << base[2];
40 
41  LogDebug("DDAlgorithm") << "DDLinear: Parent " << mother.name()
42  << "\tChild " << child.name() << " NameSpace "
43  << ns.name();
44 
45  Position direction( sin( theta ) * cos( phi ),
46  sin( theta ) * sin( phi ),
47  cos( theta ));
48 
49  Position basetr( base[0], base[1], base[2] );
50 
51  Rotation3D rotation = Rotation3D(); // Identity rotation
52 
53  for( int i = 0; i < n; ++i )
54  {
55  Position tran = basetr + ( double( copy ) * delta ) * direction;
56  mother.placeVolume( child, copy, Transform3D( rotation, tran ));
57  LogDebug( "DDAlgorithm" ) << "DDLinear: " << child.name() << " number "
58  << copy << " positioned in " << mother.name() << " at "
59  << tran << " with " << rotation;
60 
61  copy += incrCopyNo;
62  }
63 
64  return 1;
65 }
66 
67 // first argument is the type from the xml file
68 DECLARE_DDCMS_DETELEMENT( DDCMS_global_DDLinear, algorithm )
#define LogDebug(id)
dbl * delta
Definition: mlp_gen.cc:36
dd4hep::Volume volume(const std::string &name, bool exc=true) const
Definition: DDNamespace.cc:193
static long algorithm(Detector &, cms::DDParsingContext &ctxt, xml_h e, SensitiveDetector &)
Definition: DDLinear.cc:15
def copy(args, dbName)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
T value(const std::string &name) const
Geom::Theta< T > theta() const
constexpr NumType convertRadToDeg(NumType radians)
Definition: GeantUnits.h:98
std::string_view name() const
Definition: DDNamespace.h:65
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DD3Vector
A DD Translation is currently implemented with Root Vector3D.
Definition: DDTranslation.h:6
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
base
Make Sure CMSSW is Setup ##.
dd4hep::Volume Volume
Namespace of DDCMS conversion namespace.
#define DECLARE_DDCMS_DETELEMENT(name, func)
Definition: DDPlugins.h:31
bool find(const std::string &name) const
Check the existence of an argument by name.
std::string parentName() const
Access value of rParent child node.