Message: Re: Passing info to tracks Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

None Re: Passing info to tracks 

Forum: Event and Track Management
Re: Question Passing info to tracks (Jean-Pascal Laedermann)
Date: 12 Sep, 2009
From: Tom Roberts <Tom Roberts>

There is G4Track::SetUserInformation() which is designed specifically for this.

In PreUserTrackingAction() I do:
    TrackInfo *info = new TrackInfo(...);
    ((G4Track *)track)->SetUserInformation(info);

Another possibility is to define a std::map<G4Track*,TrackInfo>, add an entry in PreUserTrackingAction(), and clear it in PostUserTrackingAction() (or wherever makes sense -- you may not need the vector at all as there may only be a single track involved). Note that the Geant4 kernel will delete the track, so be careful about dereferencing its pointer -- it may be better and more useful to define the map using TrackID rather than a pointer to the G4Track (e.g. if it has Event scope then it can be used for ParentID-s also).

What I do is have a Manager class of my own that implements all of the User Actions (plus detector construction, primary event generator, and exception handler). This class can have data independent of the Geant4 code. Because of the way the user action objects are deleted by Geant4 code, I have a helper class for each that provides a separate object that merely re-directs to the singleton Manager object itself.

Be careful if you try to derive your own class from G4Track, because it uses G4Allocator (which implicitly knows the object's size).

 Add Message Add Message
to: "Re: Passing info to tracks"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews

[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]