Skip to content

Commit 3826465

Browse files
committed
Included Hybrid generators testing + example
1 parent 35d151b commit 3826465

File tree

4 files changed

+67
-2
lines changed

4 files changed

+67
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Performance generator test using hybrid configuration with Pythia8
2+
# underlying event generator
3+
[GeneratorHybrid]
4+
configFile = ${O2DPG_MC_CONFIG_ROOT}/MC/config/common/external/generator/perfConf.json
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
int Hybrid()
2+
{
3+
std::string path{"o2sim_Kine.root"};
4+
TFile file(path.c_str(), "READ");
5+
if (file.IsZombie())
6+
{
7+
std::cerr << "Cannot open ROOT file " << path << "\n";
8+
return 1;
9+
}
10+
auto tree = (TTree *)file.Get("o2sim");
11+
if (!tree)
12+
{
13+
std::cerr << "Cannot find tree 'o2sim' in file " << path << "\n";
14+
return 1;
15+
}
16+
// Get the MCTrack branch
17+
std::vector<o2::MCTrack> *tracks{};
18+
tree->SetBranchAddress("MCTrack", &tracks);
19+
// Check if processes with ID 42 are available
20+
const int processID = 42; // Performance test particle custom process ID
21+
int nEvents = tree->GetEntries();
22+
short int count_perf = 0;
23+
bool flag = false;
24+
for (int i = 0; i < nEvents; i++)
25+
{
26+
tree->GetEntry(i);
27+
int nTracks = tracks->size();
28+
count_perf = 0;
29+
for (auto &track : *tracks)
30+
{
31+
const auto &process = track.getProcess();
32+
if (process == processID)
33+
{
34+
flag = true;
35+
// No need to continue checking other tracks in the event
36+
break;
37+
}
38+
}
39+
if (flag == true)
40+
{
41+
count_perf++;
42+
flag = false;
43+
}
44+
}
45+
if (count_perf == 0)
46+
{
47+
std::cerr << "No performance test particles found in the events\n";
48+
return 1;
49+
} else if (count_perf > nEvents) {
50+
std::cerr << "More performance test flagged events than generated events\n";
51+
return 1;
52+
}
53+
file.Close();
54+
return 0;
55+
}

test/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Whenever an `ini` file is detedcted to be tested, a test macro is required to be
2424
```bash
2525
<name-of-ini-file>.C
2626
```
27-
Note, that `run_tests.sh` will automatically detect all generators used in an `ini`. For at least one generator defined in the `ini` file there must be a test. Each test is defined as a function in the `<name-of-ini-file>.C` macro. Assuming you want to test `External` and `Pythia8` generator, the macro should look like
27+
Note, that `run_tests.sh` will automatically detect all generators used in an `ini`. For at least one generator defined in the `ini` file there must be a test. Each test is defined as a function in the `<name-of-ini-file>.C` macro. Assuming you want to test `External`, `Pythia8` and `Hybrid` generators, the macro should look like
2828
```cpp
2929
int Pythia8()
3030
{
@@ -37,6 +37,12 @@ int External()
3737
// do your test
3838
return ret;
3939
}
40+
41+
int Hybrid()
42+
{
43+
// do your test
44+
return ret;
45+
}
4046
```
4147
The return type must be an integer, `0` in case of success and `!=0` in case of failure.
4248

test/run_generator_tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export ROOT_INCLUDE_PATH LD_LIBRARY_PATH
2121
# Entrypoint for O2DPG related tests #
2222
######################################
2323

24-
CHECK_GENERATORS="Pythia8 External"
24+
CHECK_GENERATORS="Pythia8 External Hybrid"
2525

2626
# The test parent dir to be cretaed in current directory
2727
TEST_PARENT_DIR="o2dpg_tests/generators"

0 commit comments

Comments
 (0)