Warning, /geant4/examples/basic/B4/README.md is written in an unsupported language. File is not indexed.
0001 \page ExampleB4 Example B4
0002
0003 This example simulates a simple Sampling Calorimeter setup.
0004 To demonstrate several possible ways of data scoring, the example
0005 is provided in four variants: %B4a, %B4b, %B4c, %B4d.
0006 (See also examples/extended/electromagnetic/TestEm3 or hadronic/Hadr05)
0007
0008 ## GEOMETRY DEFINITION
0009
0010 The geometry is constructed in B4::DetectorConstruction class
0011 (see also
0012 \link B4c::DetectorConstruction B4c \endlink,
0013 \link B4d::DetectorConstruction B4d \endlink variants).
0014 The calorimeter is a box made of a given number of layers. A layer
0015 consists of an absorber plate and of a detection gap. The layer is
0016 replicated.
0017
0018 Four parameters define the geometry of the calorimeter :
0019 - the thickness of an absorber plate,
0020 - the thickness of a gap,
0021 - the number of layers, and
0022 - the transverse size of the calorimeter (the entrance face is a square).
0023
0024 In addition, a global, uniform, and transverse magnetic field can be
0025 applied using G4GlobalMagFieldMessenger, instantiated in
0026 B4::DetectorConstruction::ConstructSDandField()
0027 (see also
0028 \link B4c::DetectorConstruction::ConstructSDandField() B4c \endlink,
0029 \link B4d::DetectorConstruction::ConstructSDandField() B4d \endlink variants)
0030 with a non zero field value, or via interactive commands.
0031 For example:
0032
0033 ```
0034 /globalField/setValue 0.2 0 0 tesla
0035 ```
0036
0037 <pre>
0038 |<----layer 0---------->|<----layer 1---------->|<----layer 2---------->|
0039 | | | |
0040 ==========================================================================
0041 || | || | || | ||
0042 || | || | || | ||
0043 beam || absorber | gap || absorber | gap || absorber | gap ||
0044 ======> || | || | || | ||
0045 || | || | || | ||
0046 ==========================================================================
0047
0048 </pre>
0049
0050 A more general version of this geometry can be found in:
0051 examples/extended/electromagnetic/TestEm3 or hadronic/Hadr05
0052 where all the geometry parameters, the absorber and gap materials
0053 can be modified interactively via the commands defined in the DetectorMessenger
0054 class.
0055
0056 ## PHYSICS LIST
0057
0058 The particle's type and the physic processes which will be available
0059 in this example are set in the FTFP_BERT physics list. This physics list
0060 requires data files for electromagnetic and hadronic processes.
0061 See more on installation of the datasets in
0062 <a href="http://geant4.web.cern.ch/geant4/UserDocumentation/UsersGuides/InstallationGuide/html/ch03s03.html">
0063 Geant4 Installation Guide, Chapter 3.3: Note On Geant4 Datasets </a>.
0064 The following datasets: G4LEDATA, G4LEVELGAMMADATA, G4SAIDXSDATA and
0065 G4ENSDFSTATEDATA are mandatory for this example.
0066
0067 In addition the build-in interactive command:
0068 ```
0069 /process/(in)activate processName
0070 ```
0071 allows to activate/inactivate the processes one by one.
0072
0073 ## ACTION INITALIZATION
0074
0075 A newly introduced class, B4a::ActionInitialization, (see also
0076 \link B4b::ActionInitialization B4b \endlink,
0077 \link B4c::ActionInitialization B4c \endlink,
0078 \link B4d::ActionInitialization B4d \endlink variants),
0079 instantiates and registers to Geant4 kernel all user action classes;
0080
0081 While in sequential mode the action classes are instatiated just once,
0082 via invoking the method:
0083 B4a::ActionInitialization::Build()
0084 (see also
0085 \link B4b::ActionInitialization::Build() B4b \endlink,
0086 \link B4c::ActionInitialization::Build() B4c \endlink,
0087 \link B4d::ActionInitialization::Build() B4d \endlink variants),
0088 in multi-threading mode the same method is invoked for each thread worker
0089 and so all user action classes are defined thread-local.
0090
0091 A run action class is instantiated both thread-local
0092 and global that's why its instance is created also in the method
0093 B4a::ActionInitialization::BuildForMaster()
0094 (see also
0095 \link B4b::ActionInitialization::BuildForMaster() B4b \endlink,
0096 \link B4c::ActionInitialization::BuildForMaster() B4c \endlink,
0097 \link B4d::ActionInitialization::BuildForMaster() B4d \endlink variants),
0098 which is invoked only in multi-threading mode.
0099
0100 ## PRIMARY GENERATOR
0101
0102 The primary beam consists of a single particle which hits the
0103 calorimeter perpendicular to the input face. The type of the particle
0104 and its energy are set in the B4::PrimaryGeneratorAction class, and can
0105 be changed via the G4 built-in commands of the G4ParticleGun class (see
0106 the macros provided with this example).
0107
0108 ## RUNS and EVENTS
0109
0110 A run is a set of events.
0111
0112 The user can choose the frequency of printing via the Geant4 interactive
0113 command, for example:
0114 ```
0115 /run/printProgress 100
0116 ```
0117
0118 ## DETECTOR RESPONSE
0119
0120 The energy deposit and track lengths of the charged particles are recorded on
0121 an event by event basis in the Absober and Gap layers.
0122
0123 In order to demonstrate several possible ways of data scoring,
0124 the example is provided in four variants:
0125
0126 ### Variant a: User Actions
0127
0128 These 4 quantities are data members of the B4a::EventAction class.
0129 They are collected step by step in
0130 B4a::SteppingAction::UserSteppingAction(), and passed to the event action
0131 via two methods: B4a::EventAction::AddAbs() and B4a::EventAction::AddGap().
0132
0133 In B4a::EventAction::EndOfEventAction(), these quantities are printed and
0134 filled in H1D histograms and ntuple to accumulate statistic and compute
0135 dispersion.
0136
0137 ### Variant b: User data object
0138
0139 In order to avoid dependencies between action classes, a user object
0140 B4b::RunData, derived from G4Run, is defined with data members needed
0141 for the accounted information.
0142 In order to reduce the number of data members a 2-dimensions array
0143 is introduced for each quantity.
0144 Then the quantities are collected step by step in user action classes:
0145 B4b::SteppingAction::UserSteppingAction() and
0146 B4b::EventAction::EndOfEventAction() in a similar way as in variant a.
0147
0148 ### Variant c: Hits and Sensitive detectors
0149
0150 In this option, the physics quantities are accounted using the hits
0151 and sensitive detectors framework defined in the Geant4 kernel.
0152 The physics quantities are stored in B4c::CalorHit via two B4c::CalorimeterSD
0153 objects, one associated with the Absorber volume and another one with Gap
0154 in B4c::DetectorConstruction::ConstructSDandField().
0155
0156 In contrary to the B2 example (Tracker) where a new hit is created
0157 with each track passing the sensitive volume (in the calorimeter), only one
0158 hit is created for each calorimeter layer and one more hit to account for
0159 the total quantities in all layers. In addition to the variants a and b,
0160 the quantities per each layer are also available in addition to the total
0161 quantities.
0162
0163 ### Variant d: Scorer
0164
0165 In this option, the Geant4 scorers which are defined on the top of hits
0166 and sensitive detectors Geant4 framework are used.
0167 In practice this means that the user does not need to define hits and sensitive
0168 detector classes but rather uses the classes already defined
0169 in Geant4. In this example, the G4MultiFunctionalDetector with
0170 G4PSEnergyDeposit and G4PSTrackLength primitive scores are used (see
0171 B4d::DetectorConstruction::ConstructSDandField()).
0172
0173 The scorers hits are saved in form of ntuples in a Root file using Geant4
0174 analysis tools. This feature is activated in the main() function with instantiating
0175 G4TScoreNtupleWriter.
0176
0177 Also with this approach, the quantities per each layer are available
0178 in addition to the total quantities.
0179
0180 ## HISTOGRAMS
0181
0182 The analysis tools are used to accumulate statistics and compute the dispersion
0183 of the energy deposit and track lengths of the charged particles.
0184 H1D histograms are created in B4::RunAction::RunAction() (see also
0185 \link B4b::RunAction::RunAction() B4b \endlink variant) for the
0186 following quantities:
0187 - Energy deposit in absorber
0188 - Energy deposit in gap
0189 - Track length in absorber
0190 - Track length in gap
0191
0192 The same values are also saved in an ntuple.
0193
0194 The histograms and the ntuple are saved in the output file in a format
0195 according to a specified file extension, the default in this example
0196 is ROOT.
0197
0198 The accumulated statistic and computed dispersion is printed at the end of
0199 run, in B4::RunAction::EndOfRunAction() ((see also
0200 \link B4b::RunAction::EndOfRunAction() B4b \endlink variant).
0201 When running in multi-threading mode, the histograms and the ntuple accumulated
0202 on threads are merged in a single output file. While merging of histograms is
0203 performed by default, merging of ntuples is explicitly activated in the B4::RunAction
0204 constructor.
0205
0206 The ROOT histograms and ntuple can be plotted with ROOT using the plotHisto.C
0207 and plotNtuple.C macros.
0208
0209 ## HOW TO RUN
0210
0211 This example handles the program arguments in a new way.
0212 It can be run with the following optional arguments:
0213 ```
0214 % exampleB4a [-m macro ] [-u UIsession] [-t nThreads] [-vDefault]
0215 ```
0216
0217 The -vDefault option will activate using the default Geant4 stepping verbose
0218 class (G4SteppingVerbose) instead of the enhanced stepping verbose with best
0219 units (G4SteppingVerboseWithUnits) used in the example by default.
0220
0221 The -t option is available only in multi-threading mode
0222 and it allows the user to override the Geant4 default number of
0223 threads. The number of threads can be also set via G4FORCENUMBEROFTHREADS
0224 environment variable which has the top priority.
0225
0226 - Execute exampleB4a in the 'interactive mode' with visualization
0227 ```
0228 % exampleB4a
0229 and type in the commands from run1.mac line by line:
0230 Idle> /tracking/verbose 1
0231 Idle> /run/beamOn 1
0232 Idle> ...
0233 Idle> exit
0234 ```
0235 or
0236 ```
0237 Idle> /control/execute run1.mac
0238 ....
0239 Idle> exit
0240 ```
0241
0242 - Execute exampleB4a in the 'batch' mode from macro files
0243 (without visualization)
0244 ```
0245 % exampleB4a -m run2.mac
0246 % exampleB4a -m exampleB4.in > exampleB4.out
0247 ```
0248
0249 - Execute exampleB4a in the 'interactive mode' with a selected UI session,
0250 e.g. tcsh
0251 ```
0252 % exampleB4a -u tcsh
0253 ```
0254
0255 <hr>
0256
0257 The following paragraphs are common to all basic examples
0258
0259 ## VISUALISATION
0260
0261 The visualization manager is set via the G4VisExecutive class
0262 in the main() function in exampleB4a.cc (or exampleB4b.cc, exampleB4c.cc,
0263 exampleB4d.cc).
0264 The initialisation of the drawing is done via a set of /vis/ commands
0265 in the macro vis.mac. This macro is automatically read from
0266 the main function when the example is used in interactive running mode.
0267
0268 By default, vis.mac opens the default viewer (/vis/open).
0269 This chooses a graphics system (in order of priority):
0270 - by argument in G4VisExecutive construction.
0271 - by environment variable, G4VIS_DEFAULT_DRIVER.
0272 - by information in ~/.g4session.
0273 - by mode (batch/interactive) and if interactive, by your build flags.
0274
0275 The user can change the initial viewer
0276 - with environment variable G4VIS_DEFAULT_DRIVER. The format is
0277 ```
0278 <graphics-system> [<window-size-hint>]
0279 ```
0280 Set this, e.g:
0281 - (bash) export G4VIS_DEFAULT_DRIVER=TSG
0282 - (tcsh) setenv G4VIS_DEFAULT_DRIVER OI
0283 - The window-size-hint can optionally be added, e.g:
0284 - (bash) export G4VIS_DEFAULT_DRIVER="RayTracerQt 1000x1000-0+0"
0285 - on the command line, precede the app invocation, e.g:
0286 - ```
0287 G4VIS_DEFAULT_DRIVER=Vtk ./<application-name>
0288 ```
0289 - with ~/.g4session.
0290
0291 For other suggestions for G4VIS_DEFAULT_DRIVER (see list of registered
0292 graphics systems printed at the start):
0293 - DAWNFILE: to create a .prim file suitable for viewing in DAWN.
0294 - VRML2FILE: to create a .wrl file suitable for viewing in a VRML viewer.
0295 - "TSG_OFFSCREEN 1200x1200": to create an image file with TSG.
0296 - See the tsg_offscreen.mac in examples/basic/B5 for more commands
0297 to change the file format, file name, picture size, etc.
0298
0299 See "Choosing a graphics viewer" in the Application Guide for details.
0300
0301 Of course you can change the viewer by editing the /vis/open line in vis.mac.
0302
0303 Also, after the initial viewer opens, you may open a different viewer by typing
0304 on the command line, e.g:
0305 ```
0306 /vis/open DAWNFILE
0307 ```
0308 or
0309 ```
0310 /vis/open RayTraceQt
0311 ```
0312 (if you are using the Qt GUI).
0313
0314 The view parameters of the existing viewer are copied.
0315
0316 The DAWNFILE and similar drivers are always available
0317 (since they require no external libraries), but the OGL driver requires
0318 that the Geant4 libraries have been built with the OpenGL option.
0319
0320 ## USER INTERFACES
0321
0322 The user command interface is set via the G4UIExecutive class
0323 in the main() function in exampleB4a.cc
0324
0325 The selection of the user command interface is then done automatically
0326 according to the Geant4 configuration or it can be done explicitly via
0327 the third argument of the G4UIExecutive constructor (see exampleB4a.cc).
0328
0329 The gui.mac macros are provided in examples B2, B4 and B5. This macro
0330 is automatically executed if Geant4 is built with any GUI session.
0331 It is also possible to customise the icons menu bar which is
0332 demonstrated in the icons.mac macro in example B5.
0333
0334