-
Notifications
You must be signed in to change notification settings - Fork 0
/
library_access.cc
128 lines (104 loc) · 3.45 KB
/
library_access.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "library_access.h"
#include <iostream>
#include <fstream>
#include "TFile.h"
#include "TTree.h"
// constructor
LibraryAccess::LibraryAccess()
: table_(std::vector<std::vector<float> >())
{
}
// function to load optical library
void LibraryAccess::LoadLibraryFromFile(std::string libraryfile)
{
std::cout << "Reading photon library from input file: " << libraryfile << std::endl;
TFile *f = nullptr;
TTree *tt = nullptr;
try
{
f = TFile::Open(libraryfile.c_str());
tt = (TTree*)f->Get("PhotonLibraryData");
if (!tt) {
TKey *key = f->FindKeyAny("PhotonLibraryData");
if (key)
tt = (TTree*)key->ReadObj();
else {
std::cout << "PhotonLibraryData not found in file: " << libraryfile << std::endl;
}
}
}
catch(...)
{
std::cout << "Error in ttree load, reading photon library: " << libraryfile << std::endl;
}
int voxel;
int opChannel;
float visibility;
int maxvoxel = tt->GetMaximum("Voxel")+1;
int maxopChannel = tt->GetMaximum("OpChannel")+2;
table_.resize(maxvoxel, std::vector<float>(maxopChannel, 0));
tt->SetBranchAddress("Voxel", &voxel);
tt->SetBranchAddress("OpChannel", &opChannel);
tt->SetBranchAddress("Visibility", &visibility);
size_t nentries = tt->GetEntries();
for(size_t i=0; i!=nentries; ++i)
{
tt->GetEntry(i);
if((voxel<0)||(voxel>= maxvoxel)||(opChannel<0)||(opChannel>= maxopChannel))
{}
else
{
table_.at(voxel).at(opChannel) = visibility;
}
}
try
{
f->Close();
}
catch(...)
{
std::cout << "Error in closing file : " << libraryfile << std::endl;
}
}
const float* LibraryAccess::GetCounts(size_t voxel, int no_pmt)
{
return &table_.at(voxel).at(no_pmt);
}
const float* LibraryAccess::GetLibraryEntries(int voxID, int no_pmt)
{
return GetCounts(voxID, no_pmt);
}
// GetVoxelID
int LibraryAccess::GetVoxelID(double* Position) //const
{
// figure out how many steps this point is in the x,y,z directions
int xStep = int ((Position[0]-gLowerCorner[0]) / (gUpperCorner[0]-gLowerCorner[0]) * gxSteps );
int yStep = int ((Position[1]-gLowerCorner[1]) / (gUpperCorner[1]-gLowerCorner[1]) * gySteps );
int zStep = int ((Position[2]-gLowerCorner[2]) / (gUpperCorner[2]-gLowerCorner[2]) * gzSteps );
int ID;
// check if point lies within the voxelized region
if((0 <= xStep) && (xStep < gxSteps) &&
(0 <= yStep) && (yStep < gySteps) &&
(0 <= zStep) && (zStep < gzSteps) )
{
// if within bounds, generate the voxel ID
ID = xStep
+ yStep * (gxSteps)
+ zStep * (gxSteps * gySteps);
}
else
{
// if out of bounds, print warning and return -1
ID = -1;
}
return ID;
}
// function to return visibility of voxel-pmt combination
float LibraryAccess::PhotonLibraryAnalyzer(int _pmt_number, int _voxel)
{
//Look up visibility parameter by comparing the optical channel (PMT Number)
//and the detector location (voxel, i)
const float *Visibilities = GetLibraryEntries(_voxel, _pmt_number);
const float vis = *Visibilities;
return vis;
}