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/ComPIDVarC.hh"
36
TEST(ComPIDVarCTestSetUp, TestSetUpAndTearDown) {
37
MAUS::recon::global::ComPIDVarC *testComPIDVarC = NULL;
38
ASSERT_NO_THROW(testComPIDVarC = new MAUS::recon::global::ComPIDVarC("test",
40
std::string testfile = testComPIDVarC->Get_filename();
41
std::string testdir = testComPIDVarC->Get_directory();
42
ASSERT_NO_THROW(delete testComPIDVarC);
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 ComPIDVarCTest : public ::testing::Test {
55
virtual void SetUp() {
56
MAUS::recon::global::ComPIDVarC testComPIDVarC("test", "test");
57
testfile = testComPIDVarC.Get_filename();
58
testdir = testComPIDVarC.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* tpKL =
64
new MAUS::DataStructure::Global::TrackPoint();
65
tpKL->set_detector(MAUS::DataStructure::Global::kCalorimeter);
66
double adc_charge_prod = r.Gaus(1000, 10);
67
tpKL->set_ADC_charge_product(adc_charge_prod);
69
tpKL->set_mapper_name("MapCppGlobalTrackMatching-Through");
70
testTrack->AddTrackPoint(tpKL);
71
testTrack->set_mapper_name("MapCppGlobalTrackMatching-Through");
72
testTracks.push_back(testTrack);
76
virtual void TearDown() {
77
gSystem->Unlink(testfile.c_str());
78
gSystem->Unlink(testdir.c_str());
82
bool fileExists(std::string filename) {
83
TFile f(filename.c_str(), "READ");
87
bool IsFiniteNumber(double x) {
88
return (x <= DBL_MAX && x >= -DBL_MAX);
96
std::vector<MAUS::DataStructure::Global::Track*> testTracks;
99
TEST_F(ComPIDVarCTest, CreateFileConstructor) {
101
ASSERT_TRUE(fileExists(testfile));
104
TEST_F(ComPIDVarCTest, ReadFileConstructor) {
106
file = new TFile(testfile.c_str(), "READ");
110
ASSERT_FALSE(file->IsZombie());
112
ASSERT_NO_THROW(MAUS::recon::global::ComPIDVarC testComPIDVarC(file, "test", 0, 8000));
114
ASSERT_ANY_THROW(MAUS::recon::global::ComPIDVarC testComPIDVarC(NULL, "test", 0, 8000));
116
ASSERT_ANY_THROW(MAUS::recon::global::ComPIDVarC testComPIDVarC(file, "sasquatch", 0, 8000));
119
/* N.B. if either FillHist or LogL are failing, check the values of min and max
120
* bin in ComPIDVarC.hh, as if the testTracks fall outside of this range FillHist
121
* and LogL will fail.
124
TEST_F(ComPIDVarCTest, FillHist) {
126
MAUS::recon::global::ComPIDVarC testComPIDVarC("test", "test");
127
for (int i = 0; i < 1000; i++) {
128
testComPIDVarC.Fill_Hist(testTracks[i]);
130
testfile = testComPIDVarC.Get_filename();
131
testdir = testComPIDVarC.Get_directory();
132
// check histogram exists
133
hist = testComPIDVarC.Get_hist();
135
// check number of entries
136
ASSERT_EQ(1000, hist->GetEntries());
139
TEST_F(ComPIDVarCTest, LogL) {
140
// Constructor called within parentheses so that destructor will be
141
// called when it goes out of scope
143
MAUS::recon::global::ComPIDVarC writetestComPIDVarC("test", "test");
144
for (int i = 0; i < 1000; i++) {
145
writetestComPIDVarC.Fill_Hist(testTracks[i]);
147
testfile = writetestComPIDVarC.Get_filename();
148
testdir = writetestComPIDVarC.Get_directory();
151
MAUS::DataStructure::Global::Track* checkTrack =
152
new MAUS::DataStructure::Global::Track();
153
MAUS::DataStructure::Global::TrackPoint* ctpKL =
154
new MAUS::DataStructure::Global::TrackPoint();
155
ctpKL->set_detector(MAUS::DataStructure::Global::kCalorimeter);
157
double adc_charge_prod = 1000;
158
ctpKL->set_ADC_charge_product(adc_charge_prod);
160
ctpKL->set_mapper_name("MapCppGlobalTrackMatching-Through");
161
checkTrack->AddTrackPoint(ctpKL);
162
checkTrack->set_mapper_name("MapCppGlobalTrackMatching-Through");
164
file = new TFile(testfile.c_str(), "READ");
168
ASSERT_FALSE(file->IsZombie());
170
ASSERT_NO_THROW(MAUS::recon::global::ComPIDVarC readtestComPIDVarC(file, "test", 0, 8000));
172
MAUS::recon::global::ComPIDVarC readtestComPIDVarC(file, "test", 0, 8000);
174
hist = readtestComPIDVarC.Get_hist();
176
// check number of entries in histogram
177
// NB as destructor was called above, the number of entries in the histogram
178
// will be increased by the number of bins (inc over and underflow) as in
179
// ComPIDVarC the behaviour to add one event across all bins is turned on.
180
ASSERT_EQ((1000 + hist->GetSize()), hist->GetEntries());
181
double prob = readtestComPIDVarC.logL(checkTrack);
184
ASSERT_TRUE(IsFiniteNumber(prob));