Issue in position tracking of neutrons

Dear all,

I have simulated fast neutrons with an energy of 2 MeV. The objective is to perform a proton-neutron conversion. In my geometry, I have a structure consisting of a converter followed by 3 mm of gas (CF4), another converter, and again 3 mm of gas (CF4), and so on. During the simulation, I record the energy deposited in my detector and the positions of the particles within the detector.

The issue arises when I project the 2D positions in the x vs y plane. I observe a significant dispersion in the results. I have attached both my simulation results and the corresponding code. As a newcomer to Geant4, I am still in the learning phase, and I am unsure about where I might have made a mistake. I would greatly appreciate any insights or suggestions on what I might have done incorrectly. Thank you in advance for your responses.

x_y Px.pdf (21.9 KB)
x_y Py.pdf (21.8 KB)
construction.cc (31.0 KB)

event.cc (4.9 KB)
generator.cc (1.6 KB)
stepping.cc (3.9 KB)

_Geant4 Version: geant4-v11.1.3
_Operating System: Ubuntu 20.04.6 LTS
_Compiler/Version: c++
_CMake Version: VERSION 2.6 FATAL_ERROR

I am unsure if your setup is correct or if your plots make sense physically, but it seems to me that your histogram binning is far too fine. You don’t have enough events. I would reduce to maybe 25 bins and see what your results look like

I did reduce the bin to 25 and increased the events and I got the graphs for the projection.

1 Like

I have made some modifications in the stepping.cc to get the positions. I have seen some people using postStepPoint and preStepPoint at the same time to access the positions. Looking at my setup. I am unsure if I should use preStepPoint to get the positions or the PostStepPoint. Can someone help me out please. thank you.

this is the code

“”
#include “stepping.hh”

MySteppingAction::MySteppingAction(MyEventAction *eventAction)
{
fEventAction = eventAction;
}

MySteppingAction::~MySteppingAction()
{}

