Geant4  10.02.p03
G4STRead Class Reference

#include <G4STRead.hh>

Collaboration diagram for G4STRead:

Public Member Functions

G4LogicalVolumeRead (const G4String &, G4Material *mediumMaterial, G4Material *solidMaterial)
 

Private Member Functions

void TessellatedRead (const std::string &)
 
void FacetRead (const std::string &)
 
void PhysvolRead (const std::string &)
 
void ReadGeom (const G4String &)
 
void ReadTree (const G4String &)
 

Private Attributes

G4Boxworld_box
 
G4ThreeVector world_extent
 
G4Materialsolid_material
 
G4LogicalVolumeworld_volume
 
std::vector< G4TessellatedSolid * > tessellatedList
 
std::map< G4TessellatedSolid *, G4LogicalVolume * > volumeMap
 

Detailed Description

Definition at line 55 of file G4STRead.hh.

Member Function Documentation

◆ FacetRead()

void G4STRead::FacetRead ( const std::string &  line)
private

Definition at line 69 of file G4STRead.cc.

70 {
71  if (tessellatedList.size()==0)
72  {
73  G4Exception("G4STRead::FacetRead()", "ReadError", FatalException,
74  "A solid must be defined before defining a facet!");
75  }
76 
77  if (line[2]=='3') // Triangular facet
78  {
79  G4double x1,y1,z1;
80  G4double x2,y2,z2;
81  G4double x3,y3,z3;
82 
83  std::istringstream stream(line.substr(4));
84  stream >> x1 >> y1 >> z1 >> x2 >> y2 >> z2 >> x3 >> y3 >> z3;
85  tessellatedList.back()->
86  AddFacet(new G4TriangularFacet(G4ThreeVector(x1,y1,z1),
87  G4ThreeVector(x2,y2,z2),
88  G4ThreeVector(x3,y3,z3), ABSOLUTE));
89  }
90  else if (line[2]=='4') // Quadrangular facet
91  {
92  G4double x1,y1,z1;
93  G4double x2,y2,z2;
94  G4double x3,y3,z3;
95  G4double x4,y4,z4;
96 
97  std::istringstream stream(line.substr(4));
98  stream >> x1 >> y1 >> z1 >> x2 >> y2 >> z2
99  >> x3 >> y3 >> z3 >> x4 >> y4 >> z4;
100  tessellatedList.back()->
101  AddFacet(new G4QuadrangularFacet(G4ThreeVector(x1,y1,z1),
102  G4ThreeVector(x2,y2,z2),
103  G4ThreeVector(x3,y3,z3),
104  G4ThreeVector(x4,y4,z4), ABSOLUTE));
105  }
106  else
107  {
108  G4Exception("G4STRead::FacetRead()", "ReadError", FatalException,
109  "Number of vertices per facet should be either 3 or 4!");
110  }
111 }
Double_t y2[nxs]
Double_t y1[nxs]
Double_t x2[nxs]
CLHEP::Hep3Vector G4ThreeVector
std::vector< G4TessellatedSolid * > tessellatedList
Definition: G4STRead.hh:75
Double_t x1[nxs]
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
double G4double
Definition: G4Types.hh:76
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PhysvolRead()

void G4STRead::PhysvolRead ( const std::string &  line)
private

Definition at line 113 of file G4STRead.cc.

