| 1 | <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>6.3. User Information Classes</title><link rel="stylesheet" href="../xml/XSLCustomizationLayer/G4HTMLStylesheet.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.71.1"><link rel="start" href="index.html" title="Geant4 User's Guide for Application Developers"><link rel="up" href="ch06.html" title="Chapter 6. User Actions"><link rel="prev" href="ch06s02.html" title="6.2. Optional User Actions"><link rel="next" href="ch07.html" title="Chapter 7. Communication and Control"><script language="JavaScript">
|
|---|
| 2 | function remote_win(fName)
|
|---|
| 3 | {
|
|---|
| 4 | var url = "AllResources/Detector/geometry.src/" + fName;
|
|---|
| 5 | RemoteWin=window.open(url,"","resizable=no,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,copyhistory=0,width=520,height=520")
|
|---|
| 6 | RemoteWin.creator=self
|
|---|
| 7 | }
|
|---|
| 8 | </script></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">6.3.
|
|---|
| 9 | User Information Classes
|
|---|
| 10 | </th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch06s02.html"><img src="AllResources/IconsGIF/prev.gif" alt="Prev"></a> </td><th width="60%" align="center">Chapter 6.
|
|---|
| 11 | User Actions
|
|---|
| 12 | </th><td width="20%" align="right"> <a accesskey="n" href="ch07.html"><img src="AllResources/IconsGIF/next.gif" alt="Next"></a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="sect.UInfoCls"></a>6.3.
|
|---|
| 13 | User Information Classes
|
|---|
| 14 | </h2></div></div></div><p>
|
|---|
| 15 | Additional user information can be associated with various Geant4
|
|---|
| 16 | classes. There are basically two ways for the user to do this:
|
|---|
| 17 |
|
|---|
| 18 | </p><div class="itemizedlist"><ul type="disc" compact><li><p>
|
|---|
| 19 | derive concrete classes from base classes used in Geant4. These
|
|---|
| 20 | are classes for run, hit, digit, trajectory and trajectory point,
|
|---|
| 21 | which are discussed in
|
|---|
| 22 | <a href="ch06s02.html" title="6.2.
|
|---|
| 23 | Optional User Actions
|
|---|
| 24 | ">Section 6.2</a> for G4Run,
|
|---|
| 25 | <a href="ch04s04.html" title="4.4.
|
|---|
| 26 | Hits
|
|---|
| 27 | ">Section 4.4</a> for G4VHit,
|
|---|
| 28 | <a href="ch04s05.html" title="4.5.
|
|---|
| 29 | Digitization
|
|---|
| 30 | ">Section 4.5</a> for G4VDigit, and
|
|---|
| 31 | <a href="ch05.html#sect.Track.Traj" title="5.1.6.
|
|---|
| 32 | Trajectory and Trajectory Point
|
|---|
| 33 | ">Section 5.1.6</a> for G4VTrajectory and G4VTrajectoryPoint
|
|---|
| 34 | </p></li><li><p>
|
|---|
| 35 | create concrete classes from provided abstract base classes and
|
|---|
| 36 | associate them with classes used in Geant4. Geant4 classes which
|
|---|
| 37 | can accommodate user information classes are G4Event, G4Track,
|
|---|
| 38 | G4PrimaryVertex, G4PrimaryParticle and G4Region. These classes are
|
|---|
| 39 | discussed here.
|
|---|
| 40 | </p></li></ul></div><p>
|
|---|
| 41 | </p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.UInfoCls.UEvtInfo"></a>6.3.1.
|
|---|
| 42 | G4VUserEventInformation
|
|---|
| 43 | </h3></div></div></div><p>
|
|---|
| 44 | <span class="emphasis"><em>G4VUserEventInformation</em></span> is an abstract class from
|
|---|
| 45 | which the user can derive his/her own concrete class for storing user
|
|---|
| 46 | information associated with a G4Event class object. It is the
|
|---|
| 47 | user's responsibility to construct a concrete class object and set
|
|---|
| 48 | the pointer to a proper G4Event object.
|
|---|
| 49 | </p><p>
|
|---|
| 50 | Within a concrete implementation of G4UserEventAction, the
|
|---|
| 51 | SetUserEventInformation() method of G4EventManager may be used to
|
|---|
| 52 | set a pointer of a concrete class object to G4Event, given that the
|
|---|
| 53 | G4Event object is available only by "pointer to const".
|
|---|
| 54 | Alternatively, the user may modify the GenerateEvent() method of
|
|---|
| 55 | his/her own RunManager to instantiate a G4VUserEventInformation
|
|---|
| 56 | object and set it to G4Event.
|
|---|
| 57 | </p><p>
|
|---|
| 58 | The concrete class object is deleted by the Geant4 kernel when
|
|---|
| 59 | the associated G4Event object is deleted.
|
|---|
| 60 | </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.UInfoCls.UTkInfo"></a>6.3.2.
|
|---|
| 61 | G4VUserTrackInformation
|
|---|
| 62 | </h3></div></div></div><p>
|
|---|
| 63 | This is an abstract class from which the user can derive his/her
|
|---|
| 64 | own concrete class for storing user information associated with a
|
|---|
| 65 | G4Track class object. It is the user's responsibility to construct
|
|---|
| 66 | a concrete class object and set the pointer to the proper G4Track
|
|---|
| 67 | object.
|
|---|
| 68 | </p><p>
|
|---|
| 69 | Within a concrete implementation of G4UserTrackingAction, the
|
|---|
| 70 | SetUserTrackInformation() method of G4TrackingManager may be used
|
|---|
| 71 | to set a pointer of a concrete class object to G4Track, given that
|
|---|
| 72 | the G4Track object is available only by "pointer to const".
|
|---|
| 73 | </p><p>
|
|---|
| 74 | The ideal place to copy a G4VUserTrackInformation object from a
|
|---|
| 75 | mother track to its daughter tracks is
|
|---|
| 76 | <span class="emphasis"><em>G4UserTrackingAction::PostUserTrackingAction()</em></span>.
|
|---|
| 77 |
|
|---|
| 78 | </p><div class="example"><a name="programlist_UInfoCls_1"></a><p class="title"><b>Example 6.9.
|
|---|
| 79 | Copying <code class="literal">G4VUserTrackInformation</code> from mother to daughter tracks
|
|---|
| 80 | </b></p><div class="example-contents"><pre class="programlisting">
|
|---|
| 81 | void RE01TrackingAction::PostUserTrackingAction(const G4Track* aTrack)
|
|---|
| 82 | {
|
|---|
| 83 | G4TrackVector* secondaries = fpTrackingManager->GimmeSecondaries();
|
|---|
| 84 | if(secondaries)
|
|---|
| 85 | {
|
|---|
| 86 | RE01TrackInformation* info = (RE01TrackInformation*)(aTrack->GetUserInformation());
|
|---|
| 87 | size_t nSeco = secondaries->size();
|
|---|
| 88 | if(nSeco>0)
|
|---|
| 89 | {
|
|---|
| 90 | for(size_t i=0; i < nSeco; i++)
|
|---|
| 91 | {
|
|---|
| 92 | RE01TrackInformation* infoNew = new RE01TrackInformation(info);
|
|---|
| 93 | (*secondaries)[i]->SetUserInformation(infoNew);
|
|---|
| 94 | }
|
|---|
| 95 | }
|
|---|
| 96 | }
|
|---|
| 97 | }
|
|---|
| 98 | </pre></div></div><p><br class="example-break">
|
|---|
| 99 | </p><p>
|
|---|
| 100 | The concrete class object is deleted by the Geant4 kernel when
|
|---|
| 101 | the associated G4Track object is deleted. In case the user wants to
|
|---|
| 102 | keep the information, it should be copied to a trajectory
|
|---|
| 103 | corresponding to the track.
|
|---|
| 104 | </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.UInfoCls.UPrimVxTk"></a>6.3.3.
|
|---|
| 105 | G4VUserPrimaryVertexInformation and G4VUserPrimaryTrackInformation
|
|---|
| 106 | </h3></div></div></div><p>
|
|---|
| 107 | These abstract classes allow the user to attach information
|
|---|
| 108 | regarding the generated primary vertex and primary particle.
|
|---|
| 109 | Concrete class objects derived from these classes should be
|
|---|
| 110 | attached to <span class="emphasis"><em>G4PrimaryVertex</em></span> and
|
|---|
| 111 | <span class="emphasis"><em>G4PrimaryParticle</em></span> class objects, respectively.
|
|---|
| 112 | </p><p>
|
|---|
| 113 | The concrete class objects are deleted by the Geant4 Kernel when
|
|---|
| 114 | the associated G4PrimaryVertex or G4PrimaryParticle class objects
|
|---|
| 115 | are deleted along with the deletion of G4Event.
|
|---|
| 116 | </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="sect.UInfoCls.URegInfo"></a>6.3.4.
|
|---|
| 117 | G4VUserRegionInformation
|
|---|
| 118 | </h3></div></div></div><p>
|
|---|
| 119 | This abstract base class allows the user to attach information
|
|---|
| 120 | associated with a region. For example, it would be quite beneficial
|
|---|
| 121 | to add some methods returning a boolean flag to indicate the
|
|---|
| 122 | characteristics of the region (e.g. tracker, calorimeter, etc.).
|
|---|
| 123 | With this example, the user can easily and quickly identify the
|
|---|
| 124 | detector component.
|
|---|
| 125 |
|
|---|
| 126 | </p><div class="example"><a name="programlist_UInfoCls_2"></a><p class="title"><b>Example 6.10.
|
|---|
| 127 | A sample region information class
|
|---|
| 128 | </b></p><div class="example-contents"><pre class="programlisting">
|
|---|
| 129 | class RE01RegionInformation : public G4VUserRegionInformation
|
|---|
| 130 | {
|
|---|
| 131 | public:
|
|---|
| 132 | RE01RegionInformation();
|
|---|
| 133 | ~RE01RegionInformation();
|
|---|
| 134 | void Print() const;
|
|---|
| 135 |
|
|---|
| 136 | private:
|
|---|
| 137 | G4bool isWorld;
|
|---|
| 138 | G4bool isTracker;
|
|---|
| 139 | G4bool isCalorimeter;
|
|---|
| 140 |
|
|---|
| 141 | public:
|
|---|
| 142 | inline void SetWorld(G4bool v=true) {isWorld = v;}
|
|---|
| 143 | inline void SetTracker(G4bool v=true) {isTracker = v;}
|
|---|
| 144 | inline void SetCalorimeter(G4bool v=true) {isCalorimeter = v;}
|
|---|
| 145 | inline G4bool IsWorld() const {return isWorld;}
|
|---|
| 146 | inline G4bool IsTracker() const {return isTracker;}
|
|---|
| 147 | inline G4bool IsCalorimeter() const {return isCalorimeter;}
|
|---|
| 148 | };
|
|---|
| 149 | </pre></div></div><p><br class="example-break">
|
|---|
| 150 | </p><p>
|
|---|
| 151 | The following code is an example of a stepping action. Here, a
|
|---|
| 152 | track is suspended when it enters the "calorimeter region" from the
|
|---|
| 153 | "tracker region".
|
|---|
| 154 |
|
|---|
| 155 | </p><div class="example"><a name="programlist_UInfoCls_3"></a><p class="title"><b>Example 6.11.
|
|---|
| 156 | Sample use of a region information class
|
|---|
| 157 | </b></p><div class="example-contents"><pre class="programlisting">
|
|---|
| 158 | void RE01SteppingAction::UserSteppingAction(const G4Step * theStep)
|
|---|
| 159 | {
|
|---|
| 160 | // Suspend a track if it is entering into the calorimeter
|
|---|
| 161 |
|
|---|
| 162 | // check if it is alive
|
|---|
| 163 | G4Track * theTrack = theStep->GetTrack();
|
|---|
| 164 | if(theTrack->GetTrackStatus()!=fAlive) { return; }
|
|---|
| 165 |
|
|---|
| 166 | // get region information
|
|---|
| 167 | G4StepPoint * thePrePoint = theStep->GetPreStepPoint();
|
|---|
| 168 | G4LogicalVolume * thePreLV = thePrePoint->GetPhysicalVolume()->GetLogicalVolume();
|
|---|
| 169 | RE01RegionInformation* thePreRInfo
|
|---|
| 170 | = (RE01RegionInformation*)(thePreLV->GetRegion()->GetUserInformation());
|
|---|
| 171 | G4StepPoint * thePostPoint = theStep->GetPostStepPoint();
|
|---|
| 172 | G4LogicalVolume * thePostLV = thePostPoint->GetPhysicalVolume()->GetLogicalVolume();
|
|---|
| 173 | RE01RegionInformation* thePostRInfo
|
|---|
| 174 | = (RE01RegionInformation*)(thePostLV->GetRegion()->GetUserInformation());
|
|---|
| 175 |
|
|---|
| 176 | // check if it is entering to the calorimeter volume
|
|---|
| 177 | if(!(thePreRInfo->IsCalorimeter()) && (thePostRInfo->IsCalorimeter()))
|
|---|
| 178 | { theTrack->SetTrackStatus(fSuspend); }
|
|---|
| 179 | }
|
|---|
| 180 | </pre></div></div><p><br class="example-break">
|
|---|
| 181 | </p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch06s02.html"><img src="AllResources/IconsGIF/prev.gif" alt="Prev"></a> </td><td width="20%" align="center"><a accesskey="u" href="ch06.html"><img src="AllResources/IconsGIF/up.gif" alt="Up"></a></td><td width="40%" align="right"> <a accesskey="n" href="ch07.html"><img src="AllResources/IconsGIF/next.gif" alt="Next"></a></td></tr><tr><td width="40%" align="left" valign="top">6.2.
|
|---|
| 182 | Optional User Actions
|
|---|
| 183 | </td><td width="20%" align="center"><a accesskey="h" href="index.html"><img src="AllResources/IconsGIF/home.gif" alt="Home"></a></td><td width="40%" align="right" valign="top"> Chapter 7.
|
|---|
| 184 | Communication and Control
|
|---|
| 185 | </td></tr></table></div></body></html>
|
|---|