33/doxy -->
44
55Here are pointers on how to use ` GeneratorTParticle ` selected by the
6- option ` -g tparticle ` for ` o2-sim ` .
6+ option ` -g tparticle ` for ` o2-sim ` .
77
8- ## Reading TParticle files
8+ ## Reading TParticle files
99
1010The generator ` GeneratorTParticle ` can read events from a ROOT file
1111containing a ` TTree ` with a branch holding a ` TClonesArray ` of
1212` TParticle ` objects. These files can be produced by a standalone event
1313generator program (EG).
1414
15- To make a simulation reading from the file ` particles.root ` , do
15+ To make a simulation reading from the file ` particles.root ` , do
1616
17- o2-sim -g tparticle --configKeyValues "GeneratorTParticle.fileName=particles.root" ...
18-
19- See also [ ` read.sh ` ] ( read.sh ) . Do
17+ o2-sim -g tparticle --configKeyValues "GeneratorTParticle.fileName=particles.root" ...
18+
19+ See also [ ` read.sh ` ] ( read.sh ) . Do
20+
21+ ./read.sh --help
2022
21- ./read.sh --help
22-
2323for a list of options. This expects an input file with a ` TTree `
2424with a single ` TBranch ` holding a ` TClonesArray ` of ` TParticle `
25- objects. One such example file can be made with [ ` myeg.sh ` ] . Do
25+ objects. One such example file can be made with [ ` myeg.sh ` ] . Do
2626
27- ./myeg.sh --help
28-
29- for a list of options.
27+ ./myeg.sh --help
28+
29+ for a list of options.
3030
31- ### Configurations
31+ ### Configurations
3232
3333- The name of the ` TTree ` to read can be set by the configuration key
34- ` GeneratorTParticle.treeName ` . The default is ` T `
34+ ` GeneratorTParticle.treeName ` . The default is ` T `
3535- The name of the ` TBranch ` holding the ` TClonesArray ` of ` TParticle `
3636 objects can be set by the configuration key
37- ` GeneratorTParticle.branchName ` . The default is ` Particles `
38-
39- For example
37+ ` GeneratorTParticle.branchName ` . The default is ` Particles `
4038
41- o2-sim -g tparticle --configKeyValues "GeneratorTParticle.fileName=particles.root;GeneratorTParticle.treeName=Events;GeneratorTParticle.branchName=Tracks" ...
39+ For example
4240
43- ## Reading TParticle events from child process
41+ o2-sim -g tparticle --configKeyValues "GeneratorTParticle.fileName=particles.root;GeneratorTParticle.treeName=Events;GeneratorTParticle.branchName=Tracks" ...
42+
43+ ## Reading TParticle events from child process
4444
4545` GeneratorTParticle ` can not only read events from a file, but can
4646also spawn an child EG to produce events. Suppose we have a program
4747named ` eg ` which is some EG that writes ` TParticle ` event records to a
4848file . Then we can execute a simulation using this external
4949EG by
5050
51- o2-sim -g tgenerator --configKeyValues "GeneratorTParticle.progCmd=eg"
51+ o2-sim -g tgenerator --configKeyValues "GeneratorTParticle.progCmd=eg"
52+
53+ See also [ ` child.sh ` ] ( child.sh ) . Do
5254
53- See also [ ` child.sh ` ] ( child.sh ) . Do
55+ ./ child.sh --help
5456
55- ./child.sh --help
56-
5757for a list of options.
5858
59- There are some requirements on the program ` eg ` :
59+ There are some requirements on the program ` eg ` :
6060
6161- It _ must_ accept the option ` -n n-events ` to set the number of
62- events to produce to ` n-events ` .
62+ events to produce to ` n-events ` .
6363
6464- It _ must_ accept the option ` -o output ` to set the output file name.
6565
6666If a program does not adhere to these requirements, it will often be
6767simple enough to make a small wrapper script that enforce this.
6868
69- ### Configurations
69+ ### Configurations
7070
71- Same as above.
71+ Same as above.
7272
73- ### Example EG
73+ ### Example EG
7474
7575The child-process feature allows us to use almost any EG for which we
7676have a ` TGenerator ` interface without compiling it in to O2. Suppose
77- we have defined the class ` MyGenerator ` to produce events.
77+ we have defined the class ` MyGenerator ` to produce events.
7878
7979 class MyGenerator : public TGenerator {
8080 public:
8181 MyGenerator();
8282 void Initialize(Long_t projectile,
83- Long_t target,
84- Double_t sqrts);
83+ Long_t target,
84+ Double_t sqrts);
8585 void GenerateEvent();
8686 Int_t ImportParticles(TClonesArray* particles,Option_t*option="");
8787 };
8888
89- and a steering class
90-
91- struct MySteer {
92- TGenerator* generator;
93- TFile* file;
94- TTree* tree;
95- TClonesArray* particle;
96- Int_t flushEvery;
97- MySteer(TGenerator* generator,
98- const TString& output,
99- Int_t flushEvery)
100- : generator(generator)
101- file(TFile::Open(output,"RECREATE")),
102- tree("T","Particle tree"),
103- particles(new TClonesArray("TParticle")),
104- flushEvery(flushEvery)
105- {
106- tree->SetDirectory(file);
107- tree->Branch("Particles",&particles);
89+ and a steering class
90+
91+ struct MySteer {
92+ TGenerator* generator;
93+ TFile* file;
94+ TTree* tree;
95+ TClonesArray* particle;
96+ Int_t flushEvery;
97+ MySteer(TGenerator* generator,
98+ const TString& output,
99+ Int_t flushEvery)
100+ : generator(generator)
101+ file(TFile::Open(output,"RECREATE")),
102+ tree("T","Particle tree"),
103+ particles(new TClonesArray("TParticle")),
104+ flushEvery(flushEvery)
105+ {
106+ tree->SetDirectory(file);
107+ tree->Branch("Particles",&particles);
108+ }
109+ ~MySteer() { close(); }
110+ void event() {
111+ particles->Clear();
112+ generator->GenerateEvent();
113+ generator->ImportParticles(particles);
114+ tree->Fill();
115+ }
116+ void sync() {
117+ tree->AutoSave("SaveSelf FlushBaskets Overwrite");
108118 }
109- ~MySteer() { close(); }
110- void event() {
111- particles->Clear();
112- generator->GenerateEvent();
113- generator->ImportParticles(particles);
114- tree->Fill();
115- }
116- void sync() {
117- tree->AutoSave("SaveSelf FlushBaskets Overwrite");
118- }
119- void run(Int_t nev) {
120- for (Int_t iev = 0; iev < nev; iev++) {
121- event();
122- if (flushEvery > 0 and (iev % flushEvery == 0) and iev != 0)
123- sync();
124- }
125- }
126- void close() {
127- if (not file) return;
128- file->Write();
129- file->Close();
130- file = nullptr;
131- }
132- };
133-
119+ void run(Int_t nev) {
120+ for (Int_t iev = 0; iev < nev; iev++) {
121+ event();
122+ if (flushEvery > 0 and (iev % flushEvery == 0) and iev != 0)
123+ sync();
124+ }
125+ }
126+ void close() {
127+ if (not file) return;
128+ file->Write();
129+ file->Close();
130+ file = nullptr;
131+ }
132+ };
133+
134134Then we could make the script [ ` MyEG.macro ` (complete code)] ( MyEG.macro ) like
135135
136136 void MyEG(Int_t nev,const TString& out,Int_t every=1)
137137 {
138138 MyGenerator* eg = new MyGenerator();
139139 eg->Initialize(2212, 2212, 5200);
140-
141- MySteer steer(eg, out, every);
142- steer.run(nev);
140+
141+ MySteer steer(eg, out, every);
142+ steer.run(nev);
143143 }
144-
144+
145145and a simple shell-script [ ` myeg.sh ` ] ( myeg.sh ) to pass arguments to
146146the ` MyEG.macro ` script
147147
148148 #!/bin/sh
149-
149+
150150 nev=1
151151 out=particles.root
152-
152+
153153 while test $# -gt 0 ; do
154154 case $1 in
155- -n) nev=$2 ; shift ;;
156- -o) out=$2 ; shift ;;
157- *) ;;
155+ -n) nev=$2 ; shift ;;
156+ -o) out=$2 ; shift ;;
157+ *) ;;
158158 esac
159159 shift
160160 done
161-
161+
162162 root -l MyEG.macro -- $nev \"$out\"
163163
164- We can then do
164+ We can then do
165165
166- o2-sim -g tgenerator --configKeyValues "GeneratorTParticle.progCmd=./myeg.sh"
166+ o2-sim -g tgenerator --configKeyValues "GeneratorTParticle.progCmd=./myeg.sh"
167167
168- to produce events with our generator ` MyGenerator ` .
168+ to produce events with our generator ` MyGenerator ` .
169169
170-
171- ### Implementation details
172170
173- Internally ` GeneratorTParticle `
171+ ### Implementation details
172+
173+ Internally ` GeneratorTParticle `
174174
1751751 . creates a unique temporary file name in the working directory,
176- 2 . builds a command line, e.g.,
176+ 2 . builds a command line, e.g.,
177+
178+ eg options -o temporary-name &
177179
178- eg options -o temporary-name &
179-
180- 3 . and executes that command line
180+ 3 . and executes that command line
181181
182- ## The future
182+ ## The future
183183
184184The ` GeneratorTParticle ` (and sister generator ` GeneratorHepMC ` ) will
185185in the not so distant future be upgraded with new functionality to
186186more easily customise reading files and executing a child process. In
187187particular
188188
189- - New options that can be specified in ` --configKeyValues `
189+ - New options that can be specified in ` --configKeyValues `
190190
191191 - ` GeneratorTParticle.treeName=name ` the name of the ` TTree ` in the
192- input files.
193-
192+ input files.
193+
194194 - ` GeneratorTParticle.branchName=name ` the name of the ` TBranch ` in
195195 the ` TTree ` that holds the ` TClonesArray ` of ` TParticle ` objects.
196-
196+
197197 - ` FileOrCmd.fileNames=list ` a comma separated list of HepMC files
198- to read
199-
198+ to read
199+
200200 - ` FileOrCmd.cmd=command line ` a command line to execute as a
201201 background child process. If this is set (not the empty string),
202- then ` FileOrCmd.fileNames ` is ignored.
203-
202+ then ` FileOrCmd.fileNames ` is ignored.
203+
204204 - A number of keys that specifies the command line option switch
205205 that the child program accepts for certain things. If any of
206206 these are set to the empty string, then that switch and
207- corresponding option value is not passed to the child program.
208-
207+ corresponding option value is not passed to the child program.
208+
209209 - ` FileOrCmd.outputSwitch=switch ` (default ` > ` ) to specify output
210210 file. The default of ` > ` assumes that the program write HepMC
211- events, and _ only_ those, to standard output.
212-
211+ events, and _ only_ those, to standard output.
212+
213213 - ` FileOrCmd.seedSwitch=switch ` (default ` -s ` ) to specify the
214214 random number generator seed. The value passed is selected by
215- the ` o2-sim ` option ` --seed `
216-
215+ the ` o2-sim ` option ` --seed `
216+
217217 - ` FileOrCmd.bMaxSwitch=switch ` (default ` -b ` ) to specify the
218218 upper limit on the impact parameters sampled. The value passed
219- is selected by the ` o2-sim ` option ` --bMax `
220-
219+ is selected by the ` o2-sim ` option ` --bMax `
220+
221221 - ` FileOrCmd.nEventsSwitch=switch ` (default ` -n ` ) to specify the
222222 number of events to generate. The value passed is selected by
223223 the ` o2-sim ` option ` --nEvents ` or (` -n ` )
224-
224+
225225 - ` FileOrCmd.backgroundSwitch=switch ` (default ` & ` ) to specify how
226226 the program is put in the background. Typically this should be
227227 ` & ` , but a program may itself fork to the background.
228228
229- - Some options are no longer available
229+ - Some options are no longer available
230230
231231 - ` GeneratorTParticle.fileName ` - use ` FileOrCmd.fileNames `
232- - ` GeneratorTParticle.progCmd ` - use ` FileOrCmd.cmd `
233-
234- The command line build will now be
232+ - ` GeneratorTParticle.progCmd ` - use ` FileOrCmd.cmd `
233+
234+ The command line build will now be
235235
236236> _ commandLine_ _ nEventsSwitch_ _ nEvents_ _ seedSwitch_ _ seed_
237237> _ bMaxSwitch_ _ bMax_ _ outputSwitch_ _ output_ _ backgroundSwitch_
@@ -244,15 +244,15 @@ example, if _bMaxSwitch_ is empty, then the build command line will be
244244> _ outputSwitch_ _ output_ _ backgroundSwitch_
245245
246246
247- ### Header information
247+ ### Header information
248248
249249The class ` GeneratorTParticle ` will take a key parameter, say
250250` headerName ` which will indicate a branch that contains header
251251information. Under that branch, the class will then search for leaves
252252(` TLeaf ` ) that correspond to standard header information keys (see
253253o2::dataformats::MCInfoKeys). If any of those leaves are present,
254- then the corresponding keys will be set on the generated event header.
254+ then the corresponding keys will be set on the generated event header.
255255
256256Thus, as long as the generator observes the convention used, we can
257257also import auxiliary information (impact parameter, Npart, ...) from
258- the input files in addition to the particle information.
258+ the input files in addition to the particle information.
0 commit comments