Skip to content

Commit f79f3ad

Browse files
committed
Merge branch 'cholmcc_generators_more' into cholmcc_aod_to_hepmc
2 parents 494110c + 209b453 commit f79f3ad

13 files changed

Lines changed: 123 additions & 101 deletions

File tree

Generators/include/Generators/GeneratorFileOrCmdParam.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct GeneratorFileOrCmdParam : public o2::conf::ConfigurableParamHelper<Genera
3636
std::string bMaxSwitch = "-b";
3737
std::string nEventsSwitch = "-n";
3838
std::string backgroundSwitch = "&";
39-
O2ParamDef(GeneratorFileOrCmdParam, "FileOrCmd");
39+
O2ParamDef(GeneratorFileOrCmdParam, "GeneratorFileOrCmd");
4040
};
4141

4242
} // end namespace eventgen

Generators/include/Generators/GeneratorHepMC.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ class GeneratorHepMC : public Generator, public GeneratorFileOrCmd
103103

104104
/** HepMC interface **/
105105
uint64_t mEventsToSkip = 0;
106+
int mVersion = 0;
106107
std::shared_ptr<HepMC3::Reader> mReader;
107108
/** Event structure */
108109
HepMC3::GenEvent* mEvent = nullptr;

Generators/src/GeneratorHepMC.cxx

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,23 @@ void GeneratorHepMC::setup(const GeneratorFileOrCmdParam& param0,
7474
const conf::SimConfig& config)
7575
{
7676
if (not param.fileName.empty()) {
77-
LOG(fatal) << "The use of the key \"HepMC.fileName\" is "
78-
<< "no longer supported, use \"FileOrCmd.fileNames\" instead";
77+
LOG(warn) << "The use of the key \"HepMC.fileName\" is "
78+
<< "deprecated, use \"GeneratorFileOrCmd.fileNames\" instead";
7979
}
80-
if (param.version != 0)
81-
LOG(warn) << "The key \"HepMC.version\" is no longer used. The "
82-
<< "version of the input files are automatically deduced.";
80+
8381
GeneratorFileOrCmd::setup(param0, config);
82+
if (not param.fileName.empty()) {
83+
setFileNames(param.fileName);
84+
}
85+
86+
mVersion = param.version;
8487
setEventsToSkip(param.eventsToSkip);
88+
89+
if (param.version != 0 and mCmd.empty()) {
90+
LOG(warn) << "The key \"HepMC.version\" is no longer used when "
91+
<< "reading from files. The format version of the input files "
92+
<< "are automatically deduced.";
93+
}
8594
}
8695

