CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
magneticfield::volumeHandle Class Reference

#include <DD4hep_volumeHandle.h>

Inheritance diagram for magneticfield::volumeHandle:
magneticfield::BaseVolumeHandle

Public Member Functions

volumeHandle operator= (const volumeHandle &v)=delete
 
DDSolidShape shape () const override
 Shape of the solid. More...
 
std::vector< VolumeSidesides () const override
 The surfaces and they orientation, as required to build a MagVolume. More...
 
 volumeHandle (const cms::DDFilteredView &fv, bool expand2Pi=false, bool debugVal=false)
 
 volumeHandle (const volumeHandle &v)=delete
 
- Public Member Functions inherited from magneticfield::BaseVolumeHandle
 BaseVolumeHandle (bool expand2Pi=false, bool debugVal=false)
 
 BaseVolumeHandle (const BaseVolumeHandle &v)=delete
 
const GlobalPointcenter () const
 Return the center of the volume. More...
 
bool isIron () const
 Temporary hack to pass information on material. Will eventually be replaced! More...
 
bool isPlaneMatched (int which_side) const
 if the specified surface has been matched. More...
 
Geom::Phi< float > maxPhi () const
 Maximum value of phi covered by the volume. More...
 
double maxZ () const
 
Geom::Phi< float > minPhi () const
 Minimum value of phi covered by the volume. More...
 
double minR () const
 Minimum R for any point within the volume. More...
 
double minZ () const
 Z limits. More...
 
const GloballyPositioned< float > * placement () const
 Position and rotation. More...
 
int references (int which_side) const
 
const double RN () const
 Distance of (x,y) plane from origin. More...
 
bool sameSurface (const Surface &s1, Sides which_side, float tolerance=0.01)
 Find out if two surfaces are the same physical surface. More...
 
bool setSurface (const Surface &s1, Sides which_side)
 Assign a shared surface perorming sanity checks. More...
 
const Surfacesurface (int which_side) const
 Get the current surface on specified side. More...
 
const Surfacesurface (Sides which_side) const
 
bool toExpand () const
 
virtual ~BaseVolumeHandle ()
 

Private Member Functions

void buildBox (double halfX, double halfY, double halfZ)
 
void buildCons (double zhalf, double rInMinusZ, double rOutMinusZ, double rInPlusZ, double rOutPlusZ, double startPhi, double deltaPhi)
 
void buildPseudoTrap (double x1, double x2, double y1, double y2, double halfZ, double radius, bool atMinusZ)
 
void buildTrap (double x1, double x2, double x3, double x4, double y1, double y2, double theta, double phi, double halfZ, double alpha1, double alpha2)
 
void buildTruncTubs (double zhalf, double rIn, double rOut, double startPhi, double deltaPhi, double cutAtStart, double cutAtDelta, bool cutInside)
 
void buildTubs (double zhalf, double rIn, double rOut, double startPhi, double deltaPhi)
 
void referencePlane (const cms::DDFilteredView &fv)
 

Private Attributes

const cms::DDFilteredViewsolid
 
const DDSolidShape theShape
 

Additional Inherited Members

- Public Types inherited from magneticfield::BaseVolumeHandle
typedef Surface::GlobalPoint GlobalPoint
 
typedef Surface::LocalPoint LocalPoint
 
typedef Surface::LocalVector LocalVector
 
typedef SurfaceOrientation::GlobalFace Sides
 
- Public Attributes inherited from magneticfield::BaseVolumeHandle
unsigned short copyno
 copy number More...
 
std::string magFile
 Name of magnetic field table file. More...
 
MagVolume6FacesmagVolume
 Pointer to the final MagVolume (must be set from outside) More...
 
int masterSector
 The sector for which an interpolator for this class of volumes should be built. More...
 
std::string name
 Name of the volume. More...
 
unsigned short volumeno
 volume number More...
 
- Protected Types inherited from magneticfield::BaseVolumeHandle
typedef ConstReferenceCountingPointer< SurfaceRCPS
 
