-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFileReader.cxx
121 lines (118 loc) · 3.33 KB
/
FileReader.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
111
112
113
114
115
116
117
118
119
120
121
#include "FileReader.h"
TH2F* FileReader::GetHist2D(TString filename, TString appendix, TString dirName,
std::vector<TString> path, TString histname,
TString prefix) {
auto file = TFile::Open(filename);
if (!file) {
std::cerr << "ERROR FileReader: File does not exist\n";
return nullptr;
}
TString name = prefix;
name += dirName;
name += appendix;
auto dir = file->GetDirectory(name);
if (!dir) {
std::cerr << "ERROR FileReader: Directory does not exist\n";
file->Close();
return nullptr;
}
auto histoList = (TList*)dir->Get(name);
TList* results = histoList;
// std::cout << path.size() << "\n";
// if (path.size() > 0) {
// for (const auto& it : path) {
// results = (TList*)results->FindObject(it);
// }
// }
if (!results) {
std::cerr << "ERROR FileReader: List does not exist\n";
file->Close();
return nullptr;
}
auto hist2D = (TH2F*)results->FindObject(histname);
if (!hist2D) {
std::cerr << "ERROR FileReader: Histogram does not exist\n";
file->Close();
return nullptr;
}
hist2D->Sumw2();
file->Close();
return hist2D;
}
TH1F* FileReader::GetHist1D(TString filename, TString appendix, TString dirName,
std::vector<TString> path, TString histname,
TString prefix) {
auto file = TFile::Open(filename);
if (!file) {
std::cerr << "ERROR FileReader: File does not exist\n";
return nullptr;
}
TString name = prefix;
name += dirName;
name += appendix;
auto dir = file->GetDirectory(name);
if (!dir) {
std::cerr << "ERROR FileReader: Directory does not exist\n";
file->Close();
return nullptr;
}
auto histoList = (TList*)dir->Get(name);
histoList->ls();
TList* results = histoList;
// for (const auto& it : path) {
// results = (TList*)results->FindObject(it);
// }
if (!results) {
std::cerr << "ERROR FileReader: List does not exist\n";
file->Close();
return nullptr;
}
auto hist1D = (TH1F*)results->FindObject(histname);
if (!hist1D) {
std::cerr << "ERROR FileReader: Histogram does not exist\n";
file->Close();
return nullptr;
}
hist1D->Sumw2();
file->Close();
return hist1D;
}
TProfile* FileReader::GetProfile(TString filename, TString appendix,
TString dirName, std::vector<TString> path,
TString histname, TString prefix) {
auto file = TFile::Open(filename);
if (!file) {
std::cerr << "ERROR FileReader: File does not exist\n";
file->Close();
return nullptr;
}
TString name = dirName;
name += appendix;
auto dir = file->GetDirectory(name);
if (!dir) {
std::cerr << "ERROR FileReader: Directory does not exist\n";
file->Close();
return nullptr;
}
name = prefix;
name += "_";
name += appendix;
auto histoList = (TList*)dir->Get(name);
TList* results = histoList;
for (const auto& it : path) {
results = (TList*)results->FindObject(it);
}
if (!results) {
std::cerr << "ERROR FileReader: List does not exist\n";
file->Close();
return nullptr;
}
auto profile = (TProfile*)results->FindObject(histname);
if (!profile) {
std::cerr << "ERROR FileReader: Histogram does not exist\n";
file->Close();
return nullptr;
}
file->Close();
return profile;
}