CMS 3D CMS Logo

DD4hep_volumeHandle.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * \author N. Amapane - INFN Torino (original developer)
5  */
6 
7 #include "DD4hep_volumeHandle.h"
8 
16 
17 #include <string>
18 #include <iterator>
19 
20 using namespace SurfaceOrientation;
21 using namespace std;
22 using namespace magneticfield;
23 using namespace edm;
24 
25 using DDBox = dd4hep::Box;
26 using DDTrap = dd4hep::Trap;
27 using DDTubs = dd4hep::Tube;
28 using DDCons = dd4hep::ConeSegment;
29 using DDTruncTubs = dd4hep::TruncatedTube;
30 
31 volumeHandle::volumeHandle(const cms::DDFilteredView &fv, bool expand2Pi, bool debugVal)
32  : BaseVolumeHandle(expand2Pi, debugVal), theShape(fv.legacyShape(fv.shape())), solid(fv) {
33  name = fv.name();
34  copyno = fv.copyNum();
35  const auto *const transArray = fv.trans();
36  center_ = GlobalPoint(transArray[0], transArray[1], transArray[2]);
37 
38  // ASSUMPTION: volume names ends with "_NUM" where NUM is the volume number
39  string volName = name;
40  volName.erase(0, volName.rfind('_') + 1);
41  volumeno = static_cast<unsigned short>(std::atoi(volName.c_str()));
42 
43  for (int i = 0; i < 6; ++i) {
44  isAssigned[i] = false;
45  }
46  referencePlane(fv);
47  switch (theShape) {
48  case DDSolidShape::ddbox: {
49  DDBox box(solid.solid());
50  // DD4hep returns units in cm, no conversion needed.
51  double halfX = box.x();
52  double halfY = box.y();
53  double halfZ = box.z();
54  buildBox(halfX, halfY, halfZ);
55  } break;
56  case DDSolidShape::ddtrap: {
57  DDTrap trap(solid.solid());
58  double x1 = trap.bottomLow1();
59  double x2 = trap.topLow1();
60  double x3 = trap.bottomLow2();
61  double x4 = trap.topLow2();
62  double y1 = trap.high1();
63  double y2 = trap.high2();
64  double theta = trap.theta();
65  double phi = trap.phi();
66  double halfZ = trap.dZ();
67  double alpha1 = trap.alpha1();
68  double alpha2 = trap.alpha2();
69  buildTrap(x1, x2, x3, x4, y1, y2, theta, phi, halfZ, alpha1, alpha2);
70  } break;
71 
72  case DDSolidShape::ddcons: {
73  DDCons cons(solid.solid());
74  double zhalf = cons.dZ();
75  double rInMinusZ = cons.rMin1();
76  double rOutMinusZ = cons.rMax1();
77  double rInPlusZ = cons.rMin2();
78  double rOutPlusZ = cons.rMax2();
79  double startPhi = cons.startPhi();
80  double deltaPhi = reco::deltaPhi(cons.endPhi(), startPhi);
81  buildCons(zhalf, rInMinusZ, rOutMinusZ, rInPlusZ, rOutPlusZ, startPhi, deltaPhi);
82  } break;
83  case DDSolidShape::ddtubs: {
84  DDTubs tubs(solid.solid());
85  double zhalf = tubs.dZ();
86  double rIn = tubs.rMin();
87  double rOut = tubs.rMax();
88  double startPhi = tubs.startPhi();
89  double deltaPhi = tubs.endPhi() - startPhi;
90  buildTubs(zhalf, rIn, rOut, startPhi, deltaPhi);
91  } break;
93  vector<double> d = solid.parameters();
94  buildPseudoTrap(d[0], d[1], d[2], d[3], d[4], d[5], d[6]);
95  } break;
97  DDTruncTubs tubs(solid.solid());
98  double zhalf = tubs.dZ(); // half of the z-Axis
99  double rIn = tubs.rMin(); // inner radius
100  double rOut = tubs.rMax(); // outer radius
101  double startPhi = tubs.startPhi(); // angular start of the tube-section
102  double deltaPhi = tubs.deltaPhi(); // angular span of the tube-section
103  double cutAtStart = tubs.cutAtStart(); // truncation at begin of the tube-section
104  double cutAtDelta = tubs.cutAtDelta(); // truncation at end of the tube-section
105  bool cutInside = tubs.cutInside(); // true, if truncation is on the inner side of the tube-section
106  buildTruncTubs(zhalf, rIn, rOut, startPhi, deltaPhi, cutAtStart, cutAtDelta, cutInside);
107  } break;
108  default:
109  LogError("magneticfield::volumeHandle")
110  << "ctor: Unexpected shape # " << static_cast<int>(theShape) << " for vol " << name;
111  }
112 
113  // Get material for this volume
114  if (fv.materialName() == "Iron")
115  isIronFlag = true;
116 
117  if (debug) {
118  LogTrace("MagGeoBuilder") << " RMin = " << theRMin << newln << " RMax = " << theRMax;
119 
120  if (theRMin < 0 || theRN < theRMin || theRMax < theRN)
121  LogTrace("MagGeoBuilder") << "*** WARNING: wrong RMin/RN/RMax";
122 
123  LogTrace("MagGeoBuilder") << "Summary: " << name << " " << copyno << " shape = " << theShape << " trasl "
124  << center() << " R " << center().perp() << " phi " << center().phi() << " magFile "
125  << magFile << " Material= " << fv.materialName() << " isIron= " << isIronFlag
126  << " masterSector= " << masterSector;
127 
128  LogTrace("MagGeoBuilder") << " Orientation of surfaces:";
129  std::string sideName[3] = {"positiveSide", "negativeSide", "onSurface"};
130  for (int i = 0; i < 6; ++i) {
131  if (surfaces[i] != nullptr)
132  LogTrace("MagGeoBuilder") << " " << i << ":" << sideName[surfaces[i]->side(center_, 0.3)];
133  }
134  }
135 }
136 
138  // The refPlane is the "main plane" for the solid. It corresponds to the
139  // x,y plane in the DDD local frame, and defines a frame where the local
140  // coordinates are the same as in DDD.
141  // In the geometry version 85l_030919, this plane is normal to the
142  // beam line for all volumes but pseudotraps, so that global R is along Y,
143  // global phi is along -X and global Z along Z:
144  //
145  // Global(for vol at pi/2) Local
146  // +R (+Y) +Y
147  // +phi(-X) -X
148  // +Z +Z
149  //
150  // For pseudotraps the refPlane is parallel to beam line and global R is
151  // along Z, global phi is along +-X and and global Z along Y:
152  //
153  // Global(for vol at pi/2) Local
154  // +R (+Y) +Z
155  // +phi(-X) +X
156  // +Z +Y
157  //
158  // Note that the frame is centered in the DDD volume center, which is
159  // inside the volume for DDD boxes and (pesudo)trapezoids, on the beam line
160  // for tubs, cons and trunctubs.
161 
162  // In geometry version 1103l, trapezoids have X and Z in the opposite direction
163  // than the above. Boxes are either oriented as described above or in some case
164  // have opposite direction for Y and X.
165 
166  // The global position
167  Surface::PositionType &posResult = center_;
168 
169  // The reference plane rotation
170  math::XYZVector x, y, z;
171  dd4hep::Rotation3D refRot;
172  fv.rot(refRot);
173  refRot.GetComponents(x, y, z);
174  if (debug) {
175  if (x.Cross(y).Dot(z) < 0.5) {
176  LogTrace("MagGeoBuilder") << "*** WARNING: Rotation is not RH ";
177  }
178  }
179 
180  // The global rotation
181  Surface::RotationType rotResult(float(x.X()),
182  float(x.Y()),
183  float(x.Z()),
184  float(y.X()),
185  float(y.Y()),
186  float(y.Z()),
187  float(z.X()),
188  float(z.Y()),
189  float(z.Z()));
190 
191  refPlane = new GloballyPositioned<float>(posResult, rotResult);
192 
193  // Check correct orientation
194  if (debug) {
195  LogTrace("MagGeoBuilder") << "Refplane pos " << refPlane->position();
196 
197  // See comments above for the conventions for orientation.
198  LocalVector globalZdir(0., 0., 1.); // Local direction of the axis along global Z
199 
201  globalZdir = LocalVector(0., 1., 0.);
202  }
203 
204  if (refPlane->toGlobal(globalZdir).z() < 0.) {
205  globalZdir = -globalZdir;
206  }
207  float chk = refPlane->toGlobal(globalZdir).dot(GlobalVector(0, 0, 1));
208  if (chk < .999)
209  LogTrace("MagGeoBuilder") << "*** WARNING RefPlane check failed!***" << chk;
210  }
211 }
212 
213 std::vector<VolumeSide> volumeHandle::sides() const {
214  std::vector<VolumeSide> result;
215  for (int i = 0; i < 6; ++i) {
216  // If this is just a master volume out of wich a 2pi volume
217  // should be built (e.g. central cylinder), skip the phi boundaries.
218  if (expand && (i == phiplus || i == phiminus))
219  continue;
220 
221  // FIXME: Skip null inner degenerate cylindrical surface
223  continue;
224 
225  ReferenceCountingPointer<Surface> s = const_cast<Surface *>(surfaces[i].get());
226  result.push_back(VolumeSide(s, GlobalFace(i), surfaces[i]->side(center_, 0.3)));
227  }
228  return result;
229 }
230 
231 #include "buildBox.icc"
232 #include "buildTrap.icc"
233 #include "buildTubs.icc"
234 #include "buildCons.icc"
235 #include "buildPseudoTrap.icc"
236 #include "buildTruncTubs.icc"
Vector3DBase< float, LocalTag >
GloballyPositioned< float >
magneticfield::BaseVolumeHandle::magFile
std::string magFile
Name of magnetic field table file.
Definition: BaseVolumeHandle.h:66
cms::DDFilteredView::rot
const Double_t * rot() const
The absolute rotation of the current node.
Definition: DDFilteredView.cc:120
SurfaceOrientation::phiplus
Definition: Surface.h:19
TkRotation< float >
mps_fire.i
i
Definition: mps_fire.py:428
cms::DDFilteredView::parameters
const std::vector< double > parameters() const
extract shape parameters
Definition: DDFilteredView.cc:536
MessageLogger.h
Cylinder.h
DDTruncTubs::startPhi
double startPhi(void) const
angular start of the tube-section
Definition: DDSolid.cc:168
DDCons
Definition: DDSolid.h:281
DDSolidShape::ddtrap
magneticfield::BaseVolumeHandle::debug
const bool debug
Definition: BaseVolumeHandle.h:151
volumeHandle
MagGeoBuilderFromDDD::volumeHandle volumeHandle
Definition: volumeHandle.cc:293
reco::deltaPhi
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
magneticfield::volumeHandle::theShape
const DDSolidShape theShape
Definition: DD4hep_volumeHandle.h:80
edm
HLT enums.
Definition: AlignableModifier.h:19
cms::DDFilteredView::copyNum
unsigned short copyNum() const
Definition: DDFilteredView.cc:863
testProducerWithPsetDescEmpty_cfi.x2
x2
Definition: testProducerWithPsetDescEmpty_cfi.py:28
DDSolidShape::ddpseudotrap
magneticfield::BaseVolumeHandle::center
const GlobalPoint & center() const
Return the center of the volume.
Definition: BaseVolumeHandle.cc:42
magneticfield::BaseVolumeHandle::isAssigned
bool isAssigned[6]
Definition: BaseVolumeHandle.h:122
magneticfield
Definition: MagFieldConfig.h:22
CoordinateSets.h
DD4hep_volumeHandle.h
magneticfield::volumeHandle::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)
ReferenceCountingPointer< Surface >
GlobalVector
Global3DVector GlobalVector
Definition: GlobalVector.h:10
magneticfield::BaseVolumeHandle::volumeno
unsigned short volumeno
volume number
Definition: BaseVolumeHandle.h:69
cms::DDFilteredView
Definition: DDFilteredView.h:70
magneticfield::BaseVolumeHandle::expand
bool expand
Definition: BaseVolumeHandle.h:146
VolumeSide
Definition: VolumeSide.h:15
magneticfield::BaseVolumeHandle::theRMin
double theRMin
Definition: BaseVolumeHandle.h:132
magneticfield::newln
const char *const newln
Definition: BaseVolumeHandle.h:218
magneticfield::volumeHandle::buildCons
void buildCons(double zhalf, double rInMinusZ, double rOutMinusZ, double rInPlusZ, double rOutPlusZ, double startPhi, double deltaPhi)
cms::DDFilteredView::name
std::string_view name() const
Definition: DDFilteredView.cc:853
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
cms::DDFilteredView::solid
dd4hep::Solid solid() const
Definition: DDFilteredView.cc:861
Plane.h
cms::DDFilteredView::trans
const Double_t * trans() const
The absolute translation of the current node.
Definition: DDFilteredView.cc:101
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition: testProducerWithPsetDescEmpty_cfi.py:33
alignCSCRings.s
s
Definition: alignCSCRings.py:92
testProducerWithPsetDescEmpty_cfi.y1
y1
Definition: testProducerWithPsetDescEmpty_cfi.py:29
DDTruncTubs
A truncated tube section.
Definition: DDSolid.h:128
magneticfield::BaseVolumeHandle::theRN
double theRN
Definition: BaseVolumeHandle.h:128
DDSolidShape::ddtubs
SiPixelRawToDigiRegional_cfi.deltaPhi
deltaPhi
Definition: SiPixelRawToDigiRegional_cfi.py:9
DDBox
Interface to a Box.
Definition: DDSolid.h:156
magneticfield::BaseVolumeHandle::isIronFlag
bool isIronFlag
Definition: BaseVolumeHandle.h:149
SurfaceOrientation::inner
Definition: Surface.h:19
DDSolidShape::ddtrunctubs
magneticfield::BaseVolumeHandle::theRMax
double theRMax
Definition: BaseVolumeHandle.h:133
magneticfield::BaseVolumeHandle::GlobalPoint
Surface::GlobalPoint GlobalPoint
Definition: BaseVolumeHandle.h:24
magneticfield::volumeHandle::buildTubs
void buildTubs(double zhalf, double rIn, double rOut, double startPhi, double deltaPhi)
theta
Geom::Theta< T > theta() const
Definition: Basic3DVectorLD.h:150
Point3DBase< float, GlobalTag >
magneticfield::BaseVolumeHandle::masterSector
int masterSector
The sector for which an interpolator for this class of volumes should be built.
Definition: BaseVolumeHandle.h:111
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
Cone.h
testProducerWithPsetDescEmpty_cfi.y2
y2
Definition: testProducerWithPsetDescEmpty_cfi.py:30
magneticfield::BaseVolumeHandle::center_
GlobalPoint center_
Definition: BaseVolumeHandle.h:142
DDTrap
Interface to a Trapezoid.
Definition: DDSolid.h:77
GeantUnits.h
magneticfield::volumeHandle::buildBox
void buildBox(double halfX, double halfY, double halfZ)
DDSolidShape::ddcons
math::XYZVector
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
magneticfield::BaseVolumeHandle::LocalVector
Surface::LocalVector LocalVector
Definition: BaseVolumeHandle.h:26
magneticfield::volumeHandle::referencePlane
void referencePlane(const cms::DDFilteredView &fv)
Definition: DD4hep_volumeHandle.cc:137
DDTubs::startPhi
double startPhi(void) const
Definition: DDSolid.cc:456
magneticfield::BaseVolumeHandle
Definition: BaseVolumeHandle.h:22
magneticfield::volumeHandle::buildTruncTubs
void buildTruncTubs(double zhalf, double rIn, double rOut, double startPhi, double deltaPhi, double cutAtStart, double cutAtDelta, bool cutInside)
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
get
#define get
magneticfield::BaseVolumeHandle::copyno
unsigned short copyno
copy number
Definition: BaseVolumeHandle.h:72
GloballyPositioned::position
const PositionType & position() const
Definition: GloballyPositioned.h:36
std
Definition: JetResolutionObject.h:76
DDSolidShape::ddbox
magneticfield::BaseVolumeHandle::name
std::string name
Name of the volume.
Definition: BaseVolumeHandle.h:63
cms::DDFilteredView::materialName
std::string_view materialName() const
Definition: DDFilteredView.cc:865
magneticfield::BaseVolumeHandle::surfaces
RCPS surfaces[6]
Definition: BaseVolumeHandle.h:120
magneticfield::volumeHandle::solid
const cms::DDFilteredView & solid
Definition: DD4hep_volumeHandle.h:81
SurfaceOrientation::GlobalFace
GlobalFace
Definition: Surface.h:19
SurfaceOrientation::phiminus
Definition: Surface.h:19
ztail.d
d
Definition: ztail.py:151
mps_fire.result
result
Definition: mps_fire.py:311
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:224
magneticfield::BaseVolumeHandle::refPlane
GloballyPositioned< float > * refPlane
Definition: BaseVolumeHandle.h:139
SurfaceOrientation
Definition: Surface.h:17
Vector3D.h
magneticfield::volumeHandle::buildPseudoTrap
void buildPseudoTrap(double x1, double x2, double y1, double y2, double halfZ, double radius, bool atMinusZ)
PV3DBase::perp
T perp() const
Definition: PV3DBase.h:69
PV3DBase::phi
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
GloballyPositioned::toGlobal
GlobalPoint toGlobal(const LocalPoint &lp) const
Definition: GloballyPositioned.h:66
magneticfield::volumeHandle::sides
std::vector< VolumeSide > sides() const override
The surfaces and they orientation, as required to build a MagVolume.
Definition: DD4hep_volumeHandle.cc:213
DDTubs
Definition: DDSolid.h:255