CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
BaseVolumeHandle.h
Go to the documentation of this file.
1 #ifndef MagneticField_GeomBuilder_BaseVolumeHandle_H
2 #define MagneticField_GeomBuilder_BaseVolumeHandle_H
3 
17 
18 class MagVolume6Faces;
19 
20 namespace magneticfield {
21 
23  public:
28 
29  BaseVolumeHandle(bool expand2Pi = false, bool debugVal = false);
30 
31  // Disallow Default/copy ctor
32  // (we want to handle only pointers!!!)
33  BaseVolumeHandle(const BaseVolumeHandle& v) = delete;
34 
35  virtual ~BaseVolumeHandle();
36 
38  const GlobalPoint& center() const;
39 
41  const double RN() const { return theRN; }
42 
44  const Surface& surface(int which_side) const;
45 
46  const Surface& surface(Sides which_side) const;
47 
49  bool sameSurface(const Surface& s1, Sides which_side, float tolerance = 0.01);
50 
52  bool setSurface(const Surface& s1, Sides which_side);
53 
55  bool isPlaneMatched(int which_side) const { return isAssigned[which_side]; }
56 
57  int references(int which_side) const { // FIXME!
58  /* return surfaces[which_side]->references(); */
59  return 0;
60  }
61 
64 
67 
69  unsigned short volumeno;
70 
72  unsigned short copyno;
73 
74  // Phi ranges: Used by: LessDPhiMax; bSector; bSlab::[min|max]Phi();
75  // MagBSector, MagBRod
76 
78  // FIXME: actually returns phi of the point on median plane of the -phi
79  // surface, except for trapezoids where the absoulte min has been implemented
80  Geom::Phi<float> minPhi() const { return thePhiMin; }
81 
83  // FIXME: actually returns phi of the point on median plane of the +phi
84  // surface
86 
88  // ASSUMPTION: Computed on median Z plane, but this is not a problem since
89  // all Z planes are orthogonal to the beam line in the current geometry.
90  double minZ() const { return surface(SurfaceOrientation::zminus).position().z(); }
91  double maxZ() const { return surface(SurfaceOrientation::zplus).position().z(); }
92 
94  double minR() const { return theRMin; }
95 
97  const GloballyPositioned<float>* placement() const { return refPlane; }
98 
100  virtual std::vector<VolumeSide> sides() const = 0;
101 
104 
105  bool toExpand() const { return expand; }
106 
108  bool isIron() const { return isIronFlag; }
109 
112 
114  virtual DDSolidShape shape() const = 0;
115 
116  protected:
118 
119  // The volume's six surfaces.
121  // If the corresponding surface has been assigned to a shared surface.
122  bool isAssigned[6];
123 
124  // Build phi, z surfaces (common for ddtubs and ddcons)
125  void buildPhiZSurf(double startPhi, double deltaPhi, double zhalf, double rCentr);
126 
127  // Distance from the origin along the normal to the volume's zphi plane.
128  double theRN;
129 
130  // Max and min radius for _any_ point within the volume
131  // FIXME!
132  double theRMin;
133  double theRMax;
135 
136  // The refPlane is the "main plane" for the solid. It corresponds to the
137  // x,y plane in the DDD local frame, and defines a frame where the local
138  // coordinates are the same as in DDD.
140 
141  // the center of the volume
143 
144  // Flag this as a master volume out of wich a 2pi volume should be built
145  // (e.g. central cylinder); this is taken into account by sides().
146  bool expand;
147 
148  // Temporary hack to keep information on material. Will eventually be replaced!
150 
151  const bool debug;
152  };
153 
154  typedef std::vector<BaseVolumeHandle*> handles;
155 
156  // Extractors for precomputed_value_sort() (safe sorting)
157 
158  // To sort volumes in Z
159  struct ExtractZ {
160  double operator()(const BaseVolumeHandle* v) const { return v->center().z(); }
161  };
162 
163  // To sort volumes in abs(Z)
164  struct ExtractAbsZ {
165  double operator()(const BaseVolumeHandle* v) const { return fabs(v->center().z()); }
166  };
167 
168  // To sort volumes in phi (from -pi to pi).
169  struct ExtractPhi {
170  double operator()(const BaseVolumeHandle* v) const {
171  // note that Geom::Phi is implicitly converted to double.
172  // Periodicity is guaranteed.
173  return v->center().phi();
174  }
175  };
176 
177  // To sort volumes based on max phi(from -pi to pi).
178  struct ExtractPhiMax {
179  double operator()(const BaseVolumeHandle* v) const {
180  // note that Geom::Phi is implicitly converted to double.
181  // Periodicity is guaranteed.
182  return v->maxPhi();
183  }
184  };
185 
186  // To sort volumes in R
187  struct ExtractR {
188  double operator()(const BaseVolumeHandle* v) const { return v->center().perp(); }
189  };
190 
191  // To sort volumes in RN (distance of (x,y) plane from origin)
192  struct ExtractRN {
193  double operator()(const BaseVolumeHandle* v) const { return v->RN(); }
194  };
195 
196  // To sort angles within any range SMALLER THAN PI "counter-clockwise",
197  // even if the angles cross the pi boundary.
198  // CAVEAT: // The result is undefined if the input values cover a
199  // range larger than pi!!!
200  struct LessDPhi {
201  bool operator()(double phi1, double phi2) const {
202  // handle periodicity
203  return ((Geom::Phi<float>(phi2) - Geom::Phi<float>(phi1)) > 0.);
204  }
205  };
206 
207  // Compare the Z of volumes.
208  // Should be used ONLY for std::max_element and std::min_element
209  // and NEVER for sorting (use precomputed_value_sort with ExtractZ instead)
210  struct LessZ {
211  bool operator()(const BaseVolumeHandle* v1, const BaseVolumeHandle* v2) const {
212  if (v1->center().z() < v2->center().z())
213  return true;
214  return false;
215  }
216  };
217 
218  inline const char* const newln = "\n";
219  // Newline for formatting debug messages
220  // Intended to be similar to "endl"
221 
222 } // namespace magneticfield
223 
224 #endif
Geom::Phi< float > maxPhi() const
Maximum value of phi covered by the volume.
int references(int which_side) const
double operator()(const BaseVolumeHandle *v) const
T perp() const
Definition: PV3DBase.h:69
Surface::LocalVector LocalVector
double minR() const
Minimum R for any point within the volume.
const double tolerance
double minZ() const
Z limits.
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
bool isPlaneMatched(int which_side) const
if the specified surface has been matched.
unsigned short volumeno
volume number
SurfaceOrientation::GlobalFace Sides
const char *const newln
unsigned short copyno
copy number
GloballyPositioned< float > * refPlane
const Surface & surface(int which_side) const
Get the current surface on specified side.
std::vector< BaseVolumeHandle * > handles
bool isIron() const
Temporary hack to pass information on material. Will eventually be replaced!
Surface::GlobalPoint GlobalPoint
T z() const
Definition: PV3DBase.h:61
int masterSector
The sector for which an interpolator for this class of volumes should be built.
virtual DDSolidShape shape() const =0
Shape of the solid.
double operator()(const BaseVolumeHandle *v) const
Geom::Phi< float > minPhi() const
Minimum value of phi covered by the volume.
MagVolume6Faces * magVolume
Pointer to the final MagVolume (must be set from outside)
const GlobalPoint & center() const
Return the center of the volume.
void buildPhiZSurf(double startPhi, double deltaPhi, double zhalf, double rCentr)
ConstReferenceCountingPointer< Surface > RCPS
std::string name
Name of the volume.
DDSolidShape
Definition: DDSolidShapes.h:6
bool operator()(double phi1, double phi2) const
virtual std::vector< VolumeSide > sides() const =0
The surfaces and they orientation, as required to build a MagVolume.
BaseVolumeHandle(bool expand2Pi=false, bool debugVal=false)
const GloballyPositioned< float > * placement() const
Position and rotation.
const double RN() const
Distance of (x,y) plane from origin.
bool setSurface(const Surface &s1, Sides which_side)
Assign a shared surface perorming sanity checks.
double operator()(const BaseVolumeHandle *v) const
double operator()(const BaseVolumeHandle *v) const
bool operator()(const BaseVolumeHandle *v1, const BaseVolumeHandle *v2) const
double operator()(const BaseVolumeHandle *v) const
double operator()(const BaseVolumeHandle *v) const
const PositionType & position() const
std::string magFile
Name of magnetic field table file.
bool sameSurface(const Surface &s1, Sides which_side, float tolerance=0.01)
Find out if two surfaces are the same physical surface.