Warning, /geant4/examples/basic/B4/README is written in an unsupported language. File is not indexed.
0001 -------------------------------------------------------------------
0002
0003 =========================================================
0004 Geant4 - an Object-Oriented Toolkit for Simulation in HEP
0005 =========================================================
0006
0007 Example B4
0008 -----------
0009
0010 This example simulates a simple Sampling Calorimeter setup.
0011 To demonstrate several possible ways of data scoring, the example
0012 is provided in four variants: B4a, B4b, B4c, B4d.
0013 (See also examples/extended/electromagnetic/TestEm3 or hadronic/Hadr05)
0014
0015 1- GEOMETRY DEFINITION
0016
0017 The geometry is constructed in B4[c,d]::DetectorConstruction class.
0018 The calorimeter is a box made of a given number of layers. A layer
0019 consists of an absorber plate and of a detection gap. The layer is
0020 replicated.
0021
0022 Four parameters define the geometry of the calorimeter :
0023 - the thickness of an absorber plate,
0024 - the thickness of a gap,
0025 - the number of layers, and
0026 - the transverse size of the calorimeter (the entrance face is a square).
0027
0028 In addition, a global, uniform, and transverse magnetic field can be
0029 applied using G4GlobalMagFieldMessenger, instantiated in
0030 B4[c,d]::DetectorConstruction::ConstructSDandField
0031 with a non zero field value, or via interactive commands.
0032 For example:
0033
0034 /globalField/setValue 0.2 0 0 tesla
0035
0036
0037 |<----layer 0---------->|<----layer 1---------->|<----layer 2---------->|
0038 | | | |
0039 ==========================================================================
0040 || | || | || | ||
0041 || | || | || | ||
0042 beam || absorber | gap || absorber | gap || absorber | gap ||
0043 ======> || | || | || | ||
0044 || | || | || | ||
0045 ==========================================================================
0046
0047 A more general version of this geometry can be found in:
0048 examples/extended/electromagnetic/TestEm3 or hadronic/Hadr05
0049 where all the geometry parameters, the absorber and gap materials
0050 can be modified interactively via the commands defined in the DetectorMessenger
0051 class.
0052
0053 2- PHYSICS LIST
0054
0055 The particle's type and the physic processes which will be available
0056 in this example are set in the FTFP_BERT physics list. This physics list
0057 requires data files for electromagnetic and hadronic processes.
0058 See more on installation of the datasets in Geant4 Installation Guide,
0059 Chapter 3.3: Note On Geant4 Datasets:
0060 http://geant4.web.cern.ch/geant4/UserDocumentation/UsersGuides/InstallationGuide/html/ch03s03.html
0061 The following datasets: G4LEDATA, G4LEVELGAMMADATA, G4SAIDXSDATA and
0062 G4ENSDFSTATEDATA are mandatory for this example.
0063
0064 In addition the build-in interactive command:
0065 /process/(in)activate processName
0066 allows to activate/inactivate the processes one by one.
0067
0068 3- ACTION INITALIZATION
0069
0070 A newly introduced class, B4[a,b,c,d]::ActionInitialization,
0071 instantiates and registers to Geant4 kernel all user action classes.
0072
0073 While in sequential mode the action classes are instatiated just once,
0074 via invoking the method:
0075 B4[a,b,c,d]::ActionInitialization::Build()
0076 in multi-threading mode the same method is invoked for each thread worker
0077 and so all user action classes are defined thread-local.
0078
0079 A run action class is instantiated both thread-local
0080 and global that's why its instance is created also in the method
0081 B4[a,b,c,d]::ActionInitialization::BuildForMaster()
0082 which is invoked only in multi-threading mode.
0083
0084 4- PRIMARY GENERATOR
0085
0086 The primary beam consists of a single particle which hits the
0087 calorimeter perpendicular to the input face. The type of the particle
0088 and its energy are set in the B4::PrimaryGeneratorAction class, and can
0089 be changed via the G4 built-in commands of the G4ParticleGun class (see
0090 the macros provided with this example).
0091
0092 5- RUNS and EVENTS
0093
0094 A run is a set of events.
0095 The user can choose the frequency of printing via the Geant4 interactive
0096 command, for example:
0097
0098 /run/printProgress 100
0099
0100 6- DETECTOR RESPONSE
0101
0102 The energy deposit and track lengths of the charged particles are recorded on
0103 an event by event basis in the Absober and Gap layers.
0104
0105 In order to demonstrate several possible ways of data scoring,
0106 the example is provided in four variants:
0107
0108 Variant a: User Actions
0109
0110 These 4 quantities are data members of the B4a::EventAction class.
0111 They are collected step by step in
0112 B4a::SteppingAction::UserSteppingAction(), and passed to the event action
0113 via two methods: B4a::EventAction::AddAbs() and B4a::EventAction::AddGap().
0114
0115 In B4a::EventAction::EndOfEventAction(), these quantities are printed and
0116 filled in H1D histograms and ntuple to accumulate statistic and compute
0117 dispersion.
0118
0119 Variant b: User data object
0120
0121 In order to avoid dependencies between action classes, a user object
0122 B4b::RunData, derived from G4Run, is defined with data members needed
0123 for the accounted information.
0124 In order to reduce the number of data members a 2-dimensions array
0125 is introduced for each quantity.
0126 Then the quantities are collected step by step in user action classes:
0127 B4b::SteppingAction::UserSteppingAction() and
0128 B4b::EventAction::EndOfEventAction() in a similar way as in variant a.
0129
0130 Variant c: Hits and Sensitive detectors
0131
0132 In this option, the physics quantities are accounted using the hits
0133 and sensitive detectors framework defined in the Geant4 kernel.
0134 The physics quantities are stored in B4c::CalorHit via two B4c::CalorimeterSD
0135 objects, one associated with the Absorber volume and another one with Gap
0136 in B4c::DetectorConstruction::ConstructSDandField().
0137
0138 In contrary to the B2 example (Tracker) where a new hit is created
0139 with each track passing the sensitive volume (in the calorimeter), only one
0140 hit is created for each calorimeter layer and one more hit to account for
0141 the total quantities in all layers. In addition to the variants a and b,
0142 the quantities per each layer are also available in addition to the total
0143 quantities.
0144
0145 Variant d: Scorer
0146
0147 In this option, the Geant4 scorers which are defined on the top of hits
0148 and sensitive detectors Geant4 framework are used.
0149 In practice this means that the user does not need to define hits and sensitive
0150 detector classes but rather uses the classes already defined
0151 in Geant4. In this example, the G4MultiFunctionalDetector with
0152 G4PSEnergyDeposit and G4PSTrackLength primitive scores are used (see
0153 B4d::DetectorConstruction::ConstructSDandField()).
0154
0155 The scorers hits are saved in form of ntuples in a Root file using Geant4
0156 analysis tools. This feature is activated in the main () function with instantiating
0157 G4TScoreNtupleWriter.
0158
0159 Also with this approach, the quantities per each layer are available
0160 in addition to the total quantities.
0161
0162 7- HISTOGRAMS
0163
0164 The analysis tools are used to accumulate statistics and compute the dispersion
0165 of the energy deposit and track lengths of the charged particles.
0166 H1D histograms are created in B4[b]::RunAction::RunAction() for the
0167 following quantities:
0168 - Energy deposit in absorber
0169 - Energy deposit in gap
0170 - Track length in absorber
0171 - Track length in gap
0172
0173 The same values are also saved in an ntuple.
0174
0175 The histograms and the ntuple are saved in the output file in a format
0176 according to a specified file extension, the default in this example
0177 is ROOT.
0178
0179 The accumulated statistic and computed dispersion is printed at the end of
0180 run, in B4::RunAction::EndOfRunAction().
0181 When running in multi-threading mode, the histograms and the ntuple accumulated
0182 on threads are merged in a single output file. While merging of histograms is
0183 performed by default, merging of ntuples is explicitly activated in the B4::RunAction
0184 constructor.
0185
0186 The ROOT histograms and ntuple can be plotted with ROOT using the plotHisto.C
0187 and plotNtuple.C macros.
0188
0189 8- HOW TO RUN
0190
0191 This example handles the program arguments in a new way.
0192 It can be run with the following optional arguments:
0193 % exampleB4a [-m macro ] [-u UIsession] [-t nThreads] [-vDefault]
0194
0195 The -vDefault option will activate using the default Geant4 stepping verbose
0196 class (G4SteppingVerbose) instead of the enhanced stepping verbose with best
0197 units (G4SteppingVerboseWithUnits) used in the example by default.
0198
0199 The -t option is available only in multi-threading mode
0200 and it allows the user to override the Geant4 default number of
0201 threads. The number of threads can be also set via G4FORCENUMBEROFTHREADS
0202 environment variable which has the top priority.
0203
0204 - Execute exampleB4a in the 'interactive mode' with visualization
0205 % exampleB4a
0206 and type in the commands from run1.mac line by line:
0207 Idle> /tracking/verbose 1
0208 Idle> /run/beamOn 1
0209 Idle> ...
0210 Idle> exit
0211 or
0212 Idle> /control/execute run1.mac
0213 ....
0214 Idle> exit
0215
0216 - Execute exampleB4a in the 'batch' mode from macro files
0217 (without visualization)
0218 % exampleB4a -m run2.mac
0219 % exampleB4a -m exampleB4.in > exampleB4.out
0220
0221 - Execute exampleB4a in the 'interactive mode' with a selected UI session,
0222 e.g. tcsh
0223 % exampleB4a -u tcsh
0224
0225 The following paragraphs are common to all basic examples
0226
0227 A- VISUALIZATION
0228
0229 The visualization manager is set via the G4VisExecutive class
0230 in the main() function in exampleB4a.cc.
0231 The initialisation of the drawing is done via a set of /vis/ commands
0232 in the macro vis.mac. This macro is automatically read from
0233 the main function when the example is used in interactive running mode.
0234
0235 By default, vis.mac opens an OpenGL viewer (/vis/open OGL).
0236 The user can change the initial viewer by commenting out this line
0237 and instead uncommenting one of the other /vis/open statements, such as
0238 HepRepFile or DAWNFILE (which produce files that can be viewed with the
0239 HepRApp and DAWN viewers, respectively). Note that one can always
0240 open new viewers at any time from the command line. For example, if
0241 you already have a view in, say, an OpenGL window with a name
0242 "viewer-0", then
0243 /vis/open DAWNFILE
0244 then to get the same view
0245 /vis/viewer/copyView viewer-0
0246 or to get the same view *plus* scene-modifications
0247 /vis/viewer/set/all viewer-0
0248 then to see the result
0249 /vis/viewer/flush
0250
0251 The DAWNFILE, HepRepFile drivers are always available
0252 (since they require no external libraries), but the OGL driver requires
0253 that the Geant4 libraries have been built with the OpenGL option.
0254
0255 For more information on visualization, including information on how to
0256 install and run DAWN, OpenGL and HepRApp, see the visualization tutorials,
0257 for example,
0258 http://geant4.slac.stanford.edu/Presentations/vis/G4[VIS]Tutorial/G4[VIS]Tutorial.html
0259 (where [VIS] can be replaced by DAWN, OpenGL and HepRApp)
0260
0261 The tracks are automatically drawn at the end of each event, accumulated
0262 for all events and erased at the beginning of the next run.
0263
0264 B- USER INTERFACES
0265
0266 The user command interface is set via the G4UIExecutive class
0267 in the main() function in exampleB4a.cc
0268 The selection of the user command interface is then done automatically
0269 according to the Geant4 configuration or it can be done explicitly via
0270 the third argument of the G4UIExecutive constructor (see exampleB4a.cc).