How to get the processname in particular detector?

The thing is, I simulated a layer of ZnS scintillator behind the stainless steel. When the electron is incident on the stainless steel, I want to know what process the scintillation photon is caused by the interaction between the electron and the stainless steel.
I tried to call the function of eventaction in the steppingaction to add ProcessName to the vector, as in B1, but the program crashed.
Here is the code in steppingaction:

    const G4VProcess *process = step->GetPostStepPoint()->GetProcessDefinedStep();
        G4String processName = process->GetProcessName();
        fEventAction->AddProcess(processName);

and in eventaction:

void AddProcess(G4String ProcessName){ fprocessNames.push_back(ProcessName);}
 std::vector<G4String> fprocessNames;

plus,i have confirmed that current step is in ZnS.

Are you asking about what process created the photon? In that case, look at G4Track::GetCreatorProcess(). Make sure you test for a null pointer before dereferencing it to get the name.

Thanks for replying.
In ZnS scintillator,the optical photon is created by “some” particle in scintillation process.
I want to know how the “some” particle is created in stainless steel,i.e.,the process to creat the “some”
partilce in stainless steel.

What is your radiation source? Gammas? Unless they are very high energy, the photons will be created from electrons. If you are using hadrons, you can look at what the target isotope was using

auto postStep = step->GetPostStepPoint();
auto stepProcess = (G4VProcess*)postStep->GetProcessDefinedStep();
G4HadronInelasticProcess* had = dynamic_cast<G4HadronInelasticProcess*>(stepProcess);
const G4Isotope* isotope = (had ? had->GetTargetIsotope() : 0);

The ZnS scintillator is attached to the back of the stainless steel, and the “reactions” of the high energy electron incident on the stainless steel makes the scintillator scintillate.
I just want to know what the “reactions” are.

i find example in examples\extended\optical\OpNovice\OpNoviceStackingAction.cc which is

 if(aTrack->GetDefinition() == G4OpticalPhoton::OpticalPhotonDefinition())
  {  // particle is optical photon
    if(aTrack->GetParentID() > 0)
    {  // particle is secondary
      if(aTrack->GetCreatorProcess()->GetProcessName() == "Scintillation")
        ++fScintillationCounter;
      else if(aTrack->GetCreatorProcess()->GetProcessName() == "Cerenkov")
        ++fCerenkovCounter;
    }
  }

The method G4Track::GetCreatorProcess() seems to only get “Scintillation” or “Cerenkov”.But what
i want to know is,the parent process of “Scintillation” and “Cerenkov”.

Are you trying to find the process that created the electron/gamma/etc, that underwent the scintillation process to create an opticalphoton? You’ll want to do that in the user action for the primary (the electron/gamma/etc).

In OpNovice2, here:
https://geant4.kek.jp/lxr/source/examples/extended/optical/OpNovice2/src/SteppingAction.cc#L405
there’s already been a check that the particle isn’t an opticalphoton. If there are secondaries created, loop over them to see if any are opticalphotons produced by scintillation. If so, call track->GetCreatorProcess() . This will give what created the electron, e.g. eIoni.

Sorry for not replying your message for so long.
I still have a question.


Like this,in opnovice2,it only tells if the opticalphoton is created by “Cerenkov” or “Scintillation”.
But i want to know the process in the steel.

Sorry for not replying your message for so long.
I still have a question.

I tried to answer before, but guess I wasn’t clear.

It’s not trivial to get what you want. As you find, the opticalphoton keeps a record of the process that created it. But, there’s no record of anything before that.

To keep this information, there are two main steps:

  1. When the electron is stepping, if there is an opticalphoton created, get the process that created the electron
  2. Record that information in a UserTrackInformation attached to the opticalphoton.

Sure,I prepare to add a tracking code in my program.Thanks a lot!