User Information Classes
Additional user information can be associated with various Geant4
classes. There are basically two ways for the user to do this:
derive concrete classes from base classes used in Geant4. These
are classes for run, hit, digit, trajectory and trajectory point,
which are discussed in
for G4Run,
for G4VHit,
for G4VDigit, and
for G4VTrajectory and G4VTrajectoryPoint
create concrete classes from provided abstract base classes and
associate them with classes used in Geant4. Geant4 classes which
can accommodate user information classes are G4Event, G4Track,
G4PrimaryVertex, G4PrimaryParticle and G4Region. These classes are
discussed here.
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.
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().
Copying G4VUserTrackInformation from mother to daughter tracks
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; i < nSeco; i++)
{
RE01TrackInformation* infoNew = new RE01TrackInformation(info);
(*secondaries)[i]->SetUserInformation(infoNew);
}
}
}
}
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.
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.
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.
A sample region information class
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;}
};
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".
Sample use of a region information class
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); }
}