Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4PVPlacement.cc
이 파일의 문서화 페이지로 가기
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: G4PVPlacement.cc 110402 2018-05-22 11:35:41Z gcosmo $
28 //
29 //
30 // class G4PVPlacement Implementation
31 //
32 // ----------------------------------------------------------------------
33 
34 #include "G4PVPlacement.hh"
35 #include "G4AffineTransform.hh"
36 #include "G4UnitsTable.hh"
37 #include "G4LogicalVolume.hh"
38 #include "G4VSolid.hh"
39 
40 // ----------------------------------------------------------------------
41 // Constructor
42 //
44  const G4ThreeVector &tlate,
45  const G4String& pName,
46  G4LogicalVolume *pLogical,
47  G4VPhysicalVolume *pMother,
48  G4bool pMany,
49  G4int pCopyNo,
50  G4bool pSurfChk )
51  : G4VPhysicalVolume(pRot,tlate,pName,pLogical,pMother),
52  fmany(pMany), fallocatedRotM(false), fcopyNo(pCopyNo)
53 {
54  if (pMother)
55  {
56  G4LogicalVolume* motherLogical = pMother->GetLogicalVolume();
57  if (pLogical == motherLogical)
58  {
59  G4Exception("G4PVPlacement::G4PVPlacement()", "GeomVol0002",
60  FatalException, "Cannot place a volume inside itself!");
61  }
62  SetMotherLogical(motherLogical);
63  motherLogical->AddDaughter(this);
64  if (pSurfChk) { CheckOverlaps(); }
65  }
66 }
67 
68 // ----------------------------------------------------------------------
69 // Constructor
70 //
72  const G4String& pName,
73  G4LogicalVolume *pLogical,
74  G4VPhysicalVolume *pMother,
75  G4bool pMany,
76  G4int pCopyNo,
77  G4bool pSurfChk )
78  : G4VPhysicalVolume(NewPtrRotMatrix(Transform3D.getRotation().inverse()),
79  Transform3D.getTranslation(),pName,pLogical,pMother),
80  fmany(pMany), fcopyNo(pCopyNo)
81 {
82  fallocatedRotM = (GetRotation() != 0);
83  if (pMother)
84  {
85  G4LogicalVolume* motherLogical = pMother->GetLogicalVolume();
86  if (pLogical == motherLogical)
87  G4Exception("G4PVPlacement::G4PVPlacement()", "GeomVol0002",
88  FatalException, "Cannot place a volume inside itself!");
89  SetMotherLogical(motherLogical);
90  motherLogical->AddDaughter(this);
91  if (pSurfChk) { CheckOverlaps(); }
92  }
93 }
94 
95 // ----------------------------------------------------------------------
96 // Constructor
97 //
98 // The logical volume of the mother is utilised (not the physical)
99 //
101  const G4ThreeVector &tlate,
102  G4LogicalVolume *pCurrentLogical,
103  const G4String& pName,
104  G4LogicalVolume *pMotherLogical,
105  G4bool pMany,
106  G4int pCopyNo,
107  G4bool pSurfChk )
108  : G4VPhysicalVolume(pRot,tlate,pName,pCurrentLogical,0),
109  fmany(pMany), fallocatedRotM(false), fcopyNo(pCopyNo)
110 {
111  if (pCurrentLogical == pMotherLogical)
112  {
113  G4Exception("G4PVPlacement::G4PVPlacement()", "GeomVol0002",
114  FatalException, "Cannot place a volume inside itself!");
115  }
116  SetMotherLogical(pMotherLogical);
117  if (pMotherLogical) { pMotherLogical->AddDaughter(this); }
118  if ((pSurfChk) && (pMotherLogical)) { CheckOverlaps(); }
119 }
120 
121 
122 // ----------------------------------------------------------------------
123 // Constructor
124 //
126  G4LogicalVolume *pCurrentLogical,
127  const G4String& pName,
128  G4LogicalVolume *pMotherLogical,
129  G4bool pMany,
130  G4int pCopyNo,
131  G4bool pSurfChk )
132  : G4VPhysicalVolume(0,Transform3D.getTranslation(),pName,pCurrentLogical,0),
133  fmany(pMany), fcopyNo(pCopyNo)
134 {
135  if (pCurrentLogical == pMotherLogical)
136  {
137  G4Exception("G4PVPlacement::G4PVPlacement()", "GeomVol0002",
138  FatalException, "Cannot place a volume inside itself!");
139  }
140  SetRotation( NewPtrRotMatrix(Transform3D.getRotation().inverse()) );
141  fallocatedRotM = (GetRotation() != 0);
142  SetMotherLogical(pMotherLogical);
143  if (pMotherLogical) { pMotherLogical->AddDaughter(this); }
144  if ((pSurfChk) && (pMotherLogical)) { CheckOverlaps(); }
145 }
146 
147 // ----------------------------------------------------------------------
148 // Fake default constructor - sets only member data and allocates memory
149 // for usage restricted to object persistency.
150 //
152  : G4VPhysicalVolume(a), fmany(false), fallocatedRotM(0), fcopyNo(0)
153 {
154 }
155 
156 // ----------------------------------------------------------------------
157 // Destructor
158 //
160 {
161  if( fallocatedRotM ){ delete this->GetRotation() ; }
162 }
163 
164 // ----------------------------------------------------------------------
165 // IsMany
166 //
168 {
169  return fmany;
170 }
171 
172 // ----------------------------------------------------------------------
173 // SetCopyNo
174 //
176 {
177  fcopyNo= newCopyNo;
178 }
179 
180 // ----------------------------------------------------------------------
181 // IsReplicated
182 //
184 {
185  return false;
186 }
187 
188 // ----------------------------------------------------------------------
189 // IsParameterised
190 //
192 {
193  return false;
194 }
195 
196 // ----------------------------------------------------------------------
197 // GetParameterisation
198 //
200 {
201  return 0;
202 }
203 
204 // ----------------------------------------------------------------------
205 // GetReplicationData
206 //
207 void G4PVPlacement::
209 {
210  // No-operations
211 }
212 
213 // ----------------------------------------------------------------------
214 // IsRegularRepeatedStructure
215 //
216 // This is for specialised repeated volumes (replicas, parameterised vol.)
217 //
219 {
220  return false;
221 }
222 
223 // ----------------------------------------------------------------------
224 // IsRegularRepeatedStructure
225 //
226 // This is for specialised repeated volumes (replicas, parameterised vol.)
227 //
229 {
230  return 0;
231 }
232 
233 // ----------------------------------------------------------------------
234 // CheckOverlaps
235 //
237  G4bool verbose, G4int maxErr)
238 {
239  if (res<=0) { return false; }
240 
241  G4VSolid* solid = GetLogicalVolume()->GetSolid();
242  G4LogicalVolume* motherLog = GetMotherLogical();
243  if (!motherLog) { return false; }
244 
245  G4int trials = 0;
246  G4bool retval = false;
247 
248  G4VSolid* motherSolid = motherLog->GetSolid();
249 
250  if (verbose)
251  {
252  G4cout << "Checking overlaps for volume " << GetName() << " ... ";
253  }
254 
255  // Create the transformation from daughter to mother
256  //
258 
259  for (G4int n=0; n<res; n++)
260  {
261  // Generate a random point on the solid's surface
262  //
263  G4ThreeVector point = solid->GetPointOnSurface();
264 
265  // Transform the generated point to the mother's coordinate system
266  //
267  G4ThreeVector mp = Tm.TransformPoint(point);
268 
269  // Checking overlaps with the mother volume
270  //
271  if (motherSolid->Inside(mp)==kOutside)
272  {
273  G4double distin = motherSolid->DistanceToIn(mp);
274  if (distin > tol)
275  {
276  trials++; retval = true;
277  std::ostringstream message;
278  message << "Overlap with mother volume !" << G4endl
279  << " Overlap is detected for volume "
280  << GetName() << ':' << GetCopyNo() << G4endl
281  << " with its mother volume "
282  << motherLog->GetName() << G4endl
283  << " at mother local point " << mp << ", "
284  << "overlapping by at least: "
285  << G4BestUnit(distin, "Length");
286  if (trials>=maxErr)
287  {
288  message << G4endl
289  << "NOTE: Reached maximum fixed number -" << maxErr
290  << "- of overlaps reports for this volume !";
291  }
292  G4Exception("G4PVPlacement::CheckOverlaps()",
293  "GeomVol1002", JustWarning, message);
294  if (trials>=maxErr) { return true; }
295  }
296  }
297 
298  // Checking overlaps with each 'sister' volume
299  //
300  for (G4int i=0; i<motherLog->GetNoDaughters(); i++)
301  {
302  G4VPhysicalVolume* daughter = motherLog->GetDaughter(i);
303 
304  if (daughter == this) { continue; }
305 
306  // Create the transformation for daughter volume and transform point
307  //
308  G4AffineTransform Td( daughter->GetRotation(),
309  daughter->GetTranslation() );
310  G4ThreeVector md = Td.InverseTransformPoint(mp);
311 
312  G4VSolid* daughterSolid = daughter->GetLogicalVolume()->GetSolid();
313  if (daughterSolid->Inside(md)==kInside)
314  {
315  G4double distout = daughterSolid->DistanceToOut(md);
316  if (distout > tol)
317  {
318  trials++; retval = true;
319  std::ostringstream message;
320  message << "Overlap with volume already placed !" << G4endl
321  << " Overlap is detected for volume "
322  << GetName() << ':' << GetCopyNo() << G4endl
323  << " with " << daughter->GetName()
324  << ':' << daughter->GetCopyNo() << " volume's"
325  << G4endl
326  << " local point " << md << ", "
327  << "overlapping by at least: "
328  << G4BestUnit(distout,"Length");
329  if (trials>=maxErr)
330  {
331  message << G4endl
332  << "NOTE: Reached maximum fixed number -" << maxErr
333  << "- of overlaps reports for this volume !";
334  }
335  G4Exception("G4PVPlacement::CheckOverlaps()",
336  "GeomVol1002", JustWarning, message);
337  if (trials>=maxErr) { return true; }
338  }
339  }
340 
341  // Now checking that 'sister' volume is not totally included and
342  // overlapping. Do it only once, for the first point generated
343  //
344  if (n==0)
345  {
346  // Generate a single point on the surface of the 'sister' volume
347  // and verify that the point is NOT inside the current volume
348 
349  G4ThreeVector dPoint = daughterSolid->GetPointOnSurface();
350 
351  // Transform the generated point to the mother's coordinate system
352  // and finally to current volume's coordinate system
353  //
354  G4ThreeVector mp2 = Td.TransformPoint(dPoint);
355  G4ThreeVector msi = Tm.InverseTransformPoint(mp2);
356 
357  if (solid->Inside(msi)==kInside)
358  {
359  trials++; retval = true;
360  std::ostringstream message;
361  message << "Overlap with volume already placed !" << G4endl
362  << " Overlap is detected for volume "
363  << GetName() << ':' << GetCopyNo() << G4endl
364  << " apparently fully encapsulating volume "
365  << daughter->GetName() << ':' << daughter->GetCopyNo()
366  << " at the same level !";
367  G4Exception("G4PVPlacement::CheckOverlaps()",
368  "GeomVol1002", JustWarning, message);
369  if (trials>=maxErr) { return true; }
370  }
371  }
372  }
373  }
374 
375  if (verbose)
376  {
377  G4cout << "OK! " << G4endl;
378  }
379 
380  return retval;
381 }
382 
383 // ----------------------------------------------------------------------
384 // NewPtrRotMatrix
385 //
386 // Auxiliary function for 2nd & 4th constructors (those with G4Transform3D)
387 // Creates a new rotation matrix on the heap (using "new") and copies its
388 // argument into it.
389 //
390 // NOTE: Ownership of the returned pointer is left to the caller !
391 // No entity is currently responsible to delete this memory.
392 //
395 {
396  G4RotationMatrix *pRotMatrix;
397  if ( RotMat.isIdentity() )
398  {
399  pRotMatrix = 0;
400  }
401  else
402  {
403  pRotMatrix = new G4RotationMatrix(RotMat);
404  }
405  // fallocatedRotM= ! (RotMat.isIdentity());
406 
407  return pRotMatrix;
408 }
CLHEP::HepRotation getRotation() const
void SetMotherLogical(G4LogicalVolume *pMother)
bool isIdentity() const
Definition: Rotation.cc:172
G4bool IsParameterised() const
std::vector< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33
G4LogicalVolume * GetLogicalVolume() const
CLHEP::HepRotation G4RotationMatrix
#define G4endl
Definition: G4ios.hh:61
void message(RunManager *runmanager)
Definition: ts_scorers.cc:72
G4int GetNoDaughters() const
virtual G4ThreeVector GetPointOnSurface() const
Definition: G4VSolid.cc:152
virtual G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const =0
const G4ThreeVector & GetTranslation() const
G4ThreeVector InverseTransformPoint(const G4ThreeVector &vec) const
virtual EInside Inside(const G4ThreeVector &p) const =0
double G4double
Definition: G4Types.hh:76
bool G4bool
Definition: G4Types.hh:79
G4LogicalVolume * GetMotherLogical() const
G4VPVParameterisation * GetParameterisation() const
G4bool IsReplicated() const
static G4RotationMatrix * NewPtrRotMatrix(const G4RotationMatrix &RotMat)
void GetReplicationData(EAxis &axis, G4int &nReplicas, G4double &width, G4double &offset, G4bool &consuming) const
virtual G4int GetCopyNo() const =0
void AddDaughter(G4VPhysicalVolume *p)
virtual ~G4PVPlacement()
G4PVPlacement(G4RotationMatrix *pRot, const G4ThreeVector &tlate, G4LogicalVolume *pCurrentLogical, const G4String &pName, G4LogicalVolume *pMotherLogical, G4bool pMany, G4int pCopyNo, G4bool pSurfChk=false)
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
G4int GetCopyNo() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
int G4int
Definition: G4Types.hh:78
EAxis
Definition: geomdefs.hh:54
G4GLOB_DLL std::ostream G4cout
virtual G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=0, G4ThreeVector *n=0) const =0
G4VSolid * GetSolid() const
G4bool IsRegularStructure() const
void SetRotation(G4RotationMatrix *)
Char_t n[5]
const G4RotationMatrix * GetRotation() const
G4bool IsMany() const
void SetCopyNo(G4int CopyNo)
G4bool fallocatedRotM
G4ThreeVector TransformPoint(const G4ThreeVector &vec) const
G4int GetRegularStructureId() const
HepRotation inverse() const
const G4String & GetName() const
G4VPhysicalVolume * GetDaughter(const G4int i) const
G4bool CheckOverlaps(G4int res=1000, G4double tol=0., G4bool verbose=true, G4int maxErr=1)
const G4String & GetName() const