Please fill out the following information to help in answering your question, and also see tips for posting code snippets. If you don’t provide this information it will take more time to help with your problem!
_Geant4 Version:_11.01
_Operating System:_ubuntu 20.04.6
_Compiler/Version:_9.4.0
_CMake Version:_3.16.3
iam a new learner of geant4, i want to simulate a gamma and neutron through a shielding material from a cesium-137 source which can be detected by a NaI detector and later analyse the result using root. how can i record the deposited energy on the detector? what is the best way to analyse the efficiency of my shielding? please i need some advice on how to do this. below are some of the codes i developed in trying to develop the Geometries, including, detectorconstruction, main/sim
#include "MyDetectorconstruction.hh"
MyDetectorConstruction::MyDetectorConstruction()
{}
MyDetectorConstruction::~MyDetectorConstruction()
{}
G4VPhysicalVolume *MyDetectorConstruction::Construct()
{
G4NistManager *nist = G4NistManager::Instance();
G4Material *worldMat = nist->FindOrBuildMaterial("G4_AIR");
G4Box *solidWorld = new G4Box("solidWorld", 1.0*m, 1.0*m, 1.5*m);
G4LogicalVolume *logicWorld = new G4LogicalVolume(solidWorld, worldMat, "logicWorld");
G4VPhysicalVolume *physWorld = new G4PVPlacement(0, G4ThreeVector(0., 0., 0.), logicWorld, "physWorld", 0, false, 0, true);
std::vector<G4double> energy = {1.239841939*eV/0.9, 1.239841939*eV/0.2};
//G4double startAngle = 0.0 * degree;
//G4double spanningAngle = 360.0 * degree;
// Define the shielding material
G4Material *Bi2O3 = new G4Material("Bi2O3", 8.9*g/cm3, 2);
Bi2O3->AddElement(nist->FindOrBuildElement("Bi"), 2);
Bi2O3->AddElement(nist->FindOrBuildElement("O"), 3);
G4Material *Polystyrene = new G4Material("Polystyrene", 1.05*g/cm3, 2);
Polystyrene->AddElement(nist->FindOrBuildElement("C"), 8);
Polystyrene->AddElement(nist->FindOrBuildElement("H"), 8);
// Define the polystyreneBi2O3 material
G4Material* PolystyreneBi2O3 = new G4Material("PolystyreneBi2O3", 1.4425 * g/cm3, 2);
PolystyreneBi2O3->AddMaterial(Polystyrene, 95*perCent); // 95% polystyrene
PolystyreneBi2O3->AddMaterial(Bi2O3, 5*perCent); // 5% bismuth oxide
// Defining the shielding geometry
G4double shielding_innerRadius = 0.0 * cm;
G4double shielding_outerRadius = 40.0 * cm;
G4double shielding_halfLength = 5.0 * cm;
G4double startAngle = 0.0 * degree;
G4double spanningAngle = 360.0 * degree;
G4VSolid* solidshielding = new G4Tubs("shielding", shielding_innerRadius, shielding_outerRadius, shielding_halfLength, startAngle, spanningAngle);
G4LogicalVolume *logicshielding = new G4LogicalVolume(solidshielding, PolystyreneBi2O3, "logicshielding");
// Set the visualization attributes for the shielding
G4VisAttributes* shieldingVisAtt = new G4VisAttributes(G4Colour(1.0, 1.0, 1.0)); // Yellow colour
logicshielding->SetVisAttributes(shieldingVisAtt);
G4VPhysicalVolume *physShielding = new G4PVPlacement(0, G4ThreeVector(0., 0., 0.5*m), logicshielding, "physShielding", logicWorld, false, 0, true);
//for detector
G4Material* NaI = new G4Material("NaI", 3.67 * g/cm3, 2);
NaI->AddElement(nist->FindOrBuildElement("Na"), 1);
NaI->AddElement(nist->FindOrBuildElement("I"), 1);
// Define the NaI detector
G4double naI_innerRadius = 0.0 * cm;
G4double naI_outerRadius = 40.0 * cm;
G4double naI_halfLength = 10.0 * cm;
G4VSolid* solidNaI = new G4Tubs("NaIDetector", naI_innerRadius, naI_outerRadius, naI_halfLength, startAngle, spanningAngle);
logicNaI = new G4LogicalVolume(solidNaI, NaI, "logicNaI");
// Set the visualization attributes for the NaI Detector
G4VisAttributes* NaIVisAtt = new G4VisAttributes(G4Colour(1.0, 1.0, 0.0)); // Yellow colour
logicNaI->SetVisAttributes(NaIVisAtt);
G4VPhysicalVolume *physNaI = new G4PVPlacement(0, G4ThreeVector(0., 0., 1.2*m), logicNaI, "physNaI", logicWorld, false, 0, true);
// Define the lead material
G4Material* leadMaterial = new G4Material("Lead", 82, 207.2 * g/mole, 11.35 * g/cm3);
// Define the lead collimator
G4double collimator_innerRadius = 0.0 * cm;
G4double collimator_outerRadius = 50.0 * cm;
G4double collimator_halfLength = 15.0 * cm;
//G4double startAngle = 0.0 * //degree; since it is define above no need to define again
//G4double spanningAngle = 360.0 * degree; //degree; since it is define above no need to define again
G4VSolid* leadCollimatorSolid = new G4Tubs("LeadCollimator", collimator_innerRadius, collimator_outerRadius, collimator_halfLength, startAngle, spanningAngle);
G4LogicalVolume* leadCollimatorLogical = new G4LogicalVolume(leadCollimatorSolid, leadMaterial, "leadCollimatorLogical");
// Set the visualization attributes for the lead collimator
G4VisAttributes* leadCollimatorVisAtt = new G4VisAttributes(G4Colour(0.0, 1.0, 0.0)); // Green colour
leadCollimatorLogical->SetVisAttributes(leadCollimatorVisAtt);
G4VPhysicalVolume* leadCollimatorPhysical = new G4PVPlacement(0, G4ThreeVector(0., 0., 1.2*m), leadCollimatorLogical, "leadCollimatorPhysical", logicWorld, false, 0, true);
// Define the Cesium-137 material
G4Material* CesiumMaterial = new G4Material("Cesium", 55, 132.9054519 * g/mole, 1.85 * g/cm3);
// Define the particle source geometry
G4double source_innerRadius = 0.0 * cm;
G4double source_outerRadius = 5.0 * cm;
G4double source_halfLength = 1.0 * cm;
//G4double startAngle = 0.0 * degree;
//G4double spanningAngle = 360.0 * degree;
G4VSolid* solidCesiumsource = new G4Tubs("CesiumSource", source_innerRadius, source_outerRadius, source_halfLength, startAngle, spanningAngle);
G4LogicalVolume *logicCesiumsource = new G4LogicalVolume(solidCesiumsource, CesiumMaterial, "logicCesiumsource");
// Set the visualization attributes for the NaI Detector
G4VisAttributes* CesiumVisAtt = new G4VisAttributes(G4Colour(1.0, 0.0, 0.0)); // Red colour
logicCesiumsource->SetVisAttributes(CesiumVisAtt);
G4VPhysicalVolume *physCesiumSource = new G4PVPlacement(0, G4ThreeVector(0., 0., 0), logicCesiumsource, "physCesiumSource", logicWorld, false, 0, true);
return physWorld;
}
void MyDetectorConstruction::ConstructSDandField()
{
MySensitiveDetector *sensDet = new MySensitiveDetector("SensitiveDetector");
logicNaI->SetSensitiveDetector(sensDet);
}
#ifndef CONSTRUCTION_HH
#define CONSTRUCTION_HH
#include "G4VUserDetectorConstruction.hh"
#include "G4VPhysicalVolume.hh"
#include "G4LogicalVolume.hh"
#include "G4Box.hh"
#include "G4PVPlacement.hh"
#include "G4NistManager.hh"
#include "G4SystemOfUnits.hh"
#include "G4Tubs.hh"
#include "G4VSolid.hh"
#include "G4Colour.hh"
#include "G4RotationMatrix.hh"
#include "G4ThreeVector.hh"
#include "G4VisAttributes.hh"
#include "MySensitiveDetector.hh"
class MyDetectorConstruction : public G4VUserDetectorConstruction
{
public:
MyDetectorConstruction();
~MyDetectorConstruction();
virtual G4VPhysicalVolume *Construct();
private:
G4LogicalVolume *logicNaI;
virtual void ConstructSDandField();
};
#endif
main/sim
#include <iostream>
#include "G4RunManager.hh"
#include "G4UImanager.hh"
#include "G4VisManager.hh"
#include "G4VisExecutive.hh"
#include "G4UIExecutive.hh"
#include "MyDetectorconstruction.hh"
#include "physics.hh"
#include "ActionInitialization.hh"
int main(int argc, char** argv)
{
G4RunManager *runManager = new G4RunManager();
runManager->SetUserInitialization(new MyDetectorConstruction());
runManager->SetUserInitialization(new MyPhysicsList());
runManager->SetUserInitialization(new MyActionInitialization());
runManager->Initialize();
G4UIExecutive *ui = new G4UIExecutive(argc, argv);
G4VisManager *visManager = new G4VisExecutive();
visManager->Initialize();
G4UImanager *UImanager = G4UImanager::GetUIpointer();
UImanager->ApplyCommand("/vis/open OGL ");
UImanager->ApplyCommand("/vis/viewer/set/viewpointVector 1 1 1");
UImanager->ApplyCommand("/vis/drawVolume");
UImanager->ApplyCommand("/vis/viewer/set/autoRefresh true");
UImanager->ApplyCommand("/vis/scene/add/trajectories smooth");
UImanager->ApplyCommand("/vis/scene/endOfEventAction accumulate");
ui->SessionStart();
return 0;
}