-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathHodoscopePatternReadoutDriver.java
More file actions
432 lines (378 loc) · 17.6 KB
/
HodoscopePatternReadoutDriver.java
File metadata and controls
432 lines (378 loc) · 17.6 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
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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
package org.hps.readout.hodoscope;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import org.hps.conditions.database.DatabaseConditionsManager;
import org.hps.conditions.hodoscope.HodoscopeChannel;
import org.hps.conditions.hodoscope.HodoscopeChannel.HodoscopeChannelCollection;
import org.hps.readout.ReadoutDataManager;
import org.hps.readout.ReadoutDriver;
import org.hps.readout.util.collection.LCIOCollection;
import org.hps.readout.util.collection.LCIOCollectionFactory;
import org.hps.record.daqconfig2019.ConfigurationManager2019;
import org.hps.record.daqconfig2019.DAQConfig2019;
import org.hps.record.daqconfig2019.VTPConfig2019;
import org.hps.readout.util.HodoscopePattern;
import org.lcsim.event.CalorimeterHit;
import org.lcsim.event.EventHeader;
import org.lcsim.geometry.Detector;
/**
* Class <code>HodoscopePatternReadoutDriver</code> produces hodoscope pattern
* objects for Ecal-hodo matching in the trigger simulation. Persistency of Hodo
* FADC hits is <code>persistentTime</code>. On the other hand, hodo FADC hits
* is earlier to enter the trigger system than Ecal by
* <code>timeEarlierThanEcal</code> Therefore, for each clock-cycle, FADC hits
* in [localTime - (persistentTime - timeEarlierThanEcal), localTime +
* timeEarlierThanEcal + 4] are taken into account to generate hodoscope
* patterns for all layers.
*/
public class HodoscopePatternReadoutDriver extends ReadoutDriver {
/** Maps hodoscope channel IDs to channels. */
private Map<Long, HodoscopeChannel> channelMap = new HashMap<Long, HodoscopeChannel>();
/**
* The name of the collection that contains the hodo FADC hits, which raw energy
* is self-defined. Through the hodo FADC hits, hodoscope pattern is generated.
*/
private String inputCollectionName = "HodoscopeCorrectedHits";
/**
* The name of the collection into which generated hodoscope patterns for all
* four layers should be output.
*/
private String outputCollectionName = "HodoscopePatterns";
/**
* The local time for the driver.
*/
private double localTime = 0.0;
/**
* Hodoscope FADC hit cut
*/
private double fADCHitThreshold = 1.0;
/**
* Hodoscope tilt/cluster hit cut
*/
private double hodoHitThreshold = 200.0;
/**
* Gain scaling factor for hits at two-hole tiles.
* Gains from database need to be scaled by the factor
* Gains in the DAQ configuration have been scaled by the factor.
*/
private double gainFactor = 1.25 / 2;
/**
* Persistent time for hodoscope FADC hit in unit of ns
*/
private double persistentTime = 60.0;
/**
* Time for hodoscope FADC hits earlier to enter the trigger system than Ecal
* with unit of ns
*/
private double timeEarlierThanEcal = 0.0;
/**
* The length of time by which objects produced by this driver are shifted due
* to the need to buffer data from later events. This is calculated
* automatically. Hodo FADC hits enter the trigger system earlier than Ecal hits
* by <code>timeEarlierThanEcal</code>
*/
private double localTimeDisplacement = 0.0;
/**
* According to setup in database, index for hodoscope layers are expressed as
* (layer+1)*y
*/
public static final int TopLayer1 = 1;
public static final int TopLayer2 = 2;
public static final int BotLayer1 = -1;
public static final int BotLayer2 = -2;
/**
* List for 4 layers;
*/
private List<Integer> layerList = new ArrayList<>(4);
/**
* List for 8 (x, hole) points of each layer
*/
private List<Point> xHolePointList = new ArrayList<>(8);
private boolean daqConfigurationAppliedintoReadout = false;
/**
* Sets whether or not the DAQ configuration is applied into the driver
* the EvIO data stream or whether to read the configuration from data files.
*
* @param state - <code>true</code> indicates that the DAQ configuration is
* applied into the readout system, and <code>false</code> that it
* is not applied into the readout system.
*/
public void setDaqConfigurationAppliedintoReadout(boolean state) {
daqConfigurationAppliedintoReadout = state;
// If the DAQ configuration should be read, attach a listener
// to track when it updates.
if (state) {
ConfigurationManager2019.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Get the DAQ configuration.
DAQConfig2019 daq = ConfigurationManager2019.getInstance();
VTPConfig2019 config = daq.getVTPConfig();
// Load the DAQ settings from the configuration manager.
fADCHitThreshold = config.getHodoFADCHitThr();
hodoHitThreshold = config.getHodoThr();
persistentTime = config.getHodoDT();
}
});
}
}
@Override
public void process(EventHeader event) {
if(doNoSpacing)
localTime=ReadoutDataManager.getCurrentTime(); // just overwrite local time on every event
// Check the data management driver to determine whether the
// input collection is available or not.
if (!doNoSpacing && !ReadoutDataManager.checkCollectionStatus(inputCollectionName, localTime + localTimeDisplacement)) {
if(debug)System.out.println(this.getClass().getName()+":: "+inputCollectionName+" doesn't exist at time = "+(localTime + localTimeDisplacement));
return;
}
// Hodoscope FADC hits enter the trigger system earlier than Ecal by the time
// <code>timeEarlierThanEcal</code> .
// On the other hand, hodoscope FADC hits persist with a range of
// <code>persistentTime</code>.
// To build current hodo patterns, FADC hits between localTime - (persistentTime
// - timeEarlierThanEcal) and localTime + timeEarlierThanEcal + 4 are used.
Collection<CalorimeterHit> fadcHits = ReadoutDataManager.getData(
localTime - (persistentTime - timeEarlierThanEcal), localTime + timeEarlierThanEcal + 4.0,
inputCollectionName, CalorimeterHit.class);
if(debug)System.out.println(this.getClass().getName()+":: number of fadcHits found = "+fadcHits.size());
// Increment the local time.
localTime += 4.0;
// All hits over <code>fadcHitThreshold</code> are saved for each hole of each
// layer
Map<Integer, Map<Point, List<Double>>> energyListMapForLayerMap = new HashMap<Integer, Map<Point, List<Double>>>();
for (int layer : layerList) {
Map<Point, List<Double>> energyListMap = new HashMap<Point, List<Double>>();
for (Point point : xHolePointList) {
energyListMap.put(point, new ArrayList<Double>());
}
energyListMapForLayerMap.put(layer, energyListMap);
}
for (CalorimeterHit hit : fadcHits) {
double energy = hit.getRawEnergy();
if (energy > fADCHitThreshold) {
Long cellID = hit.getCellID();
int layer = channelMap.get(cellID).getLayer();
int y = channelMap.get(cellID).getIY();
int x = channelMap.get(cellID).getIX();
int hole = channelMap.get(cellID).getHole();
Point point = new Point(x, hole);
// Energy of hits is scaled except hits at tiles 0 and 4
if(x == 0 || x == 4) energyListMapForLayerMap.get((layer + 1) * y).get(point).add(energy);
else {
// Gains in the DAQ configuration has been scaled by the factor.
if(daqConfigurationAppliedintoReadout) energyListMapForLayerMap.get((layer + 1) * y).get(point).add(energy);
else energyListMapForLayerMap.get((layer + 1) * y).get(point).add(energy * gainFactor);
}
}
}
//Get maximum of energy in lists for each hole of each layer
Map<Integer, Map<Point, Double>> maxEnergyMapForLayerMap = new HashMap<Integer, Map<Point, Double>>();
for (int layer : layerList) {
Map<Point, Double> maxEnergyMap = new HashMap<>();
for (Point point : xHolePointList) {
if(energyListMapForLayerMap.get(layer).get(point).size() != 0)
maxEnergyMap.put(point, Collections.max(energyListMapForLayerMap.get(layer).get(point)));
else
maxEnergyMap.put(point, 0.);
}
maxEnergyMapForLayerMap.put(layer, maxEnergyMap);
}
//Hodoscope patterns for all layers
//Order of list: TopLayer1, TopLayer2, BotLayer1, BotLayer2
List<HodoscopePattern> hodoPatterns = new ArrayList<>(4);
// Flag to determine if a pattern list at the current clock-cycle is added into data manager
boolean flag = false;
for (int i = 0; i < 4; i++) {
HodoscopePattern pattern = new HodoscopePattern();
Map<Point, Double> maxEnergyMap = maxEnergyMapForLayerMap.get(layerList.get(i));
if (maxEnergyMap.get(xHolePointList.get(0)) > hodoHitThreshold) {
pattern.setHitStatus(HodoscopePattern.HODO_LX_1, true);
flag = true;
}
if (maxEnergyMap.get(xHolePointList.get(1)) + maxEnergyMap.get(xHolePointList.get(2)) > hodoHitThreshold) {
pattern.setHitStatus(HodoscopePattern.HODO_LX_2, true);
flag = true;
}
if (maxEnergyMap.get(xHolePointList.get(3)) + maxEnergyMap.get(xHolePointList.get(4)) > hodoHitThreshold) {
pattern.setHitStatus(HodoscopePattern.HODO_LX_3, true);
flag = true;
}
if (maxEnergyMap.get(xHolePointList.get(5)) + maxEnergyMap.get(xHolePointList.get(6)) > hodoHitThreshold) {
pattern.setHitStatus(HodoscopePattern.HODO_LX_4, true);
flag = true;
}
if (maxEnergyMap.get(xHolePointList.get(7)) > hodoHitThreshold) {
pattern.setHitStatus(HodoscopePattern.HODO_LX_5, true);
flag = true;
}
if (maxEnergyMap.get(xHolePointList.get(0)) + maxEnergyMap.get(xHolePointList.get(1))
+ maxEnergyMap.get(xHolePointList.get(2)) > hodoHitThreshold
&& maxEnergyMap.get(xHolePointList.get(0)) != 0
&& (maxEnergyMap.get(xHolePointList.get(1)) != 0 || maxEnergyMap.get(xHolePointList.get(2)) != 0)) {
pattern.setHitStatus(HodoscopePattern.HODO_LX_CL_12, true);
flag = true;
}
if (maxEnergyMap.get(xHolePointList.get(1)) + maxEnergyMap.get(xHolePointList.get(2))
+ maxEnergyMap.get(xHolePointList.get(3))
+ maxEnergyMap.get(xHolePointList.get(4)) > hodoHitThreshold
&& (maxEnergyMap.get(xHolePointList.get(1)) != 0 || maxEnergyMap.get(xHolePointList.get(2)) != 0)
&& (maxEnergyMap.get(xHolePointList.get(3)) != 0 || maxEnergyMap.get(xHolePointList.get(4)) != 0)) {
pattern.setHitStatus(HodoscopePattern.HODO_LX_CL_23, true);
flag = true;
}
if (maxEnergyMap.get(xHolePointList.get(3)) + maxEnergyMap.get(xHolePointList.get(4))
+ maxEnergyMap.get(xHolePointList.get(5))
+ maxEnergyMap.get(xHolePointList.get(6)) > hodoHitThreshold
&& (maxEnergyMap.get(xHolePointList.get(3)) != 0 || maxEnergyMap.get(xHolePointList.get(4)) != 0)
&& (maxEnergyMap.get(xHolePointList.get(5)) != 0 || maxEnergyMap.get(xHolePointList.get(6)) != 0)) {
pattern.setHitStatus(HodoscopePattern.HODO_LX_CL_34, true);
flag = true;
}
if (maxEnergyMap.get(xHolePointList.get(5)) + maxEnergyMap.get(xHolePointList.get(6))
+ maxEnergyMap.get(xHolePointList.get(7)) > hodoHitThreshold
&& (maxEnergyMap.get(xHolePointList.get(5)) != 0 || maxEnergyMap.get(xHolePointList.get(6)) != 0)
&& maxEnergyMap.get(xHolePointList.get(7)) != 0) {
pattern.setHitStatus(HodoscopePattern.HODO_LX_CL_45, true);
flag = true;
}
hodoPatterns.add(pattern);
}
// At leaset there is a hodo tilt/cluster hit in any layer, then the pattern list is added into data manager
if(flag == true && debug) if(debug)System.out.println(this.getClass().getName()+":: outputting "+outputCollectionName+" with size = "+hodoPatterns.size());
if(flag == true) ReadoutDataManager.addData(outputCollectionName, hodoPatterns, HodoscopePattern.class);
}
@Override
public void startOfData() {
// Define the output LCSim collection parameters.
LCIOCollectionFactory.setCollectionName(outputCollectionName);
LCIOCollectionFactory.setProductionDriver(this);
LCIOCollection<HodoscopePattern> patternCollectionParams = LCIOCollectionFactory
.produceLCIOCollection(HodoscopePattern.class);
// Instantiate the GTP cluster collection with the readout
// data manager.
localTimeDisplacement = timeEarlierThanEcal + 4.0;
addDependency(inputCollectionName);
ReadoutDataManager.registerCollection(patternCollectionParams, false);
initLists();
}
/**
* Initiate (layer, y) list and (x, hole) list
*/
private void initLists() {
// Add elements for layer list
layerList.add(TopLayer1);
layerList.add(TopLayer2);
layerList.add(BotLayer1);
layerList.add(BotLayer2);
// Add elements for (x, hole) point list
xHolePointList.add(new Point(0, 0));
xHolePointList.add(new Point(1, -1));
xHolePointList.add(new Point(1, 1));
xHolePointList.add(new Point(2, -1));
xHolePointList.add(new Point(2, 1));
xHolePointList.add(new Point(3, -1));
xHolePointList.add(new Point(3, 1));
xHolePointList.add(new Point(4, 0));
}
@Override
public void detectorChanged(Detector detector) {
// Populate the channel ID collections.
populateChannelCollections();
}
/**
* Populates the channel ID set and maps all existing channels to their
* respective conditions.
*/
private void populateChannelCollections() {
// Load the conditions database and get the hodoscope channel
// collection data.
final DatabaseConditionsManager conditions = DatabaseConditionsManager.getInstance();
final HodoscopeChannelCollection channels = conditions
.getCachedConditions(HodoscopeChannelCollection.class, "hodo_channels").getCachedData();
// Map channels to channel IDs
for (HodoscopeChannel channel : channels) {
channelMap.put(Long.valueOf(channel.getChannelId().intValue()), channel);
}
}
@Override
protected double getTimeDisplacement() {
if(doNoSpacing)
return 0;
else
return localTimeDisplacement;
}
@Override
protected double getTimeNeededForLocalOutput() {
return 0;
}
/**
* Sets the name of the input collection containing the objects of type
* {@link org.lcsim.event.CalorimeterHit CalorimeterHit} that are output by the
* digitization driver.
*
* @param collection - The name of the input hit collection.
*/
public void setInputCollectionName(String collection) {
inputCollectionName = collection;
}
/**
* Sets the name of the output collection containing the objects of type
* {@link org.hps.readout.hodoscope.HodoscopePattern HodoscopePattern} that are
* output by this driver.
*
* @param collection - The name of the output hodoscope pattern collection.
*/
public void setOutputCollectionName(String collection) {
outputCollectionName = collection;
}
/**
* Sets hodoscope FADC hit threshold
*
* @param FADC hit threshold
*/
public void setFADCHitThreshold(double fADCHitThreshold) {
this.fADCHitThreshold = fADCHitThreshold;
}
/**
* Sets hodoscope tilt/cluster hit threshold
*
* @param hodoscope tilt/cluster hit threshold
*/
public void setHodoHitThreshold(double hodoHitThreshold) {
this.hodoHitThreshold = hodoHitThreshold;
}
/**
* Set persistency for hodoscope FADC hit in unit of ns
*
* @param persistency for hodoscope FADC hit in unit of ns
*/
public void setPersistentTime(double persistentTime) {
this.persistentTime = persistentTime;
}
/**
* Set time for hodoscope FADC hits earlier to enter the trigger system than
* Ecal with unit of ns
*
* @param time for hodoscope FADC hits earlier to enter the trigger system than
* Ecal with unit of ns
*/
public void setTimeEarlierThanEcal(double timeEarlierThanEcal) {
this.timeEarlierThanEcal = timeEarlierThanEcal;
}
/**
* Set gain factor for raw energy (self-defined unit) of FADC hits
*
* @param gain factor for raw energy (self-defined unit) of FADC hits
*/
public void setGainFactor(double gainFactor) {
this.gainFactor = gainFactor;
}
}