Recording theta, phi and psi

Please fill out the following information to help in answering your question, and also see tips for posting code snippets

_Geant4 Version:_11.1.1
_Operating System:_Ubuntu 22.04
_Compiler/Version:_CMake 2.8.12

Good morning experts,

I am recording the positions in my simulation as follows:

G4Track* track = step->GetTrack();
G4ThreeVector Position = track->GetPosition();
G4double xpos = Position.getX();
XPos = xpos;
G4double ypos = Position.getY();
YPos = ypos;
G4double zpos = Position.getZ();
ZPos = zpos;

I also want to record theta, phi and psi, could someone guide me please?

Thank you

You can not get angles from a single point. If you need spherical coordinates of the XYZ point in Cartesian, you can just apply a transform (see Wiki or Wolfram). Otherwise, you need the second point to measure the angle.

I may guess you might want the initial direction vector of the particle, which is taken from the generator

const auto generatorAction = dynamic_cast<const PrimaryGeneratorAction *>(G4RunManager::GetRunManager()->GetUserPrimaryGeneratorAction());
auto particle_direction = generatorAction->GetParticleGun()->GetParticleMomentumDirection();

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