]> git.uio.no Git - u/mrichter/AliRoot.git/blob - Flugg/FlukaMaterial.cxx
negative indexes allowed
[u/mrichter/AliRoot.git] / Flugg / FlukaMaterial.cxx
1 #include "FlukaMaterial.hh"
2 #include "FlukaLowMat.hh"
3 #include "WrapUtils.hh"
4 #include "G4ios.hh"
5
6 FlukaMaterialsTable FlukaMaterial::fFlukaMaterials;
7 FlukaMaterialsIndexTable FlukaMaterial::fFlukaIndexMaterials;
8
9 FlukaMaterial::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
53 FlukaMaterial::~FlukaMaterial() {
54   delete fFlukaLowMat;
55 }
56
57 void FlukaMaterial::AddLowMat(const G4String& name) {
58   fFlukaLowMat = new FlukaLowMat(name, this);
59 }
60
61
62 G4String FlukaMaterial::GetRealName() const {
63   if (fFlukaLowMat)
64     return fFlukaLowMat->GetName();
65   return GetName();
66 }
67
68 G4std::ostream& FlukaMaterial::PrintMaterialsByName(G4std::ostream& os) {
69   PrintHeader(os, "MATERIALS");
70   for (FlukaMaterialsIterator i = fFlukaMaterials.begin(); 
71        i != fFlukaMaterials.end(); 
72        i++) {
73     FlukaMaterial* flumat     = (*i).second;
74     
75     //if (flumat->GetZ()) //Skip materials that describe only compounds
76     os << *flumat;
77   }
78   return os;
79 }
80
81 G4std::ostream& FlukaMaterial::PrintMaterialsByIndex(G4std::ostream& os) {
82   PrintHeader(os, "MATERIALS");
83   for (FlukaMaterialsIndexIterator i = fFlukaIndexMaterials.begin(); 
84        i != fFlukaIndexMaterials.end(); 
85        i++) {
86     FlukaMaterial* flumat     = (*i).second;
87     
88     //if (flumat->GetZ()) //Skip materials that describe only compounds
89     os << *flumat;
90   }
91   return os;
92 }
93
94 G4std::ostream& operator<<(G4std::ostream& os, const FlukaMaterial& material){
95   os << setw10 << "MATERIAL  ";
96
97   os.setf(static_cast<G4std::ios::fmtflags>(0),G4std::ios::floatfield);
98   G4double Z = G4double(material.GetZ());
99   if (Z <= 0)
100     os << setw10 << " ";
101   else
102     os << setw10 
103        << setfixed
104        << G4std::setprecision(1) 
105        << Z;
106   
107   G4double A = material.GetA();
108   if (A <= 0)
109     os << setw10 << " ";
110   else
111     os << setw10 << G4std::setprecision(3)
112        << A;
113
114   G4double density = material.GetDensity();
115   if (density <=0)
116     density = 0.999;
117   os.setf(static_cast<G4std::ios::fmtflags>(0),G4std::ios::floatfield);
118   os << setw10 
119      << setscientific
120      << G4std::setprecision(3) 
121      << density;
122
123   os.setf(static_cast<G4std::ios::fmtflags>(0),G4std::ios::floatfield);
124   os << setw10 
125      << setfixed
126      << G4std::setprecision(1) 
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 }