- Protected Member Functions inherited from magneticfield::BaseVolumeHandle
void buildPhiZSurf (double startPhi, double deltaPhi, double zhalf, double rCentr)
 
- Protected Attributes inherited from magneticfield::BaseVolumeHandle
GlobalPoint center_
 
const bool debug
 
bool expand
 
bool isAssigned [6]
 
bool isIronFlag
 
GloballyPositioned< float > * refPlane
 
RCPS surfaces [6]
 
Geom::Phi< float > thePhiMin
 
double theRMax
 
double theRMin
 
double theRN
 

Detailed Description

Definition at line 23 of file DD4hep_volumeHandle.h.

Constructor & Destructor Documentation

◆ volumeHandle() [1/2]

volumeHandle::volumeHandle ( const cms::DDFilteredView fv,
bool  expand2Pi = false,
bool  debugVal = false 
)

Definition at line 33 of file DD4hep_volumeHandle.cc.

References buildBox(), buildCons(), buildPseudoTrap(), buildTrap(), buildTruncTubs(), buildTubs(), magneticfield::BaseVolumeHandle::center(), magneticfield::BaseVolumeHandle::center_, magneticfield::BaseVolumeHandle::copyno, cms::DDFilteredView::copyNum(), ztail::d, ddbox, ddcons, ddpseudotrap, ddtrap, ddtrunctubs, ddtubs, magneticfield::BaseVolumeHandle::debug, reco::deltaPhi(), srCondWrite_cfg::deltaPhi, mps_fire::i, magneticfield::BaseVolumeHandle::isAssigned, magneticfield::BaseVolumeHandle::isIronFlag, LogTrace, magneticfield::BaseVolumeHandle::magFile, magneticfield::BaseVolumeHandle::masterSector, cms::DDFilteredView::materialName(), magneticfield::BaseVolumeHandle::name, cms::DDFilteredView::name(), magneticfield::newln, cms::DDFilteredView::parameters(), PV3DBase< T, PVType, FrameType >::perp(), PV3DBase< T, PVType, FrameType >::phi(), referencePlane(), solid, cms::DDFilteredView::solid(), DDTruncTubs::startPhi(), DDTubs::startPhi(), AlCaHLTBitMon_QueryRunRegistry::string, magneticfield::BaseVolumeHandle::surfaces, magneticfield::BaseVolumeHandle::theRMax, magneticfield::BaseVolumeHandle::theRMin, magneticfield::BaseVolumeHandle::theRN, theShape, tauSpinnerTable_cfi::theta, cms::DDFilteredView::trans(), HcalDetIdTransform::transform(), heppy_batch::val, cms::DDFilteredView::volume(), magneticfield::BaseVolumeHandle::volumeno, testProducerWithPsetDescEmpty_cfi::y1, and testProducerWithPsetDescEmpty_cfi::y2.

