Warning, /geant4/examples/extended/analysis/AnaEx03/README.md is written in an unsupported language. File is not indexed.
0001 \page ExampleAnaEx03 Example AnaEx03
0002
0003 Example AnaEx03 demonstrates usage of analysis commands for file management
0004 (new since Geant4 11.1), in particular writing histograms and ntuples in a file
0005 multiple times, and commands for histogram deleting (new since Geant4 11.2).
0006
0007 It uses the same scenario (detector description, primary generator
0008 and physics) as [AnaEx01](../../html_AnaEx01/html/ExampleAnaEx01.html) and
0009 [AnaEx02](../../html_AnaEx02/html/ExampleAnaEx02.html).
0010 In difference from these examples
0011 the analysis manipulations (histograms and ntuples booking and filling)
0012 are performed directly with G4AnalysisManager. The classes that are same
0013 in all three examples are located in shared directory.
0014
0015 For detector description, primary generator, physics and the example output
0016 see [AnaEx01](../../html_AnaEx01/html/ExampleAnaEx01.html) example.
0017
0018 ## Histograms, Ntuple:
0019
0020 The example produces the same 4 histograms and 2 ntuples as in AnaEx01.
0021
0022 These histos and ntuples are booked in the RunAction constructor and filled from
0023 EventAction.
0024
0025 The file managent in this example, usually performed via calls to G4AnalysisManager
0026 OpenFile(), Write() and CloseFile() in the code, is in this example performed
0027 via UI commands in a macro:
0028 ```
0029 /analysis/openFile
0030 /analysis/write
0031 /analysis/closeFile
0032 ```
0033
0034 Note that the file does not need to be closed at each end of run and the histograms and ntuples
0035 can be saved in the same file multiple time. In that case we need to reset the histograms
0036 and ntuples data before a new run:
0037 ```
0038 /analysis/reset
0039 ```
0040
0041 We can define the default file type and set it to the analysis manager via
0042 ```
0043 /analysis/setDefaultFileType root # or csv hdf5 xml
0044 ```
0045
0046 The file names then need not to be provided with the file extension and the same macro
0047 can be used with different output types.
0048
0049 To demonstrate UI commands for deleting of selected histograms:
0050 ```
0051 /analysis/h1/delete id [keepSetting]
0052 ```
0053 two H1 histograms, id: 1 and 3, are deleted in AnaEx03.in macro before starting Run 2,
0054 and new histograms are then created before starting Run3. New histograms are created at
0055 id's liberated with previous deleting, 1 and 3.
0056
0057 It should be notes that using UI commands for writing histograms and ntuples in a file
0058 multiple times is not necessary, the same can be achieved by calls to G4AnalysisManager
0059 functions from the code using conditional statements.
0060
0061 ## Macros
0062
0063 - The AnaEx03.in macro performs 5 runs and produces 2 files: e-.root, containg data from first
0064 3 runs, and proton.root, containing data from the next 2 runs.
0065 The macro uses the `defaultFileType` parameter (alias), which default value, "root" is
0066 defined in main().
0067
0068 - AnaEx03-csv.in, AnaEx03-hdf5.in, AnaEx03-root.in, AnaEx03-xml.in: \n
0069 In these macros, the default value of the `defaultFileType` is overritten with
0070 ```
0071 /control/alias defaultFileType cvs # or hdf5 root xml
0072 ```
0073 and then the AnaEx03.in macro is called.
0074
0075 - The plotter.mac macro can be used in the interactive mode to plot histograms. It should be executed after the first `/run/beamOn` call and before the first `/analysis/reset` call.
0076 (See also a commented line with this macro call in AnaEx03.in.)
0077
0078 ## How to run
0079
0080 - It is preferable to execute the exampole in the 'batch' mode from macro files:
0081 ```
0082 % ./AnaEx03 AnaEx03.in
0083 % ./AnaEx03 AnaEx03.in >& output
0084 ```
0085
0086 - When executing AnaEx03 in the 'interactive mode' with visualization, be careful not
0087 to forget to issue the /analysis/openFile command befor starting a run:
0088 ```
0089 % ./AnaEx03
0090 and type in the commands from AnaEx03[-xyz].mac line by line:
0091 Idle> /analysis/openFile myFile
0092 Idle> /tracking/verbose 1
0093 Idle> /run/beamOn 10
0094 Idle> ...
0095 Idle> /analysis/write
0096 Idle> /analysis/closeFile
0097 ....
0098 Idle> exit
0099 ```
0100
0101 All AnaEx03-*.in macros are used in Geant4 testing.