Go to the documentation of this file.00001 #include "DetectorDescription/Algorithm/interface/DDAngular.h"
00002 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
00003 #include "DetectorDescription/Core/interface/DDSplit.h"
00004 #include "DetectorDescription/Base/interface/DDutils.h"
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00007
00008 DDAngular::DDAngular( void )
00009 {
00010 LogDebug( "DDAlgorithm" ) << "DDAngular: Creating an instance.";
00011 }
00012
00013 DDAngular::~DDAngular( void )
00014 {}
00015
00016 void
00017 DDAngular::initialize( const DDNumericArguments & nArgs,
00018 const DDVectorArguments & vArgs,
00019 const DDMapArguments & ,
00020 const DDStringArguments & sArgs,
00021 const DDStringVectorArguments & )
00022 {
00023 m_n = int(nArgs["N"]);
00024 m_startCopyNo = int(nArgs["StartCopyNo"]);
00025 m_incrCopyNo = int(nArgs["IncrCopyNo"]);
00026 m_rangeAngle = nArgs["RangeAngle"];
00027 m_startAngle = nArgs["StartAngle"];
00028 m_radius = nArgs["Radius"];
00029 m_center = vArgs["Center"];
00030 m_rotateSolid = vArgs["RotateSolid"];
00031
00032 m_solidRot = DDRotationMatrix();
00033
00034 if( fabs( m_rangeAngle - 360.0 * CLHEP::deg ) < 0.001 * CLHEP::deg )
00035 {
00036 m_delta = m_rangeAngle / double( m_n );
00037 }
00038 else
00039 {
00040 if( m_n > 1 )
00041 {
00042 m_delta = m_rangeAngle / double( m_n - 1 );
00043 }
00044 else
00045 {
00046 m_delta = 0.;
00047 }
00048 }
00049
00050 LogDebug( "DDAlgorithm" ) << "DDAngular: Parameters for position"
00051 << "ing:: n " << m_n << " Start, Range, Delta "
00052 << m_startAngle/CLHEP::deg << " "
00053 << m_rangeAngle/CLHEP::deg << " " << m_delta/CLHEP::deg
00054 << " Radius " << m_radius << " Centre " << m_center[0]
00055 << ", " << m_center[1] << ", " << m_center[2];
00056
00057
00058 typedef parE_type::mapped_type::size_type sz_type;
00059 sz_type sz = m_rotateSolid.size();
00060 if( sz%3 )
00061 {
00062 LogDebug( "DDAlgorithm" ) << "\trotateSolid must occur 3*n times (defining n subsequent rotations)\n"
00063 << "\t currently it appears " << sz << " times!\n";
00064 }
00065 for( sz_type i = 0; i < sz; i += 3 )
00066 {
00067 if(( m_rotateSolid[i] > 180. * deg ) || ( m_rotateSolid[i] < 0. ))
00068 {
00069 LogDebug( "DDAlgorithm" ) << "\trotateSolid \'theta\' must be in range [0,180*deg]\n"
00070 << "\t currently it is " << m_rotateSolid[i]/deg
00071 << "*deg in rotateSolid[" << double(i) << "]!\n";
00072 }
00073 DDAxisAngle temp( fUnitVector( m_rotateSolid[i], m_rotateSolid[i + 1] ),
00074 m_rotateSolid[i + 2] );
00075 LogDebug( "DDAlgorithm" ) << " rotsolid[" << i << "] axis=" << temp.Axis() << " rot.angle=" << temp.Angle()/deg;
00076 m_solidRot = temp * m_solidRot;
00077 }
00078
00079 m_idNameSpace = DDCurrentNamespace::ns();
00080
00081 m_childNmNs = DDSplit( sArgs["ChildName"] );
00082 if( m_childNmNs.second.empty())
00083 m_childNmNs.second = DDCurrentNamespace::ns();
00084
00085 DDName parentName = parent().name();
00086 LogDebug( "DDAlgorithm" ) << "DDAngular: Parent " << parentName
00087 << "\tChild " << m_childNmNs.first << "\tNameSpace "
00088 << m_childNmNs.second;
00089 }
00090
00091 void
00092 DDAngular::execute( DDCompactView& cpv )
00093 {
00094 DDName mother = parent().name();
00095 DDName ddname( m_childNmNs.first, m_childNmNs.second );
00096 double theta = 90.*CLHEP::deg;
00097 int copy = m_startCopyNo;
00098 double phi = m_startAngle;
00099
00100 for( int i = 0; i < m_n; ++i )
00101 {
00102 double phix = phi;
00103 double phiy = phix + 90. * CLHEP::deg;
00104 double phideg = phix / CLHEP::deg;
00105
00106 std::string rotstr = m_childNmNs.first + "_" + dbl_to_string( phideg * 10.);
00107 DDRotation rotation = DDRotation( DDName( rotstr, m_idNameSpace ));
00108 if( !rotation )
00109 {
00110 LogDebug( "DDAlgorithm" ) << "DDAngular: Creating a new "
00111 << "rotation: " << rotstr << "\t90., "
00112 << phix / CLHEP::deg << ", 90.,"
00113 << phiy / CLHEP::deg << ", 0, 0";
00114
00115 rotation = DDrot( DDName( rotstr, m_idNameSpace ), new DDRotationMatrix(( *DDcreateRotationMatrix( theta, phix, theta, phiy,
00116 0., 0. ) * m_solidRot )));
00117 }
00118
00119 double xpos = m_radius * cos( phi ) + m_center[0];
00120 double ypos = m_radius * sin( phi ) + m_center[1];
00121 double zpos = m_center[2];
00122 DDTranslation tran( xpos, ypos, zpos );
00123
00124 cpv.position( ddname, mother, copy, tran, rotation );
00125 LogDebug( "DDAlgorithm" ) << "DDAngular: child " << m_childNmNs.second << ":" << m_childNmNs.first << " number "
00126 << copy << " positioned in " << mother << " at "
00127 << tran << " with " << rotation << "\n";
00128 copy += m_incrCopyNo;
00129 phi += m_delta;
00130 }
00131 }
00132
00133 DD3Vector
00134 DDAngular::fUnitVector( double theta, double phi )
00135 {
00136 return DD3Vector( cos( phi ) * sin( theta ),
00137 sin( phi ) * sin( theta ),
00138 cos( theta ));
00139 }