34  : BaseVolumeHandle(expand2Pi, debugVal), theShape(fv.legacyShape(fv.shape())), solid(fv) {
35  name = fv.name();
36  copyno = fv.copyNum();
37  const auto *const transArray = fv.trans();
38 
39  // Convert from DD4hep units to cm
40  center_ = GlobalPoint(transArray[0] / dd4hep::cm, transArray[1] / dd4hep::cm, transArray[2] / dd4hep::cm);
41 
42  // ASSUMPTION: volume names ends with "_NUM" where NUM is the volume number
43  string volName = name;
44  volName.erase(0, volName.rfind('_') + 1);
45  volumeno = static_cast<unsigned short>(std::atoi(volName.c_str()));
46 
47  for (int i = 0; i < 6; ++i) {
48  isAssigned[i] = false;
49  }
50  referencePlane(fv);
51  switch (theShape) {
52  case DDSolidShape::ddbox: {
53  DDBox box(solid.solid());
54  // Convert from DD4hep units to cm
55  double halfX = box.x() / dd4hep::cm;
56  double halfY = box.y() / dd4hep::cm;
57  double halfZ = box.z() / dd4hep::cm;
58  buildBox(halfX, halfY, halfZ);
59  } break;
60  case DDSolidShape::ddtrap: {
61  DDTrap trap(solid.solid());
62  double x1 = trap.bottomLow1() / dd4hep::cm;
63  double x2 = trap.topLow1() / dd4hep::cm;
64  double x3 = trap.bottomLow2() / dd4hep::cm;
65  double x4 = trap.topLow2() / dd4hep::cm;
66  double y1 = trap.high1() / dd4hep::cm;
67  double y2 = trap.high2() / dd4hep::cm;
68  double theta = trap.theta();
69  double phi = trap.phi();
70  double halfZ = trap.dZ() / dd4hep::cm;
71  double alpha1 = trap.alpha1();
72  double alpha2 = trap.alpha2();
73  buildTrap(x1, x2, x3, x4, y1, y2, theta, phi, halfZ, alpha1, alpha2);
74  } break;
75 
76  case DDSolidShape::ddcons: {
77  DDCons cons(solid.solid());
78  double zhalf = cons.dZ() / dd4hep::cm;
79  double rInMinusZ = cons.rMin1() / dd4hep::cm;
80  double rOutMinusZ = cons.rMax1() / dd4hep::cm;
81  double rInPlusZ = cons.rMin2() / dd4hep::cm;
82  double rOutPlusZ = cons.rMax2() / dd4hep::cm;
83  double startPhi = cons.startPhi();
84  double deltaPhi = reco::deltaPhi(cons.endPhi(), startPhi);
85  buildCons(zhalf, rInMinusZ, rOutMinusZ, rInPlusZ, rOutPlusZ, startPhi, deltaPhi);
86  } break;
87  case DDSolidShape::ddtubs: {
88  DDTubs tubs(solid.solid());
89  double zhalf = tubs.dZ() / dd4hep::cm;
90  double rIn = tubs.rMin() / dd4hep::cm;
91  double rOut = tubs.rMax() / dd4hep::cm;
92  double startPhi = tubs.startPhi();
93  double deltaPhi = tubs.endPhi() - startPhi;
94  buildTubs(zhalf, rIn, rOut, startPhi, deltaPhi);
95  } break;
97  vector<double> d = solid.parameters();
98 
99  // The pseudo-trapezoid parameters are:
100  // d[0] -- x1
101  // d[1] -- x2
102  // d[2] -- y1
103  // d[3] -- y2
104  // d[4] -- halfZ
105  // d[5] -- radius
106  // d[6] -- atMinusZ (0 or 1)
107  // Note all are lengths except for the last one. The lengths come from
108  // DD4hep in DD4hep units and must be converted to cm for use.
109 
110  if (d.size() >= 7)
111  LogTrace("MagGeoBuilder") << " Pseudo trap params raw = " << d[0] << ", " << d[1] << ", " << d[2] << ", "
112  << d[3] << ", " << d[4] << ", " << d[5] << ", " << d[6];
113 
114  // Convert all but last parameter to cm (last one is a boolean).
115  transform(d.begin(), --(d.end()), d.begin(), [](double val) { return val / dd4hep::cm; });
116 
117  if (d.size() >= 7)
118  LogTrace("MagGeoBuilder") << " Pseudo trap params converted = " << d[0] << ", " << d[1] << ", " << d[2] << ", "
119  << d[3] << ", " << d[4] << ", " << d[5] << ", " << d[6];
120 
121  buildPseudoTrap(d[0], d[1], d[2], d[3], d[4], d[5], static_cast<bool>(d[6]));
122  } break;
124  DDTruncTubs tubs(solid.solid());
125  double zhalf = tubs.dZ() / dd4hep::cm; // half of the z-Axis
126  double rIn = tubs.rMin() / dd4hep::cm; // inner radius
127  double rOut = tubs.rMax() / dd4hep::cm; // outer radius
128  double startPhi = tubs.startPhi(); // angular start of the tube-section
129  double deltaPhi = tubs.deltaPhi(); // angular span of the tube-section
130  double cutAtStart = tubs.cutAtStart() / dd4hep::cm; // truncation at begin of the tube-section
131  double cutAtDelta = tubs.cutAtDelta() / dd4hep::cm; // truncation at end of the tube-section
132  bool cutInside = tubs.cutInside(); // true, if truncation is on the inner side of the tube-section
133  buildTruncTubs(zhalf, rIn, rOut, startPhi, deltaPhi, cutAtStart, cutAtDelta, cutInside);
134  } break;
135  default:
136  LogError("magneticfield::volumeHandle")
137  << "ctor: Unexpected shape # " << static_cast<int>(theShape) << " for vol " << name;
138  }
139 
140  // The only materials used in the geometry are: materials:Air, d=0.001214; materials:Iron, d=7.87
141  if (fv.volume().material().density() > 3.)
142  isIronFlag = true;
143 
144  if (debug) {
145  LogTrace("MagGeoBuilder") << " RMin = " << theRMin << newln << " RMax = " << theRMax;
146 
147  if (theRMin < 0 || theRN < theRMin || theRMax < theRN)
148  LogTrace("MagGeoBuilder") << "*** WARNING: wrong RMin/RN/RMax";
149 
150  LogTrace("MagGeoBuilder") << "Summary: " << name << " " << copyno << " shape = " << theShape << " trasl "
151  << center() << " R " << center().perp() << " phi " << center().phi() << " magFile "
152  << magFile << " Material= " << fv.materialName() << " isIron= " << isIronFlag
153  << " masterSector= " << masterSector;
154 
155  LogTrace("MagGeoBuilder") << " Orientation of surfaces:";
156  std::string sideName[3] = {"positiveSide", "negativeSide", "onSurface"};
157  for (int i = 0; i < 6; ++i) {
158  if (surfaces[i] != nullptr)
159  LogTrace("MagGeoBuilder") << " " << i << ":" << sideName[surfaces[i]->side(center_, 0.3)];
160  }
161  }
162 }
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
void buildBox(double halfX, double halfY, double halfZ)
T perp() const
Definition: PV3DBase.h:69
A truncated tube section.
Definition: DDSolid.h:139
const cms::DDSolidShape shape() const
double startPhi(void) const
angular start of the tube-section
Definition: DDSolid.cc:172
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
Log< level::Error, false > LogError
const GlobalPoint & center() const
Return the center of the volume.
unsigned short volumeno
volume number
const char *const newln
#define LogTrace(id)
unsigned short copyno
copy number
std::string_view name() const
const Double_t * trans() const
The absolute translation of the current node.
void referencePlane(const cms::DDFilteredView &fv)
Surface::GlobalPoint GlobalPoint
void buildTrap(double x1, double x2, double x3, double x4, double y1, double y2, double theta, double phi, double halfZ, double alpha1, double alpha2)
void buildTruncTubs(double zhalf, double rIn, double rOut, double startPhi, double deltaPhi, double cutAtStart, double cutAtDelta, bool cutInside)
Interface to a Trapezoid.
Definition: DDSolid.h:88
int masterSector
The sector for which an interpolator for this class of volumes should be built.
std::string_view materialName() const
unsigned short copyNum() const
d
Definition: ztail.py:151
void buildPseudoTrap(double x1, double x2, double y1, double y2, double halfZ, double radius, bool atMinusZ)
Interface to a Box.
Definition: DDSolid.h:167
std::string name
Name of the volume.
void buildCons(double zhalf, double rInMinusZ, double rOutMinusZ, double rInPlusZ, double rOutPlusZ, double startPhi, double deltaPhi)
dd4hep::Solid solid() const
BaseVolumeHandle(bool expand2Pi=false, bool debugVal=false)
double startPhi(void) const
Definition: DDSolid.cc:460
const PlacedVolume volume() const
The physical volume of the current node.
const std::vector< double > parameters() const
extract shape parameters
std::string magFile
Name of magnetic field table file.
const cms::DDFilteredView & solid
LegacySolidShape legacyShape(const cms::DDSolidShape shape) const
void buildTubs(double zhalf, double rIn, double rOut, double startPhi, double deltaPhi)
unsigned transform(const HcalDetId &id, unsigned transformCode)

