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.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]
1 -------------------------------------------------------------------
2
3 =========================================================
4 Geant4 - an Object-Oriented Toolkit for Simulation in HEP
5 =========================================================
6
7 Example B4
8 -----------
9
10 This example simulates a simple Sampling Calorimeter setup.
11 To demonstrate several possible ways of data scoring, the example
12 is provided in four variants: B4a, B4b, B4c, B4d.
13 (See also examples/extended/electromagnetic/TestEm3 or hadronic/Hadr05)
14
15 1- GEOMETRY DEFINITION
16
17 The geometry is constructed in B4[c,d]::DetectorConstruction class.
18 The calorimeter is a box made of a given number of layers. A layer
19 consists of an absorber plate and of a detection gap. The layer is
20 replicated.
21
22 Four parameters define the geometry of the calorimeter :
23 - the thickness of an absorber plate,
24 - the thickness of a gap,
25 - the number of layers, and
26 - the transverse size of the calorimeter (the entrance face is a square).
27
28 In addition, a global, uniform, and transverse magnetic field can be
29 applied using G4GlobalMagFieldMessenger, instantiated in
30 B4[c,d]::DetectorConstruction::ConstructSDandField
31 with a non zero field value, or via interactive commands.
32 For example:
33
34 /globalField/setValue 0.2 0 0 tesla
35
36
37 |<----layer 0---------->|<----layer 1---------->|<----layer 2---------->|
38 | | | |
39 ==========================================================================
40 || | || | || | ||
41 || | || | || | ||
42 beam || absorber | gap || absorber | gap || absorber | gap ||
43 ======> || | || | || | ||
44 || | || | || | ||
45 ==========================================================================
46
47 A more general version of this geometry can be found in:
48 examples/extended/electromagnetic/TestEm3 or hadronic/Hadr05
49 where all the geometry parameters, the absorber and gap materials
50 can be modified interactively via the commands defined in the DetectorMessenger
51 class.
52
53 2- PHYSICS LIST
54
55 The particle's type and the physic processes which will be available
56 in this example are set in the FTFP_BERT physics list. This physics list
57 requires data files for electromagnetic and hadronic processes.
58 See more on installation of the datasets in Geant4 Installation Guide,
59 Chapter 3.3: Note On Geant4 Datasets:
60 http://geant4.web.cern.ch/geant4/UserDocumentation/UsersGuides/InstallationGuide/html/ch03s03.html
61 The following datasets: G4LEDATA, G4LEVELGAMMADATA, G4SAIDXSDATA and
62 G4ENSDFSTATEDATA are mandatory for this example.
63
64 In addition the build-in interactive command:
65 /process/(in)activate processName
66 allows to activate/inactivate the processes one by one.
67
68 3- ACTION INITALIZATION
69
70 A newly introduced class, B4[a,b,c,d]::ActionInitialization,
71 instantiates and registers to Geant4 kernel all user action classes.
72
73 While in sequential mode the action classes are instatiated just once,
74 via invoking the method:
75 B4[a,b,c,d]::ActionInitialization::Build()
76 in multi-threading mode the same method is invoked for each thread worker
77 and so all user action classes are defined thread-local.
78
79 A run action class is instantiated both thread-local
80 and global that's why its instance is created also in the method
81 B4[a,b,c,d]::ActionInitialization::BuildForMaster()
82 which is invoked only in multi-threading mode.
83
84 4- PRIMARY GENERATOR
85
86 The primary beam consists of a single particle which hits the
87 calorimeter perpendicular to the input face. The type of the particle
88 and its energy are set in the B4::PrimaryGeneratorAction class, and can
89 be changed via the G4 built-in commands of the G4ParticleGun class (see
90 the macros provided with this example).
91
92 5- RUNS and EVENTS
93
94 A run is a set of events.
95 The user can choose the frequency of printing via the Geant4 interactive
96 command, for example:
97
98 /run/printProgress 100
99
100 6- DETECTOR RESPONSE
101
102 The energy deposit and track lengths of the charged particles are recorded on
103 an event by event basis in the Absober and Gap layers.
104
105 In order to demonstrate several possible ways of data scoring,
106 the example is provided in four variants:
107
108 Variant a: User Actions
109
110 These 4 quantities are data members of the B4a::EventAction class.
111 They are collected step by step in
112 B4a::SteppingAction::UserSteppingAction(), and passed to the event action
113 via two methods: B4a::EventAction::AddAbs() and B4a::EventAction::AddGap().
114
115 In B4a::EventAction::EndOfEventAction(), these quantities are printed and
116 filled in H1D histograms and ntuple to accumulate statistic and compute
117 dispersion.
118
119 Variant b: User data object
120
121 In order to avoid dependencies between action classes, a user object
122 B4b::RunData, derived from G4Run, is defined with data members needed
123 for the accounted information.
124 In order to reduce the number of data members a 2-dimensions array
125 is introduced for each quantity.
126 Then the quantities are collected step by step in user action classes:
127 B4b::SteppingAction::UserSteppingAction() and
128 B4b::EventAction::EndOfEventAction() in a similar way as in variant a.
129
130 Variant c: Hits and Sensitive detectors
131
132 In this option, the physics quantities are accounted using the hits
133 and sensitive detectors framework defined in the Geant4 kernel.
134 The physics quantities are stored in B4c::CalorHit via two B4c::CalorimeterSD
135 objects, one associated with the Absorber volume and another one with Gap
136 in B4c::DetectorConstruction::ConstructSDandField().
137
138 In contrary to the B2 example (Tracker) where a new hit is created
139 with each track passing the sensitive volume (in the calorimeter), only one
140 hit is created for each calorimeter layer and one more hit to account for
141 the total quantities in all layers. In addition to the variants a and b,
142 the quantities per each layer are also available in addition to the total
143 quantities.
144
145 Variant d: Scorer
146
147 In this option, the Geant4 scorers which are defined on the top of hits
148 and sensitive detectors Geant4 framework are used.
149 In practice this means that the user does not need to define hits and sensitive
150 detector classes but rather uses the classes already defined
151 in Geant4. In this example, the G4MultiFunctionalDetector with
152 G4PSEnergyDeposit and G4PSTrackLength primitive scores are used (see
153 B4d::DetectorConstruction::ConstructSDandField()).
154
155 The scorers hits are saved in form of ntuples in a Root file using Geant4
156 analysis tools. This feature is activated in the main () function with instantiating
157 G4TScoreNtupleWriter.
158
159 Also with this approach, the quantities per each layer are available
160 in addition to the total quantities.
161
162 7- HISTOGRAMS
163
164 The analysis tools are used to accumulate statistics and compute the dispersion
165 of the energy deposit and track lengths of the charged particles.
166 H1D histograms are created in B4[b]::RunAction::RunAction() for the
167 following quantities:
168 - Energy deposit in absorber
169 - Energy deposit in gap
170 - Track length in absorber
171 - Track length in gap
172
173 The same values are also saved in an ntuple.
174
175 The histograms and the ntuple are saved in the output file in a format
176 according to a specified file extension, the default in this example
177 is ROOT.
178
179 The accumulated statistic and computed dispersion is printed at the end of
180 run, in B4::RunAction::EndOfRunAction().
181 When running in multi-threading mode, the histograms and the ntuple accumulated
182 on threads are merged in a single output file. While merging of histograms is
183 performed by default, merging of ntuples is explicitly activated in the B4::RunAction
184 constructor.
185
186 The ROOT histograms and ntuple can be plotted with ROOT using the plotHisto.C
187 and plotNtuple.C macros.
188
189 8- HOW TO RUN
190
191 This example handles the program arguments in a new way.
192 It can be run with the following optional arguments:
193 % exampleB4a [-m macro ] [-u UIsession] [-t nThreads] [-vDefault]
194
195 The -vDefault option will activate using the default Geant4 stepping verbose
196 class (G4SteppingVerbose) instead of the enhanced stepping verbose with best
197 units (G4SteppingVerboseWithUnits) used in the example by default.
198
199 The -t option is available only in multi-threading mode
200 and it allows the user to override the Geant4 default number of
201 threads. The number of threads can be also set via G4FORCENUMBEROFTHREADS
202 environment variable which has the top priority.
203
204 - Execute exampleB4a in the 'interactive mode' with visualization
205 % exampleB4a
206 and type in the commands from run1.mac line by line:
207 Idle> /tracking/verbose 1
208 Idle> /run/beamOn 1
209 Idle> ...
210 Idle> exit
211 or
212 Idle> /control/execute run1.mac
213 ....
214 Idle> exit
215
216 - Execute exampleB4a in the 'batch' mode from macro files
217 (without visualization)
218 % exampleB4a -m run2.mac
219 % exampleB4a -m exampleB4.in > exampleB4.out
220
221 - Execute exampleB4a in the 'interactive mode' with a selected UI session,
222 e.g. tcsh
223 % exampleB4a -u tcsh
224
225 The following paragraphs are common to all basic examples
226
227 A- VISUALIZATION
228
229 The visualization manager is set via the G4VisExecutive class
230 in the main() function in exampleB4a.cc.
231 The initialisation of the drawing is done via a set of /vis/ commands
232 in the macro vis.mac. This macro is automatically read from
233 the main function when the example is used in interactive running mode.
234
235 By default, vis.mac opens an OpenGL viewer (/vis/open OGL).
236 The user can change the initial viewer by commenting out this line
237 and instead uncommenting one of the other /vis/open statements, such as
238 HepRepFile or DAWNFILE (which produce files that can be viewed with the
239 HepRApp and DAWN viewers, respectively). Note that one can always
240 open new viewers at any time from the command line. For example, if
241 you already have a view in, say, an OpenGL window with a name
242 "viewer-0", then
243 /vis/open DAWNFILE
244 then to get the same view
245 /vis/viewer/copyView viewer-0
246 or to get the same view *plus* scene-modifications
247 /vis/viewer/set/all viewer-0
248 then to see the result
249 /vis/viewer/flush
250
251 The DAWNFILE, HepRepFile drivers are always available
252 (since they require no external libraries), but the OGL driver requires
253 that the Geant4 libraries have been built with the OpenGL option.
254
255 Since 11.1, the TSG visualization driver can also produce the "offscrean"
256 file output in png, jpeg, gl2ps formats without drawing on the screen.
257 It can be controlled via UI commands provided in '/vis/tsg' which are
258 demonstrated in the tsg_offscreen.mac macro in example B5.
259
260 For more information on visualization, including information on how to
261 install and run DAWN, OpenGL and HepRApp, see the visualization tutorials,
262 for example,
263 http://geant4.slac.stanford.edu/Presentations/vis/G4[VIS]Tutorial/G4[VIS]Tutorial.html
264 (where [VIS] can be replaced by DAWN, OpenGL and HepRApp)
265
266 The tracks are automatically drawn at the end of each event, accumulated
267 for all events and erased at the beginning of the next run.
268
269 B- USER INTERFACES
270
271 The user command interface is set via the G4UIExecutive class
272 in the main() function in exampleB4a.cc
273
274 The selection of the user command interface is then done automatically
275 according to the Geant4 configuration or it can be done explicitly via
276 the third argument of the G4UIExecutive constructor (see exampleB4a.cc).
277
278 The gui.mac macros are provided in examples B2, B4 and B5. This macro
279 is automatically executed if Geant4 is built with any GUI session.
280 It is also possible to customise the icons menu bar which is
281 demonstrated in the icons.mac macro in example B5.