Skip to content

Commit 3e73db3

Browse files
committed
Merge branch 'cholmcc_generatos' into cholmcc_generators_more
2 parents 101de15 + 5b62d47 commit 3e73db3

File tree

5 files changed

+189
-175
lines changed

5 files changed

+189
-175
lines changed

run/SimExamples/HepMC/read.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/bash
22

33
inp=events.hepmc
44
seed=$RANDOM

run/SimExamples/TParticle/README.md

Lines changed: 120 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -3,235 +3,235 @@
33
/doxy -->
44

55
Here 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

1010
The generator `GeneratorTParticle` can read events from a ROOT file
1111
containing a `TTree` with a branch holding a `TClonesArray` of
1212
`TParticle` objects. These files can be produced by a standalone event
1313
generator 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-
2323
for a list of options. This expects an input file with a `TTree`
2424
with 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
4646
also spawn an child EG to produce events. Suppose we have a program
4747
named `eg` which is some EG that writes `TParticle` event records to a
4848
file . Then we can execute a simulation using this external
4949
EG 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-
5757
for 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

6666
If a program does not adhere to these requirements, it will often be
6767
simple 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

7575
The child-process feature allows us to use almost any EG for which we
7676
have 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+
134134
Then 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+
145145
and a simple shell-script [`myeg.sh`](myeg.sh) to pass arguments to
146146
the `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

175175
1. 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

184184
The `GeneratorTParticle` (and sister generator `GeneratorHepMC`) will
185185
in the not so distant future be upgraded with new functionality to
186186
more easily customise reading files and executing a child process. In
187187
particular
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

249249
The class `GeneratorTParticle` will take a key parameter, say
250250
`headerName` which will indicate a branch that contains header
251251
information. Under that branch, the class will then search for leaves
252252
(`TLeaf`) that correspond to standard header information keys (see
253253
o2::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

256256
Thus, as long as the generator observes the convention used, we can
257257
also 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

Comments
 (0)