1 #include "FlukaCompound.hh"
3 #include "WrapUtils.hh"
5 FlukaCompoundsTable FlukaCompound::fFlukaCompounds;
7 FlukaCompound::FlukaCompound(const G4String& name,
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++) {
20 //Build the associated material
21 fFlukaMaterial = new FlukaMaterial(name, 0, 0, density);
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;
30 fFlukaCompounds[testname] = this;
33 FlukaCompound::~FlukaCompound() {
39 void FlukaCompound::AddElement(G4int index, G4double fraction) {
40 if (fNAdded < fNMaterials) {
41 fElIndex[fNAdded] = index;
42 fFraction[fNAdded] = fraction;
46 G4cerr << "ERROR: Trying to add to many elements to compound \'"
47 << GetName() << "\'!" << G4endl;
48 G4cerr << " Last element not added!!!" << G4endl;
52 std::ostream& FlukaCompound::PrintCompounds(std::ostream& os) {
53 PrintHeader(os, "COMPOUNDS");
55 for (FlukaCompoundsIterator i = fFlukaCompounds.begin();
56 i != fFlukaCompounds.end();
58 FlukaCompound* flucomp = (*i).second;
65 std::ostream& operator<<(std::ostream& os, const FlukaCompound& flucomp) {
66 G4int nmats = flucomp.GetNMaterials();
67 G4String matName = flucomp.GetName();
68 G4String matRealName = flucomp.GetRealName().substr(0,8);
70 os << "* " << matName << " COMPOUND (" << nmats << ")" << G4endl;
73 //os << *(flucomp.GetFlukaMaterial());
76 G4int counttothree = 0;
77 os << setw10 <<"COMPOUND ";
78 for (G4int i = 0; i < nmats; i++) {
79 os.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield);
82 << std::setprecision(6)
83 << flucomp.GetMaterialFraction(i);
84 os.setf(static_cast<std::ios::fmtflags>(0),std::ios::floatfield);
87 << std::setprecision(1)
88 << G4double(flucomp.GetMaterialIndex(i));
90 if (counttothree == 3 ) {
94 os << setw10 <<"COMPOUND ";
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 << " ";