|
| 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> |
| 16 | +#include <Generators/GeneratorService.h> |
| 17 | +#include <SimulationDataFormat/MCTrack.h> |
| 18 | +#include <SimulationDataFormat/MCEventHeader.h> |
| 19 | +#include <SimulationDataFormat/MCGenProperties.h> |
| 20 | +#include <CommonUtils/ConfigurableParam.h> |
| 21 | +#include <cmath> |
| 22 | +#include <cstdlib> |
| 23 | +#include <fstream> |
| 24 | +#include <string> |
| 25 | +#include <unistd.h> |
| 26 | + |
| 27 | +using namespace o2::eventgen; |
| 28 | + |
| 29 | +namespace |
| 30 | +{ |
| 31 | +// forces Xic+ -> Xi(1530)0 pi+ with the Geant4 lifetime |
| 32 | +const std::string FORCE = "4232:mayDecay = on\n4232:onMode = off\n4232:oneChannel = 1 1.0 0 3324 211\n4232:tau0 = 0.1358\n"; |
| 33 | + |
| 34 | +std::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 |
| 45 | +std::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 | + |
| 56 | +BOOST_AUTO_TEST_CASE(decay_step_on) |
| 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()); |
| 66 | + BOOST_CHECK_EQUAL(o2::mcgenstatus::getHepMCStatusCode(t.getStatusCode()), 2); |
| 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); |
| 87 | + BOOST_CHECK(valid); |
| 88 | + BOOST_CHECK(summary.find("pythia8/decays/base.cfg") != std::string::npos); |
| 89 | +} |
| 90 | + |
| 91 | +BOOST_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 | +} |
0 commit comments