CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/DetectorDescription/Parser/src/DDDividedTrd.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // 25.04.04 - M. Case ddd-ize G4ParameterisationTrd*
00004 // ********************************************************************
00005 
00006 #include "DetectorDescription/Parser/src/DDDividedTrd.h"
00007 #include "DetectorDescription/Parser/src/DDXMLElement.h"
00008 
00009 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
00010 #include "DetectorDescription/Core/interface/DDName.h"
00011 #include "DetectorDescription/Core/interface/DDAxes.h"
00012 #include "DetectorDescription/Core/interface/DDSolid.h"
00013 #include "DetectorDescription/Core/interface/DDMaterial.h"
00014 
00015 #include "DetectorDescription/Base/interface/DDdebug.h"
00016 #include "DetectorDescription/Base/interface/DDException.h"
00017 
00018 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00019 
00020 #include <cmath>
00021 #include <cstdlib>
00022 
00023 DDDividedTrdX::DDDividedTrdX( const DDDivision& div, DDCompactView* cpv )
00024   : DDDividedGeometryObject(div,cpv)
00025 {
00026   checkParametersValidity();
00027   setType( "DivisionTrdX" );
00028   DDTrap mtrd = (DDTrap)( div_.parent().solid() );
00029 
00030   if ( divisionType_ == DivWIDTH )
00031   {
00032     compNDiv_ = calculateNDiv( 2 * mtrd.x1(), div_.width(), div_.offset() );
00033   }
00034   else if( divisionType_ == DivNDIV )
00035   {
00036     compWidth_ = calculateWidth( 2*mtrd.x1(), div_.nReplicas(), div_.offset() );
00037   }
00038 
00039   DCOUT_V ('P', " DDDividedTrdX - ## divisions " << compNDiv_ << " = " << div_.nReplicas() << "\n Offset " << div_.offset() << "\n Width " << compWidth_ << " = " << div_.width());
00040 }
00041 
00042 DDDividedTrdX::~DDDividedTrdX( void )
00043 {}
00044 
00045 double
00046 DDDividedTrdX::getMaxParameter( void ) const
00047 {
00048   DDTrap mtrd = (DDTrap)(div_.parent().solid());
00049   return 2 * mtrd.x1();
00050 }
00051 
00052 DDTranslation
00053 DDDividedTrdX::makeDDTranslation( const int copyNo ) const
00054 {
00055   DDTrap mtrd = (DDTrap)(div_.parent().solid());
00056   double mdx = mtrd.x1();
00057 
00058 
00059   //----- translation 
00060   double posi = -mdx + div_.offset() + (copyNo+0.5)*compWidth_;
00061 
00062   DCOUT_V ('P', " DDDividedTrdX: " << copyNo << "\n Position: x=" << posi << "  Axis= " << DDAxesNames::name(div_.axis()) << "\n");
00063 
00064   if( div_.axis() == x )
00065   {
00066     return DDTranslation(posi, 0.0, 0.0);
00067   }
00068   else
00069   { 
00070     std::string s = "ERROR - DDDividedTrdX::makeDDTranslation()";
00071     s += "\n        Axis is along ";
00072     s += DDAxesNames::name(div_.axis());
00073     s += " !\n" ;
00074     s += "DDDividedTrdX::makeDDTranslation()";
00075     s += " IllegalConstruct: Only axes along x are allowed !";
00076     throw DDException(s);
00077   }
00078   
00079   return DDTranslation();
00080 }
00081 
00082 DDRotation
00083 DDDividedTrdX::makeDDRotation( const int copyNo ) const
00084 {
00085   return DDRotation();
00086 }
00087 
00088 DDLogicalPart
00089 DDDividedTrdX::makeDDLogicalPart( const int copyNo ) const
00090 {
00091   DDTrap mtrd = (DDTrap)(div_.parent().solid());
00092   DDMaterial usemat = div_.parent().material();
00093 
00094   double pDy1 = mtrd.y1(); //GetYHalfLength1();
00095   double pDy2 = mtrd.y2(); //->GetYHalfLength2();
00096   double pDz = mtrd.halfZ(); //->GetZHalfLength();
00097   double pDx = compWidth_/2.;
00098  
00099   //trd.SetAllParameters ( pDx, pDx, pDy1, pDy2, pDz );
00100 
00101   DDName solname(div_.parent().ddname().name() + "_DIVCHILD" 
00102                  , div_.parent().ddname().ns());
00103   DDSolid dsol(solname);
00104   DDLogicalPart ddlp(solname);
00105   if (!dsol.isDefined().second)
00106   {
00107     dsol = DDSolidFactory::trap(solname
00108                                 , pDz
00109                                 , 0.*deg
00110                                 , 0.*deg
00111                                 , pDy1
00112                                 , pDx
00113                                 , pDx
00114                                 , 0.*deg
00115                                 , pDy2
00116                                 , pDx
00117                                 , pDx
00118                                 , 0.*deg);
00119     ddlp = DDLogicalPart(solname, usemat, dsol);
00120   }
00121   DCOUT_V ('P', "DDDividedTrdX::makeDDLogicalPart lp = " << ddlp);
00122   return ddlp;
00123 }
00124 
00125 void
00126 DDDividedTrdX::checkParametersValidity( void )
00127 {
00128   DDDividedGeometryObject::checkParametersValidity();
00129   
00130   DDTrap mtrd = (DDTrap)(div_.parent().solid());
00131 
00132   double mpDx1 = mtrd.x1(); //->GetXHalfLength1();
00133   double mpDx2 = mtrd.x2(); //->GetXHalfLength2();
00134   double mpDx3 = mtrd.x3(); 
00135   double mpDx4 = mtrd.x4();
00136   double mpTheta = mtrd.theta();
00137   double mpPhi = mtrd.phi();
00138   double mpAlpha1 = mtrd.alpha1();  
00139   double mpAlpha2 = mtrd.alpha2();
00140   //    double mpDy1 = mtrd.y1();
00141   //    double mpDy2 = mtrd.y2();
00142   //   double x1Tol = mpDx1 - mpDx2;
00143   //   if (x1Tol < 0.0) x1Tol = x1Tol * -1.0;
00144 
00145   if ( fabs(mpDx1 - mpDx2) > tolerance()  || fabs(mpDx3 - mpDx4) > tolerance()
00146        || fabs(mpDx1 - mpDx4) > tolerance())
00147   {
00148     std::string s = "ERROR - DDDividedTrdX::checkParametersValidity()";
00149     s+= "\n        Making a division of a TRD along axis X,";
00150     s+= "\n        while the X half lengths are not equal,";
00151     s+= "\n        is not (yet) supported. It will result";
00152     s+= "\n        in non-equal division solids.";
00153     throw DDException(s);
00154   }
00155   //    if (fabs(mpDy1 - mpDy2) > tolerance())
00156   //      {
00157   //        std::string s = "ERROR - DDDividedTrdX::checkParametersValidity()";
00158   //        s+= "\n        Making a division of a TRD along axis X,";
00159   //        s+= "\n        while the Y half lengths are not equal,";
00160   //        s+= "\n        is not (yet) supported. It will result";
00161   //        s+= "\n        in non-equal division solids.";
00162   //        throw DDException(s);
00163   //      }
00164   // mec:  we only have traps, not trds in DDD, so I added this check
00165   // to make sure it is only a trd (I think! :-))
00166   if (mpAlpha1 != 0.*deg || mpAlpha2 != 0.*deg || mpTheta != 0.*deg || mpPhi != 0.*deg)
00167   {
00168     std::string s = "ERROR - DDDividedTrdX::checkParametersValidity()";
00169     s+= "\n        Making a division of a TRD along axis X,";
00170     s+= "\n        while the theta, phi and aplhpa2 are not zero,";
00171     s+= "\n        is not (yet) supported. It will result";
00172     s+= "\n        in non-equal division solids.";
00173     throw DDException(s);
00174   }
00175 }
00176 
00177 DDDividedTrdY::DDDividedTrdY( const DDDivision& div, DDCompactView* cpv )
00178   : DDDividedGeometryObject( div, cpv )
00179 {
00180   checkParametersValidity();
00181   setType( "DivisionTrdY" );
00182   DDTrap mtrd = (DDTrap)(div_.parent().solid());
00183 
00184   if( divisionType_ == DivWIDTH )
00185   {
00186     compNDiv_ = calculateNDiv( 2 * mtrd.y1(), div_.width(), div_.offset() );
00187   }
00188   else if( divisionType_ == DivNDIV )
00189   {
00190     compWidth_ = calculateWidth( 2 * mtrd.y1(), div_.nReplicas(), div_.offset() );
00191   }
00192 
00193   DCOUT_V ('P', " DDDividedTrdY no divisions " << compNDiv_ << " = " << div_.nReplicas() << "\n Offset " << div_.offset() << "\n width " << compWidth_ << " = " << div_.width() << std::endl);  
00194 }
00195 
00196 DDDividedTrdY::~DDDividedTrdY( void )
00197 {}
00198 
00199 double
00200 DDDividedTrdY::getMaxParameter( void ) const
00201 {
00202   DDTrap mtrd = (DDTrap)(div_.parent().solid());
00203   return 2 * mtrd.y1(); 
00204 }
00205 
00206 DDTranslation
00207 DDDividedTrdY::makeDDTranslation( const int copyNo ) const
00208 {
00209   DDTrap mtrd = (DDTrap)(div_.parent().solid() );
00210   double mdy = mtrd.y1();
00211 
00212   //----- translation 
00213   double posi = -mdy + div_.offset() + (copyNo+0.5)*compWidth_;
00214 
00215   DCOUT_V ('P', " DDDividedTrdY: " << copyNo << "\n Position: y=" << posi << "  Axis= " << DDAxesNames::name(div_.axis()) << "\n");
00216 
00217   if( div_.axis() == y )
00218   {
00219     return DDTranslation(0.0, posi, 0.0);
00220   }
00221   else
00222   { 
00223     std::string s = "ERROR - DDDividedTrdY::makeDDTranslation()";
00224     s += "\n        Axis is along ";
00225     s += DDAxesNames::name(div_.axis());
00226     s += " !\n" ;
00227     s += "DDDividedTrdY::makeDDTranslation()";
00228     s += " IllegalConstruct: Only axes along y are allowed !";
00229     throw DDException(s);
00230   }
00231   return DDTranslation();
00232 }
00233 
00234 DDRotation
00235 DDDividedTrdY::makeDDRotation( const int copyNo ) const
00236 {
00237   return DDRotation();
00238 }
00239 
00240 DDLogicalPart
00241 DDDividedTrdY::makeDDLogicalPart( const int copyNo ) const
00242 {
00243   //---- The division along Y of a Trd will result a Trd, only 
00244   //--- if Y at -Z and +Z are equal, else use the G4Trap version
00245   DDTrap mtrd = (DDTrap)(div_.parent().solid());
00246   DDMaterial usemat = div_.parent().material();
00247   
00248   double pDx1 = mtrd.x1(); //->GetXHalfLength1() at Y+;
00249   double pDx2 = mtrd.x2(); //->GetXHalfLength2() at Y+;
00250   double pDx3 = mtrd.x3(); //->GetXHalfLength1() at Y-;
00251   double pDx4 = mtrd.x4(); //->GetXHalfLength2() at Y-;
00252   double pDz = mtrd.halfZ(); //->GetZHalfLength();
00253   double pDy = compWidth_/2.;
00254  
00255   //trd.SetAllParameters ( pDx1, pDx2, pDy, pDy, pDz );
00256   DDName solname(div_.name() );
00257   DDSolid  dsol(solname);
00258   DDLogicalPart ddlp(solname);
00259   if (!dsol.isDefined().second)
00260   {
00261     dsol = DDSolidFactory::trap(solname
00262                                 , pDz
00263                                 , 0.*deg
00264                                 , 0.*deg
00265                                 , pDy
00266                                 , pDx1
00267                                 , pDx2
00268                                 , 0*deg
00269                                 , pDy
00270                                 , pDx3
00271                                 , pDx4
00272                                 , 0.*deg);
00273     DDLogicalPart ddlp(solname,  usemat, dsol);
00274   }
00275   DCOUT_V ('P', "DDDividedTrdY::makeDDLogicalPart lp = " << ddlp);
00276   return ddlp;
00277 }
00278 
00279 void
00280 DDDividedTrdY::checkParametersValidity( void )
00281 {
00282   DDDividedGeometryObject::checkParametersValidity();
00283 
00284   DDTrap mtrd = (DDTrap)(div_.parent().solid());
00285 
00286   double mpDy1 = mtrd.y1(); //->GetYHalfLength1();
00287   double mpDy2 = mtrd.y2(); //->GetYHalfLength2();
00288   double mpTheta = mtrd.theta();
00289   double mpPhi = mtrd.phi();
00290   double mpAlpha1 = mtrd.alpha1();
00291   double mpAlpha2 = mtrd.alpha2();
00292 
00293   if( fabs(mpDy1 - mpDy2) > tolerance() )
00294   {
00295     std::string s= "ERROR - DDDividedTrdY::checkParametersValidity()";
00296     s += "\n        Making a division of a TRD along axis Y while";
00297     s += "\n        the Y half lengths are not equal is not (yet)";
00298     s += "\n        supported. It will result in non-equal";
00299     s += "\n        division solids.";
00300     throw DDException(s);
00301   }
00302   // mec:  we only have traps, not trds in DDD, so I added this check
00303   // to make sure it is only a trd (I think! :-))
00304   if (mpAlpha1 != 0.*deg || mpAlpha2 != 0.*deg || mpTheta != 0.*deg || mpPhi != 0.*deg)
00305   {
00306     std::string s = "ERROR - DDDividedTrdY::checkParametersValidity()";
00307     s+= "\n        Making a division of a TRD along axis X,";
00308     s+= "\n        while the theta, phi and aplhpa2 are not zero,";
00309     s+= "\n        is not (yet) supported. It will result";
00310     s+= "\n        in non-equal division solids.";
00311     throw DDException(s);
00312   }
00313 }
00314 
00315 DDDividedTrdZ::DDDividedTrdZ( const DDDivision& div, DDCompactView* cpv )
00316   : DDDividedGeometryObject( div, cpv )
00317 { 
00318   checkParametersValidity();
00319   setType( "DivTrdZ" );
00320   DDTrap mtrd = (DDTrap)(div_.parent().solid());
00321 
00322   if ( divisionType_ == DivWIDTH )
00323   {
00324     compNDiv_ = calculateNDiv( 2*mtrd.halfZ(), div_.width(), div_.offset() );
00325   }
00326   else if( divisionType_ == DivNDIV )
00327   {
00328     compWidth_ = calculateWidth( 2*mtrd.halfZ(), div_.nReplicas(), div_.offset() );
00329   }
00330   DCOUT_V ('P', " DDDividedTrdY no divisions " << compNDiv_ << " = " << div_.nReplicas() << "\n Offset " << div_.offset() << "\n width " << compWidth_ << " = " << div_.width() << std::endl);
00331 }
00332 
00333 DDDividedTrdZ::~DDDividedTrdZ( void )
00334 {}
00335 
00336 double
00337 DDDividedTrdZ::getMaxParameter( void ) const
00338 {
00339   DDTrap mtrd = (DDTrap)(div_.parent().solid());
00340   return 2 * mtrd.halfZ();
00341 }
00342 
00343 DDTranslation
00344 DDDividedTrdZ::makeDDTranslation( const int copyNo ) const
00345 {
00346   DDTrap mtrd = (DDTrap)(div_.parent().solid() );
00347   double mdz = mtrd.halfZ();
00348 
00349   //----- translation 
00350   double posi = -mdz + div_.offset() + (copyNo+0.5)*compWidth_;
00351 
00352   DCOUT_V ('P', " DDDividedTrdZ: " << copyNo << "\n Position: z=" << posi << "  Axis= " << DDAxesNames::name(div_.axis()) << "\n");
00353 
00354   if( div_.axis() == z )
00355   {
00356     return DDTranslation(0.0, 0.0, posi);
00357   }
00358   else
00359   { 
00360     std::string s = "ERROR - DDDividedTrdZ::makeDDTranslation()";
00361     s += "\n        Axis is along ";
00362     s += DDAxesNames::name(div_.axis());
00363     s += " !\n" ;
00364     s += "DDDividedTrdY::makeDDTranslation()";
00365     s += " IllegalConstruct: Only axes along z are allowed !";
00366     throw DDException(s);
00367 
00368   }
00369   return DDTranslation();
00370 }
00371 
00372 DDRotation
00373 DDDividedTrdZ::makeDDRotation( const int copyNo ) const
00374 {
00375   return DDRotation();
00376 }
00377 
00378 DDLogicalPart
00379 DDDividedTrdZ::makeDDLogicalPart ( const int copyNo ) const
00380 {
00381   //---- The division along Z of a Trd will result a Trd
00382   DDTrap mtrd = (DDTrap)(div_.parent().solid());
00383   DDMaterial usemat = div_.parent().material();
00384 
00385   double pDx1 = mtrd.x1(); //->GetXHalfLength1();
00386   //(mtrd->GetXHalfLength2() - mtrd->GetXHalfLength1() );
00387   double DDx = (mtrd.x2() - mtrd.x1() );
00388   double pDy1 = mtrd.y1(); // ->GetYHalfLength1();
00389   //(mtrd->GetYHalfLength2() - mtrd->GetYHalfLength1() );
00390   double DDy = (mtrd.y2() - mtrd.y1() );
00391   double pDz = compWidth_/2.;
00392   double zLength = 2*mtrd.halfZ(); //->GetZHalfLength();
00393  
00394   //    trd.SetAllParameters ( pDx1+DDx*(div_.offset()+copyNo*compWidth_)/zLength,
00395   //                           pDx1+DDx*(div_.offset()+(copyNo+1)*compWidth_)/zLength, 
00396   //                           pDy1+DDy*(div_.offset()+copyNo*compWidth_)/zLength,
00397   //                           pDy1+DDy*(div_.offset()+(copyNo+1)*compWidth_)/zLength, pDz );
00398 
00399   DDName solname(div_.parent().ddname().name() + "_DIVCHILD" 
00400                  + DDXMLElement::itostr(copyNo)
00401                  , div_.parent().ddname().ns());
00402   DDSolid  dsol = 
00403     DDSolidFactory::trap(solname
00404                          , pDz
00405                          , 0.*deg
00406                          , 0.*deg
00407                          , pDy1+DDy*(div_.offset()+copyNo*compWidth_)/zLength
00408                          , pDx1+DDx*(div_.offset()+copyNo*compWidth_)/zLength
00409                          , pDx1+DDx*(div_.offset()+copyNo*compWidth_)/zLength
00410                          , 0.*deg
00411                          , pDy1+DDy*(div_.offset()+(copyNo+1)*compWidth_)/zLength
00412                          , pDx1+DDx*(div_.offset()+(copyNo+1)*compWidth_)/zLength
00413                          , pDx1+DDx*(div_.offset()+(copyNo+1)*compWidth_)/zLength
00414                          , 0*deg
00415       );
00416 
00417   DDLogicalPart ddlp(solname, usemat, dsol);
00418   DCOUT_V ('P', "DDDividedTrdZ::makeDDLogicalPart lp = " << ddlp);
00419   return ddlp;
00420 }
00421 
00422 void
00423 DDDividedTrdZ::checkParametersValidity( void )
00424 {
00425   DDDividedGeometryObject::checkParametersValidity();
00426 
00427   DDTrap mtrd = (DDTrap)(div_.parent().solid());
00428 
00429   double mpTheta = mtrd.theta();
00430   double mpPhi = mtrd.phi();
00431   double mpAlpha1 = mtrd.alpha1();
00432   double mpAlpha2 = mtrd.alpha2();
00433 
00434   // mec:  we only have traps, not trds in DDD, so I added this check
00435   // to make sure it is only a trd (I think! :-))
00436   if (mpAlpha1 != 0.*deg || mpAlpha2 != 0.*deg || mpTheta != 0.*deg || mpPhi != 0.*deg)
00437   {
00438     std::string s = "ERROR - DDDividedTrdZ::checkParametersValidity()";
00439     s+= "\n        Making a division of a TRD along axis X,";
00440     s+= "\n        while the theta, phi and aplhpa2 are not zero,";
00441     s+= "\n        is not (yet) supported. It will result";
00442     s+= "\n        in non-equal division solids.";
00443     throw DDException(s);
00444   }
00445 }