ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4tgbVolumeMgr.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4tgbVolumeMgr.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 //
28 //
29 // class G4tgbVolumeMgr
30 
31 // History:
32 // - Created. P.Arce, CIEMAT (November 2007)
33 // -------------------------------------------------------------------------
34 
35 #include "G4tgbVolumeMgr.hh"
36 
37 #include "G4SystemOfUnits.hh"
38 #include "G4tgbVolume.hh"
39 #include "G4tgbMaterialMgr.hh"
41 
42 #include "G4tgrVolumeMgr.hh"
43 #include "G4tgrFileReader.hh"
44 #include "G4tgrUtils.hh"
45 
46 #include "G4VSolid.hh"
47 #include "G4PhysicalVolumeStore.hh"
48 #include "G4ReflectionFactory.hh"
49 #include "G4tgrMessenger.hh"
50 #include "G4tgbDetectorBuilder.hh"
51 
53 
54 //---------------------------------------------------------------------
56 {
58  // NOTE: problems building matrices with not enough figures,
59  // like :ROTM RR30 0.866025 0.5 0. -0.5 0.866025 0. 0. 0 -1
61 }
62 
63 
64 //---------------------------------------------------------------------
66 {
67  delete theDetectorBuilder;
68  delete theInstance;
69 }
70 
71 
72 //---------------------------------------------------------------------
74 {
75  if( !theInstance )
76  {
78  }
79  return theInstance;
80 }
81 
82 
83 //---------------------------------------------------------------------
85 {
87 }
88 
89 
90 //---------------------------------------------------------------------
92 {
93  const G4tgrVolume* tgrVoltop = theDetectorBuilder->ReadDetector();
94  return theDetectorBuilder->ConstructDetector(tgrVoltop);
95 }
96 
97 
98 //---------------------------------------------------------------------
100 {
101  theVolumeList.insert( G4mssvol::value_type( vol->GetName(),
102  const_cast<G4tgbVolume*>(vol) ) );
103 }
104 
105 
106 //---------------------------------------------------------------------
108 {
109  theSolids.insert( G4mmssol::value_type( solid->GetName(),
110  const_cast<G4VSolid*>(solid) ) );
111 }
112 
113 
114 //---------------------------------------------------------------------
116 {
117  theLVs.insert( G4mmslv::value_type( lv->GetName(),
118  const_cast<G4LogicalVolume*>(lv) ) );
119 
120 #ifdef G4VERBOSE
122  {
123  G4cout << " G4tgbVolumeMgr::RegisterMe() - Logical volume registered: "
124  << lv->GetName() << G4endl;
125  }
126 #endif
127 }
128 
129 //---------------------------------------------------------------------
131 {
132  thePVs.insert( G4mmspv::value_type( pv->GetName(),
133  const_cast<G4VPhysicalVolume*>(pv) ) );
134 }
135 
136 
137 //---------------------------------------------------------------------
139  const G4LogicalVolume* parentLV )
140 {
141  theLVInvTree[const_cast<G4LogicalVolume*>(logvol)] =
142  const_cast<G4LogicalVolume*>(parentLV);
143  theLVTree[const_cast<G4LogicalVolume*>(parentLV)] =
144  const_cast<G4LogicalVolume*>(logvol);
145 }
146 
147 //---------------------------------------------------------------------
149 {
150  //--------- Loop G4tgbVolume's and create a G4tgbVolume for each DetUnit
151  G4mapsvol::iterator cite;
153  for(cite = vollist.begin(); cite != vollist.end(); cite++)
154  {
155  G4tgrVolume* tgrvol = const_cast<G4tgrVolume*>( (*cite).second );
156  G4tgbVolume* svol = new G4tgbVolume( tgrvol );
157  RegisterMe( svol );
158  }
159 }
160 
161 
162 //---------------------------------------------------------------------
164 {
165  G4mssvol::const_iterator cite = theVolumeList.find( volname );
166  if( cite == theVolumeList.end() )
167  {
168  G4String ErrMessage = "G4tgbVolume not found: " + volname + " !";
169  G4Exception("G4tgbVolumeMgr::FindVolume()", "InvalidSetup",
170  FatalException, ErrMessage);
171  }
172  return (*cite).second;
173 }
174 
175 
176 //---------------------------------------------------------------------
178 {
179 #ifdef G4VERBOSE
181  {
182  G4cout << " G4tgbVolumeMgr::FindG4Solid() - " << name << G4endl;
183  }
184 #endif
185 
186  G4VSolid* oldSolid = 0;
187  std::pair<G4mmssol::iterator, G4mmssol::iterator> mmssdi;
188  mmssdi = theSolids.equal_range( name );
189 
190  if( mmssdi.first != mmssdi.second ) { // check there is a solid found
191  G4mmssol::const_iterator mmsscite = mmssdi.first;
192 
193 #ifdef G4VERBOSE
195  {
196  G4cout << " G4tgbVolumeMgr::FindG4Solid() - Solid finding "
197  << name << G4endl;
198  }
199 #endif
200  /*
201  G4VSolid overwrites the operator== comparing the addresses
202  => this cannot be used !!
203  Then just compare solids by name =>> POSP tag cannot be used
204  for the moment ...
205  if( solid == *( (*mmsscite).second ) )
206  {
207  oldSolid = (*mmsscite).second;
208  break;
209  }
210  until we write operator== for each solid type, we take a solid
211  with the same name (therefore we will not allow two solids with
212  equal name and different parameters (POSP) )
213  */
214  oldSolid = (*mmsscite).second;
215 #ifdef G4VERBOSE
217  {
218  G4cout << " G4tgbVolumeMgr::FindG4Solid() - Solid already found "
219  << name << G4endl;
220  }
221 #endif
222  }
223 
224 #ifdef G4VERBOSE
226  {
227  G4cout << " G4tgbVolumeMgr::FindG4Solid() - Old solid: "
228  << oldSolid << G4endl;
229  }
230 #endif
231 
232  return oldSolid;
233 }
234 
235 
236 //---------------------------------------------------------------------
239 {
240  G4mmslv::const_iterator mscite = theLVs.find( name );
241  if( mscite == theLVs.end() )
242  {
243  if( exists )
244  {
245  G4String ErrMessage = "Logical volume name " + name + " not found !";
246  G4Exception("G4tgbVolumeMgr::FindG4LogVol()", "InvalidSetup",
247  FatalException, ErrMessage);
248  }
249  return 0;
250  }
251  else
252  {
253  return (*mscite).second;
254  }
255 }
256 
257 //---------------------------------------------------------------------
260 {
261  G4mmspv::const_iterator mscite = thePVs.find( name );
262  if( mscite == thePVs.end() )
263  {
264  if( exists )
265  {
266  G4String ErrMessage = "Physical volume name " + name + " not found !";
267  G4Exception("G4tgbVolumeMgr::FindG4PhysVol()", "InvalidSetup",
268  FatalException, ErrMessage);
269  }
270  return 0;
271  }
272  else
273  {
274  return (*mscite).second;
275  }
276 }
277 
278 
279 //---------------------------------------------------------------------
281 {
282  G4LogicalVolume* lv = GetTopLogVol();
283  G4VPhysicalVolume* pv = ( *(thePVs.find( lv->GetName() )) ).second;
284 
285 #ifdef G4VERBOSE
287  {
288  G4cout << " G4tgbVolumeMgr::GetTopPhysVol() - pv: "
289  << pv->GetName() << G4endl;
290  }
291 #endif
292 
293  return pv;
294 }
295 
296 
297 //---------------------------------------------------------------------
299 {
300  //----------- Start from any G4LogicalVolume, because if you go upwards
301  // you will always end at the top
302 #ifdef G4VERBOSE
304  {
305  G4cout << " G4tgbVolumeMgr::GetTopLogVol theLVInvTresize "
306  << theLVInvTree.size() << G4endl;
307  }
308 #endif
309  if( theLVInvTree.size() == 0 )
310  {
311  G4Exception("G4tgbVolumeMgr::GetTopLogVol()", "InvalidSetup",
312  FatalException, "theLVInvTree has no elements.");
313  }
314  G4LogicalVolume* lv = (*(theLVInvTree.begin())).second;
315 
316  //------- if first element is the top LV, its parent is 0
317  if( lv == 0 )
318  {
319  lv = (*(theLVInvTree.begin())).first;
320  }
321  else
322  {
323  while( (*(theLVInvTree.find( lv ))).second != 0)
324  {
325  //---------- get parent of first position
326  lv = (*(theLVInvTree.find( lv ))).second;
327 #ifdef G4VERBOSE
329  {
330  G4cout << " G4tgbVolumeMgr::GetTopPhysVol: lv "
331  << lv->GetName() << G4endl;
332  }
333 #endif
334  }
335  }
336 
337  return lv;
338 }
339 
340 
341 //---------------------------------------------------------------------
343 {
344 /*
345  G4PhysicalVolumeStore* pvs = G4PhysicalVolumeStore::GetInstance();
346  std::vector<G4VPhysicalVolume*>::iterator cite;
347  for( cite = pvs->begin(); cite != pvs->end(); cite++ )
348  {
349  thePVTree[ *cite ] = (*cite)->GetMother();
350  thePVInvTree[ (*cite)->GetMother() ] = *cite;
351  }
352 */
353 }
354 
355 
356 //---------------------------------------------------------------------
358 {
359  //---------- Dump number of objects of each class
360  G4cout << " @@@@@@@@@@@@@ Dumping Geant4 geometry objects Summary " << G4endl;
361  G4cout << " @@@ Geometry built inside world volume: "
362  << GetTopPhysVol()->GetName() << G4endl;
363  G4cout << " Number of G4VSolid's: " << theSolids.size() << G4endl;
364  G4cout << " Number of G4LogicalVolume's: " << theLVs.size() << G4endl;
365  G4cout << " Number of G4VPhysicalVolume's: " << thePVs.size() << G4endl;
366 
368  G4cout << " Number of G4Isotope's: "
369  << mateMgr->GetG4IsotopeList().size() << G4endl;
370  G4cout << " Number of G4Element's: "
371  << mateMgr->GetG4ElementList().size() << G4endl;
372  G4cout << " Number of G4Material's: "
373  << mateMgr->GetG4MaterialList().size() << G4endl;
374 
376  G4cout << " Number of G4RotationMatrix's: "
377  << rotmMgr->GetG4RotMatList().size() << G4endl;
378 
379  //---------- Dump list of objects of each class
380  DumpG4SolidList();
383 }
384 
385 
386 //---------------------------------------------------------------------
388 {
389  G4mmssol::const_iterator cite;
390  for( cite = theSolids.begin(); cite != theSolids.end(); cite++)
391  {
392  G4cout << "G4SOLID: " << (*cite).second->GetName()
393  << " of type " << (*cite).second->GetEntityType() << G4endl;
394  }
395 }
396 
397 
398 //---------------------------------------------------------------------
400 {
401  G4cout << " @@@@@@@@@@@@@ DUMPING G4LogicalVolume's Tree " << G4endl;
402 
404 
405  DumpG4LogVolLeaf(lv, 0);
406 }
407 
408 
409 //---------------------------------------------------------------------
411  unsigned int leafDepth)
412 {
413  for( size_t ii=0; ii < leafDepth; ii++ )
414  {
415  G4cout << " ";
416  }
417  G4cout << " LV:(" << leafDepth << ")" << lv->GetName() << G4endl;
418 
419  //---------- construct the children of this volume
420  // G4LogicalVolume* lvnc = const_cast<G4LogicalVolume*>(lv);
421  // std::pair<G4mlvlv::iterator, G4mlvlv::iterator> children
422  // = theLVTree.equal_range( lvnc );
423  //
424  // G4mlvlv::iterator cite;
425 
426  leafDepth++;
427  // for( cite = children.first; cite != children.second; cite++ )
428  // {
429  // DumpG4LVLeaf( (*cite)->second, leafDepth );
430  // }
431 }
432 
433 
434 
435 //---------------------------------------------------------------------
437 {
438  G4cout << " @@@@@@@@@@@@@ DUMPING G4PhysicalVolume's Tree " << G4endl;
439 
441 
442  DumpG4PhysVolLeaf(pv, 0);
443 }
444 
445 
446 //---------------------------------------------------------------------
448  unsigned int leafDepth)
449 {
450  for( size_t ii=0; ii < leafDepth; ii++ )
451  {
452  G4cout << " ";
453  }
454  G4cout << " PV:(" << leafDepth << ")" << pv->GetName() << G4endl;
455 
456  //---------- construct the children of this PV
457  // G4VPhysicalVolume* pvnc = const_cast<G4VPhysicalVolume*>(pv);
458  // std::pair<G4mpvpv::iterator, G4mpvpv::iterator> children
459  // = thePVTree.equal_range( pvnc );
460  //
461  // G4mpvpv::iterator cite;
462 
463  leafDepth++;
464  // for( cite = children.first; cite != children.second; cite++ )
465  // {
466  // DumpG4PVLeaf( (*cite)->second, leafDepth );
467  // }
468 }