Getting a particle energy when enters a sensitive volume

Hello dear Geant4 users,

I’m writing a MC simulation of a solid cyclotron target and would like to know how much energy a proton losses passing through a vacuum window made of Al. I need to know the kinetic energy of the proton when it enters the thin window and when it leaves it and record them. The vacuum window geometry is set as a sensitive detector, so I would like to use ProcessHits function to retrieve a track information and use step points’ data. I would like to ask how can I implement such actions? How determine a point where a proton enters and leaves the desired volume knowing the previous and the next volumes?

Many thanks!

Sincerely, Ihor

Use an SD (sensitive detector) or implement SteppingAction.

The first step in the volume, where the proton enters the volume, will have the PreStepPoint with status fGeomBoundary, and you can get the energy at the start of the step from the PreStepPoint.

The last step in the volume will have the PostStepPoint with status fGeomBoundary, and you can get the energy at the end of that step from the PostStepPoint.

You’ll need to store the “start energy” in a data member, not just a local function variable, to take into account that the proton could (but probably won’t) take more than one step through the volume.

2 Likes

@mkelsey thanks a lot, your suggestion seems to work. But what did you mean by store the “start energy” (aka energy when a proton is entering the volume?) in a data member, why is it important? How it might help to take into account all steps of a proton? For the moment the chunk of code for processing and storing energies of protons which going out the volume looks like that:

        if (track_->GetTrackID() != temp_track_id_1_ && step->GetPostStepPoint()->GetStepStatus() == fGeomBoundary) {
            const G4int run_id = run_manager->GetCurrentRun()->GetRunID();
            analysis_manager->FillNtupleIColumn(3, 0, run_id);

            const G4int event_id = run_manager->GetCurrentEvent()->GetEventID();
            analysis_manager->FillNtupleIColumn(3, 1, event_id);
            const G4StepPoint* post_step_point = step->GetPostStepPoint();

            const G4double kinetic_energy_postsp = post_step_point->GetKineticEnergy();
            analysis_manager->FillNtupleDColumn(11, 2, kinetic_energy_postsp);
            // G4cout << "A proton leaving the window volume is found with KE = " << kinetic_energy_postsp << G4endl;

            const G4ThreeVector& momentum_postsp = post_step_point->GetMomentum();
            analysis_manager->FillNtupleDColumn(11, 3, momentum_postsp.x());
            analysis_manager->FillNtupleDColumn(11, 4, momentum_postsp.y());
            analysis_manager->FillNtupleDColumn(11, 5, momentum_postsp.z());

            const G4ThreeVector& momentum_direction_postsp = post_step_point->GetMomentumDirection();
            analysis_manager->FillNtupleDColumn(11, 6, momentum_direction_postsp.x());
            analysis_manager->FillNtupleDColumn(11, 7, momentum_direction_postsp.y());
            analysis_manager->FillNtupleDColumn(11, 8, momentum_direction_postsp.z());

            const G4ThreeVector& position_postsp = post_step_point->GetPosition();
            analysis_manager->FillNtupleDColumn(11, 9, position_postsp.x());
            analysis_manager->FillNtupleDColumn(11, 10, position_postsp.y());
            analysis_manager->FillNtupleDColumn(11, 11, position_postsp.z());

            analysis_manager->AddNtupleRow(11);
            temp_track_id_1_ = track_->GetTrackID();
}

I also added probing the track in order to not process the same track more than a single time.
Could you please elaborate on the correct approach of storing the energy variable in a SD class data member?

Both SD and SteppingAction get called once per step. A given track may have many steps, both in the whole geometry World, but also within a single volume. Your vacuum window is probably really thin (tens of microns?) but there’s still some tiny probability for a Rutherford-style hard scatter, in which case the proton would have two steps in the volume.

So I was describing the general case: You have to store the starting energy from the “first call” when the proton enters your volume, so that you have it available on the “second” or “Nth” call when the proton finally exits your volume.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.