Skip to content

Commit 856d118

Browse files
committed
Add simple test for the external generator
1 parent 601fd10 commit 856d118

File tree

2 files changed

+70
-4
lines changed

2 files changed

+70
-4
lines changed
Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,36 @@
1-
int External() {
2-
return 0;
1+
int External()
2+
{
3+
std::string path = "o2sim_Kine.root";
4+
int pdgToCheck = 3312;
5+
6+
TFile file(path.c_str(), "read");
7+
if (file.IsZombie()) {
8+
std::err << "Cannot open ROOT file " << path << std::endl;
9+
return 1;
10+
}
11+
12+
int nInjectedParticles = 0;
13+
TTree* tree = (TTree*)file.Get("o2sim");
14+
std::vector<o2::MCTrack>* tracks;
15+
tree->SetBranchAdress("MCTrack", &tracks)
16+
17+
int nEvents = tree->GetEntries();
18+
for (int i = 0; i < nEvents; i++) {
19+
tree->GetEntry(i);
20+
for (const auto& track : tracks) {
21+
auto pdgCode = track.getPdgCode();
22+
if (pdgCode == pdgToCheck) {
23+
// not injecting anti-particle
24+
nInjectedParticles++;
25+
}
26+
}
27+
}
28+
29+
if (nInjectedParticles < nEvents) {
30+
// Check that we are correctly injecting one
31+
// particle per event
32+
return 1;
33+
}
34+
35+
return 0;
336
}

MC/config/ALICE3/ini/tests/xi_pp.C

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,36 @@
1-
int External() {
2-
return 0;
1+
int External()
2+
{
3+
std::string path = "o2sim_Kine.root";
4+
int pdgToCheck = 3312;
5+
6+
TFile file(path.c_str(), "read");
7+
if (file.IsZombie()) {
8+
std::err << "Cannot open ROOT file " << path << std::endl;
9+
return 1;
10+
}
11+
12+
int nInjectedParticles = 0;
13+
TTree* tree = (TTree*)file.Get("o2sim");
14+
std::vector<o2::MCTrack>* tracks;
15+
tree->SetBranchAdress("MCTrack", &tracks)
16+
17+
int nEvents = tree->GetEntries();
18+
for (int i = 0; i < nEvents; i++) {
19+
tree->GetEntry(i);
20+
for (const auto& track : tracks) {
21+
auto pdgCode = track.getPdgCode();
22+
if (pdgCode == pdgToCheck) {
23+
// not injecting anti-particle
24+
nInjectedParticles++;
25+
}
26+
}
27+
}
28+
29+
if (nInjectedParticles < nEvents) {
30+
// Check that we are correctly injecting 15
31+
// particle per event
32+
return 1;
33+
}
34+
35+
return 0;
336
}

0 commit comments

Comments
 (0)