GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
genie::utils::geometry Namespace Reference

Geometry utilities. More...

Functions

void RecursiveExhaust (TGeoVolume *topvol, string volnames, bool exhaust)
 

Detailed Description

Geometry utilities.

Author
Jacek Holeczek
Created:
March 26, 2009
License:
Copyright (c) 2003-2024, The GENIE Collaboration For the full text of the license visit http://copyright.genie-mc.org

Function Documentation

void genie::utils::geometry::RecursiveExhaust ( TGeoVolume *  topvol,
string  volnames,
bool  exhaust 
)

Definition at line 16 of file GeoUtils.cxx.

Referenced by GetGeometry(), and main().

18 {
19 // contributed by Jacek Holeczek
20 //
21 //
22  if (!topvol) return; // just a precaution
23 
24  // check if the "current volume" is in the list of volumes
25  if (topvol->GetName()) // non-null pointer to volume name?
26  {
27  const char *name = topvol->GetName();
28  size_t length = strlen(name);
29  if (length) // non-empty volume name?
30  {
31  size_t ind = 0;
32  while ( (ind = volnames.find_first_of("+-", ind)) != std::string::npos )
33  {
34  ind += 1;
35  if (ind == volnames.length()) break; // just a precaution
36  if ( (!(volnames.compare(ind, length, name))) &&
37  ( ((ind + length) == volnames.length()) ||
38  (volnames[(ind + length)] == '+') ||
39  (volnames[(ind + length)] == '-') ||
40  (volnames[(ind + length)] == ' ') ) )
41  {
42  // a "match" is found ... now check what to do with it
43  if ( volnames[(ind - 1)] == '+')
44  exhaust = false;
45  else if ( volnames[(ind - 1)] == '-')
46  exhaust = true;
47  break; // we are done
48  }
49  }
50  }
51  }
52 
53 #if defined(DEBUG_RECURSIVE_EXHAUST)
54  std::cout << topvol->GetName()
55  << " <" << topvol->GetMedium()->GetName() << ">"
56  << " : " << exhaust << " :";
57 #endif /* defined(DEBUG_RECURSIVE_EXHAUST) */
58 
59  // "exhaust" the "current top volume" if requested
60  if (exhaust)
61  {
62  static TGeoMaterial *matVacuum = ((TGeoMaterial *)0);
63  static TGeoMedium *Vacuum = ((TGeoMedium *)0);
64 
65  if (!Vacuum)
66  {
67 #if defined(DEBUG_RECURSIVE_EXHAUST)
68  std::cout << " Creating the Vaccum material and medium :";
69 #endif /* defined(DEBUG_RECURSIVE_EXHAUST) */
70  // Actually ... one should check if the "Vacuum" TGeoMaterial and
71  // TGeoMedium are already defined in the geometry and, if found,
72  // re-use them ... but I was too lazy to implement it here, sorry.
73  if (!matVacuum) matVacuum = new TGeoMaterial("Vacuum", 0.0, 0.0, 0.0);
74  if (matVacuum) Vacuum = new TGeoMedium("Vacuum", 1, matVacuum);
75  }
76 
77  if (Vacuum) topvol->SetMedium(Vacuum); // "exhaust" volume
78  }
79 
80 #if defined(DEBUG_RECURSIVE_EXHAUST)
81  std::cout << " <" << topvol->GetMedium()->GetName() << ">"
82  << std::endl;
83 #endif /* defined(DEBUG_RECURSIVE_EXHAUST) */
84 
85  // proceed with all daughters of the "current volume"
86  Int_t nd = topvol->GetNdaughters();
87  for (Int_t i = 0; i < nd; i++)
88  {
89  // non-null pointer to node?
90  if (topvol->GetNode(i)) {
92  topvol->GetNode(i)->GetVolume(), volnames, exhaust);
93  }
94  }
95 }
const char * name
void RecursiveExhaust(TGeoVolume *topvol, string volnames, bool exhaust)
Definition: GeoUtils.cxx:16