Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4tgbVolumeMgr.cc
Go to the documentation of this file.
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// G4tgbVolumeMgr implementation
27//
28// Author: P.Arce, CIEMAT (November 2007)
29// --------------------------------------------------------------------
30
31#include "G4tgbVolumeMgr.hh"
32
33#include "G4SystemOfUnits.hh"
34#include "G4tgbVolume.hh"
35#include "G4tgbMaterialMgr.hh"
37
38#include "G4tgrVolumeMgr.hh"
39#include "G4tgrFileReader.hh"
40#include "G4tgrUtils.hh"
41
42#include "G4VSolid.hh"
45#include "G4tgrMessenger.hh"
47
48G4ThreadLocal G4tgbVolumeMgr* G4tgbVolumeMgr::theInstance = nullptr;
49
50// --------------------------------------------------------------------
52{
54 // NOTE: problems building matrices with not enough figures,
55 // like :ROTM RR30 0.866025 0.5 0. -0.5 0.866025 0. 0. 0 -1
56 theDetectorBuilder = new G4tgbDetectorBuilder();
57}
58
59// --------------------------------------------------------------------
61{
62 delete theDetectorBuilder;
63 delete theInstance;
64}
65
66// --------------------------------------------------------------------
68{
69 if(theInstance == nullptr)
70 {
71 theInstance = new G4tgbVolumeMgr();
72 }
73 return theInstance;
74}
75
76// --------------------------------------------------------------------
81
82// --------------------------------------------------------------------
84{
85 const G4tgrVolume* tgrVoltop = theDetectorBuilder->ReadDetector();
86 return theDetectorBuilder->ConstructDetector(tgrVoltop);
87}
88
89// --------------------------------------------------------------------
91{
92 theVolumeList.insert(
93 G4mssvol::value_type(vol->GetName(), const_cast<G4tgbVolume*>(vol)));
94}
95
96// --------------------------------------------------------------------
98{
99 theSolids.insert(
100 G4mmssol::value_type(solid->GetName(), const_cast<G4VSolid*>(solid)));
101}
102
103// --------------------------------------------------------------------
105{
106 theLVs.insert(
107 G4mmslv::value_type(lv->GetName(), const_cast<G4LogicalVolume*>(lv)));
108
109#ifdef G4VERBOSE
111 {
112 G4cout << " G4tgbVolumeMgr::RegisterMe() - Logical volume registered: "
113 << lv->GetName() << G4endl;
114 }
115#endif
116}
117
118// --------------------------------------------------------------------
120{
121 thePVs.insert(
122 G4mmspv::value_type(pv->GetName(), const_cast<G4VPhysicalVolume*>(pv)));
123}
124
125// --------------------------------------------------------------------
127 const G4LogicalVolume* parentLV)
128{
129 theLVInvTree[const_cast<G4LogicalVolume*>(logvol)] =
130 const_cast<G4LogicalVolume*>(parentLV);
131 theLVTree[const_cast<G4LogicalVolume*>(parentLV)] =
132 const_cast<G4LogicalVolume*>(logvol);
133}
134
135// --------------------------------------------------------------------
137{
138 //--------- Loop G4tgbVolume's and create a G4tgbVolume for each DetUnit
140 for(auto cite = vollist.cbegin(); cite != vollist.cend(); ++cite)
141 {
142 G4tgrVolume* tgrvol = const_cast<G4tgrVolume*>((*cite).second);
143 G4tgbVolume* svol = new G4tgbVolume(tgrvol);
144 RegisterMe(svol);
145 }
146}
147
148// --------------------------------------------------------------------
150{
151 G4mssvol::const_iterator cite = theVolumeList.find(volname);
152 if(cite == theVolumeList.cend())
153 {
154 G4String ErrMessage = "G4tgbVolume not found: " + volname + " !";
155 G4Exception("G4tgbVolumeMgr::FindVolume()", "InvalidSetup", FatalException,
156 ErrMessage);
157 return nullptr;
158 }
159 else
160 {
161 return (*cite).second;
162 }
163}
164
165// --------------------------------------------------------------------
167{
168#ifdef G4VERBOSE
170 {
171 G4cout << " G4tgbVolumeMgr::FindG4Solid() - " << name << G4endl;
172 }
173#endif
174
175 G4VSolid* oldSolid = nullptr;
176 std::pair<G4mmssol::iterator, G4mmssol::iterator> mmssdi;
177 mmssdi = theSolids.equal_range(name);
178
179 if(mmssdi.first != mmssdi.second)
180 { // check there is a solid found
181 G4mmssol::const_iterator mmsscite = mmssdi.first;
182
183#ifdef G4VERBOSE
185 {
186 G4cout << " G4tgbVolumeMgr::FindG4Solid() - Solid finding " << name
187 << G4endl;
188 }
189#endif
190 /*
191 G4VSolid overwrites the operator== comparing the addresses
192 => this cannot be used !!
193 Then just compare solids by name =>> POSP tag cannot be used
194 for the moment ...
195 if( solid == *( (*mmsscite).second ) )
196 {
197 oldSolid = (*mmsscite).second;
198 break;
199 }
200 until we write operator== for each solid type, we take a solid
201 with the same name (therefore we will not allow two solids with
202 equal name and different parameters (POSP) )
203 */
204 oldSolid = (*mmsscite).second;
205#ifdef G4VERBOSE
207 {
208 G4cout << " G4tgbVolumeMgr::FindG4Solid() - Solid already found " << name
209 << G4endl;
210 }
211#endif
212 }
213
214#ifdef G4VERBOSE
216 {
217 G4cout << " G4tgbVolumeMgr::FindG4Solid() - Old solid: " << oldSolid
218 << G4endl;
219 }
220#endif
221
222 return oldSolid;
223}
224
225// --------------------------------------------------------------------
227 const G4bool exists)
228{
229 G4mmslv::const_iterator mscite = theLVs.find(name);
230 if(mscite == theLVs.cend())
231 {
232 if(exists)
233 {
234 G4String ErrMessage = "Logical volume name " + name + " not found !";
235 G4Exception("G4tgbVolumeMgr::FindG4LogVol()", "InvalidSetup",
236 FatalException, ErrMessage);
237 }
238 return nullptr;
239 }
240 else
241 {
242 return (*mscite).second;
243 }
244}
245
246// --------------------------------------------------------------------
248 const G4bool exists)
249{
250 G4mmspv::const_iterator mscite = thePVs.find(name);
251 if(mscite == thePVs.cend())
252 {
253 if(exists)
254 {
255 G4String ErrMessage = "Physical volume name " + name + " not found !";
256 G4Exception("G4tgbVolumeMgr::FindG4PhysVol()", "InvalidSetup",
257 FatalException, ErrMessage);
258 }
259 return nullptr;
260 }
261 else
262 {
263 return (*mscite).second;
264 }
265}
266
267// --------------------------------------------------------------------
269{
271 G4VPhysicalVolume* pv = (*(thePVs.find(lv->GetName()))).second;
272
273#ifdef G4VERBOSE
275 {
276 G4cout << " G4tgbVolumeMgr::GetTopPhysVol() - pv: " << pv->GetName()
277 << G4endl;
278 }
279#endif
280
281 return pv;
282}
283
284// --------------------------------------------------------------------
286{
287 //----------- Start from any G4LogicalVolume, because if you go upwards
288 // you will always end at the top
289#ifdef G4VERBOSE
291 {
292 G4cout << " G4tgbVolumeMgr::GetTopLogVol theLVInvTresize "
293 << theLVInvTree.size() << G4endl;
294 }
295#endif
296 if(theLVInvTree.size() == 0)
297 {
298 G4Exception("G4tgbVolumeMgr::GetTopLogVol()", "InvalidSetup",
299 FatalException, "theLVInvTree has no elements.");
300 }
301 G4LogicalVolume* lv = (*(theLVInvTree.begin())).second;
302
303 //------- if first element is the top LV, its parent is 0
304 if(lv == nullptr)
305 {
306 lv = (*(theLVInvTree.begin())).first;
307 }
308 else
309 {
310 while((*(theLVInvTree.find(lv))).second != nullptr)
311 {
312 //---------- get parent of first position
313 lv = (*(theLVInvTree.find(lv))).second;
314#ifdef G4VERBOSE
316 {
317 G4cout << " G4tgbVolumeMgr::GetTopPhysVol: lv " << lv->GetName()
318 << G4endl;
319 }
320#endif
321 }
322 }
323
324 return lv;
325}
326
327// --------------------------------------------------------------------
329{
330 /*
331 G4PhysicalVolumeStore* pvs = G4PhysicalVolumeStore::GetInstance();
332 for( auto cite = pvs->cbegin(); cite != pvs->cend(); ++cite )
333 {
334 thePVTree[ *cite ] = (*cite)->GetMother();
335 thePVInvTree[ (*cite)->GetMother() ] = *cite;
336 }
337 */
338}
339
340// --------------------------------------------------------------------
342{
343 //---------- Dump number of objects of each class
344 G4cout << " @@@@@@@@@@@@@ Dumping Geant4 geometry objects Summary " << G4endl;
345 G4cout << " @@@ Geometry built inside world volume: "
346 << GetTopPhysVol()->GetName() << G4endl;
347 G4cout << " Number of G4VSolid's: " << theSolids.size() << G4endl;
348 G4cout << " Number of G4LogicalVolume's: " << theLVs.size() << G4endl;
349 G4cout << " Number of G4VPhysicalVolume's: " << thePVs.size() << G4endl;
350
352 G4cout << " Number of G4Isotope's: " << mateMgr->GetG4IsotopeList().size()
353 << G4endl;
354 G4cout << " Number of G4Element's: " << mateMgr->GetG4ElementList().size()
355 << G4endl;
356 G4cout << " Number of G4Material's: " << mateMgr->GetG4MaterialList().size()
357 << G4endl;
358
360 G4cout << " Number of G4RotationMatrix's: "
361 << rotmMgr->GetG4RotMatList().size() << G4endl;
362
363 //---------- Dump list of objects of each class
367}
368
369// --------------------------------------------------------------------
371{
372 for(auto cite = theSolids.cbegin(); cite != theSolids.cend(); ++cite)
373 {
374 G4cout << "G4SOLID: " << (*cite).second->GetName() << " of type "
375 << (*cite).second->GetEntityType() << G4endl;
376 }
377}
378
379//---------------------------------------------------------------------
381{
382 G4cout << " @@@@@@@@@@@@@ DUMPING G4LogicalVolume's Tree " << G4endl;
383
385
386 DumpG4LogVolLeaf(lv, 0);
387}
388
389//---------------------------------------------------------------------
391 unsigned int leafDepth)
392{
393 for(std::size_t ii = 0; ii < leafDepth; ++ii)
394 {
395 G4cout << " ";
396 }
397 G4cout << " LV:(" << leafDepth << ")" << lv->GetName() << G4endl;
398
399 //---------- construct the children of this volume
400 // G4LogicalVolume* lvnc = const_cast<G4LogicalVolume*>(lv);
401 // std::pair<G4mlvlv::iterator, G4mlvlv::iterator> children
402 // = theLVTree.equal_range( lvnc );
403 //
404 // G4mlvlv::iterator cite;
405
406 ++leafDepth;
407 // for( cite = children.first; cite != children.second; ++cite )
408 // {
409 // DumpG4LVLeaf( (*cite)->second, leafDepth );
410 // }
411}
412
413// --------------------------------------------------------------------
415{
416 G4cout << " @@@@@@@@@@@@@ DUMPING G4PhysicalVolume's Tree " << G4endl;
417
419
420 DumpG4PhysVolLeaf(pv, 0);
421}
422
423// --------------------------------------------------------------------
425 unsigned int leafDepth)
426{
427 for(std::size_t ii = 0; ii < leafDepth; ++ii)
428 {
429 G4cout << " ";
430 }
431 G4cout << " PV:(" << leafDepth << ")" << pv->GetName() << G4endl;
432
433 //---------- construct the children of this PV
434 // G4VPhysicalVolume* pvnc = const_cast<G4VPhysicalVolume*>(pv);
435 // std::pair<G4mpvpv::iterator, G4mpvpv::iterator> children
436 // = thePVTree.equal_range( pvnc );
437 //
438 // G4mpvpv::iterator cite;
439
440 ++leafDepth;
441 // for( cite = children.first; cite != children.second; ++cite )
442 // {
443 // DumpG4PVLeaf( (*cite)->second, leafDepth );
444 // }
445}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
bool G4bool
Definition G4Types.hh:86
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
std::map< G4String, G4tgrVolume * > G4mapsvol
const G4String & GetName() const
static G4ReflectionFactory * Instance()
void SetScalePrecision(G4double scaleValue)
const G4String & GetName() const
G4String GetName() const
virtual G4VPhysicalVolume * ConstructDetector(const G4tgrVolume *tgrVoltop)
virtual const G4tgrVolume * ReadDetector()
const G4msg4elem GetG4ElementList() const
const G4msg4mate GetG4MaterialList() const
const G4msg4isot GetG4IsotopeList() const
static G4tgbMaterialMgr * GetInstance()
const G4msg4rotm & GetG4RotMatList() const
static G4tgbRotationMatrixMgr * GetInstance()
G4LogicalVolume * FindG4LogVol(const G4String &theName, const G4bool bExists=false)
G4tgbVolume * FindVolume(const G4String &volname)
void AddTextFile(const G4String &fname)
G4VSolid * FindG4Solid(const G4String &name)
void RegisterMe(const G4tgbVolume *vol)
static G4tgbVolumeMgr * GetInstance()
void DumpG4PhysVolLeaf(const G4VPhysicalVolume *pv, unsigned int leafDepth)
G4VPhysicalVolume * ReadAndConstructDetector()
G4LogicalVolume * GetTopLogVol()
void DumpG4LogVolLeaf(const G4LogicalVolume *lv, unsigned int leafDepth)
G4VPhysicalVolume * GetTopPhysVol()
void RegisterChildParentLVs(const G4LogicalVolume *logvol, const G4LogicalVolume *parentLV)
G4VPhysicalVolume * FindG4PhysVol(const G4String &theName, const G4bool bExists=false)
const G4String & GetName() const
void AddTextFile(const G4String &fname)
static G4tgrFileReader * GetInstance()
static G4int GetVerboseLevel()
const G4mapsvol & GetVolumeMap()
static G4tgrVolumeMgr * GetInstance()
#define G4ThreadLocal
Definition tls.hh:77