VGM Version 5.3
Loading...
Searching...
No Matches
Polyhedra.cxx
Go to the documentation of this file.
1// $Id$
2
3// -----------------------------------------------------------------------
4// The Geant4GM package of the Virtual Geometry Model
5// Copyright (C) 2007, Ivana Hrivnacova
6// All rights reserved.
7//
8// For the licensing terms see vgm/LICENSE.
9// Contact: ivana@ipno.in2p3.fr
10// -----------------------------------------------------------------------
11
12//
13// Class Polyhedra
14// ---------------
15// VGM implementation for Geant4 polyhedra solid.
16// If reflected, the parameters are changed as follows:
17// sphi, dphi --> sphi', dphi'
18// nofSides --> nofSides'
19// nofZplanes --> nofZplanes'
20// z[i] --> -z'[i]
21// rin, rout --> rin', rout'
22//
23// Author: Ivana Hrivnacova; IPN Orsay
24
25#include "ClhepVGM/Units.h"
26
29
30#include "G4Polyhedra.hh"
31#include "G4ReflectedSolid.hh"
32
33const int Geant4GM::Polyhedra::fgkMaxNofZPlanes = 50;
34double* Geant4GM::Polyhedra::fgZBuffer = 0;
35double* Geant4GM::Polyhedra::fgRinBuffer = 0;
36double* Geant4GM::Polyhedra::fgRoutBuffer = 0;
37
38//_____________________________________________________________________________
39Geant4GM::Polyhedra::Polyhedra(const std::string& name, double sphi,
40 double dphi, int nofSides, int nofZplanes, double* z, double* rin,
41 double* rout)
42 : VGM::ISolid(),
43 VGM::IPolyhedra(),
44 BaseVGM::VPolyhedra(),
45 fIsReflected(false),
46 fZValuesRefl(0),
47 fPolyhedra(0)
48{
59
60 // Apply units
61
62 double* z2 = new double[nofZplanes];
63 double* rin2 = new double[nofZplanes];
64 double* rout2 = new double[nofZplanes];
65
66 for (int i = 0; i < nofZplanes; i++) {
67 z2[i] = z[i] / ClhepVGM::Units::Length();
68 rin2[i] = rin[i] / ClhepVGM::Units::Length();
69 rout2[i] = rout[i] / ClhepVGM::Units::Length();
70 }
71
72 fPolyhedra = new G4Polyhedra(name, sphi / ClhepVGM::Units::Angle(),
73 dphi / ClhepVGM::Units::Angle(), nofSides, nofZplanes, z2, rin2, rout2);
74
75 Geant4GM::SolidMap::Instance()->AddSolid(this, fPolyhedra);
76
77 CreateBuffers();
78
79 delete[] z2;
80 delete[] rin2;
81 delete[] rout2;
82}
83
84//_____________________________________________________________________________
86 G4Polyhedra* phedra, G4ReflectedSolid* reflPhedra)
87 : VGM::ISolid(),
88 VGM::IPolyhedra(),
89 BaseVGM::VPolyhedra(),
90 fIsReflected(false),
91 fZValuesRefl(0),
92 fPolyhedra(phedra)
93{
95
96 if (reflPhedra) {
97 int nofZplanes = phedra->GetOriginalParameters()->Num_z_planes;
98 double* zValues = phedra->GetOriginalParameters()->Z_values;
99 fZValuesRefl = new double[nofZplanes];
100 for (int i = 0; i < nofZplanes; i++) fZValuesRefl[i] = -zValues[i];
101
102 fIsReflected = true;
103 Geant4GM::SolidMap::Instance()->AddSolid(this, reflPhedra);
104 }
105 else
106 Geant4GM::SolidMap::Instance()->AddSolid(this, phedra);
107
108 CreateBuffers();
109}
110
111//_____________________________________________________________________________
113 : VGM::ISolid(), VGM::IPolyhedra(), BaseVGM::VPolyhedra()
114{
116}
117
118//_____________________________________________________________________________
120 : VGM::ISolid(rhs), VGM::IPolyhedra(rhs), BaseVGM::VPolyhedra(rhs)
121{
123}
124
125//_____________________________________________________________________________
127{
128 //
129 delete[] fZValuesRefl;
130}
131
132//_____________________________________________________________________________
133void Geant4GM::Polyhedra::CreateBuffers()
134{
135 if (!fgZBuffer) fgZBuffer = new double[fgkMaxNofZPlanes];
136 if (!fgRinBuffer) fgRinBuffer = new double[fgkMaxNofZPlanes];
137 if (!fgRoutBuffer) fgRoutBuffer = new double[fgkMaxNofZPlanes];
138}
139
140//_____________________________________________________________________________
141std::string Geant4GM::Polyhedra::Name() const { return fPolyhedra->GetName(); }
142
143//_____________________________________________________________________________
145{
146 return fPolyhedra->GetStartPhi() * ClhepVGM::Units::Angle();
147}
148
149//_____________________________________________________________________________
151{
152 double deltaPhi = fPolyhedra->GetEndPhi() - fPolyhedra->GetStartPhi();
153
154 return deltaPhi * ClhepVGM::Units::Angle();
155}
156
157//_____________________________________________________________________________
159{
160 return fPolyhedra->GetOriginalParameters()->numSide;
161}
162
163//_____________________________________________________________________________
165{
166 return fPolyhedra->GetOriginalParameters()->Num_z_planes;
167}
168
169//_____________________________________________________________________________
171{
172 int nofZPlanes = NofZPlanes();
173 if (nofZPlanes > fgkMaxNofZPlanes) {
174 nofZPlanes = fgkMaxNofZPlanes;
175 std::cerr << "+++ Warning +++" << std::endl;
176 std::cerr << " Number of Zplanes > size of buffer." << std::endl;
177 std::cerr << " only " << nofZPlanes << " values are returned."
178 << std::endl;
179 }
180
181 for (int i = 0; i < nofZPlanes; i++)
182 if (!fIsReflected) {
183 fgZBuffer[i] = fPolyhedra->GetOriginalParameters()->Z_values[i];
184 fgZBuffer[i] *= ClhepVGM::Units::Length();
185 }
186 else
187 fgZBuffer[i] = fZValuesRefl[i] * ClhepVGM::Units::Length();
188
189 return fgZBuffer;
190}
191
192//_____________________________________________________________________________
194{
195 int nofZPlanes = NofZPlanes();
196 if (nofZPlanes > fgkMaxNofZPlanes) {
197 nofZPlanes = fgkMaxNofZPlanes;
198 std::cerr << "+++ Warning +++" << std::endl;
199 std::cerr << " Number of Zplanes > size of buffer." << std::endl;
200 std::cerr << " only " << nofZPlanes << " values are returned."
201 << std::endl;
202 }
203
204 for (int i = 0; i < nofZPlanes; i++) {
205 fgRinBuffer[i] = fPolyhedra->GetOriginalParameters()->Rmin[i];
206 fgRinBuffer[i] *= ConvertRadiusFactor();
207 fgRinBuffer[i] *= ClhepVGM::Units::Length();
208 }
209
210 return fgRinBuffer;
211}
212
213//_____________________________________________________________________________
215{
216 int nofZPlanes = NofZPlanes();
217 if (nofZPlanes > fgkMaxNofZPlanes) {
218 nofZPlanes = fgkMaxNofZPlanes;
219 std::cerr << "+++ Warning +++" << std::endl;
220 std::cerr << " Number of Zplanes > size of buffer." << std::endl;
221 std::cerr << " only " << nofZPlanes << " values are returned."
222 << std::endl;
223 }
224
225 for (int i = 0; i < nofZPlanes; i++) {
226 fgRoutBuffer[i] = fPolyhedra->GetOriginalParameters()->Rmax[i];
227 fgRoutBuffer[i] *= ConvertRadiusFactor();
228 fgRoutBuffer[i] *= ClhepVGM::Units::Length();
229 }
230
231 return fgRoutBuffer;
232}
static double Length()
Return CLHEP default length unit in VGM units.
Definition Units.cxx:83
static double Angle()
Return CLHEP default angle unit in VGM units.
Definition Units.cxx:92
VGM implementation for Geant4 polyhedra solid.
Definition Polyhedra.h:33
virtual double * OuterRadiusValues() const
Return the array of outer radius of the planes in mm.
virtual int NofSides() const
Return number of sides of the cross section between the given phi limits.
virtual double * ZValues() const
Return the array of z positions of the planes in mm.
virtual double DeltaPhi() const
Return opening phi angle of the segment in deg.
virtual double StartPhi() const
Return starting phi angle of the segment in deg.
virtual int NofZPlanes() const
Return number of planes perpendicular to the z axis.
virtual std::string Name() const
Return the name of this solid.
virtual double * InnerRadiusValues() const
Return the array of innner radius of the planes in mm.
static SolidMap * Instance()
Definition SolidMap.cxx:28
void AddSolid(VGM::ISolid *, G4VSolid *)
Definition SolidMap.cxx:59
BaseVGM utilities.
Definition utilities.h:23
VGM interfaces.
Definition VMedium.h:28