-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathALERT.java
More file actions
313 lines (264 loc) · 10.9 KB
/
ALERT.java
File metadata and controls
313 lines (264 loc) · 10.9 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
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
package org.jlab.clas.timeline.histograms;
import java.util.*;
import org.jlab.groot.data.H1F;
import org.jlab.io.base.DataBank;
import org.jlab.io.base.DataEvent;
import org.jlab.groot.data.TDirectory;
import org.jlab.utils.groups.IndexedTable;
import org.jlab.detector.calib.utils.ConstantsManager;
/**
*
* @author sangbaek
*/
public class ALERT {
boolean userTimeBased;
public int runNum, triggerPID;
public long trigger_word;
public String outputDir;
public boolean hasRF;
public double startTime, rfTime;
public double rfPeriod;
public int rf_large_integer;
//Hodoscope
public H1F[] ATOF_Time, ATOF_Time_sl, ATOF_z, ATOF_z_sl, ATOF_z_c4, ATOF_z_c4_sl;
public H1F[] ADC, AHDC_RESIDUAL, AHDC_TIME;//AHDC-related-histograms
private H1F bits;
public IndexedTable rfTable;
public ConstantsManager ccdb;
// private int[] layer_wires = {47, 56, 56, 72, 72, 87, 87, 99};
private int[] layer_wires_cumulative = {0, 47, 103, 159, 231, 303, 390, 477, 576};
private int[] layer_encoding = {11, 21, 22, 31, 32, 41, 42, 51};
private Integer[] boxed_encoding = Arrays.stream(layer_encoding).boxed().toArray(Integer[]::new);
public ALERT(int reqrunNum, String reqOutputDir, float reqEb, boolean reqTimeBased) {
runNum = reqrunNum;
outputDir = reqOutputDir;
userTimeBased = reqTimeBased;
startTime = -1000;
rfTime = -1000;
triggerPID = 0;
rfPeriod = 4.008;
ccdb = new ConstantsManager();
ccdb.init(Arrays.asList(new String[]{"/daq/tt/fthodo", "/calibration/eb/rf/config"}));
rfTable = ccdb.getConstants(runNum, "/calibration/eb/rf/config");
if (rfTable.hasEntry(1, 1, 1)) {
System.out.println(String.format("RF period from ccdb for run %d: %f", runNum, rfTable.getDoubleValue("clock", 1, 1, 1)));
rfPeriod = rfTable.getDoubleValue("clock", 1, 1, 1);
}
rf_large_integer = 1000;
ATOF_Time = new H1F[11];// ATOF Time Histograms
ATOF_Time_sl = new H1F[660];// ATOF Time Histograms
ATOF_z = new H1F[1];// ATOF Time Histograms
ATOF_z_c4 = new H1F[1];// ATOF Time Histograms
ATOF_z_sl = new H1F[60];// ATOF z Histograms
ATOF_z_c4_sl = new H1F[60];// ATOF z Histograms
for (int component = 0; component < 11; component++) {
ATOF_Time[component] = new H1F(String.format("ATOF_Time_component%02d", component), String.format("ATOF Time component%02d", component), 200, -5, 5);
ATOF_Time[component].setTitleX("ATOF Time (ns)");
ATOF_Time[component].setTitleY("Counts");
ATOF_Time[component].setFillColor(4);
}
ATOF_z[0]= new H1F(String.format("ATOF_z_combined"), String.format("ATOF z"), 300,-300,300);
ATOF_z[0].setTitleX("ATOF z (mm)");
ATOF_z[0].setTitleY("Counts");
ATOF_z[0].setFillColor(4);
ATOF_z_c4[0]= new H1F(String.format("ATOF_z_combined_c4"), String.format("ATOF z with c4"), 300,-300,300);
ATOF_z_c4[0].setTitleX("ATOF z (mm)");
ATOF_z_c4[0].setTitleY("Counts");
ATOF_z_c4[0].setFillColor(4);
for(int sector=0;sector<15;sector++){
for(int layer=0;layer<4;layer++){
int gsector=sector*4+layer;
ATOF_z_sl[gsector] = new H1F(String.format("ATOF_z_sector%02d_layer%02d", sector,layer), String.format("ATOF z sector%02d layer %2d", sector,layer), 300,-300,300);
ATOF_z_sl[gsector].setTitleX("ATOF z (mm)");
ATOF_z_sl[gsector].setTitleY("Counts");
ATOF_z_sl[gsector].setFillColor(4);
ATOF_z_c4_sl[gsector] = new H1F(String.format("ATOF_z_c4_sector%02d_layer%02d", sector,layer), String.format("ATOF z with C4 sector%02d layer %2d", sector,layer), 300,-300,300);
ATOF_z_c4_sl[gsector].setTitleX("ATOF z (mm)");
ATOF_z_c4_sl[gsector].setTitleY("Counts");
ATOF_z_c4_sl[gsector].setFillColor(4);
for (int component = 0; component < 11; component++) {
int gcomponent = gsector*11+component;
ATOF_Time_sl[gcomponent] = new H1F(String.format("ATOF_Time_sector%02d_layer%02d_component%02d",sector,layer, component), String.format("ATOF Time sector%02d layer%02d component%02d", sector,layer,component), 200, -5, 5);
ATOF_Time_sl[gcomponent].setTitleX("ATOF Time (ns)");
ATOF_Time_sl[gcomponent].setTitleY("Counts");
ATOF_Time_sl[gcomponent].setFillColor(4);
}
}
}
//AHDC ADC Histograms
ADC = new H1F[576];
AHDC_RESIDUAL = new H1F[8];
AHDC_TIME = new H1F[576];
for (int index = 0; index<576; index++) {
int layer_number = 0;
int wire_number = 0;
for (int j=0; j<8; j++){
if (index < layer_wires_cumulative[j+1]){
layer_number = j + 1;
wire_number = index + 1 - layer_wires_cumulative[j];
break;
}
}
ADC[index] = new H1F(String.format("ADC_layer%d_wire_number%02d", layer_number, wire_number), String.format("ADC layer%d wire number%02d", layer_number, wire_number), 516, 0.0, 3612.0);
ADC[index].setTitleX("ADC");
ADC[index].setTitleY("Counts");
ADC[index].setFillColor(4);
AHDC_TIME[index] = new H1F(String.format("AHDC_TIME_layer%d_wire_number%02d", layer_number, wire_number), String.format("AHDC Time layer %d wire number%02d", layer_number, wire_number), 450, -10.f, 440.0f);
AHDC_TIME[index].setTitleX("AHDC TIME (ns)");
AHDC_TIME[index].setTitleY("Counts");
AHDC_TIME[index].setFillColor(4);
}
for (int k=0; k<8; k++){
AHDC_RESIDUAL[k] = new H1F(String.format("AHDC_RESIDUAL_layer%d", layer_encoding[k]), String.format("AHDC Residual layer%d", layer_encoding[k]), 300, -20.0f, 10.0f);
AHDC_RESIDUAL[k].setTitleX("AHDC RESIDUAL (mm)");
AHDC_RESIDUAL[k].setTitleY("Counts");
AHDC_RESIDUAL[k].setFillColor(4);
}
// Trigger bits
bits = new H1F("bits", "bits",65,0,65);
bits.getDataX(0);
bits.getEntries();
bits.getMaximumBin();
bits.getAxis().getNBins();
}
public void fillAHDC(DataBank ahdc_adc) {
int rows = ahdc_adc.rows();
for (int loop = 0; loop < rows; loop++) {
int layer = ahdc_adc.getInt("layer", loop);
int component = ahdc_adc.getInt("component", loop);
int adc = ahdc_adc.getInt("ADC", loop);
int index = 0;
int layer_number = Arrays.asList(boxed_encoding).indexOf(layer) + 1;
index = component - 1 + layer_wires_cumulative[layer_number - 1];
ADC[index].fill(adc);
}
}
public void fillAHDC_hits(DataBank ahdc_hits) {
int rows = ahdc_hits.rows();
for (int loop = 0; loop < rows; loop++) {
int layer = ahdc_hits.getByte("layer", loop);
int superlayer = ahdc_hits.getByte("superlayer", loop);
int component = ahdc_hits.getInt("wire", loop);
float time = (float) ahdc_hits.getDouble("time", loop);
float residual = (float) ahdc_hits.getDouble("residual", loop);
int index = 0;
layer = superlayer * 10 + layer;
int layer_number = Arrays.asList(boxed_encoding).indexOf(layer) + 1;
index = component - 1 + layer_wires_cumulative[layer_number - 1];
if (Math.signum(residual) != 0) AHDC_RESIDUAL[layer_number - 1].fill(residual);
AHDC_TIME[index].fill(time);
}
}
public void fillATOF_hits(DataBank atof_hits) {
int rows = atof_hits.rows();
// First pass: collect which gsectors have a hit on component 4
Set<Integer> gsectors_with_c4 = new HashSet<>();
for (int loop = 0; loop < rows; loop++) {
if (atof_hits.getInt("component", loop) == 4) {
int sector = atof_hits.getInt("sector", loop);
int layer = atof_hits.getInt("layer", loop);
gsectors_with_c4.add(sector * 4 + layer);
}
}
// Second pass: fill all histograms
for (int loop = 0; loop < rows; loop++) {
int sector = atof_hits.getInt("sector", loop);
int layer = atof_hits.getInt("layer", loop);
int component = atof_hits.getInt("component", loop);
float time = atof_hits.getFloat("time", loop);
int gsector = sector * 4 + layer;
int gcomponent = gsector * 11 + component;
ATOF_Time[component].fill(time);
ATOF_Time_sl[gcomponent].fill(time);
if (component == 10) {
float z = atof_hits.getFloat("z", loop);
ATOF_z[0].fill(z);
ATOF_z_sl[gsector].fill(z);
if (gsectors_with_c4.contains(gsector)) {
ATOF_z_c4[0].fill(z);
ATOF_z_c4_sl[gsector].fill(z);
}
}
}
}
public void processEvent(DataEvent event) {
DataBank recBankEB = null;
DataBank recEvenEB = null;
DataBank runConfig = null;
DataBank atof_hits = null;
DataBank ahdc_adc = null;
DataBank ahdc_hits = null;
if (event.hasBank("REC::Particle")) {
recBankEB = event.getBank("REC::Particle");
}
if (event.hasBank("REC::Event")) {
recEvenEB = event.getBank("REC::Event");
}
if (event.hasBank("RUN::config")) {
runConfig = event.getBank("RUN::config");
}
if (event.hasBank("ATOF::hits")) {
atof_hits = event.getBank("ATOF::hits");
}
if (event.hasBank("AHDC::adc")) {
ahdc_adc = event.getBank("AHDC::adc");
}
if (event.hasBank("AHDC::hits")){
ahdc_hits = event.getBank("AHDC::hits");
}
if (runConfig!= null){
trigger_word = runConfig.getLong("trigger", 0);
bits.fill(64);
for (int i=0; i<64; ++i){
if ( 1 == ((trigger_word>>i)&1) ) {
bits.fill(i);
}
}
}
if (recEvenEB != null) {
startTime = recEvenEB.getFloat("startTime", 0);
rfTime = recEvenEB.getFloat("RFTime", 0);
}
//Get trigger particle
if (recBankEB != null) {
triggerPID = recBankEB.getInt("pid", 0);
}
if (atof_hits != null) {
fillATOF_hits(atof_hits);
}
if (ahdc_adc != null) {
fillAHDC(ahdc_adc);
}
if (ahdc_hits != null) {
fillAHDC_hits(ahdc_hits);
}
}
public void write() {
TDirectory dirout = new TDirectory();
dirout.mkdir("/ALERT/");
dirout.cd("/ALERT/");
for (int component = 0; component < 11; component++) {
dirout.addDataSet(ATOF_Time[component]);
}
dirout.addDataSet(ATOF_z[0]);
dirout.addDataSet(ATOF_z_c4[0]);
for (int gsector = 0; gsector < 60; gsector++) {
dirout.addDataSet(ATOF_z_sl[gsector]);
dirout.addDataSet(ATOF_z_c4_sl[gsector]);
}
for (int gcomponent = 0; gcomponent < 660; gcomponent++) {
dirout.addDataSet(ATOF_Time_sl[gcomponent]);
}
for (int index = 0; index < 576; index++) {
dirout.addDataSet(ADC[index], AHDC_TIME[index]);
}
for (int index = 0; index < 8; index++){
dirout.addDataSet(AHDC_RESIDUAL[index]);
}
dirout.mkdir("/TRIGGER/");
dirout.cd("/TRIGGER/");
dirout.addDataSet(bits);
if(runNum>0) dirout.writeFile(outputDir+"/out_ALERT_"+runNum+".hipo");
else dirout.writeFile(outputDir+"/out_ALERT.hipo");
}
}