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/PIDVarF.hh"
36
TEST(PIDVarFTestSetUp, TestSetUpAndTearDown) {
37
MAUS::recon::global::PIDVarF *testPIDVarF = NULL;
38
ASSERT_NO_THROW(testPIDVarF = new MAUS::recon::global::PIDVarF("test",
40
std::string testfile = testPIDVarF->Get_filename();
41
std::string testdir = testPIDVarF->Get_directory();
42
ASSERT_NO_THROW(delete testPIDVarF);
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 PIDVarFTest : public ::testing::Test {
55
virtual void SetUp() {
56
MAUS::recon::global::PIDVarF testPIDVarF("test", "test");
57
testfile = testPIDVarF.Get_filename();
58
testdir = testPIDVarF.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* tpTracker =
64
new MAUS::DataStructure::Global::TrackPoint();
65
tpTracker->set_detector(MAUS::DataStructure::Global::kTracker1_1);
66
MAUS::DataStructure::Global::TrackPoint* tpEMR =
67
new MAUS::DataStructure::Global::TrackPoint();
69
double emr_range = r.Gaus(50, 10);
70
testTrack->set_emr_range_primary(emr_range);
76
TLorentzVector tpTrackerMom(px, py, pz, E);
78
tpTracker->set_momentum(tpTrackerMom);
79
tpTracker->set_mapper_name("MapCppGlobalTrackMatching-Through");
80
testTrack->AddTrackPoint(tpTracker);
81
tpEMR->set_mapper_name("MapCppGlobalTrackMatching-Through");
82
tpEMR->set_detector(MAUS::DataStructure::Global::kEMR);
83
testTrack->AddTrackPoint(tpEMR);
84
testTrack->set_mapper_name("MapCppGlobalTrackMatching-Through");
85
testTracks.push_back(testTrack);
89
virtual void TearDown() {
90
gSystem->Unlink(testfile.c_str());
91
gSystem->Unlink(testdir.c_str());
95
bool fileExists(std::string filename) {
96
TFile f(filename.c_str(), "READ");
100
bool IsFiniteNumber(double x) {
101
return (x <= DBL_MAX && x >= -DBL_MAX);
104
std::string testfile;
108
std::string histname;
109
std::vector<MAUS::DataStructure::Global::Track*> testTracks;
112
TEST_F(PIDVarFTest, CreateFileConstructor) {
114
ASSERT_TRUE(fileExists(testfile));
117
TEST_F(PIDVarFTest, ReadFileConstructor) {
119
file = new TFile(testfile.c_str(), "READ");
123
ASSERT_FALSE(file->IsZombie());
125
ASSERT_NO_THROW(MAUS::recon::global::PIDVarF testPIDVarF(file, "test", 50, 350, 0, 1000));
127
ASSERT_ANY_THROW(MAUS::recon::global::PIDVarF testPIDVarF(NULL, "test", 50, 350, 0, 1000));
129
ASSERT_ANY_THROW(MAUS::recon::global::PIDVarF testPIDVarF(file, "sasquatch", 50, 350, 0, 1000));
132
/* N.B. if either FillHist or LogL are failing, check the values of min and max
133
* bins in PIDVarF.hh, as if the testTracks fall outside of this range FillHist
134
* and LogL will fail.
137
TEST_F(PIDVarFTest, FillHist) {
139
MAUS::recon::global::PIDVarF testPIDVarF("test", "test");
140
for (int i = 0; i < 1000; i++) {
141
testPIDVarF.Fill_Hist(testTracks[i]);
143
testfile = testPIDVarF.Get_filename();
144
testdir = testPIDVarF.Get_directory();
145
// check histogram exists
146
hist = testPIDVarF.Get_hist();
148
// check number of entries
149
ASSERT_EQ(1000, hist->GetEntries());
152
TEST_F(PIDVarFTest, LogL) {
153
// Constructor called within parentheses so that destructor will be
154
// called when it goes out of scope
156
MAUS::recon::global::PIDVarF writetestPIDVarF("test", "test");
157
for (int i = 0; i < 1000; i++) {
158
writetestPIDVarF.Fill_Hist(testTracks[i]);
160
testfile = writetestPIDVarF.Get_filename();
161
testdir = writetestPIDVarF.Get_directory();
164
MAUS::DataStructure::Global::Track* checkTrack =
165
new MAUS::DataStructure::Global::Track();
166
MAUS::DataStructure::Global::TrackPoint* ctpTracker =
167
new MAUS::DataStructure::Global::TrackPoint();
168
ctpTracker->set_detector(MAUS::DataStructure::Global::kTracker1_1);
174
TLorentzVector ctpTrackerMom(px, py, pz, E);
176
ctpTracker->set_momentum(ctpTrackerMom);
177
MAUS::DataStructure::Global::TrackPoint* ctpEMR =
178
new MAUS::DataStructure::Global::TrackPoint();
179
ctpEMR->set_detector(MAUS::DataStructure::Global::kCalorimeter);
181
double emr_range = 50;
182
checkTrack->set_emr_range_primary(emr_range);
183
ctpEMR->set_detector(MAUS::DataStructure::Global::kEMR);
184
ctpEMR->set_mapper_name("MapCppGlobalTrackMatching-Through");
185
checkTrack->AddTrackPoint(ctpEMR);
186
ctpTracker->set_mapper_name("MapCppGlobalTrackMatching-Through");
187
checkTrack->AddTrackPoint(ctpTracker);
188
checkTrack->set_mapper_name("MapCppGlobalTrackMatching-Through");
190
file = new TFile(testfile.c_str(), "READ");
194
ASSERT_FALSE(file->IsZombie());
196
ASSERT_NO_THROW(MAUS::recon::global::PIDVarF readtestPIDVarF(file, "test", 50, 350, 0, 1000));
198
MAUS::recon::global::PIDVarF readtestPIDVarF(file, "test", 50, 350, 0, 1000);
200
hist = readtestPIDVarF.Get_hist();
202
// check number of entries in histogram
203
// NB as destructor was called above, the number of entries in the histogram
204
// will be increased by the number of bins (inc over and underflow) as in
205
// PIDVarF the behaviour to add one event across all bins is turned on.
206
ASSERT_EQ((1000 + hist->GetSize()), hist->GetEntries());
207
double prob = readtestPIDVarF.logL(checkTrack);
210
ASSERT_TRUE(IsFiniteNumber(prob));