CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/DetectorDescription/Parser/src/DDDividedTubs.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // 25.04.04 - M. Case ddd-ize G4ParameterisationTubs*
00004 // ********************************************************************
00005 
00006 #include "DetectorDescription/Parser/src/DDDividedTubs.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 DDDividedTubsRho::DDDividedTubsRho( const DDDivision& div, DDCompactView* cpv )
00021   :  DDDividedGeometryObject::DDDividedGeometryObject( div, cpv )
00022 {
00023   checkParametersValidity();
00024   setType( "DivisionTubsRho" );
00025   DDTubs msol = (DDTubs)(div_.parent().solid());
00026 
00027   if( divisionType_ == DivWIDTH )
00028   {
00029     compNDiv_ = calculateNDiv( msol.rIn() - msol.rOut(),
00030                                div_.width(), div_.offset() );
00031   }
00032   else if( divisionType_ == DivNDIV )
00033   {
00034     compWidth_ = calculateWidth( msol.rIn() - msol.rOut(),
00035                                  div_.nReplicas(), div_.offset() );
00036   }
00037 
00038   DCOUT_V ('P', " DDDividedTubsRho - no divisions " << compNDiv_ << " = " << div_.nReplicas() << "\n Offset " << div_.offset() << "\n Width " << compWidth_ << " = " << div_.width() << "\n DivType " << divisionType_);
00039  
00040 }
00041 
00042 DDDividedTubsRho::~DDDividedTubsRho( void )
00043 {}
00044 
00045 double
00046 DDDividedTubsRho::getMaxParameter( void ) const
00047 {
00048   DDTubs msol = (DDTubs)(div_.parent().solid());
00049   return msol.rOut() - msol.rIn();
00050 
00051 }
00052 
00053 DDRotation
00054 DDDividedTubsRho::makeDDRotation( const int copyNo ) const
00055 {
00056   DDRotation myddrot; // sets to identity.
00057   DCOUT_V ('P', "DDDividedTubsRho::makeDDRotation made a rotation: " << myddrot);
00058   return myddrot;
00059 }
00060 
00061 
00062 DDTranslation
00063 DDDividedTubsRho::makeDDTranslation( const int copyNo ) const
00064 {
00065   //----- translation 
00066   DDTranslation translation;
00067 
00068   DCOUT_V ('P', " DDDividedTubsRho " << "\n\t Position: " << translation << " - Width: " << compWidth_ << " - Axis " << DDAxesNames::name(div_.axis()));
00069   return translation;
00070 }
00071 
00072 DDLogicalPart
00073 DDDividedTubsRho::makeDDLogicalPart( const int copyNo ) const
00074 {
00075   // must always make new name and new solid
00076   DDName solname(div_.parent().ddname().name() + "_DIVCHILD"
00077                  + DDXMLElement::itostr(copyNo) 
00078                  , div_.parent().ddname().ns());
00079   DDSolid ddtubs(solname);
00080   DDMaterial usemat(div_.parent().material());
00081   DDTubs msol = (DDTubs) (div_.parent().solid());
00082   DDLogicalPart ddlp;
00083       
00084   double pRMin = msol.rIn() + div_.offset() + compWidth_ * copyNo;
00085   double pRMax = msol.rIn() + div_.offset() + compWidth_ * (copyNo+1);
00086   double pDz = msol.zhalf();
00087   double pSPhi = msol.startPhi();
00088   double pDPhi = msol.deltaPhi();
00089   ddtubs = DDSolidFactory::tubs(DDName(solname), pDz, pRMin, pRMax, pSPhi, pDPhi);      
00090   ddlp = DDLogicalPart(solname, usemat, ddtubs);
00091 
00092   DCOUT_V ('P', " DDDividedTubsRho::computeDimensions() lp:" << ddlp);
00093   return ddlp;
00094 }
00095 
00096 DDDividedTubsPhi::DDDividedTubsPhi( const DDDivision& div, DDCompactView* cpv )
00097   : DDDividedGeometryObject::DDDividedGeometryObject( div, cpv )
00098 {
00099   checkParametersValidity();
00100   setType( "DivisionTubsPhi" );
00101 
00102   DDTubs msol = (DDTubs)(div_.parent().solid());
00103   if( divisionType_ == DivWIDTH )
00104   {
00105     //If you divide a tube of 360 degrees the offset displaces the starting angle, but you still fill the 360 degrees
00106     if( msol.deltaPhi() == 360.*deg ) {
00107       compNDiv_ = calculateNDiv( msol.deltaPhi(), div_.width(), 0. );
00108     }else {
00109       compNDiv_ = calculateNDiv( msol.deltaPhi(), div_.width(), div_.offset() );
00110     }
00111 
00112   }
00113   else if( divisionType_ == DivNDIV )
00114   {
00115     if( msol.deltaPhi() == 360.*deg ) {
00116       compWidth_ = calculateWidth( msol.deltaPhi(), div_.nReplicas(), 0. );
00117     }else {
00118       compWidth_ = calculateWidth( msol.deltaPhi(), div_.nReplicas(), div_.offset() );
00119     }
00120   }
00121 }
00122 
00123 DDDividedTubsPhi::~DDDividedTubsPhi( void )
00124 {}
00125 
00126 double
00127 DDDividedTubsPhi::getMaxParameter( void ) const
00128 {
00129   DDTubs msol = (DDTubs)(div_.parent().solid());
00130   return msol.deltaPhi();
00131 }
00132 
00133 DDRotation
00134 DDDividedTubsPhi::makeDDRotation( const int copyNo ) const
00135 {
00136   DDRotation myddrot; // sets to identity.
00137   double posi = ( copyNo - 1 ) * compWidth_; // This should put the first one at the 0 of the parent.
00138   DDRotationMatrix * rotMat = changeRotMatrix( posi );
00139   // how to name the rotation??
00140   // i hate this crap :-)
00141   DDName ddrotname(div_.parent().ddname().name() + "_DIVCHILD_ROT"
00142                    + DDXMLElement::itostr(copyNo)
00143                    , div_.parent().ddname().ns());
00144   myddrot = DDrot(ddrotname, rotMat);
00145 
00146   return myddrot;
00147 }
00148 
00149 DDTranslation
00150 DDDividedTubsPhi::makeDDTranslation( const int copyNo ) const
00151 {
00152   //----- translation 
00153   DDTranslation translation;
00154 
00155   DCOUT_V ('P', " DDDividedTubsPhi " << "\n\t Position: " << translation << " - Width: " << compWidth_ << " - Axis " << DDAxesNames::name(div_.axis()));
00156   return translation;
00157 }
00158 
00159 DDLogicalPart
00160 DDDividedTubsPhi::makeDDLogicalPart( const int copyNo ) const
00161 {
00162   DDName solname(div_.name());
00163   //-  DDName solname(div_.parent().ddname().name() + "_DIVCHILD", div_.parent().ddname().ns());
00164   DDSolid ddtubs(solname);
00165   DDMaterial usemat(div_.parent().material());
00166   DDTubs msol = (DDTubs) (div_.parent().solid());
00167   DDLogicalPart ddlp(solname);
00168 
00169   if (!ddtubs.isDefined().second)  // only if it is not defined, make new dimensions and solid.
00170   {
00171     double pRMin = msol.rIn();
00172     double pRMax = msol.rOut();
00173     double pDz = msol.zhalf();
00174     double pSPhi = msol.startPhi()+div_.offset(); 
00175     double pDPhi = compWidth_;  
00176     ddtubs = DDSolidFactory::tubs(DDName(solname), pDz, pRMin, pRMax, pSPhi, pDPhi);
00177     ddlp = DDLogicalPart(solname, usemat, ddtubs);
00178   }
00179 
00180   DCOUT_V ('P', " DDDividedTubsPhi::computeDimensions() lp:" << ddlp);
00181   return ddlp;
00182 }
00183 
00184 DDDividedTubsZ::DDDividedTubsZ( const DDDivision& div, DDCompactView* cpv )
00185   : DDDividedGeometryObject::DDDividedGeometryObject( div, cpv )
00186 {
00187   checkParametersValidity();
00188 
00189   DDTubs msol = (DDTubs)(div_.parent().solid());
00190 
00191   setType( "DivisionTubsZ" );
00192   if( divisionType_ == DivWIDTH )
00193   {
00194     compNDiv_ = calculateNDiv( 2*msol.zhalf(), div_.width(), div_.offset() );
00195   }
00196   else if( divisionType_ == DivNDIV )
00197   {
00198     compWidth_ = calculateWidth( 2*msol.zhalf(), div_.nReplicas(), div_.offset() );
00199   }
00200 
00201   DCOUT_V ('P', " DDDividedTubsZ - no divisions " << compNDiv_ << " = " << div_.nReplicas() << "\n Offset " << div_.offset() << "\n Width " << compWidth_ << " = " << div_.width() << "\n DivType " << divisionType_);
00202  
00203 }
00204 
00205 DDDividedTubsZ::~DDDividedTubsZ( void )
00206 {}
00207 
00208 double
00209 DDDividedTubsZ::getMaxParameter( void ) const
00210 {
00211   DDTubs msol = (DDTubs)(div_.parent().solid());
00212   return 2*msol.zhalf();
00213 
00214 }
00215 
00216 DDRotation
00217 DDDividedTubsZ::makeDDRotation( const int copyNo ) const
00218 {
00219   DDRotation myddrot; // sets to identity.
00220   DCOUT_V ('P', "DDDividedTubsZ::makeDDRotation made a rotation: " << myddrot);
00221   return myddrot;
00222 }
00223 
00224 DDTranslation
00225 DDDividedTubsZ::makeDDTranslation( const int copyNo ) const
00226 {
00227   //----- translation 
00228   DDTranslation translation;
00229 
00230   DDTubs msol = (DDTubs)(div_.parent().solid());
00231   double posi = - msol.zhalf() + div_.offset() + compWidth_/2 + copyNo*compWidth_;
00232   translation.SetZ(posi);
00233   
00234   DCOUT_V ('P', " DDDividedTubsZ " << "\n\t Position: " << translation << " - Width: " << compWidth_ << " - Axis " << DDAxesNames::name(div_.axis()));
00235   return translation;
00236 }
00237 
00238 DDLogicalPart
00239 DDDividedTubsZ::makeDDLogicalPart( const int copyNo ) const
00240 {
00241   DDMaterial usemat(div_.parent().material());
00242   DDTubs msol = (DDTubs) (div_.parent().solid());
00243   DDLogicalPart ddlp;
00244 
00245   DDName solname(div_.parent().ddname().name() + "_DIVCHILD", div_.parent().ddname().ns());
00246   DDSolid ddtubs(solname);
00247 
00248   if (!ddtubs.isDefined().second)  // only if it is not defined, make new dimensions and solid.
00249   {
00250     double pRMin = msol.rIn();
00251     double pRMax = msol.rOut();
00252     double pDz = compWidth_/2.;
00253     double pSPhi = msol.startPhi();
00254     double pDPhi = msol.deltaPhi();
00255     ddtubs = DDSolidFactory::tubs(DDName(solname), pDz, pRMin, pRMax, pSPhi, pDPhi);
00256     ddlp = DDLogicalPart(solname, usemat, ddtubs);
00257   }
00258   else {
00259     ddlp = DDLogicalPart(solname);
00260   }
00261 
00262   DCOUT_V ('P', " DDDividedTubsZ::computeDimensions() lp:" << ddlp);
00263   return ddlp;
00264 }