Problem with stepping action

Dear all,
I am running a neutron simulation. In my geometry I have an OPPAC detector and a silicon detector in which I am interested in calculating the energy deposition in each detector. the problem is that I only get the graph for the energies deposited in the OPPAC detector but the silicon detector. I think that it could be a problem with my I put the code here: please does anyone know how I can fix this. thank you all in advance.


#include “stepping.hh”

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


void MySteppingAction::UserSteppingAction(const G4Step *step)
// if (step->GetTrack()->GetDefinition()->GetParticleName() == “proton”) {
const DetectorConstruction detectorConstruction = static_cast<const DetectorConstruction> (G4RunManager::GetRunManager()->GetUserDetectorConstruction());

G4LogicalVolume *fScoringVolume = detectorConstruction->GetScoringVolume();
G4LogicalVolume *fScoringVolume2 = detectorConstruction->GetScoringVolume1();
G4LogicalVolume *volume = step->GetPreStepPoint()->GetTouchableHandle()->GetVolume()->GetLogicalVolume();
G4LogicalVolume *volume1 = step->GetPreStepPoint()->GetTouchableHandle()->GetVolume()->GetLogicalVolume();

//collect energy deposition. 
if(volume != fScoringVolume)

    // If it's the first step in the volume, save the position. 
if (step->IsFirstStepInVolume()) {
G4double edep = step->GetTotalEnergyDeposit();
if(volume != fScoringVolume2)

G4double edep1 = step->GetTotalEnergyDeposit();

// }


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

If your OPPAC detector is fScoringVolume then your issue makes sense as you satisfy the first conditional statement and avoid the return. Your first conditional statement followed by the return kills your stepping action code if you are not in fScoringVolume so you never get a chance to record in your other volume.

I set something similar up recently where I had two regions I wanted to record data with a stepping action except I used some code that could be summed up as “if (volume == ScoringVolume1) {Record Something} and then (volume == ScoringVolume2) {Record Something}”, I did not include a return statement in my

thank you very much. This worked.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.