Don't kill particles inside detector

Hi,

I want to perform a simulation of x-rays. I’m still at the beginning of my project where I’m using code snippets of other projects. So far, it’s working well, I guess but I’m a bit stuck now where I expect the x-rays to go through the detectors and not being stopped there. This is the code of the detector:

G4bool MySensitiveDetector::ProcessHits(G4Step *aStep, G4TouchableHistory *ROhist)
{
G4Track *track = aStep->GetTrack();

track->SetTrackStatus(fStopAndKill);

G4StepPoint *preStepPoint = aStep->GetPreStepPoint();
G4StepPoint *postStepPoint = aStep->GetPostStepPoint(); // leaves detector

G4ThreeVector posPhoton = preStepPoint->GetPosition();

const G4VTouchable *touchable = aStep->GetPreStepPoint()->GetTouchable();

G4int detector_number = touchable->GetCopyNumber();

G4VPhysicalVolume *physVol = touchable->GetVolume();
G4ThreeVector posDetector = physVol->GetTranslation();

G4int evt = G4RunManager::GetRunManager()->GetCurrentEvent()->GetEventID();

G4AnalysisManager *man = G4AnalysisManager::Instance();
man->FillNtupleIColumn(0, evt);
man->FillNtupleDColumn(1, posDetector[0]);
man->FillNtupleDColumn(2, posDetector[1]);
man->FillNtupleDColumn(3, posDetector[2]);
man->AddNtupleRow(0);

return true;
}

I have identified the line

track->SetTrackStatus(fStopAndKill);

which is responsible for doing so. However, the alternative options Geant4: G4TrackStatus.hh File Reference don’t tell me much which one I should use:

fAlive : Continue the tracking
fStopButAlive : Invoke active rest physics processes and kill the current track afterward
fStopAndKill : Kill the current track
fKillTrackAndSecondaries : Kill the current track and also associated secondaries. Suspend the current track.
fSuspend : Suspend the current track
fPostponeToNextEvent : Postpones the tracking of the current track to the next event

What are you trying to do? If you want the xray to travel through your detector, just comment out that line. You don’t have to replace it with anything

1 Like

Good point, actually, I want to measure the deposited energy at the detectors but x-rays are possible to go through matter, right? So I would expect that a part of the x-rays go through even if there’s a detector?

Yes, it depends on your detector efficiency, but its very possible that x-rays travel through your detector.

You can track the deposited energy, and use a StopandKill command if the x-ray leaves the detector, because you don’t care about it any more.

Or, you can just let the particle run out of energy or leave your world box, at which point it is no longer tracked anyway

1 Like

How do I let the particle run out of energy, I mean, with which command?

In the above case, it would be possible that a particle goes through three detectors sequentially and I would like to allow this.

You don’t have to do anything. That’s what Geant4 does. It will track a particle, with all of its interactions and energy losses, until the particle either reaches zero energy, or leaves the world volume.

1 Like

Thanks, ok. What would I enter in

track->SetTrackStatus()

then?

Why do you want to chage the track status? Your question was about measuring quantities (i.e., using a sensitive detector, a scorer, or a stepping action). If you want to let Geant4 do it’s normal thing, you shouldn’t interfere with that by changing the track status.

Means I can simply remove this command line?
What would be the default setting?

You can remove any line. There are very few required commands in GEANT4, namely specify your user action classes, and creating a minimal geometry, particle source, etc.

If you don’t have that line, Geant4 will handle the process and only record what you ask it to

1 Like