diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/AI/ModelTrackFinding.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/AI/ModelTrackFinding.java index 3da8939071..8a2ebb7d23 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/AI/ModelTrackFinding.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/AI/ModelTrackFinding.java @@ -49,7 +49,7 @@ public NDList processInput(TranslatorContext translatorContext, float[] floats) .optTranslator(my_translator) .optProgress(new ProgressBar()) .build(); - + try { model = my_model.loadModel(); diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Hit/HitReader.java b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Hit/HitReader.java index 3636fe8c70..20f72bde1b 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Hit/HitReader.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/ahdc/Hit/HitReader.java @@ -10,119 +10,201 @@ public class HitReader { - private ArrayList _AHDCHits; - private ArrayList _TrueAHDCHits; - private boolean sim = false; - - public HitReader(DataEvent event, AlertDCDetector detector, boolean simulation) { - sim = simulation; - fetch_AHDCHits(event, detector); - if (simulation) fetch_TrueAHDCHits(event); - } - - public final void fetch_AHDCHits(DataEvent event, AlertDCDetector detector) { - ArrayList hits = new ArrayList<>(); - - - if (event.hasBank("AHDC::adc")) { - // Useful if one does not run the full CLAS12 reconstrcution - // i.e only run the reconstruction of ALERT - // or use simulated data - double startTime = 0; - if (event.hasBank("REC::Event") && !sim) { - DataBank bankRecEvent = event.getBank("REC::Event"); - startTime = bankRecEvent.getFloat("startTime", 0); - } - - RawDataBank bankDGTZ = new RawDataBank("AHDC::adc"); - bankDGTZ.read(event); - - for (int i = 0; i < bankDGTZ.rows(); i++) { - int id = bankDGTZ.trueIndex(i) + 1; - int number = bankDGTZ.getByte("layer", i); - int layer = number % 10; - int superlayer = (int) (number % 100) / 10; - int sector = bankDGTZ.getInt("sector", i); - int wire = bankDGTZ.getShort("component", i); - double adc = bankDGTZ.getInt("ADC", i); - double leadingEdgeTime = bankDGTZ.getFloat("leadingEdgeTime", i); - double timeOverThreshold = bankDGTZ.getFloat("timeOverThreshold", i); - double adcOffset = bankDGTZ.getFloat("ped", i); - int wfType = bankDGTZ.getShort("wfType", i); - // Retrieve raw hit cuts from CCDB - int key_value = sector*10000 + number*100 + wire; - double[] rawHitCuts = CalibrationConstantsLoader.AHDC_RAW_HIT_CUTS.get( key_value ); - double t_min = rawHitCuts[0]; - double t_max = rawHitCuts[1]; - double tot_min = rawHitCuts[2]; - double tot_max = rawHitCuts[3]; - double adc_min = rawHitCuts[4]; - double adc_max = rawHitCuts[5]; - double ped_min = rawHitCuts[6]; - double ped_max = rawHitCuts[7]; - //System.out.println("t_min : " + t_min + " t_max : " + t_max + " tot_min : " + tot_min + " tot_max : " + tot_max + " adc_min : " + adc_min + " adc_max : " + adc_max + " ped_min : " + ped_min + " ped_max : " + ped_max); - // Retrieve t0 and t2d from CCDB - // What's about simulation? - double[] timeOffsets = CalibrationConstantsLoader.AHDC_TIME_OFFSETS.get( key_value ); - double[] time2distance = CalibrationConstantsLoader.AHDC_TIME_TO_DISTANCE.get( 10101 ); // the time to distance table has only one row ! (10101 is its only key) - double t0 = timeOffsets[0]; - double p0 = time2distance[0]; - double p1 = time2distance[1]; - double p2 = time2distance[2]; - double p3 = time2distance[3]; - double p4 = time2distance[4]; - double p5 = time2distance[5]; - // Apply time calibration - // We may need adc calibration too - // Remark: leadingEdgeTime already has the fine timestamp correction - double time = leadingEdgeTime - t0 - startTime; - - // Hit selection : wfType and additional cuts - if (((wfType <= 2) && (adc >= adc_min) && (adc <= adc_max) && (time >= t_min) && (time <= t_max) && (timeOverThreshold >= tot_min) && (timeOverThreshold <= tot_max) && (adcOffset >= ped_min) && (adcOffset <= ped_max)) || sim) { - double doca = p0 + p1*Math.pow(time,1.0) + p2*Math.pow(time,2.0) + p3*Math.pow(time,3.0) + p4*Math.pow(time,4.0) + p5*Math.pow(time, 5.0); - if (time < 0) doca = 0; - Hit h = new Hit(id, superlayer, layer, wire, doca, adc, time); - h.setWirePosition(detector); - hits.add(h); - } - } - } - this.set_AHDCHits(hits); - } - - public final void fetch_TrueAHDCHits(DataEvent event) { - ArrayList truehits = new ArrayList<>(); - - DataBank bankSIMU = event.getBank("MC::True"); - - if (event.hasBank("MC::True")) { - for (int i = 0; i < bankSIMU.rows(); i++) { - int pid = bankSIMU.getInt("pid", i); - double x_true = bankSIMU.getFloat("avgX", i); - double y_true = bankSIMU.getFloat("avgY", i); - double z_true = bankSIMU.getFloat("avgZ", i); - double trackE = bankSIMU.getFloat("trackE", i); - - truehits.add(new TrueHit(pid, x_true, y_true, z_true, trackE)); - } - } - this.set_TrueAHDCHits(truehits); - } - - public ArrayList get_AHDCHits() { - return _AHDCHits; - } - - public void set_AHDCHits(ArrayList _AHDCHits) { - this._AHDCHits = _AHDCHits; - } - - public ArrayList get_TrueAHDCHits() { - return _TrueAHDCHits; - } - - public void set_TrueAHDCHits(ArrayList _TrueAHDCHits) { - this._TrueAHDCHits = _TrueAHDCHits; - } - + private ArrayList _AHDCHits; + private ArrayList _TrueAHDCHits; + private boolean sim = false; + + public HitReader(DataEvent event, AlertDCDetector detector, boolean simulation) { + sim = simulation; + fetch_AHDCHits(event, detector); + if (simulation) fetch_TrueAHDCHits(event); + } + + public final void fetch_AHDCHits(DataEvent event, AlertDCDetector detector) { + + ArrayList hits = new ArrayList<>(); + + if (!event.hasBank("AHDC::adc")) { + this.set_AHDCHits(hits); + return; + } + + double startTime = 0.0; + if (event.hasBank("REC::Event") && !sim) { + DataBank bankRecEvent = event.getBank("REC::Event"); + startTime = bankRecEvent.getFloat("startTime", 0); + } + + RawDataBank bankDGTZ = new RawDataBank("AHDC::adc"); + bankDGTZ.read(event); + + for (int i = 0; i < bankDGTZ.rows(); i++) { + + int id = bankDGTZ.trueIndex(i) + 1; + int number = bankDGTZ.getByte("layer", i); // e.g. 11,12,21,... (this matches CCDB "layer") + int layer = number % 10; + int superlayer = (number % 100) / 10; + int sector = bankDGTZ.getInt("sector", i); + int wire = bankDGTZ.getShort("component", i); + + // RAW quantities from bank + double adcRaw = bankDGTZ.getInt("ADC", i); + double leadingEdgeTime = bankDGTZ.getFloat("leadingEdgeTime", i); + double timeOverThreshold = bankDGTZ.getFloat("timeOverThreshold", i); + double adcOffset = bankDGTZ.getFloat("ped", i); + int wfType = bankDGTZ.getShort("wfType", i); + + // CCDB key + int key_value = sector * 10000 + number * 100 + wire; + + // ----------------------------- + // Raw hit cuts + // ----------------------------- + // double[] rawHitCuts = CalibrationConstantsLoader.AHDC_RAW_HIT_CUTS.get(key_value); + //if (rawHitCuts == null) continue; + + + double[] rawHitCuts = CalibrationConstantsLoader.AHDC_RAW_HIT_CUTS.get(key_value); + if (rawHitCuts == null) {throw new IllegalStateException("Missing CCDB table /calibration/alert/ahdc/raw_hit_cuts for key=" + key_value+ " (check run/variation + key mapping)"); + } + + double t_min = rawHitCuts[0]; + double t_max = rawHitCuts[1]; + double tot_min = rawHitCuts[2]; + double tot_max = rawHitCuts[3]; + double adc_min = rawHitCuts[4]; + double adc_max = rawHitCuts[5]; + double ped_min = rawHitCuts[6]; + double ped_max = rawHitCuts[7]; + + // ----------------------------- + // Time calibration + t->d + // ----------------------------- + //double[] timeOffsets = CalibrationConstantsLoader.AHDC_TIME_OFFSETS.get(key_value); + //if (timeOffsets == null) continue; + + // double[] timeOffsets = CalibrationConstantsLoader.AHDC_TIME_OFFSETS.get(key_value); + //if (timeOffsets == null) { + //throw new IllegalStateException("Missing AHDC time_offsets for key=" + key_value); + //} + + double[] timeOffsets = CalibrationConstantsLoader.AHDC_TIME_OFFSETS.get(key_value); + + if (timeOffsets == null) { + throw new IllegalStateException("Missing CCDB /calibration/alert/ahdc/time_offsets for key=" + key_value + " (check run/variation + key mapping)"); + } + + + + + double[] time2distance = CalibrationConstantsLoader.AHDC_TIME_TO_DISTANCE.get(10101); + if (time2distance == null) continue; + + double t0 = timeOffsets[0]; + + double p0 = time2distance[0]; + double p1 = time2distance[1]; + double p2 = time2distance[2]; + double p3 = time2distance[3]; + double p4 = time2distance[4]; + double p5 = time2distance[5]; + + double time = leadingEdgeTime - t0 - startTime; + + // ----------------------------- + // ToT correction (new CCDB) + // convention: ToT_corr = ToT_raw * totCorr + // ----------------------------- + double totUsed = timeOverThreshold; + if (!sim) { + double[] totArr = CalibrationConstantsLoader.AHDC_TIME_OVER_THRESHOLD.get(key_value); + if (totArr != null && totArr.length > 0) { + double totCorr = totArr[0]; + totUsed = timeOverThreshold * totCorr; + } + } + + // ----------------------------- + // Hit selection (cuts) + // NOTE: we cut on totUsed (corrected ToT). If you want RAW-ToT cuts, + // replace totUsed with timeOverThreshold in the condition. + // ----------------------------- + boolean passCuts = + (wfType <= 2) && + (adcRaw >= adc_min) && (adcRaw <= adc_max) && + (time >= t_min) && (time <= t_max) && + (timeOverThreshold >= tot_min) && (timeOverThreshold <= tot_max)&& + //(totUsed >= tot_min) && (totUsed <= tot_max) && + (adcOffset >= ped_min) && (adcOffset <= ped_max); + + if (!passCuts && !sim) continue; + + // ----------------------------- + // DOCA from calibrated time + // ----------------------------- + double doca = p0 + + p1*Math.pow(time, 1.0) + + p2*Math.pow(time, 2.0) + + p3*Math.pow(time, 3.0) + + p4*Math.pow(time, 4.0) + + p5*Math.pow(time, 5.0); + + if (time < 0) doca = 0.0; + + // ----------------------------- + // ADC gain calibration (new gains schema: gainCorr is index 0) + // convention: ADC_cal = ADC_raw * gainCorr + // ----------------------------- + double adcCal = adcRaw; + if (!sim) { + double[] gainArr = CalibrationConstantsLoader.AHDC_ADC_GAINS.get(key_value); + if (gainArr != null && gainArr.length > 0) { + double gainCorr = gainArr[0]; + adcCal = adcRaw * gainCorr; + } + } + + Hit h = new Hit(id, superlayer, layer, wire, doca, adcCal, time); + h.setWirePosition(detector); + hits.add(h); + } + + this.set_AHDCHits(hits); + } + + public final void fetch_TrueAHDCHits(DataEvent event) { + + ArrayList truehits = new ArrayList<>(); + + if (event.hasBank("MC::True")) { + DataBank bankSIMU = event.getBank("MC::True"); + for (int i = 0; i < bankSIMU.rows(); i++) { + int pid = bankSIMU.getInt("pid", i); + double x_true = bankSIMU.getFloat("avgX", i); + double y_true = bankSIMU.getFloat("avgY", i); + double z_true = bankSIMU.getFloat("avgZ", i); + double trackE = bankSIMU.getFloat("trackE", i); + + truehits.add(new TrueHit(pid, x_true, y_true, z_true, trackE)); + } + } + + this.set_TrueAHDCHits(truehits); + } + + public ArrayList get_AHDCHits() { + return _AHDCHits; + } + + public void set_AHDCHits(ArrayList hits) { + this._AHDCHits = hits; + } + + public ArrayList get_TrueAHDCHits() { + return _TrueAHDCHits; + } + + public void set_TrueAHDCHits(ArrayList trueHits) { + this._TrueAHDCHits = trueHits; + } } diff --git a/reconstruction/alert/src/main/java/org/jlab/rec/alert/constants/CalibrationConstantsLoader.java b/reconstruction/alert/src/main/java/org/jlab/rec/alert/constants/CalibrationConstantsLoader.java index 032c72a066..0da9fef09c 100644 --- a/reconstruction/alert/src/main/java/org/jlab/rec/alert/constants/CalibrationConstantsLoader.java +++ b/reconstruction/alert/src/main/java/org/jlab/rec/alert/constants/CalibrationConstantsLoader.java @@ -9,206 +9,296 @@ /** * This class loads constants from CCDB - * + * * inspired by the one of the BAND subsystem - * + * * @author ftouchte */ - public class CalibrationConstantsLoader { - public CalibrationConstantsLoader() { - // TODO Auto-generated constructor stub - } - public static boolean CSTLOADED = false; + public CalibrationConstantsLoader() { + // default ctor + } + + public static boolean CSTLOADED = false; + + // Maps for constants from database + // AHDC + public static Map AHDC_TIME_OFFSETS = new HashMap<>(); ///< {t0,dt0,extra1,extra2,chi2ndf} + public static Map AHDC_TIME_TO_DISTANCE = new HashMap<>(); ///< {p0..p5, dp0..dp5, chi2ndf} + public static Map AHDC_RAW_HIT_CUTS = new HashMap<>(); ///< {t_min,t_max,tot_min,tot_max,adc_min,adc_max,ped_min,ped_max} + + // UPDATED SCHEMA: keys (sector,layer,component), columns: gainCorr,dgainCorr,extra1,extra2,extra3 + public static Map AHDC_ADC_GAINS = new HashMap<>(); ///< {gainCorr, dgainCorr, extra1, extra2, extra3} + + // NEW ToT TABLE: keys (sector,layer,component), columns: totCorr,dtotCorr,extra1,extra2,extra3 + public static Map AHDC_TIME_OVER_THRESHOLD = new HashMap<>(); ///< {totCorr, dtotCorr, extra1, extra2, extra3} + + // ATOF + public static Map ATOF_EFFECTIVE_VELOCITY = new HashMap<>(); ///< {veff,dveff,extra1,extra2} + public static Map ATOF_TIME_WALK = new HashMap<>(); ///< {tw0..tw3, dtw0..dtw3, chi2ndf} + public static Map ATOF_ATTENUATION_LENGTH = new HashMap<>(); ///< {attlen,dattlen,extra1,extra2} + public static Map ATOF_TIME_OFFSETS = new HashMap<>(); ///< {t0,upstream_downstream,wedge_bar,extra1,extra2} + + public static synchronized void Load(int runno, ConstantsManager manager) { + + if (CSTLOADED) return; + + IndexedTable ahdc_timeOffsets = manager.getConstants(runno, "/calibration/alert/ahdc/time_offsets"); + IndexedTable ahdc_time2distance = manager.getConstants(runno, "/calibration/alert/ahdc/time_to_distance"); + IndexedTable ahdc_rawHitCuts = manager.getConstants(runno, "/calibration/alert/ahdc/raw_hit_cuts"); + + // Gains table (UPDATED SCHEMA) + IndexedTable ahdc_adcGains = manager.getConstants(runno, "/calibration/alert/ahdc/gains"); + + // NEW ToT table + IndexedTable ahdc_timeOverThreshold = manager.getConstants(runno, "/calibration/alert/ahdc/time_over_threshold"); + + IndexedTable atof_effectiveVelocity = manager.getConstants(runno, "/calibration/alert/atof/effective_velocity"); + IndexedTable atof_timeWalk = manager.getConstants(runno, "/calibration/alert/atof/time_walk"); + IndexedTable atof_attenuationLength = manager.getConstants(runno, "/calibration/alert/atof/attenuation"); + IndexedTable atof_timeOffsets = manager.getConstants(runno, "/calibration/alert/atof/time_offsets"); + + //////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // AHDC time offsets + for (int i = 0; i < ahdc_timeOffsets.getRowCount(); i++) { + int sector = Integer.parseInt((String) ahdc_timeOffsets.getValueAt(i, 0)); + int layer = Integer.parseInt((String) ahdc_timeOffsets.getValueAt(i, 1)); + int component = Integer.parseInt((String) ahdc_timeOffsets.getValueAt(i, 2)); + + double t0 = ahdc_timeOffsets.getDoubleValue("t0", sector, layer, component); + double dt0 = ahdc_timeOffsets.getDoubleValue("dt0", sector, layer, component); + double extra1 = ahdc_timeOffsets.getDoubleValue("extra1", sector, layer, component); + double extra2 = ahdc_timeOffsets.getDoubleValue("extra2", sector, layer, component); + double chi2ndf = ahdc_timeOffsets.getDoubleValue("chi2ndf", sector, layer, component); + + int key = sector * 10000 + layer * 100 + component; + double params[] = { t0, dt0, extra1, extra2, chi2ndf }; + AHDC_TIME_OFFSETS.put(Integer.valueOf(key), params); + } + + //////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // AHDC time to distance + // Caution, this table has only one row + // the corresponding identifiers are (sector, layer, component) == (1,1,1) + // but it applies for all AHDC wires ! + for (int i = 0; i < ahdc_time2distance.getRowCount(); i++) { + int sector = Integer.parseInt((String) ahdc_time2distance.getValueAt(i, 0)); + int layer = Integer.parseInt((String) ahdc_time2distance.getValueAt(i, 1)); + int component = Integer.parseInt((String) ahdc_time2distance.getValueAt(i, 2)); + + double p0 = ahdc_time2distance.getDoubleValue("p0", sector, layer, component); + double p1 = ahdc_time2distance.getDoubleValue("p1", sector, layer, component); + double p2 = ahdc_time2distance.getDoubleValue("p2", sector, layer, component); + double p3 = ahdc_time2distance.getDoubleValue("p3", sector, layer, component); + double p4 = ahdc_time2distance.getDoubleValue("p4", sector, layer, component); + double p5 = ahdc_time2distance.getDoubleValue("p5", sector, layer, component); + double dp0 = ahdc_time2distance.getDoubleValue("dp0", sector, layer, component); + double dp1 = ahdc_time2distance.getDoubleValue("dp1", sector, layer, component); + double dp2 = ahdc_time2distance.getDoubleValue("dp2", sector, layer, component); + double dp3 = ahdc_time2distance.getDoubleValue("dp3", sector, layer, component); + double dp4 = ahdc_time2distance.getDoubleValue("dp4", sector, layer, component); + double dp5 = ahdc_time2distance.getDoubleValue("dp5", sector, layer, component); + double chi2ndf = ahdc_time2distance.getDoubleValue("chi2ndf", sector, layer, component); + + int key = sector * 10000 + layer * 100 + component; + double params[] = { p0, p1, p2, p3, p4, p5, dp0, dp1, dp2, dp3, dp4, dp5, chi2ndf }; + AHDC_TIME_TO_DISTANCE.put(Integer.valueOf(key), params); + } + + //////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // AHDC raw hit cuts + for (int i = 0; i < ahdc_rawHitCuts.getRowCount(); i++) { + int sector = Integer.parseInt((String) ahdc_rawHitCuts.getValueAt(i, 0)); + int layer = Integer.parseInt((String) ahdc_rawHitCuts.getValueAt(i, 1)); + int component = Integer.parseInt((String) ahdc_rawHitCuts.getValueAt(i, 2)); + + double t_min = ahdc_rawHitCuts.getDoubleValue("t_min", sector, layer, component); + double t_max = ahdc_rawHitCuts.getDoubleValue("t_max", sector, layer, component); + double tot_min = ahdc_rawHitCuts.getDoubleValue("tot_min", sector, layer, component); + double tot_max = ahdc_rawHitCuts.getDoubleValue("tot_max", sector, layer, component); + double adc_min = ahdc_rawHitCuts.getDoubleValue("adc_min", sector, layer, component); + double adc_max = ahdc_rawHitCuts.getDoubleValue("adc_max", sector, layer, component); + double ped_min = ahdc_rawHitCuts.getDoubleValue("ped_min", sector, layer, component); + double ped_max = ahdc_rawHitCuts.getDoubleValue("ped_max", sector, layer, component); + + int key = sector * 10000 + layer * 100 + component; + double params[] = { t_min, t_max, tot_min, tot_max, adc_min, adc_max, ped_min, ped_max }; + AHDC_RAW_HIT_CUTS.put(Integer.valueOf(key), params); + } - // Maps for constants from database - // AHDC - public static Map AHDC_TIME_OFFSETS = new HashMap<>(); ///< AHDC Parameters for timing offsets - public static Map AHDC_TIME_TO_DISTANCE = new HashMap<>(); ///< AHDC Parameters for time to distance - public static Map AHDC_RAW_HIT_CUTS = new HashMap<>(); ///< AHDC Parameters for raw hit cuts - // ATOF - public static Map ATOF_EFFECTIVE_VELOCITY = new HashMap<>(); ///< ATOF Parameters for effective velocity - public static Map ATOF_TIME_WALK = new HashMap<>(); ///< ATOF Parameters for time walk - public static Map ATOF_ATTENUATION_LENGTH = new HashMap<>(); ///< ATOF Parameters for attenuation lenght - public static Map ATOF_TIME_OFFSETS = new HashMap<>(); ///< ATOF Parameters for timing offsets - - public static synchronized void Load(int runno, ConstantsManager manager) { - - //System.out.println("*Loading calibration constants*"); - - IndexedTable ahdc_timeOffsets = manager.getConstants(runno, "/calibration/alert/ahdc/time_offsets"); - IndexedTable ahdc_time2distance = manager.getConstants(runno, "/calibration/alert/ahdc/time_to_distance"); - IndexedTable ahdc_rawHitCuts = manager.getConstants(runno, "/calibration/alert/ahdc/raw_hit_cuts"); - IndexedTable atof_effectiveVelocity = manager.getConstants(runno, "/calibration/alert/atof/effective_velocity"); - IndexedTable atof_timeWalk = manager.getConstants(runno, "/calibration/alert/atof/time_walk"); - IndexedTable atof_attenuationLength = manager.getConstants(runno, "/calibration/alert/atof/attenuation"); - IndexedTable atof_timeOffsets = manager.getConstants(runno, "/calibration/alert/atof/time_offsets"); - - - //////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // AHDC time offsets - for( int i = 0; i < ahdc_timeOffsets.getRowCount(); i++){ - int sector = Integer.parseInt((String)ahdc_timeOffsets.getValueAt(i, 0)); - int layer = Integer.parseInt((String)ahdc_timeOffsets.getValueAt(i, 1)); - int component = Integer.parseInt((String)ahdc_timeOffsets.getValueAt(i, 2)); - double t0 = ahdc_timeOffsets.getDoubleValue("t0", sector, layer, component); - double dt0 = ahdc_timeOffsets.getDoubleValue("dt0", sector, layer, component); - double extra1 = ahdc_timeOffsets.getDoubleValue("extra1", sector, layer, component); - double extra2 = ahdc_timeOffsets.getDoubleValue("extra2", sector, layer, component); - double chi2ndf = ahdc_timeOffsets.getDoubleValue("chi2ndf", sector, layer, component); - // Put in map - int key = sector*10000 + layer*100 + component; - double params[] = {t0, dt0, extra1, extra2, chi2ndf}; - AHDC_TIME_OFFSETS.put(Integer.valueOf(key), params); - //System.out.println("t0 : " + t0 + " dt0 : " + dt0 + " extra1 : " + extra1 + " extra2 : " + extra2 + " chi2ndf : " + chi2ndf); - } - - //////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // AHDC time to distance - // Caution, this table has only one row - // the corresponding identifers are (sector, layer, component) == (1,1,1) - // but it applies for all AHDC wires ! - for( int i = 0; i < ahdc_time2distance.getRowCount(); i++){ - int sector = Integer.parseInt((String)ahdc_time2distance.getValueAt(i, 0)); - int layer = Integer.parseInt((String)ahdc_time2distance.getValueAt(i, 1)); - int component = Integer.parseInt((String)ahdc_time2distance.getValueAt(i, 2)); - double p0 = ahdc_time2distance.getDoubleValue("p0", sector, layer, component); - double p1 = ahdc_time2distance.getDoubleValue("p1", sector, layer, component); - double p2 = ahdc_time2distance.getDoubleValue("p2", sector, layer, component); - double p3 = ahdc_time2distance.getDoubleValue("p3", sector, layer, component); - double p4 = ahdc_time2distance.getDoubleValue("p4", sector, layer, component); - double p5 = ahdc_time2distance.getDoubleValue("p5", sector, layer, component); - double dp0 = ahdc_time2distance.getDoubleValue("dp0", sector, layer, component); - double dp1 = ahdc_time2distance.getDoubleValue("dp1", sector, layer, component); - double dp2 = ahdc_time2distance.getDoubleValue("dp2", sector, layer, component); - double dp3 = ahdc_time2distance.getDoubleValue("dp3", sector, layer, component); - double dp4 = ahdc_time2distance.getDoubleValue("dp4", sector, layer, component); - double dp5 = ahdc_time2distance.getDoubleValue("dp5", sector, layer, component); - double chi2ndf = ahdc_time2distance.getDoubleValue("chi2ndf", sector, layer, component); - // Put in map - int key = sector*10000 + layer*100 + component; - double params[] = {p0, p1, p2, p3, p4, p5, dp0, dp1, dp2, dp3, dp4, dp5, chi2ndf}; - AHDC_TIME_TO_DISTANCE.put(Integer.valueOf(key), params); - //System.out.println("p0 : " + p0 + " p1 : " + p1 + " p2 : " + p2 + " p3 : " + p3 + " p4 : " + p4 + " p5 : " + p5); - } - - //////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // AHDC raw hit cuts - for( int i = 0; i < ahdc_rawHitCuts.getRowCount(); i++){ - int sector = Integer.parseInt((String)ahdc_rawHitCuts.getValueAt(i, 0)); - int layer = Integer.parseInt((String)ahdc_rawHitCuts.getValueAt(i, 1)); - int component = Integer.parseInt((String)ahdc_rawHitCuts.getValueAt(i, 2)); - double t_min = ahdc_rawHitCuts.getDoubleValue("t_min", sector, layer, component); - double t_max = ahdc_rawHitCuts.getDoubleValue("t_max", sector, layer, component); - double tot_min = ahdc_rawHitCuts.getDoubleValue("tot_min", sector, layer, component); - double tot_max = ahdc_rawHitCuts.getDoubleValue("tot_max", sector, layer, component); - double adc_min = ahdc_rawHitCuts.getDoubleValue("adc_min", sector, layer, component); - double adc_max = ahdc_rawHitCuts.getDoubleValue("adc_max", sector, layer, component); - double ped_min = ahdc_rawHitCuts.getDoubleValue("ped_min", sector, layer, component); - double ped_max = ahdc_rawHitCuts.getDoubleValue("ped_max", sector, layer, component); - // Put in map - int key = sector*10000 + layer*100 + component; - double params[] = {t_min, t_max, tot_min, tot_max, adc_min, adc_max, ped_min, ped_max}; - AHDC_RAW_HIT_CUTS.put(Integer.valueOf(key), params); - //System.out.println("t_min : " + t_min + " t_max : " + t_max + " tot_min : " + tot_min + " tot_max : " + tot_max + " adc_min : " + adc_min + " adc_max : " + adc_max + " ped_min : " + ped_min + " ped_max : " + ped_max); - } - - //////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // ATOF effective velocity - for( int i = 0; i < atof_effectiveVelocity.getRowCount(); i++){ - int sector = Integer.parseInt((String)atof_effectiveVelocity.getValueAt(i, 0)); - int layer = Integer.parseInt((String)atof_effectiveVelocity.getValueAt(i, 1)); - int component = Integer.parseInt((String)atof_effectiveVelocity.getValueAt(i, 2)); - double veff = atof_effectiveVelocity.getDoubleValue("veff", sector, layer, component); - double dveff = atof_effectiveVelocity.getDoubleValue("dveff", sector, layer, component); - double extra1 = atof_effectiveVelocity.getDoubleValue("extra1", sector, layer, component); - double extra2 = atof_effectiveVelocity.getDoubleValue("extra2", sector, layer, component); - // Put in map - int key = sector*10000 + layer*1000 + component*10; - double params[] = {veff, dveff, extra1, extra2}; - ATOF_EFFECTIVE_VELOCITY.put(Integer.valueOf(key), params); - //System.out.println("veff : " + veff + " dveff : " + dveff + " extra1 : " + extra1 + " extra2 : " + extra2); - } - - //////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // ATOF time walk - for( int i = 0; i < atof_timeWalk.getRowCount(); i++){ - int sector = Integer.parseInt((String)atof_timeWalk.getValueAt(i, 0)); - 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, 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); - } - - //////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // ATOF attenuation length - for( int i = 0; i < atof_attenuationLength.getRowCount(); i++){ - int sector = Integer.parseInt((String)atof_attenuationLength.getValueAt(i, 0)); - int layer = Integer.parseInt((String)atof_attenuationLength.getValueAt(i, 1)); - int component = Integer.parseInt((String)atof_attenuationLength.getValueAt(i, 2)); - double attlen = atof_attenuationLength.getDoubleValue("attlen", sector, layer, component); - double dattlen = atof_attenuationLength.getDoubleValue("dattlen", sector, layer, component); - double extra1 = atof_attenuationLength.getDoubleValue("extra1", sector, layer, component); - double extra2 = atof_attenuationLength.getDoubleValue("extra2", sector, layer, component); - // Put in map - int key = sector*10000 + layer*1000 + component*10; - double params[] = {attlen, dattlen, extra1, extra2}; - ATOF_ATTENUATION_LENGTH.put(Integer.valueOf(key), params); - //System.out.println("attlen : " + attlen + " dattlen : " + dattlen + " extra1 : " +extra1 + " extra2 : " + extra2 + " ..."); - } - - //////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // ATOF time offsets - for( int i = 0; i < atof_timeOffsets.getRowCount(); i++){ - int sector = Integer.parseInt((String)atof_timeOffsets.getValueAt(i, 0)); - 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, 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}; - ATOF_TIME_OFFSETS.put(Integer.valueOf(key), params); - //System.out.println("t0 : " + t0 + " up_down : " + upstream_downstream + " wedge_bar : " + wedge_bar + " ..."); - } - - - CSTLOADED = true; - - } - - - private static DatabaseConstantProvider DB; - - public static final DatabaseConstantProvider getDB() { - return DB; - } - - - public static final void setDB(DatabaseConstantProvider dB) { - DB = dB; - } - - public static void main (String arg[]) { - } + // AHDC ADC gains table + // keys : sector, layer, component + // cols : gainCorr, dgainCorr, extra1, extra2, extra3 + + if (ahdc_adcGains != null) { + for (int i = 0; i < ahdc_adcGains.getRowCount(); i++) { + + int sector = Integer.parseInt((String) ahdc_adcGains.getValueAt(i, 0)); + int layer = Integer.parseInt((String) ahdc_adcGains.getValueAt(i, 1)); + int component = Integer.parseInt((String) ahdc_adcGains.getValueAt(i, 2)); + + double gainCorr = ahdc_adcGains.getDoubleValue("gainCorr", sector, layer, component); + double dgainCorr = ahdc_adcGains.getDoubleValue("dgainCorr", sector, layer, component); + + double extra1 = 0.0, extra2 = 0.0, extra3 = 0.0; + try { extra1 = ahdc_adcGains.getDoubleValue("extra1", sector, layer, component); } catch (Exception e) {} + try { extra2 = ahdc_adcGains.getDoubleValue("extra2", sector, layer, component); } catch (Exception e) {} + try { extra3 = ahdc_adcGains.getDoubleValue("extra3", sector, layer, component); } catch (Exception e) {} + + int key = sector * 10000 + layer * 100 + component; + AHDC_ADC_GAINS.put(key, new double[]{gainCorr, dgainCorr, extra1, extra2, extra3}); + } +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// AHDC time_over_threshold (NEW TABLE) +// keys : sector, layer, component +// columns: totCorr, dtotCorr, extra1, extra2, extra3 + +// always clear so behavior is deterministic if Load() is ever called again +AHDC_TIME_OVER_THRESHOLD.clear(); + +// Table may not exist for some runs/variations -> treat as "no correction" +if (ahdc_timeOverThreshold != null) { + + for (int i = 0; i < ahdc_timeOverThreshold.getRowCount(); i++) { + int sector = Integer.parseInt((String) ahdc_timeOverThreshold.getValueAt(i, 0)); + int layer = Integer.parseInt((String) ahdc_timeOverThreshold.getValueAt(i, 1)); + int component = Integer.parseInt((String) ahdc_timeOverThreshold.getValueAt(i, 2)); + + double totCorr = ahdc_timeOverThreshold.getDoubleValue("totCorr", sector, layer, component); + double dtotCorr = ahdc_timeOverThreshold.getDoubleValue("dtotCorr", sector, layer, component); + + double extra1 = 0.0, extra2 = 0.0, extra3 = 0.0; + try { extra1 = ahdc_timeOverThreshold.getDoubleValue("extra1", sector, layer, component); } catch (Exception e) {} + try { extra2 = ahdc_timeOverThreshold.getDoubleValue("extra2", sector, layer, component); } catch (Exception e) {} + try { extra3 = ahdc_timeOverThreshold.getDoubleValue("extra3", sector, layer, component); } catch (Exception e) {} + + int key = sector * 10000 + layer * 100 + component; + double[] params = { totCorr, dtotCorr, extra1, extra2, extra3 }; + AHDC_TIME_OVER_THRESHOLD.put(Integer.valueOf(key), params); + } +} + + + + + + + + //////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // AHDC time_over_threshold (NEW TABLE) + // keys : sector, layer, component + // columns: totCorr, dtotCorr, extra1, extra2, extra3 +// for (int i = 0; i < ahdc_timeOverThreshold.getRowCount(); i++) { +// int sector = Integer.parseInt((String) ahdc_timeOverThreshold.getValueAt(i, 0)); +// int layer = Integer.parseInt((String) ahdc_timeOverThreshold.getValueAt(i, 1)); +// int component = Integer.parseInt((String) ahdc_timeOverThreshold.getValueAt(i, 2)); +// +// double totCorr = ahdc_timeOverThreshold.getDoubleValue("totCorr", sector, layer, component); +// double dtotCorr = ahdc_timeOverThreshold.getDoubleValue("dtotCorr", sector, layer, component); + +// double extra1 = 0.0, extra2 = 0.0, extra3 = 0.0; +// try { extra1 = ahdc_timeOverThreshold.getDoubleValue("extra1", sector, layer, component); } catch (Exception e) {} +//// try { extra2 = ahdc_timeOverThreshold.getDoubleValue("extra2", sector, layer, component); } catch (Exception e) {} +// try { extra3 = ahdc_timeOverThreshold.getDoubleValue("extra3", sector, layer, component); } catch (Exception e) {} + +// int key = sector * 10000 + layer * 100 + component; +// double params[] = { totCorr, dtotCorr, extra1, extra2, extra3 }; +// AHDC_TIME_OVER_THRESHOLD.put(Integer.valueOf(key), params); +// } + + //////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // ATOF effective velocity + for (int i = 0; i < atof_effectiveVelocity.getRowCount(); i++) { + int sector = Integer.parseInt((String) atof_effectiveVelocity.getValueAt(i, 0)); + int layer = Integer.parseInt((String) atof_effectiveVelocity.getValueAt(i, 1)); + int component = Integer.parseInt((String) atof_effectiveVelocity.getValueAt(i, 2)); + + double veff = atof_effectiveVelocity.getDoubleValue("veff", sector, layer, component); + double dveff = atof_effectiveVelocity.getDoubleValue("dveff", sector, layer, component); + double extra1 = atof_effectiveVelocity.getDoubleValue("extra1", sector, layer, component); + double extra2 = atof_effectiveVelocity.getDoubleValue("extra2", sector, layer, component); + + int key = sector * 10000 + layer * 1000 + component * 10; + double params[] = { veff, dveff, extra1, extra2 }; + ATOF_EFFECTIVE_VELOCITY.put(Integer.valueOf(key), params); + } + + //////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // ATOF time walk + for (int i = 0; i < atof_timeWalk.getRowCount(); i++) { + int sector = Integer.parseInt((String) atof_timeWalk.getValueAt(i, 0)); + 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, 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); + + int key = sector * 10000 + layer * 1000 + component * 10 + order; + double params[] = { tw0, tw1, tw2, tw3, dtw0, dtw1, dtw2, dtw3, chi2ndf }; + ATOF_TIME_WALK.put(Integer.valueOf(key), params); + } + + //////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // ATOF attenuation length + for (int i = 0; i < atof_attenuationLength.getRowCount(); i++) { + int sector = Integer.parseInt((String) atof_attenuationLength.getValueAt(i, 0)); + int layer = Integer.parseInt((String) atof_attenuationLength.getValueAt(i, 1)); + int component = Integer.parseInt((String) atof_attenuationLength.getValueAt(i, 2)); + + double attlen = atof_attenuationLength.getDoubleValue("attlen", sector, layer, component); + double dattlen = atof_attenuationLength.getDoubleValue("dattlen", sector, layer, component); + double extra1 = atof_attenuationLength.getDoubleValue("extra1", sector, layer, component); + double extra2 = atof_attenuationLength.getDoubleValue("extra2", sector, layer, component); + + int key = sector * 10000 + layer * 1000 + component * 10; + double params[] = { attlen, dattlen, extra1, extra2 }; + ATOF_ATTENUATION_LENGTH.put(Integer.valueOf(key), params); + } + + //////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // ATOF time offsets + for (int i = 0; i < atof_timeOffsets.getRowCount(); i++) { + int sector = Integer.parseInt((String) atof_timeOffsets.getValueAt(i, 0)); + 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, 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); + + int key = sector * 10000 + layer * 1000 + component * 10 + order; + double params[] = { t0, upstream_downstream, wedge_bar, extra1, extra2 }; + ATOF_TIME_OFFSETS.put(Integer.valueOf(key), params); + } + + CSTLOADED = true; + } + + private static DatabaseConstantProvider DB; + + public static final DatabaseConstantProvider getDB() { + return DB; + } + + public static final void setDB(DatabaseConstantProvider dB) { + DB = dB; + } + + public static void main(String arg[]) { + } } diff --git a/reconstruction/alert/src/main/java/org/jlab/service/ahdc/AHDCEngine.java b/reconstruction/alert/src/main/java/org/jlab/service/ahdc/AHDCEngine.java index eccb2c8894..4f8dda448f 100644 --- a/reconstruction/alert/src/main/java/org/jlab/service/ahdc/AHDCEngine.java +++ b/reconstruction/alert/src/main/java/org/jlab/service/ahdc/AHDCEngine.java @@ -94,7 +94,10 @@ else if (Objects.equals(this.getEngineConfigString("Mode"), ModeTrackFinding.CV_ "/calibration/alert/atof/effective_velocity", "/calibration/alert/atof/time_walk", "/calibration/alert/atof/attenuation", - "/calibration/alert/atof/time_offsets" + "/calibration/alert/atof/time_offsets", + "/calibration/alert/ahdc/gains", + "/calibration/alert/ahdc/time_over_threshold" + }; requireConstants(Arrays.asList(alertTables));