CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/DetectorDescription/Parser/src/DDDividedCons.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // 25.04.04 - M. Case ddd-ize G4ParameterisationCons*
00004 // ********************************************************************
00005 
00006 #include "DetectorDescription/Parser/src/DDDividedCons.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/DDRotationMatrix.h"
00017 
00018 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00019 
00020 DDDividedConsRho::DDDividedConsRho( const DDDivision& div, DDCompactView* cpv )
00021   : DDDividedGeometryObject::DDDividedGeometryObject( div, cpv )
00022 {
00023   checkParametersValidity();
00024   setType( "DivisionConsRho" );
00025   DDCons msol = (DDCons)(div_.parent().solid());
00026 
00027   if( msol.rInPlusZ() == 0. )
00028   {
00029     std::cout << "WARNING - DDDividedConsRho, rOutMinusZ = 0. "
00030               << std::endl 
00031               << "          Width is calculated as that of rOutMinusZ !"
00032               << std::endl;
00033   } 
00034       
00035   if( divisionType_ == DivWIDTH )
00036   {
00037     compNDiv_ = calculateNDiv( msol.rOutMinusZ()
00038                                - msol.rInMinusZ(), div_.width(), div_.offset() );
00039   }
00040   else if( divisionType_ == DivNDIV )
00041   {
00042     DDCons msol = (DDCons)(div_.parent().solid());
00043     compWidth_ = calculateWidth( msol.rOutMinusZ() - msol.rInMinusZ()
00044                                  , div_.nReplicas()
00045                                  , div_.offset() );
00046   }
00047 
00048   DCOUT_V( 'P', " DDDividedConsRho - no divisions " << compNDiv_ << " = " << div_.nReplicas()
00049            << "\n Offset " << div_.offset()
00050            << "\n Width " << compWidth_ << " = " << div_.width()
00051            << "\n DivType " << divisionType_);  
00052 }
00053 
00054 DDDividedConsRho::~DDDividedConsRho( void )
00055 {}
00056 
00057 double
00058 DDDividedConsRho::getMaxParameter( void ) const
00059 {
00060   DDCons msol = (DDCons)(div_.parent().solid());
00061   return msol.rOutMinusZ() - msol.rInMinusZ();
00062 
00063 }
00064 
00065 DDRotation
00066 DDDividedConsRho::makeDDRotation( const int copyNo ) const
00067 {
00068   DDRotation myddrot; // sets to identity.
00069   DCOUT_V ('P', "DDDividedConsRho::makeDDRotation : " << myddrot);
00070   return myddrot;
00071 }
00072 
00073 DDTranslation
00074 DDDividedConsRho::makeDDTranslation( const int copyNo ) const
00075 {
00076   //----- translation 
00077   DDTranslation translation;
00078   DCOUT_V ('P', " DDDividedConsRho " << "\n\t Position: " << translation << " - Width: " << compWidth_ << " - Axis " << DDAxesNames::name(div_.axis()));
00079   return translation;
00080 }
00081 
00082 DDLogicalPart
00083 DDDividedConsRho::makeDDLogicalPart( const int copyNo ) const
00084 { 
00085   DDName solname(div_.parent().ddname().name() + "_DIVCHILD" 
00086                  + DDXMLElement::itostr(copyNo) 
00087                  , div_.parent().ddname().ns());
00088   DDSolid ddcons(solname);
00089   DDMaterial usemat(div_.parent().material());
00090   DDCons msol = (DDCons)(div_.parent().solid());
00091 
00092   double pRMin1 = msol.rInMinusZ() + div_.offset() + compWidth_ * copyNo;
00093   double pRMax1 = msol.rInMinusZ() + div_.offset() + compWidth_ * (copyNo+1);
00094  
00095   //width at Z Plus
00096   //- double compWidth_Plus =
00097   //   compWidth_ * ( msol.rOutPlusZ()/ msol.rInPlusZ())
00098   //-         / ( msol.rOutMinusZ() - msol.rInMinusZ());
00099   double compWidth_Plus = calculateWidth( msol.rOutPlusZ()
00100                                           - msol.rInPlusZ(), compNDiv_, div_.offset() );
00101   double pRMin2 = msol.rInPlusZ()
00102                   + div_.offset() + compWidth_Plus * copyNo;
00103   double pRMax2 = msol.rInPlusZ()
00104                   + div_.offset() + compWidth_Plus * (copyNo+1);
00105   double pDz = msol.zhalf();
00106 
00107   double pSPhi = msol.phiFrom();
00108   double pDPhi = msol.deltaPhi();
00109 
00110   ddcons = DDSolidFactory::cons(DDName(solname), pDz, pRMin1, pRMax1
00111                                 , pRMin2, pRMax2, pSPhi, pDPhi);      
00112   
00113   DDLogicalPart ddlp = DDLogicalPart(solname, usemat, ddcons);
00114   DCOUT_V( 'P', " DDDividedConsRho::makeDDLogicalPart() lp:" << ddlp );
00115   return ddlp;
00116 }
00117 
00118 //--------------------------------------------------------------------------
00119 //--------------------------------------------------------------------------
00120 DDDividedConsPhi::DDDividedConsPhi( const DDDivision& div, DDCompactView* cpv )
00121   : DDDividedGeometryObject::DDDividedGeometryObject( div, cpv )
00122 {
00123   checkParametersValidity();
00124   setType( "DivisionConsPhi" );
00125   DDCons msol = (DDCons)(div_.parent().solid());
00126 
00127   if( divisionType_ == DivWIDTH )
00128   {
00129     DDCons msol = (DDCons)(div_.parent().solid());
00130     //If you divide a tube of 360 degrees the offset displaces the starting angle, but you still fill the 360 degrees
00131     if( msol.deltaPhi() == 360.*deg )
00132     {
00133       compNDiv_ = calculateNDiv( msol.deltaPhi(), div_.width(), 0. );
00134     }
00135     else
00136     {
00137       compNDiv_ = calculateNDiv( msol.deltaPhi(), div_.width(), div_.offset() );
00138     }
00139   }
00140   else if( divisionType_ == DivNDIV )
00141   {
00142     DDCons msol = (DDCons)(div_.parent().solid());
00143     if( msol.deltaPhi() == 360.*deg )
00144     {
00145       compWidth_ = calculateWidth( msol.deltaPhi(), div_.nReplicas(), 0. );
00146     }
00147     else
00148     {
00149       compWidth_ = calculateWidth( msol.deltaPhi(), div_.nReplicas(), div_.offset() );
00150     }
00151   }
00152 
00153   DCOUT_V( 'P', " DDDividedConsPhi - no divisions " << compNDiv_ << " = " << div_.nReplicas()
00154            << "\n Offset " << div_.offset()
00155            << "\n Width " << compWidth_ << " = " << div_.width()
00156            << "\n DivType " << divisionType_); 
00157 }
00158 
00159 DDDividedConsPhi::~DDDividedConsPhi( void )
00160 {}
00161 
00162 double
00163 DDDividedConsPhi::getMaxParameter( void ) const
00164 {
00165   DDCons msol = (DDCons)(div_.parent().solid());
00166   return msol.deltaPhi();
00167 }
00168 
00169 DDRotation
00170 DDDividedConsPhi::makeDDRotation( const int copyNo ) const
00171 {
00172   DDRotation myddrot; // sets to identity.
00173   double posi = ( copyNo - 1 ) * compWidth_;
00174   DDRotationMatrix* rotMat = changeRotMatrix( posi );
00175   // how to name the rotation??
00176   // i hate this crap :-)
00177   DDName ddrotname(div_.parent().ddname().name() + "_DIVCHILD_ROT" + DDXMLElement::itostr(copyNo)
00178                    , div_.parent().ddname().ns());
00179   myddrot = DDrot(ddrotname, rotMat);
00180 
00181   DCOUT_V ('P', "DDDividedConsPhi::makeDDRotation : " << myddrot);
00182   return myddrot;
00183 }
00184 
00185 DDTranslation
00186 DDDividedConsPhi::makeDDTranslation( const int copyNo ) const
00187 {
00188   //----- translation 
00189   DDTranslation translation;  
00190   DCOUT_V( 'P', " DDDividedConsPhi " << "\n\t Position: " << translation
00191            << " - Width: " << compWidth_
00192            << " - Axis " << DDAxesNames::name(div_.axis()));
00193   return translation;
00194 }
00195 
00196 DDLogicalPart
00197 DDDividedConsPhi::makeDDLogicalPart( const int copyNo ) const
00198 { 
00199   DDName solname(div_.parent().ddname().name() + "_DIVCHILD"
00200                  , div_.parent().ddname().ns());
00201   DDSolid ddcons(solname);
00202   DDMaterial usemat(div_.parent().material());
00203   DDCons msol = (DDCons)(div_.parent().solid());
00204 
00205   if (!ddcons.isDefined().second)
00206   {
00207     double pRMin1 = msol.rInMinusZ();
00208     double pRMax1 = msol.rOutMinusZ();
00209     double pRMin2 = msol.rInPlusZ();
00210     double pRMax2 = msol.rOutPlusZ();
00211     double pDz = msol.zhalf();
00212           
00213     //- already rotated  double pSPhi = div_.offset() + copyNo*compWidth_;
00214     double pSPhi = div_.offset() + msol.phiFrom();
00215     double pDPhi = compWidth_;
00216     ddcons = DDSolidFactory::cons(DDName(solname), pDz, pRMin1, pRMax1
00217                                   , pRMin2, pRMax2, pSPhi, pDPhi);      
00218   }
00219   
00220   DDLogicalPart ddlp = DDLogicalPart(solname, usemat, ddcons);
00221   DCOUT_V ('P', " DDDividedConsPhi::makeDDLogicalPart() lp:" << ddlp);
00222   return ddlp;
00223 }
00224 
00225 DDDividedConsZ::DDDividedConsZ( const DDDivision& div, DDCompactView* cpv )
00226   :  DDDividedGeometryObject::DDDividedGeometryObject( div, cpv )
00227 {
00228   checkParametersValidity();
00229 
00230   DDCons msol = (DDCons)(div_.parent().solid());
00231   setType( "DivisionConsZ" );
00232       
00233   if( divisionType_ == DivWIDTH )
00234   {
00235     DDCons msol = (DDCons)(div_.parent().solid());
00236     compNDiv_ = calculateNDiv( 2*msol.zhalf()
00237                                , div_.width(), div_.offset() );
00238   }
00239   else if( divisionType_ == DivNDIV )
00240   {
00241     DDCons msol = (DDCons)(div_.parent().solid());
00242     compWidth_ = calculateWidth( 2*msol.zhalf()
00243                                  , div_.nReplicas(), div_.offset() );
00244   }
00245 
00246   DCOUT_V( 'P', " DDDividedConsZ - no divisions " << compNDiv_ << " = " << div_.nReplicas()
00247            << "\n Offset " << div_.offset()
00248            << "\n Width " << compWidth_ << " = " << div_.width()
00249            << "\n DivType " << divisionType_ );
00250 }
00251 
00252 DDDividedConsZ::~DDDividedConsZ( void )
00253 {}
00254 
00255 double
00256 DDDividedConsZ::getMaxParameter( void ) const
00257 {
00258   DDCons msol = (DDCons)(div_.parent().solid());
00259   return 2*msol.zhalf();
00260 }
00261 
00262 DDRotation
00263 DDDividedConsZ::makeDDRotation( const int copyNo ) const
00264 {
00265   DDRotation myddrot; // sets to identity.
00266   DCOUT_V ('P', "DDDividedConsZ::makeDDRotation : " << myddrot);
00267   return myddrot;
00268 }
00269 
00270 DDTranslation
00271 DDDividedConsZ::makeDDTranslation( const int copyNo ) const
00272 {
00273   //----- translation 
00274   DDTranslation translation;
00275 
00276   DDCons motherCons = (DDCons)(div_.parent().solid());
00277   double posi = - motherCons.zhalf() + div_.offset() 
00278                 + compWidth_/2 + copyNo*compWidth_;
00279   translation.SetZ(posi); 
00280   
00281   DCOUT_V ('P', " DDDividedConsZ " << "\n\t Position: " << translation << " - Width: " << compWidth_ << " - Axis " << DDAxesNames::name(div_.axis()));
00282   return translation;
00283 }
00284 
00285 DDLogicalPart
00286 DDDividedConsZ::makeDDLogicalPart( const int copyNo ) const
00287 { 
00288   DDName solname(div_.parent().ddname().name() + "_DIVCHILD" + DDXMLElement::itostr(copyNo) 
00289                  , div_.parent().ddname().ns());
00290   DDSolid ddcons(solname);
00291   DDMaterial usemat(div_.parent().material());
00292   DDCons msol = (DDCons)(div_.parent().solid());
00293 
00294   double mHalfLength = msol.zhalf();
00295   double aRInner = (msol.rInPlusZ()
00296                     - msol.rInMinusZ()) / (2*mHalfLength);
00297   double bRInner = (msol.rInPlusZ()
00298                     + msol.rInMinusZ()) / 2;
00299   double aROuter = (msol.rOutPlusZ()
00300                     - msol.rOutMinusZ()) / (2*mHalfLength);
00301   double bROuter = (msol.rOutPlusZ()
00302                     + msol.rOutMinusZ()) / 2;
00303   double xMinusZ = -mHalfLength + div_.offset() + compWidth_*copyNo;
00304   double xPlusZ  = -mHalfLength + div_.offset() + compWidth_*(copyNo+1);
00305 
00306   double pDz = compWidth_ / 2.;
00307   double pSPhi = msol.phiFrom();
00308   double pDPhi = msol.deltaPhi();
00309 
00310   ddcons = DDSolidFactory::cons(DDName(solname)
00311                                 , pDz
00312                                 , aRInner * xMinusZ + bRInner
00313                                 , aROuter * xMinusZ + bROuter
00314                                 , aRInner * xPlusZ + bRInner
00315                                 , aROuter * xPlusZ + bROuter
00316                                 , pSPhi
00317                                 , pDPhi
00318     );
00319   
00320   DDLogicalPart ddlp = DDLogicalPart(solname, usemat, ddcons);
00321   DCOUT_V( 'P', " DDDividedConsZ::makeDDLogicalPart() lp:" << ddlp );
00322   return ddlp;
00323 }