-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPreProcessor.cc
250 lines (237 loc) · 10.3 KB
/
PreProcessor.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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#include <cmath>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
using namespace std;
//Storage for all Ge77 Events. Global variables cause im lazy and this is program consists of a singular file.
//One entry corresponds to one Ge77 Event
vector<vector<string>> AllIsotopes;
vector<vector<double>> AllNCaptureX;
vector<vector<double>> AllNCaptureY;
vector<vector<double>> AllNCaptureZ;
vector<vector<double>> AllNCaptureEnergy;
vector<vector<double>> AllNCaptureTime;
ifstream newfile;
int read_out(string filename)
{
int counterGe = 0;
newfile.open(filename);
string delimiter = ";";
string seperator = ",";
if(newfile.is_open()){
string s;
//Skip first 12 useless lines
for(int i = 0; i < 12; i++)
{
newfile.ignore(1000,'\n');
}
while(getline(newfile, s))
{
//Store all neutron information for one Ge77 Event
vector<string> IsotopeNames;
vector<double> NCaptureX;
vector<double> NCaptureY;
vector<double> NCaptureZ;
vector<double> NCaptureEnergy;
vector<double> NCaptureTime;
//Get first entry array. Each array is seperated with seperator.
size_t pos = 0;
string token;
string element;
//First is nGe so just add to Ge counter.
pos =s.find(seperator);
token = s.substr(0, pos);
counterGe = counterGe + stoi(token);
s.erase(0,pos + delimiter.length());
// Second is Amount which currently doesnt work so erase
pos =s.find(seperator);
s.erase(0,pos + delimiter.length());
//Next is isotope names, mucho importante
pos =s.find(seperator);
token = s.substr(0, pos);
s.erase(0,pos + delimiter.length());
//Iterate through each entry of the array, seperated by delimiter. First Isotope names
stringstream ss(token);
while (getline(ss, element, ';'))
{
// Add each value to the vector
IsotopeNames.push_back(element);
}
//Second x Position
pos =s.find(seperator);
token = s.substr(0, pos);
s.erase(0,pos + delimiter.length());
ss.clear();
ss.str(token);
while (getline(ss, element, ';'))
{
double value = stod(element);
NCaptureX.push_back(value);
}
//Third y Position
pos =s.find(seperator);
token = s.substr(0, pos);
s.erase(0,pos + delimiter.length());
ss.clear();
ss.str(token);
while (getline(ss, element, ';'))
{
double value = stod(element);
NCaptureY.push_back(value);
}
//Fourth z Position
pos =s.find(seperator);
token = s.substr(0, pos);
s.erase(0,pos + delimiter.length());
ss.clear();
ss.str(token);
while (getline(ss, element, ';'))
{
double value = stod(element);
NCaptureZ.push_back(value);
}
//Fifth Energy in eV
pos =s.find(seperator);
token = s.substr(0, pos);
s.erase(0,pos + delimiter.length());
ss.clear();
ss.str(token);
while (getline(ss, element, ';'))
{
double value = stod(element);
NCaptureEnergy.push_back(value);
}
//Last time in ns
pos =s.find(seperator);
token = s.substr(0, pos);
s.erase(0,pos + delimiter.length());
ss.clear();
ss.str(token);
while (getline(ss, element, ';'))
{
double value = stod(element);
NCaptureTime.push_back(value);
}
//After one Ge77 Event is done add it to the whole entry as one array
AllIsotopes.push_back(IsotopeNames);
AllNCaptureX.push_back(NCaptureX);
AllNCaptureY.push_back(NCaptureY);
AllNCaptureZ.push_back(NCaptureZ);
AllNCaptureEnergy.push_back(NCaptureEnergy);
AllNCaptureTime.push_back(NCaptureTime);
}
//After every line is through each "All" entry is an array corresponding to one Ge77 event.
newfile.close();
}
else{
cout << "Could not open file: " << filename << endl;
}
return counterGe;
}
int main(){
// Open output file in corresponding directories
ofstream outfile{ "/home/eric/sim/WWLegend/Output/NeutronTagger/NeutronTemp/run.txt" };
ofstream Comparisonfile{ "/home/eric/sim/WWLegend/Output/NeutronTagger/OpticalOutput/ShowerIDs.txt" };
// Read out each file for each thread into corresponding global arrays.
int counterGe = read_out("/home/eric/sim/WWLegend/Output/NeutronTagger/NeutronTemp/session_nt_Score_t0.csv");
counterGe = counterGe + read_out("/home/eric/sim/WWLegend/Output/NeutronTagger/NeutronTemp/session_nt_Score_t1.csv");
counterGe = counterGe + read_out("/home/eric/sim/WWLegend/Output/NeutronTagger/NeutronTemp/session_nt_Score_t2.csv");
counterGe = counterGe + read_out("/home/eric/sim/WWLegend/Output/NeutronTagger/NeutronTemp/session_nt_Score_t3.csv");
counterGe = counterGe + read_out("/home/eric/sim/WWLegend/Output/NeutronTagger/NeutronTemp/session_nt_Score_t4.csv");
counterGe = counterGe + read_out("/home/eric/sim/WWLegend/Output/NeutronTagger/NeutronTemp/session_nt_Score_t5.csv");
counterGe = counterGe + read_out("/home/eric/sim/WWLegend/Output/NeutronTagger/NeutronTemp/session_nt_Score_t6.csv");
counterGe = counterGe + read_out("/home/eric/sim/WWLegend/Output/NeutronTagger/NeutronTemp/session_nt_Score_t7.csv");
counterGe = counterGe + read_out("/home/eric/sim/WWLegend/Output/NeutronTagger/NeutronTemp/session_nt_Score_t8.csv");
counterGe = counterGe + read_out("/home/eric/sim/WWLegend/Output/NeutronTagger/NeutronTemp/session_nt_Score_t9.csv");
counterGe = counterGe + read_out("/home/eric/sim/WWLegend/Output/NeutronTagger/NeutronTemp/session_nt_Score_t10.csv");
counterGe = counterGe + read_out("/home/eric/sim/WWLegend/Output/NeutronTagger/NeutronTemp/session_nt_Score_t11.csv");
counterGe = counterGe + read_out("/home/eric/sim/WWLegend/Output/NeutronTagger/NeutronTemp/session_nt_Score_t12.csv");
counterGe = counterGe + read_out("/home/eric/sim/WWLegend/Output/NeutronTagger/NeutronTemp/session_nt_Score_t13.csv");
counterGe = counterGe + read_out("/home/eric/sim/WWLegend/Output/NeutronTagger/NeutronTemp/session_nt_Score_t14.csv");
counterGe = counterGe + read_out("/home/eric/sim/WWLegend/Output/NeutronTagger/NeutronTemp/session_nt_Score_t15.csv");
int counterW = 0;
int counterElse = 0;
int counterModerator = 0;
int counterSteel = 0;
int counterArg = 0;
int counterGd = 0;
int total = 0;
int ID = 0;
double radius = 3499; //radius of cryostat in mm
//Now todo: Print output and count captures
for (size_t i = 0; i < AllIsotopes.size(); ++i)
{
const auto& innerVector = AllIsotopes[i];
for (size_t j = 0; j < innerVector.size(); ++j)
{
const auto& token = innerVector[j];
double xPosition = AllNCaptureX[i][j];
double yPosition = AllNCaptureY[i][j];
double zPosition = AllNCaptureZ[i][j];
double Energy = AllNCaptureEnergy[i][j];
double time = AllNCaptureTime[i][j];
if(token == "H1" || token == "O16")
{
outfile << "1,";
// Check if capture is outside of cryostat so it was water. Otherwise could be moderator
double nradiussquare = AllNCaptureX[i][j] * AllNCaptureX[i][j] + AllNCaptureY[i][j] * AllNCaptureY[i][j];
if(nradiussquare > (radius * radius) || AllNCaptureZ[i][j] > 2499 || AllNCaptureZ[i][j] < -4499)
{
counterW = counterW + 1;
}
else
{
counterModerator = counterModerator + 1;
}
}
else if((token == "Gd154" || token == "Gd155") || (token == "Gd156" || token == "Gd158") || (token == "Gd160"))
{
outfile << "0,";
counterGd = counterGd + 1;
}
else if(token == "Gd157")
{
outfile << "3,";
counterGd = counterGd + 1;
}
else if((token.find("Ar") != string::npos))
{
outfile << "4,";
counterArg = counterArg + 1;
}
else if((token.find("Fe") != string::npos) || (token.find("Cr") != string::npos) || (token.find("Ni") != string::npos) )
{
outfile << "4,";
counterSteel = counterSteel + 1;
}
else
{
outfile << "4,";
counterElse = counterElse + 1;
}
outfile << xPosition << "," << yPosition << "," << zPosition << "," << Energy << "," << time << endl;
Comparisonfile << ID << "," << xPosition << "," << yPosition << "," << zPosition << "," << Energy << "," << time << endl;
total = total + 1;
}
ID = ID + 1;
}
outfile.close();
Comparisonfile.close();
outfile.open("/home/eric/sim/WWLegend/Output/NeutronTagger/NeutronTemp/run.mac");
outfile << "/run/beamOn " << total << endl;
outfile.close();
cout << "Amount of Ge Captures: " << counterGe << endl;
cout << "Amount of Water Captures: " << counterW << endl;
cout << "Amount of Gd Captures: " << counterGd << endl;
cout << "Amount of Argon Captures: " << counterArg << endl;
cout << "Amount of Moderator Captures: " << counterModerator << endl;
cout << "Amount of Steel Captures: " << counterSteel << endl;
cout << "Amount of Else Captures: " << counterElse << endl;
//ofstream outfile{ "run.mac" };
//outfile << "/run/beamOn " << counterW + counterGd +counterArg + counterSteel + counterElse << endl;
//outfile.close();
return 0;
}