source: trunk/Documentation/geant4/UserDocumentation/UsersGuides/ForApplicationDeveloper/html/ch06s03.html@ 901

Last change on this file since 901 was 901, checked in by garnier, 17 years ago

Add Geant4 Documentation at 8.12.2008

File size: 9.9 KB
Line 
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">
2function 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. 
9User 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. 
11User 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. 
13User Information Classes
14</h2></div></div></div><p>
15Additional user information can be associated with various Geant4
16classes. 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. 
23Optional User Actions
24">Section 6.2</a> for G4Run,
25 <a href="ch04s04.html" title="4.4. 
26Hits
27">Section 4.4</a> for G4VHit,
28 <a href="ch04s05.html" title="4.5. 
29Digitization
30">Section 4.5</a> for G4VDigit, and
31 <a href="ch05.html#sect.Track.Traj" title="5.1.6. 
32Trajectory 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. 
42G4VUserEventInformation
43</h3></div></div></div><p>
44<span class="emphasis"><em>G4VUserEventInformation</em></span> is an abstract class from
45which the user can derive his/her own concrete class for storing user
46information associated with a G4Event class object. It is the
47user's responsibility to construct a concrete class object and set
48the pointer to a proper G4Event object.
49</p><p>
50Within a concrete implementation of G4UserEventAction, the
51SetUserEventInformation() method of G4EventManager may be used to
52set a pointer of a concrete class object to G4Event, given that the
53G4Event object is available only by "pointer to const".
54Alternatively, the user may modify the GenerateEvent() method of
55his/her own RunManager to instantiate a G4VUserEventInformation
56object and set it to G4Event.
57</p><p>
58The concrete class object is deleted by the Geant4 kernel when
59the 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. 
61G4VUserTrackInformation
62</h3></div></div></div><p>
63This is an abstract class from which the user can derive his/her
64own concrete class for storing user information associated with a
65G4Track class object. It is the user's responsibility to construct
66a concrete class object and set the pointer to the proper G4Track
67object.
68</p><p>
69Within a concrete implementation of G4UserTrackingAction, the
70SetUserTrackInformation() method of G4TrackingManager may be used
71to set a pointer of a concrete class object to G4Track, given that
72the G4Track object is available only by "pointer to const".
73</p><p>
74The ideal place to copy a G4VUserTrackInformation object from a
75mother 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. 
79Copying <code class="literal">G4VUserTrackInformation</code> from mother to daughter tracks
80</b></p><div class="example-contents"><pre class="programlisting">
81void RE01TrackingAction::PostUserTrackingAction(const G4Track* aTrack)
82{
83 G4TrackVector* secondaries = fpTrackingManager-&gt;GimmeSecondaries();
84 if(secondaries)
85 {
86 RE01TrackInformation* info = (RE01TrackInformation*)(aTrack-&gt;GetUserInformation());
87 size_t nSeco = secondaries-&gt;size();
88 if(nSeco&gt;0)
89 {
90 for(size_t i=0; i &lt; nSeco; i++)
91 {
92 RE01TrackInformation* infoNew = new RE01TrackInformation(info);
93 (*secondaries)[i]-&gt;SetUserInformation(infoNew);
94 }
95 }
96 }
97}
98</pre></div></div><p><br class="example-break">
99</p><p>
100The concrete class object is deleted by the Geant4 kernel when
101the associated G4Track object is deleted. In case the user wants to
102keep the information, it should be copied to a trajectory
103corresponding 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. 
105G4VUserPrimaryVertexInformation and G4VUserPrimaryTrackInformation
106</h3></div></div></div><p>
107These abstract classes allow the user to attach information
108regarding the generated primary vertex and primary particle.
109Concrete class objects derived from these classes should be
110attached to <span class="emphasis"><em>G4PrimaryVertex</em></span> and
111<span class="emphasis"><em>G4PrimaryParticle</em></span> class objects, respectively.
112</p><p>
113The concrete class objects are deleted by the Geant4 Kernel when
114the associated G4PrimaryVertex or G4PrimaryParticle class objects
115are 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. 
117G4VUserRegionInformation
118</h3></div></div></div><p>
119This abstract base class allows the user to attach information
120associated with a region. For example, it would be quite beneficial
121to add some methods returning a boolean flag to indicate the
122characteristics of the region (e.g. tracker, calorimeter, etc.).
123With this example, the user can easily and quickly identify the
124detector component.
125
126</p><div class="example"><a name="programlist_UInfoCls_2"></a><p class="title"><b>Example 6.10. 
127A sample region information class
128</b></p><div class="example-contents"><pre class="programlisting">
129class 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>
151The following code is an example of a stepping action. Here, a
152track 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. 
156Sample use of a region information class
157</b></p><div class="example-contents"><pre class="programlisting">
158void 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-&gt;GetTrack();
164 if(theTrack-&gt;GetTrackStatus()!=fAlive) { return; }
165
166 // get region information
167 G4StepPoint * thePrePoint = theStep-&gt;GetPreStepPoint();
168 G4LogicalVolume * thePreLV = thePrePoint-&gt;GetPhysicalVolume()-&gt;GetLogicalVolume();
169 RE01RegionInformation* thePreRInfo
170 = (RE01RegionInformation*)(thePreLV-&gt;GetRegion()-&gt;GetUserInformation());
171 G4StepPoint * thePostPoint = theStep-&gt;GetPostStepPoint();
172 G4LogicalVolume * thePostLV = thePostPoint-&gt;GetPhysicalVolume()-&gt;GetLogicalVolume();
173 RE01RegionInformation* thePostRInfo
174 = (RE01RegionInformation*)(thePostLV-&gt;GetRegion()-&gt;GetUserInformation());
175
176 // check if it is entering to the calorimeter volume
177 if(!(thePreRInfo-&gt;IsCalorimeter()) &amp;&amp; (thePostRInfo-&gt;IsCalorimeter()))
178 { theTrack-&gt;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. 
182Optional 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. 
184Communication and Control
185</td></tr></table></div></body></html>
Note: See TracBrowser for help on using the repository browser.