Skip to content

Commit 4715d37

Browse files
committed
Renamed _script_ (not macro) to end in .macro (sigh)
1 parent 595d843 commit 4715d37

File tree

3 files changed

+149
-27
lines changed

3 files changed

+149
-27
lines changed

run/SimExamples/HepMC/README.md

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,33 @@
55
Here are pointers on how to use `GeneratorHepMC` selected by the
66
option `-g hepmc` for `o2-sim`.
77

8-
## Reading HepMC files
8+
## Reading HepMC files
99

1010
The generator `GeneratorHepMC` can read events from a
11-
[HepMC(3)](http://hepmc.web.cern.ch/hepmc/) formatted file. These files
12-
can be produced by a standalone event generator program (EG).
13-
Examples of such programs are
11+
[HepMC(3)](http://hepmc.web.cern.ch/hepmc/) formatted file. These
12+
files can be produced by a standalone event generator program (EG).
13+
Examples of such programs are
1414

1515
- [Pythia8](https://pythia.org)
16-
- The [CRMC](https://gitlab.iap.kit.edu/AirShowerPhysics/crmc) suite
16+
- The [CRMC](https://gitlab.iap.kit.edu/AirShowerPhysics/crmc) suite
1717
- [Herwig](https://herwig.hepforge.org/)
1818
- [SMASH](https://smash-transport.github.io/)
19-
- ... and many others
19+
- ... and many others
2020

2121
Please refer to the documentation of these for more on how to make
2222
event files in the HepMC format.
2323

24-
To make a simulation reading from the file `events.hepmc`, do
25-
24+
To make a simulation reading from the file `events.hepmc`, do
2625
o2-sim -g hepmc --configKeyValues "HepMC.fileName=events.hepmc" ...
2726

2827
See also [`read.sh`](read.sh)
2928

30-
## Reading HepMC events from child process
31-
29+
## Reading HepMC events from child process
3230
`GeneratorHepMC` can not only read HepMC events from a file, but can
3331
also spawn an child EG to produce events. Suppose we have a program
3432
named `eg` which is some EG that writes HepMC event records to the
3533
standard output. Then we can execute a simulation using this external
36-
EG by
37-
34+
EG by
3835
o2-sim -g hepmc --configKeyValues "HepMC.progCmd=eg"
3936

4037
See also [`child.sh`](child.sh)
@@ -50,10 +47,9 @@ There are some requirements on the program `eg`:
5047
If a program does not adhere to these requirements, it will often be
5148
simple enough to make a small wrapper script that enforce this. For
5249
example, `crmc` will write a lot of information to standard output.
53-
We can filter that out via a shell script ([`crmc.sh`](crmc.sh)) like
50+
We can filter that out via a shell script ([`crmc.sh`](crmc.sh)) like
5451

55-
#!/bin/sh
56-
52+
#!/bin/sh
5753
crmc $@ -o hepmc3 -f /dev/stdout | sed -n 's/^\(HepMC::\|[EAUWVP] \)/\1/p'
5854

5955
The `sed` command selects lines that begin with `HepMC::`, or one
@@ -65,12 +61,12 @@ standard output.
6561
The script above also passes any additional command line options on to
6662
`crmc` via `$@`. We can utilise this with `o2-sim` to set options to
6763
the CRMC suite. For example, if we want to simulate p-Pb collisions
68-
using DpmJET, we can do
64+
using DpmJET, we can do
6965

7066
o2-sim -g hepmc --configKeyValues "HepMC.progCmd=crmc.sh -m 12 -i2212 -I 1002080820"
7167

7268

73-
### Implementation details
69+
### Implementation details
7470

7571
Internally `GeneratorHepMC`
7672

@@ -81,14 +77,14 @@ Internally `GeneratorHepMC`
8177

8278
eg options > fifo-name &
8379

84-
4. and executes that command line
80+
4. and executes that command line
8581

86-
## The future
82+
## The future
8783

8884
The `GeneratorHepMC` (and sister generator `GeneratorTParticle`) will
8985
in the not so distant future be upgraded with new functionality to
9086
more easily customise reading files and executing a child process. In
91-
particular
87+
particular
9288

9389
- HepMC event structures can be read from any file format supported by
9490
HepMC it self (see
@@ -101,8 +97,7 @@ particular
10197
beginning of each file read.
10298

10399
- `FileOrCmd.fileNames=list` a comma separated list of HepMC files
104-
to read
105-
100+
to read
106101
- `FileOrCmd.cmd=command line` a command line to execute as a
107102
background child process. If this is set (not the empty string),
108103
then `FileOrCmd.fileNames` is ignored.
@@ -132,19 +127,18 @@ particular
132127
the program is put in the background. Typically this should be
133128
`&`, but a program may itself fork to the background.
134129

135-
- Some options are no longer available
136-
130+
- Some options are no longer available
137131
- `HepMC.fileName` - use `FileOrCmd.fileNames`
138132
- `HepMC.progCmd` - use `FileOrCmd.cmd`
139133

140-
The command line build will now be
134+
The command line build will now be
141135

142136
> _commandLine_ _nEventsSwitch_ _nEvents_ _seedSwitch_ _seed_
143137
> _bMaxSwitch_ _bMax_ _outputSwitch_ _output_ _backgroundSwitch_
144138
145139
If any of the `Switch` keys are empty, then the corresponding option
146140
is not propagated to the command line. For example, if _bMaxSwitch_
147-
is empty, then the build command line will be
141+
is empty, then the build command line will be
148142

149143
> _commandLine_ _nEventsSwitch_ _nEvents_ _seedSwitch_ _seed_
150144
> _outputSwitch_ _output_ _backgroundSwitch_
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#include <TGenerator.h>
2+
#include <TFile.h>
3+
#include <TTree.h>
4+
#include <TClonesArray.h>
5+
#include <TRandom.h>
6+
#include <TParticle.h>
7+
8+
//--------------------------------------------------------------------
9+
// Our generator class. Really simple.
10+
class MyGenerator : public TGenerator
11+
{
12+
public:
13+
Long_t projectilePDG;
14+
Long_t targetPDG;
15+
Double_t sqrts;
16+
MyGenerator() {}
17+
void Initialize(Long_t projectile,
18+
Long_t target,
19+
Double_t sqrts)
20+
{
21+
this->projectilePDG = projectile;
22+
this->targetPDG = target;
23+
this->sqrts = sqrts;
24+
}
25+
void GenerateEvent()
26+
{ /* Do something */
27+
}
28+
TObjArray* ImportParticles(Option_t* option = "") { return 0; }
29+
Int_t ImportParticles(TClonesArray* particles, Option_t* option = "")
30+
{
31+
Int_t nParticles = 10;
32+
Int_t iParticle = 0;
33+
// Make beam particles
34+
new ((*particles)[iParticle++]) TParticle(projectilePDG, 4, -1, -1,
35+
2, nParticles - 1,
36+
0, 0, sqrts / 2,
37+
TMath::Sqrt(1 + sqrts * sqrts),
38+
0, 0, 0, 0);
39+
new ((*particles)[iParticle++]) TParticle(projectilePDG, 4, -1, -1,
40+
2, nParticles - 1,
41+
0, 0, -sqrts / 2,
42+
TMath::Sqrt(1 + sqrts * sqrts),
43+
0, 0, 0, 0);
44+
for (; iParticle < nParticles; iParticle++)
45+
new ((*particles)[iParticle])
46+
TParticle(211, 1, 0, 1,
47+
-1, -1,
48+
0.1 * iParticle,
49+
0.1 * iParticle,
50+
0.1 * iParticle,
51+
TMath::Sqrt(0.03 * iParticle * iParticle + 0.14 * 0.14),
52+
0, 0, 0, 0);
53+
54+
return nParticles;
55+
}
56+
};
57+
//--------------------------------------------------------------------
58+
// Our steering class
59+
struct MySteer {
60+
TGenerator* generator;
61+
TFile* file;
62+
TTree* tree;
63+
TClonesArray* particles;
64+
Int_t every;
65+
MySteer(TGenerator* generator, const TString& output, Int_t every)
66+
: generator(generator),
67+
file(TFile::Open(output, "RECREATE")),
68+
tree(new TTree("T", "T")),
69+
particles(new TClonesArray("TParticle")),
70+
every(every)
71+
{
72+
tree->SetDirectory(file);
73+
tree->Branch("Particles", &particles);
74+
}
75+
~MySteer()
76+
{
77+
close();
78+
}
79+
void event()
80+
{
81+
particles->Clear();
82+
generator->GenerateEvent();
83+
generator->ImportParticles(particles);
84+
tree->Fill();
85+
}
86+
void sync()
87+
{
88+
// Important so that GeneratorTParticle picks up the events as
89+
// they come.
90+
tree->AutoSave("SaveSelf FlushBaskets Overwrite");
91+
}
92+
void run(Int_t nev)
93+
{
94+
for (Int_t iev = 0; iev < nev; iev++) {
95+
event();
96+
97+
if (every > 0 and (iev % every == 0) and iev != 0)
98+
sync();
99+
}
100+
}
101+
void close()
102+
{
103+
if (not file)
104+
return;
105+
file->Write();
106+
file->Close();
107+
file = nullptr;
108+
}
109+
};
110+
111+
//--------------------------------------------------------------------
112+
// Our steering function
113+
void MyEG(Int_t nev, const TString& out, Int_t seed, Int_t every = 1)
114+
{
115+
gRandom->SetSeed(seed);
116+
117+
MyGenerator* eg = new MyGenerator();
118+
eg->Initialize(2212, 2212, 5200);
119+
120+
MySteer steer(eg, out, every);
121+
steer.run(nev);
122+
}
123+
// Local Variables:
124+
// mode: C++
125+
// End:
126+
//
127+
// EOF
128+
//

run/SimExamples/TParticle/myeg.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ while test $# -gt 0 ; do
1818
shift
1919
done
2020

21-
root -q -l MyEG.cc${opt} -- $nev \"$out\" $seed
21+
root -q -l MyEG.macro${opt} -- $nev \"$out\" $seed
2222

0 commit comments

Comments
 (0)