This repository was archived by the owner on Aug 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEEEanalyzer_bin.m
267 lines (196 loc) · 12.2 KB
/
EEEanalyzer_bin.m
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
%E.E.E.-analyzer - MAIN by Fabio Pinciroli
%Copyright 2016-2017 Fabio Pinciroli DISTRIBUTED UNDER GPL V3 LICENSE
function EEEanalyzer_bin(figSaveMode, fName, fDir, v20Name, v20Dir, doDqm, doStats)
% Load xlwrite libraries
root = ctfroot
javaaddpath(strcat(root, '\poi-3.8-20120326.jar'));
javaaddpath(strcat(root, '\poi-ooxml-3.8-20120326.jar'));
javaaddpath(strcat(root, '\poi-ooxml-schemas-3.8-20120326.jar'));
javaaddpath(strcat(root, '\xmlbeans-2.3.0.jar'));
javaaddpath(strcat(root, '\dom4j-1.6.1.jar'));
javaaddpath(strcat(root, '\stax-api-1.0.1.jar'));
wbar = waitbar(0/10, 'Setting up folders'); %set progress bar
wbar.WindowStyle = 'modal';
%Create working folder and convert file------------------------------------
mkdir(fDir, fName(1: length(fName) - 4)); %create working folder
movefile(fullfile(fDir, fName), strcat(fDir,'/', fName(1: length(fName) - 4))); %move the file to the working folder
fDir = strcat(fDir, strcat(fName(1: length(fName) - 4), '\')); %update fDir pointer to new file location
if doDqm
mkdir(fDir, 'DQM'); %create dqm folder
end
waitbar(1/11, wbar, 'Converting data'); %update progress bar
comA = strcat('cd "',fDir,'" &&','"',v20Dir,v20Name,'" "',fName,'" "',fDir, '"'); %run eee_v20 on file, to current directory
system(comA);
fName = strcat(fName(1: length(fName) - 3), 'out'); %update data file name to the converted one
fRep = fopen(fullfile(fDir, 'STATISTICS REPORT.txt'), 'wt'); %open report file
%Data import---------------------------------------------------------------
waitbar(2/11, wbar, 'Prepairing data for import'); %update progress bar
comA = ['sed -i "s/\s\{3,\}/,/g" "', fDir, fName,'"'];
system(comA); %Done with sed for cross platform compatibility and is faster that powershell
comA = ['sed -i "1d" "', fDir, fName, '"'];
system(comA);
waitbar(3/11, wbar, 'Importing data'); %update progress bar
format long; %Set full decimal resolution
dati = csvread(fullfile(fDir, fName)); %import data
[dataLenght, ~] = size(dati); %calculate array size
%Folder cleanup--------------------------------------------------------
delete(strcat(fDir, fName(1: length(fName) - 3), 'out'));
delete(strcat(fDir, fName(1: length(fName) - 3), '2tt'));
delete(strcat(fDir, fName(1: length(fName) - 3), 'sum'));
delete(strcat(fDir, fName(1: length(fName) - 3), 'tim'));
delete(strcat(fDir, 'eee_calib.txt'));
%{
*=calcualted field
|1 |2 |3 |4 |5 |6 |7 |8 |9 |10 |11 |12* |13* |14* |15* |
|RUN NUMBER|TELESCOPE HIT NUMBER|SECONDS SINCE 1/1/2007|NANOSECONDS|MICROSECONDS SINCE STARD OF RUN|VECTOR X|VECTOR Y|VECTOR Z|CHI^2|TOF|TRACK LENGHT|EFFECTIVE NUMBER|THETA(RAD)|THETA(DEG)|0-360 DIRECTION|
%}
%Extract Telescope name, acquisition date----------------------------------
tName = fName(1: length(fName) - 21);
tYear = fName(length(fName) - 19: length(fName) - 16);
tMonth = fName(length(fName) - 14: length(fName) - 13);
tDay = fName(length(fName) - 11: length(fName) - 10);
tDate = fName(length(fName) - 19: length(fName) - 10);
%download and save the dqm Report------------------------------------------
%Downloads done with wget instead of the matlab comand because the dqm site has a broken SSL certificate, and the matlab comand refuses to work.
if doDqm
waitbar(4/11, wbar, 'Downloading DQM data'); %update progress bar
%comA = strcat('cd "',strcat(fDir, '\DQM\'),'" &&','"',wGetDir,wGetName,'" -p -nd --no-check-certificate',' https://www1.cnaf.infn.it/eee/monitor//dqmreport/',tName,'/',tDate, '/'); %Get the page
comA = strcat('wget -nd --no-check-certificate https://www1.cnaf.infn.it/eee/monitor//dqmreport/',tName,'/',tDate,'/ -P "',fDir,'\DQM\');
system(comA);
%comA = strcat('cd "',strcat(fDir, '\DQM\'),'" &&','"',wGetDir,wGetName,'" -r -a png -nd --no-check-certificate',' https://www1.cnaf.infn.it/eee/monitor//dqmreport/',tName,'/',tDate, '/'); %Get the images
comA = strcat('wget -r -a png -nd --no-check-certificate https://www1.cnaf.infn.it/eee/monitor//dqmreport/',tName,'/',tDate,'/ -P "',fDir,'\DQM\');
system(comA);
end
%!!!TODO basic data----------------------------------------------
%header
waitbar(5/11, wbar, 'Doing report'); %update progress bar
fprintf(fRep, 'E.E.E. packet automatic analysis report\nGenerated by E.E.E. analyzer by Fabio Pinciroli (https://github.com/fabiusp98/E.E.E.-analyzer)\n');
%telescope
fprintf(fRep, 'Telescope: %s \n', tName);
%Start time
epoch = datetime(2007,1,1,0,0,0); %start epoch(1/1/2007 00:00:00)
fprintf(fRep, 'Run start: %s s\n', datestr(epoch + seconds(dati(1,3))));
%Stop time
fprintf(fRep, 'Run end: %s s\n', datestr(epoch + seconds(dati(dataLenght,3))));
%run duration in seconds
fprintf(fRep, 'Run duration: %f s\n', dati(dataLenght,3) - dati(1,3));
%run duration in minutes
fprintf(fRep, 'Run duration: %f m\n', (dati(dataLenght,3) - dati(1,3)) / 60);
%Add other columns to working dataset--------------------------
waitbar(6/11, wbar, 'Calculating entry angle'); %update progress bar
tot = 0; %counter, init to 0
for cnt = 1:1:dataLenght %pass all the data
%effective number
dati(cnt, 12) = tot; %save counter do column
tot = tot + 1; %update counter
%theta(rad)
dati(cnt, 13) = asin(dati(cnt, 8));
%theta(deg)
dati(cnt, 14) = rad2deg(dati(cnt, 13));
%0-360 direction
if(dati(cnt, 6) < 0)
dataOut = 180 + rad2deg(atan((dati(cnt, 7) / dati(cnt, 6))));
else
if(dati(cnt, 7) > 0)
dataOut = rad2deg(atan((dati(cnt, 7) / dati(cnt, 6))));
else
dataOut = 360 + rad2deg(atan((dati(cnt, 7) / dati(cnt, 6))));
end
end
dati(cnt, 15) = dataOut;
end
%save effective number
fprintf(fRep, 'Hits: %f \n', tot);
waitbar(7/11, wbar, 'Calculating distribution'); %update progress bar
%statistics of dirty dataset--------------------
%heading
fprintf(fRep, '\nDIRTY DATA STATISTICS:\n');
%no hit events
fprintf(fRep, 'no hit events: %f\n', dati(dataLenght,2) - dati(dataLenght,12));
%save dirty data do first excel file--------------------------
xlwrite(strcat(fDir, '/dirty data.xls'), dati);
%Stats for track lenght----------------------------------------------
fprintf(fRep, 'Track lenght max: %f \n', max(dati(:,11)));
fprintf(fRep, 'Track lenght max: %f \n', min(dati(:,11)));
fprintf(fRep, 'Track lenght mean: %f \n', mean(dati(:,11)));
fprintf(fRep, 'Track lenght mode: %f \n', mode(dati(:,11)));
fprintf(fRep, 'Track lenght median: %f \n', median(dati(:,11)));
%Distribution--------------------------------------------------------
if doStats
set(0,'DefaultFigureVisible','off'); %Turn off figure visibility
GraphStats(dati, 'DIRTY DATA - angular distribution', fDir, figSaveMode);
set(0,'DefaultFigureVisible','on'); %Turn figs back on
end
%count and move entries with chi^2 > %10-------------------------------------------
waitbar(8/11, wbar, 'Filtering for chi'); %update progress bar
cnt = 1; %arrays in matlab start at 1 ??? – – – :-)
tot = 0; %chi2 entries total
while cnt < dataLenght %for loop done with while because for in matlab doesn't care about upper limit updates ??? – – – :-)
if dati(cnt, 9) > 10 %if erroneous entry found
tot = tot + 1; %update count
chiArray(tot + 1,:) = dati(cnt,:); %save data to other array (position is counter + 1 because matlab arrays suck and start at 1)
%dati(cnt,:) = []; %delete row in main array
%cnt = cnt - 1; %recheck same line because everything above the current position shifted back one row
end
cnt = cnt + 1 ; %advance to the next row
end
fprintf(fRep, 'Hits with Chi^2 > 10: %f\n', tot); %save chi2 count to report
xlwrite(strcat(fDir, '/chi2.xls'), chiArray); %save excel file for chi2 rejects
%count entries with chi^2 > 10 and tof < 0-------------------------------------------
cnt = 1; %arrays in matlab start at 1 ??? – – – :-)
tot = 0; %entries total
while cnt < dataLenght %for loop done with while because for in matlab doesn't care about upper limit updates ??? – – – :-)
if (dati(cnt, 9) > 10) && (dati(cnt, 10) < 0) %if erroneous entry found
tot = tot + 1; %update count
end
cnt = cnt + 1 ; %advance to the next row
end
fprintf(fRep, 'Hits with Chi^2 > 10 and TOF < 0: %f\n', tot); %save count to report
%count and move entries with tof < 0-------------------------------------------
waitbar(9/11, wbar, 'Filtering for TOF'); %update progress bar
cnt = 1; %arrays in matlab start at 1 ??? – – – :-)
tot = 0; %tof entries total
while cnt < dataLenght %for loop done with while because for in matlab doesn't care about upper limit updates ??? – – – :-)
if dati(cnt, 10) < 0 %if erroneous entry found
tot = tot + 1; %update count
tofArray(tot + 1,:) = dati(cnt,:); %save data to other array (position is counter + 1 because matlab arrays suck and start at 1)
dati(cnt,:) = []; %delete row in main array
dataLenght = dataLenght - 1; %decrease array size because a row has been deleted
cnt = cnt - 1; %recheck same line because everything above the current position shifted back one row
end
cnt = cnt + 1 ; %advance to the next row
end
fprintf(fRep, 'TOF < 0: %f\n', tot); %save tof count to report
xlwrite(strcat(fDir, '/tof.xls'), tofArray); %save excel file for tof rejects
%clean back up for chi^2 > 0 (previously counted and capoed, but not deleted to not hinder the stats for the TOF)---------------
cnt = 1; %arrays in matlab start at 1 ??? – – – :-)
while cnt < dataLenght %for loop done with while because for in matlab doesn't care about upper limit updates ??? – – – :-)
if dati(cnt, 9) > 10 %if erroneous entry found
dati(cnt,:) = []; %delete row in main array
dataLenght = dataLenght - 1; %decrease array size because a row has been deleted
cnt = cnt - 1; %recheck same line because everything above the current position shifted back one row
end
cnt = cnt + 1 ; %advance to the next row
end
xlwrite(strcat(fDir, '/clean data.xls'), dati); %save excel file for tof rejects
%Clean data header
fprintf(fRep, '\nCLEAN DATA STATISTICS\n');
waitbar(10/11, wbar, 'Calculating distribution'); %update progress bar
%Stats for track lenght----------------------------------------------
fprintf(fRep, 'Track lenght max: %f \n', max(dati(:,11)));
fprintf(fRep, 'Track lenght max: %f \n', min(dati(:,11)));
fprintf(fRep, 'Track lenght mean: %f \n', mean(dati(:,11)));
fprintf(fRep, 'Track lenght mode: %f \n', mode(dati(:,11)));
fprintf(fRep, 'Track lenght median: %f \n', median(dati(:,11)));
%Distribution----------------------------------------------------------
if doStats
set(0,'DefaultFigureVisible','off'); %Turn off figure visibility
GraphStats(dati, 'CLEAN DATA - angular distribution', fDir, figSaveMode);
set(0,'DefaultFigureVisible','on'); %Turn figs back on
end
fclose(fRep); %close report
disp('DONE');
delete('sed*'); %temporary fix: sed leaves a temp file in the matlab executable folder for some reason, this cleans it up. Otherwise the temp files accumulate> memory leak
delete('png');
delete(wbar); %close waitbar
end