00001
00002
00003
00004
00005 #include "DDDividedPolyhedra.h"
00006 #include "DDXMLElement.h"
00007
00008 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
00009 #include "DetectorDescription/Core/interface/DDName.h"
00010 #include "DetectorDescription/Core/interface/DDPosPart.h"
00011 #include "DetectorDescription/Core/interface/DDAxes.h"
00012 #include "DetectorDescription/Core/interface/DDSolid.h"
00013 #include "DetectorDescription/Core/interface/DDSolidShapes.h"
00014 #include "DetectorDescription/Core/interface/DDMaterial.h"
00015
00016 #include "DetectorDescription/Base/interface/DDdebug.h"
00017 #include "DetectorDescription/Base/interface/DDException.h"
00018 #include "DetectorDescription/Base/interface/DDRotationMatrix.h"
00019 #include "DetectorDescription/Base/interface/DDTranslation.h"
00020
00021 #include "CLHEP/Units/SystemOfUnits.h"
00022
00023
00024 DDDividedPolyhedraRho::DDDividedPolyhedraRho( const DDDivision & div )
00025 : DDDividedGeometryObject( div )
00026 {
00027 checkParametersValidity();
00028 setType( "DivisionPolyhedraRho" );
00029
00030 DDPolyhedra msol = (DDPolyhedra)( div_.parent().solid() );
00031
00032
00033 if( divisionType_ == DivWIDTH )
00034 {
00035 compNDiv_ = calculateNDiv( msol.rMaxVec()[0] - msol.rMinVec()[0]
00036 , div_.width()
00037 , div_.offset() );
00038 }
00039 else if( divisionType_ == DivNDIV )
00040 {
00041 compWidth_ = calculateWidth( msol.rMaxVec()[0] - msol.rMinVec()[0]
00042 , div_.nReplicas()
00043 , div_.offset() );
00044 }
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 DCOUT_V ('P', " DDDividedPolyhedraRho - # divisions " << compNDiv_ << " = " << div_.nReplicas() << "\n Offset " << div_.offset() << " Width " << compWidth_ << " = " << div_.width() << "\n");
00058
00059 }
00060
00061
00062 DDDividedPolyhedraRho::~DDDividedPolyhedraRho()
00063 {
00064 }
00065
00066
00067 void DDDividedPolyhedraRho::checkParametersValidity()
00068 {
00069 DDDividedGeometryObject::checkParametersValidity();
00070
00071 DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
00072
00073 if( divisionType_ == DivNDIVandWIDTH || divisionType_ == DivWIDTH )
00074 {
00075 std::cout << "WARNING - "
00076 << "DDDividedPolyhedraRho::checkParametersValidity()"
00077 << std::endl
00078 << " Solid " << msol << std::endl
00079 << " Division along R will be done with a width "
00080 << "different for each solid section." << std::endl
00081 << " WIDTH will not be used !" << std::endl;
00082 }
00083 if( div_.offset() != 0. )
00084 {
00085 std::cout << "WARNING - "
00086 << "DDDividedPolyhedraRho::checkParametersValidity()"
00087 << std::endl
00088 << " Solid " << msol << std::endl
00089 << " Division along R will be done with a width "
00090 << "different for each solid section." << std::endl
00091 << " OFFSET will not be used !" << std::endl;
00092 }
00093
00094
00095 }
00096
00097
00098 double DDDividedPolyhedraRho::getMaxParameter() const
00099 {
00100 DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
00101
00102 return msol.rMaxVec()[0] - msol.rMinVec()[0];
00103 }
00104
00105
00106 DDTranslation DDDividedPolyhedraRho::makeDDTranslation( const int copyNo ) const
00107 {
00108 return DDTranslation();
00109 }
00110
00111
00112 DDRotation DDDividedPolyhedraRho::makeDDRotation( const int copyNo ) const
00113 {
00114 return DDRotation();
00115 }
00116
00117
00118 DDLogicalPart DDDividedPolyhedraRho::makeDDLogicalPart ( const int copyNo ) const
00119 {
00120 DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
00121 DDMaterial usemat = div_.parent().material();
00122
00123
00124 std::vector<double> localrMaxVec = msol.rMaxVec();
00125 std::vector<double> localrMinVec = msol.rMinVec();
00126 std::vector<double> localzVec = msol.zVec();
00127 std::vector<double> newrMinVec;
00128 std::vector<double> newrMaxVec;
00129 int nZplanes = localzVec.size();
00130
00131 double width = 0.;
00132 for(int ii = 0; ii < nZplanes; ++ii)
00133 {
00134
00135
00136
00137
00138 width = calculateWidth(localrMaxVec[ii] - localrMinVec[ii], compNDiv_, div_.offset());
00139 newrMinVec[ii] = localrMinVec[ii] + div_.offset() + width * copyNo;
00140 newrMaxVec[ii] = localrMaxVec[ii] + div_.offset() + width * (copyNo + 1);
00141 }
00142
00143
00144
00145
00146 DDName solname(div_.parent().ddname().name() + "_DIVCHILD" + DDXMLElement::itostr(copyNo)
00147 , div_.parent().ddname().ns());
00148
00149 DDSolid dsol = DDSolidFactory::polyhedra(solname
00150 , msol.sides()
00151 , msol.startPhi()
00152 , msol.deltaPhi()
00153 , localzVec
00154 , newrMinVec
00155 , newrMaxVec);
00156 DDLogicalPart ddlp = DDLogicalPart(solname, usemat, dsol);
00157 DCOUT_V ('P', "DDDividedPolyhedraRho:makeDDLogicalPart lp:" << ddlp);
00158 return ddlp;
00159 }
00160
00161
00162 DDDividedPolyhedraPhi::DDDividedPolyhedraPhi ( const DDDivision & div )
00163 : DDDividedGeometryObject( div )
00164 {
00165 checkParametersValidity();
00166 setType( "DivisionPolyhedraPhi" );
00167
00168 DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
00169
00170
00171 if( divisionType_ == DivWIDTH )
00172 {
00173
00174 if( msol.deltaPhi() == 360.*deg ) {
00175 compNDiv_ = calculateNDiv( msol.deltaPhi(), div_.width(), 0. );
00176 }else {
00177 compNDiv_ = calculateNDiv( msol.deltaPhi(), div_.width(), div_.offset() );
00178 }
00179 }
00180 else if( divisionType_ == DivNDIV )
00181 {
00182 if( msol.deltaPhi() == 360.*deg ) {
00183 compWidth_ = calculateWidth( msol.deltaPhi(), div_.nReplicas(), 0. );
00184 }else {
00185
00186 compWidth_ = calculateWidth( msol.deltaPhi(), div_.nReplicas(), div_.offset() );
00187 }
00188 }
00189
00190 DCOUT_V ('P', " DDDividedPolyhedraRho - # divisions " << compNDiv_ << " = " << div_.nReplicas() << "\n Offset " << div_.offset() << " Width " << compWidth_ << " = " << div_.width() << "\n");
00191 }
00192
00193
00194 DDDividedPolyhedraPhi::~DDDividedPolyhedraPhi()
00195 {
00196 }
00197
00198
00199 double DDDividedPolyhedraPhi::getMaxParameter() const
00200 {
00201 DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
00202 return msol.deltaPhi();
00203 }
00204
00205
00206 void DDDividedPolyhedraPhi::checkParametersValidity()
00207 {
00208 DDDividedGeometryObject::checkParametersValidity();
00209
00210 DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
00211
00212 if( divisionType_ == DivNDIVandWIDTH || divisionType_ == DivWIDTH )
00213 {
00214 std::cout << "WARNING - "
00215 << "DDDividedPolyhedraPhi::checkParametersValidity()"
00216 << std::endl
00217 << " Solid " << msol << std::endl
00218 << " Division along PHI will be done splitting "
00219 << "in the defined numSide." << std::endl
00220 << " WIDTH will not be used !" << std::endl;
00221 }
00222 if( div_.offset() != 0. )
00223 {
00224 std::cout << "WARNING - "
00225 << "DDDividedPolyhedraPhi::checkParametersValidity()"
00226 << std::endl
00227 << " Solid " << msol << std::endl
00228 << " Division along PHI will be done splitting "
00229 << "in the defined numSide." << std::endl
00230 << " OFFSET will not be used !" << std::endl;
00231 }
00232
00233
00234
00235 if ( msol.sides() != compNDiv_ )
00236 {
00237 std::cout << "ERROR - "
00238 << "DDDividedPolyhedraPhi::checkParametersValidity()"
00239 << std::endl
00240 << " Division along PHI will be done splitting in the defined"
00241 << std::endl
00242 << " numSide, i.e, the number of division would be :"
00243 << " " << msol.sides()
00244 << " instead of " << compNDiv_ << " !"
00245 << std::endl;
00246 std::string s = "DDDividedPolyhedraPhi::checkParametersValidity() Not supported configuration.";
00247 throw DDException(s);
00248 }
00249 }
00250
00251
00252
00253 DDTranslation DDDividedPolyhedraPhi::makeDDTranslation( const int copyNo ) const
00254 {
00255 return DDTranslation();
00256 }
00257
00258
00259 DDRotation DDDividedPolyhedraPhi::makeDDRotation( const int copyNo ) const
00260 {
00261
00262 double posi = ( copyNo - 1 ) * compWidth_;
00263
00264 DCOUT_V ('P', " DDDividedPolyhedraPhi - position: " << posi/deg << "\n copyNo: " << copyNo << " - compWidth_: " << compWidth_/deg << "\n");
00265
00266
00267 DDRotationMatrix* rotMat = changeRotMatrix( posi);
00268
00269
00270 DDName ddrotname(div_.parent().ddname().name() + "_DIVCHILD_ROT" + DDXMLElement::itostr(copyNo)
00271 , div_.parent().ddname().ns());
00272 DDRotation myddrot = DDrot(ddrotname, rotMat);
00273 DCOUT_V ('P', "DDDividedPolyhedra::makeDDRotation: copyNo = " << copyNo << " rotation = " << myddrot);
00274 return myddrot;
00275
00276 }
00277
00278
00279 DDLogicalPart DDDividedPolyhedraPhi::makeDDLogicalPart( const int copyNo ) const
00280 {
00281 DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
00282 DDMaterial usemat = div_.parent().material();
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293 DDName solname(div_.parent().ddname().name() + "_DIVCHILD"
00294 , div_.parent().ddname().ns());
00295 DDSolid dsol(solname);
00296 if (!dsol.isDefined().second)
00297 {
00298 dsol = DDSolidFactory::polyhedra(solname
00299 , msol.sides()
00300 , msol.startPhi()+div_.offset()
00301 , compWidth_
00302 , msol.zVec()
00303 , msol.rMinVec()
00304 , msol.rMaxVec()
00305 );
00306 }
00307 DDLogicalPart ddlp(solname);
00308 if (!ddlp.isDefined().second)
00309 DDLogicalPart ddlp2 = DDLogicalPart(solname, usemat, dsol);
00310 DCOUT_V ('P', "DDDividedPolyhedraPhi::makeDDLogicalPart() ddlp = " << ddlp);
00311 return ddlp;
00312 }
00313
00314
00315 DDDividedPolyhedraZ::DDDividedPolyhedraZ ( const DDDivision & div )
00316 : DDDividedGeometryObject ( div )
00317 {
00318 checkParametersValidity();
00319 setType( "DivisionPolyhedraZ" );
00320
00321 DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
00322
00323 std::vector<double> zvec = msol.zVec();
00324
00325 if ( divisionType_ == DivWIDTH )
00326 {
00327 compNDiv_ =
00328 calculateNDiv( zvec[zvec.size() - 1] - zvec[0], div_.width(), div_.offset() );
00329 }
00330 else if( divisionType_ == DivNDIV )
00331 {
00332 compWidth_ = calculateWidth( zvec[zvec.size() - 1] - zvec[0]
00333 , div_.nReplicas()
00334 , div_.offset());
00335
00336
00337
00338 }
00339
00340 DCOUT_V ('P', " DDDividedPolyhedraZ - # divisions " << compNDiv_ << " = " << div_.nReplicas() << "\n Offset " << " = " << div_.offset() << "\n Width " << compWidth_ << " = " << div_.width());
00341
00342 }
00343
00344
00345 DDDividedPolyhedraZ::~DDDividedPolyhedraZ()
00346 {
00347 }
00348
00349
00350 double DDDividedPolyhedraZ::getMaxParameter() const
00351 {
00352 DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
00353
00354 std::vector<double> zvec = msol.zVec();
00355 return (zvec[zvec.size() - 1] - zvec[0]);
00356
00357
00358 }
00359
00360
00361 void DDDividedPolyhedraZ::checkParametersValidity()
00362 {
00363 DDDividedGeometryObject::checkParametersValidity();
00364
00365 DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
00366
00367 if( divisionType_ == DivNDIVandWIDTH || divisionType_ == DivWIDTH )
00368 {
00369 std::cout << "WARNING - "
00370 << "DDDividedPolyhedraZ::checkParametersValidity()"
00371 << std::endl
00372 << " Solid " << msol << std::endl
00373 << " Division along Z will be done splitting "
00374 << "in the defined z_planes." << std::endl
00375 << " WIDTH will not be used !" << std::endl;
00376 }
00377
00378 if( div_.offset() != 0. )
00379 {
00380 std::cout << "WARNING - "
00381 << "DDDividedPolyhedraZ::checkParametersValidity()"
00382 << std::endl
00383 << " Solid " << msol << std::endl
00384 << " Division along Z will be done splitting "
00385 << "in the defined z_planes." << std::endl
00386 << " OFFSET will not be used !" << std::endl;
00387 }
00388
00389
00390
00391 std::vector<double> zvec = msol.zVec();
00392
00393 if ( zvec.size() - 1 != size_t(compNDiv_) )
00394 {
00395 std::cout << "ERROR - "
00396 << "DDDividedPolyhedraZ::checkParametersValidity()"
00397 << std::endl
00398 << " Division along Z can only be done by splitting in the defined"
00399 << std::endl
00400 << " z_planes, i.e, the number of division would be :"
00401 << " " << zvec.size() - 1
00402 << " instead of " << compNDiv_ << " !"
00403 << std::endl;
00404 std::string s = "DDDividedPolyhedraZ::checkParametersValidity()";
00405 s += "Illegal Construct. Not a supported configuration.";
00406 throw DDException (s);
00407 }
00408 }
00409
00410
00411 DDTranslation DDDividedPolyhedraZ::makeDDTranslation( const int copyNo ) const
00412 {
00413 DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
00414 std::vector<double> zvec = msol.zVec();
00415
00416
00417
00418
00419
00420
00421 double posi = (zvec[copyNo] + zvec[copyNo+1])/2;
00422
00423
00424
00425
00426 DDTranslation tr(0,0,posi);
00427
00428
00429 DCOUT_V ('P', " DDDividedPolyhedraZ - position: " << posi << "\n copyNo: " << copyNo << " - offset: " << div_.offset()/deg << " - compWidth_: " << compWidth_/deg << " translation = " << tr);
00430 return tr;
00431 }
00432
00433
00434 DDRotation DDDividedPolyhedraZ::makeDDRotation( const int copyNo ) const
00435 {
00436 return DDRotation();
00437 }
00438
00439
00440 DDLogicalPart DDDividedPolyhedraZ::makeDDLogicalPart( const int copyNo ) const
00441 {
00442
00443
00444 DDPolyhedra msol = (DDPolyhedra)(div_.parent().solid());
00445 DDMaterial usemat = div_.parent().material();
00446
00447
00448 std::vector<double> zvec = msol.zVec();
00449 std::vector<double> rminvec = msol.rMinVec();
00450 std::vector<double> rmaxvec = msol.rMaxVec();
00451
00452 double posi = (zvec[copyNo] + zvec[copyNo+1])/2;
00453
00454
00455
00456
00457
00458
00459
00460
00461 DDName solname(div_.parent().ddname().name() + "_DIVCHILD"
00462 + DDXMLElement::itostr(copyNo)
00463 , div_.parent().ddname().ns());
00464 std::vector<double> newRmin, newRmax, newZ;
00465 newZ.push_back(zvec[copyNo] - posi);
00466 newZ.push_back(zvec[copyNo+1] - posi);
00467 newRmin.push_back(rminvec[copyNo]);
00468 newRmin.push_back(rminvec[copyNo+1]);
00469 newRmax.push_back(rmaxvec[copyNo]);
00470 newRmax.push_back(rmaxvec[copyNo+1]);
00471
00472 DDSolid dsol = DDSolidFactory::polyhedra(solname
00473 , msol.sides()
00474 , msol.startPhi()
00475 , msol.deltaPhi()
00476 , newZ
00477 , newRmin
00478 , newRmax);
00479 DDLogicalPart lp(solname, usemat, dsol);
00480
00481
00482
00483
00484 DCOUT_V ('P', "DDDividedPolyhedraZ::makeDDLogicalPart" << "\n-- Parametrised phedra copy-number: " << copyNo << "\n-- DDLogicalPart " << lp );
00485 return lp;
00486
00487 }
00488