Including St2 in the new geometry segmentation (Christian)
[u/mrichter/AliRoot.git] / Flugg / FlukaMaterial.cxx
CommitLineData
26d97e06 1#include "FlukaMaterial.hh"
2#include "FlukaLowMat.hh"
3#include "WrapUtils.hh"
4#include "G4ios.hh"
5
6FlukaMaterialsTable FlukaMaterial::fFlukaMaterials;
7FlukaMaterialsIndexTable FlukaMaterial::fFlukaIndexMaterials;
8
9FlukaMaterial::FlukaMaterial(const G4String& name,
10 G4int Z, G4double A,
11 G4double density,
12 G4int N):
13 fName(name),
14 fZ(Z),
15 fA(A),
16 fDensity(density),
17 fN(N),
18 fFlukaLowMat(0) {
19
20 G4String testname(name);
21 G4int matrep = 1;
22 while (fFlukaMaterials[testname] && matrep < 100) {
23 matrep++;
24 char smatrep[3];
25 sprintf(smatrep,"%.2d",matrep);
26
27 testname = name;
28 if (testname.length() <= 6)
29 testname += smatrep;
30 else
31 testname.replace(6,testname.length()-6, smatrep, 2);
32
33#ifdef G4GEOMETRY_DEBUG
34 G4cout << "INFO: We found material \'" << name << " previously defined."
35 << G4endl;
36 G4cout << " Checking if \'" << testname << "\' exists." << G4endl;
37#endif
38 }
39
40 if (matrep > 99) {
41 G4cerr << "ERROR: Too many materials with the same name. Exiting!"
42 << G4endl;
43 abort();
44 }
45
46 fFlukaMaterials[testname] = this;
47 if (name != testname)
48 AddLowMat(testname);
49 fIndex = fFlukaMaterials.size() + 2;
50 fFlukaIndexMaterials[fIndex] = this;
51}
52
53FlukaMaterial::~FlukaMaterial() {
54 delete fFlukaLowMat;
55}
56
57void FlukaMaterial::AddLowMat(const G4String& name) {
58 fFlukaLowMat = new FlukaLowMat(name, this);
59}
60
61
62G4String FlukaMaterial::GetRealName() const {
63 if (fFlukaLowMat)
64 return fFlukaLowMat->GetName();
65 return GetName();
66}
67
0edf14e7 68std::ostream& FlukaMaterial::PrintMaterialsByName(std::ostream& os) {
26d97e06 69 PrintHeader(os, "MATERIALS");
70 for (FlukaMaterialsIterator i = fFlukaMaterials.begin();
71 i != fFlukaMaterials.end();
72 i++) {
73 FlukaMaterial* flumat = (*i).second;
74
7ee550c2 75 //if (flumat->GetZ()) //Skip materials that describe only compounds
76 os << *flumat;
26d97e06 77 }
78 return os;
79}
80
0edf14e7 81std::ostream& FlukaMaterial::PrintMaterialsByIndex(std::ostream& os) {
26d97e06 82 PrintHeader(os, "MATERIALS");
83 for (FlukaMaterialsIndexIterator i = fFlukaIndexMaterials.begin();
84 i != fFlukaIndexMaterials.end();
85 i++) {
86 FlukaMaterial* flumat = (*i).second;
87
7ee550c2 88 //if (flumat->GetZ()) //Skip materials that describe only compounds
89 os << *flumat;
26d97e06 90 }
91 return os;
92}
93
0edf14e7 94std::ostream& operator<<(std::ostream& os, const FlukaMaterial& material){
26d97e06 95 os << setw10 << "MATERIAL ";
96
0edf14e7 97 os.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield);
26d97e06 98 G4double Z = G4double(material.GetZ());
99 if (Z <= 0)
100 os << setw10 << " ";
101 else
102 os << setw10
103 << setfixed
0edf14e7 104 << std::setprecision(1)
26d97e06 105 << Z;
106
107 G4double A = material.GetA();
108 if (A <= 0)
109 os << setw10 << " ";
110 else
0edf14e7 111 os << setw10 << std::setprecision(3)
26d97e06 112 << A;
113
114 G4double density = material.GetDensity();
115 if (density <=0)
116 density = 0.999;
0edf14e7 117 os.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield);
26d97e06 118 os << setw10
119 << setscientific
0edf14e7 120 << std::setprecision(3)
26d97e06 121 << density;
122
0edf14e7 123 os.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield);
26d97e06 124 os << setw10
125 << setfixed
0edf14e7 126 << std::setprecision(1)
26d97e06 127 << G4double(material.GetIndex());
128
129 os << setw10 << " ";
130 if (material.GetN())
131 os << setw10 << G4double(material.GetN());
132 else
133 os << setw10 << " ";
134
135
136 os << material.GetRealName().substr(0,8) << G4endl;
137
138 if (material.GetLowMat() && material.GetZ() != 0)
139 os << *(material.GetLowMat());
140
141 return os;
142}