Project
Loading...
Searching...
No Matches
testMCGenStatus.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 MCGenStatus class
13#define BOOST_TEST_MAIN
14#define BOOST_TEST_DYN_LINK
15#include <boost/test/unit_test.hpp>
20#include "TFile.h"
21#include "TParticle.h"
22
23using namespace o2;
24using namespace o2::mcgenstatus;
25
26BOOST_AUTO_TEST_CASE(MCGenStatus_test)
27{
28 // check basic properties
29 const int status{91};
30
31 // should not be flagged as encoded when the encoding is set
34
35 // check if everuthing correctly assigned
36 MCGenStatusEncoding enc2(status, -status);
38 BOOST_CHECK(enc2.hepmc == status);
39 BOOST_CHECK(enc2.gen == -status);
40
41 // check if helper functionality works as expected
42 BOOST_CHECK(getHepMCStatusCode(enc2) == status);
43 BOOST_CHECK(getGenStatusCode(enc2) == -status);
46
47 // check default constructed MCTrack object's status code
48 MCTrack track1;
50
51 // check MCTrack object constructed from TParticle (primary)
52 TParticle part2(22, MCGenStatusEncoding(status, -status).fullEncoding, 1, 2, 3, 4, 0.1, 0.1, 0.1, 0.1, 0, 0, 0, 0);
53 part2.SetBit(ParticleStatus::kPrimary);
54 MCTrack track2(part2);
55 BOOST_CHECK(getHepMCStatusCode(track2.getStatusCode()) == status);
56 BOOST_CHECK(getGenStatusCode(track2.getStatusCode()) == -status);
57
58 // make sure status codes survive serialising and deserialising
59 {
60 // serialize it
61 TFile f("MCGenStatusOut.root", "RECREATE");
62 f.WriteObject(&track2, "MCTrack");
63 f.Close();
64 }
65
66 {
67 MCTrack* intrack = nullptr;
68 TFile f("MCGenStatusOut.root", "OPEN");
69 f.GetObject("MCTrack", intrack);
70 BOOST_CHECK(getHepMCStatusCode(intrack->getStatusCode()) == status);
71 BOOST_CHECK(getGenStatusCode(intrack->getStatusCode()) == -status);
72 }
73
74 // check MCTrack object constructed from TParticle (secondary)
75 MCTrack track3(TParticle(22, MCGenStatusEncoding(status, -status).fullEncoding, 1, 2, 3, 4, 0.1, 0.1, 0.1, 0.1, 0, 0, 0, 0));
76 // both must now be -1 since not encoced and hence only number is returned
79
80 // do tests to check utility functionality
81 int thisHepMCCode{4};
82 TParticle part3(22, thisHepMCCode, 1, 2, 3, 4, 0.1, 0.1, 0.1, 0.1, 0, 0, 0, 0);
83 std::vector<bool> trueFalse{true, false};
84 for (auto value : trueFalse) {
85 auto status3 = part3.GetStatusCode();
88 status3 = part3.GetStatusCode();
90 BOOST_CHECK(getHepMCStatusCode(status3) == thisHepMCCode);
91 BOOST_CHECK(getGenStatusCode(status3) == 0);
93 }
94}
Definition of the MCTrack class.
Utility functions for MC particles.
@ kPrimary
@ kToBeDone
o2::mcgenstatus::MCGenStatusEncoding getStatusCode() const
get generator status code
Definition MCTrack.h:233
static void encodeParticleStatusAndTracking(TParticle &particle, bool wanttracking=true)
Definition MCUtils.cxx:211
GLdouble f
Definition glcorearb.h:310
GLsizei const GLfloat * value
Definition glcorearb.h:819
int getGenStatusCode(MCGenStatusEncoding enc)
int getHepMCStatusCode(MCGenStatusEncoding enc)
constexpr unsigned int isEncodedValue
bool isEncoded(MCGenStatusEncoding statusCode)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
BOOST_AUTO_TEST_CASE(FlatHisto)
BOOST_CHECK(tree)