-
Notifications
You must be signed in to change notification settings - Fork 496
Expand file tree
/
Copy pathtestMCGenStatus.cxx
More file actions
94 lines (82 loc) · 3.71 KB
/
testMCGenStatus.cxx
File metadata and controls
94 lines (82 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#define BOOST_TEST_MODULE Test MCGenStatus class
#define BOOST_TEST_MAIN
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include "SimulationDataFormat/MCTrack.h"
#include "SimulationDataFormat/ParticleStatus.h"
#include "SimulationDataFormat/MCGenProperties.h"
#include "SimulationDataFormat/MCUtils.h"
#include "TFile.h"
#include "TParticle.h"
using namespace o2;
using namespace o2::mcgenstatus;
BOOST_AUTO_TEST_CASE(MCGenStatus_test)
{
// check basic properties
const int status{91};
// should not be flagged as encoded when the encoding is set
MCGenStatusEncoding enc1(isEncodedValue);
BOOST_CHECK(enc1.isEncoded != isEncodedValue);
// check if everuthing correctly assigned
MCGenStatusEncoding enc2(status, -status);
BOOST_CHECK(enc2.isEncoded == isEncodedValue);
BOOST_CHECK(enc2.hepmc == status);
BOOST_CHECK(enc2.gen == -status);
// check if helper functionality works as expected
BOOST_CHECK(getHepMCStatusCode(enc2) == status);
BOOST_CHECK(getGenStatusCode(enc2) == -status);
BOOST_CHECK(getHepMCStatusCode(enc2) == getHepMCStatusCode(enc2.fullEncoding));
BOOST_CHECK(getGenStatusCode(enc2) == getGenStatusCode(enc2.fullEncoding));
// check default constructed MCTrack object's status code
MCTrack track1;
BOOST_CHECK(track1.getStatusCode().fullEncoding == 0);
// check MCTrack object constructed from TParticle (primary)
TParticle part2(22, MCGenStatusEncoding(status, -status).fullEncoding, 1, 2, 3, 4, 0.1, 0.1, 0.1, 0.1, 0, 0, 0, 0);
part2.SetBit(ParticleStatus::kPrimary);
MCTrack track2(part2);
BOOST_CHECK(getHepMCStatusCode(track2.getStatusCode()) == status);
BOOST_CHECK(getGenStatusCode(track2.getStatusCode()) == -status);
// make sure status codes survive serialising and deserialising
{
// serialize it
TFile f("MCGenStatusOut.root", "RECREATE");
f.WriteObject(&track2, "MCTrack");
f.Close();
}
{
MCTrack* intrack = nullptr;
TFile f("MCGenStatusOut.root", "OPEN");
f.GetObject("MCTrack", intrack);
BOOST_CHECK(getHepMCStatusCode(intrack->getStatusCode()) == status);
BOOST_CHECK(getGenStatusCode(intrack->getStatusCode()) == -status);
}
// check MCTrack object constructed from TParticle (secondary)
MCTrack track3(TParticle(22, MCGenStatusEncoding(status, -status).fullEncoding, 1, 2, 3, 4, 0.1, 0.1, 0.1, 0.1, 0, 0, 0, 0));
// both must now be -1 since not encoced and hence only number is returned
BOOST_CHECK(getHepMCStatusCode(track3.getStatusCode()) == -1);
BOOST_CHECK(getGenStatusCode(track3.getStatusCode()) == -1);
// do tests to check utility functionality
int thisHepMCCode{4};
TParticle part3(22, thisHepMCCode, 1, 2, 3, 4, 0.1, 0.1, 0.1, 0.1, 0, 0, 0, 0);
std::vector<bool> trueFalse{true, false};
for (auto value : trueFalse) {
auto status3 = part3.GetStatusCode();
BOOST_CHECK(mcgenstatus::isEncoded(status3) != value);
mcutils::MCGenHelper::encodeParticleStatusAndTracking(part3, value);
status3 = part3.GetStatusCode();
BOOST_CHECK(mcgenstatus::isEncoded(status3));
BOOST_CHECK(getHepMCStatusCode(status3) == thisHepMCCode);
BOOST_CHECK(getGenStatusCode(status3) == 0);
BOOST_CHECK(part3.TestBit(ParticleStatus::kToBeDone) == value);
}
}