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/ComPIDVarD.hh"
36
TEST(ComPIDVarDTestSetUp, TestSetUpAndTearDown) {
37
MAUS::recon::global::ComPIDVarD *testComPIDVarD = NULL;
38
ASSERT_NO_THROW(testComPIDVarD = new MAUS::recon::global::ComPIDVarD("test",
40
std::string testfile = testComPIDVarD->Get_filename();
41
std::string testdir = testComPIDVarD->Get_directory();
42
ASSERT_NO_THROW(delete testComPIDVarD);
44
EXPECT_EQ(gSystem->Unlink(testfile.c_str()), 0);
45
// Unlink dir does not seem to work on some systems
46
// suspect NFS mounts or stale handles
47
// force system removal
48
// std::string rmdirCmd = "rm -fr ";
49
// rmdirCmd += testdir.c_str();
50
// EXPECT_EQ(system(rmdirCmd.c_str()), 0);
53
class ComPIDVarDTest : public ::testing::Test {
55
virtual void SetUp() {
56
MAUS::recon::global::ComPIDVarD testComPIDVarD("test", "test");
57
testfile = testComPIDVarD.Get_filename();
58
testdir = testComPIDVarD.Get_directory();
60
for (int i = 0; i < 1000; i++) {
61
MAUS::DataStructure::Global::Track* testTrack =
62
new MAUS::DataStructure::Global::Track();
63
MAUS::DataStructure::Global::TrackPoint* tpEMR =
64
new MAUS::DataStructure::Global::TrackPoint();
66
double emr_range = r.Gaus(50, 10);
67
testTrack->set_emr_range_primary(emr_range);
69
tpEMR->set_mapper_name("MapCppGlobalTrackMatching-Through");
70
tpEMR->set_detector(MAUS::DataStructure::Global::kEMR);
71
testTrack->AddTrackPoint(tpEMR);
72
testTrack->set_mapper_name("MapCppGlobalTrackMatching-Through");
73
testTracks.push_back(testTrack);
77
virtual void TearDown() {
78
gSystem->Unlink(testfile.c_str());
79
gSystem->Unlink(testdir.c_str());
83
bool fileExists(std::string filename) {
84
TFile f(filename.c_str(), "READ");
88
bool IsFiniteNumber(double x) {
89
return (x <= DBL_MAX && x >= -DBL_MAX);
97
std::vector<MAUS::DataStructure::Global::Track*> testTracks;
100
TEST_F(ComPIDVarDTest, CreateFileConstructor) {
102
ASSERT_TRUE(fileExists(testfile));
105
TEST_F(ComPIDVarDTest, ReadFileConstructor) {
107
file = new TFile(testfile.c_str(), "READ");
111
ASSERT_FALSE(file->IsZombie());
113
ASSERT_NO_THROW(MAUS::recon::global::ComPIDVarD testComPIDVarD(file, "test", 0, 8000));
115
ASSERT_ANY_THROW(MAUS::recon::global::ComPIDVarD testComPIDVarD(NULL, "test", 0, 8000));
117
ASSERT_ANY_THROW(MAUS::recon::global::ComPIDVarD testComPIDVarD(file, "sasquatch", 0, 8000));
120
/* N.B. if either FillHist or LogL are failing, check the values of min and max
121
* bins in ComPIDVarD.hh, as if the testTracks fall outside of this range FillHist
122
* and LogL will fail.
125
TEST_F(ComPIDVarDTest, FillHist) {
127
MAUS::recon::global::ComPIDVarD testComPIDVarD("test", "test");
128
for (int i = 0; i < 1000; i++) {
129
testComPIDVarD.Fill_Hist(testTracks[i]);
131
testfile = testComPIDVarD.Get_filename();
132
testdir = testComPIDVarD.Get_directory();
133
// check histogram exists
134
hist = testComPIDVarD.Get_hist();
136
// check number of entries
137
ASSERT_EQ(1000, hist->GetEntries());
140
TEST_F(ComPIDVarDTest, LogL) {
141
// Constructor called within parentheses so that destructor will be
142
// called when it goes out of scope
144
MAUS::recon::global::ComPIDVarD writetestComPIDVarD("test", "test");
145
for (int i = 0; i < 1000; i++) {
146
writetestComPIDVarD.Fill_Hist(testTracks[i]);
148
testfile = writetestComPIDVarD.Get_filename();
149
testdir = writetestComPIDVarD.Get_directory();
152
MAUS::DataStructure::Global::Track* checkTrack =
153
new MAUS::DataStructure::Global::Track();
154
MAUS::DataStructure::Global::TrackPoint* ctpEMR =
155
new MAUS::DataStructure::Global::TrackPoint();
156
ctpEMR->set_detector(MAUS::DataStructure::Global::kCalorimeter);
158
double emr_range = 50;
159
checkTrack->set_emr_range_primary(emr_range);
160
ctpEMR->set_detector(MAUS::DataStructure::Global::kEMR);
161
ctpEMR->set_mapper_name("MapCppGlobalTrackMatching-Through");
162
checkTrack->AddTrackPoint(ctpEMR);
163
checkTrack->set_mapper_name("MapCppGlobalTrackMatching-Through");
165
file = new TFile(testfile.c_str(), "READ");
169
ASSERT_FALSE(file->IsZombie());
171
ASSERT_NO_THROW(MAUS::recon::global::ComPIDVarD readtestComPIDVarD(file, "test", 0, 1000));
173
MAUS::recon::global::ComPIDVarD readtestComPIDVarD(file, "test", 0, 1000);
175
hist = readtestComPIDVarD.Get_hist();
177
// check number of entries in histogram
178
// NB as destructor was called above, the number of entries in the histogram
179
// will be increased by the number of bins (inc over and underflow) as in
180
// ComPIDVarD the behaviour to add one event across all bins is turned on.
181
ASSERT_EQ((1000 + hist->GetSize()), hist->GetEntries());
182
double prob = readtestComPIDVarD.logL(checkTrack);
185
ASSERT_TRUE(IsFiniteNumber(prob));