How to get primary particles information?

Hi all,

I have a source that emitted proton particles. I would like to store information of each particle (position, particle type, energy, direction, …) to a root file (Ntuple type). I have created a GPS source via macro.
I think we can get the information of each primary particle at BeginOfEventAction(const G4Event*) method. That is correct?
Can anyone help me please? Thank you in advance.

Look at G4PrimaryVertex which contains the primary position information, and contains a list (vector) of G4PrimaryParticle which contains the kinematics. G4Event provides an accessor for the list (vector) of G4PrimaryVertex instances in the event.

Hi @mkelsey,
Thank you for your help.
Here is my code. Could you help me to check it? Thank you in advance.

	G4int evtID = evt->GetEventID();
	G4PrimaryParticle* priPar = evt->GetPrimaryVertex()->GetPrimary();
	G4String parName = priPar->GetParticleDefinition()->GetParticleName();
	G4double parCharge = priPar->GetCharge();
	G4double parEng = priPar->GetKineticEnergy();
	G4ThreeVector parPos = priPar->GetMomentum();
	G4ThreeVector parDir = priPar->GetMomentumDirection();

	G4cout << "Event ID: "    << evtID
		   << " Par name: "    << parName 
	       << " , Charge: "   << parCharge 
		   << " , Energy: "   << parEng/MeV << "MeV"
		   << " , Position: " << "(" << parPos.getX() << ", " << parPos.getY() << ", " << parPos.getZ() << ")"
		   << " , Direction: " << "(" << parDir.getX() << ", " << parDir.getY() << ", " << parDir.getZ() << ")"		   
		   << G4endl; 

	// get analysis manager
    G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();

	analysisManager->FillNtupleIColumn(6, 0, evtID);
	analysisManager->FillNtupleSColumn(6, 1, parName);
	analysisManager->FillNtupleIColumn(6, 2, parCharge);
	analysisManager->FillNtupleDColumn(6, 3, parEng);
	analysisManager->FillNtupleDColumn(6, 4, parPos.getX());
	analysisManager->FillNtupleDColumn(6, 5, parPos.getY());
	analysisManager->FillNtupleDColumn(6, 6, parPos.getZ());
	analysisManager->FillNtupleDColumn(6, 7, parDir.getX());
	analysisManager->FillNtupleDColumn(6, 8, parDir.getY());
	analysisManager->FillNtupleDColumn(6, 9, parDir.getZ());
	analysisManager->AddNtupleRow(6);

parPos is not a position. You’re filling it with the full momentum vector (in units of MeV) from the kinematics.