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