Skip to content

Commit 666c825

Browse files
authored
adding bar time offsets for the atof (#819)
* feat: added start time reading * feat: reading calib constants for the atof * feat: adding time offset to hit times * fix: order for reference bar time is set to 0 * fix: bar to bar time offset needs to be halved
1 parent 344cd31 commit 666c825

File tree

4 files changed

+127
-35
lines changed

4 files changed

+127
-35
lines changed

reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/ATOFHit.java

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
import org.jlab.geom.base.*;
44
import org.jlab.geom.prim.Point3D;
55
import org.jlab.rec.atof.constants.Parameters;
6-
import java.util.logging.Level;
76
import java.util.logging.Logger;
7+
import org.jlab.detector.calib.utils.DatabaseConstantProvider;
8+
import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory;
9+
import org.jlab.rec.constants.CalibrationConstantsLoader;
810

911
/**
1012
*
@@ -18,9 +20,18 @@
1820
public class ATOFHit {
1921

2022
static final Logger LOGGER = Logger.getLogger(ATOFHit.class.getName());
23+
24+
//For aligning bar together, take module 0, component 10 as the reference
25+
//For now the table is full of things with order = 0 or order = 1 for the bars
26+
//However these offsets are defined uniquely for order 0 and order 1
27+
//Eventually the table will need to be revisited, either by adding another table
28+
//That does not index the order or by indexing things with order 2 (or another number)
29+
private int referenceModuleKey = 0*10000 + 0*1000 + 10*10 + 0;
30+
double[] timeOffsetsRef = CalibrationConstantsLoader.ATOF_TIME_OFFSETS.get(referenceModuleKey);
2131

2232
private int sector, layer, component, order;
2333
private int tdc, tot;
34+
private float startTime;
2435
private double time, energy, x, y, z;
2536
private String type;
2637
private boolean isInACluster;
@@ -184,29 +195,67 @@ public final String makeType() {
184195
* unsupported.
185196
*/
186197
public final int convertTdcToTime() {
187-
double tdc2time, veff, distance_to_sipm;
198+
199+
//Converting tdc to ns, event start time correction
200+
this.time = Parameters.TDC2TIME*this.tdc - this.startTime;
201+
202+
//For now we use order 0 to read everything because the current calib constants
203+
//are not for a specific bar channel
204+
//Eventually this will need to be adjusted
205+
int key = this.sector*10000 + this.layer*1000 + this.component*10 + 0;//this.order;
206+
207+
//Time offsets
208+
double[] timeOffsets = CalibrationConstantsLoader.ATOF_TIME_OFFSETS.get(key);
209+
//The names below correspond to the CCDB entries
210+
//They will most probably evolve
211+
//For now let's say t0 is used to store the bar-to-bar alignment
212+
double t0 = timeOffsets[0];
213+
double tB2B = (t0 - timeOffsetsRef[0])/2;
214+
//tud is used to store the bar up - bar down alignment
215+
double tud = timeOffsets[1];
216+
//The rest of the constants are not used for now
217+
/*double twb = timeOffsets[2];
218+
double xtra1 = timeOffsets[3];
219+
double xtra2 = timeOffsets[4];*/
220+
221+
//TW corrections TO BE IMPLEMENTED
222+
/*
223+
double[] timeWalks = CalibrationConstantsLoader.ATOF_TIME_WALK.get(key);
224+
double tw0 = timeWalks[0];
225+
double tw1 = timeWalks[1];
226+
double tw2 = timeWalks[2];
227+
double tw3 = timeWalks[3];
228+
double dtw0 = timeWalks[4];
229+
double dtw1 = timeWalks[5];
230+
double dtw2 = timeWalks[6];
231+
double dtw3 = timeWalks[7];
232+
double chi2ndf = timeWalks[8];*/
233+
234+
//Veff corrections TO BE IMPLEMENTED
235+
236+
double veff, distance_to_sipm, timeOffset;
188237
if (null == this.type) {
189238
LOGGER.finest("Null hit type, cannot convert tdc to time.");
190239
return 1;
191240
} else {
192241
switch (this.type) {
193242
case "wedge" -> {
194-
tdc2time = Parameters.TDC2TIME;
195243
veff = Parameters.VEFF;
196244
//Wedge hits are placed at the center of wedges and sipm at their top
197245
distance_to_sipm = Parameters.WEDGE_THICKNESS / 2.;
246+
timeOffset = 0; //To be replaced with w2w time and eventual other offsets
198247
}
199248
case "bar up" -> {
200-
tdc2time = Parameters.TDC2TIME;
201249
veff = Parameters.VEFF;
202250
//The distance will be computed at barhit level when z information is available
203251
distance_to_sipm = 0;
252+
timeOffset = - tud/2. - tB2B;
204253
}
205254
case "bar down" -> {
206-
tdc2time = Parameters.TDC2TIME;
207255
veff = Parameters.VEFF;
208256
//The distance will be computed at barhit level when z information is available
209257
distance_to_sipm = 0;
258+
timeOffset = + tud/2. - tB2B;
210259
}
211260
case "bar" -> {
212261
LOGGER.finest("Bar hit type, cannot convert tdc to time.");
@@ -218,8 +267,8 @@ public final int convertTdcToTime() {
218267
}
219268
}
220269
}
221-
//Hit time. Will need implementation of offsets.
222-
this.time = tdc2time * this.tdc - distance_to_sipm / veff;
270+
//Hit time.
271+
this.time = this.time - distance_to_sipm / veff + timeOffset;
223272
return 0;
224273
}
225274

@@ -363,13 +412,14 @@ public double getPhi() {
363412
* @param atof Detector object representing the atof, used to calculate
364413
* spatial coordinates.
365414
*/
366-
public ATOFHit(int sector, int layer, int component, int order, int tdc, int tot, Detector atof) {
415+
public ATOFHit(int sector, int layer, int component, int order, int tdc, int tot, float startTime, Detector atof) {
367416
this.sector = sector;
368417
this.layer = layer;
369418
this.component = component;
370419
this.order = order;
371420
this.tdc = tdc;
372421
this.tot = tot;
422+
this.startTime = startTime;
373423
this.isInACluster = false;
374424

375425
this.makeType();

reconstruction/alert/src/main/java/org/jlab/rec/atof/hit/HitFinder.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ public void findHits(DataEvent event, Detector atof) {
6969
this.wedgeHits.clear();
7070
//They are read from the ATOF TDC bank
7171
DataBank bank = event.getBank("ATOF::tdc");
72+
//Check that the event start time is defined are done in the engine
73+
//if (event.hasBank("REC::Event") &&
74+
// event.getBank("REC::Event").getFloat("startTime", 0)!=-1000)
75+
float startTime = event.getBank("REC::Event").getFloat("startTime", 0);
76+
7277
int nt = bank.rows(); // number of hits
7378
//Hits in the bar downstream and upstream will be matched
7479
ArrayList<ATOFHit> hit_up = new ArrayList<>();
@@ -85,7 +90,7 @@ public void findHits(DataEvent event, Detector atof) {
8590
int tot = bank.getInt("ToT", i);
8691

8792
//Building a Hit
88-
ATOFHit hit = new ATOFHit(sector, layer, component, order, tdc, tot, atof);
93+
ATOFHit hit = new ATOFHit(sector, layer, component, order, tdc, tot, startTime, atof);
8994
if (hit.getEnergy() < 0.01) {
9095
continue; //energy threshold
9196
}

reconstruction/alert/src/main/java/org/jlab/rec/constants/CalibrationConstantsLoader.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -139,20 +139,21 @@ public static synchronized void Load(int runno, ConstantsManager manager) {
139139
int layer = Integer.parseInt((String)atof_timeWalk.getValueAt(i, 1));
140140
int component = Integer.parseInt((String)atof_timeWalk.getValueAt(i, 2));
141141
int order = Integer.parseInt((String)atof_timeWalk.getValueAt(i, 3));
142-
double tw0 = atof_timeWalk.getDoubleValue("tw0", sector, layer, component);
143-
double tw1 = atof_timeWalk.getDoubleValue("tw1", sector, layer, component);
144-
double tw2 = atof_timeWalk.getDoubleValue("tw2", sector, layer, component);
145-
double tw3 = atof_timeWalk.getDoubleValue("tw3", sector, layer, component);
146-
double dtw0 = atof_timeWalk.getDoubleValue("dtw0", sector, layer, component);
147-
double dtw1 = atof_timeWalk.getDoubleValue("dtw1", sector, layer, component);
148-
double dtw2 = atof_timeWalk.getDoubleValue("dtw2", sector, layer, component);
149-
double dtw3 = atof_timeWalk.getDoubleValue("dtw3", sector, layer, component);
150-
double chi2ndf = atof_timeWalk.getDoubleValue("chi2ndf", sector, layer, component);
142+
double tw0 = atof_timeWalk.getDoubleValue("tw0", sector, layer, component, order);
143+
double tw1 = atof_timeWalk.getDoubleValue("tw1", sector, layer, component, order);
144+
double tw2 = atof_timeWalk.getDoubleValue("tw2", sector, layer, component, order);
145+
double tw3 = atof_timeWalk.getDoubleValue("tw3", sector, layer, component, order);
146+
double dtw0 = atof_timeWalk.getDoubleValue("dtw0", sector, layer, component, order);
147+
double dtw1 = atof_timeWalk.getDoubleValue("dtw1", sector, layer, component, order);
148+
double dtw2 = atof_timeWalk.getDoubleValue("dtw2", sector, layer, component, order);
149+
double dtw3 = atof_timeWalk.getDoubleValue("dtw3", sector, layer, component, order);
150+
double chi2ndf = atof_timeWalk.getDoubleValue("chi2ndf", sector, layer, component, order);
151151
// Put in map
152152
int key = sector*10000 + layer*1000 + component*10 + order;
153+
//System.out.println("s " + sector + " l " + layer + " c " + component + " o " + order);
153154
double params[] = {tw0, tw1, tw2, tw3, dtw0, dtw1, dtw2, dtw3, chi2ndf};
154155
ATOF_TIME_WALK.put(Integer.valueOf(key), params);
155-
//System.out.println("tw0 : " + tw0 + " tw1 : " + tw1 + " tw2 : " + tw2 + " tw3 : " + tw3 + " ...");
156+
//System.out.println("tw0 : " + tw0 + " tw1 : " + tw1 + " tw2 : " + tw2 + " tw3 : " + tw3);
156157
}
157158

158159
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -179,11 +180,11 @@ public static synchronized void Load(int runno, ConstantsManager manager) {
179180
int layer = Integer.parseInt((String)atof_timeOffsets.getValueAt(i, 1));
180181
int component = Integer.parseInt((String)atof_timeOffsets.getValueAt(i, 2));
181182
int order = Integer.parseInt((String)atof_timeOffsets.getValueAt(i, 3)); // we have to use it here !
182-
double t0 = atof_timeOffsets.getDoubleValue("t0", sector, layer, component);
183-
double upstream_downstream = atof_timeOffsets.getDoubleValue("upstream_downstream", sector, layer, component);
184-
double wedge_bar = atof_timeOffsets.getDoubleValue("wedge_bar", sector, layer, component);
185-
double extra1 = atof_timeOffsets.getDoubleValue("extra1", sector, layer, component);
186-
double extra2 = atof_timeOffsets.getDoubleValue("extra2", sector, layer, component);
183+
double t0 = atof_timeOffsets.getDoubleValue("t0", sector, layer, component, order);
184+
double upstream_downstream = atof_timeOffsets.getDoubleValue("upstream_downstream", sector, layer, component, order);
185+
double wedge_bar = atof_timeOffsets.getDoubleValue("wedge_bar", sector, layer, component, order);
186+
double extra1 = atof_timeOffsets.getDoubleValue("extra1", sector, layer, component, order);
187+
double extra2 = atof_timeOffsets.getDoubleValue("extra2", sector, layer, component, order);
187188
// Put in map
188189
int key = sector*10000 + layer*1000 + component*10 + order;
189190
double params[] = {t0, upstream_downstream, wedge_bar, extra1, extra2};
@@ -209,6 +210,5 @@ public static final void setDB(DatabaseConstantProvider dB) {
209210
}
210211

211212
public static void main (String arg[]) {
212-
// CalibrationConstantsLoader.Load(10,"default");
213213
}
214214
}

reconstruction/alert/src/main/java/org/jlab/service/atof/ATOFEngine.java

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package org.jlab.service.atof;
22

33
import java.util.ArrayList;
4+
import java.util.Arrays;
5+
import java.util.HashMap;
6+
import java.util.Map;
47

58
import org.jlab.clas.reco.ReconstructionEngine;
69
import org.jlab.io.base.DataBank;
710
import org.jlab.io.base.DataEvent;
811

9-
import java.util.concurrent.atomic.AtomicInteger;
10-
import org.jlab.clas.swimtools.Swim;
1112
import org.jlab.detector.calib.utils.DatabaseConstantProvider;
1213
import org.jlab.geom.base.Detector;
1314
import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory;
@@ -18,6 +19,7 @@
1819
import org.jlab.rec.atof.hit.ATOFHit;
1920
import org.jlab.rec.atof.hit.BarHit;
2021
import org.jlab.rec.atof.hit.HitFinder;
22+
import org.jlab.rec.constants.CalibrationConstantsLoader;
2123
//import org.jlab.rec.alert.projections.TrackProjector;
2224

2325
/**
@@ -34,7 +36,6 @@ public ATOFEngine() {
3436

3537
RecoBankWriter rbc;
3638

37-
private final AtomicInteger run = new AtomicInteger(0);
3839
private Detector ATOF;
3940
private double b; //Magnetic field
4041

@@ -51,23 +52,33 @@ public Detector getATOF() {
5152
return ATOF;
5253
}
5354

55+
int Run = -1;
56+
5457
@Override
5558
public boolean processDataEvent(DataEvent event) {
5659

5760
if (!event.hasBank("RUN::config")) {
5861
return true;
5962
}
60-
61-
DataBank bank = event.getBank("RUN::config");
62-
63-
int newRun = bank.getInt("run", 0);
64-
if (newRun == 0) {
63+
64+
//This assumes the FD reconstruction produced an event with good startTime
65+
//All start time handling could be moved as an EB-type step later
66+
if (!event.hasBank("REC::Event") || event.getBank("REC::Event").getFloat("startTime", 0)==-1000) {
6567
return true;
6668
}
6769

68-
if (run.get() == 0 || (run.get() != 0 && run.get() != newRun)) {
69-
run.set(newRun);
70+
DataBank bank = event.getBank("RUN::config");
71+
72+
int runNo = bank.getInt("run", 0);
73+
if (runNo <= 0) {
74+
System.err.println("ATOFEngine: got run <= 0 in RUN::config, skipping event.");
75+
return false;
7076
}
77+
int newRun = runNo;
78+
// Load the constants
79+
if(Run!=newRun) {
80+
CalibrationConstantsLoader.Load(newRun, this.getConstantsManager());
81+
}
7182

7283
////Do we need to read the event vx,vy,vz?
7384
////If not, this part can be moved in the initialization of the engine.
@@ -116,11 +127,37 @@ public boolean init() {
116127
AlertTOFFactory factory = new AlertTOFFactory();
117128
DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default");
118129
this.ATOF = factory.createDetectorCLAS(cp);
130+
131+
String[] alertTables = new String[] {
132+
"/calibration/alert/ahdc/time_offsets",
133+
"/calibration/alert/ahdc/time_to_distance",
134+
"/calibration/alert/ahdc/raw_hit_cuts",
135+
"/calibration/alert/atof/effective_velocity",
136+
"/calibration/alert/atof/time_walk",
137+
"/calibration/alert/atof/attenuation",
138+
"/calibration/alert/atof/time_offsets"
139+
};
140+
141+
Map<String, Integer> tableMap = new HashMap<>();
142+
for (String table : alertTables) {
143+
if (table.equals("/calibration/alert/atof/time_offsets") ||
144+
table.equals("/calibration/alert/atof/time_walk")) {
145+
tableMap.put(table, 4);
146+
} else {
147+
tableMap.put(table, 3);
148+
}
149+
}
150+
151+
requireConstants(tableMap);
152+
153+
this.getConstantsManager().setVariation("default");
154+
119155
this.registerOutputBank("ATOF::hits", "ATOF::clusters");
120156

121157
return true;
122158
}
123159

124160
public static void main(String arg[]) {
161+
125162
}
126163
}

0 commit comments

Comments
 (0)