CMS 3D CMS Logo

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