CMS 3D CMS Logo

DDAngular.cc
Go to the documentation of this file.
1 #include "DDAngular.h"
2 
3 #include <cmath>
4 
5 #include "CLHEP/Units/GlobalSystemOfUnits.h"
6 #include "CLHEP/Units/SystemOfUnits.h"
15 #include "Math/GenVector/AxisAngle.h"
16 #include "Math/GenVector/DisplacementVector3D.h"
17 #include "Math/GenVector/Rotation3D.h"
18 
20  : m_n( 1 ),
21  m_startCopyNo( 1 ),
22  m_incrCopyNo( 1 ),
23  m_startAngle( 0. ),
24  m_rangeAngle( 360*deg ),
25  m_radius( 0. ),
26  m_delta( 0. )
27 {
28  LogDebug( "DDAlgorithm" ) << "DDAngular: Creating an instance.";
29 }
30 
32 {}
33 
34 void
36  const DDVectorArguments & vArgs,
37  const DDMapArguments & ,
38  const DDStringArguments & sArgs,
39  const DDStringVectorArguments & )
40 {
41  m_n = int(nArgs["N"]);
42  m_startCopyNo = int(nArgs["StartCopyNo"]);
43  m_incrCopyNo = int(nArgs["IncrCopyNo"]);
44  m_rangeAngle = nArgs["RangeAngle"];
45  m_startAngle = nArgs["StartAngle"];
46  m_radius = nArgs["Radius"];
47  m_center = vArgs["Center"];
48  m_rotateSolid = vArgs["RotateSolid"];
49 
51 
52  if( fabs( m_rangeAngle - 360.0 * CLHEP::deg ) < 0.001 * CLHEP::deg )
53  {
54  m_delta = m_rangeAngle / double( m_n );
55  }
56  else
57  {
58  if( m_n > 1 )
59  {
60  m_delta = m_rangeAngle / double( m_n - 1 );
61  }
62  else
63  {
64  m_delta = 0.;
65  }
66  }
67 
68  LogDebug( "DDAlgorithm" ) << "DDAngular: Parameters for position"
69  << "ing:: n " << m_n << " Start, Range, Delta "
70  << m_startAngle/CLHEP::deg << " "
71  << m_rangeAngle/CLHEP::deg << " " << m_delta/CLHEP::deg
72  << " Radius " << m_radius << " Centre " << m_center[0]
73  << ", " << m_center[1] << ", " << m_center[2];
74 
75  //======= collect data concerning the rotation of the solid
76  typedef parE_type::mapped_type::size_type sz_type;
77  sz_type sz = m_rotateSolid.size();
78  if( sz%3 )
79  {
80  LogDebug( "DDAlgorithm" ) << "\trotateSolid must occur 3*n times (defining n subsequent rotations)\n"
81  << "\t currently it appears " << sz << " times!\n";
82  }
83  for( sz_type i = 0; i < sz; i += 3 )
84  {
85  if(( m_rotateSolid[i] > 180. * deg ) || ( m_rotateSolid[i] < 0. ))
86  {
87  LogDebug( "DDAlgorithm" ) << "\trotateSolid \'theta\' must be in range [0,180*deg]\n"
88  << "\t currently it is " << m_rotateSolid[i]/deg
89  << "*deg in rotateSolid[" << double(i) << "]!\n";
90  }
92  m_rotateSolid[i + 2] );
93  LogDebug( "DDAlgorithm" ) << " rotsolid[" << i << "] axis=" << temp.Axis() << " rot.angle=" << temp.Angle()/deg;
94  m_solidRot = temp * m_solidRot;
95  }
96 
98  m_childNmNs = DDSplit( sArgs["ChildName"] );
99  if( m_childNmNs.second.empty())
101 
102  DDName parentName = parent().name();
103  LogDebug( "DDAlgorithm" ) << "DDAngular: Parent " << parentName
104  << "\tChild " << m_childNmNs.first << "\tNameSpace "
105  << m_childNmNs.second;
106 }
107 
108 void
110 {
111  DDName mother = parent().name();
112  DDName ddname( m_childNmNs.first, m_childNmNs.second );
113  double theta = 90.*CLHEP::deg;
114  int copy = m_startCopyNo;
115  double phi = m_startAngle;
116 
117  for( int i = 0; i < m_n; ++i )
118  {
119  double phix = phi;
120  double phiy = phix + 90. * CLHEP::deg;
121  double phideg = phix / CLHEP::deg;
122 
123  std::string rotstr = m_childNmNs.first + "_" + std::to_string( phideg * 10.);
125  if( !rotation )
126  {
127  LogDebug( "DDAlgorithm" ) << "DDAngular: Creating a new "
128  << "rotation: " << rotstr << "\t90., "
129  << phix / CLHEP::deg << ", 90.,"
130  << phiy / CLHEP::deg << ", 0, 0";
131 
132  rotation = DDrot( DDName( rotstr, m_idNameSpace ), new DDRotationMatrix(( *DDcreateRotationMatrix( theta, phix, theta, phiy,
133  0., 0. ) * m_solidRot )));
134  }
135 
136  double xpos = m_radius * cos( phi ) + m_center[0];
137  double ypos = m_radius * sin( phi ) + m_center[1];
138  double zpos = m_center[2];
139  DDTranslation tran( xpos, ypos, zpos );
140 
141  cpv.position( ddname, mother, copy, tran, rotation );
142  LogDebug( "DDAlgorithm" ) << "DDAngular: child " << m_childNmNs.second << ":" << m_childNmNs.first << " number "
143  << copy << " positioned in " << mother << " at "
144  << tran << " with " << rotation << "\n";
145  copy += m_incrCopyNo;
146  phi += m_delta;
147  }
148 }
149 
150 DD3Vector
152 {
153  return DD3Vector( cos( phi ) * sin( theta ),
154  sin( phi ) * sin( theta ),
155  cos( theta ));
156 }
#define LogDebug(id)
double m_radius
Definition: DDAngular.h:37
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Theta< T > theta() const
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:15
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override
Definition: DDAngular.cc:35
static std::string & ns()
DD3Vector fUnitVector(double theta, double phi)
Definition: DDAngular.cc:151
type of data representation of DDCompactView
Definition: DDCompactView.h:90
uint16_t size_type
DDRotationMatrix m_solidRot
Definition: DDAngular.h:46
double m_delta
Definition: DDAngular.h:38
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:67
void execute(DDCompactView &cpv) override
Definition: DDAngular.cc:109
int m_n
Definition: DDAngular.h:32
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
int m_incrCopyNo
Definition: DDAngular.h:34
std::vector< double > m_rotateSolid
Definition: DDAngular.h:40
std::vector< double > m_center
Definition: DDAngular.h:39
~DDAngular(void) override
Definition: DDAngular.cc:31
DDRotation DDrot(const DDName &name, DDRotationMatrix *rot)
Definition of a uniquely identifiable rotation matrix named by DDName name.
Definition: DDRotation.cc:90
std::string m_idNameSpace
Definition: DDAngular.h:42
DDAngular(void)
Definition: DDAngular.cc:19
double m_rangeAngle
Definition: DDAngular.h:36
void position(const DDLogicalPart &self, const DDLogicalPart &parent, const std::string &copyno, const DDTranslation &trans, const DDRotation &rot, const DDDivision *div=0)
std::pair< std::string, std::string > m_childNmNs
Definition: DDAngular.h:43
std::pair< std::string, std::string > DDSplit(const std::string &n)
split into (name,namespace), separator = &#39;:&#39;
Definition: DDSplit.cc:3
ROOT::Math::AxisAngle DDAxisAngle
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
int m_startCopyNo
Definition: DDAngular.h:33
double m_startAngle
Definition: DDAngular.h:35
DDRotationMatrix * DDcreateRotationMatrix(double thetaX, double phiX, double thetaY, double phiY, double thetaZ, double phiZ)
create a new DDRotationMatrix in the GEANT3 style.
Definition: DDRotation.cc:164