CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_6/src/DetectorDescription/Parser/src/DDDividedPolyhedra.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // 25.04.04 - M. Case ddd-ize G4ParameterisationPolyhedra*
00004 //---------------------------------------------------------------------
00005 #include "DetectorDescription/Parser/src/DDDividedPolyhedra.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 DDDividedPolyhedraRho::DDDividedPolyhedraRho( const DDDivision& div, DDCompactView* cpv )
00019   : DDDividedGeometryObject( div, cpv )
00020 {
00021   checkParametersValidity();
00022   setType( "DivisionPolyhedraRho" );
00023 
00024   DDPolyhedra msol = (DDPolyhedra)( div_.parent().solid() );
00025 
00026   if( divisionType_ == DivWIDTH )
00027   {
00028     compNDiv_ = calculateNDiv( msol.rMaxVec()[0] - msol.rMinVec()[0]
00029                                , div_.width()
00030                                , div_.offset() );
00031   }
00032   else if( divisionType_ == DivNDIV )
00033   {
00034     compWidth_ = calculateWidth( msol.rMaxVec()[0] - msol.rMinVec()[0]
00035                                  , div_.nReplicas()
00036                                  , div_.offset() );
00037   }
00038 
00039   //     for (int i = 0; i < compNDiv_; ++i)
00040   //      {
00041   //        DDpos(  makeDDLogicalPart(i)
00042   //          , div_.parent()
00043   //          , i
00044   //          , makeDDTranslation(i)
00045   //          , makeDDRotation(i)
00046   //          , &div_
00047   //          );
00048   //      } 
00049  
00050   DCOUT_V ('P', " DDDividedPolyhedraRho - # divisions " << compNDiv_  << " = " << div_.nReplicas() << "\n Offset " << div_.offset() << " Width " << compWidth_ << " = " << div_.width() << "\n");
00051 
00052 }
00053 
00054 DDDividedPolyhedraRho::~DDDividedPolyhedraRho( void )
00055 {}
00056 
00057 void
00058 DDDividedPolyhedraRho::checkParametersValidity( void )
00059 {
00060   DDDividedGeometryObject::checkParametersValidity();
00061 
00062   DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
00063 
00064   if( divisionType_ == DivNDIVandWIDTH || divisionType_ == DivWIDTH )
00065   {
00066     std::cout << "WARNING - "
00067               << "DDDividedPolyhedraRho::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               << "          WIDTH will not be used !" << std::endl;
00073   }
00074   if( div_.offset() != 0. )
00075   {
00076     std::cout << "WARNING - "
00077               << "DDDividedPolyhedraRho::checkParametersValidity()"
00078               << std::endl
00079               << "          Solid " << msol << std::endl
00080               << "          Division along  R will be done with a width "
00081               << "different for each solid section." << std::endl
00082               << "          OFFSET will not be used !" << std::endl;
00083   }
00084 }
00085 
00086 double
00087 DDDividedPolyhedraRho::getMaxParameter( void ) const
00088 {
00089   DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
00090   return msol.rMaxVec()[0] - msol.rMinVec()[0];
00091 }
00092 
00093 DDTranslation
00094 DDDividedPolyhedraRho::makeDDTranslation( const int copyNo ) const
00095 {
00096   return DDTranslation();
00097 }
00098 
00099 DDRotation
00100 DDDividedPolyhedraRho::makeDDRotation( const int copyNo ) const
00101 {
00102   return DDRotation();
00103 }
00104 
00105 DDLogicalPart
00106 DDDividedPolyhedraRho::makeDDLogicalPart( const int copyNo ) const
00107 {
00108   DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
00109   DDMaterial usemat = div_.parent().material();
00110 
00111   std::vector<double> localrMaxVec = msol.rMaxVec();
00112   std::vector<double> localrMinVec = msol.rMinVec();
00113   std::vector<double> localzVec = msol.zVec(); 
00114   std::vector<double> newrMinVec;
00115   std::vector<double> newrMaxVec;
00116   int nZplanes = localzVec.size();
00117 
00118   double width = 0.;
00119   for(int ii = 0; ii < nZplanes; ++ii)
00120   {
00121     //     width = CalculateWidth( origparamMother->Rmax[ii]
00122     //                           - origparamMother->Rmin[ii], compNDiv_, foffset );
00123     //     origparam.Rmin[ii] = origparamMother->Rmin[ii]+foffset+width*copyNo;
00124     //     origparam.Rmax[ii] = origparamMother->Rmin[ii]+foffset+width*(copyNo+1);
00125     width = calculateWidth(localrMaxVec[ii] - localrMinVec[ii], compNDiv_, div_.offset());
00126     newrMinVec[ii] = localrMinVec[ii] + div_.offset() + width * copyNo;
00127     newrMaxVec[ii] = localrMaxVec[ii] + div_.offset() + width * (copyNo + 1);
00128   }
00129 
00130   //   phedra.SetOriginalParameters(&origparam); // copy values & transfer pointers
00131   //   phedra.Reset();                           // reset to new solid parameters
00132   
00133   DDName solname(div_.parent().ddname().name() + "_DIVCHILD" + DDXMLElement::itostr(copyNo) 
00134                  , div_.parent().ddname().ns());
00135   
00136   DDSolid dsol = DDSolidFactory::polyhedra(solname
00137                                            , msol.sides()
00138                                            , msol.startPhi()
00139                                            , msol.deltaPhi()
00140                                            , localzVec
00141                                            , newrMinVec
00142                                            , newrMaxVec);
00143   DDLogicalPart ddlp = DDLogicalPart(solname, usemat, dsol);
00144   DCOUT_V ('P', "DDDividedPolyhedraRho:makeDDLogicalPart lp:" <<  ddlp);
00145   return ddlp;
00146 }
00147 
00148 DDDividedPolyhedraPhi::DDDividedPolyhedraPhi( const DDDivision& div, DDCompactView* cpv )
00149   : DDDividedGeometryObject( div, cpv )
00150 { 
00151   checkParametersValidity();
00152   setType( "DivisionPolyhedraPhi" );
00153 
00154   DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
00155   //  double deltaPhi = msol->GetEndPhi() - msol->GetStartPhi();
00156   
00157   if( divisionType_ == DivWIDTH )
00158   {
00159     //If you divide a tube of 360 degrees the offset displaces the starting angle, but you still fill the 360 degrees
00160     if( msol.deltaPhi() == 360.*deg ) {
00161       compNDiv_ = calculateNDiv( msol.deltaPhi(), div_.width(), 0. );
00162     }else {
00163       compNDiv_ = calculateNDiv( msol.deltaPhi(), div_.width(), div_.offset() );
00164     }
00165   }
00166   else if( divisionType_ == DivNDIV )
00167   {
00168     if( msol.deltaPhi() == 360.*deg ) {
00169       compWidth_ = calculateWidth( msol.deltaPhi(), div_.nReplicas(), 0. );
00170     }else {
00171       // original line looks wrong!
00172       compWidth_ = calculateWidth( msol.deltaPhi(), div_.nReplicas(), div_.offset() );
00173     }
00174   }
00175  
00176   DCOUT_V ('P', " DDDividedPolyhedraRho - # divisions " << compNDiv_  << " = " << div_.nReplicas() << "\n Offset " << div_.offset() << " Width " << compWidth_ << " = " << div_.width() << "\n");
00177 }
00178 
00179 DDDividedPolyhedraPhi::~DDDividedPolyhedraPhi( void )
00180 {}
00181 
00182 double
00183 DDDividedPolyhedraPhi::getMaxParameter( void ) const
00184 {
00185   DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
00186   return msol.deltaPhi(); //msol->GetEndPhi() - msol->GetStartPhi();
00187 }
00188 
00189 void
00190 DDDividedPolyhedraPhi::checkParametersValidity( void )
00191 {
00192   DDDividedGeometryObject::checkParametersValidity();
00193   
00194   DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
00195   
00196   if( divisionType_ == DivNDIVandWIDTH || divisionType_ == DivWIDTH )
00197   {
00198     std::cout << "WARNING - "
00199               << "DDDividedPolyhedraPhi::checkParametersValidity()"
00200               << std::endl
00201               << "          Solid " << msol << std::endl
00202               << "          Division along PHI will be done splitting "
00203               << "in the defined numSide." << std::endl
00204               << "          WIDTH will not be used !" << std::endl;
00205   }
00206   if( div_.offset() != 0. )
00207   {
00208     std::cout << "WARNING - "
00209               << "DDDividedPolyhedraPhi::checkParametersValidity()"
00210               << std::endl
00211               << "          Solid " << msol << std::endl
00212               << "          Division along PHI will be done splitting "
00213               << "in the defined numSide." << std::endl
00214               << "          OFFSET will not be used !" << std::endl;
00215   }
00216   
00217   if ( msol.sides() != compNDiv_ )
00218   { 
00219     std::cout << "ERROR - "
00220               << "DDDividedPolyhedraPhi::checkParametersValidity()"
00221               << std::endl
00222               << "        Division along PHI will be done splitting in the defined"
00223               << std::endl
00224               << "        numSide, i.e, the number of division would be :"
00225               << "        " << msol.sides()
00226               << " instead of " << compNDiv_ << " !"
00227               << std::endl; 
00228     std::string s = "DDDividedPolyhedraPhi::checkParametersValidity() Not supported configuration.";
00229     throw cms::Exception("DDException") << s;
00230   }
00231 }
00232 
00233 DDTranslation
00234 DDDividedPolyhedraPhi::makeDDTranslation( const int copyNo ) const
00235 {
00236   return DDTranslation();
00237 }
00238 
00239 DDRotation
00240 DDDividedPolyhedraPhi::makeDDRotation( const int copyNo ) const
00241 {
00242 
00243   double posi = ( copyNo - 1 ) * compWidth_;
00244 
00245   DCOUT_V ('P', " DDDividedPolyhedraPhi - position: " << posi/deg << "\n copyNo: " << copyNo << " - compWidth_: " << compWidth_/deg << "\n");
00246   
00247   //  ChangeRotMatrix( physVol, -posi );
00248   DDRotationMatrix* rotMat = changeRotMatrix( posi);
00249   // how to name the rotation??
00250   // i do not like this...
00251   DDName ddrotname(div_.parent().ddname().name() + "_DIVCHILD_ROT" + DDXMLElement::itostr(copyNo)
00252                    , div_.parent().ddname().ns());
00253   DDRotation myddrot = DDrot(ddrotname, rotMat);
00254   DCOUT_V ('P', "DDDividedPolyhedra::makeDDRotation: copyNo = " << copyNo << " rotation = " << myddrot);
00255   return myddrot;
00256 
00257 }
00258 
00259 DDLogicalPart
00260 DDDividedPolyhedraPhi::makeDDLogicalPart( const int copyNo ) const
00261 {
00262   DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
00263   DDMaterial usemat = div_.parent().material();
00264 
00265   DDName solname( div_.parent().ddname().name() + "_DIVCHILD",
00266                   div_.parent().ddname().ns());
00267   DDSolid dsol(solname);
00268   if (!dsol.isDefined().second)
00269   {
00270     dsol = DDSolidFactory::polyhedra( solname,
00271                                       msol.sides(),
00272                                       msol.startPhi()+div_.offset(),
00273                                       compWidth_,
00274                                       msol.zVec(),
00275                                       msol.rMinVec(),
00276                                       msol.rMaxVec());
00277   }
00278   DDLogicalPart ddlp(solname);
00279   if (!ddlp.isDefined().second)
00280     DDLogicalPart ddlp2 = DDLogicalPart(solname, usemat, dsol);
00281   DCOUT_V ('P', "DDDividedPolyhedraPhi::makeDDLogicalPart() ddlp = " << ddlp);
00282   return ddlp;
00283 }
00284 
00285 DDDividedPolyhedraZ::DDDividedPolyhedraZ( const DDDivision& div, DDCompactView* cpv )
00286   : DDDividedGeometryObject( div, cpv )
00287 { 
00288   checkParametersValidity();
00289   setType( "DivisionPolyhedraZ" );
00290   
00291   DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
00292 
00293   std::vector<double> zvec = msol.zVec();
00294   
00295   if  ( divisionType_ == DivWIDTH )
00296   {
00297     compNDiv_ =
00298       calculateNDiv( zvec[zvec.size() - 1] - zvec[0], div_.width(), div_.offset() );
00299   }
00300   else if( divisionType_ == DivNDIV )
00301   {
00302     compWidth_ = calculateWidth( zvec[zvec.size() - 1] - zvec[0],
00303                                  div_.nReplicas(),
00304                                  div_.offset());
00305     // ?what?      CalculateNDiv( zvec[zvec.size() - 1] - zvec[0], origparamMother->Z_values[origparamMother->Num_z_planes-1]
00306     //       - origparamMother->Z_values[0] , nDiv, offset );
00307   }
00308   
00309   DCOUT_V ('P', " DDDividedPolyhedraZ - # divisions " << compNDiv_ << " = " << div_.nReplicas() << "\n Offset " << " = " << div_.offset() << "\n Width " << compWidth_ << " = " << div_.width());
00310 }
00311                                            
00312 DDDividedPolyhedraZ::~DDDividedPolyhedraZ( void )
00313 {}
00314 
00315 double
00316 DDDividedPolyhedraZ::getMaxParameter( void ) const
00317 {
00318   DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
00319 
00320   std::vector<double> zvec = msol.zVec();
00321   return (zvec[zvec.size() - 1] - zvec[0]);
00322 }
00323 
00324 void
00325 DDDividedPolyhedraZ::checkParametersValidity( void )
00326 {
00327   DDDividedGeometryObject::checkParametersValidity();
00328 
00329   DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
00330 
00331   if( divisionType_ == DivNDIVandWIDTH || divisionType_ == DivWIDTH )
00332   {
00333     std::cout << "WARNING - "
00334               << "DDDividedPolyhedraZ::checkParametersValidity()"
00335               << std::endl
00336               << "          Solid " << msol << std::endl
00337               << "          Division along Z will be done splitting "
00338               << "in the defined z_planes." << std::endl
00339               << "          WIDTH will not be used !" << std::endl;
00340   }
00341 
00342   if( div_.offset() != 0. )
00343   {
00344     std::cout << "WARNING - "
00345               << "DDDividedPolyhedraZ::checkParametersValidity()"
00346               << std::endl
00347               << "          Solid " << msol << std::endl
00348               << "          Division along Z will be done splitting "
00349               << "in the defined z_planes." << std::endl
00350               << "          OFFSET will not be used !" << std::endl;
00351   }
00352 
00353   std::vector<double> zvec = msol.zVec();
00354   
00355   if ( zvec.size() - 1 != size_t(compNDiv_) )
00356   { 
00357     std::cout << "ERROR - "
00358               << "DDDividedPolyhedraZ::checkParametersValidity()"
00359               << std::endl
00360               << "        Division along Z can only be done by splitting in the defined"
00361               << std::endl
00362               << "        z_planes, i.e, the number of division would be :"
00363               << "        " << zvec.size() - 1
00364               << " instead of " << compNDiv_ << " !"
00365               << std::endl; 
00366     std::string s = "DDDividedPolyhedraZ::checkParametersValidity()";
00367     s += "Illegal Construct. Not a supported configuration.";
00368     throw cms::Exception("DDException") << s;
00369   }
00370 }
00371 
00372 DDTranslation
00373 DDDividedPolyhedraZ::makeDDTranslation( const int copyNo ) const
00374 {
00375   DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
00376   std::vector<double> zvec = msol.zVec();
00377   
00378   //----- set translation: along Z axis
00379   double posi = (zvec[copyNo] + zvec[copyNo+1])/2;
00380   
00381   DDTranslation tr(0,0,posi);
00382   //----- calculate rotation matrix: unit
00383   
00384   DCOUT_V ('P', " DDDividedPolyhedraZ - position: " << posi << "\n copyNo: " << copyNo << " - offset: " << div_.offset()/deg << " - compWidth_: " << compWidth_/deg << " translation = " << tr);
00385   return tr;
00386 }
00387 
00388 DDRotation
00389 DDDividedPolyhedraZ::makeDDRotation( const int copyNo ) const
00390 {
00391   return DDRotation();
00392 }
00393 
00394 DDLogicalPart
00395 DDDividedPolyhedraZ::makeDDLogicalPart( const int copyNo ) const
00396 {
00397   // only for mother number of planes = 2!!
00398   // mec: what?  why?  comment above and = 2 below straight from G4 impl.
00399   DDPolyhedra msol = (DDPolyhedra)( div_.parent().solid());
00400   DDMaterial usemat = div_.parent().material();
00401 
00402   std::vector<double> zvec = msol.zVec();
00403   std::vector<double> rminvec = msol.rMinVec();
00404   std::vector<double> rmaxvec = msol.rMaxVec();
00405 
00406   double posi = ( zvec[ copyNo ] + zvec[ copyNo + 1 ] ) / 2.0;
00407   
00408   DDName solname( div_.parent().ddname().name() + "_DIVCHILD" + DDXMLElement::itostr( copyNo ),
00409                   div_.parent().ddname().ns());
00410   std::vector<double> newRmin, newRmax, newZ;
00411   newZ.push_back( zvec[ copyNo ] - posi );
00412   newZ.push_back( zvec[ copyNo + 1 ] - posi );
00413   newRmin.push_back( rminvec[ copyNo ]);
00414   newRmin.push_back( rminvec[ copyNo + 1 ]);
00415   newRmax.push_back( rmaxvec[ copyNo ]);
00416   newRmax.push_back( rmaxvec[ copyNo + 1 ]);
00417 
00418   DDSolid dsol = DDSolidFactory::polyhedra( solname,
00419                                             msol.sides(),
00420                                             msol.startPhi(),
00421                                             msol.deltaPhi(),
00422                                             newZ,
00423                                             newRmin,
00424                                             newRmax );
00425   DDLogicalPart lp( solname, usemat, dsol );
00426 
00427   DCOUT_V( 'P', "DDDividedPolyhedraZ::makeDDLogicalPart" << "\n-- Parametrised phedra copy-number: " << copyNo << "\n-- DDLogicalPart " << lp );
00428   return lp;
00429 }
00430