-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathTreeConvert.cxx
More file actions
178 lines (139 loc) · 4 KB
/
TreeConvert.cxx
File metadata and controls
178 lines (139 loc) · 4 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Convert .txt file into ROOT tree and store in .root file.
Includes routines to handle data given by Goloskokov & Kroll,
and data from http://rprmodel.ugent.be/calc/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include "TFile.h"
#include "TTree.h"
using namespace std;
void GKConvert(string in_filepath, string out_filepath){
ifstream in_filestream;
in_filestream.open(in_filepath.c_str());
if (! in_filestream){
cout << "File not Found" << endl;
exit(1);
}
//Skip to Data
string line;
int i;
for (i = 0; i < 18; i++) {
getline(in_filestream, line);
}
//Create a tree
TFile out_TFile(out_filepath.c_str(), "UPDATE");
gDirectory->Delete("GK_Raw;*");
//This ensures only the most recent tree in in the file
TTree GK_Raw("GK_Raw", "Asymmetry Data");
//Initialize variables for each data column
Double_t w, q2, tp, t, asy, asysfi, asy2fi, asyfpfs, asy3f;
//Create branches for each variable
GK_Raw.Branch("w", &w, "w/D");
GK_Raw.Branch("q2", &q2, "q2/D");
GK_Raw.Branch("tp", &tp, "tp/D");
GK_Raw.Branch("t",&t,"t/D");
GK_Raw.Branch("asy",&asy,"asy/D");
GK_Raw.Branch("asysfi",&asysfi,"asysfi/D");
GK_Raw.Branch("asy2fi",&asy2fi,"asy2fi/D");
GK_Raw.Branch("asyfpfs",&asyfpfs,"asyfpfs/D");
GK_Raw.Branch("asy3f",&asy3f,"asy3f/D");
//Fill the tree
while (!in_filestream.eof()) {
in_filestream >> w >> q2 >> tp >> t >> asy >> asysfi >> asy2fi
>> asyfpfs >> asy3f;
//cout << w << "\t" << q2 << "\t" << tp <<"\t";
//cout << t << "\t" << asy << "\t" << asysfi << "\t";
//cout << asy2fi << "\t" << asyfpfs << "\t" << asy3f;
//cout << endl;
GK_Raw.Fill();
}
GK_Raw.Write();
}
void VR_SigL(string in_filepath, string out_filepath){
ifstream in_filestream;
in_filestream.open(in_filepath.c_str());
if (! in_filestream){
cout << "File not Found" << endl;
exit(1);
}
//Skip to Data
string line;
int i;
for (i = 0; i < 3; i++) {
getline(in_filestream, line);
}
//Create a tree
TFile out_TFile(out_filepath.c_str(), "UPDATE");
gDirectory->Delete("VR_SigL_Raw;*");
//This ensures only the most recent tree in in the file
TTree VR_SigL_Raw("VR_SigL_Raw", "VR Model");
//Initialize variables for each data column
Double_t Q2, W, Negt, sigL;
//Create branches for each variable
VR_SigL_Raw.Branch("Q2", &Q2, "Q2/D");
VR_SigL_Raw.Branch("W", &W, "W/D");
VR_SigL_Raw.Branch("Negt", &Negt, "-t/D");
VR_SigL_Raw.Branch("dsig_L",&sigL,"dsig_L/D");
//Fill the tree
while (!in_filestream.eof()) {
in_filestream >> Q2 >> W >> Negt >> sigL;
VR_SigL_Raw.Fill();
}
VR_SigL_Raw.Write();
}
void AsyPars(string in_filepath, string out_filepath,
string asyname, int nPars)
{
ifstream in_filestream;
in_filestream.open(in_filepath.c_str());
if (! in_filestream){
cout << "File not Found" << endl;
exit(1);
}
//Create a tree
TFile out_TFile(out_filepath.c_str(), "UPDATE");
TTree t1(asyname.c_str(), "Asymmetry");
double pars[nPars];
double Qsq;
char llist[100] = "pars[%d]/D";
char temp[100];
sprintf(temp, llist, nPars);
t1.Branch("Qsq",&Qsq,"Qsq/D");
t1.Branch("pars",&pars,temp);
while(!in_filestream.eof()){
in_filestream >> Qsq;
for (int i=0; i<nPars; i++){
in_filestream >> pars[i];
}
t1.Fill();
}
t1.Write();
}
void AsyAll()
{
AsyPars("../data/input/asyout.txt",
"test.root",
"asy",
4);
AsyPars("../data/input/asysfiout.txt",
"test.root",
"asysfi",
3);
AsyPars("../data/input/asy2fiout.txt",
"test.root",
"asy2fi",
3);
AsyPars("../data/input/asyfpfsout.txt",
"test.root",
"asyfpfs",
3);
AsyPars("../data/input/asy3fout.txt",
"test.root",
"asy3f",
3);
}