Overview Contents Previous Next Geant4 User's Guide
For Application Developers
User Actions


6.3 User Information Classes


Additional user information can be associated with various Geant4 classes. There are basically two ways for the user to do this:

6.3.1 G4VUserEventInformation

G4VUserEventInformation is an abstract class from which the user can derive his/her own concrete class for storing user information associated with a G4Event class object. It is the user's responsibility to construct a concrete class object and set the pointer to a proper G4Event object.

Within a concrete implementation of G4UserEventAction, the SetUserEventInformation() method of G4EventManager may be used to set a pointer of a concrete class object to G4Event, given that the G4Event object is available only by "pointer to const". Alternatively, the user may modify the GenerateEvent() method of his/her own RunManager to instantiate a G4VUserEventInformation object and set it to G4Event.

The concrete class object is deleted by the Geant4 kernel when the associated G4Event object is deleted.

6.3.2 G4VUserTrackInformation

This is an abstract class from which the user can derive his/her own concrete class for storing user information associated with a G4Track class object. It is the user's responsibility to construct a concrete class object and set the pointer to the proper G4Track object.

Within a concrete implementation of G4UserTrackingAction, the SetUserTrackInformation() method of G4TrackingManager may be used to set a pointer of a concrete class object to G4Track, given that the G4Track object is available only by "pointer to const".

The ideal place to copy a G4VUserTrackInformation object from a mother track to its daughter tracks is G4UserTrackingAction::PostUserTrackingAction().

void RE01TrackingAction::PostUserTrackingAction(const G4Track* aTrack)
{
  G4TrackVector* secondaries = fpTrackingManager->GimmeSecondaries();
  if(secondaries)
  {
    RE01TrackInformation* info = (RE01TrackInformation*)(aTrack->GetUserInformation());
    size_t nSeco = secondaries->size();
    if(nSeco>0)
    {
      for(size_t i=0;iSetUserInformation(infoNew);
      }
    }
  }
}
 
Source listing 6.3.1
Copying G4VUserTrackInformation from mother to daughter tracks

The concrete class object is deleted by the Geant4 kernel when the associated G4Track object is deleted. In case the user wants to keep the information, it should be copied to a trajectory corresponding to the track.

6.3.3 G4VUserPrimaryVertexInformation and G4VUserPrimaryTrackInformation

These abstract classes allow the user to attach information regarding the generated primary vertex and primary particle. Concrete class objects derived from these classes should be attached to G4PrimaryVertex and G4PrimaryParticle class objects, respectively.

The concrete class objects are deleted by the Geant4 Kernel when the associated G4PrimaryVertex or G4PrimaryParticle class objects are deleted along with the deletion of G4Event.

6.3.4 G4VUserRegionInformation

This abstract base class allows the user to attach information associated with a region. For example, it would be quite beneficial to add some methods returning a boolean flag to indicate the characteristics of the region (e.g. tracker, calorimeter, etc.). With this example, the user can easily and quickly identify the detector component.

class RE01RegionInformation : public G4VUserRegionInformation
{
  public:
    RE01RegionInformation();
    ~RE01RegionInformation();
    void Print() const;

  private:
    G4bool isWorld;
    G4bool isTracker;
    G4bool isCalorimeter;

  public:
    inline void SetWorld(G4bool v=true) {isWorld = v;}
    inline void SetTracker(G4bool v=true) {isTracker = v;}
    inline void SetCalorimeter(G4bool v=true) {isCalorimeter = v;}
    inline G4bool IsWorld() const {return isWorld;}
    inline G4bool IsTracker() const {return isTracker;}
    inline G4bool IsCalorimeter() const {return isCalorimeter;}
};
 
Source listing 6.3.2
A sample region information class

The following code is an example of a stepping action. Here, a track is suspended when it enters the "calorimeter region" from the "tracker region".

void RE01SteppingAction::UserSteppingAction(const G4Step * theStep)
{
  // Suspend a track if it is entering into the calorimeter

  // check if it is alive
  G4Track * theTrack = theStep->GetTrack();
  if(theTrack->GetTrackStatus()!=fAlive) { return; }

  // get region information
  G4StepPoint * thePrePoint = theStep->GetPreStepPoint();
  G4LogicalVolume * thePreLV = thePrePoint->GetPhysicalVolume()->GetLogicalVolume();
  RE01RegionInformation* thePreRInfo
   = (RE01RegionInformation*)(thePreLV->GetRegion()->GetUserInformation());
  G4StepPoint * thePostPoint = theStep->GetPostStepPoint();
  G4LogicalVolume * thePostLV = thePostPoint->GetPhysicalVolume()->GetLogicalVolume();
  RE01RegionInformation* thePostRInfo
   = (RE01RegionInformation*)(thePostLV->GetRegion()->GetUserInformation());

  // check if it is entering to the calorimeter volume
  if(!(thePreRInfo->IsCalorimeter()) && (thePostRInfo->IsCalorimeter()))
  { theTrack->SetTrackStatus(fSuspend); }
}
 
Source listing 6.3.2
Sample use of a region information class



About the authors