CMS 3D CMS Logo

BaseVolumeHandle.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 "BaseVolumeHandle.h"
8 
13 
14 #include <cassert>
15 #include <string>
16 #include <iterator>
17 #include <iomanip>
18 #include <iostream>
19 
20 using namespace SurfaceOrientation;
21 using namespace std;
22 using namespace magneticfield;
23 
24 BaseVolumeHandle::BaseVolumeHandle(bool expand2Pi, bool debugVal)
25  : magVolume(nullptr),
26  masterSector(1),
27  theRN(0.),
28  theRMin(0.),
29  theRMax(0.),
30  refPlane(nullptr),
31  expand(expand2Pi),
32  isIronFlag(false),
33  debug(debugVal) {}
34 
36  if (refPlane != nullptr) {
37  delete refPlane;
38  refPlane = nullptr;
39  }
40 }
41 
43 
44 void BaseVolumeHandle::buildPhiZSurf(double startPhi, double deltaPhi, double zhalf, double rCentr) {
45  // This is 100% equal for cons and tubs!!!
46 
47  GlobalVector planeXAxis = refPlane->toGlobal(LocalVector(1, 0, 0));
48  GlobalVector planeYAxis = refPlane->toGlobal(LocalVector(0, 1, 0));
49  GlobalVector planeZAxis = refPlane->toGlobal(LocalVector(0, 0, 1));
50 
51  // Local Y axis of the faces at +-phi.
52  GlobalVector y_phiplus = refPlane->toGlobal(LocalVector(cos(startPhi + deltaPhi), sin(startPhi + deltaPhi), 0.));
53  GlobalVector y_phiminus = refPlane->toGlobal(LocalVector(cos(startPhi), sin(startPhi), 0.));
54 
55  Surface::RotationType rot_Z(planeXAxis, planeYAxis);
56  Surface::RotationType rot_phiplus(planeZAxis, y_phiplus);
57  Surface::RotationType rot_phiminus(planeZAxis, y_phiminus);
58 
59  GlobalPoint pos_zplus(center_.x(), center_.y(), center_.z() + zhalf);
60  GlobalPoint pos_zminus(center_.x(), center_.y(), center_.z() - zhalf);
61  // BEWARE: in this case, the origin for phiplus,phiminus surfaces is
62  // at radius R and not on a plane passing by center_ orthogonal to the radius.
63  GlobalPoint pos_phiplus(
64  refPlane->toGlobal(LocalPoint(rCentr * cos(startPhi + deltaPhi), rCentr * sin(startPhi + deltaPhi), 0.)));
65  GlobalPoint pos_phiminus(refPlane->toGlobal(LocalPoint(rCentr * cos(startPhi), rCentr * sin(startPhi), 0.)));
66  surfaces[zplus] = new Plane(pos_zplus, rot_Z);
67  surfaces[zminus] = new Plane(pos_zminus, rot_Z);
68  surfaces[phiplus] = new Plane(pos_phiplus, rot_phiplus);
69  surfaces[phiminus] = new Plane(pos_phiminus, rot_phiminus);
70 
71  if (debug) {
72  cout << "Actual Center at: " << center_ << " R " << center_.perp() << " phi " << center_.phi() << endl;
73  cout << "RN " << theRN << endl;
74 
75  cout << "pos_zplus " << pos_zplus << " " << pos_zplus.perp() << " " << pos_zplus.phi() << endl
76  << "pos_zminus " << pos_zminus << " " << pos_zminus.perp() << " " << pos_zminus.phi() << endl
77  << "pos_phiplus " << pos_phiplus << " " << pos_phiplus.perp() << " " << pos_phiplus.phi() << endl
78  << "pos_phiminus " << pos_phiminus << " " << pos_phiminus.perp() << " " << pos_phiminus.phi() << endl;
79 
80  cout << "y_phiplus " << y_phiplus << endl;
81  cout << "y_phiminus " << y_phiminus << endl;
82 
83  cout << "rot_Z " << surfaces[zplus]->toGlobal(LocalVector(0., 0., 1.)) << endl
84  << "rot_phi+ " << surfaces[phiplus]->toGlobal(LocalVector(0., 0., 1.)) << " phi "
85  << surfaces[phiplus]->toGlobal(LocalVector(0., 0., 1.)).phi() << endl
86  << "rot_phi- " << surfaces[phiminus]->toGlobal(LocalVector(0., 0., 1.)) << " phi "
87  << surfaces[phiminus]->toGlobal(LocalVector(0., 0., 1.)).phi() << endl;
88  }
89 
90  // // Check ordering.
91  if (debug) {
92  if (pos_zplus.z() < pos_zminus.z()) {
93  cout << "*** WARNING: pos_zplus < pos_zminus " << endl;
94  }
95  if (Geom::Phi<float>(pos_phiplus.phi() - pos_phiminus.phi()) < 0.) {
96  cout << "*** WARNING: pos_phiplus < pos_phiminus " << endl;
97  }
98  }
99 }
100 
101 bool BaseVolumeHandle::sameSurface(const Surface &s1, Sides which_side, float tolerance) {
102  //Check for null comparison
103  if (&s1 == (surfaces[which_side]).get()) {
104  if (debug)
105  cout << " sameSurface: OK (same ptr)" << endl;
106  return true;
107  }
108 
109  const float maxtilt = 0.999;
110 
111  const Surface &s2 = *(surfaces[which_side]);
112  // Try with a plane.
113  const Plane *p1 = dynamic_cast<const Plane *>(&s1);
114  if (p1 != nullptr) {
115  const Plane *p2 = dynamic_cast<const Plane *>(&s2);
116  if (p2 == nullptr) {
117  if (debug)
118  cout << " sameSurface: different types" << endl;
119  return false;
120  }
121 
122  if ((fabs(p1->normalVector().dot(p2->normalVector())) > maxtilt) &&
123  (fabs((p1->toLocal(p2->position())).z()) < tolerance)) {
124  if (debug)
125  cout << " sameSurface: OK " << fabs(p1->normalVector().dot(p2->normalVector())) << " "
126  << fabs((p1->toLocal(p2->position())).z()) << endl;
127  return true;
128  } else {
129  if (debug)
130  cout << " sameSurface: not the same: " << p1->normalVector() << p1->position() << endl
131  << " " << p2->normalVector() << p2->position() << endl
132  << fabs(p1->normalVector().dot(p2->normalVector())) << " " << (p1->toLocal(p2->position())).z() << endl;
133  return false;
134  }
135  }
136 
137  // Try with a cylinder.
138  const Cylinder *cy1 = dynamic_cast<const Cylinder *>(&s1);
139  if (cy1 != nullptr) {
140  const Cylinder *cy2 = dynamic_cast<const Cylinder *>(&s2);
141  if (cy2 == nullptr) {
142  if (debug)
143  cout << " sameSurface: different types" << endl;
144  return false;
145  }
146  // Assume axis is the same!
147  if (fabs(cy1->radius() - cy2->radius()) < tolerance) {
148  return true;
149  } else {
150  return false;
151  }
152  }
153 
154  // Try with a cone.
155  const Cone *co1 = dynamic_cast<const Cone *>(&s1);
156  if (co1 != nullptr) {
157  const Cone *co2 = dynamic_cast<const Cone *>(&s2);
158  if (co2 == nullptr) {
159  if (debug)
160  cout << " sameSurface: different types" << endl;
161  return false;
162  }
163  // FIXME
164  if (fabs(co1->openingAngle() - co2->openingAngle()) < maxtilt &&
165  (co1->vertex() - co2->vertex()).mag() < tolerance) {
166  return true;
167  } else {
168  return false;
169  }
170  }
171 
172  if (debug)
173  cout << " sameSurface: unknown surfaces..." << endl;
174  return false;
175 }
176 
177 bool BaseVolumeHandle::setSurface(const Surface &s1, Sides which_side) {
178  //Check for null assignment
179  if (&s1 == (surfaces[which_side]).get()) {
180  isAssigned[which_side] = true;
181  return true;
182  }
183 
184  if (!sameSurface(s1, which_side)) {
185  cout << "***ERROR: setSurface: trying to assign a surface that does not match destination surface. Skipping."
186  << endl;
187  const Surface &s2 = *(surfaces[which_side]);
188  //FIXME: Just planes for the time being!!!
189  const Plane *p1 = dynamic_cast<const Plane *>(&s1);
190  const Plane *p2 = dynamic_cast<const Plane *>(&s2);
191  if (p1 != nullptr && p2 != nullptr)
192  cout << p1->normalVector() << p1->position() << endl << p2->normalVector() << p2->position() << endl;
193  return false;
194  }
195 
196  if (isAssigned[which_side]) {
197  if (&s1 != (surfaces[which_side]).get()) {
198  cout << "*** WARNING BaseVolumeHandle::setSurface: trying to reassign a surface to a different surface instance"
199  << endl;
200  return false;
201  }
202  } else {
203  surfaces[which_side] = &s1;
204  isAssigned[which_side] = true;
205  if (debug)
206  cout << " Volume " << name << " # " << copyno << " Assigned: " << (int)which_side << endl;
207  return true;
208  }
209 
210  return false; // let the compiler be happy
211 }
212 
213 const Surface &BaseVolumeHandle::surface(Sides which_side) const { return *(surfaces[which_side]); }
214 
215 const Surface &BaseVolumeHandle::surface(int which_side) const {
216  assert(which_side >= 0 && which_side < 6);
217  return *(surfaces[which_side]);
218 }
Vector3DBase
Definition: Vector3DBase.h:8
Cone::openingAngle
Geom::Theta< float > openingAngle() const
Angle of the cone.
Definition: Cone.h:50
SurfaceOrientation::phiplus
Definition: Surface.h:19
TkRotation< float >
Cylinder.h
Cylinder::radius
Scalar radius() const
Radius of the cylinder.
Definition: Cylinder.h:64
funct::false
false
Definition: Factorize.h:29
magneticfield::BaseVolumeHandle::debug
const bool debug
Definition: BaseVolumeHandle.h:151
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
magneticfield::BaseVolumeHandle::center
const GlobalPoint & center() const
Return the center of the volume.
Definition: BaseVolumeHandle.cc:42
gather_cfg.cout
cout
Definition: gather_cfg.py:144
magneticfield::BaseVolumeHandle::surface
const Surface & surface(int which_side) const
Get the current surface on specified side.
Definition: BaseVolumeHandle.cc:215
magneticfield::BaseVolumeHandle::isAssigned
bool isAssigned[6]
Definition: BaseVolumeHandle.h:122
magneticfield
Definition: MagFieldConfig.h:22
cms::cuda::assert
assert(be >=bs)
CoordinateSets.h
Surface
Definition: Surface.h:36
Cone::vertex
GlobalPoint vertex() const
Global position of the cone vertex.
Definition: Cone.h:47
indexGen.s2
s2
Definition: indexGen.py:107
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
Plane.h
debug
#define debug
Definition: HDRShower.cc:19
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
magneticfield::BaseVolumeHandle::theRN
double theRN
Definition: BaseVolumeHandle.h:128
SiPixelRawToDigiRegional_cfi.deltaPhi
deltaPhi
Definition: SiPixelRawToDigiRegional_cfi.py:9
magneticfield::BaseVolumeHandle::~BaseVolumeHandle
virtual ~BaseVolumeHandle()
Definition: BaseVolumeHandle.cc:35
p2
double p2[4]
Definition: TauolaWrapper.h:90
magneticfield::BaseVolumeHandle::sameSurface
bool sameSurface(const Surface &s1, Sides which_side, float tolerance=0.01)
Find out if two surfaces are the same physical surface.
Definition: BaseVolumeHandle.cc:101
Point3DBase< float, GlobalTag >
Cone
Definition: Cone.h:17
SurfaceOrientation::zminus
Definition: Surface.h:19
Cone.h
magneticfield::BaseVolumeHandle::center_
GlobalPoint center_
Definition: BaseVolumeHandle.h:142
magneticfield::BaseVolumeHandle::LocalVector
Surface::LocalVector LocalVector
Definition: BaseVolumeHandle.h:26
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
createfilelist.int
int
Definition: createfilelist.py:10
tolerance
const double tolerance
Definition: HGCalGeomParameters.cc:29
Geom::Phi< float >
p1
double p1[4]
Definition: TauolaWrapper.h:89
BaseVolumeHandle.h
get
#define get
magneticfield::BaseVolumeHandle::copyno
unsigned short copyno
copy number
Definition: BaseVolumeHandle.h:72
mag
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Definition: Basic3DVectorLD.h:127
std
Definition: JetResolutionObject.h:76
magneticfield::BaseVolumeHandle::name
std::string name
Name of the volume.
Definition: BaseVolumeHandle.h:63
magneticfield::BaseVolumeHandle::buildPhiZSurf
void buildPhiZSurf(double startPhi, double deltaPhi, double zhalf, double rCentr)
Definition: BaseVolumeHandle.cc:44
magneticfield::BaseVolumeHandle::surfaces
RCPS surfaces[6]
Definition: BaseVolumeHandle.h:120
SurfaceOrientation::zplus
Definition: Surface.h:19
Plane
Definition: Plane.h:16
SurfaceOrientation::GlobalFace
GlobalFace
Definition: Surface.h:19
SurfaceOrientation::phiminus
Definition: Surface.h:19
Cylinder
Definition: Cylinder.h:19
magneticfield::BaseVolumeHandle::setSurface
bool setSurface(const Surface &s1, Sides which_side)
Assign a shared surface perorming sanity checks.
Definition: BaseVolumeHandle.cc:177
magneticfield::BaseVolumeHandle::refPlane
GloballyPositioned< float > * refPlane
Definition: BaseVolumeHandle.h:139
SurfaceOrientation
Definition: Surface.h:17
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