Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:05:31

0001 #include "DetectorDescription/Parser/src/DDDividedCons.h"
0002 #include "DetectorDescription/Core/interface/DDRotationMatrix.h"
0003 #include "DetectorDescription/Core/interface/DDAxes.h"
0004 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0005 #include "DetectorDescription/Core/interface/DDMaterial.h"
0006 #include "DetectorDescription/Core/interface/DDName.h"
0007 #include "DetectorDescription/Core/interface/DDSolid.h"
0008 #include "DetectorDescription/Core/interface/DDTransform.h"
0009 #include "DataFormats/Math/interface/GeantUnits.h"
0010 #include "DetectorDescription/Parser/src/DDDividedGeometryObject.h"
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 
0013 #include <iostream>
0014 #include <string>
0015 #include <utility>
0016 
0017 class DDCompactView;
0018 
0019 using namespace geant_units::operators;
0020 
0021 DDDividedConsRho::DDDividedConsRho(const DDDivision& div, DDCompactView* cpv)
0022     : DDDividedGeometryObject::DDDividedGeometryObject(div, cpv) {
0023   checkParametersValidity();
0024   setType("DivisionConsRho");
0025   DDCons msol = (DDCons)(div_.parent().solid());
0026 
0027   if (msol.rInPlusZ() == 0.) {
0028     std::cout << "WARNING - DDDividedConsRho, rOutMinusZ = 0. " << std::endl
0029               << "          Width is calculated as that of rOutMinusZ !" << std::endl;
0030   }
0031 
0032   if (divisionType_ == DivWIDTH) {
0033     compNDiv_ = calculateNDiv(msol.rOutMinusZ() - msol.rInMinusZ(), div_.width(), div_.offset());
0034   } else if (divisionType_ == DivNDIV) {
0035     DDCons msol = (DDCons)(div_.parent().solid());
0036     compWidth_ = calculateWidth(msol.rOutMinusZ() - msol.rInMinusZ(), div_.nReplicas(), div_.offset());
0037   }
0038 }
0039 
0040 double DDDividedConsRho::getMaxParameter(void) const {
0041   DDCons msol = (DDCons)(div_.parent().solid());
0042   return msol.rOutMinusZ() - msol.rInMinusZ();
0043 }
0044 
0045 DDRotation DDDividedConsRho::makeDDRotation(const int copyNo) const {
0046   DDRotation myddrot;  // sets to identity.
0047   return myddrot;
0048 }
0049 
0050 DDTranslation DDDividedConsRho::makeDDTranslation(const int copyNo) const {
0051   DDTranslation translation;
0052   return translation;
0053 }
0054 
0055 DDLogicalPart DDDividedConsRho::makeDDLogicalPart(const int copyNo) const {
0056   DDName solname(div_.parent().ddname().name() + "_DIVCHILD" + std::to_string(copyNo), div_.parent().ddname().ns());
0057   DDSolid ddcons(solname);
0058   DDMaterial usemat(div_.parent().material());
0059   DDCons msol = (DDCons)(div_.parent().solid());
0060 
0061   double pRMin1 = msol.rInMinusZ() + div_.offset() + compWidth_ * copyNo;
0062   double pRMax1 = msol.rInMinusZ() + div_.offset() + compWidth_ * (copyNo + 1);
0063 
0064   //width at Z Plus
0065   //- double compWidth_Plus =
0066   //   compWidth_ * ( msol.rOutPlusZ()/ msol.rInPlusZ())
0067   //-         / ( msol.rOutMinusZ() - msol.rInMinusZ());
0068   double compWidth_Plus = calculateWidth(msol.rOutPlusZ() - msol.rInPlusZ(), compNDiv_, div_.offset());
0069   double pRMin2 = msol.rInPlusZ() + div_.offset() + compWidth_Plus * copyNo;
0070   double pRMax2 = msol.rInPlusZ() + div_.offset() + compWidth_Plus * (copyNo + 1);
0071   double pDz = msol.zhalf();
0072 
0073   double pSPhi = msol.phiFrom();
0074   double pDPhi = msol.deltaPhi();
0075 
0076   ddcons = DDSolidFactory::cons(DDName(solname), pDz, pRMin1, pRMax1, pRMin2, pRMax2, pSPhi, pDPhi);
0077 
0078   DDLogicalPart ddlp = DDLogicalPart(solname, usemat, ddcons);
0079   return ddlp;
0080 }
0081 
0082 DDDividedConsPhi::DDDividedConsPhi(const DDDivision& div, DDCompactView* cpv)
0083     : DDDividedGeometryObject::DDDividedGeometryObject(div, cpv) {
0084   checkParametersValidity();
0085   setType("DivisionConsPhi");
0086   DDCons msol = (DDCons)(div_.parent().solid());
0087 
0088   if (divisionType_ == DivWIDTH) {
0089     DDCons msol = (DDCons)(div_.parent().solid());
0090     //If you divide a tube of 360 degrees the offset displaces the starting angle, but you still fill the 360 degrees
0091     if (msol.deltaPhi() == 360._deg) {
0092       compNDiv_ = calculateNDiv(msol.deltaPhi(), div_.width(), 0.);
0093     } else {
0094       compNDiv_ = calculateNDiv(msol.deltaPhi(), div_.width(), div_.offset());
0095     }
0096   } else if (divisionType_ == DivNDIV) {
0097     DDCons msol = (DDCons)(div_.parent().solid());
0098     if (msol.deltaPhi() == 360._deg) {
0099       compWidth_ = calculateWidth(msol.deltaPhi(), div_.nReplicas(), 0.);
0100     } else {
0101       compWidth_ = calculateWidth(msol.deltaPhi(), div_.nReplicas(), div_.offset());
0102     }
0103   }
0104 }
0105 
0106 double DDDividedConsPhi::getMaxParameter(void) const {
0107   DDCons msol = (DDCons)(div_.parent().solid());
0108   return msol.deltaPhi();
0109 }
0110 
0111 DDRotation DDDividedConsPhi::makeDDRotation(const int copyNo) const {
0112   DDRotation myddrot;  // sets to identity.
0113   double posi = (copyNo - 1) * compWidth_;
0114   // how to name the rotation??
0115   // i hate this crap :-)
0116   DDName ddrotname(div_.parent().ddname().name() + "_DIVCHILD_ROT" + std::to_string(copyNo),
0117                    div_.parent().ddname().ns());
0118   myddrot = DDrot(ddrotname, changeRotMatrix(posi));
0119 
0120   return myddrot;
0121 }
0122 
0123 DDTranslation DDDividedConsPhi::makeDDTranslation(const int copyNo) const {
0124   DDTranslation translation;
0125   return translation;
0126 }
0127 
0128 DDLogicalPart DDDividedConsPhi::makeDDLogicalPart(const int copyNo) const {
0129   DDName solname(div_.parent().ddname().name() + "_DIVCHILD", div_.parent().ddname().ns());
0130   DDSolid ddcons(solname);
0131   DDMaterial usemat(div_.parent().material());
0132   DDCons msol = (DDCons)(div_.parent().solid());
0133 
0134   if (!ddcons.isDefined().second) {
0135     double pRMin1 = msol.rInMinusZ();
0136     double pRMax1 = msol.rOutMinusZ();
0137     double pRMin2 = msol.rInPlusZ();
0138     double pRMax2 = msol.rOutPlusZ();
0139     double pDz = msol.zhalf();
0140 
0141     //- already rotated  double pSPhi = div_.offset() + copyNo*compWidth_;
0142     double pSPhi = div_.offset() + msol.phiFrom();
0143     double pDPhi = compWidth_;
0144     ddcons = DDSolidFactory::cons(DDName(solname), pDz, pRMin1, pRMax1, pRMin2, pRMax2, pSPhi, pDPhi);
0145   }
0146 
0147   DDLogicalPart ddlp = DDLogicalPart(solname, usemat, ddcons);
0148 
0149   return ddlp;
0150 }
0151 
0152 DDDividedConsZ::DDDividedConsZ(const DDDivision& div, DDCompactView* cpv)
0153     : DDDividedGeometryObject::DDDividedGeometryObject(div, cpv) {
0154   checkParametersValidity();
0155 
0156   DDCons msol = (DDCons)(div_.parent().solid());
0157   setType("DivisionConsZ");
0158 
0159   if (divisionType_ == DivWIDTH) {
0160     DDCons msol = (DDCons)(div_.parent().solid());
0161     compNDiv_ = calculateNDiv(2 * msol.zhalf(), div_.width(), div_.offset());
0162   } else if (divisionType_ == DivNDIV) {
0163     DDCons msol = (DDCons)(div_.parent().solid());
0164     compWidth_ = calculateWidth(2 * msol.zhalf(), div_.nReplicas(), div_.offset());
0165   }
0166 }
0167 
0168 double DDDividedConsZ::getMaxParameter(void) const {
0169   DDCons msol = (DDCons)(div_.parent().solid());
0170   return 2 * msol.zhalf();
0171 }
0172 
0173 DDRotation DDDividedConsZ::makeDDRotation(const int copyNo) const {
0174   DDRotation myddrot;  // sets to identity.
0175   return myddrot;
0176 }
0177 
0178 DDTranslation DDDividedConsZ::makeDDTranslation(const int copyNo) const {
0179   DDTranslation translation;
0180 
0181   DDCons motherCons = (DDCons)(div_.parent().solid());
0182   double posi = -motherCons.zhalf() + div_.offset() + compWidth_ / 2 + copyNo * compWidth_;
0183   translation.SetZ(posi);
0184 
0185   return translation;
0186 }
0187 
0188 DDLogicalPart DDDividedConsZ::makeDDLogicalPart(const int copyNo) const {
0189   DDName solname(div_.parent().ddname().name() + "_DIVCHILD" + std::to_string(copyNo), div_.parent().ddname().ns());
0190   DDSolid ddcons(solname);
0191   DDMaterial usemat(div_.parent().material());
0192   DDCons msol = (DDCons)(div_.parent().solid());
0193 
0194   double mHalfLength = msol.zhalf();
0195   double aRInner = (msol.rInPlusZ() - msol.rInMinusZ()) / (2 * mHalfLength);
0196   double bRInner = (msol.rInPlusZ() + msol.rInMinusZ()) / 2;
0197   double aROuter = (msol.rOutPlusZ() - msol.rOutMinusZ()) / (2 * mHalfLength);
0198   double bROuter = (msol.rOutPlusZ() + msol.rOutMinusZ()) / 2;
0199   double xMinusZ = -mHalfLength + div_.offset() + compWidth_ * copyNo;
0200   double xPlusZ = -mHalfLength + div_.offset() + compWidth_ * (copyNo + 1);
0201 
0202   double pDz = compWidth_ / 2.;
0203   double pSPhi = msol.phiFrom();
0204   double pDPhi = msol.deltaPhi();
0205 
0206   ddcons = DDSolidFactory::cons(DDName(solname),
0207                                 pDz,
0208                                 aRInner * xMinusZ + bRInner,
0209                                 aROuter * xMinusZ + bROuter,
0210                                 aRInner * xPlusZ + bRInner,
0211                                 aROuter * xPlusZ + bROuter,
0212                                 pSPhi,
0213                                 pDPhi);
0214 
0215   DDLogicalPart ddlp = DDLogicalPart(solname, usemat, ddcons);
0216 
0217   return ddlp;
0218 }