1 | # $Id: README,v 1.21 2005/03/17 19:48:27 daquinog Exp $ |
---|
2 | # ------------------------------------------------------------------- |
---|
3 | # GEANT4 tag $Name: $ |
---|
4 | # ------------------------------------------------------------------- |
---|
5 | |
---|
6 | Simulation of the TIARA experiment using importance sampling |
---|
7 | ============================================================ |
---|
8 | |
---|
9 | This example is a simulation of the neutron shielding experiment TIARA |
---|
10 | see http://idsun1.kek.jp/nakao/research/tiara/tiara.htm. |
---|
11 | The example is meant to provide a realistic example for |
---|
12 | applying geometrical importance sampling (geometrical splitting and |
---|
13 | Russian roulette). |
---|
14 | In the TIARA experiment neutrons of two different energy distributions |
---|
15 | created by 43 MeV and 68 MeV protons bombarding a 7Li target are measured |
---|
16 | behind several shields. The simulation starts from the neutron spectra. |
---|
17 | In this example the interactions of the neutrons with the (concrete) |
---|
18 | shields are simulated and energy dependent neutron fluxes are measured |
---|
19 | behind the shields. Users may choose to run the simulation for different |
---|
20 | shielding configuration with or without importance sampling. |
---|
21 | The simulated neutron fluxes are compared to the published |
---|
22 | experimental data. The efficiency of applying importance sampling |
---|
23 | depends strongly on the shield thickness and importance configuration. |
---|
24 | The efficiency of the simulations may be obtained as FOM values. |
---|
25 | |
---|
26 | See also "Geant4 User's Guide |
---|
27 | For Application Developers", Chapter "Toolkit Fundamentals" |
---|
28 | Section "Event Biasing Techniques" and references there. |
---|
29 | |
---|
30 | The example has been tested on CERN RH 7.3 with the |
---|
31 | gcc-3.2.3 and gcc-2.95.2 compilers. |
---|
32 | |
---|
33 | Note for system testing without analysis: see points 1.1, 1.3 and 3.2. |
---|
34 | |
---|
35 | |
---|
36 | |
---|
37 | 1) Setting the environment |
---|
38 | ========================== |
---|
39 | |
---|
40 | You must compile Geant4 with: |
---|
41 | "G4LIB_BUILD_SHARED" set to 1. |
---|
42 | You need to set: |
---|
43 | "NeutronHPCrossSections" (e.g. pointing to a directory containing G4NDL3.7) |
---|
44 | |
---|
45 | |
---|
46 | Three examples are given of how to set environment variables |
---|
47 | in the three cases: |
---|
48 | |
---|
49 | 1.1) PI via AFS (most simple): |
---|
50 | -------------------- |
---|
51 | You have access to afs and you want to use PI for the |
---|
52 | analysis: |
---|
53 | Set the following environment variables: |
---|
54 | "G4ANALYSIS_USE" |
---|
55 | "PI_BASE_DIR" (where PI has been installed) |
---|
56 | "SWIG_BASE_DIR" (where SWIG has been installed) |
---|
57 | |
---|
58 | Finally source the script envCommon.csh from the directory where you have Tiara |
---|
59 | installed, e.g. ${G4INSTALL}/examples/advanced/Tiara |
---|
60 | |
---|
61 | |
---|
62 | 1.2) No afs but a local PI and SWIG installation: |
---|
63 | ----------------------------------------------------- |
---|
64 | You don't use afs but you have a local installation of SWIG and PI |
---|
65 | Set the following environment variables: |
---|
66 | "G4ANALYSIS_USE" |
---|
67 | "PI_BASE_DIR" |
---|
68 | "SWIG_BASE_DIR" |
---|
69 | |
---|
70 | Finally source the script envCommon.csh from the directory where |
---|
71 | you have Tiara installed, e.g. ${G4INSTALL}/examples/advanced/Tiara |
---|
72 | |
---|
73 | |
---|
74 | 1.3) No afs, no PI and no SWIG (e.g. for system testing): |
---|
75 | ------------------------------------------------------------- |
---|
76 | You don't want to use PI and SWIG and you don't have afs access. |
---|
77 | Make sure "G4ANALYSIS_USE" is unset (e.g. unsetenv G4ANALYSIS_USE or setenv G4ANALYSIS_USE 0) |
---|
78 | |
---|
79 | Note 1: python must be built against a "libc". |
---|
80 | You may do this by creating a shared library by a command |
---|
81 | similar to this |
---|
82 | "ld -shared -o libpython2.3.so --whole-archive libpython2.3.a /usr/lib/libc.so" |
---|
83 | |
---|
84 | Set the following environment variables: |
---|
85 | "PYTHONVERSION" (2.3 or higher) |
---|
86 | "PYTHON_BASE_DIR" (e.g. to /usr) |
---|
87 | "SWIG_VERSION" (e.g. 1.3 or higher) |
---|
88 | "SWIG_BASE_DIR" (e.g. /usr) |
---|
89 | "CLHEP_BASE_DIR" (e.g. to /opt/local) |
---|
90 | |
---|
91 | Finally source the script envCommon.csh from the directory where |
---|
92 | you have Tiara installed, e.g. ${G4INSTALL}/examples/advanced/Tiara |
---|
93 | |
---|
94 | NOTE 2: Passing from a simulation WITH to another WITHOUT analysis implies |
---|
95 | that the G4ANALYSIS_use should be unset and that the SWIG-wrapper scripts |
---|
96 | in the directory TiaraWrapper should be deleted. Normally, the whole code |
---|
97 | should be compiled again using gmake clean_all and, afterwards, gmake. |
---|
98 | The same procedure should be followed also passing from a simulation WITHOUT |
---|
99 | to another WITH analysis. |
---|
100 | |
---|
101 | 2) Building the example |
---|
102 | ======================= |
---|
103 | |
---|
104 | Geant4 has to be compiled using G4LIB_BUILD_SHARED 1 and the one of the |
---|
105 | above environment settings have to be set. |
---|
106 | Type "gmake". |
---|
107 | |
---|
108 | |
---|
109 | 2.1) In more detail |
---|
110 | ------------------- |
---|
111 | |
---|
112 | Geant4 must be compiled into granular shared libraries. |
---|
113 | Therefore before compiling Geant4 set "G4LIB_BUILD_SHARED" to "1". |
---|
114 | |
---|
115 | External packages used in this example are PI, SWIG and Python. |
---|
116 | |
---|
117 | |
---|
118 | 2.2) Cleaning up |
---|
119 | ---------------- |
---|
120 | To remove the files created by swig ( *_wrap.cc, the corresponding |
---|
121 | .py files) use "gmake swigClean". |
---|
122 | To remove the directories of compiled code related to this example under |
---|
123 | $G4WORKDIR/tmp/$G4SYSTEM/ use "gmake tiaraClean". |
---|
124 | To remove all the files created during the previous compilation, use |
---|
125 | "gmake clean_all". |
---|
126 | |
---|
127 | |
---|
128 | 3) Running the example: |
---|
129 | ======================= |
---|
130 | |
---|
131 | |
---|
132 | 3.1) Using PI |
---|
133 | ----------------- |
---|
134 | Change to the sub directory "run" and execute "runSim.py". |
---|
135 | "runSim.py" runs an example configuration which may be |
---|
136 | changed by the user. The results of the simulation are stored in |
---|
137 | the directory "simData". |
---|
138 | The script "runSim.py" periodically prints scoring information to the |
---|
139 | screen. |
---|
140 | It also prints out the relative path of a ".shelve" file. |
---|
141 | This file can be used to access results of the simulation. |
---|
142 | |
---|
143 | In case the example was build using analysis |
---|
144 | results may be viewed e.g. using python or ROOT: |
---|
145 | 1) Start python |
---|
146 | 2) type: import dataAcess |
---|
147 | 3) type: p = dataAcess.ExpMcPlot (shelveFileName,detectorposition) |
---|
148 | where "shelveFileName" is the name (enclosed in quotes) of the |
---|
149 | shelve file created during the execution of runSim.py. |
---|
150 | The name is printed on the screen during execution of runSim.py. |
---|
151 | "detectorposition" may be "00, "20" or "40" and stand for the |
---|
152 | detectors 00, 20, 40 cm off beam axis respectively. |
---|
153 | 4) type: p.display () |
---|
154 | 5) type: import extractShelve |
---|
155 | 6) type: extractShelve.getFluxes (p.she) |
---|
156 | p.she is the shelve object containing simulation results. |
---|
157 | This prints the FOM values for the used detectors |
---|
158 | for two energy regions below and in the peak region. |
---|
159 | The FOM should be compared to unbiased simulations. To run |
---|
160 | an unbiased simulation set the importance values to one (see |
---|
161 | runSim.py) |
---|
162 | |
---|
163 | Note: the output files written after every run are incremental! Meaning |
---|
164 | the file with the highest run number contains the data from |
---|
165 | all the runs! |
---|
166 | |
---|
167 | The modules (dataAcess, extractShelve) imported in the above steps are |
---|
168 | placed in source/py_modules in files named after the module ending with |
---|
169 | ".py". |
---|
170 | |
---|
171 | Since the simulation time used by "runSim.py" is only 5 minutes the |
---|
172 | calculated results have large errors. If you want to see a better result |
---|
173 | do the following changes in "runSim.py". |
---|
174 | Extend the total run time to e,g, 2 hours by setting: |
---|
175 | "totalTime = 2 * myUtils.hour", |
---|
176 | set the print out period to 30 minutes by setting: |
---|
177 | "timeForOneRun = 30 * myUtils.min". |
---|
178 | |
---|
179 | |
---|
180 | |
---|
181 | |
---|
182 | 3.2) Not using PI (mainly for system testing) |
---|
183 | ------------------------------------------------- |
---|
184 | Change to the sub directory "run" and execute |
---|
185 | runSimNoAnalysis.py. |
---|
186 | |
---|
187 | |
---|
188 | |
---|
189 | |
---|
190 | |
---|
191 | 4) Content of the directory: |
---|
192 | ============================ |
---|
193 | |
---|
194 | |
---|
195 | envCommon.csh - a script to setup environment variables |
---|
196 | in case the above one of the above environment settings have been |
---|
197 | done beforehand. |
---|
198 | |
---|
199 | GNUmakefile - for building the example |
---|
200 | |
---|
201 | |
---|
202 | data / - directory containing experimental data |
---|
203 | |
---|
204 | expDataOrig - experimental data taken from |
---|
205 | http://idsun1.kek.jp/nakao/research/tiara/tiara.htm |
---|
206 | |
---|
207 | expDataConverted - some of the experimental data and the source |
---|
208 | spectra converted into Anaphes DataPointSet |
---|
209 | and stored in Anaphes xml format |
---|
210 | |
---|
211 | |
---|
212 | source / - directory containing the source code |
---|
213 | |
---|
214 | tiara - C++ source code |
---|
215 | |
---|
216 | CLHEPWrapper - wrapper classes for usage in python |
---|
217 | \include\CLHEP.i - specification file for swig |
---|
218 | \src\CLHEP_wrap.cc - wrapper created with swig |
---|
219 | |
---|
220 | G4KernelWrapper - wrapper classes for usage in python |
---|
221 | |
---|
222 | TiaraWrapper - wrapper classes for usage in python |
---|
223 | |
---|
224 | py_modules - python modules for running and analysing |
---|
225 | |
---|
226 | swig.gmk - makefile rules for using swig |
---|
227 | |
---|
228 | run / - directory for running the example |
---|
229 | runSim.py - executable example script |
---|
230 | runSimNoAnalysis.py - executable script for running without |
---|
231 | analysis |
---|
232 | |
---|
233 | |
---|
234 | |
---|
235 | 5) Technicalities about this example |
---|
236 | =================================== |
---|
237 | |
---|
238 | This example is composed out of a layer of classes written in C++ |
---|
239 | (source/tiara/include, source/tiara/src), a layer of python |
---|
240 | shadow classes created by swig (source/CLHEPWrapper, |
---|
241 | source/G4KernelWrapper, source/TiaraWrapper) and a layer of |
---|
242 | python modules (source/py_modules). |
---|
243 | The C++ layer under source/tiara provides lower level classes closely |
---|
244 | related to the Geant4 kernel. |
---|
245 | The shadow classes in the source/*Wrapper directories provide classes |
---|
246 | that may be instantiated in a python script or session. This way the |
---|
247 | lower level C++ code can be used directly for scripting in python. The |
---|
248 | shadow classes are declared in the files with extensions ".i" in the |
---|
249 | source/*Wrapper/include directories. Swig is used to create C++ code for |
---|
250 | a library that can be loaded into python and python modules (files with |
---|
251 | extensions .py in the source/*Wrapper directories). When the python |
---|
252 | modules created by swig are imported into python (in a session or a |
---|
253 | script) the corresponding C++ library is automatically loaded as well. |
---|
254 | The python modules in source/py_modules provide classes and functions |
---|
255 | that may be changed or customized more frequently than the C++ classes |
---|
256 | in source/tiara. These classes complete the construction of geometries, |
---|
257 | take care of the procedure of setting up the simulation, the run sequence |
---|
258 | and the analysis after the simulation has been ran. |
---|
259 | The script runSim.py is an commented example of using the python modules |
---|
260 | to run a simulation. |
---|
261 | |
---|
262 | |
---|
263 | 6) Note about how to call the hadronic physics lists in runSim.py and runSimNoAnalysis.py |
---|
264 | ========================================================================================= |
---|
265 | |
---|
266 | It is only necessary to change the physList value in runSim.py or runSimNoAnalysis.py. In the example, there are 4 available physics lists, but of course the user can use whatever physics lists he/she likes and present in the Geant4-7.0 repository. In such a case, the user should also modify the |
---|
267 | /source/TiaraWrapper/include/Tiara.i file in order to create an instantiation of the |
---|
268 | physics list class. In particular, just follow the same lines already used for the six |
---|
269 | available physics lists. |
---|
270 | |
---|