GeoUtils.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*
3  Copyright (c) 2003-2019, The GENIE Collaboration
4  For the full text of the license visit http://copyright.genie-mc.org
5  or see $GENIE/LICENSE
6 
7  Author: Costas Andreopoulos <costas.andreopoulos \at stfc.ac.uk>
8  University of Liverpool & STFC Rutherford Appleton Lab - May 06, 2004
9 
10  For documentation see the corresponding header file.
11 
12  Important revisions after version 2.0.0 :
13  @ Mar 26, 2009 - CA
14  That file was added in 2.5.1 - Added RecursiveExhaust() method contributed
15  by Jacek Holeczek.
16 
17 */
18 //____________________________________________________________________________
19 
20 #include <TGeoVolume.h>
21 #include <TGeoNode.h>
22 
24 
25 //___________________________________________________________________________
27  TGeoVolume *topvol, string volnames, bool exhaust)
28 {
29 // contributed by Jacek Holeczek
30 //
31 //
32  if (!topvol) return; // just a precaution
33 
34  // check if the "current volume" is in the list of volumes
35  if (topvol->GetName()) // non-null pointer to volume name?
36  {
37  const char *name = topvol->GetName();
38  size_t length = strlen(name);
39  if (length) // non-empty volume name?
40  {
41  size_t ind = 0;
42  while ( (ind = volnames.find_first_of("+-", ind)) != std::string::npos )
43  {
44  ind += 1;
45  if (ind == volnames.length()) break; // just a precaution
46  if ( (!(volnames.compare(ind, length, name))) &&
47  ( ((ind + length) == volnames.length()) ||
48  (volnames[(ind + length)] == '+') ||
49  (volnames[(ind + length)] == '-') ||
50  (volnames[(ind + length)] == ' ') ) )
51  {
52  // a "match" is found ... now check what to do with it
53  if ( volnames[(ind - 1)] == '+')
54  exhaust = false;
55  else if ( volnames[(ind - 1)] == '-')
56  exhaust = true;
57  break; // we are done
58  }
59  }
60  }
61  }
62 
63 #if defined(DEBUG_RECURSIVE_EXHAUST)
64  std::cout << topvol->GetName()
65  << " <" << topvol->GetMedium()->GetName() << ">"
66  << " : " << exhaust << " :";
67 #endif /* defined(DEBUG_RECURSIVE_EXHAUST) */
68 
69  // "exhaust" the "current top volume" if requested
70  if (exhaust)
71  {
72  static TGeoMaterial *matVacuum = ((TGeoMaterial *)0);
73  static TGeoMedium *Vacuum = ((TGeoMedium *)0);
74 
75  if (!Vacuum)
76  {
77 #if defined(DEBUG_RECURSIVE_EXHAUST)
78  std::cout << " Creating the Vaccum material and medium :";
79 #endif /* defined(DEBUG_RECURSIVE_EXHAUST) */
80  // Actually ... one should check if the "Vacuum" TGeoMaterial and
81  // TGeoMedium are already defined in the geometry and, if found,
82  // re-use them ... but I was too lazy to implement it here, sorry.
83  if (!matVacuum) matVacuum = new TGeoMaterial("Vacuum", 0.0, 0.0, 0.0);
84  if (matVacuum) Vacuum = new TGeoMedium("Vacuum", 1, matVacuum);
85  }
86 
87  if (Vacuum) topvol->SetMedium(Vacuum); // "exhaust" volume
88  }
89 
90 #if defined(DEBUG_RECURSIVE_EXHAUST)
91  std::cout << " <" << topvol->GetMedium()->GetName() << ">"
92  << std::endl;
93 #endif /* defined(DEBUG_RECURSIVE_EXHAUST) */
94 
95  // proceed with all daughters of the "current volume"
96  Int_t nd = topvol->GetNdaughters();
97  for (Int_t i = 0; i < nd; i++)
98  {
99  // non-null pointer to node?
100  if (topvol->GetNode(i)) {
102  topvol->GetNode(i)->GetVolume(), volnames, exhaust);
103  }
104  }
105 }
106 //___________________________________________________________________________
107 
const XML_Char * name
Definition: expat.h:151
length
Definition: demo0.py:21
OStream cout
Definition: OStream.cxx:6
void RecursiveExhaust(TGeoVolume *topvol, string volnames, bool exhaust)
Definition: GeoUtils.cxx:26