void MySteppingAction::UserSteppingAction(const G4Step *step)
{
if (step->GetTrack()->GetDefinition()->GetParticleName() == “proton” ) {
G4AnalysisManager *man = G4AnalysisManager::Instance();

 const DetectorConstruction *detectorConstruction = static_cast<const DetectorConstruction*> (G4RunManager::GetRunManager()->GetUserDetectorConstruction());
 G4LogicalVolume *volume = step->GetPreStepPoint()->GetTouchableHandle()->GetVolume()->GetLogicalVolume();

 G4LogicalVolume *fScoringVolume_1 = detectorConstruction->GetScoringVolume();
 G4LogicalVolume *fScoringVolume_2 = detectorConstruction->GetScoringVolume_2();
 G4LogicalVolume *fScoringVolume_3 = detectorConstruction->GetScoringVolume_3();
 G4LogicalVolume *fScoringVolume_4 = detectorConstruction->GetScoringVolume_4();
 G4LogicalVolume *fScoringVolume_5 = detectorConstruction->GetScoringVolume_5();
 G4LogicalVolume *fScoringVolume_6 = detectorConstruction->GetScoringVolume_6();
 G4LogicalVolume *fScoringVolume_7 = detectorConstruction->GetScoringVolume_7();
 G4LogicalVolume *fScoringVolume_8 = detectorConstruction->GetScoringVolume_8();
 G4LogicalVolume *fScoringVolume_9 = detectorConstruction->GetScoringVolume_9();
 G4LogicalVolume *fScoringVolume_10 = detectorConstruction->GetScoringVolume_10();

 G4LogicalVolume *fScoringVolume2 = detectorConstruction->GetScoringVolume1();

 //G4cout << "\n thickness of this material "<< detectorConstruction->GetMaterialThickness() << G4endl;
 G4double current_thickness = detectorConstruction->GetMaterialThickness();

 G4Track* track = step->GetTrack();
 auto material = track->GetMaterial()->GetName();
 //track->SetTrackStatus(fStopAndKill);
 G4int stepNumber = track->GetCurrentStepNumber();
 G4cout << "the track material:" << material << G4endl; 
 G4double energy = step->GetPreStepPoint()->GetKineticEnergy();

// man->FillNtupleDColumn(12, 0, energy);
// man->AddNtupleRow(12);
//G4cout << energy << G4endl;

 G4double edep = step->GetTotalEnergyDeposit();
 G4double edep1 = step->GetTotalEnergyDeposit();
 G4double edep_2 = step->GetTotalEnergyDeposit();
 G4double edep_3 = step->GetTotalEnergyDeposit();
 G4double edep_4 = step->GetTotalEnergyDeposit();
 G4double edep_5 = step->GetTotalEnergyDeposit();
 G4double edep_6 = step->GetTotalEnergyDeposit();
 G4double edep_7 = step->GetTotalEnergyDeposit();
 G4double edep_8 = step->GetTotalEnergyDeposit();
 G4double edep_9 = step->GetTotalEnergyDeposit();
 G4double edep_10 = step->GetTotalEnergyDeposit();

 // If it's the first step in the volume, save the position.
 G4ThreeVector posPhoton; 
 G4StepPoint *preStepPoint; 
 G4StepPoint *postStepPoint ;   

 /*if (step->IsFirstStepInVolume()) {
    fEventAction->SetPosition(step->GetPreStepPoint()->GetPosition()/cm);
    preStepPoint = step->GetPreStepPoint();
    //postStepPoint = step->GetPostStepPoint();

    posPhoton = preStepPoint->GetPosition()/cm;

 //man->FillH2(0, posPhoton[0], posPhoton[1]);
 }*/

 if (volume == fScoringVolume_1){
    fEventAction->AddEdep(edep);
    if (step->IsFirstStepInVolume() ){
       preStepPoint = step->GetPreStepPoint();
       postStepPoint = step->GetPostStepPoint();
       G4ThreeVector posPhoton1 = postStepPoint->GetPosition()/cm;

       man->FillH2(0, posPhoton1[0], posPhoton1[1]);
       man->FillH1(0,  posPhoton1[2]);


    }
       //man->FillNtupleDColumn(12, 0, energy);
       //man->AddNtupleRow(12);

 }
 if (volume == fScoringVolume_2){
    fEventAction->AddEdep_2(edep_2);
    if (step->IsFirstStepInVolume()){
       preStepPoint = step->GetPreStepPoint();
       postStepPoint = step->GetPostStepPoint();
       G4ThreeVector posPhoton2 = postStepPoint->GetPosition()/cm;

       man->FillH2(1, posPhoton2[0], posPhoton2[1]);
       man->FillH1(1, posPhoton2[2]);


    }

 }

 if (volume == fScoringVolume_3){
    fEventAction->AddEdep_3(edep_3);
    if (step->IsFirstStepInVolume()){

       preStepPoint = step->GetPreStepPoint();
       postStepPoint = step->GetPostStepPoint();

       G4ThreeVector posPhoton3 = postStepPoint->GetPosition()/cm;

       man->FillH2(2, posPhoton3[0], posPhoton3[1]);
       man->FillH1(2, posPhoton3[2]);

    }
 }
 if (volume == fScoringVolume_4){
    fEventAction->AddEdep_4(edep_4);
    if (step->IsFirstStepInVolume()){

       preStepPoint = step->GetPreStepPoint();
       postStepPoint = step->GetPostStepPoint();

       G4ThreeVector posPhoton4 = postStepPoint->GetPosition()/cm;

       man->FillH2(3, posPhoton4[0], posPhoton4[1]);
       man->FillH1(3, posPhoton4[2]);


    }
 }
 if (volume == fScoringVolume_5){
    fEventAction->AddEdep_5(edep_5);
    if (step->IsFirstStepInVolume()){

       preStepPoint = step->GetPreStepPoint();
       postStepPoint = step->GetPostStepPoint();

       G4ThreeVector posPhoton5 = postStepPoint->GetPosition()/cm;

       man->FillH2(4, posPhoton5[0], posPhoton5[1]);
       man->FillH1(4,  posPhoton5[2]);


    }

 }

 if (volume == fScoringVolume_6){
    fEventAction->AddEdep_6(edep_6);
    if (step->IsFirstStepInVolume()){

       preStepPoint = step->GetPreStepPoint();
       postStepPoint = step->GetPostStepPoint();

       G4ThreeVector posPhoton6 = postStepPoint->GetPosition()/cm;

       man->FillH2(5, posPhoton6[0], posPhoton6[1]);
       man->FillH1(5, posPhoton6[2]);

    }
 }
 if (volume == fScoringVolume_7){
    fEventAction->AddEdep_7(edep_7);
    if (step->IsFirstStepInVolume()){

       preStepPoint = step->GetPreStepPoint();
       postStepPoint = step->GetPostStepPoint();

       G4ThreeVector posPhoton7 = postStepPoint->GetPosition()/cm;


       man->FillH2(6, posPhoton7[0], posPhoton7[1]);
       man->FillH1(6,  posPhoton7[2]);

    }
 }

 if (volume == fScoringVolume_8){
    fEventAction->AddEdep_8(edep_8);
    if (step->IsFirstStepInVolume()){

       preStepPoint = step->GetPreStepPoint();
       postStepPoint = step->GetPostStepPoint();

       G4ThreeVector posPhoton8 = postStepPoint->GetPosition()/cm;

       man->FillH2(7, posPhoton8[0], posPhoton8[1]);
       man->FillH1(7,  posPhoton8[2]);



    }

 }
 if (volume == fScoringVolume_9){
    fEventAction->AddEdep_9(edep_9);
    if (step->IsFirstStepInVolume()){

       preStepPoint = step->GetPreStepPoint();
       postStepPoint = step->GetPostStepPoint();

       G4ThreeVector posPhoton9 = postStepPoint->GetPosition()/cm;


       man->FillH2(8, posPhoton9[0], posPhoton9[1]);
       man->FillH1(8, posPhoton9[2]);


    }

 }
 if (volume == fScoringVolume_10){
    fEventAction->AddEdep_10(edep_10);
    if (step->IsFirstStepInVolume()){

       preStepPoint = step->GetPreStepPoint();
       postStepPoint = step->GetPostStepPoint();

       G4ThreeVector posPhoton10 = postStepPoint->GetPosition()/cm;

       man->FillH2(9, posPhoton10[0], posPhoton10[1]);
       man->FillH1(9, posPhoton10[2]);


    }
 }

 if (volume == fScoringVolume2){
    fEventAction->AddEdep1(edep1);
 }

}

}

“”