]>
Commit | Line | Data |
---|---|---|
26d97e06 | 1 | #include "FlukaCompound.hh" |
2 | #include "G4ios.hh" | |
3 | #include "WrapUtils.hh" | |
4 | ||
5 | FlukaCompoundsTable FlukaCompound::fFlukaCompounds; | |
6 | ||
7 | FlukaCompound::FlukaCompound(const G4String& name, | |
8 | G4double density, | |
9 | G4int nelem): | |
10 | fNMaterials(nelem), | |
11 | fNAdded(0) { | |
12 | //Initialise arrays for element indices and fractions | |
13 | fElIndex = new G4int[nelem]; | |
14 | fFraction = new G4double[nelem]; | |
15 | for (G4int i = 0; i < nelem; i++) { | |
16 | fElIndex[i] = 0; | |
17 | fFraction[i] = 0; | |
18 | } | |
19 | ||
20 | //Build the associated material | |
21 | fFlukaMaterial = new FlukaMaterial(name, 0, 0, density); | |
22 | ||
23 | //If it already exists it will have got a new name | |
24 | G4String testname(fFlukaMaterial->GetRealName()); | |
25 | if (testname != name) { | |
26 | G4cerr << "INFO: Found two materials with the same name! (" | |
27 | << name << ")" << G4endl; | |
28 | G4cerr << " Renaming to " << testname << G4endl; | |
29 | } | |
30 | fFlukaCompounds[testname] = this; | |
31 | } | |
32 | ||
33 | FlukaCompound::~FlukaCompound() { | |
34 | delete[] fElIndex; | |
35 | delete[] fFraction; | |
36 | } | |
37 | ||
38 | ||
39 | void FlukaCompound::AddElement(G4int index, G4double fraction) { | |
40 | if (fNAdded < fNMaterials) { | |
41 | fElIndex[fNAdded] = index; | |
42 | fFraction[fNAdded] = fraction; | |
43 | fNAdded++; | |
44 | } | |
45 | else { | |
46 | G4cerr << "ERROR: Trying to add to many elements to compound \'" | |
47 | << GetName() << "\'!" << G4endl; | |
48 | G4cerr << " Last element not added!!!" << G4endl; | |
49 | } | |
50 | } | |
51 | ||
0edf14e7 | 52 | std::ostream& FlukaCompound::PrintCompounds(std::ostream& os) { |
26d97e06 | 53 | PrintHeader(os, "COMPOUNDS"); |
54 | ||
55 | for (FlukaCompoundsIterator i = fFlukaCompounds.begin(); | |
56 | i != fFlukaCompounds.end(); | |
57 | i++) { | |
58 | FlukaCompound* flucomp = (*i).second; | |
59 | os << *flucomp; | |
60 | } | |
61 | ||
62 | return os; | |
63 | } | |
64 | ||
0edf14e7 | 65 | std::ostream& operator<<(std::ostream& os, const FlukaCompound& flucomp) { |
26d97e06 | 66 | G4int nmats = flucomp.GetNMaterials(); |
67 | G4String matName = flucomp.GetName(); | |
68 | G4String matRealName = flucomp.GetRealName().substr(0,8); | |
69 | //Some comment | |
70 | os << "* " << matName << " COMPOUND (" << nmats << ")" << G4endl; | |
71 | ||
72 | //Material card | |
7ee550c2 | 73 | //os << *(flucomp.GetFlukaMaterial()); |
26d97e06 | 74 | |
75 | //The card | |
76 | G4int counttothree = 0; | |
77 | os << setw10 <<"COMPOUND "; | |
78 | for (G4int i = 0; i < nmats; i++) { | |
0edf14e7 | 79 | os.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield); |
26d97e06 | 80 | os << setw10 |
81 | << setfixed | |
0edf14e7 | 82 | << std::setprecision(6) |
26d97e06 | 83 | << flucomp.GetMaterialFraction(i); |
0edf14e7 | 84 | os.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield); |
26d97e06 | 85 | os << setw10 |
86 | << setfixed | |
0edf14e7 | 87 | << std::setprecision(1) |
26d97e06 | 88 | << G4double(flucomp.GetMaterialIndex(i)); |
89 | counttothree++; | |
90 | if (counttothree == 3 ) { | |
91 | os << matRealName; | |
92 | os << G4endl; | |
93 | if ( (i+1) != nmats) | |
94 | os << setw10 <<"COMPOUND "; | |
95 | counttothree = 0; | |
96 | } | |
97 | } | |
98 | ||
99 | if ((nmats % 3) != 0) { | |
100 | //Unless we have 3, 6, 9... submaterials we need to put some empty | |
101 | //space and the compound name | |
102 | for (G4int i = 0; i < (3 - (nmats % 3)); i++) | |
103 | os << setw10 << " " << setw10 << " "; | |
104 | os << matRealName; | |
105 | os << G4endl; | |
106 | } | |
107 | ||
108 | return os; | |
109 | } |