Do detector properties matter

…when the option StopAndKill is used?
I wonder whether all particles, no matter which, are just being killed independent from their specific properties when they enter a detector?

Thanks in advance!

Hi @BenjaminW,

We need more information to fully assess your question. Are there any if statements being invoked before the track status is set to “fStopandKill”? And where is setting the track status being invoked from in your code?

In general setting the track status to fStopandKill kills all particles, but there are lots of ways to make it only act only on certain particles, or depend on the properties (energy, charge, etc.) of those particles.

Joseph

1 Like

Hi @JDecunha ,

thank you, no, there are none if statements.
I’m using the StopAndKill command in my class G4bool MySensitiveDetector::ProcessHits(G4Step *aStep, G4TouchableHistory *ROhist).

Well, ok, this means that, without any further specification StopAndKill indeed kills every particle independent of any further physical or even technical consideration?

Setting the fStopAndKill status kills the current track (whatever track you assigned the status to). If you don’t have any conditional statements, then as every track is passed into your SD, you will kill it.

1 Like

Thank you, as well!

So detector properties itself do not matter? In case there are any available(?). I assume there are as many features possible/available as I am able to define within the code? Or are there already any built-in/ready to use features which are good to use?

In my case I constructed a G4box which I assigned to a sensitive detector. So I conclude my detector is actually just a box that does nothing but killing each particle it enters?

This is my code:


MySensitiveDetector::MySensitiveDetector(G4String name) : G4VSensitiveDetector(name)
{}

MySensitiveDetector::~MySensitiveDetector()
{}

G4bool MySensitiveDetector::ProcessHits(G4Step *aStep, G4TouchableHistory *ROhist)
{
	G4Track *track = aStep->GetTrack();
	track->SetTrackStatus(fStopAndKill);
	G4StepPoint *preStepPoint = aStep->GetPreStepPoint();	
	G4StepPoint *postStepPoint = aStep->GetPostStepPoint();		
	G4ThreeVector posPhoton = preStepPoint->GetPosition();	

	if(preStepPoint->GetStepStatus() == fGeomBoundary)
	{
	const G4VTouchable *touchable = aStep->GetPreStepPoint()->GetTouchable();	
	G4int history_depth = touchable->GetHistoryDepth();

	G4int evt = G4RunManager::GetRunManager()->GetCurrentEvent()->GetEventID();
	G4double partEdep = aStep->GetTotalEnergyDeposit();	

	G4double energy = preStepPoint->GetTotalEnergy();
	//Convert from MeV to keV
	partEdep *= 1000;
	energy *= 1000;
	
	// show only each 100th particle
	G4EventManager* evMan = G4EventManager::GetEventManager();
	if(evMan->GetConstCurrentEvent()->GetEventID() % 100 == 0)
	{
		evMan->KeepTheCurrentEvent();
	}
	
	
	G4AnalysisManager *man = G4AnalysisManager::Instance();

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

	// Distinguishing detectors
	if(history_depth < 5)	
	{
		if(touchable->GetReplicaNumber(1) == 200){man->FillNtupleDColumn(1, 0, energy); man->AddNtupleRow(1);}
		if(touchable->GetReplicaNumber(1) == 210){man->FillNtupleDColumn(2, 0, energy); man->AddNtupleRow(2);}
		if(touchable->GetReplicaNumber(1) == 220){man->FillNtupleDColumn(3, 0, energy); man->AddNtupleRow(3);}
	}

	}
	return true;
}

in your example, the second line sets the status to kill, every track that enters the detector will execute that line, because there is no if-clause that would prevent that in some cases.

the rest of ProcessHits will still be executed, btw.

1 Like

Thanks, but you don’t see a red flag when I kill the particle immediately?

Would the energy deposition differ when it would be able to travel further?

I don’t see a red flag, but you need to know what you want to achieve.

very likely, yes. killing it immediately removes the particle with all its energy and mass from the simulation, that is reasonably non-physical :wink:

Really? I refer to the energy deposition within the detector itself.

Have to figure that out…

well, depending on the geometry, there are a certain number of scattering events inside the detector. not performing these steps makes your simulation miss potential deposits.

what you could do is to kill the particles only when leaving the detector volume, i.e. poststep status is fgeomboundary, that reduces the effect. (keep in mind that particles could re-enter the detector in reality, and estimate how significant this is!)

1 Like

That’s a good way to go, thank you!

I’d do this as follows:

G4StepPoint *postStepPoint = aStep->GetPostStepPoint();	
if(postStepPoint->GetStepStatus() == fGeomBoundary)
{
    const G4VTouchable *touchable = aStep->GetPreStepPoint()->GetTouchable();
   ...
    magic that happens..
    ...
}

Is this correct?
Btw, when I change SetTrackStatus to fAlive it takes ages and I’m even not sure whether there is something going on. Before, I could simulate 10,000,000 photons in around 10-15 minutes, now even 1,000 photon need more than half an hour…?
Mh, when I set const G4VTouchable *touchable = aStep->GetPreStepPoint()->GetTouchable(); to const G4VTouchable *touchable = aStep->GetPostStepPoint()->GetTouchable(); it still takes ages.
Can I somehow figure out whether there is something meaningful going on? Or is it reasonable that it takes sooo long?

I would not mess with the TrackStatus, except you know exactly what you are doing :slight_smile:

how about this:
record the desposited energy in every step in the SD and also measure the total energy leaving the detector (if(postStepPoint->GetStepStatus() == fGeomBoundary)).
If there is no / insignificant energy leaving the volume, I believe you have your answer + you can proceed to kill everything that enters the detector volume and simply accumulate the total energy (saving computation time).

1 Like

Ok, have to figure out how to modify the SD.

I didn’t change the SetTrackStatus now and only changed to

	if(postStepPoint->GetStepStatus() == fGeomBoundary)
	{
		const G4VTouchable *touchable = aStep->GetPostStepPoint()->GetTouchable();
	....
	}

but now I record only entries and no energy will be deposited. I guess something is not correct? Does the touchable itself need to be GetPreStepPoint(), or so?

Btw, what exactly are here the Post and Pre step? According to my needs the one would be entering volume boundary and the other one the leaving volume boundary. Is this correct?
If not, how else do I figure out how many energy is deposited within the detector?

I’m also not sure whether to use GetTotalEnergyDeposit() or GetDeltaEnergy()?

aStep->GetTotalEnergyDeposit() might be a useful function for you. Reading $G4INCLUDE/G4Step.hh and $G4INCLUDE/G4StepPoint.hh might also be useful, to give you insight into what information is available to you.

1 Like