◆ volumeHandle() [2/2]

magneticfield::volumeHandle::volumeHandle ( const volumeHandle v)
delete

Member Function Documentation

◆ buildBox()

void magneticfield::volumeHandle::buildBox ( double  halfX,
double  halfY,
double  halfZ 
)
private

Referenced by volumeHandle().

◆ buildCons()

void magneticfield::volumeHandle::buildCons ( double  zhalf,
double  rInMinusZ,
double  rOutMinusZ,
double  rInPlusZ,
double  rOutPlusZ,
double  startPhi,
double  deltaPhi 
)
private

Referenced by volumeHandle().

◆ buildPseudoTrap()

void magneticfield::volumeHandle::buildPseudoTrap ( double  x1,
double  x2,
double  y1,
double  y2,
double  halfZ,
double  radius,
bool  atMinusZ 
)
private

Referenced by volumeHandle().

◆ buildTrap()

void magneticfield::volumeHandle::buildTrap ( double  x1,
double  x2,
double  x3,
double  x4,
double  y1,
double  y2,
double  theta,
double  phi,
double  halfZ,
double  alpha1,
double  alpha2 
)
private

Referenced by volumeHandle().

◆ buildTruncTubs()

void magneticfield::volumeHandle::buildTruncTubs ( double  zhalf,
double  rIn,
double  rOut,
double  startPhi,
double  deltaPhi,
double  cutAtStart,
double  cutAtDelta,
bool  cutInside 
)
private