8796
/*****************************************************************/
@@ -349,9 +358,14 @@ bool GeneratorHepMC::makeReader()
349358
// For FIFO reading, we assume straight ASCII output always.
350359
// Unfortunately, the HepMC3::deduce_reader `stat`s the filename
351360
// which isn't supported on a FIFO, so we have to use the reader
352-
// directly.
361+
// directly. Here, we allow for version 2 formats if the user
362+
// specifies that
353363
LOG(info) << "Creating ASCII reader of " << filename;
354-
mReader.reset(new HepMC3::ReaderAscii(filename));
364+
if (mVersion == 2) {
365+
mReader.reset(new HepMC3::ReaderAsciiHepMC2(filename));
366+
} else {
367+
mReader.reset(new HepMC3::ReaderAscii(filename));
368+
}
355369
} else {
356370
LOG(info) << "Deduce a reader of " << filename;
357371
mReader = HepMC3::deduce_reader(filename);

Generators/src/GeneratorPythia8.cxx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,10 @@ void GeneratorPythia8::getNpart(const Pythia8::Info& info, int& nPart)
380380
#else
381381
auto hiinfo = info.hiInfo;
382382
#endif
383-
if (hiinfo)
383+
if (hiinfo) {
384384
nPart = (hiinfo->nAbsProj() + hiinfo->nDiffProj() +
385385
hiinfo->nAbsTarg() + hiinfo->nDiffTarg());
386+
}
386387

387388
int nProtonProj, nNeutronProj, nProtonTarg, nNeutronTarg;
388389
getNpart(info, nProtonProj, nNeutronProj, nProtonTarg, nNeutronTarg);

run/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ o2_add_test_command(NAME o2sim_hepmc
279279
-g
280280
hepmc
281281
--configKeyValues
282-
"FileOrCmd.fileNames=${CMAKE_SOURCE_DIR}/Generators/share/data/pythia.hepmc;HepMC.version=2;align-geom.mDetectors=none"
282+
"GeneratorFileOrCmd.fileNames=${CMAKE_SOURCE_DIR}/Generators/share/data/pythia.hepmc;HepMC.version=2;align-geom.mDetectors=none"
283283
-o
284284
o2simhepmc
285285
LABELS long sim hepmc3

run/SimExamples/HepMC/README.md

Lines changed: 52 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -28,45 +28,46 @@ event files in the HepMC format.
2828

2929
To make a simulation reading from the file `events.hepmc`, do
3030

31-
o2-sim -g hepmc --configKeyValues "FileOrCmd.fileNames=events.hepmc" ...
31+
o2-sim -g hepmc --configKeyValues "GeneratorFileOrCmd.fileNames=events.hepmc" ...
3232

3333
See also [`read.sh`](read.sh).
3434

3535
## Reading HepMC events from child process
36+
3637
`GeneratorHepMC` can not only read HepMC events from a file, but can
3738
also spawn an child EG to produce events. Suppose we have a program
3839
named `eg` which is some EG that writes HepMC event records to the
3940
standard output. Then we can execute a simulation using this external
4041
EG by
4142

42-
o2-sim -g hepmc --configKeyValues "FileOrCmd.cmd=eg"
43+
o2-sim -g hepmc --configKeyValues "GeneratorFileOrCmd.cmd=eg"
4344

4445
See also [`child.sh`](child.sh).
4546

4647
There are some requirements on the program `eg`:
4748

4849
- The EG program _must_ be able to write the HepMC event structures to
4950
a specified file. The option passed to the program is specified via
50-
the key `FileOrCmd.outputSwitch`. This defaults to `>` which means
51-
the EG program is assumed to write the HepMC event structures to
52-
standard output, _and_ that nothing else is printed on standard
53-
output.
51+
the key `GeneratorFileOrCmd.outputSwitch`. This defaults to `>`
52+
which means the EG program is assumed to write the HepMC event
53+
structures to standard output, _and_ that nothing else is printed on
54+
standard output.
5455
- It _must_ accept an option to set the number of events to generate.
5556
This is controlled by the configuration key
56-
`FileOrCmd.nEventsSwitch` and defaults to `-n`. Thus, the EG
57-
application should accept `-n 10` to mean that it should generate
57+
`GeneratorFileOrCmd.nEventsSwitch` and defaults to `-n`. Thus, the
58+
EG application should accept `-n 10` to mean that it should generate
5859
`10` events, for example.
5960
- The EG application should accept a command line switch to set the
60-
random number generator seed. This option is specified via the
61-
configuration key `FileOrCmd.seedSwitch` and defaults to `-s`.
62-
Thus, the EG application must accept `-s 123456` to mean to set the
63-
random number seed to `123456` for example.
61+
random number generator seed. This option is specified via the
62+
configuration key `GeneratorFileOrCmd.seedSwitch` and defaults to
63+
`-s`. Thus, the EG application must accept `-s 123456` to mean to
64+
set the random number seed to `123456` for example.
6465
- The EG application should accept a command line switch to set the
6566
maximum impact parameter (in Fermi-metre) sampled. This is set via
66-
the configuration key `FileOrCmd.bMaxSwithc` and defaults to `-b`.
67-
Thus, the EG application should take the command line argument `-b
68-
10` to mean that it should only generate events with an impact
69-
parameter between 0fm and 10fm.
67+
the configuration key `GeneratorFileOrCmd.bMaxSwithc` and defaults
68+
to `-b`. Thus, the EG application should take the command line
69+
argument `-b 10` to mean that it should only generate events with an
70+
impact parameter between 0fm and 10fm.
7071

7172
If a program does not adhere to these requirements, it will often be
7273
simple enough to make a small wrapper script that enforce this. For
@@ -76,8 +77,8 @@ We can filter that out via a shell script ([`crmc.sh`](crmc.sh)) like
7677
#!/bin/sh
7778
crmc $@ -o hepmc3 -f /dev/stdout | sed -n 's/^\(HepMC::\|[EAUWVP] \)/\1/p'
7879

79-
The `sed` command selects lines that begin with `HepMC::`, or one
80-
of single characters `E` (event), `A` (attribute), `U` (units), `W`
80+
The `sed` command selects lines that begin with `HepMC::`, or one of
81+
single characters `E` (event), `A` (attribute), `U` (units), `W`
8182
(weight), `V` (vertex), or `P` (particle) followed by a space. This
8283
should in most cases be enough to filter out extra stuff written on
8384
standard output.
@@ -87,7 +88,7 @@ The script above also passes any additional command line options on to
8788
the CRMC suite. For example, if we want to simulate p-Pb collisions
8889
using DpmJET, we can do
8990

90-
o2-sim -g hepmc --configKeyValues "FileOrCmd.cmd=crmc.sh -m 12 -i2212 -I 1002080820"
91+
o2-sim -g hepmc --configKeyValues "GeneratorFileOrCmd.cmd=crmc.sh -m 12 -i2212 -I 1002080820"
9192

9293

9394
### Implementation details
@@ -109,46 +110,50 @@ The `GeneratorHepMC` (and sister generator `GeneratorTParticle`)
109110
allows customisation of the execution via configuration keys passed
110111
via `--configKeyValues`
111112

112-
- `HepMC.eventsToSkip=number` a number events to skip at the
113-
beginning of each file read.
113+
- `HepMC.eventsToSkip=number` a number events to skip at the beginning
114+
of each file read.
115+
116+
- `HepMC.version` - when reading the events from files, this option is
117+
no longer needed. The code itself figures out which format version
118+
the input file is in. If executing a child process through
119+
`GeneratorFileOrCmd.cmd` and the EG writes out HepMC2 format, then
120+
this _must_ be set to `2`. Otherwise, HepMC3 is assumed.
114121

115-
- `FileOrCmd.fileNames=list` a comma separated list of HepMC files
116-
to read.
122+
- `GeneratorFileOrCmd.fileNames=list` a comma separated list of HepMC
123+
files to read.
117124

118-
- `FileOrCmd.cmd=command line` a command line to execute as a
125+
- `GeneratorFileOrCmd.cmd=command line` a command line to execute as a
119126
background child process. If this is set (not the empty string),
120-
then `FileOrCmd.fileNames` is ignored.
127+
then `GeneratorFileOrCmd.fileNames` is ignored.
121128

122-
- A number of keys that specifies the command line option switch
123-
that the child program accepts for certain things. If any of
124-
these are set to the empty string, then that switch and
125-
corresponding option value is not passed to the child program.
129+
- A number of keys that specifies the command line option switch that
130+
the child program accepts for certain things. If any of these are
131+
set to the empty string, then that switch and corresponding option
132+
value is not passed to the child program.
126133

127-
- `FileOrCmd.outputSwitch=switch` (default `>`) to specify output
128-
file. The default of `>` assumes that the program write HepMC
129-
events, and _only_ those, to standard output.
134+
- `GeneratorFileOrCmd.outputSwitch=switch` (default `>`) to specify
135+
output file. The default of `>` assumes that the program write
136+
HepMC events, and _only_ those, to standard output.
130137

131-
- `FileOrCmd.seedSwitch=switch` (default `-s`) to specify the
132-
random number generator seed. The value passed is selected by
138+
- `GeneratorFileOrCmd.seedSwitch=switch` (default `-s`) to specify
139+
the random number generator seed. The value passed is selected by
133140
the `o2-sim` option `--seed`
134141

135-
- `FileOrCmd.bMaxSwitch=switch` (default `-b`) to specify the
136-
upper limit on the impact parameters sampled. The value passed
137-
is selected by the `o2-sim` option `--bMax`
142+
- `GeneratorFileOrCmd.bMaxSwitch=switch` (default `-b`) to specify
143+
the upper limit on the impact parameters sampled. The value
144+
passed is selected by the `o2-sim` option `--bMax`
138145

139-
- `FileOrCmd.nEventsSwitch=switch` (default `-n`) to specify the
140-
number of events to generate. The value passed is selected by
141-
the `o2-sim` option `--nEvents` or (`-n`)
146+
- `GeneratorFileOrCmd.nEventsSwitch=switch` (default `-n`) to
147+
specify the number of events to generate. The value passed is
148+
selected by the `o2-sim` option `--nEvents` or (`-n`)
142149

143-
- `FileOrCmd.backgroundSwitch=switch` (default `&`) to specify how
144-
the program is put in the background. Typically this should be
145-
`&`, but a program may itself fork to the background.
150+
- `GeneratorFileOrCmd.backgroundSwitch=switch` (default `&`) to
151+
specify how the program is put in the background. Typically this
152+
should be `&`, but a program may itself fork to the background.
146153

147-
- Some options are no longer available
154+
- Some options are deprecated
148155

149-
- `HepMC.fileName` - use `FileOrCmd.fileNames`
150-
- `HepMC.version` - now the code itself figures out which format
151-
version the input file is in.
156+
- `HepMC.fileName` - use `GeneratorFileOrCmd.fileNames`
152157

153158
The command line build will now be
154159

run/SimExamples/HepMC/child.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env bash
22

33
cmd="./crmc.sh"
4+
more="GeneratorFileOrCmd.bMaxSwitch=none"
45
seed=$RANDOM
56
nev=1
67
out=
@@ -13,6 +14,7 @@ Usage: $0 [OPTIONS]
1314
Options:
1415
1516
-c,--cmdline COMMAND Command line
17+
-m,--more CONFIG More configurations ($more)
1618
-s,--seed SEED Random number seed ($seed)
1719
-n,--nevents EVENTS Number of events ($nev)
1820
-o,--output OUTPUT Output prefix ($out)
@@ -47,5 +49,5 @@ fi
4749
out=`echo "$out" | tr ' ' '_'`
4850

4951
export VMCWORKDIR=${O2_ROOT}/share
50-
o2-sim -g hepmc --configKeyValues "FileOrCmd.cmd=$cmd" \
52+
o2-sim -g hepmc --configKeyValues "GeneratorFileOrCmd.cmd=$cmd;${more}" \
5153
--outPrefix "$out" --seed $seed --nEvents $nev $@

run/SimExamples/HepMC/crmc.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
# event record.
44

55
crmcParam=$(dirname $(dirname `which crmc`))/etc/crmc.param
6-
exec crmc -c $crmcParam $@ -o hepmc3 -f /dev/stdout | \
6+
exec crmc -c $crmcParam $@ -o hepmc -f /dev/stdout | \
77
sed -n 's/^\(HepMC::\|[EAUWVP] \)/\1/p'

run/SimExamples/HepMC/read.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ fi
4444
out=`echo "$out" | tr ' ' '_'`
4545

4646
export VMCWORKDIR=${O2_ROOT}/share
47-
o2-sim -g hepmc --configKeyValues "FileOrCmd.fileNames=$inp" \
47+
o2-sim -g hepmc --configKeyValues "GeneratorFileOrCmd.fileNames=$inp" \
4848
--outPrefix "$out" --seed $seed --nEvents $nev $@

run/SimExamples/HepMC_STARlight/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ env -i HOME="$HOME" USER="$USER" PATH="/bin:/usr/bin:/usr/local/bin" \
1515
# PART b)
1616
NEV=1000
1717
o2-sim -j 20 -n ${NEV} -g hepmc -m PIPE ITS -o sim \
18-
--configKeyValues "FileOrCmd.fileNames=starlight.hepmc;Diamond.position[2]=0.1;Diamond.width[2]=0.05"
18+
--configKeyValues "GeneratorFileOrCmd.fileNames=starlight.hepmc;Diamond.position[2]=0.1;Diamond.width[2]=0.05"

0 commit comments

Comments
 (0)