From ac4d7315ad610c7d07d788e8c3f2d60ec34b57fb Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Thu, 19 Feb 2026 16:50:17 -0500 Subject: [PATCH 1/5] test: separate rollover correction for gated and ungated clocks debugging RG-A 6.4 GeV --- .../detector/scalers/DaqScalersSequence.java | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScalersSequence.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScalersSequence.java index 2741112635..9e039212cb 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScalersSequence.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScalersSequence.java @@ -362,18 +362,35 @@ public boolean validateOrdering() { */ public void fixClockRollover() { boolean modified = true; + // ungated clock while (modified) { modified = false; for (int i=this.scalers.size()-1; i>0; --i) { Dsc2Scaler previous = this.scalers.get(i-1).dsc2; - Dsc2Scaler next = this.scalers.get(i).dsc2; + Dsc2Scaler next = this.scalers.get(i).dsc2; if (previous.clock > next.clock) { for (int j=i; j ",this.scalers.get(j).dsc2.clock,this.scalers.get(j).dsc2.gatedClock)); + if (j==i) System.out.print( String.format("FIXING UNGATED CLOCK ROLLOVER: %d -> ",this.scalers.get(j).dsc2.clock)); this.scalers.get(j).dsc2.clock += 2*(long)Integer.MAX_VALUE; - // The gated clock also rolls over (but it's triggered by the ungated clock, not itself!?): + if (j==i) System.out.println(String.format("%d",this.scalers.get(j).dsc2.clock)); + } + modified = true; + break; + } + } + } + // repeat for gated clock + modified = true; + while (modified) { + modified = false; + for (int i=this.scalers.size()-1; i>0; --i) { + Dsc2Scaler previous = this.scalers.get(i-1).dsc2; + Dsc2Scaler next = this.scalers.get(i).dsc2; + if (previous.gatedClock > next.gatedClock) { + for (int j=i; j ",this.scalers.get(j).dsc2.gatedClock)); this.scalers.get(j).dsc2.gatedClock += 2*(long)Integer.MAX_VALUE; - if (j==i) System.out.println(String.format("%d %d",this.scalers.get(j).dsc2.clock,this.scalers.get(j).dsc2.gatedClock)); + if (j==i) System.out.println(String.format("%d",this.scalers.get(j).dsc2.gatedClock)); } modified = true; break; From 8f0471f93076c78c09b69a3ce7c25599c972c225 Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Fri, 20 Feb 2026 18:41:25 -0500 Subject: [PATCH 2/5] fix: generalize rollover correction --- .../java/org/jlab/detector/scalers/DaqScalersSequence.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScalersSequence.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScalersSequence.java index 9e039212cb..c7028c89ac 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScalersSequence.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScalersSequence.java @@ -371,7 +371,7 @@ public void fixClockRollover() { if (previous.clock > next.clock) { for (int j=i; j ",this.scalers.get(j).dsc2.clock)); - this.scalers.get(j).dsc2.clock += 2*(long)Integer.MAX_VALUE; + this.scalers.get(j).dsc2.clock += previous.clock - next.clock; if (j==i) System.out.println(String.format("%d",this.scalers.get(j).dsc2.clock)); } modified = true; @@ -389,7 +389,7 @@ public void fixClockRollover() { if (previous.gatedClock > next.gatedClock) { for (int j=i; j ",this.scalers.get(j).dsc2.gatedClock)); - this.scalers.get(j).dsc2.gatedClock += 2*(long)Integer.MAX_VALUE; + this.scalers.get(j).dsc2.gatedClock += previous.gatedClock - next.gatedClock; if (j==i) System.out.println(String.format("%d",this.scalers.get(j).dsc2.gatedClock)); } modified = true; From 9aef4b91143384945ee69d31c97284169da1c7b2 Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Fri, 20 Feb 2026 19:00:16 -0500 Subject: [PATCH 3/5] fix: infinite loop --- .../java/org/jlab/detector/scalers/DaqScalersSequence.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScalersSequence.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScalersSequence.java index c7028c89ac..f14f8523a1 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScalersSequence.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScalersSequence.java @@ -369,9 +369,10 @@ public void fixClockRollover() { Dsc2Scaler previous = this.scalers.get(i-1).dsc2; Dsc2Scaler next = this.scalers.get(i).dsc2; if (previous.clock > next.clock) { + var corr = previous.clock - next.clock + 1; for (int j=i; j ",this.scalers.get(j).dsc2.clock)); - this.scalers.get(j).dsc2.clock += previous.clock - next.clock; + this.scalers.get(j).dsc2.clock += corr; if (j==i) System.out.println(String.format("%d",this.scalers.get(j).dsc2.clock)); } modified = true; @@ -387,9 +388,10 @@ public void fixClockRollover() { Dsc2Scaler previous = this.scalers.get(i-1).dsc2; Dsc2Scaler next = this.scalers.get(i).dsc2; if (previous.gatedClock > next.gatedClock) { + var corr = previous.gatedClock - next.gatedClock + 1; for (int j=i; j ",this.scalers.get(j).dsc2.gatedClock)); - this.scalers.get(j).dsc2.gatedClock += previous.gatedClock - next.gatedClock; + this.scalers.get(j).dsc2.gatedClock += corr; if (j==i) System.out.println(String.format("%d",this.scalers.get(j).dsc2.gatedClock)); } modified = true; From 28dfd977376fae6c2281a718c6d57c571d0662aa Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Fri, 20 Feb 2026 19:37:10 -0500 Subject: [PATCH 4/5] fix: deal with large gaps too --- .../detector/scalers/DaqScalersSequence.java | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScalersSequence.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScalersSequence.java index f14f8523a1..a0527f30db 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScalersSequence.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScalersSequence.java @@ -368,12 +368,19 @@ public void fixClockRollover() { for (int i=this.scalers.size()-1; i>0; --i) { Dsc2Scaler previous = this.scalers.get(i-1).dsc2; Dsc2Scaler next = this.scalers.get(i).dsc2; - if (previous.clock > next.clock) { - var corr = previous.clock - next.clock + 1; + long corr = previous.clock - next.clock + 1; + boolean is_rollover = previous.clock > next.clock; + boolean is_gap = corr <= -2*(long)Integer.MAX_VALUE; + if (is_rollover || is_gap) { + if(is_gap) corr = -corr; for (int j=i; j ",this.scalers.get(j).dsc2.clock)); this.scalers.get(j).dsc2.clock += corr; - if (j==i) System.out.println(String.format("%d",this.scalers.get(j).dsc2.clock)); + if (j==i) { + System.out.println(String.format("%d",this.scalers.get(j).dsc2.clock)); + System.out.println((double)corr/(2*(long)Integer.MAX_VALUE)); + if(is_gap) System.out.println("GAP!"); + } } modified = true; break; @@ -387,12 +394,19 @@ public void fixClockRollover() { for (int i=this.scalers.size()-1; i>0; --i) { Dsc2Scaler previous = this.scalers.get(i-1).dsc2; Dsc2Scaler next = this.scalers.get(i).dsc2; - if (previous.gatedClock > next.gatedClock) { - var corr = previous.gatedClock - next.gatedClock + 1; + long corr = previous.gatedClock - next.gatedClock + 1; + boolean is_rollover = previous.gatedClock > next.gatedClock; + boolean is_gap = corr <= -2*(long)Integer.MAX_VALUE; + if (is_rollover || is_gap) { + if(is_gap) corr = -corr; for (int j=i; j ",this.scalers.get(j).dsc2.gatedClock)); this.scalers.get(j).dsc2.gatedClock += corr; - if (j==i) System.out.println(String.format("%d",this.scalers.get(j).dsc2.gatedClock)); + if (j==i) { + System.out.println(String.format("%d",this.scalers.get(j).dsc2.gatedClock)); + System.out.println((double)corr/(2*(long)Integer.MAX_VALUE)); + if(is_gap) System.out.println("GAP!"); + } } modified = true; break; From a8038b567b72c02b607897870bdac2bbbf72f027 Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Mon, 23 Feb 2026 16:33:41 -0500 Subject: [PATCH 5/5] test: change the clock freq --- .../java/org/jlab/detector/scalers/DaqScaler.java | 12 ++++++++++++ .../java/org/jlab/detector/scalers/StruckScaler.java | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScaler.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScaler.java index 8ae107969c..49cac50153 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScaler.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScaler.java @@ -81,6 +81,14 @@ protected void calibrate(IndexedTable fcupTable,IndexedTable slmTable,double sec final double slm_offset = slmTable.getDoubleValue("offset",0,0,0); // Hz final double slm_atten = slmTable.getDoubleValue("atten",0,0,0); // attenuation + // increase clock frequency by this factor + // double clockFreqFactor = 10.0; + // seconds /= clockFreqFactor; + // liveSeconds /= clockFreqFactor; + + // String prefix = String.format("TICK [%s]", this.getClass().getSimpleName()); + // System.out.println(String.format("%s freq(orig)=%f seconds=%f liveSeconds=%f ", prefix, this.clockFreq, seconds, liveSeconds) + this.toString()); + double q = (double)this.slm - slm_offset * seconds; double qg = (double)this.gatedSlm - slm_offset * liveSeconds; this.beamChargeSLM = q * slm_atten / slm_slope; @@ -90,13 +98,17 @@ protected void calibrate(IndexedTable fcupTable,IndexedTable slmTable,double sec if (fcup_atten<1e-8 || fcup_slope<1e-8) { this.beamCharge = this.beamChargeSLM; this.beamChargeGated = this.beamChargeGatedSLM; + // System.out.println(String.format("%s [slm]: %f %f", prefix, this.beamChargeGated, this.beamCharge)); } else { q = (double)this.fcup - fcup_offset * seconds; qg = (double)this.gatedFcup - fcup_offset * liveSeconds; this.beamCharge = q * fcup_atten / fcup_slope; this.beamChargeGated = qg * fcup_atten / fcup_slope; + // System.out.println(String.format("%s [fcup]: %f %f", prefix, this.beamChargeGated, this.beamCharge)); } + // if(this.getClass().getSimpleName().equals("Dsc2Scaler")) + // System.out.println(String.format("%s %f %f %s", prefix, this.beamChargeGated, this.beamCharge, this.toString())); } } diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/StruckScaler.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/StruckScaler.java index 14237ebe62..de95c288e7 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/StruckScaler.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/StruckScaler.java @@ -53,7 +53,7 @@ public Interval getInterval() { @Override public String toString() { - return String.format("i=%s h=%d q=%d %s",this.interval,this.helicity.value(),this.quartet.value(),super.toString()); + return String.format("[STRUCK] i=%s h=%d q=%d %s",this.interval,this.helicity.value(),this.quartet.value(),super.toString()); } /** @@ -239,4 +239,4 @@ else if (Input.equals(Input.CLOCK, chan)) { this.calibrate(fcupTable,slmTable); } -} \ No newline at end of file +}