00001
00002
00003
00004
00005
00006 #include "DDDividedTrd.h"
00007 #include "DDXMLElement.h"
00008
00009 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
00010 #include "DetectorDescription/Core/interface/DDName.h"
00011 #include "DetectorDescription/Core/interface/DDPosPart.h"
00012 #include "DetectorDescription/Core/interface/DDAxes.h"
00013 #include "DetectorDescription/Core/interface/DDSolid.h"
00014 #include "DetectorDescription/Core/interface/DDSolidShapes.h"
00015 #include "DetectorDescription/Core/interface/DDMaterial.h"
00016
00017 #include "DetectorDescription/Base/interface/DDdebug.h"
00018 #include "DetectorDescription/Base/interface/DDException.h"
00019 #include "DetectorDescription/Base/interface/DDRotationMatrix.h"
00020 #include "DetectorDescription/Base/interface/DDTranslation.h"
00021
00022 #include "CLHEP/Units/SystemOfUnits.h"
00023
00024 #include <cmath>
00025 #include <cstdlib>
00026
00027
00028 DDDividedTrdX::DDDividedTrdX ( const DDDivision & div )
00029 : DDDividedGeometryObject ( div )
00030 {
00031 checkParametersValidity();
00032 setType( "DivisionTrdX" );
00033 DDTrap mtrd = (DDTrap)( div_.parent().solid() );
00034
00035 if ( divisionType_ == DivWIDTH )
00036 {
00037 compNDiv_ = calculateNDiv( 2 * mtrd.x1(), div_.width(), div_.offset() );
00038 }
00039 else if( divisionType_ == DivNDIV )
00040 {
00041 compWidth_ = calculateWidth( 2*mtrd.x1(), div_.nReplicas(), div_.offset() );
00042 }
00043
00044 DCOUT_V ('P', " DDDividedTrdX - ## divisions " << compNDiv_ << " = " << div_.nReplicas() << "\n Offset " << div_.offset() << "\n Width " << compWidth_ << " = " << div_.width());
00045 }
00046
00047
00048 DDDividedTrdX::~DDDividedTrdX()
00049 {
00050 }
00051
00052
00053 double DDDividedTrdX::getMaxParameter() const
00054 {
00055 DDTrap mtrd = (DDTrap)(div_.parent().solid());
00056 return 2 * mtrd.x1();
00057 }
00058
00059
00060 DDTranslation DDDividedTrdX::makeDDTranslation ( const int copyNo ) const
00061 {
00062 DDTrap mtrd = (DDTrap)(div_.parent().solid());
00063 double mdx = mtrd.x1();
00064
00065
00066
00067 double posi = -mdx + div_.offset() + (copyNo+0.5)*compWidth_;
00068
00069 DCOUT_V ('P', " DDDividedTrdX: " << copyNo << "\n Position: x=" << posi << " Axis= " << DDAxesNames::name(div_.axis()) << "\n");
00070
00071 if( div_.axis() == x )
00072 {
00073 return DDTranslation(posi, 0.0, 0.0);
00074 }
00075 else
00076 {
00077 std::string s = "ERROR - DDDividedTrdX::makeDDTranslation()";
00078 s += "\n Axis is along ";
00079 s += DDAxesNames::name(div_.axis());
00080 s += " !\n" ;
00081 s += "DDDividedTrdX::makeDDTranslation()";
00082 s += " IllegalConstruct: Only axes along x are allowed !";
00083 throw DDException(s);
00084 }
00085
00086 return DDTranslation();
00087 }
00088
00089
00090 DDRotation DDDividedTrdX::makeDDRotation ( const int copyNo ) const
00091 {
00092 return DDRotation();
00093 }
00094
00095
00096 DDLogicalPart DDDividedTrdX::makeDDLogicalPart( const int copyNo ) const
00097 {
00098 DDTrap mtrd = (DDTrap)(div_.parent().solid());
00099 DDMaterial usemat = div_.parent().material();
00100
00101 double pDy1 = mtrd.y1();
00102 double pDy2 = mtrd.y2();
00103 double pDz = mtrd.halfZ();
00104 double pDx = compWidth_/2.;
00105
00106
00107
00108 DDName solname(div_.parent().ddname().name() + "_DIVCHILD"
00109 , div_.parent().ddname().ns());
00110 DDSolid dsol(solname);
00111 DDLogicalPart ddlp(solname);
00112 if (!dsol.isDefined().second)
00113 {
00114 dsol = DDSolidFactory::trap(solname
00115 , pDz
00116 , 0.*deg
00117 , 0.*deg
00118 , pDy1
00119 , pDx
00120 , pDx
00121 , 0.*deg
00122 , pDy2
00123 , pDx
00124 , pDx
00125 , 0.*deg);
00126 ddlp = DDLogicalPart(solname, usemat, dsol);
00127 }
00128 DCOUT_V ('P', "DDDividedTrdX::makeDDLogicalPart lp = " << ddlp);
00129 return ddlp;
00130 }
00131
00132
00133 void DDDividedTrdX::checkParametersValidity()
00134 {
00135 DDDividedGeometryObject::checkParametersValidity();
00136
00137 DDTrap mtrd = (DDTrap)(div_.parent().solid());
00138
00139 double mpDx1 = mtrd.x1();
00140 double mpDx2 = mtrd.x2();
00141 double mpDx3 = mtrd.x3();
00142 double mpDx4 = mtrd.x4();
00143 double mpTheta = mtrd.theta();
00144 double mpPhi = mtrd.phi();
00145 double mpAlpha1 = mtrd.alpha1();
00146 double mpAlpha2 = mtrd.alpha2();
00147
00148
00149
00150
00151
00152 if ( fabs(mpDx1 - mpDx2) > tolerance() || fabs(mpDx3 - mpDx4) > tolerance()
00153 || fabs(mpDx1 - mpDx4) > tolerance())
00154 {
00155 std::string s = "ERROR - DDDividedTrdX::checkParametersValidity()";
00156 s+= "\n Making a division of a TRD along axis X,";
00157 s+= "\n while the X half lengths are not equal,";
00158 s+= "\n is not (yet) supported. It will result";
00159 s+= "\n in non-equal division solids.";
00160 throw DDException(s);
00161 }
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173 if (mpAlpha1 != 0.*deg || mpAlpha2 != 0.*deg || mpTheta != 0.*deg || mpPhi != 0.*deg)
00174 {
00175 std::string s = "ERROR - DDDividedTrdX::checkParametersValidity()";
00176 s+= "\n Making a division of a TRD along axis X,";
00177 s+= "\n while the theta, phi and aplhpa2 are not zero,";
00178 s+= "\n is not (yet) supported. It will result";
00179 s+= "\n in non-equal division solids.";
00180 throw DDException(s);
00181 }
00182
00183 }
00184
00185
00186 DDDividedTrdY::DDDividedTrdY ( const DDDivision & div )
00187 : DDDividedGeometryObject( div )
00188 {
00189 checkParametersValidity();
00190 setType( "DivisionTrdY" );
00191 DDTrap mtrd = (DDTrap)(div_.parent().solid());
00192
00193 if( divisionType_ == DivWIDTH )
00194 {
00195 compNDiv_ = calculateNDiv( 2 * mtrd.y1(), div_.width(), div_.offset() );
00196 }
00197 else if( divisionType_ == DivNDIV )
00198 {
00199 compWidth_ = calculateWidth( 2 * mtrd.y1(), div_.nReplicas(), div_.offset() );
00200 }
00201
00202 DCOUT_V ('P', " DDDividedTrdY no divisions " << compNDiv_ << " = " << div_.nReplicas() << "\n Offset " << div_.offset() << "\n width " << compWidth_ << " = " << div_.width() << std::endl);
00203
00204 }
00205
00206
00207 DDDividedTrdY::~DDDividedTrdY()
00208 {
00209 }
00210
00211
00212 double DDDividedTrdY::getMaxParameter() const
00213 {
00214 DDTrap mtrd = (DDTrap)(div_.parent().solid());
00215 return 2 * mtrd.y1();
00216 }
00217
00218
00219 DDTranslation DDDividedTrdY::makeDDTranslation( const int copyNo ) const
00220 {
00221 DDTrap mtrd = (DDTrap)(div_.parent().solid() );
00222 double mdy = mtrd.y1();
00223
00224
00225 double posi = -mdy + div_.offset() + (copyNo+0.5)*compWidth_;
00226
00227 DCOUT_V ('P', " DDDividedTrdY: " << copyNo << "\n Position: y=" << posi << " Axis= " << DDAxesNames::name(div_.axis()) << "\n");
00228
00229 if( div_.axis() == y )
00230 {
00231 return DDTranslation(0.0, posi, 0.0);
00232 }
00233 else
00234 {
00235 std::string s = "ERROR - DDDividedTrdY::makeDDTranslation()";
00236 s += "\n Axis is along ";
00237 s += DDAxesNames::name(div_.axis());
00238 s += " !\n" ;
00239 s += "DDDividedTrdY::makeDDTranslation()";
00240 s += " IllegalConstruct: Only axes along y are allowed !";
00241 throw DDException(s);
00242 }
00243 return DDTranslation();
00244 }
00245
00246
00247 DDRotation DDDividedTrdY::makeDDRotation ( const int copyNo ) const
00248 {
00249 return DDRotation();
00250 }
00251
00252
00253 DDLogicalPart DDDividedTrdY::makeDDLogicalPart( const int copyNo ) const
00254 {
00255
00256
00257 DDTrap mtrd = (DDTrap)(div_.parent().solid());
00258 DDMaterial usemat = div_.parent().material();
00259
00260 double pDx1 = mtrd.x1();
00261 double pDx2 = mtrd.x2();
00262 double pDx3 = mtrd.x3();
00263 double pDx4 = mtrd.x4();
00264 double pDz = mtrd.halfZ();
00265 double pDy = compWidth_/2.;
00266
00267
00268 DDName solname(div_.name() );
00269 DDSolid dsol(solname);
00270 DDLogicalPart ddlp(solname);
00271 if (!dsol.isDefined().second)
00272 {
00273 dsol = DDSolidFactory::trap(solname
00274 , pDz
00275 , 0.*deg
00276 , 0.*deg
00277 , pDy
00278 , pDx1
00279 , pDx2
00280 , 0*deg
00281 , pDy
00282 , pDx3
00283 , pDx4
00284 , 0.*deg);
00285 DDLogicalPart ddlp(solname, usemat, dsol);
00286 }
00287 DCOUT_V ('P', "DDDividedTrdY::makeDDLogicalPart lp = " << ddlp);
00288 return ddlp;
00289 }
00290
00291
00292 void DDDividedTrdY::checkParametersValidity()
00293 {
00294 DDDividedGeometryObject::checkParametersValidity();
00295
00296 DDTrap mtrd = (DDTrap)(div_.parent().solid());
00297
00298 double mpDy1 = mtrd.y1();
00299 double mpDy2 = mtrd.y2();
00300 double mpTheta = mtrd.theta();
00301 double mpPhi = mtrd.phi();
00302 double mpAlpha1 = mtrd.alpha1();
00303 double mpAlpha2 = mtrd.alpha2();
00304
00305 if( fabs(mpDy1 - mpDy2) > tolerance() )
00306 {
00307 std::string s= "ERROR - DDDividedTrdY::checkParametersValidity()";
00308 s += "\n Making a division of a TRD along axis Y while";
00309 s += "\n the Y half lengths are not equal is not (yet)";
00310 s += "\n supported. It will result in non-equal";
00311 s += "\n division solids.";
00312 throw DDException(s);
00313 }
00314
00315
00316 if (mpAlpha1 != 0.*deg || mpAlpha2 != 0.*deg || mpTheta != 0.*deg || mpPhi != 0.*deg)
00317 {
00318 std::string s = "ERROR - DDDividedTrdY::checkParametersValidity()";
00319 s+= "\n Making a division of a TRD along axis X,";
00320 s+= "\n while the theta, phi and aplhpa2 are not zero,";
00321 s+= "\n is not (yet) supported. It will result";
00322 s+= "\n in non-equal division solids.";
00323 throw DDException(s);
00324 }
00325 }
00326
00327
00328 DDDividedTrdZ::DDDividedTrdZ( const DDDivision & div )
00329 : DDDividedGeometryObject ( div )
00330 {
00331 checkParametersValidity();
00332 setType( "DivTrdZ" );
00333 DDTrap mtrd = (DDTrap)(div_.parent().solid());
00334
00335 if ( divisionType_ == DivWIDTH )
00336 {
00337 compNDiv_ = calculateNDiv( 2*mtrd.halfZ(), div_.width(), div_.offset() );
00338 }
00339 else if( divisionType_ == DivNDIV )
00340 {
00341 compWidth_ = calculateWidth( 2*mtrd.halfZ(), div_.nReplicas(), div_.offset() );
00342 }
00343 DCOUT_V ('P', " DDDividedTrdY no divisions " << compNDiv_ << " = " << div_.nReplicas() << "\n Offset " << div_.offset() << "\n width " << compWidth_ << " = " << div_.width() << std::endl);
00344 }
00345
00346
00347 DDDividedTrdZ::~DDDividedTrdZ()
00348 {
00349 }
00350
00351
00352 double DDDividedTrdZ::getMaxParameter() const
00353 {
00354 DDTrap mtrd = (DDTrap)(div_.parent().solid());
00355 return 2 * mtrd.halfZ();
00356 }
00357
00358
00359 DDTranslation DDDividedTrdZ::makeDDTranslation ( const int copyNo ) const
00360 {
00361 DDTrap mtrd = (DDTrap)(div_.parent().solid() );
00362 double mdz = mtrd.halfZ();
00363
00364
00365 double posi = -mdz + div_.offset() + (copyNo+0.5)*compWidth_;
00366
00367 DCOUT_V ('P', " DDDividedTrdZ: " << copyNo << "\n Position: z=" << posi << " Axis= " << DDAxesNames::name(div_.axis()) << "\n");
00368
00369 if( div_.axis() == z )
00370 {
00371 return DDTranslation(0.0, 0.0, posi);
00372 }
00373 else
00374 {
00375 std::string s = "ERROR - DDDividedTrdZ::makeDDTranslation()";
00376 s += "\n Axis is along ";
00377 s += DDAxesNames::name(div_.axis());
00378 s += " !\n" ;
00379 s += "DDDividedTrdY::makeDDTranslation()";
00380 s += " IllegalConstruct: Only axes along z are allowed !";
00381 throw DDException(s);
00382
00383 }
00384 return DDTranslation();
00385 }
00386
00387
00388 DDRotation DDDividedTrdZ::makeDDRotation ( const int copyNo ) const
00389 {
00390 return DDRotation();
00391 }
00392
00393
00394 DDLogicalPart DDDividedTrdZ::makeDDLogicalPart ( const int copyNo ) const
00395 {
00396
00397 DDTrap mtrd = (DDTrap)(div_.parent().solid());
00398 DDMaterial usemat = div_.parent().material();
00399
00400 double pDx1 = mtrd.x1();
00401
00402 double DDx = (mtrd.x2() - mtrd.x1() );
00403 double pDy1 = mtrd.y1();
00404
00405 double DDy = (mtrd.y2() - mtrd.y1() );
00406 double pDz = compWidth_/2.;
00407 double zLength = 2*mtrd.halfZ();
00408
00409
00410
00411
00412
00413
00414 DDName solname(div_.parent().ddname().name() + "_DIVCHILD"
00415 + DDXMLElement::itostr(copyNo)
00416 , div_.parent().ddname().ns());
00417 DDSolid dsol =
00418 DDSolidFactory::trap(solname
00419 , pDz
00420 , 0.*deg
00421 , 0.*deg
00422 , pDy1+DDy*(div_.offset()+copyNo*compWidth_)/zLength
00423 , pDx1+DDx*(div_.offset()+copyNo*compWidth_)/zLength
00424 , pDx1+DDx*(div_.offset()+copyNo*compWidth_)/zLength
00425 , 0.*deg
00426 , pDy1+DDy*(div_.offset()+(copyNo+1)*compWidth_)/zLength
00427 , pDx1+DDx*(div_.offset()+(copyNo+1)*compWidth_)/zLength
00428 , pDx1+DDx*(div_.offset()+(copyNo+1)*compWidth_)/zLength
00429 , 0*deg
00430 );
00431
00432 DDLogicalPart ddlp(solname, usemat, dsol);
00433 DCOUT_V ('P', "DDDividedTrdZ::makeDDLogicalPart lp = " << ddlp);
00434 return ddlp;
00435 }
00436
00437
00438 void DDDividedTrdZ::checkParametersValidity()
00439 {
00440 DDDividedGeometryObject::checkParametersValidity();
00441
00442 DDTrap mtrd = (DDTrap)(div_.parent().solid());
00443
00444 double mpTheta = mtrd.theta();
00445 double mpPhi = mtrd.phi();
00446 double mpAlpha1 = mtrd.alpha1();
00447 double mpAlpha2 = mtrd.alpha2();
00448
00449
00450
00451 if (mpAlpha1 != 0.*deg || mpAlpha2 != 0.*deg || mpTheta != 0.*deg || mpPhi != 0.*deg)
00452 {
00453 std::string s = "ERROR - DDDividedTrdZ::checkParametersValidity()";
00454 s+= "\n Making a division of a TRD along axis X,";
00455 s+= "\n while the theta, phi and aplhpa2 are not zero,";
00456 s+= "\n is not (yet) supported. It will result";
00457 s+= "\n in non-equal division solids.";
00458 throw DDException(s);
00459 }
00460 }