Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import org.jlab.geom.base.*;
import org.jlab.geom.prim.Point3D;
import org.jlab.rec.atof.constants.Parameters;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jlab.detector.calib.utils.DatabaseConstantProvider;
import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory;
import org.jlab.rec.constants.CalibrationConstantsLoader;

/**
*
Expand All @@ -18,9 +20,18 @@
public class ATOFHit {

static final Logger LOGGER = Logger.getLogger(ATOFHit.class.getName());

//For aligning bar together, take module 0, component 10 as the reference
//For now the table is full of things with order = 0 or order = 1 for the bars
//However these offsets are defined uniquely for order 0 and order 1
//Eventually the table will need to be revisited, either by adding another table
//That does not index the order or by indexing things with order 2 (or another number)
private int referenceModuleKey = 0*10000 + 0*1000 + 10*10 + 0;
double[] timeOffsetsRef = CalibrationConstantsLoader.ATOF_TIME_OFFSETS.get(referenceModuleKey);

private int sector, layer, component, order;
private int tdc, tot;
private float startTime;
private double time, energy, x, y, z;
private String type;
private boolean isInACluster;
Expand Down Expand Up @@ -184,29 +195,67 @@ public final String makeType() {
* unsupported.
*/
public final int convertTdcToTime() {
double tdc2time, veff, distance_to_sipm;

//Converting tdc to ns, event start time correction
this.time = Parameters.TDC2TIME*this.tdc - this.startTime;

//For now we use order 0 to read everything because the current calib constants
//are not for a specific bar channel
//Eventually this will need to be adjusted
int key = this.sector*10000 + this.layer*1000 + this.component*10 + 0;//this.order;

//Time offsets
double[] timeOffsets = CalibrationConstantsLoader.ATOF_TIME_OFFSETS.get(key);
//The names below correspond to the CCDB entries
//They will most probably evolve
//For now let's say t0 is used to store the bar-to-bar alignment
double t0 = timeOffsets[0];
double tB2B = (t0 - timeOffsetsRef[0])/2;
//tud is used to store the bar up - bar down alignment
double tud = timeOffsets[1];
//The rest of the constants are not used for now
/*double twb = timeOffsets[2];
double xtra1 = timeOffsets[3];
double xtra2 = timeOffsets[4];*/

//TW corrections TO BE IMPLEMENTED
/*
double[] timeWalks = CalibrationConstantsLoader.ATOF_TIME_WALK.get(key);
double tw0 = timeWalks[0];
double tw1 = timeWalks[1];
double tw2 = timeWalks[2];
double tw3 = timeWalks[3];
double dtw0 = timeWalks[4];
double dtw1 = timeWalks[5];
double dtw2 = timeWalks[6];
double dtw3 = timeWalks[7];
double chi2ndf = timeWalks[8];*/

//Veff corrections TO BE IMPLEMENTED

double veff, distance_to_sipm, timeOffset;
if (null == this.type) {
LOGGER.finest("Null hit type, cannot convert tdc to time.");
return 1;
} else {
switch (this.type) {
case "wedge" -> {
tdc2time = Parameters.TDC2TIME;
veff = Parameters.VEFF;
//Wedge hits are placed at the center of wedges and sipm at their top
distance_to_sipm = Parameters.WEDGE_THICKNESS / 2.;
timeOffset = 0; //To be replaced with w2w time and eventual other offsets
}
case "bar up" -> {
tdc2time = Parameters.TDC2TIME;
veff = Parameters.VEFF;
//The distance will be computed at barhit level when z information is available
distance_to_sipm = 0;
timeOffset = - tud/2. - tB2B;
}
case "bar down" -> {
tdc2time = Parameters.TDC2TIME;
veff = Parameters.VEFF;
//The distance will be computed at barhit level when z information is available
distance_to_sipm = 0;
timeOffset = + tud/2. - tB2B;
}
case "bar" -> {
LOGGER.finest("Bar hit type, cannot convert tdc to time.");
Expand All @@ -218,8 +267,8 @@ public final int convertTdcToTime() {
}
}
}
//Hit time. Will need implementation of offsets.
this.time = tdc2time * this.tdc - distance_to_sipm / veff;
//Hit time.
this.time = this.time - distance_to_sipm / veff + timeOffset;
return 0;
}

Expand Down Expand Up @@ -363,13 +412,14 @@ public double getPhi() {
* @param atof Detector object representing the atof, used to calculate
* spatial coordinates.
*/
public ATOFHit(int sector, int layer, int component, int order, int tdc, int tot, Detector atof) {
public ATOFHit(int sector, int layer, int component, int order, int tdc, int tot, float startTime, Detector atof) {
this.sector = sector;
this.layer = layer;
this.component = component;
this.order = order;
this.tdc = tdc;
this.tot = tot;
this.startTime = startTime;
this.isInACluster = false;

this.makeType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ public void findHits(DataEvent event, Detector atof) {
this.wedgeHits.clear();
//They are read from the ATOF TDC bank
DataBank bank = event.getBank("ATOF::tdc");
//Check that the event start time is defined are done in the engine
//if (event.hasBank("REC::Event") &&
// event.getBank("REC::Event").getFloat("startTime", 0)!=-1000)
float startTime = event.getBank("REC::Event").getFloat("startTime", 0);

int nt = bank.rows(); // number of hits
//Hits in the bar downstream and upstream will be matched
ArrayList<ATOFHit> hit_up = new ArrayList<>();
Expand All @@ -85,7 +90,7 @@ public void findHits(DataEvent event, Detector atof) {
int tot = bank.getInt("ToT", i);

//Building a Hit
ATOFHit hit = new ATOFHit(sector, layer, component, order, tdc, tot, atof);
ATOFHit hit = new ATOFHit(sector, layer, component, order, tdc, tot, startTime, atof);
if (hit.getEnergy() < 0.01) {
continue; //energy threshold
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,20 +139,21 @@ public static synchronized void Load(int runno, ConstantsManager manager) {
int layer = Integer.parseInt((String)atof_timeWalk.getValueAt(i, 1));
int component = Integer.parseInt((String)atof_timeWalk.getValueAt(i, 2));
int order = Integer.parseInt((String)atof_timeWalk.getValueAt(i, 3));
double tw0 = atof_timeWalk.getDoubleValue("tw0", sector, layer, component);
double tw1 = atof_timeWalk.getDoubleValue("tw1", sector, layer, component);
double tw2 = atof_timeWalk.getDoubleValue("tw2", sector, layer, component);
double tw3 = atof_timeWalk.getDoubleValue("tw3", sector, layer, component);
double dtw0 = atof_timeWalk.getDoubleValue("dtw0", sector, layer, component);
double dtw1 = atof_timeWalk.getDoubleValue("dtw1", sector, layer, component);
double dtw2 = atof_timeWalk.getDoubleValue("dtw2", sector, layer, component);
double dtw3 = atof_timeWalk.getDoubleValue("dtw3", sector, layer, component);
double chi2ndf = atof_timeWalk.getDoubleValue("chi2ndf", sector, layer, component);
double tw0 = atof_timeWalk.getDoubleValue("tw0", sector, layer, component, order);
double tw1 = atof_timeWalk.getDoubleValue("tw1", sector, layer, component, order);
double tw2 = atof_timeWalk.getDoubleValue("tw2", sector, layer, component, order);
double tw3 = atof_timeWalk.getDoubleValue("tw3", sector, layer, component, order);
double dtw0 = atof_timeWalk.getDoubleValue("dtw0", sector, layer, component, order);
double dtw1 = atof_timeWalk.getDoubleValue("dtw1", sector, layer, component, order);
double dtw2 = atof_timeWalk.getDoubleValue("dtw2", sector, layer, component, order);
double dtw3 = atof_timeWalk.getDoubleValue("dtw3", sector, layer, component, order);
double chi2ndf = atof_timeWalk.getDoubleValue("chi2ndf", sector, layer, component, order);
// Put in map
int key = sector*10000 + layer*1000 + component*10 + order;
//System.out.println("s " + sector + " l " + layer + " c " + component + " o " + order);
double params[] = {tw0, tw1, tw2, tw3, dtw0, dtw1, dtw2, dtw3, chi2ndf};
ATOF_TIME_WALK.put(Integer.valueOf(key), params);
//System.out.println("tw0 : " + tw0 + " tw1 : " + tw1 + " tw2 : " + tw2 + " tw3 : " + tw3 + " ...");
//System.out.println("tw0 : " + tw0 + " tw1 : " + tw1 + " tw2 : " + tw2 + " tw3 : " + tw3);
}

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

public static void main (String arg[]) {
// CalibrationConstantsLoader.Load(10,"default");
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package org.jlab.service.atof;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import org.jlab.clas.reco.ReconstructionEngine;
import org.jlab.io.base.DataBank;
import org.jlab.io.base.DataEvent;

import java.util.concurrent.atomic.AtomicInteger;
import org.jlab.clas.swimtools.Swim;
import org.jlab.detector.calib.utils.DatabaseConstantProvider;
import org.jlab.geom.base.Detector;
import org.jlab.geom.detector.alert.ATOF.AlertTOFFactory;
Expand All @@ -18,6 +19,7 @@
import org.jlab.rec.atof.hit.ATOFHit;
import org.jlab.rec.atof.hit.BarHit;
import org.jlab.rec.atof.hit.HitFinder;
import org.jlab.rec.constants.CalibrationConstantsLoader;
//import org.jlab.rec.alert.projections.TrackProjector;

/**
Expand All @@ -34,7 +36,6 @@ public ATOFEngine() {

RecoBankWriter rbc;

private final AtomicInteger run = new AtomicInteger(0);
private Detector ATOF;
private double b; //Magnetic field

Expand All @@ -51,23 +52,33 @@ public Detector getATOF() {
return ATOF;
}

int Run = -1;

@Override
public boolean processDataEvent(DataEvent event) {

if (!event.hasBank("RUN::config")) {
return true;
}

DataBank bank = event.getBank("RUN::config");

int newRun = bank.getInt("run", 0);
if (newRun == 0) {

//This assumes the FD reconstruction produced an event with good startTime
//All start time handling could be moved as an EB-type step later
if (!event.hasBank("REC::Event") || event.getBank("REC::Event").getFloat("startTime", 0)==-1000) {
return true;
}

if (run.get() == 0 || (run.get() != 0 && run.get() != newRun)) {
run.set(newRun);
DataBank bank = event.getBank("RUN::config");

int runNo = bank.getInt("run", 0);
if (runNo <= 0) {
System.err.println("ATOFEngine: got run <= 0 in RUN::config, skipping event.");
return false;
}
int newRun = runNo;
// Load the constants
if(Run!=newRun) {
CalibrationConstantsLoader.Load(newRun, this.getConstantsManager());
}

////Do we need to read the event vx,vy,vz?
////If not, this part can be moved in the initialization of the engine.
Expand Down Expand Up @@ -116,11 +127,37 @@ public boolean init() {
AlertTOFFactory factory = new AlertTOFFactory();
DatabaseConstantProvider cp = new DatabaseConstantProvider(11, "default");
this.ATOF = factory.createDetectorCLAS(cp);

String[] alertTables = new String[] {
"/calibration/alert/ahdc/time_offsets",
"/calibration/alert/ahdc/time_to_distance",
"/calibration/alert/ahdc/raw_hit_cuts",
"/calibration/alert/atof/effective_velocity",
"/calibration/alert/atof/time_walk",
"/calibration/alert/atof/attenuation",
"/calibration/alert/atof/time_offsets"
};

Map<String, Integer> tableMap = new HashMap<>();
for (String table : alertTables) {
if (table.equals("/calibration/alert/atof/time_offsets") ||
table.equals("/calibration/alert/atof/time_walk")) {
tableMap.put(table, 4);
} else {
tableMap.put(table, 3);
}
}

requireConstants(tableMap);

this.getConstantsManager().setVariation("default");

this.registerOutputBank("ATOF::hits", "ATOF::clusters");

return true;
}

public static void main(String arg[]) {

}
}