How to accessing which material caused G4OpWLS process

Please fill out the following information to help in answering your question, and also see tips for posting code snippets. If you don’t provide this information it will take more time to help with your problem!

Geant4 Version: 11.2.2
Operating System: macOS 15.3.1
Compiler/Version:
_CMake Version:_3.31.2


I am simulating optical photons in a medium with two wavelength shifting components each with unique absorption and emission spectra. In the stepping action I am writing a process that simulates fluoresence quantum efficiency for re-emission from these wavelength shifting components, as seen in the code snippet below. I cannot find how to access information on which of the two wavelength shifting components were in any give OpWLS process so that I can model each wavelength shifting component as having a different quantum efficiency. The G4OpWLS Class Reference doesn’t seem to suggest there is a way to access this information. Any help is much appreciated.

	if (fTrack->GetCreatorProcess())
	{
		if (fTrack->GetCreatorProcess()->GetProcessName() == "OpWLS")
		{
			G4double energy = fTrack->GetKineticEnergy(); 
			G4double wavelength = 1239.8 / energy;		  
			G4double randomValue = G4UniformRand();
			G4double QE;

			if (wavelength < 450.18)
			{ 
				QE += 0.93;
			}
			else
			{
				QE += -9.22e7 * wavelength + 42.45;
			}

			// Kill the track if the random number is greater than QE
			if (randomValue > QE)
			{
				// G4cout << "Track killed by OpWSL condition: Track ID " << fTrack->GetTrackID()
					//    << ", Random Value: " << randomValue << G4endl;
				fTrack->SetTrackStatus(fStopAndKill);
			}
		}
	 }

There are several options.

  1. Call methods of the track, for example GetLogicalVolumeAtVertex, or GetVertexPosition, and implement the quantum efficiency based on that, either directly, or use it to determine the material.
    Geant4/track/include/G4Track.hh
  2. Use a UserTrackingAction (or maybe UserStackingAction) to store information about the particle’s creation in a UserTrackInformation.
  3. If there are only 2 materials, you could use the OpWLS process for one, and the OpWLS2 process for the other. The processes are the same, and intended to enable two processes in the same material. But it might work for this case. Test to see what the creator process is to determine the material.

Hi, thank you very much for you response. It seems like using OpWLS2 is very much the correct path here. If I have some material properties table defined like this:

    // LAB
    GetOptData(datapath + "LAB_AbsLen_eV_m.txt", 1 * m, optdata);
    MPT_LAB->AddProperty("ABSLENGTH", &optdata.at(0)[0], &optdata.at(1)[0],
                         optdata.at(0).size());
    optdata.clear();
    // PPO
    GetOptData(datapath + "WLS1_AbsLen_eV_m.txt", 1 * m, optdata);
    MPT_LAB->AddProperty("WLSABSLENGTH", &optdata.at(0)[0], &optdata.at(1)[0],
                         optdata.at(0).size());
    optdata.clear();
    GetOptData(datapath + "WLS1_EmissionSpec_eV.txt", 1, optdata);
    MPT_LAB->AddProperty("WLSCOMPONENT", &optdata.at(0)[0], &optdata.at(1)[0],
                         optdata.at(0).size());
    optdata.clear();
    MPT_LAB->AddConstProperty("WLSTIMECONSTANT", 1.6 * ns); 
    // bis-MSB
    GetOptData(datapath + "WLS2_AbsLen_eV_m.txt", 1 * m, optdata);
    MPT_LAB->AddProperty("WLSABSLENGTH2", &optdata.at(0)[0], &optdata.at(1)[0],
                         optdata.at(0).size());
    optdata.clear();
    GetOptData(datapath + "WLS2_EmissionSpec_eV.txt", 1, optdata);
    MPT_LAB->AddProperty("WLSCOMPONENT2", &optdata.at(0)[0], &optdata.at(1)[0],
                         optdata.at(0).size());
    optdata.clear();
    MPT_LAB->AddConstProperty("WLSTIMECONSTANT2", 1.5 * ns); //

How can I ensure that each WLS component is dealt with separately by OpWLS and OpWLS2?

The material properties relevant for each process are hard-coded into the process code. OpWLS2 will only use the WLS properties ending in 2, for example.