countmass.C
Go to the documentation of this file.
1 #include "TSystem.h"
2 #include "TString.h"
3 #include "TGeoVolume.h"
4 #include "TGeoManager.h"
5 #include "TGeoNode.h"
6 #include <iostream>
7 #include <stdio.h>
8 
9 class TGeoNode;
10 class TGeoVolume;
11 
12 // Recurse through the geometry to count the mass
13 double CountMass(const TGeoVolume* vol, const char * const material)
14 {
15  double mass = 0;
16  double children_capacity = 0;
17 
18  // Recurse through all the children and count their mass. Also keep track
19  // of their volume ("capacity") so we don't double-count our own.
20  for(int d = 0; d < vol->GetNdaughters(); ++d){
21  const TGeoNode* node = vol->GetNode(d);
22  std::string name = node->GetName();
23  name.erase(name.find('_'));
24  TGeoVolume* child_vol = gGeoManager->FindVolumeFast(name.c_str());
25  children_capacity += child_vol->Capacity();
26  mass += CountMass(child_vol, material);
27  }
28 
29  if(!strcmp(material, "PVC") &&
30  string(vol->GetName()).find("Extru") == string::npos)
31  return mass;
32 
33  // g -> kg
34  if(!strcmp(vol->GetMaterial()->GetName(), material))
35  mass += .001 * (vol->Capacity()-children_capacity) * vol->GetMaterial()->GetDensity();
36 
37  return mass;
38 }
39 
40 void countmass(const bool near)
41 {
42  gSystem->Load("libGeom");
43  gSystem->Load("libGdml");
44 
45  if(near)
46  TGeoManager::Import("neardet-3x3-8block-xtru-vacuum-stagger.gdml");
47  else
48  TGeoManager::Import("fardet-12x12-28block-xtru-vacuum-stagger-pivoter.gdml");
49 
50  TGeoVolume * vol = gGeoManager->GetVolume("vWorld");
51  printf("scint mass: %f\n", CountMass(vol, "Scintillator"));
52  printf("Scintillator mass only counts the mass inside extrusions, not\n"
53  "in the horizontal manifolds, because that isn't simulated.\n");
54  printf("PVC mass: %f\n", CountMass(vol, "PVC"));
55  printf("PVC mass only counts the mass of the extrusions, not the end\n"
56  "plates or anything else, because that's what I want to compare.\n");
57  printf("Glue mass: %f\n", CountMass(vol, "Glue"));
58  //printf("Air mass: %f\n", CountMass(vol, "Air"));
59  return;
60 }
const XML_Char * name
Definition: expat.h:151
string material
Definition: eplot.py:19
double CountMass(const TGeoVolume *vol, const char *const material)
Definition: countmass.C:13
printf("%d Experimental points found\n", nlines)
Float_t d
Definition: plot.C:236
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
void countmass(const bool near)
Definition: countmass.C:40