CMS 3D CMS Logo

DDDividedGeometryObject.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // 25.04.04 - M.Case ported algorithm from G4VDivisionParameterisation.cc. to 
00004 //            DDD version
00005 // ********************************************************************
00006 
00007 #include "DDDividedGeometryObject.h"
00008 
00009 #include "DetectorDescription/Base/interface/DDRotationMatrix.h"
00010 #include "DetectorDescription/Base/interface/DDTranslation.h"
00011 #include "DetectorDescription/Base/interface/DDException.h"
00012 #include "DetectorDescription/Base/interface/DDdebug.h"
00013 
00014 #include "DetectorDescription/Core/interface/DDAxes.h"
00015 #include "DetectorDescription/Core/interface/DDDivision.h"
00016 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
00017 #include "DetectorDescription/Core/interface/DDPosPart.h"
00018 #include "DetectorDescription/Core/interface/DDSolid.h"
00019 #include "DetectorDescription/Core/interface/DDSolidShapes.h"
00020 
00021 #include <Math/RotationZ.h>
00022 
00023 
00024 //--------------------------------------------------------------------------
00025 DDDividedGeometryObject::DDDividedGeometryObject( const DDDivision & div ) 
00026   : div_(div), ftype_(), compNDiv_(div.nReplicas()), compWidth_(div.width())
00027     , divisionType_(DivNDIVandWIDTH), theVoluFirstCopyNo_(1)
00028 {
00029 
00030   if (div_.nReplicas() == 0 || div_.width() < tolerance())
00031     {
00032       if (div_.width() < tolerance())
00033         divisionType_ = DivNDIV;
00034       else 
00035         divisionType_ = DivWIDTH;
00036     } 
00037   DCOUT_V('P', " DDDividedGeometryObject Divisions " << div_ << std::endl);
00038 }
00039 
00040 //--------------------------------------------------------------------------
00041 DDDividedGeometryObject::~DDDividedGeometryObject()
00042 {
00043 }
00044 
00045 //--------------------------------------------------------------------------
00046 DDRotationMatrix* DDDividedGeometryObject::changeRotMatrix( double rotZ ) const
00047 {
00048   DDRotationMatrix * rm = new DDRotationMatrix(ROOT::Math::RotationZ(rotZ));
00049   return rm;
00050 }
00051 
00052 //--------------------------------------------------------------------------
00053 int
00054 DDDividedGeometryObject::
00055 calculateNDiv( double motherDim, double width, double offset ) const
00056 {
00057   DCOUT_V('P', " DDDividedGeometryObject::calculateNDiv: " << ( motherDim - offset ) / width << " Motherdim: " <<  motherDim << ", Offset: " << offset << ", Width: " << width << std::endl);
00058   return int( ( motherDim - offset ) / width );
00059 }
00060 
00061 //--------------------------------------------------------------------------
00062 double
00063 DDDividedGeometryObject::
00064 calculateWidth( double motherDim, int nDiv, double offset ) const
00065 { 
00066   DCOUT_V('P', " DDDividedGeometryObject::calculateWidth: " << ( motherDim - offset ) / nDiv << ", Motherdim: " << motherDim << ", Offset: " << offset << ", Number of divisions: " << nDiv << std::endl);
00067 
00068   return ( motherDim - offset ) / nDiv;
00069 }
00070 
00071 //--------------------------------------------------------------------------
00072 void DDDividedGeometryObject::checkParametersValidity()
00073 {
00074   double maxPar = getMaxParameter();
00075   checkOffset( maxPar );
00076   checkNDivAndWidth( maxPar );
00077   if (!div_.parent().isDefined().second) {
00078     std::string s = "DDDividedGeometryObject::checkParametersValidity() :";
00079     s+= "\n ERROR - the LogicalPart of the parent must be ";
00080     s+= "\n         defined before a division can occur.";
00081     s+= "\n         Parent= " + div_.parent().toString();
00082     throw DDException(s);
00083   }
00084 
00085 }
00086 
00087 //--------------------------------------------------------------------------
00088 void DDDividedGeometryObject::checkOffset( double maxPar )
00089 {
00090   if( div_.offset() >= maxPar )
00091   {
00092     DCOUT_V('P', "DDDividedGeometryObject::checkOffset() Division of LogicalPart " << div_.parent() << " offset=" << div_.offset() << " maxPar=" << maxPar << "\n");
00093     std::string s = "DDDividedGeometryObject::checkOffset() IllegalConstruct";
00094     s += "\nERROR - DDDividedGeometryObject::checkOffset()";
00095     s += "\n        failed.";
00096     s += "  Too big an offset.";
00097     throw DDException(s);
00098   }
00099 }
00100 
00101 //--------------------------------------------------------------------------
00102 void DDDividedGeometryObject::checkNDivAndWidth( double maxPar )
00103 {
00104   if( (divisionType_ == DivNDIVandWIDTH)
00105       && (div_.offset() + compWidth_*compNDiv_ - maxPar > tolerance() ) )
00106   {
00107     std::string s = "ERROR - DDDividedGeometryObject::checkNDivAndWidth()";
00108     s+= "\n        Division of LogicalPart " + div_.parent();
00109     s+= " has too big an offset.";
00110     DCOUT_V('P', "DDDividedGeometryObject::checkNDivAndWidth has computed div_.offset() + compWidth_*compNDiv_ - maxPar =" << div_.offset() + compWidth_*compNDiv_ - maxPar << " and tolerance()=" << tolerance());
00111     std::cout << compWidth_ << std::endl;
00112     throw DDException(s);
00113   }
00114 }
00115 
00116 const double DDDividedGeometryObject::tolerance()
00117 {
00118   // this can come from some global tolerance if you want.
00119   static const double tol = 1.0/1000.00;
00120   return tol;
00121 }
00122 
00123 void DDDividedGeometryObject::setType( const std::string& s) 
00124 {
00125   ftype_ = s;
00126 }
00127 
00128 const std::string& DDDividedGeometryObject::getType() const
00129 {
00130   return ftype_;
00131 }
00132 
00133 void DDDividedGeometryObject::execute()
00134 {
00135   DCOUT_V('D', "about to make " <<  compNDiv_ << " divisions." << std::endl);
00136   for (int i = theVoluFirstCopyNo_; i < compNDiv_+theVoluFirstCopyNo_; ++i)
00137     {
00138       DCOUT_V('D',  "Parent Volume: " << div_.parent() << std::endl);
00139       DCOUT_V('D',  "Child Volume: " << makeDDLogicalPart(i) << std::endl);
00140       DCOUT_V('D',  "   copyNo:" << i << std::endl);
00141       DCOUT_V('D',  "   Translation: " << makeDDTranslation(i) << std::endl);
00142       DCOUT_V('D',  "   rotation=" << makeDDRotation(i) << std::endl);
00143 
00144       DDpos( makeDDLogicalPart(i)
00145              , div_.parent()
00146              , i
00147              , makeDDTranslation(i)
00148              , makeDDRotation(i)
00149              , &div_
00150              );
00151     }
00152 }
00153 
00154 //------------------------------------------------------------------------
00155 double DDDividedGeometryObject::getMaxParameter() const
00156 {
00157   return 0.0;
00158 }
00159 
00160 //------------------------------------------------------------------------
00161 DDRotation DDDividedGeometryObject::makeDDRotation( const int copyNo ) const
00162 {
00163   return DDRotation();
00164 }
00165 
00166 //------------------------------------------------------------------------
00167 DDTranslation DDDividedGeometryObject::makeDDTranslation( const int copyNo ) const
00168 {
00169   return DDTranslation();
00170 }
00171 
00172 //------------------------------------------------------------------------
00173 DDLogicalPart DDDividedGeometryObject::makeDDLogicalPart( const int copyNo ) const
00174 {
00175   // just return the parent... this is USELESS
00176   return div_.parent();
00177 }

Generated on Tue Jun 9 17:32:23 2009 for CMSSW by  doxygen 1.5.4