Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DetectorDescription/Parser/src/DDDividedGeometryObject.h"
0002 #include "DetectorDescription/Core/interface/DDCompactView.h"
0003 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0004 #include "DetectorDescription/Core/interface/DDName.h"
0005 #include "DetectorDescription/Core/interface/DDTransform.h"
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include "FWCore/Utilities/interface/Exception.h"
0008 #include "Math/GenVector/RotationZ.h"
0009 
0010 #include <iostream>
0011 #include <utility>
0012 
0013 DDDividedGeometryObject::DDDividedGeometryObject(const DDDivision& div, DDCompactView* cpv)
0014     : div_(div),
0015       ftype_(),
0016       compNDiv_(div.nReplicas()),
0017       compWidth_(div.width()),
0018       divisionType_(DivNDIVandWIDTH),
0019       theVoluFirstCopyNo_(1),
0020       cpv_(cpv) {
0021   if (div_.nReplicas() == 0 || div_.width() < tolerance()) {
0022     if (div_.width() < tolerance())
0023       divisionType_ = DivNDIV;
0024     else
0025       divisionType_ = DivWIDTH;
0026   }
0027 }
0028 
0029 std::unique_ptr<DDRotationMatrix> DDDividedGeometryObject::changeRotMatrix(double rotZ) const {
0030   return std::make_unique<DDRotationMatrix>(ROOT::Math::RotationZ(rotZ));
0031 }
0032 
0033 int DDDividedGeometryObject::calculateNDiv(double motherDim, double width, double offset) const {
0034   return int((motherDim - offset) / width);
0035 }
0036 
0037 double DDDividedGeometryObject::calculateWidth(double motherDim, int nDiv, double offset) const {
0038   return (motherDim - offset) / nDiv;
0039 }
0040 
0041 void DDDividedGeometryObject::checkParametersValidity(void) {
0042   double maxPar = getMaxParameter();
0043   checkOffset(maxPar);
0044   checkNDivAndWidth(maxPar);
0045   if (!div_.parent().isDefined().second) {
0046     std::string s = "DDDividedGeometryObject::checkParametersValidity() :";
0047     s += "\n ERROR - the LogicalPart of the parent must be ";
0048     s += "\n         defined before a division can occur.";
0049     s += "\n         Parent= " + div_.parent().toString();
0050     throw cms::Exception("DDException") << s;
0051   }
0052 }
0053 
0054 void DDDividedGeometryObject::checkOffset(double maxPar) {
0055   if (div_.offset() >= maxPar) {
0056     std::string s = "DDDividedGeometryObject::checkOffset() IllegalConstruct";
0057     s += "\nERROR - DDDividedGeometryObject::checkOffset()";
0058     s += "\n        failed.";
0059     s += "  Too big an offset.";
0060     throw cms::Exception("DDException") << s;
0061   }
0062 }
0063 
0064 void DDDividedGeometryObject::checkNDivAndWidth(double maxPar) {
0065   if ((divisionType_ == DivNDIVandWIDTH) && (div_.offset() + compWidth_ * compNDiv_ - maxPar > tolerance())) {
0066     std::string s = "ERROR - DDDividedGeometryObject::checkNDivAndWidth()";
0067     s += "\n        Division of LogicalPart " + div_.parent().name().name();
0068     s += " has too big an offset.";
0069 
0070     std::cout << compWidth_ << std::endl;
0071     throw cms::Exception("DDException") << s;
0072   }
0073 }
0074 
0075 const double DDDividedGeometryObject::tolerance(void) {
0076   // this can come from some global tolerance if you want.
0077   static const double tol = 1.0 / 1000.00;
0078   return tol;
0079 }
0080 
0081 void DDDividedGeometryObject::setType(const std::string& s) { ftype_ = s; }
0082 
0083 const std::string& DDDividedGeometryObject::getType(void) const { return ftype_; }
0084 
0085 void DDDividedGeometryObject::execute(void) {
0086   for (int i = theVoluFirstCopyNo_; i < compNDiv_ + theVoluFirstCopyNo_; ++i) {
0087     cpv_->position(makeDDLogicalPart(i), div_.parent(), i, makeDDTranslation(i), makeDDRotation(i), &div_);
0088   }
0089 }
0090 
0091 double DDDividedGeometryObject::getMaxParameter(void) const { return 0.0; }
0092 
0093 DDRotation DDDividedGeometryObject::makeDDRotation(const int copyNo) const { return DDRotation(); }
0094 
0095 DDTranslation DDDividedGeometryObject::makeDDTranslation(const int copyNo) const { return DDTranslation(); }
0096 
0097 DDLogicalPart DDDividedGeometryObject::makeDDLogicalPart(const int copyNo) const {
0098   // just return the parent... this is USELESS
0099   return div_.parent();
0100 }