Skip to content

Commit 100a234

Browse files
preghenellasawenzel
authored andcommitted
Add example to show how to add custom information to event header
1 parent a0da596 commit 100a234

8 files changed

Lines changed: 119 additions & 2 deletions

File tree

Generators/src/GeneratorPythia8.cxx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,12 @@ void GeneratorPythia8::getNremn(const Pythia8::Event& event, int& nProtonProj, i
388388
auto pdg = particle.id();
389389

390390
// nuclear remnants have pdg code = ±10LZZZAAA9
391-
if (pdg < 1000000000)
391+
if (pdg < 1000000000) {
392392
continue; // must be nucleus
393-
if (pdg % 10 != 9)
393+
}
394+
if (pdg % 10 != 9) {
394395
continue; // first digit must be 9
396+
}
395397
nNucRem++;
396398

397399
// extract A, Z and L from pdg code

doc/DetectorSimulation.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,5 +460,6 @@ Other helpful resources are the scripts used for regression testing in [prodtest
460460
| [HepMC_STARlight](../run/SimExamples/HepMC_STARlight) | Simple example showing **generator configuration** that runs a standalone `STARlight` generation that couples to the `o2` via a `HepMC` file |
461461
| [Jet_Embedding_Pythia](../run/SimExamples/Jet_Embedding_Pythia8) | Complex example showing **generator configuration**, **digitization embedding**, **MCTrack access** |
462462
| [Selective_Transport](../run/SimExamples/Selective_Transport) | Simple example showing how to run simulation transporting only a custumisable set of particles |
463+
| [Custom_EventInfo](../run/SimExamples/Custom_EventInfo) | Simple example showing how to add custom information to the MC event header |
463464
| [sim_challenge.sh](../prodtests/sim_challenge.sh) | Basic example doing a **simple transport, digitization, reconstruction pipeline** on the full dectector. All stages use parallelism. |
464465
| [sim_performance.sh](../prodtests/sim_performance_test.sh) | Basic example for serial transport and linearized digitization sequence (one detector after the other). Serves as standard performance candle. |
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
class Generator : public o2::eventgen::GeneratorPythia8 {
2+
3+
public:
4+
5+
Generator() = default;
6+
~Generator() = default;
7+
8+
/** static functions that define the information
9+
stored in the header (key and data type)
10+
and provide a mean to retrieve it
11+
**/
12+
13+
static void setXsection(o2::dataformats::MCEventHeader* head, double val) { head->putInfo<double>("Xsection", val); };
14+
static double getXsection(o2::dataformats::MCEventHeader* head, bool& isvalid) { return head->getInfo<double>("Xsection", isvalid); };
15+
16+
static void setXsectionErr(o2::dataformats::MCEventHeader* head, double val) { head->putInfo<double>("Xsection_err", val); };
17+
static double getXsectionErr(o2::dataformats::MCEventHeader* head, bool& isvalid) { return head->getInfo<double>("Xsection_err", isvalid); };
18+
19+
static void setNmpi(o2::dataformats::MCEventHeader* head, int val) { head->putInfo<int>("Nmpi", val); };
20+
static int getNmpi(o2::dataformats::MCEventHeader* head, bool& isvalid) { return head->getInfo<int>("Nmpi", isvalid); };
21+
22+
private:
23+
24+
void updateHeader(o2::dataformats::MCEventHeader* head) final {
25+
26+
// call original function
27+
o2::eventgen::GeneratorPythia8::updateHeader(head);
28+
29+
// store cross-section and Nmpi
30+
setXsection(head, mPythia.info.sigmaGen());
31+
setXsectionErr(head, mPythia.info.sigmaErr());
32+
setNmpi(head, mPythia.info.nMPI());
33+
34+
};
35+
36+
};
37+
38+
FairGenerator*
39+
generator()
40+
{
41+
return new Generator;
42+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
### beams
2+
Beams:idA 2212 # proton
3+
Beams:idB 2212 # proton
4+
Beams:eCM 14000. # GeV
5+
6+
### processes
7+
SoftQCD:inelastic on # all inelastic processes
8+
9+
### decays
10+
ParticleDecays:limitTau0 on
11+
ParticleDecays:tau0Max 0.001
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include "generator.macro"
2+
3+
void
4+
read_event_info(const char *fname)
5+
{
6+
7+
auto fin = TFile::Open(fname);
8+
auto tin = (TTree*)fin->Get("o2sim");
9+
auto head = new o2::dataformats::MCEventHeader;
10+
tin->SetBranchAddress("MCEventHeader.", &head);
11+
12+
bool isvalid;
13+
14+
for (int iev = 0; iev < tin->GetEntries(); ++iev) {
15+
16+
tin->GetEntry(iev);
17+
18+
std::cout << " ---------------" << std::endl;
19+
auto Xsection = Generator::getXsection(head, isvalid);
20+
if (isvalid)
21+
std::cout << " Xsection = " << Xsection << std::endl;
22+
auto XsectionErr = Generator::getXsectionErr(head, isvalid);
23+
if (isvalid)
24+
std::cout << " XsectionErr = " << XsectionErr << std::endl;
25+
auto Nmpi = Generator::getNmpi(head, isvalid);
26+
if (isvalid)
27+
std::cout << " Nmpi = " << Nmpi << std::endl;
28+
29+
}
30+
31+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
#
3+
# This is a simulation example showing how to run simulation with Pythia8
4+
# with an external generator that adds custom information to the event header
5+
#
6+
#
7+
8+
set -x
9+
10+
MODULES="PIPE ITS TPC"
11+
EVENTS=100
12+
NWORKERS=8
13+
14+
### generate some events with the external generator that will
15+
### provide some custom information in the event header
16+
17+
o2-sim -j ${NWORKERS} -n ${EVENTS} -g external -m ${MODULES} \
18+
--configFile sim.ini > log 2>&1
19+
20+
### read the kinematics to print the custom information stored by
21+
### the external generator that we ran before
22+
23+
root -b -q -l "read_event_info.macro(\"o2sim_Kine.root\")"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[GeneratorExternal]
2+
fileName=generator.macro
3+
funcName=generator()
4+
5+
[GeneratorPythia8]
6+
config=pythia8_inel.cfg

run/SimExamples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@
1717
* \subpage refrunSimExamplesForceDecay_Lambda_Neutron_Dalitz
1818
* \subpage refrunSimExamplesJustPrimaryKinematics
1919
* \subpage refrunSimExamplesSelective_Transport
20+
* \subpage refrunSimExamplesCustom_EventInfo
2021
/doxy -->

0 commit comments

Comments
 (0)