source: trunk/source/geometry/volumes/src/G4PVParameterised.cc@ 1330

Last change on this file since 1330 was 1228, checked in by garnier, 16 years ago

update geant4.9.3 tag

File size: 9.5 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27// $Id: G4PVParameterised.cc,v 1.11 2009/09/21 10:27:05 gcosmo Exp $
28// GEANT4 tag $Name: geant4-09-03 $
29//
30//
31// class G4PVParameterised
32//
33// Implementation
34//
35// ----------------------------------------------------------------------
36
37#include "G4PVParameterised.hh"
38#include "G4VPVParameterisation.hh"
39#include "G4AffineTransform.hh"
40#include "G4UnitsTable.hh"
41#include "G4VSolid.hh"
42#include "G4LogicalVolume.hh"
43
44// ----------------------------------------------------------------------
45// Constructor
46//
47G4PVParameterised::G4PVParameterised( const G4String& pName,
48 G4LogicalVolume* pLogical,
49 G4VPhysicalVolume* pMother,
50 const EAxis pAxis,
51 const G4int nReplicas,
52 G4VPVParameterisation *pParam,
53 G4bool pSurfChk )
54 : G4PVReplica(pName, pLogical, pMother, pAxis, nReplicas, 0, 0),
55 fparam(pParam)
56{
57#ifdef G4VERBOSE
58 if ((pMother) && (pMother->IsParameterised()))
59 {
60 G4cout << "WARNING - G4PVParameterised::G4PVParameterised()" << G4endl
61 << " A parameterised volume is being placed" << G4endl
62 << " inside another parameterised volume !" << G4endl
63 << " To make sure that no overlaps are generated," << G4endl
64 << " you should verify the mother replicated shapes" << G4endl
65 << " are of the same type and dimensions." << G4endl
66 << " Mother physical volume: " << pMother->GetName() << G4endl
67 << " Parameterised volume: " << pName << G4endl
68 << " (To switch this warning off, compile with G4_NO_VERBOSE)" << G4endl;
69 }
70#endif
71 if (pSurfChk) { CheckOverlaps(); }
72}
73
74// ----------------------------------------------------------------------
75// Constructor
76//
77G4PVParameterised::G4PVParameterised( const G4String& pName,
78 G4LogicalVolume* pLogical,
79 G4LogicalVolume* pMotherLogical,
80 const EAxis pAxis,
81 const G4int nReplicas,
82 G4VPVParameterisation *pParam,
83 G4bool pSurfChk )
84 : G4PVReplica(pName, pLogical, pMotherLogical, pAxis, nReplicas, 0, 0),
85 fparam(pParam)
86{
87 if (pSurfChk) { CheckOverlaps(); }
88}
89
90// ----------------------------------------------------------------------
91// Fake default constructor - sets only member data and allocates memory
92// for usage restricted to object persistency.
93//
94G4PVParameterised::G4PVParameterised( __void__& a )
95 : G4PVReplica(a), fparam(0)
96{
97}
98
99// ----------------------------------------------------------------------
100// Destructor
101//
102G4PVParameterised::~G4PVParameterised()
103{
104}
105
106// ----------------------------------------------------------------------
107// GetParameterisation
108//
109G4VPVParameterisation* G4PVParameterised::GetParameterisation() const
110{
111 return fparam;
112}
113
114// ----------------------------------------------------------------------
115// IsParameterised
116//
117G4bool G4PVParameterised::IsParameterised() const
118{
119 return true;
120}
121
122// ----------------------------------------------------------------------
123// GetReplicationData
124//
125void G4PVParameterised::GetReplicationData( EAxis& axis,
126 G4int& nReplicas,
127 G4double& width,
128 G4double& offset,
129 G4bool& consuming) const
130{
131 axis = faxis;
132 nReplicas = fnReplicas;
133 width = fwidth;
134 offset = foffset;
135 consuming = false;
136}
137
138// ----------------------------------------------------------------------
139// SetRegularStructureId
140//
141void G4PVParameterised::SetRegularStructureId( G4int Code )
142{
143 G4PVReplica::SetRegularStructureId( Code );
144 // To undertake additional preparation, a derived volume must
145 // redefine this method, while calling also the above method.
146}
147
148
149// ----------------------------------------------------------------------
150// CheckOverlaps
151//
152G4bool
153G4PVParameterised::CheckOverlaps(G4int res, G4double tol, G4bool verbose)
154{
155 if (res<=0) { return false; }
156
157 G4VSolid *solidA = 0, *solidB = 0;
158 G4LogicalVolume *motherLog = GetMotherLogical();
159 G4VSolid *motherSolid = motherLog->GetSolid();
160 std::vector<G4ThreeVector> points;
161
162 if (verbose)
163 {
164 G4cout << "Checking overlaps for parameterised volume "
165 << GetName() << " ... ";
166 }
167
168 for (G4int i=0; i<GetMultiplicity(); i++)
169 {
170 solidA = fparam->ComputeSolid(i, this);
171 solidA->ComputeDimensions(fparam, i, this);
172 fparam->ComputeTransformation(i, this);
173
174 // Create the transformation from daughter to mother
175 //
176 G4AffineTransform Tm( GetRotation(), GetTranslation() );
177
178 // Generate random points on surface according to the given resolution,
179 // transform them to the mother's coordinate system and if no overlaps
180 // with the mother volume, cache them in a vector for later use with
181 // the daughters
182 //
183 for (G4int n=0; n<res; n++)
184 {
185 G4ThreeVector mp = Tm.TransformPoint(solidA->GetPointOnSurface());
186
187 // Checking overlaps with the mother volume
188 //
189 if (motherSolid->Inside(mp)==kOutside)
190 {
191 G4double distin = motherSolid->DistanceToIn(mp);
192 if (distin > tol)
193 {
194 G4cout << G4endl;
195 G4cout << "WARNING - G4PVParameterised::CheckOverlaps()" << G4endl
196 << " Overlap is detected for volume "
197 << GetName() << ", parameterised instance: " << i << G4endl
198 << " with its mother volume "
199 << motherLog->GetName() << G4endl
200 << " at mother local point " << mp << ", "
201 << "overlapping by at least: " << G4BestUnit(distin, "Length")
202 << G4endl;
203 G4Exception("G4PVParameterised::CheckOverlaps()", "InvalidSetup",
204 JustWarning, "Overlap with mother volume !");
205 return true;
206 }
207 }
208 points.push_back(mp);
209 }
210
211 // Checking overlaps with each other parameterised instance
212 //
213 std::vector<G4ThreeVector>::iterator pos;
214 for (G4int j=i+1; j<GetMultiplicity(); j++)
215 {
216 solidB = fparam->ComputeSolid(j,this);
217 solidB->ComputeDimensions(fparam, j, this);
218 fparam->ComputeTransformation(j, this);
219
220 // Create the transformation for daughter volume
221 //
222 G4AffineTransform Td( GetRotation(), GetTranslation() );
223
224 for (pos=points.begin(); pos!=points.end(); pos++)
225 {
226 // Transform each point according to daughter's frame
227 //
228 G4ThreeVector md = Td.Inverse().TransformPoint(*pos);
229
230 if (solidB->Inside(md)==kInside)
231 {
232 G4double distout = solidB->DistanceToOut(md);
233 if (distout > tol)
234 {
235 G4cout << G4endl;
236 G4cout << "WARNING - G4PVParameterised::CheckOverlaps()" << G4endl
237 << " Overlap is detected for volume "
238 << GetName() << ", parameterised instance: " << i << G4endl
239 << " with parameterised volume instance: " << j
240 << G4endl
241 << " at local point " << md << ", "
242 << "overlapping by at least: "
243 << G4BestUnit(distout, "Length")
244 << ", related to volume instance: " << j << "." << G4endl;
245 G4Exception("G4PVParameterised::CheckOverlaps()", "InvalidSetup",
246 JustWarning, "Overlap within parameterised volumes !");
247 return true;
248 }
249 }
250 }
251 }
252 }
253 if (verbose)
254 {
255 G4cout << "OK! " << G4endl;
256 }
257
258 return false;
259}
Note: See TracBrowser for help on using the repository browser.