From 5a7060aa7b36fdf04ba9495aeac23ae45641f369 Mon Sep 17 00:00:00 2001 From: Felix Touchte Codjo Date: Thu, 24 Jul 2025 08:22:05 -0400 Subject: [PATCH 1/8] apply fine timestamp correction to leadingEdgeTime --- .../org/jlab/detector/pulse/ModeAHDC.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ModeAHDC.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ModeAHDC.java index 9a3707cafd..6d4475cfc5 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ModeAHDC.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ModeAHDC.java @@ -42,6 +42,8 @@ public class ModeAHDC extends HipoExtractor { private final int flateness = 200; //ADC offset to be considered as the default baseline private final float defaultBaseline = 300; + // dream clock for fine timestamp correction + private final float dream_clock = 8.0f; //Waveform and corresponding pulse //This is the CURRENT pulse, it is initialized @@ -318,6 +320,25 @@ public int computeTimeUsingConstantFractionDiscriminator(){ return 0; } + + /** + * Apply fine timestamp correction + * + * adapted from decode/MVTFitter.java + * + * @param timestamp for fine time correction + * @param fineTimeStampResolution correspond to the dream clock (usually equals to 8; but to be checked!) + */ + + private void fineTimeStampCorrection(long timestamp, float fineTimeStampResolution) { + String binaryTimeStamp = Long.toBinaryString(timestamp); //get 64 bit timestamp in binary format + if (binaryTimeStamp.length()>=3){ + byte fineTimeStamp = Byte.parseByte(binaryTimeStamp.substring(binaryTimeStamp.length()-3,binaryTimeStamp.length()),2); //fineTimeStamp : keep and convert last 3 bits of binary timestamp + this.pulse.leadingEdgeTime += (double) ((fineTimeStamp+0.5) * fineTimeStampResolution); //fineTimeStampCorrection, only on the leadingEdgeTime for the moment (we don't use timeMax or constantFractionTime in the reconstruction yet) + } + } + + /** * This method extracts relevant information from the waveform @@ -355,6 +376,9 @@ public List extract(NamedEntry pars, int id, long timestamp, long time_ZS //Get the CFD time this.computeTimeUsingConstantFractionDiscriminator(); + + // Fine timestamp correction on leadingEdgeTime + this.fineTimeStampCorrection(timestamp, dream_clock); output.add(this.pulse); return output; From 449e368b7552b86c915571177f43121c81bb2bad Mon Sep 17 00:00:00 2001 From: Felix Touchte Codjo Date: Thu, 24 Jul 2025 11:35:22 -0400 Subject: [PATCH 2/8] ahdc hit time corrected --- .../java/org/jlab/rec/ahdc/Hit/HitReader.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) 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 0932ba6403..bef3fb967c 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 @@ -23,12 +23,16 @@ public HitReader(DataEvent event, AlertDCDetector detector, boolean simulation) public final void fetch_AHDCHits(DataEvent event, AlertDCDetector detector) { ArrayList hits = new ArrayList<>(); - if (event.hasBank("AHDC::adc")) { + if (event.hasBank("AHDC::adc") && event.hasBank("REC::Event")) { + DataBank bankRecEvent = event.getBank("REC::Event"); + double startTime = bankRecEvent.getFloat("startTime", 0); + if (startTime < 0) { // reject bad events + return; + } + RawDataBank bankDGTZ = new RawDataBank("AHDC::adc"); - bankDGTZ.read(event); - //DataBank bankDGTZ = event.getBank("ALRTDC::adc"); - + bankDGTZ.read(event); for (int i = 0; i < bankDGTZ.rows(); i++) { int id = bankDGTZ.trueIndex(i) + 1; @@ -65,8 +69,9 @@ public final void fetch_AHDCHits(DataEvent event, AlertDCDetector detector) { double p4 = time2distance[4]; double p5 = time2distance[5]; // Apply time calibration - // We may need adc calibration too - double time = leadingEdgeTime - t0; + // We may need adc calibration too + // Remark: leadingEdgeTime already has the fine timestamp correction + double time = leadingEdgeTime - t0 - startTime; // Apply raw hit cuts if (((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) { From 58c0bd877692faf2574f1cf0e935b838766f481b Mon Sep 17 00:00:00 2001 From: Felix Touchte Codjo Date: Mon, 28 Jul 2025 04:28:10 -0400 Subject: [PATCH 3/8] add modeAHDC in PulseExtractorEngine --- .../java/org/jlab/clas/service/PulseExtractorEngine.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/common-tools/clas-reco/src/main/java/org/jlab/clas/service/PulseExtractorEngine.java b/common-tools/clas-reco/src/main/java/org/jlab/clas/service/PulseExtractorEngine.java index caf6702f20..3f2dc5254e 100644 --- a/common-tools/clas-reco/src/main/java/org/jlab/clas/service/PulseExtractorEngine.java +++ b/common-tools/clas-reco/src/main/java/org/jlab/clas/service/PulseExtractorEngine.java @@ -3,6 +3,7 @@ import org.jlab.clas.reco.ReconstructionEngine; import org.jlab.detector.pulse.Mode3; import org.jlab.detector.pulse.Mode7; +import org.jlab.detector.pulse.ModeAHDC; import org.jlab.io.base.DataEvent; /** @@ -15,6 +16,7 @@ public class PulseExtractorEngine extends ReconstructionEngine { Mode3 mode3 = new Mode3(); Mode3 mode7 = new Mode7(); + ModeAHDC mode_ahdc = new ModeAHDC(); public PulseExtractorEngine() { super("PULSE", "baltzell", "0.0"); @@ -31,8 +33,9 @@ public boolean init() { public boolean processDataEvent(DataEvent event) { // No CCDB table, hardcoded parameters in the extractor: - mode3.update(6, null, event, "BMT::wf", "BMT::adc"); + //mode3.update(6, null, event, "BMT::wf", "BMT::adc"); //mode7.update(80, null, event, "AHDC::wf", "AHDC::adc"); + mode_ahdc.update(30, null, event, "AHDC::wf", "AHDC::adc"); /* // Requiring a CCDB table: From 225162556d5544dd4ad2cdff91a8da6af8c5523b Mon Sep 17 00:00:00 2001 From: Felix Touchte Codjo Date: Mon, 28 Jul 2025 17:24:39 -0400 Subject: [PATCH 4/8] use wf type for hit selection --- .../src/main/java/org/jlab/detector/pulse/ModeAHDC.java | 2 +- .../src/main/java/org/jlab/rec/ahdc/Hit/HitReader.java | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ModeAHDC.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ModeAHDC.java index 6d4475cfc5..5ff688a180 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ModeAHDC.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ModeAHDC.java @@ -423,7 +423,7 @@ protected void update(int n, IndexedTable it, Bank wfBank, Bank adcBank) { adcBank.putFloat("timeOverThreshold", i, pulses.get(i).timeOverThreshold); adcBank.putFloat("constantFractionTime", i, pulses.get(i).constantFractionTime); adcBank.putInt("integral", i, (int)pulses.get(i).integral); - adcBank.putFloat("ped", i, (short)pulses.get(i).pedestal); + adcBank.putFloat("ped", i, pulses.get(i).pedestal); adcBank.putShort("wfType", i, pulses.get(i).wftype); } } 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 bef3fb967c..584d0595c7 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 @@ -44,7 +44,7 @@ public final void fetch_AHDCHits(DataEvent event, AlertDCDetector detector) { double adc = bankDGTZ.getInt("ADC", i); double leadingEdgeTime = bankDGTZ.getFloat("leadingEdgeTime", i); double timeOverThreshold = bankDGTZ.getFloat("timeOverThreshold", i); - double adcOffset = bankDGTZ.getShort("ped", i); + double adcOffset = bankDGTZ.getFloat("ped", 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 ); @@ -72,9 +72,10 @@ public final void fetch_AHDCHits(DataEvent event, AlertDCDetector detector) { // We may need adc calibration too // Remark: leadingEdgeTime already has the fine timestamp correction double time = leadingEdgeTime - t0 - startTime; - + + if (bankDGTZ.getShort("wfType", i) == 0) { // Apply raw hit cuts - if (((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) { + //if (((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) { // we may prevent time to be too small or too big // CONDITION TO BE ADDED // we should also use a flag to prevent to read the ccdb if reconstructed event if from simulation From 97f8727b5fb2acb16ffcd4dea8ee1bf6e0870166 Mon Sep 17 00:00:00 2001 From: Felix Touchte Codjo Date: Mon, 28 Jul 2025 17:35:08 -0400 Subject: [PATCH 5/8] take into account simulation --- .../alert/src/main/java/org/jlab/rec/ahdc/Hit/HitReader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 584d0595c7..d05085e750 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 @@ -73,7 +73,7 @@ public final void fetch_AHDCHits(DataEvent event, AlertDCDetector detector) { // Remark: leadingEdgeTime already has the fine timestamp correction double time = leadingEdgeTime - t0 - startTime; - if (bankDGTZ.getShort("wfType", i) == 0) { + if ((bankDGTZ.getShort("wfType", i) == 0) || sim) { // Apply raw hit cuts //if (((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) { // we may prevent time to be too small or too big From d6fe4faa912a8d98678a3426609b2a2a25d1646f Mon Sep 17 00:00:00 2001 From: Felix Touchte Codjo Date: Tue, 29 Jul 2025 03:54:38 -0400 Subject: [PATCH 6/8] replace string manipulation with bit operation --- .../src/main/java/org/jlab/detector/pulse/ModeAHDC.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ModeAHDC.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ModeAHDC.java index 5ff688a180..75058451a6 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ModeAHDC.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/pulse/ModeAHDC.java @@ -331,11 +331,8 @@ public int computeTimeUsingConstantFractionDiscriminator(){ */ private void fineTimeStampCorrection(long timestamp, float fineTimeStampResolution) { - String binaryTimeStamp = Long.toBinaryString(timestamp); //get 64 bit timestamp in binary format - if (binaryTimeStamp.length()>=3){ - byte fineTimeStamp = Byte.parseByte(binaryTimeStamp.substring(binaryTimeStamp.length()-3,binaryTimeStamp.length()),2); //fineTimeStamp : keep and convert last 3 bits of binary timestamp - this.pulse.leadingEdgeTime += (double) ((fineTimeStamp+0.5) * fineTimeStampResolution); //fineTimeStampCorrection, only on the leadingEdgeTime for the moment (we don't use timeMax or constantFractionTime in the reconstruction yet) - } + long fineTimeStamp = timestamp & 0x00000007; // keep and convert last 3 bits of binary timestamp + this.pulse.leadingEdgeTime += (double) ((fineTimeStamp+0.5) * fineTimeStampResolution); //fineTimeStampCorrection, only on the leadingEdgeTime for the moment (we don't use timeMax or constantFractionTime in the reconstruction yet) } From 1fc1542c3e9e4363d228810f2eb24580b805d822 Mon Sep 17 00:00:00 2001 From: Felix Touchte Codjo Date: Tue, 29 Jul 2025 04:07:52 -0400 Subject: [PATCH 7/8] comment unnecessary code lines --- .../main/java/org/jlab/rec/ahdc/Hit/HitReader.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) 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 d05085e750..6e29052f62 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 @@ -43,8 +43,8 @@ public final void fetch_AHDCHits(DataEvent event, AlertDCDetector detector) { 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); + //double timeOverThreshold = bankDGTZ.getFloat("timeOverThreshold", i); + //double adcOffset = bankDGTZ.getFloat("ped", 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 ); @@ -57,7 +57,7 @@ public final void fetch_AHDCHits(DataEvent event, AlertDCDetector detector) { 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 t2 from CCDB + // 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) @@ -76,11 +76,6 @@ public final void fetch_AHDCHits(DataEvent event, AlertDCDetector detector) { if ((bankDGTZ.getShort("wfType", i) == 0) || sim) { // Apply raw hit cuts //if (((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) { - // we may prevent time to be too small or too big - // CONDITION TO BE ADDED - // we should also use a flag to prevent to read the ccdb if reconstructed event if from simulation - // TO BE DONE - //double doca = bankDGTZ.getShort("ped", i) / 1000.0; 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); Hit h = new Hit(id, superlayer, layer, wire, doca, adc, time); h.setWirePosition(detector); From 1cb452256a5b361920aab2cf3a84e414057eb7db Mon Sep 17 00:00:00 2001 From: Felix Touchte Codjo Date: Wed, 30 Jul 2025 10:35:11 -0400 Subject: [PATCH 8/8] use wfType 0 or 1 --- .../alert/src/main/java/org/jlab/rec/ahdc/Hit/HitReader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 6e29052f62..ed67f3fced 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 @@ -73,7 +73,7 @@ public final void fetch_AHDCHits(DataEvent event, AlertDCDetector detector) { // Remark: leadingEdgeTime already has the fine timestamp correction double time = leadingEdgeTime - t0 - startTime; - if ((bankDGTZ.getShort("wfType", i) == 0) || sim) { + if ((bankDGTZ.getShort("wfType", i) <= 1) || sim) { // Apply raw hit cuts //if (((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);