File: PrintConstituents.C

package info (click to toggle)
vecgeom 1.2.8%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 24,016 kB
  • sloc: cpp: 88,803; ansic: 6,888; python: 1,035; sh: 582; sql: 538; makefile: 23
file content (58 lines) | stat: -rw-r--r-- 1,867 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// a ROOT macro to print out all volumes contained in a given volume ("topname")
// (used mainly for subsequent systematic stress testing of all parts of a detector -- from
//  simple to complex)

typedef std::pair<std::string, size_t> Volume_Count_t;

void FillParts(TGeoVolume const *v, std::vector<Volume_Count_t> &allparts)
{
  allparts.push_back(Volume_Count_t(
      std::string(std::string(v->GetName()) + std::string(" ") + std::string(v->GetShape()->ClassName())),
      v->GetNtotal()));

  for (size_t d = 0; d < (size_t)v->GetNdaughters(); ++d) {
    FillParts(v->GetNode(d)->GetVolume(), allparts);
  }
}

void PrintParts(std::vector<Volume_Count_t> const &allparts)
{
  size_t counter(0);
  for (auto v : allparts) {
    std::cerr << counter++ << " " << v.first << " " << v.second << "\n";
  }
}

void PrintConstituents(char const *detector = "alice.root", char const *topname = "ITSS")
{

  TGeoManager::Import(detector);
  TGeoVolume *topvolume = gGeoManager->FindVolumeFast(topname);
  if (topvolume == nullptr) {
    std::cerr << "Warning: NO SUCH VOLUME FOUND .. will use top volume\n";
    topvolume = gGeoManager->GetTopVolume();
  }

  if (topvolume == nullptr) {
    std::cerr << "ERROR: NO VOLUME FOUND .. aborting\n";
    return;
  }

  std::vector<Volume_Count_t> allparts;

  // fill parts vector
  FillParts(topvolume, allparts);

  // remove duplicates
  std::set<Volume_Count_t> allpartsset(allparts.begin(), allparts.end());

  // sort parts according to number of total nodes
  // from elementary to complex
  std::vector<Volume_Count_t> allpartsfinal;
  std::copy(allpartsset.begin(), allpartsset.end(), std::back_inserter(allpartsfinal));
  std::sort(allpartsfinal.begin(), allpartsfinal.end(),
            [](Volume_Count_t p1, Volume_Count_t p2) { return p1.second < p2.second; });

  // print parts
  PrintParts(allpartsfinal);
}