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);
}
}
}
“”