Warning, /geant4/examples/basic/B5/README.md is written in an unsupported language. File is not indexed.
0001 \page ExampleB5 Example B5
0002
0003 Example B5 implements a double-arm spectrometer with wire chambers,
0004 hodoscopes and calorimeters. Event simulation and collection are
0005 enabled, as well as event display and analysis.
0006
0007
0008 ## GEOMETRY
0009
0010 The spectrometer consists of two detector arms
0011 (see B5::DetectorConstruction). One arm provides
0012 position and timing information of the incident particle while the
0013 other collects position, timing and energy information of the particle
0014 after it has been deflected by a magnetic field centered at the
0015 spectrometer pivot point.
0016
0017 - First arm: box filled with air, also containing:
0018 - 1 hodoscope (15 vertical strips of plastic scintillator)
0019 - 1 drift chamber (5 horizontal argon gas layers with a
0020 "virtual wire" at the center of each layer)
0021
0022 - Second arm: box filled with air, also containing:
0023 - 1 hodoscope (25 vertical strips of plastic scintillator)
0024 - 1 drift chamber (5 horizontal argon gas layers with a
0025 "virtual wire" at the center of each layer)
0026 - 1 electromagnetic calorimeter:
0027 a box sub-divided along x,y and z
0028 axes into cells of CsI
0029 - 1 hadronic calorimeter:
0030 a box sub-divided along x,y, and z axes
0031 into cells of lead, with a layer of
0032 plastic scintillator placed at the center
0033 of each cell
0034
0035 - Magnetic field region: air-filled cylinder which contains
0036 the field (see B5::MagneticField)
0037
0038 The maximum step limit in the magnetic field region is also set
0039 via the G4UserLimits class in a similar way as in Example B2
0040 (see \ref B2_s6 in B2 example documentation).
0041
0042 The rotation angle of the second arm and the magnetic field value
0043 can be set via the interactive commands defined using the G4GenericMessenger
0044 class.
0045
0046 ## PHYSICS
0047
0048 This example uses the reference hadronic physics list, FTFP_BERT,
0049 and also adds the G4StepLimiter process.
0050
0051 ## ACTION INITALIZATION
0052
0053 B5::ActionInitialization class
0054 instantiates and registers to Geant4 kernel all user action classes.
0055
0056 While in sequential mode the action classes are instatiated just once,
0057 via invoking the method:
0058 B5::ActionInitialization::Build()
0059 in multi-threading mode the same method is invoked for each thread worker
0060 and so all user action classes are defined thread-local.
0061
0062 A run action class is instantiated both thread-local
0063 and global that's why its instance is created also in the method
0064 B5::ActionInitialization::BuildForMaster()
0065 which is invoked only in multi-threading mode.
0066
0067 ## PRIMARY GENERATOR
0068
0069 The primary generator action class employs the G4ParticleGun.
0070 The primary kinematics consists of a single particle which is
0071 is sent in the direction of the first spectrometer arm.
0072
0073 The type of the particle and its several properties can be changed
0074 via the G4 built-in commands of the G4ParticleGun class or
0075 this example command defined using the G4GenericMessenger class.
0076
0077
0078 ## EVENT
0079
0080 An event consists of the generation of a single particle which is
0081 transported through the first spectrometer arm. Here, a scintillator
0082 hodoscope records the reference time of the particle before it passes
0083 through a drift chamber where the particle position is measured.
0084 Momentum analysis is performed as the particle passes through a magnetic
0085 field at the spectrometer pivot and then into the second spectrometer
0086 arm. In the second arm, the particle passes through another hodoscope
0087 and drift chamber before interacting in the electromagnetic calorimeter.
0088 Here it is likely that particles will induce electromagnetic showers.
0089 The shower energy is recorded in a three-dimensional array of CsI
0090 crystals. Secondary particles from the shower, as well as primary
0091 particles which do not interact in the CsI crystals, pass into the
0092 hadronic calorimeter. Here, the remaining energy is collected in a
0093 three-dimensional array of scintillator-lead sandwiches.
0094
0095 Several aspects of the event may be changed interactively by the user:
0096 - angle of the second spectrometer arm
0097 - strength of magnetic field
0098 - initial particle type
0099 - initial momentum and angle
0100 - momentum and angle spreads
0101 - type of initial particle may be randomized
0102
0103 The initial particle type can be changed using the G4ParticleGun command:
0104 ```
0105 /gun/particle particleName
0106 ```
0107
0108 The UI commands specific to this example are available in /B5 command
0109 directory:
0110 ```
0111 /B5/detector/armAngle angle unit
0112 /B5/field/value field unit
0113 /B5/generator/momentum value unit
0114 /B5/generator/sigmaMomentum value unit
0115 /B5/generator/sigmaAngle value unit
0116 /B5/generator/randomizePrimary [true|false]
0117 ```
0118
0119 They are implemented in
0120 - B5::DetectorConstruction::DefineCommands(),
0121 - B5::MagneticField::DefineCommands() and
0122 - B5::PrimaryGeneratorAction::DefineCommands() methods
0123 using G4GenericMessenger class.
0124
0125 In first execution of B5::EventAction::BeginOfEventAction()
0126 the hits collections identifiers are saved in data members of the class
0127 and used in B5::EventAction::EndOfEventAction() for accessing
0128 the hists collections and filling the accounted information in defined
0129 histograms and ntuples and printing its summary in a log file.
0130 The frequency of printing can be tuned with the built-in command
0131 ```
0132 /run/printProgress frequency
0133 ```
0134
0135 ## DETECTOR RESPONSE
0136
0137 All the information required to simulate and analyze an event is
0138 recorded in hits. This information is recorded in the following
0139 sensitive detectors:
0140
0141 - hodoscope:
0142 - particle time
0143 - strip ID, position and rotation
0144 - see B5::HodoscopeSD, B5::HodoscopeHit
0145
0146 - drift chamber:
0147 - particle time
0148 - particle position
0149 - layer ID
0150 - see B5::DriftChamberSD, B5::DriftChamberHit classes
0151
0152 - electromagnetic calorimeter:
0153 - energy deposited in cell
0154 - cell ID, position and rotation
0155 - see B5::EmCalorimeterSD, B5::EmCalorimeterHit classes
0156
0157 - hadronic calorimeter:
0158 - energy deposited in cell
0159 - cell column ID and row ID, position and rotation
0160 - see B5::HadCalorimeterSD, B5::HadCalorimeterHit classes
0161
0162 The hit classes include methods GetAttDefs and CreateAttValues to define
0163 and then fill extra "HepRep-style" Attributes that the visualization system
0164 can use to present extra information about the hits.
0165 For example, if you pick a B5::HadCalorimeterHit in a viewer instrumented for picking,
0166 you will be shown the hit's "Hit Type", "Column ID", "Row ID",
0167 "Energy Deposited" and "Position".
0168 These attributes are essentially arbitrary extra pieces of information
0169 (integers, doubles or strings) that are carried through the visualization.
0170 Each attribute is defined once in G4AttDef object and then is filled for
0171 each hit in a G4AttValue object.
0172 These attributes can also be used by commands to filter which hits are drawn:
0173 /vis/filtering/hits/drawByAttribute
0174 Detector Geometry and trajectories also carry HepRep-style attributes,
0175 but these are filled automatically in the base classes.
0176 HepRep is further described at the
0177 <a href="https://web.archive.org/web/20240702104514/https://www.slac.stanford.edu/~perl/heprep/"> HepRep Home Page </a>.
0178
0179 ## ANALYSIS
0180
0181 The analysis tools are used to accumulate statistics.
0182 Histograms and an ntuple are created in B5::RunAction::RunAction()
0183 constructor for the following quantities:
0184
0185 - 1D histograms:
0186 - Number of hits in Chamber 1
0187 - Number of hits in Chamber 2
0188
0189 - 2D histograms:
0190 - Drift Chamber 1 X vs Y positions
0191 - Drift Chamber 2 X vs Y positions
0192
0193 - Ntuple:
0194 - Number of hits in Chamber 1
0195 - Number of hits in Chamber 2
0196 - Total energy deposit in EM calorimeter
0197 - Total energy deposit in Hadronic calorimeter
0198 - Time of flight in Hodoscope 1
0199 - Time of flight in Hodoscope 2
0200 - Vector of energy deposits in EM calorimeter cells
0201 - Vector of energy deposits in Hadronic calorimeter cells
0202
0203 The histograms and ntuple are saved in two output files in a default
0204 (Root) file format.
0205
0206 Another file format (for example xml) can be selected either by
0207 changing the generic analysis manager default file type:
0208 ```
0209 analysisManager->SetDefaultFileType("xml");
0210 ```
0211 or by providing the file names with the extension:
0212 ```
0213 analysisManager->SetFileName("B5.xml");
0214 analysisManager->SetNtupleFileName(0, "B5ntuple.xml");
0215 ```
0216
0217 When running in multi-threading mode, the histograms and ntuple accumulated
0218 on threads are automatically merged in a single output file.
0219
0220 ## PLOTTING:
0221
0222 This example comes with a commented plotter.mac that shows how to use the
0223 plotting coming with some of the visualization drivers (for example the
0224 ToolsSG ones) to see the histograms. In it you will see how to activate
0225 the vis driver (create a "scene handler"), create a viewer, create a scene
0226 containing a plotter model object, create plotting "regions" (here 2x2
0227 regions) and attach the histograms to each region. When done, each
0228 run beamOn should display at end the content of the histograms.
0229
0230 In the second part of plotter.mac, is shown various ways to customize the
0231 regions, for example changing the bins color, the axis labels fonts, etc...
0232 This could be done by using default embedded styles, defining styles with commands,
0233 or setting up directly parameters of the various parts of a plot by using a
0234 dedicated command.
0235
0236 By default the fonts used are the Hershey vectorial ones that do not need
0237 an extra package, but you can use some freetype fonts if building with the
0238 cmake flag -DGEANT4_USE_FREETYPE=ON. Two embedded ttf fonts comes with the
0239 ToolsSG plotting: roboto_bold (some open source kind of the Microsoft arialbd)
0240 and lato_regular (close to an helvetica). You can use your own .ttf files by
0241 using the TOOLS_FONT_PATH environment variable to specify the directory where
0242 they could be found.
0243
0244 <hr>
0245
0246 The following paragraphs are common to all basic examples
0247
0248 ## VISUALISATION
0249
0250 The visualization manager is set via the G4VisExecutive class
0251 in the main () function in exampleB5.cc.
0252 The initialisation of the drawing is done via a set of /vis/ commands
0253 in the macro vis.mac. This macro is automatically read from
0254 the main function when the example is used in interactive running mode.
0255
0256 By default, vis.mac opens the default viewer (/vis/open).
0257 This chooses a graphics system (in order of priority):
0258 - by argument in G4VisExecutive construction.
0259 - by environment variable, G4VIS_DEFAULT_DRIVER.
0260 - by information in ~/.g4session.
0261 - by mode (batch/interactive) and if interactive, by your build flags.
0262
0263 The user can change the initial viewer
0264 - with environment variable G4VIS_DEFAULT_DRIVER. The format is
0265 ```
0266 <graphics-system> [<window-size-hint>]
0267 ```
0268 Set this, e.g:
0269 - (bash) export G4VIS_DEFAULT_DRIVER=TSG
0270 - (tcsh) setenv G4VIS_DEFAULT_DRIVER OI
0271 - The window-size-hint can optionally be added, e.g:
0272 - (bash) export G4VIS_DEFAULT_DRIVER="RayTracerQt 1000x1000-0+0"
0273 - on the command line, precede the app invocation, e.g:
0274 - ```
0275 G4VIS_DEFAULT_DRIVER=Vtk ./<application-name>
0276 ```
0277 - with ~/.g4session.
0278
0279 For other suggestions for G4VIS_DEFAULT_DRIVER (see list of registered
0280 graphics systems printed at the start):
0281 - DAWNFILE: to create a .prim file suitable for viewing in DAWN.
0282 - VRML2FILE: to create a .wrl file suitable for viewing in a VRML viewer.
0283 - "TSG_OFFSCREEN 1200x1200": to create an image file with TSG.
0284 - See the tsg_offscreen.mac in examples/basic/B5 for more commands
0285 to change the file format, file name, picture size, etc.
0286
0287 See "Choosing a graphics viewer" in the Application Guide for details.
0288
0289 Of course you can change the viewer by editing the /vis/open line in vis.mac.
0290
0291 Also, after the initial viewer opens, you may open a different viewer by typing
0292 on the command line, e.g:
0293 ```
0294 /vis/open DAWNFILE
0295 ```
0296 or
0297 ```
0298 /vis/open RayTraceQt
0299 ```
0300 (if you are using the Qt GUI).
0301
0302 The view parameters of the existing viewer are copied.
0303
0304 The DAWNFILE and similar drivers are always available
0305 (since they require no external libraries), but the OGL driver requires
0306 that the Geant4 libraries have been built with the OpenGL option.
0307
0308 Since 11.1, the TSG visualization driver can also produce the "offscrean"
0309 file output in png, jpeg, gl2ps formats without drawing on the screen.
0310 It can be controlled via UI commands provided in '/vis/tsg' which are
0311 demonstrated in the tsg_offscreen.mac macro in example B5.
0312
0313 For more information on visualization, including information on how to
0314 install and run DAWN, OpenGL and TSG see the visualization tutorials,
0315 for example,\n
0316 - <a href="http://geant4.slac.stanford.edu/Presentations/vis/G4OpenGLTutorial/G4OpenGLTutorial.html">
0317 OpenGL Tutorial </a>
0318 - <a href="http://geant4.slac.stanford.edu/Presentations/vis/G4DAWNTutorial/G4DAWNTutorial.html">
0319 DAWN Tutorial </a>
0320
0321 The tracks are automatically drawn at the end of each event, accumulated
0322 for all events and erased at the beginning of the next run.
0323
0324 ## USER INTERFACES
0325
0326 The user command interface is set via the G4UIExecutive class
0327 in the main () function in exampleB5.cc
0328
0329 The selection of the user command interface is then done automatically
0330 according to the Geant4 configuration or it can be done explicitly via
0331 the third argument of the G4UIExecutive constructor (see exampleB4a.cc).
0332
0333 The gui.mac macros are provided in examples B2, B4 and B5. This macro
0334 is automatically executed if Geant4 is built with any GUI session.
0335 It is also possible to customise the icons menu bar which is
0336 demonstrated in the icons.mac macro in example B5.
0337
0338 ## HOW TO RUN
0339
0340 - Execute exampleB5 in the 'interactive mode' with visualization
0341 ```
0342 % exampleB5
0343 and type in the commands from run1.mac line by line:
0344 Idle> /control/verbose 2
0345 Idle> /tracking/verbose 1
0346 Idle> /run/beamOn 10
0347 Idle> ...
0348 Idle> exit
0349 ```
0350 or
0351 ```
0352 Idle> /control/execute run1.mac
0353 ....
0354 Idle> exit
0355 ```
0356
0357 - Execute exampleB5 in the 'batch' mode from macro files
0358 (without visualization)
0359 ```
0360 % exampleB5 run2.mac
0361 % exampleB5 exampleB5.in > exampleB5.out
0362 ```