-
Notifications
You must be signed in to change notification settings - Fork 0
/
mPMTTreeReader.cxx
111 lines (93 loc) · 2.74 KB
/
mPMTTreeReader.cxx
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
//////////////////////////////////////////////////////////
// Author: Ciro Riccio
// Date: Nov 8, 2019
//////////////////////////////////////////////////////////
#ifndef mPMTTreeReader_cxx
#define mPMTTreeReader_cxx
#include "mPMTTreeReader.hxx"
#include <TH1D.h>
#include <TH2D.h>
#include <TMath.h>
mPMTTreeReader::mPMTTreeReader(TString fname)
{
if(fname.IsNull()){
cerr << "Specify the input file name!" <<endl;
exit(1);
}
infile = new TFile(fname.Data(),"OPEN");
if (infile->IsZombie()) {
// if we cannot open the file, print an error message and return immediatly
cerr << "File not open!" <<endl;
return;
}
infile->GetObject("Dome01_events",tree);
Init(tree);
}
mPMTTreeReader::~mPMTTreeReader()
{
if (!tree) return;
delete tree->GetCurrentFile();
}
Int_t mPMTTreeReader::GetEntry(Long64_t entry)
{
// Read contents of entry.
if (!tree) return 0;
return tree->GetEntry(entry);
}
Long64_t mPMTTreeReader::LoadTree(Long64_t entry)
{
// Set the environment to read one entry
if (!tree) return -5;
Long64_t centry = tree->LoadTree(entry);
if (centry < 0) return centry;
if (tree->GetTreeNumber() != fCurrent) {
fCurrent = tree->GetTreeNumber();
}
return centry;
}
void mPMTTreeReader::Init(TTree *tree)
{
// Set branch addresses and branch pointers
if (!tree) return;
tree = tree;
fCurrent = -1;
tree->SetMakeClass(1);
tree->SetBranchAddress("TS" , &TS_nTS, &b_TS );
tree->SetBranchAddress("CHAN", &CHAN_nCHAN, &b_CHAN);
tree->SetBranchAddress("TIME", &TIME_nTIME, &b_TIME);
tree->SetBranchAddress("TIHR", &TIHR_nTIHR, &b_TIHR);
tree->SetBranchAddress("WIDT", &WIDT_nWIDT, &b_WIDT);
tree->SetBranchAddress("WIHR", &WIHR_nWIHR, &b_WIHR);
tree->SetBranchAddress("ENER", &ENER_nENER, &b_ENER);
}
void mPMTTreeReader::SetOutputFile(TString name){
if(name.IsNull()){
cerr << "Specify the output file name!" <<endl;
exit(1);
}
outfile = new TFile(name.Data(),"RECREATE");
//outtree = new TTree("mPMTEvents","mPMTEvents");
}
mPMTEventAnalyser mPMTTreeReader::GetPMTEvents(int channelID){
Long64_t nentries = tree->GetEntriesFast();
Long64_t nbytes = 0, nb = 0;
mPMTEventAnalyser anaev;
//144167591/1000
for (Long64_t jentry=0; jentry<nentries;jentry++){
nb = tree->GetEntry(jentry); nbytes += nb;
//===== Create and fill event structure
mPMTEventManager ev(jentry);
ev.SetChannelID( CHAN_CHAN[0] );
ev.SetEnergy( ENER_ENER[0] );
ev.SetUnixTime( TS_TS[0] );
ev.SetTime28Bit( TIME_TIME[0] );
ev.SetTime5Bit( TIHR_TIHR[0] );
ev.SetWidth( WIDT_WIDT[0] );
ev.SetWidthHR( WIHR_WIHR[0] );
if (CHAN_CHAN[0]==channelID){
anaev.AddEvent(ev);
}
}
return anaev;
}
#endif