Skip to content

Commit

Permalink
Merge pull request #31649 from namapane/DD4hep_MFBuilder_Shapes
Browse files Browse the repository at this point in the history
Remove dependency from DDCMS/interface/DDShapes.h
  • Loading branch information
cmsbuild committed Oct 6, 2020
2 parents 13187ed + 0851263 commit d2bf361
Show file tree
Hide file tree
Showing 10 changed files with 212 additions and 136 deletions.
95 changes: 63 additions & 32 deletions MagneticField/GeomBuilder/src/DD4hep_volumeHandle.cc
Expand Up @@ -14,8 +14,6 @@
#include "DataFormats/Math/interface/Vector3D.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include "DetectorDescription/DDCMS/interface/DDShapes.h"

#include <string>
#include <iterator>

Expand All @@ -24,8 +22,14 @@ using namespace std;
using namespace magneticfield;
using namespace edm;

using DDBox = dd4hep::Box;
using DDTrap = dd4hep::Trap;
using DDTubs = dd4hep::Tube;
using DDCons = dd4hep::ConeSegment;
using DDTruncTubs = dd4hep::TruncatedTube;

volumeHandle::volumeHandle(const cms::DDFilteredView &fv, bool expand2Pi, bool debugVal)
: BaseVolumeHandle(expand2Pi, debugVal), theShape(fv.legacyShape(cms::dd::getCurrentShape(fv))), solid(fv) {
: BaseVolumeHandle(expand2Pi, debugVal), theShape(fv.legacyShape(fv.shape())), solid(fv) {
name = fv.name();
copyno = fv.copyNum();
const auto *const transArray = fv.trans();
Expand All @@ -41,25 +45,66 @@ volumeHandle::volumeHandle(const cms::DDFilteredView &fv, bool expand2Pi, bool d
}
referencePlane(fv);
switch (theShape) {
case DDSolidShape::ddbox:
buildBox();
break;
case DDSolidShape::ddtrap:
buildTrap();
break;
case DDSolidShape::ddcons:
buildCons();
break;
case DDSolidShape::ddtubs:
buildTubs();
break;
case DDSolidShape::ddbox: {
DDBox box(solid.solid());
// DD4hep returns units in cm, no conversion needed.
double halfX = box.x();
double halfY = box.y();
double halfZ = box.z();
buildBox(halfX, halfY, halfZ);
} break;
case DDSolidShape::ddtrap: {
DDTrap trap(solid.solid());
double x1 = trap.bottomLow1();
double x2 = trap.topLow1();
double x3 = trap.bottomLow2();
double x4 = trap.topLow2();
double y1 = trap.high1();
double y2 = trap.high2();
double theta = trap.theta();
double phi = trap.phi();
double halfZ = trap.dZ();
double alpha1 = trap.alpha1();
double alpha2 = trap.alpha2();
buildTrap(x1, x2, x3, x4, y1, y2, theta, phi, halfZ, alpha1, alpha2);
} break;

case DDSolidShape::ddcons: {
DDCons cons(solid.solid());
double zhalf = cons.dZ();
double rInMinusZ = cons.rMin1();
double rOutMinusZ = cons.rMax1();
double rInPlusZ = cons.rMin2();
double rOutPlusZ = cons.rMax2();
double startPhi = cons.startPhi();
double deltaPhi = reco::deltaPhi(cons.endPhi(), startPhi);
buildCons(zhalf, rInMinusZ, rOutMinusZ, rInPlusZ, rOutPlusZ, startPhi, deltaPhi);
} break;
case DDSolidShape::ddtubs: {
DDTubs tubs(solid.solid());
double zhalf = tubs.dZ();
double rIn = tubs.rMin();
double rOut = tubs.rMax();
double startPhi = tubs.startPhi();
double deltaPhi = tubs.endPhi() - startPhi;
buildTubs(zhalf, rIn, rOut, startPhi, deltaPhi);
} break;
case DDSolidShape::ddpseudotrap: {
vector<double> d = solid.volume().volume().solid().dimensions();
buildPseudoTrap(d[0], d[1], d[2], d[3], d[4], d[5], d[6]);
} break;
case DDSolidShape::ddtrunctubs:
buildTruncTubs();
break;
case DDSolidShape::ddtrunctubs: {
DDTruncTubs tubs(solid.solid());
double zhalf = tubs.dZ(); // half of the z-Axis
double rIn = tubs.rMin(); // inner radius
double rOut = tubs.rMax(); // outer radius
double startPhi = tubs.startPhi(); // angular start of the tube-section
double deltaPhi = tubs.deltaPhi(); // angular span of the tube-section
double cutAtStart = tubs.cutAtStart(); // truncation at begin of the tube-section
double cutAtDelta = tubs.cutAtDelta(); // truncation at end of the tube-section
bool cutInside = tubs.cutInside(); // true, if truncation is on the inner side of the tube-section
buildTruncTubs(zhalf, rIn, rOut, startPhi, deltaPhi, cutAtStart, cutAtDelta, cutInside);
} break;
default:
LogError("magneticfield::volumeHandle")
<< "ctor: Unexpected shape # " << static_cast<int>(theShape) << " for vol " << name;
Expand Down Expand Up @@ -183,20 +228,6 @@ std::vector<VolumeSide> volumeHandle::sides() const {
return result;
}

// The files included below are used here and in the old DD version of this file.
// To allow them to be used in both places, they call a "convertUnits" function
// that is defined differently between old and new DD.
// For the old DD, another version of this function converts mm to cm.

namespace {
template <class NumType>
inline constexpr NumType convertUnits(NumType centimeters) {
return (centimeters);
}
} // namespace

using namespace cms::dd;

#include "buildBox.icc"
#include "buildTrap.icc"
#include "buildTubs.icc"
Expand Down
33 changes: 28 additions & 5 deletions MagneticField/GeomBuilder/src/DD4hep_volumeHandle.h
Expand Up @@ -40,18 +40,41 @@ namespace magneticfield {
void referencePlane(const cms::DDFilteredView& fv);

// Build the surfaces for a box
void buildBox();
void buildBox(double halfX, double halfY, double halfZ);
// Build the surfaces for a trapezoid
void buildTrap();
void buildTrap(double x1,
double x2,
double x3,
double x4,
double y1,
double y2,
double theta,
double phi,
double halfZ,
double alpha1,
double alpha2);
// Build the surfaces for a ddtubs shape
void buildTubs();
void buildTubs(double zhalf, double rIn, double rOut, double startPhi, double deltaPhi);
// Build the surfaces for a ddcons shape
void buildCons();
void buildCons(double zhalf,
double rInMinusZ,
double rOutMinusZ,
double rInPlusZ,
double rOutPlusZ,
double startPhi,
double deltaPhi);
// Build the surfaces for a ddpseudotrap. This is not a supported
// shape in DD4hep; it is handled here to cope with legacy geometries.
void buildPseudoTrap(double x1, double x2, double y1, double y2, double halfZ, double radius, bool atMinusZ);
// Build the surfaces for a ddtrunctubs shape
void buildTruncTubs();
void buildTruncTubs(double zhalf,
double rIn,
double rOut,
double startPhi,
double deltaPhi,
double cutAtStart,
double cutAtDelta,
bool cutInside);

// Shape at initialization
const DDSolidShape theShape;
Expand Down
9 changes: 1 addition & 8 deletions MagneticField/GeomBuilder/src/buildBox.icc
Expand Up @@ -4,16 +4,9 @@
* \author N. Amapane - INFN Torino
*/

void volumeHandle::buildBox() {
void volumeHandle::buildBox(double halfX, double halfY, double halfZ) {
LogTrace("MagGeoBuilder") << "Building box surfaces...: ";

DDBox box(solid);
// Old DD needs mm to cm conversion, but DD4hep needs no conversion.
// convertUnits should be defined appropriately.
double halfX = convertUnits(box.halfX());
double halfY = convertUnits(box.halfY());
double halfZ = convertUnits(box.halfZ());

// Global vectors of the normals to X, Y, Z axes
GlobalVector planeXAxis = refPlane->toGlobal(LocalVector(1, 0, 0));
GlobalVector planeYAxis = refPlane->toGlobal(LocalVector(0, 1, 0));
Expand Down
21 changes: 7 additions & 14 deletions MagneticField/GeomBuilder/src/buildCons.icc
Expand Up @@ -6,21 +6,14 @@

#include "DataFormats/GeometrySurface/interface/SimpleConeBounds.h"

void volumeHandle::buildCons() {
void volumeHandle::buildCons(double zhalf,
double rInMinusZ,
double rOutMinusZ,
double rInPlusZ,
double rOutPlusZ,
double startPhi,
double deltaPhi) {
LogTrace("MagGeoBuilder") << "Building cons surfaces...: ";

DDCons cons(solid);

// Old DD needs mm to cm conversion, but DD4hep needs no conversion.
// convertUnits should be defined appropriately.
double zhalf = convertUnits(cons.zhalf());
double rInMinusZ = convertUnits(cons.rInMinusZ());
double rOutMinusZ = convertUnits(cons.rOutMinusZ());
double rInPlusZ = convertUnits(cons.rInPlusZ());
double rOutPlusZ = convertUnits(cons.rOutPlusZ());
double startPhi = cons.phiFrom();
double deltaPhi = cons.deltaPhi();

LogTrace("MagGeoBuilder") << "zhalf " << zhalf << newln << "rInMinusZ " << rInMinusZ << newln << "rOutMinusZ "
<< rOutMinusZ << newln << "rInPlusZ " << rInPlusZ << newln << "rOutPlusZ " << rOutPlusZ
<< newln << "phiFrom " << startPhi << newln << "deltaPhi " << deltaPhi;
Expand Down
12 changes: 2 additions & 10 deletions MagneticField/GeomBuilder/src/buildPseudoTrap.icc
Expand Up @@ -13,16 +13,8 @@
*/

void volumeHandle::buildPseudoTrap(
double x1_, double x2_, double y1_, double y2_, double halfZ_, double radius_, bool atMinusZ) {
// Old DD needs mm to cm conversion, but DD4hep needs no conversion.
// convertUnits should be defined appropriately.
double halfZ = convertUnits(halfZ_);
double x1 = convertUnits(x1_);
double x2 = convertUnits(x2_);
double y1 = convertUnits(y1_);
double y2 = convertUnits(y2_);
double radius = convertUnits(radius_);

double x1, double x2, double y1, double y2, double halfZ, double radius, bool atMinusZ) {
LogTrace("MagGeoBuilder") << "Building PseudoTrap surfaces...: ";
LogTrace("MagGeoBuilder") << "halfZ " << halfZ << newln << "x1 " << x1 << newln << "x2 " << x2
<< newln << "y1 " << y1 << newln << "y2 " << y2 << newln << "radius "
<< radius << newln << "atMinusZ " << atMinusZ;
Expand Down
29 changes: 11 additions & 18 deletions MagneticField/GeomBuilder/src/buildTrap.icc
Expand Up @@ -4,25 +4,18 @@
* \author N. Amapane - INFN Torino
*/

void volumeHandle::buildTrap() {
void volumeHandle::buildTrap(double x1,
double x2,
double x3,
double x4,
double y1,
double y2,
double theta,
double phi,
double halfZ,
double alpha1,
double alpha2) {
LogTrace("MagGeoBuilder") << "Building trapezoid surfaces...: ";

DDTrap trap(solid); //FIXME

// Old DD needs mm to cm conversion, but DD4hep needs no conversion.
// convertUnits should be defined appropriately.
double x1 = convertUnits(trap.x1());
double x2 = convertUnits(trap.x2());
double x3 = convertUnits(trap.x3());
double x4 = convertUnits(trap.x4());
double y1 = convertUnits(trap.y1());
double y2 = convertUnits(trap.y2());
double theta = trap.theta();
double phi = trap.phi();
double halfZ = convertUnits(trap.halfZ());
double alpha1 = trap.alpha1();
double alpha2 = trap.alpha2();

LogTrace("MagGeoBuilder") << "x1 " << x1 << newln << "x2 " << x2 << newln << "x3 " << x3 << newln << "x4 " << x4
<< newln << "y1 " << y1 << newln << "y2 " << y2 << newln << "theta " << theta << newln
<< "phi " << phi << newln << "halfZ " << halfZ << newln << "alpha1 " << alpha1 << newln
Expand Down
23 changes: 8 additions & 15 deletions MagneticField/GeomBuilder/src/buildTruncTubs.icc
Expand Up @@ -9,22 +9,15 @@
* \author N. Amapane - INFN Torino
*/

void volumeHandle::buildTruncTubs() {
void volumeHandle::buildTruncTubs(double zhalf,
double rIn,
double rOut,
double startPhi,
double deltaPhi,
double cutAtStart,
double cutAtDelta,
bool cutInside) {
LogTrace("MagGeoBuilder") << "Building TruncTubs surfaces...: ";

DDTruncTubs tubs(solid);

// Old DD needs mm to cm conversion, but DD4hep needs no conversion.
// convertUnits should be defined appropriately.
double zhalf = convertUnits(tubs.zHalf()); // half of the z-Axis
double rIn = convertUnits(tubs.rIn()); // inner radius
double rOut = convertUnits(tubs.rOut()); // outer radius
double startPhi = tubs.startPhi(); // angular start of the tube-section
double deltaPhi = tubs.deltaPhi(); // angular span of the tube-section
double cutAtStart = convertUnits(tubs.cutAtStart()); // truncation at begin of the tube-section
double cutAtDelta = convertUnits(tubs.cutAtDelta()); // truncation at end of the tube-section
bool cutInside = tubs.cutInside(); // true, if truncation is on the inner side of the tube-section

LogTrace("MagGeoBuilder") << "zhalf " << zhalf << newln << "rIn " << rIn << newln << "rOut " << rOut
<< newln << "startPhi " << startPhi << newln << "deltaPhi " << deltaPhi << newln
<< "cutAtStart " << cutAtStart << newln << "cutAtDelta " << cutAtDelta << newln
Expand Down
13 changes: 1 addition & 12 deletions MagneticField/GeomBuilder/src/buildTubs.icc
@@ -1,16 +1,5 @@
void volumeHandle::buildTubs() {
void volumeHandle::buildTubs(double zhalf, double rIn, double rOut, double startPhi, double deltaPhi) {
LogTrace("MagGeoBuilder") << "Building tubs surfaces...: ";

DDTubs tubs(solid);

// Old DD needs mm to cm conversion, but DD4hep needs no conversion.
// convertUnits should be defined appropriately.
double zhalf = convertUnits(tubs.zhalf());
double rIn = convertUnits(tubs.rIn());
double rOut = convertUnits(tubs.rOut());
double startPhi = tubs.startPhi();
double deltaPhi = tubs.deltaPhi();

LogTrace("MagGeoBuilder") << "zhalf " << zhalf << newln << "rIn " << rIn << newln << "rOut " << rOut
<< newln << "startPhi " << startPhi << newln << "deltaPhi " << deltaPhi;

Expand Down

0 comments on commit d2bf361

Please sign in to comment.