// Standard library : #include #include // Third part : // - Geant4 : #include "G4SystemOfUnits.hh" #include "G4VPhysicalVolume.hh" #include "G4Material.hh" #include "G4VSolid.hh" // SolidSim : // This project : #include "SolidMassComputation.hh" //============================================== // Constructor and destructor //============================================== SolidMassComputation::SolidMassComputation(int verbosity_){ verbosity = verbosity_; } //============================================== // Compute mass of a logical //============================================== void SolidMassComputation::ComputeMassForLogical(G4LogicalVolume * logInput_){ G4cout << "***********************************************" << G4endl << " Mass composition of " << logInput_->GetName() << G4endl << "***********************************************" << G4endl << G4endl ; //creation of materials vs mass map std::map Mmat; for (unsigned int i = 0 ; i < G4Material::GetNumberOfMaterials() ; i++) { Mmat[G4Material::GetMaterialTable()->at(i)->GetName()]=0.; } //Vectors creation and initialisation std::vector < std::vector < G4VPhysicalVolume *> > PV_navigator; std::vector dummy_init; for (int i = 0 ; i < logInput_->GetNoDaughters() ; i++ ) { dummy_init.push_back(logInput_->GetDaughter(i)); } PV_navigator.push_back(dummy_init); // Loop on daughter volume bool do_navigation = true; // bool do_navigation = false; while (do_navigation) { G4VPhysicalVolume * act_PV = PV_navigator.back().front(); G4LogicalVolume * act_LV = act_PV->GetLogicalVolume(); std::string indentation = "| "; for (unsigned int i = 0 ; i < PV_navigator.size() ; i++) {indentation = " " + indentation;} if (act_LV->GetNoDaughters() == 0 ) { int multiplicity = 1; for (unsigned int i = 0 ; i < PV_navigator.size() ; i++) { multiplicity *= PV_navigator.at(i).front()->GetMultiplicity();} if (verbosity >=1){ G4cout << indentation << act_PV->GetName() << " : no daugther volume" << G4endl << indentation << " Volume = " << act_LV->GetSolid()->GetCubicVolume()/mm3 << " mm3" << G4endl << indentation << " Material = " << act_LV->GetMaterial()->GetName() << G4endl << indentation << " Density = " << act_LV->GetMaterial()->GetDensity()/(g/cm3) << " g/cm3" << G4endl << indentation << " Mass = " << act_LV->GetMass(false,false)/g << " g" << G4endl; if (multiplicity > 1 ) G4cout << indentation << " Multiplicity = " << multiplicity << G4endl; } Mmat[act_LV->GetMaterial()->GetName()] += act_LV->GetMass(false,false)*multiplicity; PV_navigator.back().erase(PV_navigator.back().begin()); //delete actual volume in vector while (PV_navigator.back().size() == 0){ PV_navigator.erase(PV_navigator.end()); if (PV_navigator.size() == 0) { do_navigation = false; //if no other vector, close navigation break; } else { PV_navigator.back().erase(PV_navigator.back().begin()); //else, delete parent volume } } } else if (act_LV->GetNoDaughters() > 0) { if (verbosity >=1){ G4cout << indentation << act_PV->GetName() << " : " << act_LV->GetNoDaughters() << " daugther volumes" << G4endl << indentation << " Volume = " << act_LV->GetSolid()->GetCubicVolume()/mm3 << " mm3" << G4endl << indentation << " Material = " << act_LV->GetMaterial()->GetName() << G4endl << indentation << " Density = " << act_LV->GetMaterial()->GetDensity()/(g/cm3) << " g/cm3" << G4endl << indentation << " Mass = " << act_LV->GetMass(false,false)/g << " g" << G4endl; } Mmat[act_LV->GetMaterial()->GetName()] += act_LV->GetMass(false,false); std::vector dummy; for (int i = 0 ; i < act_LV->GetNoDaughters() ; i++ ) { dummy.push_back(act_LV->GetDaughter(i)); } PV_navigator.push_back(dummy); } } G4cout << "Mass summary per material in " << logInput_->GetName() << G4endl; for (unsigned int i = 0 ; i < G4Material::GetNumberOfMaterials() ; i++ ){ if (Mmat[G4Material::GetMaterialTable()->at(i)->GetName()] != 0.){ G4cout << " " << G4Material::GetMaterialTable()->at(i)->GetName() << " : " << Mmat[G4Material::GetMaterialTable()->at(i)->GetName()]/kg << " kg" << G4endl; } } G4cout << G4endl; return; }