Counting particle that pass through a volume without depositing energy

I have a non rectangular volume that is a scintillator. I have a sensitive detector placed at one end to detect photons. I have my particle source as gamma. Due to the relative small size of my detector, that majority of the gamma pass through the volume without depositing any energy. I would like to count the number of gamma that pass through my volume with no interactions. Is there a way to count the pass through particle of a specific volume? I am using a modified version of the LXe example.

Yes, I do it in stepping action.
In the stepping action you can as if in gamma comes in volume just count it.
like
counter =0;
if (Volume_name == scintillator && Particle == “gamma”){
counter++;
}

Using a stepping action as suggested is a possible way. Given that you have a sensitive detector already, and that it’s small I think counting “full pass through” gammas will be easier and more efficient here (it will only be called for steps made in the volume the SD is attached to).

The Primitive Scorer functionality has a several pass through scorers (the G4PSPassage... one listed). However, I don’t think this would cover your use case of a simple count, though the code can be taken from these as inspiration.

For example, G4PSPassageTrackLength is close to what you need, so taking its ProcessHits and IsPassed member functions, we could implement the relevant parts of suitable sensitive detector as

class GammaPassageCounter : public G4VSensitiveDetector
{
  public:
    // Constructor/other member functions omitted

    G4bool ProcessHits(G4Step* aStep, G4Touchable* /*unused*/) override
    {
        // 1. Filter out gammas
        if(aStep->GetTrack()->GetDefinition() != G4Gamma::GammaDefinition())
        {
          return false;
        }

        // 2. Check that step is a one-step passthrough (i.e. pure transportation)
        G4bool IsEnter = aStep->GetPreStepPoint()->GetStepStatus() == fGeomBoundary;
        G4bool IsExit  = aStep->GetPostStepPoint()->GetStepStatus() == fGeomBoundary;

        if(!IsEnter && !IsExit) 
        {
          return false;
        }

        // 3. Have a direct passthrough gamma, so count it
        fNPassthroughGammas += 1;

        return true;
    }

  private:
    size_t fNPassthroughGammas = 0; /// number of gammas that pass through volume with no interaction
};

Of course, this omits the noted code and how to store/extract the count, but hopefully shows how the count can be made at least.

1 Like