Referenced by volumeHandle().

◆ buildTubs()

void magneticfield::volumeHandle::buildTubs ( double  zhalf,
double  rIn,
double  rOut,
double  startPhi,
double  deltaPhi 
)
private

Referenced by volumeHandle().

◆ operator=()

volumeHandle magneticfield::volumeHandle::operator= ( const volumeHandle v)
delete

◆ referencePlane()

void volumeHandle::referencePlane ( const cms::DDFilteredView fv)
private

Definition at line 164 of file DD4hep_volumeHandle.cc.

References magneticfield::BaseVolumeHandle::center_, ddpseudotrap, magneticfield::BaseVolumeHandle::debug, LogTrace, GloballyPositioned< T >::position(), magneticfield::BaseVolumeHandle::refPlane, cms::DDFilteredView::rot(), theShape, GloballyPositioned< T >::toGlobal(), x, and PV3DBase< T, PVType, FrameType >::z().

Referenced by volumeHandle().

164  {
165  // The refPlane is the "main plane" for the solid. It corresponds to the
166  // x,y plane in the DDD local frame, and defines a frame where the local
167  // coordinates are the same as in DDD.
168  // In the geometry version 85l_030919, this plane is normal to the
169  // beam line for all volumes but pseudotraps, so that global R is along Y,
170  // global phi is along -X and global Z along Z:
171  //
172  // Global(for vol at pi/2) Local
173  // +R (+Y) +Y
174  // +phi(-X) -X
175  // +Z +Z
176  //
177  // For pseudotraps the refPlane is parallel to beam line and global R is
178  // along Z, global phi is along +-X and and global Z along Y:
179  //
180  // Global(for vol at pi/2) Local
181  // +R (+Y) +Z
182  // +phi(-X) +X
183  // +Z +Y
184  //
185  // Note that the frame is centered in the DDD volume center, which is
186  // inside the volume for DDD boxes and (pesudo)trapezoids, on the beam line
187  // for tubs, cons and trunctubs.
188 
189  // In geometry version 1103l, trapezoids have X and Z in the opposite direction
190  // than the above. Boxes are either oriented as described above or in some case
191  // have opposite direction for Y and X.
192 
193  // The global position
194  Surface::PositionType &posResult = center_;
195 
196  // The reference plane rotation
197  math::XYZVector x, y, z;
198  dd4hep::Rotation3D refRot;
199  fv.rot(refRot);
200  refRot.GetComponents(x, y, z);
201  if (debug) {
202  if (x.Cross(y).Dot(z) < 0.5) {
203  LogTrace("MagGeoBuilder") << "*** WARNING: Rotation is not RH ";
204  }
205  }
206 
207  // The global rotation
208  Surface::RotationType rotResult(float(x.X()),
209  float(x.Y()),
210  float(x.Z()),
211  float(y.X()),
212  float(y.Y()),
213  float(y.Z()),
214  float(z.X()),
215  float(z.Y()),
216  float(z.Z()));
217 
218  refPlane = new GloballyPositioned<float>(posResult, rotResult);
219 
220  // Check correct orientation
221  if (debug) {
222  LogTrace("MagGeoBuilder") << "Refplane pos " << refPlane->position();
223 
224  // See comments above for the conventions for orientation.
225  LocalVector globalZdir(0., 0., 1.); // Local direction of the axis along global Z
226 
228  globalZdir = LocalVector(0., 1., 0.);
229  }
230 
231  if (refPlane->toGlobal(globalZdir).z() < 0.) {
232  globalZdir = -globalZdir;
233  }
234  float chk = refPlane->toGlobal(globalZdir).dot(GlobalVector(0, 0, 1));
235  if (chk < .999)
236  LogTrace("MagGeoBuilder") << "*** WARNING RefPlane check failed!***" << chk;
237  }
238 }
GlobalPoint toGlobal(const LocalPoint &lp) const
Surface::LocalVector LocalVector
T z() const
Definition: PV3DBase.h:61
const Double_t * rot() const
The absolute rotation of the current node.
#define LogTrace(id)
GloballyPositioned< float > * refPlane
const PositionType & position() const
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
Global3DVector GlobalVector
Definition: GlobalVector.h:10

