CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/DetectorDescription/Algorithm/src/DDAngular.cc

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