Project
Loading...
Searching...
No Matches
test_GeneratorEventDecayer.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 decay step of Generator
13#define BOOST_TEST_MAIN
14#define BOOST_TEST_DYN_LINK
15#include <boost/test/unit_test.hpp>
21#include <cmath>
22#include <cstdlib>
23#include <fstream>
24#include <string>
25#include <unistd.h>
26
27using namespace o2::eventgen;
28
29namespace
30{
31// forces Xic+ -> Xi(1530)0 pi+ with the Geant4 lifetime
32const std::string FORCE = "4232:mayDecay = on\n4232:onMode = off\n4232:oneChannel = 1 1.0 0 3324 211\n4232:tau0 = 0.1358\n";
33
34std::string writeCfg(std::string const& text)
35{
36 char name[] = "/tmp/test_GeneratorEventDecayer_XXXXXX";
37 int fd = mkstemp(name);
38 close(fd);
39 std::ofstream out(name);
40 out << text;
41 return name;
42}
43
44// generates one boxgen event of five Xic+ with the decay step on or off
45std::pair<std::vector<o2::MCTrack>, o2::dataformats::MCEventHeader> generate(bool enable)
46{
47 static const std::string forcePath = writeCfg(FORCE);
48 o2::conf::ConfigurableParam::updateFromString("BoxGun.pdg=4232;BoxGun.number=5;EventDecayer.config[1]=" + forcePath +
49 ";EventDecayer.enable=" + (enable ? "true" : "false"));
50 GeneratorService service;
51 service.initService("boxgen", "", o2::eventgen::NoVertexOption());
52 return service.generateEvent();
53}
54} // namespace
55
57{
58 auto [tracks, header] = generate(true);
59 int nXic = 0;
60 int nXiStar = 0;
61 for (int i = 0; i < (int)tracks.size(); ++i) {
62 auto const& t = tracks[i];
63 if (t.GetPdgCode() == 4232) {
64 ++nXic;
65 BOOST_CHECK(!t.getToBeDone());
67 }
68 if (t.GetPdgCode() == 3324) {
69 ++nXiStar;
70 int m = t.getMotherTrackId();
71 BOOST_REQUIRE(m >= 0 && m < (int)tracks.size());
72 BOOST_CHECK_EQUAL(tracks[m].GetPdgCode(), 4232);
73 BOOST_CHECK(!t.getToBeDone());
74 // the Xic+ decay point in cm, displaced from the origin by about its decay length
75 double r = std::sqrt(t.Vx() * t.Vx() + t.Vy() * t.Vy() + t.Vz() * t.Vz());
76 BOOST_CHECK(r > 0. && r < 10.);
77 for (int d = t.getFirstDaughterTrackId(); d >= 0 && d <= t.getLastDaughterTrackId(); ++d) {
78 BOOST_CHECK_EQUAL(tracks[d].getMotherTrackId(), i);
79 BOOST_CHECK(tracks[d].getToBeDone());
80 }
81 }
82 }
83 BOOST_CHECK_EQUAL(nXic, 5);
84 BOOST_CHECK_EQUAL(nXiStar, 5);
85 bool valid = false;
86 auto summary = header.getInfo<std::string>("eventDecayer", valid);
88 BOOST_CHECK(summary.find("pythia8/decays/base.cfg") != std::string::npos);
89}
90
91BOOST_AUTO_TEST_CASE(decay_step_off)
92{
93 auto [tracks, header] = generate(false);
94 BOOST_REQUIRE_EQUAL(tracks.size(), 5);
95 for (auto const& t : tracks) {
96 BOOST_CHECK_EQUAL(t.GetPdgCode(), 4232);
97 BOOST_CHECK(t.getToBeDone());
98 BOOST_CHECK_EQUAL(t.getFirstDaughterTrackId(), -1);
99 }
100 BOOST_CHECK(!header.hasInfo("eventDecayer"));
101}
std::vector< std::string > header
int32_t i
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events d
std::vector< o2::its::TrackITS > tracks
Definition of the MCTrack class.
bool valid
static void updateFromString(std::string const &)
A class offering convenient generator configuration and encapsulation of lower level classes....
std::pair< std::vector< MCTrack >, o2::dataformats::MCEventHeader > generateEvent()
void initService(std::string const &generatorName, std::string const &triggerName, VertexOption const &vtxOption)
const GLfloat * m
Definition glcorearb.h:4066
GLuint const GLchar * name
Definition glcorearb.h:781
int getHepMCStatusCode(MCGenStatusEncoding enc)
BOOST_AUTO_TEST_CASE(decay_step_on)
BOOST_CHECK(tree)
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())