Momentum and Time at the Vertex for Primary and Secondary particle

_Geant4 Version: 11.1
_Operating System: Ubuntu 22.04
_Compiler/Version: 11.4.0
_CMake Version: 3.22.1

Hello everyone, I have a muon as a primary particle which travels inside a water Cherenkov detector and emits optical photons.
I want to take the momentum and the time of the secondary particle(photon) at the vertex of creation.
However, I want to keep this info(momentum and time), only for those photons that arrive at the end of the detector(2 meters).

To take the momentum and the time at the vertex:

G4double xc,yc,zc;
	G4double xVertex = (theTrack->GetVertexPosition()).x();
	G4double yVertex = (theTrack->GetVertexPosition()).y();
	G4double zVertex = (theTrack->GetVertexPosition()).z();

	G4double timeVertex, momentumVertexX, momentumVertexY, momentumVertexZ;
	G4ThreeVector momentumVertex;
	if(xc==xVertex && yc==yVertex && zc==zVertex) {

If I want to have the Vertex coordinates only for those who arrive at the end I am doing:

	   			analysisMan->FillH1(28, xc/cm);
	   			analysisMan->FillH1(29, yc/cm);
	   			analysisMan->FillH1(30, zc/cm);
	   			real_delta=std::sqrt(((xc-xVertex)*(xc-xVertex))+ ((yc-yVertex)*(yc-yVertex)) + ((zc-zVertex)*(zc-zVertex))); //just a variable

Any ideas how to have momentum and time of the photon at the vertex but only for the photons at the end?

Also, How can I find the momentum of the muon at the vertex(which is the primary particle)?

Set up your SD or SteppingAction to catch the photon at its end point. Then, in that code, access G4Track::GetVertexPosition() (as you do above), to get the photon’s initial position. Use G4Track::GetVertexKineticEnergy() and G4Track::GetDynamicParticle()->GetMass() to calculate the momentum magnitude, and multiply that by G4Track::GetVertexMomentumDirection() to get the momentum vector. Finally, use G4Track::GetGlobalTime() and G4Track::GetLocalTime() to compute the timestamp at the photon’s initial position.

Assuming you know that you only have exactly one primary particle per event, then G4Event::GetPrimaryVertex()->GetPrimaryParticle()->GetMomentum() will give you the initial momentum vector of the muon. You’ll need all the intermediate .hh files for those pointer dereferences to work properly.

Thank you, However if I do G4Event::GetPrimaryVertex()->GetPrimaryParticle()->GetMomentum() then it prints only the first vertex and not all of them.
I need a “for” for all vertices of this event, right?

I do

G4int n_vertex = evt->GetNumberOfPrimaryVertex();

But it says that I have only one vertex, when at I have many vertices(I know that because I get the coordinates of the vertex)

You are confusing the “vertices” that are associated with the individually created secondary tracks (and which are stored within G4Track), with the primary vertex, which contains the particle or particles you create with G4ParticleGun or G4GeneralParticleSource.

I did it*, but just to have it clear in my mind I want to ask you something.
A primary muon travels and emits photons. I thought we had a vertex at the point of emission . In that vertex I wanted the momentum of the muon(every time we have an emission, I need the momentum of the muon).
So, does the vertex only refer to the secondary track?
When we say primary vertex, we mean only the first point of ‘‘creation’’ of primary particle?
How can we have access to information of the primary particle at different points of its track?

*(I did it in stepping, checking if we have cherenkov process and then I got the momentum with G4Track)

Thank you in advance!

Yes, you can call the point where the photon is emitted a vertex, but there is no object by that name in Geant4 that you can reference. In Geant4, G4PrimaryVertex and G4PrimaryParticle refer to the generated initial particles in the event.

If you want to know the momentum of the muon when the secondary photon is emitted, then you will need a block of code in your SteppingAction:

  • Look for a track with ParentID == 0. That’s one of the primary particles.
  • Check if the process which limited the step is a process where photons are emitted
  • Check whether a secondary track was created in the step
  • If all those are true, get the track momentum and do what you want with it.

Yes. More specifically, the G4PrimaryVertex object specifies the location, and carries a list of the primary particles at that location. The G4PrimaryParticle object specifies the kinematics (mass, momentum, energy, charge, etc.) of one of the primary particles.

Each primary particle is converted into a G4Track, for which the parent ID is zero (i.e., the primaries don’t have a parent). So you can test for that condition in your SteppingAction or SD.

Thank you very much for the explanation!