-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRunSetupBuilder.m
136 lines (115 loc) · 4.18 KB
/
RunSetupBuilder.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
function [Struct]=RunSetupBuilder(nrun,AnalysisType)
% Look for present detectors in studied run and use SetupCharacteristics to
% save importants informations as position, delays, cable...
% 14/04/10, TS
% Last modification : OMH 23/12/10
SharedGlobals;
%%%%%%%%%%%%%%% WARNING!! Change these values in case of experimental setup change %%%%%%%%%%%%%%%%%%%%%
if nrun > 444400 % NS polar
det_search=[101:139 140 156:158 175 176];
else %EW polar
det_search=[101:139 140 148:158 175 176];
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%% SCINTILLATORS ONLY %%%%%%%%%%%%%%%%
%det_search=[139 175 176];
Detectors=[];
DetectorsFound=0;
TotalNbEvents=[];
TimeStart=[];
TimeStop=[];
DetMalfunction=[];
DetNoTrig=[];
% Identification of present antenna/scintillator in the run
for i=1:length(det_search)
% Opening of antenna time file
ft = OpenFileTime(nrun,det_search(i));
% if exist, antenna name and number of events save
if ft~=-1
time=double(fread(ft,inf,'uint32'));
fseek( ft, 0, 'eof' );
NbEvents=ftell(ft)/(ibufft*4);
if size(time,1)~=0
% security on acquisition bug (corrupted time file)
unixtime(1)=time(1);
unixtime(2)=time(1+(NbEvents-1)*ibufft);
if isempty(find(unixtime==0))
Detectors=[Detectors det_search(i)];
DetectorsFound=DetectorsFound+1;
TotalNbEvents=[TotalNbEvents NbEvents]; % Total number of events for this antenna
TimeStart=[TimeStart unixtime(1)];
TimeStop=[TimeStop unixtime(2)];
else
DetMalfunction=[DetMalfunction det_search(i)];
end
else
DetNoTrig=[DetNoTrig det_search(i)];
end
fclose(ft);
clear unixtime NbEvents
end;
end;
disp(sprintf('%d triggers on %d antennas recorded in R%d.',sum(TotalNbEvents),DetectorsFound,nrun));
% Run quality check
if (DetectorsFound==0)||(sum(TotalNbEvents)==0)
display('RunSetupBuilder error : no access to data! Path error? ')
return;
end;
clear RunSetup
RunSetup.Run=nrun;
RunSetup.TotalEvt=sum(TotalNbEvents);
% Setup characterisitcs (antennas, scintillators, positions, delays)
if ismember(nrun,runs2010)
[pos_det,podN,pos_pod,cable,delay,delaycorr,sciID,logID]=SetupCharacteristics2010(Detectors);
else
[pos_det,podN,pos_pod,cable,delay,delaycorr,sciID,logID]=SetupCharacteristics(Detectors,nrun);
end
%delay = delay-delaycorr
% RunSetup sub structre creation
cpt_det=0;
% Scintillators only analysis
if AnalysisType==2
ind=find(sciID==1);
Detectors=Detectors(ind);
DetectorsFound=length(Detectors);
TotalNbEvents=TotalNbEvents(ind);
pos_det=pos_det(ind,:);
podN=podN(ind);
pos_pod=pos_pod(ind,:);
cable=cable(ind);
delay=delay(ind);
delaycorr=delaycorr(ind);
sciID=sciID(ind);
logID=logID(ind);
TimeStart=TimeStart(ind);
TimeStop=TimeStop(ind);
end;
for i=1:DetectorsFound
cpt_det=cpt_det+1;
det(cpt_det).Name=Detectors(i);
det(cpt_det).Evt=TotalNbEvents(i);
det(cpt_det).X=pos_det(i,1);
det(cpt_det).Y=pos_det(i,2);
det(cpt_det).Z=pos_det(i,3);
det(cpt_det).PodNb=podN(i);
det(cpt_det).PodX=pos_pod(i,1);
det(cpt_det).PodY=pos_pod(i,2);
det(cpt_det).PodZ=pos_pod(i,3);
det(cpt_det).Cable=cable(i);
det(cpt_det).Delay=delay(i);
det(cpt_det).DelayCorr=delaycorr(i);
det(cpt_det).isScint=sciID(i);
det(cpt_det).isLog=logID(i);
end;
% Clean TimeStart
dif = TimeStart-max(TimeStart);
good = find(abs(dif)<24*3600); % Keep machines within 24h of maximum TimeStart (reject machines with bad clock)
Struct.Setup = RunSetup;
Struct.Setup.Det = det;
Struct.Setup.DetMalfunction=DetMalfunction;
Struct.Setup.DetNoTrig=DetNoTrig;
Struct.Setup.TotalCoinc = 0;
Struct.Setup.RunTimeStart = min(TimeStart(good));
Struct.Setup.RunTimeStop = max(TimeStop(good));
Struct.Setup.InfosRun.TimeStart = TimeStart;
Struct.Setup.InfosRun.TimeStop = TimeStop;