From 74157e764c0a58842d2e9d87d011d3a0c8d9ec5c Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Fri, 20 Mar 2026 14:46:11 -0400 Subject: [PATCH 1/5] test: scaler clock diagnostics --- .../main/java/org/jlab/detector/scalers/DaqScaler.java | 9 +++++++++ .../main/java/org/jlab/detector/scalers/Dsc2Scaler.java | 4 ++-- 2 files changed, 11 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..f0323c9006 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 @@ -74,6 +74,11 @@ public void add(DaqScaler other) { protected void calibrate(IndexedTable fcupTable,IndexedTable slmTable,double seconds,double liveSeconds) { if (this.clock > 0) { + + String prefix = String.format("clocktest [%s]", this.getClass().getSimpleName()); + System.out.println(String.format("%s: -----------", prefix)); + System.out.println(String.format("%s: toString: %s", prefix, this.toString())); + final double fcup_slope = fcupTable.getDoubleValue("slope",0,0,0); // Hz/nA final double fcup_offset = fcupTable.getDoubleValue("offset",0,0,0); // Hz final double fcup_atten = fcupTable.getDoubleValue("atten",0,0,0); // attenuation @@ -97,6 +102,10 @@ protected void calibrate(IndexedTable fcupTable,IndexedTable slmTable,double sec this.beamCharge = q * fcup_atten / fcup_slope; this.beamChargeGated = qg * fcup_atten / fcup_slope; } + + System.out.println(String.format("%s: BANK fcup=%f fcupGated=%f", prefix, this.fcup, this.gatedFcup)); + System.out.println(String.format("%s: CCDB fcup_offset=%f fcup_slope=%f fcup_atten=%f", prefix, fcup_offset, fcup_slope, fcup_atten)); + System.out.println(String.format("%s: clockFreq=%f beamCharge=%f beamChargeGated=%f", prefix, this.clockFreq, this.beamCharge, this.beamChargeGated)); } } diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/Dsc2Scaler.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/Dsc2Scaler.java index 5f48d43421..dd947e0988 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/Dsc2Scaler.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/Dsc2Scaler.java @@ -38,7 +38,7 @@ public Dsc2Scaler() {} * @param seconds dwell time, provided in case the clock rolls over */ public Dsc2Scaler(Bank bank, IndexedTable fcupTable, IndexedTable slmTable, double seconds) { - this.clockFreq=1e6; + this.clockFreq=1e6; // FIXME: this is what's actually used this.read(bank); this.calibrate(fcupTable,slmTable,seconds); } @@ -110,4 +110,4 @@ public final void read(Bank bank) { } } -} \ No newline at end of file +} From 1d4795b624771934a58a6b24412d06073e003063 Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Fri, 20 Mar 2026 15:00:07 -0400 Subject: [PATCH 2/5] fix: type --- .../src/main/java/org/jlab/detector/scalers/DaqScaler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f0323c9006..7f54c86158 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 @@ -103,7 +103,7 @@ protected void calibrate(IndexedTable fcupTable,IndexedTable slmTable,double sec this.beamChargeGated = qg * fcup_atten / fcup_slope; } - System.out.println(String.format("%s: BANK fcup=%f fcupGated=%f", prefix, this.fcup, this.gatedFcup)); + System.out.println(String.format("%s: BANK fcup=%d fcupGated=%d", prefix, this.fcup, this.gatedFcup)); System.out.println(String.format("%s: CCDB fcup_offset=%f fcup_slope=%f fcup_atten=%f", prefix, fcup_offset, fcup_slope, fcup_atten)); System.out.println(String.format("%s: clockFreq=%f beamCharge=%f beamChargeGated=%f", prefix, this.clockFreq, this.beamCharge, this.beamChargeGated)); } From 1dd5d2a748bd316635760382fcb68bccbb22200c Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Fri, 20 Mar 2026 18:37:27 -0400 Subject: [PATCH 3/5] feat: print time --- .../src/main/java/org/jlab/detector/scalers/DaqScaler.java | 1 + 1 file changed, 1 insertion(+) 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 7f54c86158..22a8e18f9c 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 @@ -78,6 +78,7 @@ protected void calibrate(IndexedTable fcupTable,IndexedTable slmTable,double sec String prefix = String.format("clocktest [%s]", this.getClass().getSimpleName()); System.out.println(String.format("%s: -----------", prefix)); System.out.println(String.format("%s: toString: %s", prefix, this.toString())); + System.out.println(String.format("%s: seconds=%f liveSeconds=%f", prefix, seconds, liveSeconds)); final double fcup_slope = fcupTable.getDoubleValue("slope",0,0,0); // Hz/nA final double fcup_offset = fcupTable.getDoubleValue("offset",0,0,0); // Hz From 3552dc07e46ff2e840465fac6922c8066413230e Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Tue, 7 Apr 2026 14:22:03 -0400 Subject: [PATCH 4/5] test: 125 MHz DSC2 clock for RG-A Spring 2018 6.4 GeV We suspect the DSC2 clock frequency for RG-A Spring 2018 6.4 GeV data was 125 MHz, not 1 MHz. This PR allows one to run `RebuildScalers` with the higher frequency clock, and more generalized clock rollover corrections. **do not merge** --- .../java/org/jlab/detector/scalers/DaqScaler.java | 14 +++++++------- .../java/org/jlab/detector/scalers/Dsc2Scaler.java | 4 ++-- 2 files changed, 9 insertions(+), 9 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 22a8e18f9c..8f8327e2c8 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 @@ -75,10 +75,10 @@ protected void calibrate(IndexedTable fcupTable,IndexedTable slmTable,double sec if (this.clock > 0) { - String prefix = String.format("clocktest [%s]", this.getClass().getSimpleName()); - System.out.println(String.format("%s: -----------", prefix)); - System.out.println(String.format("%s: toString: %s", prefix, this.toString())); - System.out.println(String.format("%s: seconds=%f liveSeconds=%f", prefix, seconds, liveSeconds)); + // String prefix = String.format("clocktest [%s]", this.getClass().getSimpleName()); + // System.out.println(String.format("%s: -----------", prefix)); + // System.out.println(String.format("%s: toString: %s", prefix, this.toString())); + // System.out.println(String.format("%s: seconds=%f liveSeconds=%f", prefix, seconds, liveSeconds)); final double fcup_slope = fcupTable.getDoubleValue("slope",0,0,0); // Hz/nA final double fcup_offset = fcupTable.getDoubleValue("offset",0,0,0); // Hz @@ -104,9 +104,9 @@ protected void calibrate(IndexedTable fcupTable,IndexedTable slmTable,double sec this.beamChargeGated = qg * fcup_atten / fcup_slope; } - System.out.println(String.format("%s: BANK fcup=%d fcupGated=%d", prefix, this.fcup, this.gatedFcup)); - System.out.println(String.format("%s: CCDB fcup_offset=%f fcup_slope=%f fcup_atten=%f", prefix, fcup_offset, fcup_slope, fcup_atten)); - System.out.println(String.format("%s: clockFreq=%f beamCharge=%f beamChargeGated=%f", prefix, this.clockFreq, this.beamCharge, this.beamChargeGated)); + // System.out.println(String.format("%s: BANK fcup=%d fcupGated=%d", prefix, this.fcup, this.gatedFcup)); + // System.out.println(String.format("%s: CCDB fcup_offset=%f fcup_slope=%f fcup_atten=%f", prefix, fcup_offset, fcup_slope, fcup_atten)); + // System.out.println(String.format("%s: clockFreq=%f beamCharge=%f beamChargeGated=%f", prefix, this.clockFreq, this.beamCharge, this.beamChargeGated)); } } diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/Dsc2Scaler.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/Dsc2Scaler.java index dd947e0988..9b31f2d866 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/Dsc2Scaler.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/Dsc2Scaler.java @@ -38,7 +38,7 @@ public Dsc2Scaler() {} * @param seconds dwell time, provided in case the clock rolls over */ public Dsc2Scaler(Bank bank, IndexedTable fcupTable, IndexedTable slmTable, double seconds) { - this.clockFreq=1e6; // FIXME: this is what's actually used + this.clockFreq=125e6; // for RG-A spring 2018 6.4 GeV data this.read(bank); this.calibrate(fcupTable,slmTable,seconds); } @@ -50,7 +50,7 @@ public Dsc2Scaler(Bank bank, IndexedTable fcupTable, IndexedTable slmTable, doub * @param dscTable /daq/config/scalers/dsc1 CCDB table */ public Dsc2Scaler(Bank bank, IndexedTable fcupTable, IndexedTable slmTable, IndexedTable dscTable) { - this.clockFreq = dscTable.getIntValue("frequency", 0,0,0); + this.clockFreq = 125e6; // for RG-A spring 2018 6.4 GeV data // dscTable.getIntValue("frequency", 0,0,0); this.read(bank); this.calibrate(fcupTable,slmTable); } From 6f6f0e754ac848aa2315aff27b80d18b683fda00 Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Tue, 7 Apr 2026 14:26:14 -0400 Subject: [PATCH 5/5] fix: cherry pick generalized rollover correction --- .../detector/scalers/DaqScalersSequence.java | 47 ++++++++++++++++--- 1 file changed, 40 insertions(+), 7 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..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 @@ -362,18 +362,51 @@ 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; - if (previous.clock > next.clock) { + Dsc2Scaler next = this.scalers.get(i).dsc2; + 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.gatedClock)); - 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!?): - 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.print( String.format("FIXING UNGATED CLOCK ROLLOVER: %d -> ",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)); + System.out.println((double)corr/(2*(long)Integer.MAX_VALUE)); + if(is_gap) System.out.println("GAP!"); + } + } + 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; + 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)); + System.out.println((double)corr/(2*(long)Integer.MAX_VALUE)); + if(is_gap) System.out.println("GAP!"); + } } modified = true; break;