diff --git a/MC/config/common/ini/GeneratorPerformance.ini b/MC/config/common/ini/GeneratorPerformance.ini new file mode 100644 index 000000000..c4a4efb03 --- /dev/null +++ b/MC/config/common/ini/GeneratorPerformance.ini @@ -0,0 +1,4 @@ +# Performance generator test using hybrid configuration with Pythia8 +# underlying event generator +[GeneratorHybrid] +configFile = ${O2DPG_MC_CONFIG_ROOT}/MC/config/common/external/generator/perfConf.json diff --git a/MC/config/common/ini/tests/GeneratorPerformance.C b/MC/config/common/ini/tests/GeneratorPerformance.C new file mode 100644 index 000000000..c34ca7c5d --- /dev/null +++ b/MC/config/common/ini/tests/GeneratorPerformance.C @@ -0,0 +1,55 @@ +int Hybrid() +{ + std::string path{"o2sim_Kine.root"}; + TFile file(path.c_str(), "READ"); + if (file.IsZombie()) + { + std::cerr << "Cannot open ROOT file " << path << "\n"; + return 1; + } + auto tree = (TTree *)file.Get("o2sim"); + if (!tree) + { + std::cerr << "Cannot find tree 'o2sim' in file " << path << "\n"; + return 1; + } + // Get the MCTrack branch + std::vector *tracks{}; + tree->SetBranchAddress("MCTrack", &tracks); + // Check if processes with ID 42 are available + const int processID = 42; // Performance test particle custom process ID + int nEvents = tree->GetEntries(); + short int count_perf = 0; + bool flag = false; + for (int i = 0; i < nEvents; i++) + { + tree->GetEntry(i); + int nTracks = tracks->size(); + count_perf = 0; + for (auto &track : *tracks) + { + const auto &process = track.getProcess(); + if (process == processID) + { + flag = true; + // No need to continue checking other tracks in the event + break; + } + } + if (flag == true) + { + count_perf++; + flag = false; + } + } + if (count_perf == 0) + { + std::cerr << "No performance test particles found in the events\n"; + return 1; + } else if (count_perf > nEvents) { + std::cerr << "More performance test flagged events than generated events\n"; + return 1; + } + file.Close(); + return 0; +} \ No newline at end of file diff --git a/test/README.md b/test/README.md index 3c2a90d47..5f34eb20d 100644 --- a/test/README.md +++ b/test/README.md @@ -24,7 +24,7 @@ Whenever an `ini` file is detedcted to be tested, a test macro is required to be ```bash .C ``` -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 `.C` macro. Assuming you want to test `External` and `Pythia8` generator, the macro should look like +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 `.C` macro. Assuming you want to test `External`, `Pythia8` and `Hybrid` generators, the macro should look like ```cpp int Pythia8() { @@ -37,6 +37,12 @@ int External() // do your test return ret; } + +int Hybrid() +{ + // do your test + return ret; +} ``` The return type must be an integer, `0` in case of success and `!=0` in case of failure. diff --git a/test/run_generator_tests.sh b/test/run_generator_tests.sh index 6c5f3b8b8..dc021cbe5 100755 --- a/test/run_generator_tests.sh +++ b/test/run_generator_tests.sh @@ -21,7 +21,7 @@ export ROOT_INCLUDE_PATH LD_LIBRARY_PATH # Entrypoint for O2DPG related tests # ###################################### -CHECK_GENERATORS="Pythia8 External" +CHECK_GENERATORS="Pythia8 External Hybrid" # The test parent dir to be cretaed in current directory TEST_PARENT_DIR="o2dpg_tests/generators"