◆ shape()

DDSolidShape magneticfield::volumeHandle::shape ( ) const
inlineoverridevirtual

Shape of the solid.

Implements magneticfield::BaseVolumeHandle.

Definition at line 33 of file DD4hep_volumeHandle.h.

References theShape.

33 { return (theShape); }

◆ sides()

std::vector< VolumeSide > volumeHandle::sides ( void  ) const
overridevirtual

The surfaces and they orientation, as required to build a MagVolume.

Implements magneticfield::BaseVolumeHandle.

Definition at line 240 of file DD4hep_volumeHandle.cc.

References magneticfield::BaseVolumeHandle::center_, ddtubs, magneticfield::BaseVolumeHandle::expand, mps_fire::i, SurfaceOrientation::inner, SurfaceOrientation::phiminus, SurfaceOrientation::phiplus, mps_fire::result, alignCSCRings::s, ALPAKA_ACCELERATOR_NAMESPACE::ecal::reconstruction::internal::barrel::side(), magneticfield::BaseVolumeHandle::surfaces, magneticfield::BaseVolumeHandle::theRMin, and theShape.

Referenced by magneticfield::MagGeoBuilder::buildInterpolator().

240  {
241  std::vector<VolumeSide> result;
242  for (int i = 0; i < 6; ++i) {
243  // If this is just a master volume out of wich a 2pi volume
244  // should be built (e.g. central cylinder), skip the phi boundaries.
245  if (expand && (i == phiplus || i == phiminus))
246  continue;
247 
248  // FIXME: Skip null inner degenerate cylindrical surface
250  continue;
251 
252  ReferenceCountingPointer<Surface> s = const_cast<Surface *>(surfaces[i].get());
253  result.push_back(VolumeSide(s, GlobalFace(i), surfaces[i]->side(center_, 0.3)));
254  }
255  return result;
256 }

Member Data Documentation

◆ solid

const cms::DDFilteredView& magneticfield::volumeHandle::solid
private

Definition at line 81 of file DD4hep_volumeHandle.h.

Referenced by volumeHandle().

◆ theShape

const DDSolidShape magneticfield::volumeHandle::theShape
private

Definition at line 80 of file DD4hep_volumeHandle.h.

Referenced by referencePlane(), shape(), sides(), and volumeHandle().