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..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 @@ -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,22 @@ 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) { + 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) + } + + /** * This method extracts relevant information from the waveform @@ -355,6 +373,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; @@ -399,7 +420,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/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: 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..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 @@ -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; @@ -39,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.getShort("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 ); @@ -53,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) @@ -65,16 +69,13 @@ 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; + + 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) { - // 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; + //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); Hit h = new Hit(id, superlayer, layer, wire, doca, adc, time); h.setWirePosition(detector);