Difference between Step and Track?

Can anyone explains in simple terms. I am not able to digest it. I have following trackingAction.cc file but I do not understand how do we store information about track or step (which one??) ?

I only know that:
step is delta information of track. but track is not collection of step(how???).
track is snapshot of particle.
step has two points - delta information.

// ********************************************************************
// * License and Disclaimer                                           *
// *                                                                  *
// * The  Geant4 software  is  copyright of the Copyright Holders  of *
// * the Geant4 Collaboration.  It is provided  under  the terms  and *
// * conditions of the Geant4 Software License,  included in the file *
// * LICENSE and available at  http://cern.ch/geant4/license .  These *
// * include a list of copyright holders.                             *
// *                                                                  *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work  make  any representation or  warranty, express or implied, *
// * regarding  this  software system or assume any liability for its *
// * use.  Please see the license in the file  LICENSE  and URL above *
// * for the full disclaimer and the limitation of liability.         *
// *                                                                  *
// * This  code  implementation is the result of  the  scientific and *
// * technical work of the GEANT4 collaboration.                      *
// * By using,  copying,  modifying or  distributing the software (or *
// * any work based  on the software)  you  agree  to acknowledge its *
// * use  in  resulting  scientific  publications,  and indicate your *
// * acceptance of all terms of the Geant4 Software license.          *
// ********************************************************************
/// \file radioactivedecay/rdecay01/src/TrackingAction.cc
/// \brief Implementation of the TrackingAction class
// $Id$

#include "TrackingAction.hh"
#include "RunAction.hh"
#include "HistoManager.hh"
#include "RunAction.hh"
#include "EventAction.hh"
#include "TrackingMessenger.hh"

#include "G4Track.hh"
#include "G4ParticleTypes.hh"
#include "G4RunManager.hh"


TrackingAction::TrackingAction(RunAction* RA, EventAction* EA)
  fullChain = false;
  fTrackMessenger = new TrackingMessenger(this);   


  delete fTrackMessenger;


void TrackingAction::PreUserTrackingAction(const G4Track* track)
  G4ParticleDefinition* particle = track->GetDefinition();
  G4String name   = particle->GetParticleName();
  fCharge = particle->GetPDGCharge();
  fMass   = particle->GetPDGMass();  
  G4double Ekin = track->GetKineticEnergy();
  G4int ID      = track->GetTrackID();
  G4bool condition = false;  

  //count particles
  fRun->ParticleCount(name, Ekin);
  //energy spectrum
  G4int ih = 0;
  if (particle == G4Electron::Electron()||
      particle == G4Positron::Positron())  ih = 1;
  else if (particle == G4NeutrinoE::NeutrinoE()||
           particle == G4AntiNeutrinoE::AntiNeutrinoE()) ih = 2;
  else if (particle == G4Gamma::Gamma()) ih = 3;
  else if (particle == G4Alpha::Alpha()) ih = 4;
  else if (fCharge > 2.) ih = 5;
  if (ih) G4AnalysisManager::Instance()->FillH1(ih, Ekin);
  //fullChain: stop ion and print decay chain
  if (fCharge > 2.) {
    G4Track* tr = (G4Track*) track;
    if (fullChain) tr->SetTrackStatus(fStopButAlive);
    if (ID == 1) fEvent->AddDecayChain(name);
      else       fEvent->AddDecayChain(" ---> " + name); 
  //example of saving random number seed of this fEvent, under condition
  ////condition = (ih == 3);
  if (condition) G4RunManager::GetRunManager()->rndmSaveThisEvent();


void TrackingAction::PostUserTrackingAction(const G4Track* track)
  //keep only ions
  if (fCharge < 3. ) return;

  G4AnalysisManager* analysis = G4AnalysisManager::Instance();
  //get time
  G4double time = track->GetGlobalTime();
  G4int ID = track->GetTrackID();
  if (ID == 1) fRun->PrimaryTiming(time);        //time of life of primary ion  
  //energy and momentum balance (from secondaries)
  G4TrackVector* secondaries = fpTrackingManager->GimmeSecondaries();
  size_t nbtrk = (*secondaries).size();
  if (nbtrk) {
    //there are secondaries --> it is a decay
    //force 'single' decay
    if ((!fullChain)&&(ID > 1)) G4RunManager::GetRunManager()->AbortEvent();
    G4double EkinTot = 0.;
    G4ThreeVector Pbalance = - track->GetMomentum();
    for (size_t itr=0; itr<nbtrk; itr++) {
       G4Track* trk = (*secondaries)[itr];
       EkinTot += trk->GetKineticEnergy();
       //exclude gamma desexcitation from momentum balance
       if (trk->GetDefinition() != G4Gamma::Gamma())         
         Pbalance += trk->GetMomentum();                 
    G4double Pbal = Pbalance.mag();  
  //no secondaries --> end of chain    
  if (!nbtrk) {
    fRun->EventTiming(time);                     //total time of life

A “particle” is an abstract concept, what you picture in your head starting from a source and moving through the geometry. The particle follows a trajectory in space, losing energy, scattering, or producing secondary particles along the way, until it either leaves the geometry or stops for some reason.

The G4Track represents the instantaneous state of the particle at the current location along it’s trajectory. For your convenience, the G4Track also carries around some information about where the particle started, and its permanent information (particle type, mass, charge).

Geant4 does not (cannot) move particles smoothly and continuously through the geometry. Instead, the particle takes steps along it’s trajectory, from some chosen point to the next, from beginning to end. The G4Step represents the most recent step taken by the particle. It carries information about the starting point of that step (the PreStepPoint), the ending point of that step (the PostStepPoint), and what happened in between the two (for instance, energy loss due to dE/dx).

The kinematic information stored in the PostStepPoint is also the information stored in G4Track at that time, because the track carries the most recent state of the particle, and the PostStepPoint is the endpoint of the most recent step.

If you want information about the particle’s whole spatial trajectory, there is a G4Trajectory object with that information, but it doesn’t store anything like a “container of steps”; there is no such thing in Geant4.


@mkelsey Thank you so much for very detailed explanation. This will help me a lot. Thank you so much for your time. I have posted another question which might be interesting for you. It is about detector construction. If you can answer that it will be great help.

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