Medtech/src/MedtechSteppingAction.cc

103 lines
3.5 KiB
C++

//
// MedtechSteppingAction.cc
// medtech
//
// Created by Baranyai David on 2018. 04. 01..
//
#include "MedtechSteppingAction.hh"
MedtechSteppingAction::MedtechSteppingAction(MedtechEventAction* eventAction) : G4UserSteppingAction(), fEventAction(eventAction), fScoringVolume(0)
{
}
MedtechSteppingAction::~MedtechSteppingAction()
{
}
void MedtechSteppingAction::UserSteppingAction(const G4Step* step)
{
if (!fScoringVolume) {
const MedtechDetectorConstruction* detectorConstruction
= static_cast<const MedtechDetectorConstruction*>
(G4RunManager::GetRunManager()->GetUserDetectorConstruction());
fScoringVolume = detectorConstruction->GetScoringVolume();
}
// get volume of the current step
G4LogicalVolume* volume
= step->GetPreStepPoint()->GetTouchableHandle()
->GetVolume()->GetLogicalVolume();
G4Track *fTrack = step -> GetTrack();
G4int trackID = fTrack -> GetTrackID();
G4double postTime = step->GetPostStepPoint()->GetLocalTime();
if(fTrack->GetTrackStatus()!=fAlive) { return; } /// check if it is alive
G4VPhysicalVolume* prevolume = step -> GetPreStepPoint() -> GetTouchableHandle() -> GetVolume();
G4VPhysicalVolume* postvolume = step -> GetPostStepPoint() -> GetTouchableHandle() -> GetVolume();
G4double preX = step->GetPreStepPoint()->GetPosition().x();
G4double preY = step->GetPreStepPoint()->GetPosition().y();
G4double preZ = step->GetPreStepPoint()->GetPosition().z();
G4double prekinE = step->GetPreStepPoint()->GetKineticEnergy();
G4double postX = step->GetPostStepPoint()->GetPosition().x();
G4double postY = step->GetPostStepPoint()->GetPosition().y();
G4double postZ = step->GetPostStepPoint()->GetPosition().z();
G4double postkinE = step->GetPostStepPoint()->GetKineticEnergy();
G4String preName = prevolume -> GetName();
G4String postName = postvolume -> GetName();
G4String procN;
G4ParticleDefinition *particle = fTrack -> GetDefinition();
if(fTrack -> GetCreatorProcess() != 0)
{
procN = fTrack -> GetCreatorProcess() -> GetProcessName();
if(particle == G4Gamma::GammaDefinition())
{
if(postkinE < 1*MeV)
{
fTrack -> SetTrackStatus(fStopAndKill);
//std::cout << "Low energy killed" <<std::endl;
}
else
{
if(postName == "Target")
{
//fTrack -> SetTrackStatus(fStopAndKill);
MedtechAnalysis *man = MedtechAnalysis::getInstance();
//std::cout << "Target" <<std::endl;
man -> Fill(1, postX, postY, postZ, postkinE);
}
}
}
if(particle == G4Electron::ElectronDefinition())
{
if(preName == "sphere")
{
MedtechAnalysis *man = MedtechAnalysis::getInstance();
//std::cout << "Globe to sphere" <<std::endl;
man -> Fill(2, postX, postY, postZ, postkinE);
}
}
//G4cout << "X: " << postX << " Y: " << postY << " KinE: " << postkinE << " Particle: " << fTrack -> GetDefinition() << G4endl;
}
// check if we are in scoring volume
if (volume != fScoringVolume) return;
// collect energy deposited in this step
G4double edepStep = step->GetTotalEnergyDeposit();
fEventAction->AddEdep(edepStep);
}