Energy Spectrum

//My modification. Spits out the energy of the particle as it enters the absorber.

G4StepPoint* prePoint = step->GetPreStepPoint();

G4StepPoint* postPoint = step->GetPostStepPoint();

G4VPhysicalVolume* prePhysVol = prePoint->GetPhysicalVolume();

G4VPhysicalVolume* postPhysVol = postPoint->GetPhysicalVolume();

if (prePhysVol != postPhysVol)

{

G4double KE = track->GetKineticEnergy();

//G4ThreeVector Position = track->GetPosition();    

//G4ThreeVector Momentum = track->GetMomentum();

if (KE > 1.0)

{

  G4String postPhysVolName = postPhysVol->GetName();

  if (postPhysVolName == "Absorber")

  {

    if (writefile)

    {

      G4ThreeVector Position = track->GetPosition();    

      G4ThreeVector Momentum = track->GetMomentum();

      // Not a mistype. Beam is rotated in the macro file and enters on the x axis so x = z and vice versa. 

      writefile << Position.z() << "," << Momentum.z() << "," << Position.y() << "," << Momentum.y() << "," << Position.x() << "," << Momentum.x() << "," << KE << G4endl;

    }

  }

}

}

1 Like