Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:55:06

0001 #include "DetectorDescription/Parser/src/DDDividedTrd.h"
0002 #include "DetectorDescription/Core/interface/DDAxes.h"
0003 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0004 #include "DetectorDescription/Core/interface/DDMaterial.h"
0005 #include "DetectorDescription/Core/interface/DDName.h"
0006 #include "DetectorDescription/Core/interface/DDSolid.h"
0007 #include "DetectorDescription/Core/interface/DDTransform.h"
0008 #include "DataFormats/Math/interface/GeantUnits.h"
0009 #include "DetectorDescription/Parser/src/DDDividedGeometryObject.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 #include "FWCore/Utilities/interface/Exception.h"
0012 
0013 #include <cmath>
0014 #include <ostream>
0015 #include <string>
0016 #include <utility>
0017 
0018 class DDCompactView;
0019 
0020 using namespace geant_units::operators;
0021 
0022 DDDividedTrdX::DDDividedTrdX(const DDDivision& div, DDCompactView* cpv) : DDDividedGeometryObject(div, cpv) {
0023   checkParametersValidity();
0024   setType("DivisionTrdX");
0025   DDTrap mtrd = (DDTrap)(div_.parent().solid());
0026 
0027   if (divisionType_ == DivWIDTH) {
0028     compNDiv_ = calculateNDiv(2 * mtrd.x1(), div_.width(), div_.offset());
0029   } else if (divisionType_ == DivNDIV) {
0030     compWidth_ = calculateWidth(2 * mtrd.x1(), div_.nReplicas(), div_.offset());
0031   }
0032 }
0033 
0034 double DDDividedTrdX::getMaxParameter(void) const {
0035   DDTrap mtrd = (DDTrap)(div_.parent().solid());
0036   return 2 * mtrd.x1();
0037 }
0038 
0039 DDTranslation DDDividedTrdX::makeDDTranslation(const int copyNo) const {
0040   DDTrap mtrd = (DDTrap)(div_.parent().solid());
0041   double mdx = mtrd.x1();
0042 
0043   //----- translation
0044   double posi = -mdx + div_.offset() + (copyNo + 0.5) * compWidth_;
0045 
0046   if (div_.axis() == DDAxes::x) {
0047     return DDTranslation(posi, 0.0, 0.0);
0048   } else {
0049     std::string s = "ERROR - DDDividedTrdX::makeDDTranslation()";
0050     s += "\n        Axis is along ";
0051     s += DDAxesNames::name(div_.axis());
0052     s += " !\n";
0053     s += "DDDividedTrdX::makeDDTranslation()";
0054     s += " IllegalConstruct: Only axes along x are allowed !";
0055     throw cms::Exception("DDException") << s;
0056   }
0057 
0058   return DDTranslation();
0059 }
0060 
0061 DDRotation DDDividedTrdX::makeDDRotation(const int copyNo) const { return DDRotation(); }
0062 
0063 DDLogicalPart DDDividedTrdX::makeDDLogicalPart(const int copyNo) const {
0064   DDTrap mtrd = (DDTrap)(div_.parent().solid());
0065   DDMaterial usemat = div_.parent().material();
0066 
0067   double pDy1 = mtrd.y1();    // Y half length1
0068   double pDy2 = mtrd.y2();    // Y half length2
0069   double pDz = mtrd.halfZ();  // Z half length
0070   double pDx = compWidth_ / 2.;
0071 
0072   DDName solname(div_.parent().ddname().name() + "_DIVCHILD", div_.parent().ddname().ns());
0073   DDSolid dsol(solname);
0074   DDLogicalPart ddlp(solname);
0075   if (!dsol.isDefined().second) {
0076     dsol = DDSolidFactory::trap(solname, pDz, 0._deg, 0._deg, pDy1, pDx, pDx, 0._deg, pDy2, pDx, pDx, 0._deg);
0077     ddlp = DDLogicalPart(solname, usemat, dsol);
0078   }
0079   return ddlp;
0080 }
0081 
0082 void DDDividedTrdX::checkParametersValidity(void) {
0083   DDDividedGeometryObject::checkParametersValidity();
0084 
0085   DDTrap mtrd = (DDTrap)(div_.parent().solid());
0086 
0087   double mpDx1 = mtrd.x1();  // X half length1
0088   double mpDx2 = mtrd.x2();  // X half length2
0089   double mpDx3 = mtrd.x3();
0090   double mpDx4 = mtrd.x4();
0091   double mpTheta = mtrd.theta();
0092   double mpPhi = mtrd.phi();
0093   double mpAlpha1 = mtrd.alpha1();
0094   double mpAlpha2 = mtrd.alpha2();
0095 
0096   if (fabs(mpDx1 - mpDx2) > tolerance() || fabs(mpDx3 - mpDx4) > tolerance() || fabs(mpDx1 - mpDx4) > tolerance()) {
0097     std::string s = "ERROR - DDDividedTrdX::checkParametersValidity()";
0098     s += "\n        Making a division of a TRD along axis X,";
0099     s += "\n        while the X half lengths are not equal,";
0100     s += "\n        is not (yet) supported. It will result";
0101     s += "\n        in non-equal division solids.";
0102     throw cms::Exception("DDException") << s;
0103   }
0104 
0105   // mec:  we only have traps, not trds in DDD, so I added this check
0106   // to make sure it is only a trd (I think! :-))
0107   if (mpAlpha1 != 0._deg || mpAlpha2 != 0._deg || mpTheta != 0._deg || mpPhi != 0._deg) {
0108     std::string s = "ERROR - DDDividedTrdX::checkParametersValidity()";
0109     s += "\n        Making a division of a TRD along axis X,";
0110     s += "\n        while the theta, phi and aplhpa2 are not zero,";
0111     s += "\n        is not (yet) supported. It will result";
0112     s += "\n        in non-equal division solids.";
0113     throw cms::Exception("DDException") << s;
0114   }
0115 }
0116 
0117 DDDividedTrdY::DDDividedTrdY(const DDDivision& div, DDCompactView* cpv) : DDDividedGeometryObject(div, cpv) {
0118   checkParametersValidity();
0119   setType("DivisionTrdY");
0120   DDTrap mtrd = (DDTrap)(div_.parent().solid());
0121 
0122   if (divisionType_ == DivWIDTH) {
0123     compNDiv_ = calculateNDiv(2 * mtrd.y1(), div_.width(), div_.offset());
0124   } else if (divisionType_ == DivNDIV) {
0125     compWidth_ = calculateWidth(2 * mtrd.y1(), div_.nReplicas(), div_.offset());
0126   }
0127 }
0128 
0129 double DDDividedTrdY::getMaxParameter(void) const {
0130   DDTrap mtrd = (DDTrap)(div_.parent().solid());
0131   return 2 * mtrd.y1();
0132 }
0133 
0134 DDTranslation DDDividedTrdY::makeDDTranslation(const int copyNo) const {
0135   DDTrap mtrd = (DDTrap)(div_.parent().solid());
0136   double mdy = mtrd.y1();
0137 
0138   //----- translation
0139   double posi = -mdy + div_.offset() + (copyNo + 0.5) * compWidth_;
0140 
0141   if (div_.axis() == DDAxes::y) {
0142     return DDTranslation(0.0, posi, 0.0);
0143   } else {
0144     std::string s = "ERROR - DDDividedTrdY::makeDDTranslation()";
0145     s += "\n        Axis is along ";
0146     s += DDAxesNames::name(div_.axis());
0147     s += " !\n";
0148     s += "DDDividedTrdY::makeDDTranslation()";
0149     s += " IllegalConstruct: Only axes along y are allowed !";
0150     throw cms::Exception("DDException") << s;
0151   }
0152   return DDTranslation();
0153 }
0154 
0155 DDRotation DDDividedTrdY::makeDDRotation(const int copyNo) const { return DDRotation(); }
0156 
0157 DDLogicalPart DDDividedTrdY::makeDDLogicalPart(const int copyNo) const {
0158   //---- The division along Y of a Trd will result a Trd, only
0159   //--- if Y at -Z and +Z are equal, else use the G4Trap version
0160   DDTrap mtrd = (DDTrap)(div_.parent().solid());
0161   DDMaterial usemat = div_.parent().material();
0162 
0163   double pDx1 = mtrd.x1();    // X half length1 at Y+
0164   double pDx2 = mtrd.x2();    // X half length2 at Y+
0165   double pDx3 = mtrd.x3();    // X half length1 at Y-
0166   double pDx4 = mtrd.x4();    // X half length2 at Y-
0167   double pDz = mtrd.halfZ();  // Z half length
0168   double pDy = compWidth_ / 2.;
0169 
0170   DDName solname(div_.name());
0171   DDSolid dsol(solname);
0172   DDLogicalPart ddlp(solname);
0173   if (!dsol.isDefined().second) {
0174     dsol = DDSolidFactory::trap(solname, pDz, 0._deg, 0._deg, pDy, pDx1, pDx2, 0._deg, pDy, pDx3, pDx4, 0._deg);
0175     DDLogicalPart ddlp(solname, usemat, dsol);
0176   }
0177   return ddlp;
0178 }
0179 
0180 void DDDividedTrdY::checkParametersValidity(void) {
0181   DDDividedGeometryObject::checkParametersValidity();
0182 
0183   DDTrap mtrd = (DDTrap)(div_.parent().solid());
0184 
0185   double mpDy1 = mtrd.y1();  // Y half length1
0186   double mpDy2 = mtrd.y2();  // Y half length2
0187   double mpTheta = mtrd.theta();
0188   double mpPhi = mtrd.phi();
0189   double mpAlpha1 = mtrd.alpha1();
0190   double mpAlpha2 = mtrd.alpha2();
0191 
0192   if (fabs(mpDy1 - mpDy2) > tolerance()) {
0193     std::string s = "ERROR - DDDividedTrdY::checkParametersValidity()";
0194     s += "\n        Making a division of a TRD along axis Y while";
0195     s += "\n        the Y half lengths are not equal is not (yet)";
0196     s += "\n        supported. It will result in non-equal";
0197     s += "\n        division solids.";
0198     throw cms::Exception("DDException") << s;
0199   }
0200   // mec:  we only have traps, not trds in DDD, so I added this check
0201   // to make sure it is only a trd (I think! :-))
0202   if (mpAlpha1 != 0._deg || mpAlpha2 != 0._deg || mpTheta != 0._deg || mpPhi != 0._deg) {
0203     std::string s = "ERROR - DDDividedTrdY::checkParametersValidity()";
0204     s += "\n        Making a division of a TRD along axis X,";
0205     s += "\n        while the theta, phi and aplhpa2 are not zero,";
0206     s += "\n        is not (yet) supported. It will result";
0207     s += "\n        in non-equal division solids.";
0208     throw cms::Exception("DDException") << s;
0209   }
0210 }
0211 
0212 DDDividedTrdZ::DDDividedTrdZ(const DDDivision& div, DDCompactView* cpv) : DDDividedGeometryObject(div, cpv) {
0213   checkParametersValidity();
0214   setType("DivTrdZ");
0215   DDTrap mtrd = (DDTrap)(div_.parent().solid());
0216 
0217   if (divisionType_ == DivWIDTH) {
0218     compNDiv_ = calculateNDiv(2 * mtrd.halfZ(), div_.width(), div_.offset());
0219   } else if (divisionType_ == DivNDIV) {
0220     compWidth_ = calculateWidth(2 * mtrd.halfZ(), div_.nReplicas(), div_.offset());
0221   }
0222 }
0223 
0224 double DDDividedTrdZ::getMaxParameter(void) const {
0225   DDTrap mtrd = (DDTrap)(div_.parent().solid());
0226   return 2 * mtrd.halfZ();
0227 }
0228 
0229 DDTranslation DDDividedTrdZ::makeDDTranslation(const int copyNo) const {
0230   DDTrap mtrd = (DDTrap)(div_.parent().solid());
0231   double mdz = mtrd.halfZ();
0232 
0233   //----- translation
0234   double posi = -mdz + div_.offset() + (copyNo + 0.5) * compWidth_;
0235 
0236   if (div_.axis() == DDAxes::z) {
0237     return DDTranslation(0.0, 0.0, posi);
0238   } else {
0239     std::string s = "ERROR - DDDividedTrdZ::makeDDTranslation()";
0240     s += "\n        Axis is along ";
0241     s += DDAxesNames::name(div_.axis());
0242     s += " !\n";
0243     s += "DDDividedTrdY::makeDDTranslation()";
0244     s += " IllegalConstruct: Only axes along z are allowed !";
0245     throw cms::Exception("DDException") << s;
0246   }
0247   return DDTranslation();
0248 }
0249 
0250 DDRotation DDDividedTrdZ::makeDDRotation(const int copyNo) const { return DDRotation(); }
0251 
0252 DDLogicalPart DDDividedTrdZ::makeDDLogicalPart(const int copyNo) const {
0253   //---- The division along Z of a Trd will result a Trd
0254   DDTrap mtrd = (DDTrap)(div_.parent().solid());
0255   DDMaterial usemat = div_.parent().material();
0256 
0257   double pDx1 = mtrd.x1();  // X half length1
0258   double DDx = (mtrd.x2() - mtrd.x1());
0259   double pDy1 = mtrd.y1();  // Y half length1
0260   double DDy = (mtrd.y2() - mtrd.y1());
0261   double pDz = compWidth_ / 2.;
0262   double zLength = 2 * mtrd.halfZ();  // Z half length
0263 
0264   DDName solname(div_.parent().ddname().name() + "_DIVCHILD" + std::to_string(copyNo), div_.parent().ddname().ns());
0265   DDSolid dsol = DDSolidFactory::trap(solname,
0266                                       pDz,
0267                                       0._deg,
0268                                       0._deg,
0269                                       pDy1 + DDy * (div_.offset() + copyNo * compWidth_) / zLength,
0270                                       pDx1 + DDx * (div_.offset() + copyNo * compWidth_) / zLength,
0271                                       pDx1 + DDx * (div_.offset() + copyNo * compWidth_) / zLength,
0272                                       0._deg,
0273                                       pDy1 + DDy * (div_.offset() + (copyNo + 1) * compWidth_) / zLength,
0274                                       pDx1 + DDx * (div_.offset() + (copyNo + 1) * compWidth_) / zLength,
0275                                       pDx1 + DDx * (div_.offset() + (copyNo + 1) * compWidth_) / zLength,
0276                                       0._deg);
0277 
0278   DDLogicalPart ddlp(solname, usemat, dsol);
0279   return ddlp;
0280 }
0281 
0282 void DDDividedTrdZ::checkParametersValidity(void) {
0283   DDDividedGeometryObject::checkParametersValidity();
0284 
0285   DDTrap mtrd = (DDTrap)(div_.parent().solid());
0286 
0287   double mpTheta = mtrd.theta();
0288   double mpPhi = mtrd.phi();
0289   double mpAlpha1 = mtrd.alpha1();
0290   double mpAlpha2 = mtrd.alpha2();
0291 
0292   // mec:  we only have traps, not trds in DDD, so I added this check
0293   // to make sure it is only a trd (I think! :-))
0294   if (mpAlpha1 != 0._deg || mpAlpha2 != 0._deg || mpTheta != 0._deg || mpPhi != 0._deg) {
0295     std::string s = "ERROR - DDDividedTrdZ::checkParametersValidity()";
0296     s += "\n        Making a division of a TRD along axis X,";
0297     s += "\n        while the theta, phi and aplhpa2 are not zero,";
0298     s += "\n        is not (yet) supported. It will result";
0299     s += "\n        in non-equal division solids.";
0300     throw cms::Exception("DDException") << s;
0301   }
0302 }