114 {
115  G4int level;
116  G4String name;
117  G4double r1,r2,r3;
118  G4double r4,r5,r6;
119  G4double r7,r8,r9;
120  G4double pX,pY,pZ;
121  G4double n1,n2,n3,n4,n5;
122 
123  std::istringstream stream(line.substr(2));
124  stream >> level >> name >> r1 >> r2 >> r3 >> n1 >> r4 >> r5 >> r6
125  >> n2 >> r7 >> r8 >> r9 >> n3 >> pX >> pY >> pZ >> n4 >> n5;
126  std::string::size_type idx = name.rfind("_");
127  if (idx!=std::string::npos)
128  {
129  name.resize(idx);
130  }
131  else
132  {
133  G4Exception("G4STRead::PhysvolRead()", "ReadError",
134  FatalException, "Invalid input stream!");
135  return;
136  }
137 
138  G4cout << "G4STRead: Placing tessellated solid: " << name << G4endl;
139 
140  G4TessellatedSolid* tessellated = 0;
141 
142  for (size_t i=0; i<tessellatedList.size(); i++)
143  { // Find the volume for this physvol!
144  if (tessellatedList[i]->GetName() == G4String(name))
145  {
146  tessellated = tessellatedList[i];
147  break;
148  }
149  }
150 
151  if (tessellated == 0)
152  {
153  G4String error_msg = "Referenced solid '" + name + "' not found!";
154  G4Exception("G4STRead::PhysvolRead()", "ReadError",
155  FatalException, error_msg);
156  }
157  if (volumeMap.find(tessellated) == volumeMap.end())
158  {
159  G4String error_msg = "Referenced solid '" + name
160  + "' is not associated with a logical volume!";
161  G4Exception("G4STRead::PhysvolRead()", "InvalidSetup",
162  FatalException, error_msg);
163  }
164  const G4RotationMatrix rot(G4ThreeVector(r1,r2,r3),
165  G4ThreeVector(r4,r5,r6),
166  G4ThreeVector(r7,r8,r9));
167  const G4ThreeVector pos(pX,pY,pZ);
168 
169  new G4PVPlacement(G4Transform3D(rot.inverse(),pos),
170  volumeMap[tessellated], name+"_PV", world_volume, 0, 0);
171  // Note: INVERSE of rotation is needed!!!
172 
173  G4double minx,miny,minz;
174  G4double maxx,maxy,maxz;
175  const G4VoxelLimits limits;
176 
177  tessellated->CalculateExtent(kXAxis,limits,
178  G4AffineTransform(rot,pos),minx,maxx);
179  tessellated->CalculateExtent(kYAxis,limits,
180  G4AffineTransform(rot,pos),miny,maxy);
181  tessellated->CalculateExtent(kZAxis,limits,
182  G4AffineTransform(rot,pos),minz,maxz);
183 
184  if (world_extent.x() < std::fabs(minx))
185  { world_extent.setX(std::fabs(minx)); }
186  if (world_extent.y() < std::fabs(miny))
187  { world_extent.setY(std::fabs(miny)); }
188  if (world_extent.z() < std::fabs(minz))
189  { world_extent.setZ(std::fabs(minz)); }
190  if (world_extent.x() < std::fabs(maxx))
191  { world_extent.setX(std::fabs(maxx)); }
192  if (world_extent.y() < std::fabs(maxy))
193  { world_extent.setY(std::fabs(maxy)); }
194  if (world_extent.z() < std::fabs(maxz))
195  { world_extent.setZ(std::fabs(maxz)); }
196 }
G4LogicalVolume * world_volume
Definition: G4STRead.hh:74
G4ThreeVector world_extent
Definition: G4STRead.hh:72
CLHEP::Hep3Vector G4ThreeVector
G4String name
Definition: TRTMaterials.hh:40
virtual G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const
std::vector< G4TessellatedSolid * > tessellatedList
Definition: G4STRead.hh:75
int G4int
Definition: G4Types.hh:78
void setY(double)
void setZ(double)
void setX(double)
G4GLOB_DLL std::ostream G4cout
HepGeom::Transform3D G4Transform3D
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
double x() const
double y() const
double z() const
#define G4endl
Definition: G4ios.hh:61
std::map< G4TessellatedSolid *, G4LogicalVolume * > volumeMap
Definition: G4STRead.hh:76
double G4double
Definition: G4Types.hh:76
static const G4double pos
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Read()

G4LogicalVolume * G4STRead::Read ( const G4String name,
G4Material mediumMaterial,
G4Material solidMaterial 
)

Definition at line 253 of file G4STRead.cc.

255 {
256  if (mediumMaterial == 0)
257  {
258  G4Exception("G4STRead::Read()", "InvalidSetup", FatalException,
259  "Pointer to medium material is not valid!");
260  }
261  if (solidMaterial == 0)
262  {
263  G4Exception("G4STRead::Read()", "InvalidSetup", FatalException,
264  "Pointer to solid material is not valid!");
265  }
266 
267  solid_material = solidMaterial;
268 
269  world_box = new G4Box("TessellatedWorldBox",kInfinity,kInfinity,kInfinity);
270  // We don't know the extent of the world yet!
271  world_volume = new G4LogicalVolume(world_box, mediumMaterial,
272  "TessellatedWorldLV", 0, 0, 0);
273  world_extent = G4ThreeVector(0,0,0);
274 
275  ReadGeom(name+".geom");
276  ReadTree(name+".tree");
277 
278  // Now setting the world extent ...
279  //
286 
287  return world_volume;
288 }
G4LogicalVolume * world_volume
Definition: G4STRead.hh:74
G4ThreeVector world_extent
Definition: G4STRead.hh:72
void SetZHalfLength(G4double dz)
Definition: G4Box.cc:171
static const G4double kInfinity
Definition: geomdefs.hh:42
CLHEP::Hep3Vector G4ThreeVector
Definition: G4Box.hh:64
G4double GetXHalfLength() const
G4double GetZHalfLength() const
void ReadTree(const G4String &)
Definition: G4STRead.cc:229
G4Material * solid_material
Definition: G4STRead.hh:73
G4Box * world_box
Definition: G4STRead.hh:71
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
double x() const
G4double GetYHalfLength() const
double y() const
double z() const
void SetYHalfLength(G4double dy)
Definition: G4Box.cc:151
void SetXHalfLength(G4double dx)
Definition: G4Box.cc:131
void ReadGeom(const G4String &)
Definition: G4STRead.cc:198
Here is the call graph for this function:

