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/ComPIDVarG.hh"
36
TEST(ComPIDVarGTestSetUp, TestSetUpAndTearDown) {
37
MAUS::recon::global::ComPIDVarG *testComPIDVarG = NULL;
38
ASSERT_NO_THROW(testComPIDVarG = new MAUS::recon::global::ComPIDVarG("test",
40
std::string testfile = testComPIDVarG->Get_filename();
41
std::string testdir = testComPIDVarG->Get_directory();
42
ASSERT_NO_THROW(delete testComPIDVarG);
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 ComPIDVarGTest : public ::testing::Test {
55
virtual void SetUp() {
56
MAUS::recon::global::ComPIDVarG testComPIDVarG("test", "test");
57
testfile = testComPIDVarG.Get_filename();
58
testdir = testComPIDVarG.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* tp1 =
64
new MAUS::DataStructure::Global::TrackPoint();
65
MAUS::DataStructure::Global::TrackPoint* tp2 =
66
new MAUS::DataStructure::Global::TrackPoint();
67
tp1->set_detector(MAUS::DataStructure::Global::kTOF1);
68
tp2->set_detector(MAUS::DataStructure::Global::kTOF2);
70
MAUS::DataStructure::Global::TrackPoint* tpEMR =
71
new MAUS::DataStructure::Global::TrackPoint();
73
double emr_density = r.Gaus(0.5, 0.001);
74
testTrack->set_emr_plane_density(emr_density);
79
double t1 = r.Gaus(45, 2);
80
TLorentzVector pos1(x1, y1, z1, t1);
85
double t2 = r.Gaus(85, 2);
86
TLorentzVector pos2(x2, y2, z2, t2);
88
tp1->set_position(pos1);
89
tp2->set_position(pos2);
90
tp1->set_mapper_name("MapCppGlobalTrackMatching-Through");
91
tp2->set_mapper_name("MapCppGlobalTrackMatching-Through");
92
testTrack->AddTrackPoint(tp1);
93
testTrack->AddTrackPoint(tp2);
94
tpEMR->set_mapper_name("MapCppGlobalTrackMatching-Through");
95
tpEMR->set_detector(MAUS::DataStructure::Global::kEMR);
96
testTrack->AddTrackPoint(tpEMR);
97
testTrack->set_mapper_name("MapCppGlobalTrackMatching-Through");
98
testTracks.push_back(testTrack);
102
virtual void TearDown() {
103
gSystem->Unlink(testfile.c_str());
104
gSystem->Unlink(testdir.c_str());
108
bool fileExists(std::string filename) {
109
TFile f(filename.c_str(), "READ");
110
return !f.IsZombie();
113
bool IsFiniteNumber(double x) {
114
return (x <= DBL_MAX && x >= -DBL_MAX);
117
std::string testfile;
121
std::string histname;
122
std::vector<MAUS::DataStructure::Global::Track*> testTracks;
125
TEST_F(ComPIDVarGTest, CreateFileConstructor) {
127
ASSERT_TRUE(fileExists(testfile));
130
TEST_F(ComPIDVarGTest, ReadFileConstructor) {
132
file = new TFile(testfile.c_str(), "READ");
136
ASSERT_FALSE(file->IsZombie());
138
ASSERT_NO_THROW(MAUS::recon::global::ComPIDVarG testComPIDVarG(file, "test", 20, 40, 0, 1));
140
ASSERT_ANY_THROW(MAUS::recon::global::ComPIDVarG testComPIDVarG(NULL, "test", 20, 40, 0, 1));
142
ASSERT_ANY_THROW(MAUS::recon::global::ComPIDVarG testComPIDVarG(file, "sasquatch", 20, 40, 0, 1));
145
/* N.B. if either FillHist or LogL are failing, check the values of min and max
146
* bin in ComPIDVarG.hh, as if the testTracks fall outside of this range FillHist
147
* and LogL will fail.
150
TEST_F(ComPIDVarGTest, FillHist) {
152
MAUS::recon::global::ComPIDVarG testComPIDVarG("test", "test");
153
for (int i = 0; i < 1000; i++) {
154
testComPIDVarG.Fill_Hist(testTracks[i]);
156
testfile = testComPIDVarG.Get_filename();
157
testdir = testComPIDVarG.Get_directory();
158
// check histogram exists
159
hist = testComPIDVarG.Get_hist();
161
// check number of entries
162
ASSERT_EQ(1000, hist->GetEntries());
165
TEST_F(ComPIDVarGTest, LogL) {
166
// Constructor called within parentheses so that destructor will be
167
// called when it goes out of scope
169
MAUS::recon::global::ComPIDVarG writetestComPIDVarG("test", "test");
170
for (int i = 0; i < 1000; i++) {
171
writetestComPIDVarG.Fill_Hist(testTracks[i]);
173
testfile = writetestComPIDVarG.Get_filename();
174
testdir = writetestComPIDVarG.Get_directory();
177
MAUS::DataStructure::Global::Track* checkTrack =
178
new MAUS::DataStructure::Global::Track();
179
MAUS::DataStructure::Global::TrackPoint* ctp1 =
180
new MAUS::DataStructure::Global::TrackPoint();
181
MAUS::DataStructure::Global::TrackPoint* ctp2 =
182
new MAUS::DataStructure::Global::TrackPoint();
183
ctp1->set_detector(MAUS::DataStructure::Global::kTOF1);
184
ctp2->set_detector(MAUS::DataStructure::Global::kTOF2);
190
TLorentzVector cpos1(x1, y1, z1, t1);
196
TLorentzVector cpos2(x2, y2, z2, t2);
198
MAUS::DataStructure::Global::TrackPoint* ctpEMR =
199
new MAUS::DataStructure::Global::TrackPoint();
200
ctpEMR->set_detector(MAUS::DataStructure::Global::kCalorimeter);
202
double emr_density = 0.5;
203
checkTrack->set_emr_plane_density(emr_density);
204
ctpEMR->set_detector(MAUS::DataStructure::Global::kEMR);
205
ctpEMR->set_mapper_name("MapCppGlobalTrackMatching-Through");
206
checkTrack->AddTrackPoint(ctpEMR);
207
ctp1->set_position(cpos1);
208
ctp2->set_position(cpos2);
209
ctp1->set_mapper_name("MapCppGlobalTrackMatching-Through");
210
ctp2->set_mapper_name("MapCppGlobalTrackMatching-Through");
211
checkTrack->AddTrackPoint(ctp1);
212
checkTrack->AddTrackPoint(ctp2);
213
checkTrack->set_mapper_name("MapCppGlobalTrackMatching-Through");
215
file = new TFile(testfile.c_str(), "READ");
219
ASSERT_FALSE(file->IsZombie());
221
ASSERT_NO_THROW(MAUS::recon::global::ComPIDVarG readtestComPIDVarG(file, "test", 30, 50, 0, 1));
223
MAUS::recon::global::ComPIDVarG readtestComPIDVarG(file, "test", 30, 50, 0, 1);
225
hist = readtestComPIDVarG.Get_hist();
227
// check number of entries in histogram
228
// NB as destructor was called above, the number of entries in the histogram
229
// will be increased by the number of bins (inc over and underflow) as in
230
// ComPIDVarG the behaviour to add one event across all bins is turned on.
231
ASSERT_EQ((1000 + hist->GetSize()), hist->GetEntries());
232
double prob = readtestComPIDVarG.logL(checkTrack);
235
ASSERT_TRUE(IsFiniteNumber(prob));