-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDstBuilder.m
350 lines (278 loc) · 12.6 KB
/
DstBuilder.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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
function []=StructureBuilder(nrun)
nrun=sscanf(nrun,'%d')
% load global variables
SharedGlobals;
if DC == 1 % Data challenge
display(sprintf('DataChallenge = %d, setting DST_PATH to %s, RAWDATA_PATH to %s',DC,DST_PATH,RAWDATA_PATH))
end
% Check for existing raw dst
% - if only CoincData, start from pre-analysis
% - if only PreProcessData, start from filtering
% - if dst, ask for rebuilding (from which step)
% - if nothing, start from beginning!
% Define Building flags
DstBuild=0;
PreProcessBuild=0;
CoincBuild=0;
NbIter=1; % just looking for the first file
filename = [DST_PATH sprintf(dst_filename,nrun,NbIter)];
ft=fopen(filename);
filename2 = [DST_PATH sprintf(preprocess_filename,nrun,NbIter)];
ft2=fopen(filename2);
filename3 = [DST_PATH sprintf(coinc_filename,nrun,NbIter)];
ft3=fopen(filename3);
if (ft~=-1) % dst file found
display('Dst found for this run')
display('Dst will be rebuilt from preprocessed data')
display('Previous dst will be erased')
fclose(ft);
pause(5);
DstBuild=1; % only dst rebuild
elseif ft2~=-1 % preprocess file found
display('Preprocess data found for this run')
display('Dst will be built from preprocessed data')
fclose(ft2);
DstBuild=1;
elseif ft3~=-1 % coinc file found
display('Coinc data found for this run')
display('Preprocess data will be generated')
display('Dst will be built from preprocessed data')
fclose(ft3);
PreProcessBuild=1;
DstBuild=1;
else
% No file found, generate structure from beginning
CoincBuild=1;
PreProcessBuild=1;
DstBuild=1;
end;
% if we don't start from the beginning, we need the number of iteration
if CoincBuild==0
filename = [DST_PATH sprintf(coinc_filename,nrun,NbIter)];
ft=fopen(filename);
while ft~=-1
NbIter=NbIter+1; % initialised at 1 previously
filename = [DST_PATH sprintf(coinc_filename,nrun,NbIter)];
ft=fopen(filename);
fclose all;
end;
NbIter=NbIter-1; % final value
end;
%%%%%%%%%%%%%%%%%%% PRE PROCESSING DATA OPERATIONS%%%%%%%%%%%%%%%%%%%%%%%%
% Coincidence building
if CoincBuild
display('Building setup configuration...')
[Struct]=RunSetupBuilder(nrun,AnalysisType);
RunSetup = Struct.Setup;
if ~exist('RunSetup')
display('Setup building error...')
return
else
display('Done!')
end
if Struct.Setup.TotalEvt>100e6
disp(sprintf('%d triggers in run, exceeds limit! Aborting.',Struct.Setup.TotalEvt));
return
else
% OBSOLETE: replaced by (independant) CalibStructureBuilder
% 18/05/2012 OMH
%display('Loading calibration data...')
%[Struct]=CalibBuilder(Struct);
%display('Done!')
display('Building Time Table...')
[EventTimeTable,Struct]=EventTimeTableBuilder(Struct,TrigRateFilterFlag);
display('Done!')
save('/afs/in2p3.fr/throng/trend/soft/ana/TREND_insertsimu/table.mat','EventTimeTable')
if (Struct.Setup.TotalEvt-size(Struct.Setup.InfosRun.EmptySignals,1))==0
display(sprintf('All events empty for run %d',nrun));
filename = sprintf(coinc_filename,nrun,1);
EmptyStructure(filename,Struct,nrun,1);
filename = sprintf(preprocess_filename,nrun,1);
EmptyStructure(filename,Struct,nrun,1);
filename = sprintf(dst_filename,nrun,1);
EmptyStructure(filename,Struct,nrun,1);
return
end;
% Saving total structure
StructBase=Struct;
% Creation of sub-structures of msize events
NbIter=0;
StopOrder=0;
RefTable=1;
while StopOrder==0
NbIter=NbIter+1;
% Saving filename
filename = [DST_PATH sprintf(coinc_filename,nrun,NbIter)];
% Reduction of EventTimeTable (depending on number of iterations)
EventTimeTable=EventTimeTable(RefTable:end,:);
% Look for coincidences in the reduced time table, give the new RefTable
[Struct,RefTable]=CoincidenceFinder(StructBase,EventTimeTable,NbIter,AnalysisType);
[GlobalCoincRate,DetCoincRate]=CoincidenceRate(Struct);
Struct.Setup.InfosRun.GlobalCoincRateRaw=GlobalCoincRate;
Struct.Setup.InfosRun.DetCoincRateRaw=DetCoincRate;
% Saving substructures
save(filename,'Struct');
clear Struct;
% If RefTable is null, there is no more event to study
if RefTable==0
StopOrder=1;
end;
end;
end;
end;
% Pre process building
if PreProcessBuild
% Loop on all files
for i=1:NbIter
filename =[DST_PATH sprintf(coinc_filename,nrun,i)];
load(filename);
if Struct.Setup.TotalCoinc==0
display(sprintf('No coinc found (CoincData stage) for run %d iteration %d',nrun,i));
filename = sprintf(preprocess_filename,nrun,i);
EmptyStructure(filename,Struct,nrun,i);
display(sprintf('DST %s now saved to file.',filename));
continue
end
% Consecutive coincs filter
display('Lauching Consecutive coincidences filter...');
[Struct]=ConsecutiveCoincidenceFilter(Struct);
display('Done!')
if QuickReject & SelectedData == 0 % structure modification: erase rejected events
goodevts=find([Struct.Coinc.Reject.ConsCoinc]==0);
if ~isempty(goodevts)
Struct.Setup.TotalCoinc=length(goodevts);
Struct.Coinc.Mult=Struct.Coinc.Mult(goodevts);
Struct.Coinc.MultAnt=Struct.Coinc.MultAnt(goodevts);
Struct.Coinc.MultSci=Struct.Coinc.MultSci(goodevts);
Struct.Coinc.IdCoinc=Struct.Coinc.IdCoinc(goodevts);
Struct.Coinc.Det.Tag=Struct.Coinc.Det.Tag(goodevts,:);
Struct.Coinc.Det.Status=Struct.Coinc.Det.Status(goodevts,:);
Struct.Coinc.Det.Id=Struct.Coinc.Det.Id(goodevts,:);
Struct.Coinc.Det.Evt=Struct.Coinc.Det.Evt(goodevts,:);
Struct.Coinc.Det.Time=Struct.Coinc.Det.Time(goodevts,:);
Struct.Coinc.Det.UnixTime=Struct.Coinc.Det.UnixTime(goodevts,:);
Struct.Coinc.Det.TriggerRate=Struct.Coinc.Det.TriggerRate(goodevts,:);
[GlobalCoincRate,DetCoincRate]=CoincidenceRate(Struct);
Struct.Setup.InfosRun.GlobalCoincRateQuickReject=GlobalCoincRate;
Struct.Setup.InfosRun.DetCoincRateQuickReject=DetCoincRate;
else
display(sprintf('No coinc found (Quick reject stage) for run %d iteration %d',nrun,i));
filename = sprintf(preprocess_filename,nrun,i);
EmptyStructure(filename,Struct,nrun,i);
display(sprintf('DST %s now saved to file.',filename));
continue
end;
end;
% Raw filter (Valentin)
display('Lauching raw filter...');
[Struct] = RawFilter(Struct);
display('Done!')
% Correction of scintillators trigger time using RawFilter result
% SciTimeCorrection2: use alternative method (strong deviation from mean)
[Struct]=SciTimeCorrection2(Struct);
% Saving pre process data
filename = [DST_PATH sprintf(preprocess_filename,nrun,i)];
save(filename,'Struct');
clear Struct
end
end;
%%%%%%%%%%%%%%%%%%%%%%%%% BUILDING DST %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if DstBuild
display('Building final DST...')
[NbIterDst]=CoincidenceFiltering(nrun,NbIter);
for i=1:NbIterDst
filename =[DST_PATH sprintf(dst_filename,nrun,i)];
load(filename);
if Struct.Setup.TotalCoinc==0
display(sprintf('No coinc found (dst building stage) for run %d iteration %d',nrun,i));
filename = sprintf(dst_filename,nrun,i);
EmptyStructure(filename,Struct,nrun,i);
continue
end;
display('Launching TriggerTimeBuilder...')
[Struct]=TriggerTimeBuilder(Struct);
display('Done!')
display('Launchig StatusBuilder...')
[Struct]=StatusBuilder(Struct);
display('Done!')
% Perform cross correlation treatment
if CORREL
display('Launching CrossCorrelationBuilder...')
[Struct]=CrossCorrelationBuilder(Struct);
else
Struct.Coinc.Det.TrigCor = zeros(Struct.Setup.TotalCoinc,length([ Struct.Setup.Det.Name ]));
Struct.Coinc.Det.CoefCor = zeros(Struct.Setup.TotalCoinc,length([ Struct.Setup.Det.Name ]));
end
% Build .txt file for C++ reconstruction (fast)
display('Now reconstructing pure radio coincs only...')
display('Launching CoinctableFileBuilder...')
[Struct]=CoinctableFileBuilder(Struct,0);
display('Done!')
reconsex = [CXX_PATH 'recons'];
unix(sprintf('export TREND_TEXT_PATH=%s;%s %d %d',TEXT_PATH,reconsex,nrun,CORREL));
%unix(sprintf('setenv TREND_TEXT_PATH %s;%s %d %d',TEXT_PATH,reconsex,nrun,CORREL));
[Struct]=ReconsLoader(Struct,0);
[Struct]=Dist2Source(Struct); % distance antennas - point sources
display('Launching CandidateFileBuilder...')
[Struct]=CandidateFileBuilder(Struct);
display('Done!')
%reconsShowerex = [CXX_PATH 'reconsShower'];
%%unix(sprintf('export TREND_TEXT_PATH=%s;%s %d %d %d',TEXT_PATH,reconsShowerex,nrun,CORREL,0));
%unix(sprintf('setenv TREND_TEXT_PATH %s;%s %d %d %d',TEXT_PATH,reconsShowerex,nrun,CORREL, 0));
[Struct]=ShowerLoader(Struct,0);
%%unix(sprintf('export TREND_TEXT_PATH=%s;%s %d %d %d',TEXT_PATH,reconsShowerex,nrun,CORREL,1));
%unix(sprintf('setenv TREND_TEXT_PATH %s;%s %d %d %d',TEXT_PATH,reconsShowerex,nrun,CORREL,1));
[Struct]=ShowerLoader(Struct,1);
display('Now reconstructing hybrid coincs only...')
display('Launching CoinctableFileBuilder...')
[Struct]=CoinctableFileBuilder(Struct,1);
display('Done!')
%reconsScintex = [CXX_PATH 'reconsScint'];
%unix(sprintf('export TREND_TEXT_PATH=%s;%s %d %d',TEXT_PATH,reconsScintex,nrun,CORREL));
%unix(sprintf('setenv TREND_TEXT_PATH %s;%s %d %d',TEXT_PATH,reconsScintex,nrun,CORREL));
[Struct]=ReconsLoader(Struct,1);
display('Done!')
% Recalculation for corrected delays
if 0
Struct.Coinc.DelayCorrRecons=[];
display('Recalculation for new delays')
display('Now reconstructing pure radio coincs only...')
display('Launching CoinctableFileBuilder...')
[Struct]=CoinctableFileBuilder(Struct,0);
display('Done!')
reconsex = [CXX_PATH 'recons'];
unix(sprintf('export TREND_TEXT_PATH=%s;%s %d %d',TEXT_PATH,reconsex,nrun,CORREL));
%unix(sprintf('setenv TREND_TEXT_PATH %s;%s %d %d',TEXT_PATH,reconsex,nrun,CORREL));
[Struct]=ReconsLoader(Struct,0);
[Struct]=Dist2Source(Struct); % distance antennas - point sources
display('Launching CandidateFileBuilder...')
[Struct]=CandidateFileBuilder(Struct);
display('Done!')
reconsShowerex = [CXX_PATH 'reconsShower'];
unix(sprintf('export TREND_TEXT_PATH=%s;%s %d %d %d',TEXT_PATH,reconsShowerex,nrun,CORREL,0));
%unix(sprintf('setenv TREND_TEXT_PATH %s;%s %d %d %d',TEXT_PATH,reconsShowerex,nrun,CORREL, 0));
[Struct]=ShowerLoader(Struct,0);
unix(sprintf('export TREND_TEXT_PATH=%s;%s %d %d %d',TEXT_PATH,reconsShowerex,nrun,CORREL,1));
%unix(sprintf('setenv TREND_TEXT_PATH %s;%s %d %d %d',TEXT_PATH,reconsShowerex,nrun,CORREL,1));
[Struct]=ShowerLoader(Struct,1);
display('Now reconstructing hybrid coincs only...')
display('Launching CoinctableFileBuilder...')
[Struct]=CoinctableFileBuilder(Struct,1);
display('Done!')
%reconsScintex = [CXX_PATH 'reconsScint'];
%unix(sprintf('export TREND_TEXT_PATH=%s;%s %d %d',TEXT_PATH,reconsScintex,nrun,CORREL));
%unix(sprintf('setenv TREND_TEXT_PATH %s;%s %d %d',TEXT_PATH,reconsScintex,nrun,CORREL));
[Struct]=ReconsLoader(Struct,1);
display('Done!')
end
% NO SCINT RECONS
display('Now reconstructing pure scintillator coincs only...')
[Struct]=SciOnlyRecons(Struct, AnalysisType);
% Structure save
%Struct.Coinc.IsShower=4
filename =[DST_PATH sprintf(dst_filename,nrun,i)];
save(filename,'Struct');
display(sprintf('DST %s now saved to file.',filename));
clear Struct
end;
end;