1
/* This file is part of MAUS: http://micewww.pp.rl.ac.uk:8080/projects/maus
3
* MAUS is free software: you can redistribute it and/or modify
4
* it under the terms of the GNU General Public License as published by
5
* the Free Software Foundation, either version 3 of the License, or
6
* (at your option) any later version.
8
* MAUS is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with MAUS. If not, see <http://www.gnu.org/licenses/>.
27
#include "TLorentzVector.h"
30
#include "gtest/gtest.h"
32
#include "Recon/Global/PIDVarA.hh"
36
TEST(PIDVarATestSetUp, TestSetUpAndTearDown) {
37
MAUS::recon::global::PIDVarA *testPIDVarA = NULL;
38
ASSERT_NO_THROW(testPIDVarA = new MAUS::recon::global::PIDVarA("test",
40
std::string testfile = testPIDVarA->Get_filename();
41
std::string testdir = testPIDVarA->Get_directory();
42
ASSERT_NO_THROW(delete testPIDVarA);
44
EXPECT_EQ(gSystem->Unlink(testfile.c_str()), 0);
45
EXPECT_EQ(gSystem->Unlink(testdir.c_str()), 0);
48
class PIDVarATest : public ::testing::Test {
50
virtual void SetUp() {
51
MAUS::recon::global::PIDVarA testPIDVarA("test", "test");
52
testfile = testPIDVarA.Get_filename();
53
testdir = testPIDVarA.Get_directory();
55
for (int i = 0; i < 1000; i++) {
56
MAUS::DataStructure::Global::Track* testTrack =
57
new MAUS::DataStructure::Global::Track();
58
MAUS::DataStructure::Global::TrackPoint* tp0 =
59
new MAUS::DataStructure::Global::TrackPoint();
60
MAUS::DataStructure::Global::TrackPoint* tp1 =
61
new MAUS::DataStructure::Global::TrackPoint();
62
tp0->set_detector(MAUS::DataStructure::Global::kTOF0_1);
63
tp1->set_detector(MAUS::DataStructure::Global::kTOF1_1);
68
double t0 = r.Gaus(15, 2);
69
TLorentzVector pos0(x0, y0, z0, t0);
74
double t1 = r.Gaus(45, 2);
75
TLorentzVector pos1(x1, y1, z1, t1);
77
tp0->set_position(pos0);
78
tp1->set_position(pos1);
79
testTrack->AddTrackPoint(tp0);
80
testTrack->AddTrackPoint(tp1);
81
testTracks.push_back(testTrack);
85
virtual void TearDown() {
86
gSystem->Unlink(testfile.c_str());
87
gSystem->Unlink(testdir.c_str());
91
bool fileExists(std::string filename) {
92
TFile f(filename.c_str(), "READ");
96
bool IsFiniteNumber(double x) {
97
return (x <= DBL_MAX && x >= -DBL_MAX);
100
std::string testfile;
104
std::string histname;
105
std::vector<MAUS::DataStructure::Global::Track*> testTracks;
108
TEST_F(PIDVarATest, CreateFileConstructor) {
110
ASSERT_TRUE(fileExists(testfile));
113
TEST_F(PIDVarATest, ReadFileConstructor) {
115
file = new TFile(testfile.c_str(), "READ");
119
ASSERT_FALSE(file->IsZombie());
121
ASSERT_NO_THROW(MAUS::recon::global::PIDVarA testPIDVarA(file, "test"));
123
ASSERT_ANY_THROW(MAUS::recon::global::PIDVarA testPIDVarA(NULL, "test"));
125
ASSERT_ANY_THROW(MAUS::recon::global::PIDVarA testPIDVarA(file, "sasquatch"));
128
/* N.B. if either FillHist or LogL are failing, check the values of min and max
129
* bin in PIDVarA.hh, as if the testTracks fall outside of this range FillHist
130
* and LogL will fail.
133
TEST_F(PIDVarATest, FillHist) {
135
MAUS::recon::global::PIDVarA testPIDVarA("test", "test");
136
for (int i = 0; i < 1000; i++) {
137
testPIDVarA.Fill_TH1(testTracks[i]);
139
testfile = testPIDVarA.Get_filename();
140
testdir = testPIDVarA.Get_directory();
141
// check histogram exists
142
hist = testPIDVarA.Get_hist();
144
// check number of entries
145
ASSERT_EQ(1000, hist->GetEntries());
148
TEST_F(PIDVarATest, LogL) {
149
// Constructor called within parentheses so that destructor will be
150
// called when it goes out of scope
152
MAUS::recon::global::PIDVarA writetestPIDVarA("test", "test");
153
for (int i = 0; i < 1000; i++) {
154
writetestPIDVarA.Fill_TH1(testTracks[i]);
156
testfile = writetestPIDVarA.Get_filename();
157
testdir = writetestPIDVarA.Get_directory();
160
MAUS::DataStructure::Global::Track* checkTrack =
161
new MAUS::DataStructure::Global::Track();
162
MAUS::DataStructure::Global::TrackPoint* ctp0 =
163
new MAUS::DataStructure::Global::TrackPoint();
164
MAUS::DataStructure::Global::TrackPoint* ctp1 =
165
new MAUS::DataStructure::Global::TrackPoint();
166
ctp0->set_detector(MAUS::DataStructure::Global::kTOF0_1);
167
ctp1->set_detector(MAUS::DataStructure::Global::kTOF1_1);
173
TLorentzVector cpos0(x0, y0, z0, t0);
179
TLorentzVector cpos1(x1, y1, z1, t1);
181
ctp0->set_position(cpos0);
182
ctp1->set_position(cpos1);
183
checkTrack->AddTrackPoint(ctp0);
184
checkTrack->AddTrackPoint(ctp1);
186
file = new TFile(testfile.c_str(), "READ");
190
ASSERT_FALSE(file->IsZombie());
192
ASSERT_NO_THROW(MAUS::recon::global::PIDVarA readtestPIDVarA(file, "test"));
194
MAUS::recon::global::PIDVarA readtestPIDVarA(file, "test");
196
hist = readtestPIDVarA.Get_hist();
198
// check number of entries in histogram
199
// NB as destructor was called above, the number of entries in the histogram
200
// will be increased by the number of bins (inc over and underflow) as in
201
// PIDVarA the behaviour to add one event across all bins is turned on.
202
ASSERT_EQ((1000 + hist->GetSize()), hist->GetEntries());
203
double prob = readtestPIDVarA.logL(checkTrack);
206
ASSERT_TRUE(IsFiniteNumber(prob));