Project
Loading...
Searching...
No Matches
test_GeneratorPythia8Param.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#define BOOST_TEST_MODULE Test GeneratorPythia8Param class
13#define BOOST_TEST_MAIN
14#define BOOST_TEST_DYN_LINK
15#include <boost/test/unit_test.hpp>
18#include <boost/property_tree/ptree.hpp>
21#include <iostream>
22#include <filesystem>
23#include <unistd.h>
24
25// Tests various aspects of the
26// ConfigurableParamPromoter class, which is used to promote
27// Pythia8GenConfig to a configurable param
28BOOST_AUTO_TEST_CASE(pythia8_Pythia8GenConfig)
29{
31 "GeneratorPythia8.config=Foo;GeneratorPythia8.includePartonEvent=true");
32
34
35 BOOST_CHECK_EQUAL(GeneratorPythia8Param::Instance().config, std::string("Foo"));
36 BOOST_CHECK_EQUAL(GeneratorPythia8Param::Instance().includePartonEvent, true);
37
38 BOOST_CHECK_EQUAL(GeneratorPythia8Param::Instance().includePartonEvent, o2::conf::ConfigurableParam::getValueAs<bool>("GeneratorPythia8.includePartonEvent"));
39 // setValue - getValue
40 o2::conf::ConfigurableParam::setValue("GeneratorPythia8.config", "Baz");
41 BOOST_CHECK_EQUAL(o2::conf::ConfigurableParam::getValueAs<std::string>("GeneratorPythia8.config"), std::string("Baz"));
42 BOOST_CHECK_EQUAL(GeneratorPythia8Param::Instance().config, std::string("Baz"));
43
44 // member provenance
45 BOOST_CHECK_EQUAL(GeneratorPythia8Param::Instance().getMemberProvenance("config"), o2::conf::ConfigurableParam::EParamProvenance::kRT);
46 BOOST_CHECK_EQUAL(GeneratorPythia8Param::Instance().getMemberProvenance("verbose"), o2::conf::ConfigurableParam::EParamProvenance::kCODE);
47
48 // config detach
49 auto config_copy = GeneratorPythia8Param::Instance().detach();
50 BOOST_CHECK_EQUAL(config_copy.config, std::string("Baz"));
51 BOOST_CHECK_EQUAL(config_copy.includePartonEvent, true);
52
53 // file IO
54 TFile tmp_file("GeneratorParamConfig_tmp.root", "RECREATE");
55
56 GeneratorPythia8Param::Instance().serializeTo(&tmp_file);
57 // modify the instance to some intermediate fluent value
58 o2::conf::ConfigurableParam::setValue("GeneratorPythia8.includePartonEvent", "0");
59 BOOST_CHECK_EQUAL(config_copy.includePartonEvent, true);
60 BOOST_CHECK_EQUAL(GeneratorPythia8Param::Instance().includePartonEvent, false);
61 tmp_file.Close();
62
63 // read back
64 TFile tmp_file2("GeneratorParamConfig_tmp.root", "READ");
65 const_cast<GeneratorPythia8Param&>(GeneratorPythia8Param::Instance()).initFrom(&tmp_file2);
66 BOOST_CHECK_EQUAL(GeneratorPythia8Param::Instance().includePartonEvent, true);
67 tmp_file2.Close();
68
69 // CCDB IO
70 std::string ccdbUrl = "http://ccdb-test.cern.ch:8080";
71 bool hostReachable = false;
73 api.init(ccdbUrl);
74 std::string pathA = "/Generators/UnitTest/Pythia8/GeneratorPythia8Param";
75 std::map<std::string, std::string> md;
76 long start = 1000, stop = 2000;
77 api.storeAsTFileAny(&GeneratorPythia8Param::Instance(), pathA, md, start, stop);
78
79 // modify the instance to some intermediate fluent value
80 o2::conf::ConfigurableParam::setValue("GeneratorPythia8.includePartonEvent", "0");
81
82 auto returnedobj = api.retrieveFromTFileAny<o2::eventgen::GeneratorPythia8Param>(pathA, md, (start + stop) / 2);
83 GeneratorPythia8Param::Instance().printKeyValues();
84};
85
86BOOST_AUTO_TEST_CASE(EventPool_Alien_Path)
87{
89 config.eventPoolPath = "alien:///alice/cern.ch/user/s/swenzel/selfjobs/evtpool_pythia8pp_test-20241126-152715";
91 auto files = gen.setupFileUniverse(config.eventPoolPath);
92 BOOST_CHECK(files.size() > 0);
93};
94
95BOOST_AUTO_TEST_CASE(EventPool_Alien_File)
96{
98 config.eventPoolPath = "alien:///alice/cern.ch/user/s/swenzel/selfjobs/evtpool_pythia8pp_test-20241126-152715/001/evtpool.root";
100 auto files = gen.setupFileUniverse(config.eventPoolPath);
101 BOOST_CHECK(files.size() == 1);
102};
103
104BOOST_AUTO_TEST_CASE(EventPool_Alien_WrongFileName)
105{
107 config.eventPoolPath = "alien:///foo_123";
109 auto files = gen.setupFileUniverse(config.eventPoolPath);
110 BOOST_CHECK(files.size() == 0);
111};
112
113BOOST_AUTO_TEST_CASE(EventPool_Local_Path)
114{
115 namespace fs = std::filesystem;
116
117 // we need to create some local tmp files that mimick the event pool
118 // this is a helper to do this
119 auto createPoolFiles = [](const fs::path& tmpDir, int numFiles) {
120 for (int i = 0; i < numFiles; ++i) {
121 // Generate a unique file name
122 fs::path fileDir = tmpDir / std::to_string(i);
124 fs::create_directory(fileDir);
125 // Create and close the file (touch)
126 std::ofstream file(filePath);
127 file.close();
128 }
129 };
130
131 // Seed for randomness
132 std::srand(static_cast<unsigned>(std::time(nullptr)));
133 // process id
134 auto proc = getpid();
135
136 // Create a random directory in the system temp directory
137 fs::path tmpDir = fs::temp_directory_path() / ("eventpool_test_" + std::to_string(proc) + "_" + std::to_string(std::rand()));
138 fs::create_directory(tmpDir);
139 constexpr int numfiles = 11;
140 createPoolFiles(tmpDir, numfiles);
141
143 config.eventPoolPath = tmpDir.string();
145 auto files = gen.setupFileUniverse(config.eventPoolPath);
146 BOOST_CHECK(files.size() == numfiles);
147
148 // remove the files
149 if (fs::exists(tmpDir)) {
150 fs::remove_all(tmpDir); // Remove all files and the directory
151 }
152};
153
154BOOST_AUTO_TEST_CASE(EventPool_Local_RootFile)
155{
156 namespace fs = std::filesystem;
157
158 // we need to create a fake local root file in the right format
159 // Seed for randomness
160 std::srand(static_cast<unsigned>(std::time(nullptr)));
161 // process id
162 auto proc = getpid();
163 // Create a random directory in the system temp directory
164 fs::path tmpDir = fs::temp_directory_path() / ("eventpool_testlocalrootfile_" + std::to_string(proc) + "_" + std::to_string(std::rand()));
165 //
167 fs::create_directory(tmpDir);
168 // Create and close the file (touch); needs to be a ROOT file so using TFile
169 TFile file(filePath.string().c_str(), "CREATE");
170 file.Close();
171
173 config.eventPoolPath = tmpDir.string() + "/evtpool.root";
175 auto files = gen.setupFileUniverse(config.eventPoolPath);
176 BOOST_CHECK(files.size() == 1);
177
178 // remove the files
179 if (fs::exists(tmpDir)) {
180 fs::remove_all(tmpDir); // Remove all files and the directory
181 }
182};
183
184BOOST_AUTO_TEST_CASE(EventPool_Local_ListFile)
185{
186 // test reading list of files from a (txt) file
187 // create this txt file on the fly
188
189 namespace fs = std::filesystem;
190
191 std::srand(static_cast<unsigned>(std::time(nullptr)));
192 // process id
193 auto proc = getpid();
194 // Create a random directory in the system temp directory
195 fs::path tmpDir = fs::temp_directory_path() / ("eventpool_testlocallistfile_" + std::to_string(proc) + "_" + std::to_string(std::rand()));
196 fs::create_directory(tmpDir);
197
198 std::ofstream file(tmpDir / std::string("filelist.txt"));
199
200 constexpr int numfiles = 11;
201 for (int i = 0; i < numfiles; ++i) {
202 // Generate a unique file name
203 fs::path filePath = fs::path(std::string("alien:///foo")) / std::to_string(i) / o2::eventgen::GeneratorFromEventPool::eventpool_filename;
204 file << filePath.string() << "\n";
205 }
206 file.close();
207
209 config.eventPoolPath = tmpDir.string() + std::string("/filelist.txt");
211 auto files = gen.setupFileUniverse(config.eventPoolPath);
212 BOOST_CHECK(files.size() == numfiles);
213
214 // remove the files
215 if (fs::exists(tmpDir)) {
216 fs::remove_all(tmpDir); // Remove all files and the directory
217 }
218};
219
220BOOST_AUTO_TEST_CASE(EventPool_Local_WrongPath)
221{
223 config.eventPoolPath = "/tmp/MyEvtPool/filelist_DOESNOTEXIST.txt";
225 auto files = gen.setupFileUniverse(config.eventPoolPath);
226 BOOST_CHECK(files.size() == 0);
227};
default_random_engine gen(dev())
int32_t i
configStandalone Light OpenGL display display_light Apply smoothing to points Enable Z buffer Highlight links Highlight seeds Highlight sector tracks Highlight final tracks Show individual Show related Highlight grid Show only individual collision Color clusters belonging to track objects Set line Enable drawing TPC data Enable drawing TOF data Enable drawing magnetic field Set field line step count Invert colors configStandalone Heavy OpenGL display display_heavy Show tracks with ITS contribution Show tracks with TOF contribution Enable propagation of loopers Show clusters at nominal x of pad row for early transformed data Split CE tracks when they cross the central Mark clusters Mark adjacent clusters Hide rejected tracks Apply filter on tracks to be displayed Separate increase X h configStandalone Camera window renderer OpenGL display display_camera Orient the camera such that the y axis is always upwards Full Screen MultiSample Anti Downsampling Anti Enable Vertical Sync Target frame or if the backend cannot limit to the refresh Use OpenGL indirect draws to reduce number of draw calls Display h configStandalone Vulkan display display_vulkan Have uniform buffers in host accessible device memory h configStandalone Internal display display_internal Number of updates the Qt GUI may send ahead of the last one the display has before it waits for the display Opacity of the console background Number of console lines the history is shortened to this when it reaches twice the size Time in seconds an info message fades out after setInfoTime h OpenGL display display Font size Do not use Freetype for font Renderer for event Frontend to use for event ROOT macros used as track filter Console script file
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h configStandalone Reconstruction rec_trd Max chi2 for TRD tracklets to be matched to a track Chi2 cut for strict matching mode Number of sigmas for ITS TPC track time error estimate Addition to search road around track prolongation along Y in cm Optimal tracklet rphi resolution in maximum chi2 per attached tracklet for TRD tracks take into account the full likelihood of the slope including exponential tails Tracks with less attached tracklets are discarded after the tracking Post trigger Pile up integration time in BCs fits all iterations but the last one in projections Use material lookup table for TPC refit Apply workarounds to avoid cyclic merge should not be needed tpc dyn configStandalone proc
int storeAsTFileAny(const T *obj, std::string const &path, std::map< std::string, std::string > const &metadata, long startValidityTimestamp=-1, long endValidityTimestamp=-1, std::vector< char >::size_type maxSize=0) const
Definition CcdbApi.h:163
void init(std::string const &hosts)
Definition CcdbApi.cxx:240
std::enable_if<!std::is_base_of< o2::conf::ConfigurableParam, T >::value, T * >::type retrieveFromTFileAny(std::string const &path, std::map< std::string, std::string > const &metadata, long timestamp=-1, std::map< std::string, std::string > *headers=nullptr, std::string const &etag="", const std::string &createdNotAfter="", const std::string &createdNotBefore="") const
Definition CcdbApi.h:662
static void setValue(std::string const &mainkey, std::string const &subkey, T x)
static void updateFromString(std::string const &)
static constexpr std::string_view eventpool_filename
GLuint pathA
Definition glcorearb.h:5477
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
std::string ccdbUrl
bool hostReachable
BOOST_AUTO_TEST_CASE(pythia8_Pythia8GenConfig)
BOOST_CHECK(tree)
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())