CMS 3D CMS Logo

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