File indexing completed on 2024-05-10 02:21:04
0001
0002
0003
0004
0005
0006
0007 #include "volumeHandle.h"
0008 #include "DetectorDescription/Core/interface/DDExpandedView.h"
0009 #include "DetectorDescription/Core/interface/DDTranslation.h"
0010 #include "DetectorDescription/Core/interface/DDSolid.h"
0011 #include "DetectorDescription/Core/interface/DDValue.h"
0012 #include "DetectorDescription/Core/interface/DDMaterial.h"
0013
0014 #include "DataFormats/GeometrySurface/interface/Plane.h"
0015 #include "DataFormats/GeometrySurface/interface/Cylinder.h"
0016 #include "DataFormats/GeometrySurface/interface/Cone.h"
0017 #include "DataFormats/GeometryVector/interface/CoordinateSets.h"
0018
0019 #include <CLHEP/Units/SystemOfUnits.h>
0020
0021 #include <string>
0022 #include <iterator>
0023 #include <iomanip>
0024 #include <iostream>
0025
0026 using namespace SurfaceOrientation;
0027 using namespace std;
0028
0029 #include "DataFormats/Math/interface/GeantUnits.h"
0030
0031 namespace {
0032
0033 template <class NumType>
0034 inline constexpr NumType convertUnits(NumType millimeters)
0035 {
0036 return (geant_units::operators::convertMmToCm(millimeters));
0037 }
0038 }
0039
0040 MagGeoBuilderFromDDD::volumeHandle::volumeHandle(const DDExpandedView &fv, bool expand2Pi, bool debugVal)
0041 : magneticfield::BaseVolumeHandle(expand2Pi, debugVal) {
0042 name = fv.logicalPart().name().name();
0043 copyno = fv.copyno();
0044 solid = fv.logicalPart().solid();
0045 center_ =
0046 GlobalPoint(fv.translation().x() / CLHEP::cm, fv.translation().y() / CLHEP::cm, fv.translation().z() / CLHEP::cm);
0047
0048
0049 string volName = name;
0050 volName.erase(0, volName.rfind('_') + 1);
0051 volumeno = std::stoul(volName);
0052
0053 for (int i = 0; i < 6; ++i) {
0054 isAssigned[i] = false;
0055 }
0056
0057 if (debug) {
0058 cout.precision(7);
0059 }
0060
0061 referencePlane(fv);
0062
0063 if (solid.shape() == DDSolidShape::ddbox) {
0064 DDBox box(solid);
0065 double halfX = convertUnits(box.halfX());
0066 double halfY = convertUnits(box.halfY());
0067 double halfZ = convertUnits(box.halfZ());
0068 buildBox(halfX, halfY, halfZ);
0069 } else if (solid.shape() == DDSolidShape::ddtrap) {
0070 DDTrap trap(solid);
0071 double x1 = convertUnits(trap.x1());
0072 double x2 = convertUnits(trap.x2());
0073 double x3 = convertUnits(trap.x3());
0074 double x4 = convertUnits(trap.x4());
0075 double y1 = convertUnits(trap.y1());
0076 double y2 = convertUnits(trap.y2());
0077 double theta = trap.theta();
0078 double phi = trap.phi();
0079 double halfZ = convertUnits(trap.halfZ());
0080 double alpha1 = trap.alpha1();
0081 double alpha2 = trap.alpha2();
0082 buildTrap(x1, x2, x3, x4, y1, y2, theta, phi, halfZ, alpha1, alpha2);
0083 } else if (solid.shape() == DDSolidShape::ddcons) {
0084 DDCons cons(solid);
0085 double zhalf = convertUnits(cons.zhalf());
0086 double rInMinusZ = convertUnits(cons.rInMinusZ());
0087 double rOutMinusZ = convertUnits(cons.rOutMinusZ());
0088 double rInPlusZ = convertUnits(cons.rInPlusZ());
0089 double rOutPlusZ = convertUnits(cons.rOutPlusZ());
0090 double startPhi = cons.phiFrom();
0091 double deltaPhi = cons.deltaPhi();
0092 buildCons(zhalf, rInMinusZ, rOutMinusZ, rInPlusZ, rOutPlusZ, startPhi, deltaPhi);
0093 } else if (solid.shape() == DDSolidShape::ddtubs) {
0094 DDTubs tubs(solid);
0095 double zhalf = convertUnits(tubs.zhalf());
0096 double rIn = convertUnits(tubs.rIn());
0097 double rOut = convertUnits(tubs.rOut());
0098 double startPhi = tubs.startPhi();
0099 double deltaPhi = tubs.deltaPhi();
0100 buildTubs(zhalf, rIn, rOut, startPhi, deltaPhi);
0101 } else if (solid.shape() == DDSolidShape::ddpseudotrap) {
0102 DDPseudoTrap ptrap(solid);
0103 double x1 = convertUnits(ptrap.x1());
0104 double x2 = convertUnits(ptrap.x2());
0105 double y1 = convertUnits(ptrap.y1());
0106 double y2 = convertUnits(ptrap.y2());
0107 double halfZ = convertUnits(ptrap.halfZ());
0108 double radius = convertUnits(ptrap.radius());
0109 bool atMinusZ = ptrap.atMinusZ();
0110 buildPseudoTrap(x1, x2, y1, y2, halfZ, radius, atMinusZ);
0111 } else if (solid.shape() == DDSolidShape::ddtrunctubs) {
0112 DDTruncTubs tubs(solid);
0113 double zhalf = convertUnits(tubs.zHalf());
0114 double rIn = convertUnits(tubs.rIn());
0115 double rOut = convertUnits(tubs.rOut());
0116 double startPhi = tubs.startPhi();
0117 double deltaPhi = tubs.deltaPhi();
0118 double cutAtStart = convertUnits(tubs.cutAtStart());
0119 double cutAtDelta = convertUnits(tubs.cutAtDelta());
0120 bool cutInside = tubs.cutInside();
0121 buildTruncTubs(zhalf, rIn, rOut, startPhi, deltaPhi, cutAtStart, cutAtDelta, cutInside);
0122 } else {
0123 cout << "volumeHandle ctor: Unexpected solid: " << DDSolidShapesName::name(solid.shape()) << endl;
0124 }
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178 if (fv.logicalPart().material().name().name() == "Iron")
0179 isIronFlag = true;
0180
0181 if (debug) {
0182 cout << " RMin = " << theRMin << endl;
0183 cout << " RMax = " << theRMax << endl;
0184
0185 if (theRMin < 0 || theRN < theRMin || theRMax < theRN)
0186 cout << "*** WARNING: wrong RMin/RN/RMax , shape: " << DDSolidShapesName::name(shape()) << endl;
0187
0188 cout << "Summary: " << name << " " << copyno << " Shape= " << DDSolidShapesName::name(shape()) << " trasl "
0189 << center() << " R " << center().perp() << " phi " << center().phi() << " magFile " << magFile
0190 << " Material= " << fv.logicalPart().material().name() << " isIron= " << isIronFlag
0191 << " masterSector= " << masterSector << std::endl;
0192
0193 cout << " Orientation of surfaces:";
0194 std::string sideName[3] = {"positiveSide", "negativeSide", "onSurface"};
0195 for (int i = 0; i < 6; ++i) {
0196 cout << " " << i << ":" << sideName[surfaces[i]->side(center_, 0.3)];
0197 }
0198 cout << endl;
0199 }
0200 }
0201
0202 void MagGeoBuilderFromDDD::volumeHandle::referencePlane(const DDExpandedView &fv) {
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232 Surface::PositionType &posResult = center_;
0233
0234
0235 DD3Vector x, y, z;
0236 fv.rotation().GetComponents(x, y, z);
0237 if (debug) {
0238 if (x.Cross(y).Dot(z) < 0.5) {
0239 cout << "*** WARNING: Rotation is not RH " << endl;
0240 }
0241 }
0242
0243
0244 Surface::RotationType rotResult(float(x.X()),
0245 float(x.Y()),
0246 float(x.Z()),
0247 float(y.X()),
0248 float(y.Y()),
0249 float(y.Z()),
0250 float(z.X()),
0251 float(z.Y()),
0252 float(z.Z()));
0253
0254 refPlane = new GloballyPositioned<float>(posResult, rotResult);
0255
0256
0257 if (debug) {
0258 cout << "Refplane pos " << refPlane->position() << endl;
0259
0260
0261 LocalVector globalZdir(0., 0., 1.);
0262 if (solid.shape() == DDSolidShape::ddpseudotrap) {
0263 globalZdir = LocalVector(0., 1., 0.);
0264 }
0265 if (refPlane->toGlobal(globalZdir).z() < 0.) {
0266 globalZdir = -globalZdir;
0267 }
0268
0269 float chk = refPlane->toGlobal(globalZdir).dot(GlobalVector(0, 0, 1));
0270 if (chk < .999)
0271 cout << "*** WARNING RefPlane check failed!***" << chk << endl;
0272 }
0273 }
0274
0275 std::vector<VolumeSide> MagGeoBuilderFromDDD::volumeHandle::sides() const {
0276 std::vector<VolumeSide> result;
0277 for (int i = 0; i < 6; ++i) {
0278
0279
0280 if (expand && (i == phiplus || i == phiminus))
0281 continue;
0282
0283
0284 if (solid.shape() == DDSolidShape::ddtubs && i == SurfaceOrientation::inner && theRMin < 0.001)
0285 continue;
0286
0287 ReferenceCountingPointer<Surface> s = const_cast<Surface *>(surfaces[i].get());
0288 result.push_back(VolumeSide(s, GlobalFace(i), surfaces[i]->side(center_, 0.3)));
0289 }
0290 return result;
0291 }
0292
0293 using volumeHandle = MagGeoBuilderFromDDD::volumeHandle;
0294 using namespace magneticfield;
0295
0296 #include "buildBox.icc"
0297 #include "buildTrap.icc"
0298 #include "buildTubs.icc"
0299 #include "buildCons.icc"
0300 #include "buildPseudoTrap.icc"
0301 #include "buildTruncTubs.icc"