CMS 3D CMS Logo

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

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // 25.04.04 - M. Case ddd-ize G4ParameterisationPolycone*
00004 //---------------------------------------------------------------------
00005 #include "DetectorDescription/Parser/src/DDDividedPolycone.h"
00006 #include "DetectorDescription/Parser/src/DDXMLElement.h"
00007 
00008 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
00009 #include "DetectorDescription/Core/interface/DDName.h"
00010 #include "DetectorDescription/Core/interface/DDSolid.h"
00011 #include "DetectorDescription/Core/interface/DDMaterial.h"
00012 
00013 #include "DetectorDescription/Base/interface/DDdebug.h"
00014 #include "DetectorDescription/Base/interface/DDRotationMatrix.h"
00015 
00016 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00017 
00018 DDDividedPolyconeRho::DDDividedPolyconeRho( const DDDivision& div, DDCompactView* cpv )
00019   :  DDDividedGeometryObject::DDDividedGeometryObject( div, cpv )
00020 {
00021   checkParametersValidity();
00022   DDPolycone msol = (DDPolycone)(div_.parent().solid());
00023   std::vector<double> localrMaxVec = msol.rMaxVec();
00024   std::vector<double> localrMinVec = msol.rMinVec();
00025 
00026   setType( "DivisionPolyconeRho" );
00027 
00028   // in DDD we only have ONE representation
00029   // in the case when rMinVec and rMaxVec
00030   // are empty rVec and zVec are the r and z std::vectors.
00031 
00032   if( divisionType_ == DivWIDTH )
00033   {
00034     compNDiv_ = calculateNDiv( localrMaxVec[0] - localrMinVec[0], div_.width(), div_.offset());
00035   }
00036   else if( divisionType_ == DivNDIV )
00037   {
00038     compWidth_ = calculateWidth( localrMaxVec[0] - localrMinVec[0], div_.nReplicas(), div_.offset());
00039   }
00040 
00041   DCOUT_V( 'P', " DDDividedPolyconeRho - # divisions " << compNDiv_ << " = " << div_.nReplicas() << "/n Offset " << div_.offset() << " Width " << compWidth_ << " = " << div_.width() << "\n" );
00042 }
00043 
00044 DDDividedPolyconeRho::~DDDividedPolyconeRho( void )
00045 {}
00046 
00047 void
00048 DDDividedPolyconeRho::checkParametersValidity( void )
00049 {
00050   DDDividedGeometryObject::checkParametersValidity();
00051 
00052   DDPolycone msol = (DDPolycone)(div_.parent().solid());
00053 
00054   if( divisionType_ == DivNDIVandWIDTH || divisionType_ == DivWIDTH )
00055   {
00056     std::cout << "WARNING - "
00057               << "DDDividedPolyconeRho::checkParametersValidity()"
00058               << std::endl
00059               << "          Solid " << msol << std::endl
00060               << "          Division along r will be done with a width "
00061               << "different for each solid section." << std::endl
00062               << "          WIDTH will not be used !" << std::endl;
00063   }
00064   if( div_.offset() != 0. )
00065   {
00066     std::cout << "WARNING - "
00067               << "DDDividedPolyconeRho::checkParametersValidity()"
00068               << std::endl
00069               << "          Solid " << msol << std::endl
00070               << "          Division along  R will be done with a width "
00071               << "different for each solid section." << std::endl
00072               << "          OFFSET will not be used !" << std::endl;
00073   }
00074 }
00075 
00076 double
00077 DDDividedPolyconeRho::getMaxParameter( void ) const
00078 {
00079   DDPolycone msol = (DDPolycone)(div_.parent().solid());
00080   std::vector<double> localrMaxVec = msol.rMaxVec();
00081   std::vector<double> localrMinVec = msol.rMinVec();
00082 
00083   return localrMaxVec[0] - localrMinVec[0];
00084 }
00085 
00086 DDRotation
00087 DDDividedPolyconeRho::makeDDRotation( const int copyNo ) const
00088 {
00089   DDRotation myddrot; // sets to identity.
00090   DCOUT_V ('P', "DDDividedPolyconeRho::makeDDRotation : " << myddrot);
00091   return myddrot;
00092 }
00093 
00094 DDTranslation
00095 DDDividedPolyconeRho::makeDDTranslation( const int copyNo ) const
00096 {
00097   DDTranslation translation;
00098   return translation;
00099 }
00100 
00101 DDLogicalPart
00102 DDDividedPolyconeRho::makeDDLogicalPart( const int copyNo ) const
00103 {
00104   DDName solname;
00105   DDSolid ddpolycone;
00106   DDMaterial usemat(div_.parent().material());
00107 
00108   DDPolycone msol = (DDPolycone)(div_.parent().solid());
00109   std::vector<double> localrMaxVec = msol.rMaxVec();
00110   std::vector<double> localrMinVec = msol.rMinVec();
00111   std::vector<double> localzVec = msol.zVec();
00112 
00113   int nZplanes = localzVec.size();
00114 
00115   std::vector<double> newrMinVec;
00116   std::vector<double> newrMaxVec;
00117 
00118   double width = 0.;
00119   for(int ii = 0; ii < nZplanes; ++ii)
00120   {
00121     width = calculateWidth( localrMaxVec[ii]
00122                             - localrMinVec[ii], compNDiv_, div_.offset() );
00123     // hmmm different width every time... probably should use width 
00124     // not compWidth_
00125     //    newrMinVec[ii] = localrMinVec[ii]+div_.offset()+compWidth_*copyNo;
00126     //    newrMaxVec[ii] = localrMinVec[ii]+div_.offset()+compWidth_*(copyNo+1);
00127     newrMinVec.push_back(localrMinVec[ii]+div_.offset()+width*copyNo);
00128     newrMaxVec.push_back(localrMinVec[ii]+div_.offset()+width*(copyNo+1));
00129   }
00130   solname = DDName( div_.parent().ddname().name() + "_DIVCHILD" + DDXMLElement::itostr(copyNo),
00131                     div_.parent().ddname().ns());
00132       
00133   ddpolycone = DDSolidFactory::polycone( solname,
00134                                          msol.startPhi(),
00135                                          msol.deltaPhi(),
00136                                          localzVec,
00137                                          newrMinVec,
00138                                          newrMaxVec );
00139 
00140   DDLogicalPart ddlp = DDLogicalPart( solname, usemat, ddpolycone );
00141   DCOUT_V ('P', " DDDividedPolyconeRho::makeDDLogicalPart() lp:" << ddlp);
00142   return ddlp;
00143 }
00144 
00145 DDDividedPolyconePhi::DDDividedPolyconePhi( const DDDivision& div, DDCompactView* cpv )
00146   : DDDividedGeometryObject::DDDividedGeometryObject( div, cpv )
00147 {
00148   checkParametersValidity();
00149   DDPolycone msol = (DDPolycone)(div_.parent().solid());
00150   setType( "DivisionPolyconePhi" );
00151   // this is the g4.  what do we keep??? I think it is deltaPhi
00152   // double deltaPhi = msol->GetEndPhi() - msol->GetStartPhi();
00153   if( divisionType_ == DivWIDTH )
00154   {
00155     //If you divide a tube of 360 degrees the offset displaces the starting angle, but you still fill the 360 degrees
00156     if( msol.deltaPhi() == 360.*deg ) {
00157       compNDiv_ = calculateNDiv( msol.deltaPhi(), div_.width(), 0. );
00158     }else {
00159       compNDiv_ = calculateNDiv( msol.deltaPhi(), div_.width(), div_.offset() );
00160     }
00161   }
00162   else if( divisionType_ == DivNDIV )
00163   {
00164     if( msol.deltaPhi() == 360.*deg ) {
00165       compWidth_ = calculateWidth( msol.deltaPhi(), div_.nReplicas(), 0. );
00166     }else {
00167       compWidth_ = calculateWidth( msol.deltaPhi(), div_.nReplicas(), div_.offset() );
00168     }
00169   }
00170   
00171   DCOUT_V ('P', " DDDividedPolyconePhi - # divisions " << compNDiv_ << " = " << div_.nReplicas() << "/n Offset " << div_.offset() << " Width " << compWidth_ << " = " << div_.width() << "\n");
00172 }
00173 
00174 DDDividedPolyconePhi::~DDDividedPolyconePhi( void )
00175 {}
00176 
00177 void
00178 DDDividedPolyconePhi::checkParametersValidity( void )
00179 {
00180   DDDividedGeometryObject::checkParametersValidity();
00181 }
00182 
00183 double
00184 DDDividedPolyconePhi::getMaxParameter( void ) const
00185 {
00186   DDPolycone msol = (DDPolycone)(div_.parent().solid());
00187   return msol.deltaPhi();
00188 }
00189 
00190 DDRotation
00191 DDDividedPolyconePhi::makeDDRotation( const int copyNo ) const
00192 {
00193   DDRotation myddrot; // sets to identity.
00194   double posi = ( copyNo - 1 ) * compWidth_;
00195   DDRotationMatrix* rotMat = changeRotMatrix( posi );
00196   // how to name the rotation??
00197   // i do not like this
00198   DDName ddrotname( div_.parent().ddname().name() + "_DIVCHILD_ROT" + DDXMLElement::itostr( copyNo ),
00199                     div_.parent().ddname().ns());
00200   myddrot = DDrot( ddrotname, rotMat );
00201 
00202   DCOUT_V( 'P', "DDDividedPolyconePhi::makeDDRotation : " << myddrot );
00203   return myddrot;
00204 }
00205 
00206 DDTranslation
00207 DDDividedPolyconePhi::makeDDTranslation( const int copyNo ) const
00208 {
00209   DDTranslation translation;
00210   return translation;
00211 }
00212 
00213 DDLogicalPart
00214 DDDividedPolyconePhi::makeDDLogicalPart( const int copyNo ) const
00215 {
00216   DDName solname;
00217   DDSolid ddpolycone;
00218   DDMaterial usemat(div_.parent().material());
00219 
00220   DDPolycone msol = (DDPolycone)(div_.parent().solid());
00221   std::vector<double> localrMaxVec = msol.rMaxVec();
00222   std::vector<double> localrMinVec = msol.rMinVec();
00223   std::vector<double> localzVec = msol.zVec();
00224 
00225   solname = DDName(div_.parent().ddname().name() + "_DIVCHILD",
00226                    div_.parent().ddname().ns());
00227   DDSolid sol( solname );
00228   if( !sol.isDefined().second )
00229   {
00230     ddpolycone = DDSolidFactory::polycone( solname,
00231                                            msol.startPhi()+div_.offset(),
00232                                            compWidth_,
00233                                            localzVec,
00234                                            localrMinVec,
00235                                            localrMaxVec );
00236   }
00237   DDLogicalPart ddlp( solname );
00238   if( !ddlp.isDefined().second )
00239   {
00240     ddlp = DDLogicalPart( solname, usemat, ddpolycone );
00241   }
00242   DCOUT_V( 'P', " DDDividedPolyconePhi::makeDDLogicalPart() lp:" << ddlp );
00243   return ddlp;
00244 }
00245 
00246 DDDividedPolyconeZ::DDDividedPolyconeZ( const DDDivision& div, DDCompactView* cpv )
00247   : DDDividedGeometryObject::DDDividedGeometryObject( div, cpv )
00248 {
00249   checkParametersValidity();
00250   DDPolycone msol = (DDPolycone)(div_.parent().solid());
00251   std::vector<double> localrMaxVec = msol.rMaxVec();
00252   std::vector<double> localrMinVec = msol.rMinVec();
00253   std::vector<double> localzVec = msol.zVec();
00254 
00255   if( divisionType_ == DivWIDTH )
00256   {
00257     compNDiv_ =
00258       calculateNDiv( localzVec[localzVec.size() - 1]
00259                      - localzVec[0] , div_.width(), div_.offset() );
00260   }
00261   else if( divisionType_ == DivNDIV )
00262   {
00263     compWidth_ =
00264       calculateNDiv( localzVec[localzVec.size()-1]
00265                      - localzVec[0] , div_.nReplicas(), div_.offset() );
00266   }
00267    
00268   DCOUT_V ('P', " DDDividedPolyconeZ - # divisions " << compNDiv_ << " = " << div_.nReplicas() << "/n Offset " << div_.offset() << " Width " << compWidth_ << " = " << div_.width() << "\n");
00269 }
00270 
00271 DDDividedPolyconeZ::~DDDividedPolyconeZ( void )
00272 {}
00273 
00274 void
00275 DDDividedPolyconeZ::checkParametersValidity( void )
00276 {
00277   DDDividedGeometryObject::checkParametersValidity();
00278 
00279   DDPolycone msol = (DDPolycone)(div_.parent().solid());
00280   std::vector<double> localzVec = msol.zVec();
00281   // CHANGE FROM G4 a polycone can be divided in Z by specifying
00282   // nReplicas IF they happen to coincide with the number of 
00283   // z plans.
00284   size_t tempNDiv = div_.nReplicas();
00285   if (tempNDiv == 0)
00286     tempNDiv = calculateNDiv( localzVec[localzVec.size() - 1] - localzVec[0] 
00287                               , div_.width()
00288                               , div_.offset() );
00289   if ((msol.zVec().size() - 1) != tempNDiv)
00290   { 
00291     std::string s = "ERROR - DDDividedPolyconeZ::checkParametersValidity()";
00292     s += "\n\tDivision along Z will be done splitting in the defined";
00293     s += "\n\tz_planes, i.e, the number of division would be :";
00294     s += "\n\t" + DDXMLElement::itostr( msol.zVec().size() - 1 );
00295     s += "\n\tinstead of " + DDXMLElement::itostr(tempNDiv) + " !\n";
00296 
00297     throw cms::Exception("DDException") << s;
00298   }
00299 }
00300 
00301 double
00302 DDDividedPolyconeZ::getMaxParameter( void ) const
00303 {
00304   DDPolycone msol = (DDPolycone)(div_.parent().solid());
00305   std::vector<double> localzVec = msol.zVec();
00306 
00307   return (localzVec[ localzVec.size() - 1] - localzVec[0]);
00308 }
00309 
00310 DDRotation
00311 DDDividedPolyconeZ::makeDDRotation( const int copyNo ) const
00312 {
00313   DDRotation myddrot; // sets to identity.
00314   DCOUT_V ('P', "DDDividedPolyconeZ::makeDDRotation : " << myddrot);
00315   return myddrot;
00316 }
00317 
00318 DDTranslation
00319 DDDividedPolyconeZ::makeDDTranslation( const int copyNo ) const
00320 {
00321   DDTranslation translation;
00322   DDPolycone msol = (DDPolycone)(div_.parent().solid());
00323   std::vector<double> localzVec = msol.zVec();
00324   double posi = (localzVec[copyNo] + localzVec[copyNo+1]) / 2;
00325   translation.SetZ(posi);
00326   return translation;
00327 }
00328 
00329 DDLogicalPart
00330 DDDividedPolyconeZ::makeDDLogicalPart( const int copyNo ) const
00331 {
00332   DDName solname;
00333   DDSolid ddpolycone;
00334   DDMaterial usemat(div_.parent().material());
00335 
00336   DDPolycone msol = (DDPolycone)(div_.parent().solid());
00337   std::vector<double> localrMaxVec = msol.rMaxVec();
00338   std::vector<double> localrMinVec = msol.rMinVec();
00339   std::vector<double> localzVec = msol.zVec();
00340 
00341   solname = DDName( div_.parent().ddname().name() + "_DIVCHILD" + DDXMLElement::itostr(copyNo),
00342                     div_.parent().ddname().ns());
00343   ddpolycone = DDSolidFactory::cons( solname,
00344                                      compWidth_ / 2,
00345                                      localrMinVec[copyNo],
00346                                      localrMaxVec[copyNo],
00347                                      localrMinVec[copyNo+1],
00348                                      localrMaxVec[copyNo+1],
00349                                      msol.startPhi(),
00350                                      msol.deltaPhi());
00351 
00352   DDLogicalPart ddlp = DDLogicalPart( solname, usemat, ddpolycone );
00353 
00354   DCOUT_V( 'P', " DDDividedPolyconeZ::makeDDLogicalPart() lp:" << ddlp );
00355 
00356   return ddlp;
00357 }