ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4SolidExtentList.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4SolidExtentList.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 // G4SolidExtentList implementation; a list of (voxel) extents along one axis.
27 //
28 // Author: David C. Williams (davidw@scipp.ucsc.edu)
29 // --------------------------------------------------------------------
30 
31 #include "G4SolidExtentList.hh"
32 #include "G4VoxelLimits.hh"
33 #include "G4GeometryTolerance.hh"
34 
35 // Constructor (default)
36 //
38 {
39  axis = kZAxis;
40  minLimit = -INT_MAX/2;
41  maxLimit = INT_MAX/2;
42 }
43 
44 // Constructor (limited case)
45 //
47  const G4VoxelLimits &voxelLimits )
48 {
49  axis = targetAxis;
50 
51  limited = voxelLimits.IsLimited( axis );
52  if (limited)
53  {
54  minLimit = voxelLimits.GetMinExtent( axis );
55  maxLimit = voxelLimits.GetMaxExtent( axis );
56  }
57  else
58  {
59  minLimit = -INT_MAX/2;
60  maxLimit = INT_MAX/2;
61  }
62 }
63 
64 // Destructor
65 //
67 {
68 }
69 
70 // AddSurface
71 //
72 //
74 {
75  //
76  // Keep track of four surfaces
77  //
78  G4double min, max;
79 
80  surface.GetExtent( axis, min, max );
81 
82  if (min > maxLimit)
83  {
84  //
85  // Nearest surface beyond maximum limit
86  //
87  if (surface.InFrontOf(minAbove,axis)) minAbove = surface;
88  }
89  else if (max < minLimit)
90  {
91  //
92  // Nearest surface below minimum limit
93  //
94  if (surface.BehindOf(maxBelow,axis)) maxBelow = surface;
95  }
96  else
97  {
98  //
99  // Max and min surfaces inside
100  //
101  if (surface.BehindOf(maxSurface,axis)) maxSurface = surface;
102  if (surface.InFrontOf(minSurface,axis)) minSurface = surface;
103  }
104 }
105 
106 // GetExtent
107 //
108 // Return extent after processing all surfaces
109 //
111 {
114  //
115  // Did we have any surfaces within the limits?
116  //
117  if (minSurface.Empty())
118  {
119  //
120  // Nothing! Do we have anything above?
121  //
122  if (minAbove.Empty()) return false;
123 
124  //
125  // Yup. Is it facing inwards?
126  //
127  if (minAbove.GetNormal().operator()(axis) < 0) return false;
128 
129  //
130  // No. We must be entirely within the solid
131  //
132  max = maxLimit + kCarTolerance;
133  min = minLimit - kCarTolerance;
134  return true;
135  }
136 
137  //
138  // Check max surface
139  //
140  if (maxSurface.GetNormal().operator()(axis) < 0)
141  {
142  //
143  // Inward facing: max limit must be embedded within solid
144  //
145  max = maxLimit + kCarTolerance;
146  }
147  else
148  {
149  G4double sMin, sMax;
150  maxSurface.GetExtent( axis, sMin, sMax );
151  max = ( (sMax > maxLimit) ? maxLimit : sMax ) + kCarTolerance;
152  }
153 
154  //
155  // Check min surface
156  //
157  if (minSurface.GetNormal().operator()(axis) > 0)
158  {
159  //
160  // Inward facing: max limit must be embedded within solid
161  //
162  min = minLimit - kCarTolerance;
163  }
164  else
165  {
166  G4double sMin, sMax;
167  minSurface.GetExtent( axis, sMin, sMax );
168  min = ( (sMin < minLimit) ? minLimit : sMin ) - kCarTolerance;
169  }
170 
171  return true;
172 }
173