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