◆ ReadGeom()

void G4STRead::ReadGeom ( const G4String name)
private

Definition at line 198 of file G4STRead.cc.

199 {
200  G4cout << "G4STRead: Reading '" << name << "'..." << G4endl;
201 
202  std::ifstream GeomFile(name);
203 
204  if (!GeomFile)
205  {
206  G4String error_msg = "Cannot open file: " + name;
207  G4Exception("G4STRead::ReadGeom()", "ReadError",
208  FatalException, error_msg);
209  }
210 
211  tessellatedList.clear();
212  volumeMap.clear();
213  std::string line;
214 
215  while (getline(GeomFile,line))
216  {
217  if (line[0] == 'f') { TessellatedRead(line); } else
218  if (line[0] == 'p') { FacetRead(line); }
219  }
220 
221  if (tessellatedList.size()>0) // Finish the last solid!
222  {
223  tessellatedList.back()->SetSolidClosed(true);
224  }
225 
226  G4cout << "G4STRead: Reading '" << name << "' done." << G4endl;
227 }
void TessellatedRead(const std::string &)
Definition: G4STRead.cc:48
G4String name
Definition: TRTMaterials.hh:40
std::vector< G4TessellatedSolid * > tessellatedList
Definition: G4STRead.hh:75
G4GLOB_DLL std::ostream G4cout
void FacetRead(const std::string &)
Definition: G4STRead.cc:69
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
#define G4endl
Definition: G4ios.hh:61
std::map< G4TessellatedSolid *, G4LogicalVolume * > volumeMap
Definition: G4STRead.hh:76
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReadTree()

void G4STRead::ReadTree ( const G4String name)
private

Definition at line 229 of file G4STRead.cc.

230 {
231  G4cout << "G4STRead: Reading '" << name << "'..." << G4endl;
232 
233  std::ifstream TreeFile(name);
234 
235  if (!TreeFile)
236  {
237  G4String error_msg = "Cannot open file: " + name;
238  G4Exception("G4STRead::ReadTree()", "ReadError",
239  FatalException, error_msg);
240  }
241 
242  std::string line;
243 
244  while (getline(TreeFile,line))
245  {
246  if (line[0] == 'g') { PhysvolRead(line); }
247  }
248 
249  G4cout << "G4STRead: Reading '" << name << "' done." << G4endl;
250 }
G4String name
Definition: TRTMaterials.hh:40
void PhysvolRead(const std::string &)
Definition: G4STRead.cc:113
G4GLOB_DLL std::ostream G4cout
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
#define G4endl
Definition: G4ios.hh:61
Here is the call graph for this function:
Here is the caller graph for this function:

◆ TessellatedRead()

void G4STRead::TessellatedRead ( const std::string &  line)
private

Definition at line 48 of file G4STRead.cc.

49 {
50  if (tessellatedList.size()>0)
51  {
52  tessellatedList.back()->SetSolidClosed(true);
53  // Finish the previous solid at first!
54  }
55 
56  std::istringstream stream(line.substr(2));
57 
58  G4String name;
59  stream >> name;
60 
61  G4TessellatedSolid* tessellated = new G4TessellatedSolid(name);
62  volumeMap[tessellated] =
63  new G4LogicalVolume(tessellated, solid_material, name+"_LV" , 0, 0, 0);
64  tessellatedList.push_back(tessellated);
65 
66  G4cout << "G4STRead: Reading solid: " << name << G4endl;
67 }
G4String name
Definition: TRTMaterials.hh:40
std::vector< G4TessellatedSolid * > tessellatedList
Definition: G4STRead.hh:75
G4GLOB_DLL std::ostream G4cout
G4Material * solid_material
Definition: G4STRead.hh:73
#define G4endl
Definition: G4ios.hh:61
std::map< G4TessellatedSolid *, G4LogicalVolume * > volumeMap
Definition: G4STRead.hh:76
Here is the caller graph for this function:

Member Data Documentation

◆ solid_material

G4Material* G4STRead::solid_material
private

Definition at line 73 of file G4STRead.hh.

◆ tessellatedList

std::vector<G4TessellatedSolid*> G4STRead::tessellatedList
private

Definition at line 75 of file G4STRead.hh.

◆ volumeMap

std::map<G4TessellatedSolid*,G4LogicalVolume*> G4STRead::volumeMap
private

Definition at line 76 of file G4STRead.hh.

◆ world_box

G4Box* G4STRead::world_box
private

Definition at line 71 of file G4STRead.hh.

◆ world_extent

G4ThreeVector G4STRead::world_extent
private

Definition at line 72 of file G4STRead.hh.

◆ world_volume

G4LogicalVolume* G4STRead::world_volume
private

Definition at line 74 of file G4STRead.hh.


The documentation for this class was generated from the following files: