CMS 3D CMS Logo

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