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 
18 
19 #include <string>
20 #include <iterator>
21 
22 using namespace SurfaceOrientation;
23 using namespace std;
24 using namespace magneticfield;
25 using namespace edm;
26 
27 volumeHandle::volumeHandle(const cms::DDFilteredView &fv, bool expand2Pi, bool debugVal)
28  : BaseVolumeHandle(expand2Pi, debugVal), theShape(fv.legacyShape(cms::dd::getCurrentShape(fv))), solid(fv) {
29  name = fv.name();
30  copyno = fv.copyNum();
31  const auto *const transArray = fv.trans();
32  center_ = GlobalPoint(transArray[0], transArray[1], transArray[2]);
33 
34  // ASSUMPTION: volume names ends with "_NUM" where NUM is the volume number
35  string volName = name;
36  volName.erase(0, volName.rfind('_') + 1);
37  volumeno = static_cast<unsigned short>(std::atoi(volName.c_str()));
38 
39  for (int i = 0; i < 6; ++i) {
40  isAssigned[i] = false;
41  }
42  referencePlane(fv);
43  switch (theShape) {
45  buildBox();
46  break;
48  buildTrap();
49  break;
51  buildCons();
52  break;
54  buildTubs();
55  break;
57  vector<double> d = solid.volume().volume().solid().dimensions();
58  buildPseudoTrap(d[0], d[1], d[2], d[3], d[4], d[5], d[6]);
59  } break;
62  break;
63  default:
64  LogError("magneticfield::volumeHandle")
65  << "ctor: Unexpected shape # " << static_cast<int>(theShape) << " for vol " << name;
66  }
67 
68  // Get material for this volume
69  if (fv.materialName() == "Iron")
70  isIronFlag = true;
71 
72  if (debug) {
73  LogTrace("MagGeoBuilder") << " RMin = " << theRMin << newln << " RMax = " << theRMax;
74 
75  if (theRMin < 0 || theRN < theRMin || theRMax < theRN)
76  LogTrace("MagGeoBuilder") << "*** WARNING: wrong RMin/RN/RMax";
77 
78  LogTrace("MagGeoBuilder") << "Summary: " << name << " " << copyno << " shape = " << theShape << " trasl "
79  << center() << " R " << center().perp() << " phi " << center().phi() << " magFile "
80  << magFile << " Material= " << fv.materialName() << " isIron= " << isIronFlag
81  << " masterSector= " << masterSector;
82 
83  LogTrace("MagGeoBuilder") << " Orientation of surfaces:";
84  std::string sideName[3] = {"positiveSide", "negativeSide", "onSurface"};
85  for (int i = 0; i < 6; ++i) {
86  if (surfaces[i] != nullptr)
87  LogTrace("MagGeoBuilder") << " " << i << ":" << sideName[surfaces[i]->side(center_, 0.3)];
88  }
89  }
90 }
91 
93  // The refPlane is the "main plane" for the solid. It corresponds to the
94  // x,y plane in the DDD local frame, and defines a frame where the local
95  // coordinates are the same as in DDD.
96  // In the geometry version 85l_030919, this plane is normal to the
97  // beam line for all volumes but pseudotraps, so that global R is along Y,
98  // global phi is along -X and global Z along Z:
99  //
100  // Global(for vol at pi/2) Local
101  // +R (+Y) +Y
102  // +phi(-X) -X
103  // +Z +Z
104  //
105  // For pseudotraps the refPlane is parallel to beam line and global R is
106  // along Z, global phi is along +-X and and global Z along Y:
107  //
108  // Global(for vol at pi/2) Local
109  // +R (+Y) +Z
110  // +phi(-X) +X
111  // +Z +Y
112  //
113  // Note that the frame is centered in the DDD volume center, which is
114  // inside the volume for DDD boxes and (pesudo)trapezoids, on the beam line
115  // for tubs, cons and trunctubs.
116 
117  // In geometry version 1103l, trapezoids have X and Z in the opposite direction
118  // than the above. Boxes are either oriented as described above or in some case
119  // have opposite direction for Y and X.
120 
121  // The global position
122  Surface::PositionType &posResult = center_;
123 
124  // The reference plane rotation
125  math::XYZVector x, y, z;
126  dd4hep::Rotation3D refRot;
127  fv.rot(refRot);
128  refRot.GetComponents(x, y, z);
129  if (debug) {
130  if (x.Cross(y).Dot(z) < 0.5) {
131  LogTrace("MagGeoBuilder") << "*** WARNING: Rotation is not RH ";
132  }
133  }
134 
135  // The global rotation
136  Surface::RotationType rotResult(float(x.X()),
137  float(x.Y()),
138  float(x.Z()),
139  float(y.X()),
140  float(y.Y()),
141  float(y.Z()),
142  float(z.X()),
143  float(z.Y()),
144  float(z.Z()));
145 
146  refPlane = new GloballyPositioned<float>(posResult, rotResult);
147 
148  // Check correct orientation
149  if (debug) {
150  LogTrace("MagGeoBuilder") << "Refplane pos " << refPlane->position();
151 
152  // See comments above for the conventions for orientation.
153  LocalVector globalZdir(0., 0., 1.); // Local direction of the axis along global Z
154 
156  globalZdir = LocalVector(0., 1., 0.);
157  }
158 
159  if (refPlane->toGlobal(globalZdir).z() < 0.) {
160  globalZdir = -globalZdir;
161  }
162  float chk = refPlane->toGlobal(globalZdir).dot(GlobalVector(0, 0, 1));
163  if (chk < .999)
164  LogTrace("MagGeoBuilder") << "*** WARNING RefPlane check failed!***" << chk;
165  }
166 }
167 
168 std::vector<VolumeSide> volumeHandle::sides() const {
169  std::vector<VolumeSide> result;
170  for (int i = 0; i < 6; ++i) {
171  // If this is just a master volume out of wich a 2pi volume
172  // should be built (e.g. central cylinder), skip the phi boundaries.
173  if (expand && (i == phiplus || i == phiminus))
174  continue;
175 
176  // FIXME: Skip null inner degenerate cylindrical surface
178  continue;
179 
180  ReferenceCountingPointer<Surface> s = const_cast<Surface *>(surfaces[i].get());
181  result.push_back(VolumeSide(s, GlobalFace(i), surfaces[i]->side(center_, 0.3)));
182  }
183  return result;
184 }
185 
186 // The files included below are used here and in the old DD version of this file.
187 // To allow them to be used in both places, they call a "convertUnits" function
188 // that is defined differently between old and new DD.
189 // For the old DD, another version of this function converts mm to cm.
190 
191 namespace {
192  template <class NumType>
193  inline constexpr NumType convertUnits(NumType centimeters) {
194  return (centimeters);
195  }
196 } // namespace
197 
198 using namespace cms::dd;
199 
200 #include "buildBox.icc"
201 #include "buildTrap.icc"
202 #include "buildTubs.icc"
203 #include "buildCons.icc"
204 #include "buildPseudoTrap.icc"
205 #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
cms::DDFilteredView::volume
const PlacedVolume volume() const
The physical volume of the current node.
Definition: DDFilteredView.cc:68
SurfaceOrientation::phiplus
Definition: Surface.h:19
TkRotation< float >
mps_fire.i
i
Definition: mps_fire.py:355
MessageLogger.h
Cylinder.h
DDSolidShape::ddtrap
magneticfield::BaseVolumeHandle::debug
const bool debug
Definition: BaseVolumeHandle.h:151
magneticfield::volumeHandle::buildBox
void buildBox()
volumeHandle
MagGeoBuilderFromDDD::volumeHandle volumeHandle
Definition: volumeHandle.cc:238
magneticfield::volumeHandle::theShape
const DDSolidShape theShape
Definition: DD4hep_volumeHandle.h:57
edm
HLT enums.
Definition: AlignableModifier.h:19
cms::DDFilteredView::copyNum
unsigned short copyNum() const
Definition: DDFilteredView.cc:610
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
DDShapes.h
magneticfield
Definition: MagFieldConfig.h:22
CoordinateSets.h
DD4hep_volumeHandle.h
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:65
magneticfield::BaseVolumeHandle::expand
bool expand
Definition: BaseVolumeHandle.h:146
magneticfield::volumeHandle::buildTruncTubs
void buildTruncTubs()
VolumeSide
Definition: VolumeSide.h:15
magneticfield::BaseVolumeHandle::theRMin
double theRMin
Definition: BaseVolumeHandle.h:132
magneticfield::newln
const char *const newln
Definition: BaseVolumeHandle.h:218
cms::DDFilteredView::name
std::string_view name() const
Definition: DDFilteredView.cc:606
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
Plane.h
cms::DDFilteredView::trans
const Double_t * trans() const
The absolute translation of the current node.
Definition: DDFilteredView.cc:101
alignCSCRings.s
s
Definition: alignCSCRings.py:92
magneticfield::BaseVolumeHandle::theRN
double theRN
Definition: BaseVolumeHandle.h:128
DDSolidShape::ddtubs
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
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
createTree.dd
string dd
Definition: createTree.py:154
cms::dd::getCurrentShape
DDSolidShape getCurrentShape(const cms::DDFilteredView &fview)
Definition: DDShapes.cc:19
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
Cone.h
magneticfield::BaseVolumeHandle::center_
GlobalPoint center_
Definition: BaseVolumeHandle.h:142
edm::LogError
Definition: MessageLogger.h:183
GeantUnits.h
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:92
magneticfield::BaseVolumeHandle
Definition: BaseVolumeHandle.h:22
get
#define get
magneticfield::BaseVolumeHandle::copyno
unsigned short copyno
copy number
Definition: BaseVolumeHandle.h:72
magneticfield::volumeHandle::buildCons
void buildCons()
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:612
magneticfield::BaseVolumeHandle::surfaces
RCPS surfaces[6]
Definition: BaseVolumeHandle.h:120
magneticfield::volumeHandle::solid
const cms::DDFilteredView & solid
Definition: DD4hep_volumeHandle.h:58
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:303
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:671
magneticfield::BaseVolumeHandle::refPlane
GloballyPositioned< float > * refPlane
Definition: BaseVolumeHandle.h:139
magneticfield::volumeHandle::buildTrap
void buildTrap()
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
cms::dd
Definition: DDShapes.h:10
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::buildTubs
void buildTubs()
magneticfield::volumeHandle::sides
std::vector< VolumeSide > sides() const override
The surfaces and they orientation, as required to build a MagVolume.
Definition: DD4hep_volumeHandle.cc:168
cms
Namespace of DDCMS conversion namespace.
Definition: ProducerAnalyzer.cc:21