From 74157e764c0a58842d2e9d87d011d3a0c8d9ec5c Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Fri, 20 Mar 2026 14:46:11 -0400 Subject: [PATCH 1/8] 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/8] 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/8] 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/8] 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/8] 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; From cd4c205deae9b26aed4da6fd660574a4f99bfc01 Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Thu, 9 Apr 2026 12:04:23 -0400 Subject: [PATCH 6/8] fix: correct by `2**32` always; complain if this may not be valid --- .../detector/scalers/DaqScalersSequence.java | 99 ++++++++++--------- 1 file changed, 52 insertions(+), 47 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 a0527f30db..5a2650772e 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 @@ -361,60 +361,65 @@ public boolean validateOrdering() { * 2. Assume any subsequent clock decrease is a rollover. */ 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; - 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)); - System.out.println((double)corr/(2*(long)Integer.MAX_VALUE)); - if(is_gap) System.out.println("GAP!"); - } + // fixed rollover size + final long ROLLOVER = 2*(long)Integer.MAX_VALUE; + // loop over ungated and gated, to apply correction separately for each + final int is_ungated = 0; + final int is_gated = 1; + for (int clk : List.of(is_ungated, is_gated)) { + boolean 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; + String clock_name; + long diff; + boolean is_rollover; + switch (clk) { + case is_ungated: + clock_name = "ungated clock"; + diff = previous.clock - next.clock + 1; + is_rollover = previous.clock > next.clock; + break; + default: // is_gated + clock_name = "gated clock"; + diff = previous.gatedClock - next.gatedClock + 1; + is_rollover = previous.gatedClock > next.gatedClock; + break; } - 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!"); + boolean is_gap = diff <= -ROLLOVER / 2; + if (is_rollover || is_gap) { + for (int j=i; j", this.scalers.get(j).dsc2.clock)); + if (is_gap) this.scalers.get(j).dsc2.clock -= ROLLOVER; + else this.scalers.get(j).dsc2.clock += ROLLOVER; + if (j==i) logger.info( String.format(" -> %d", this.scalers.get(j).dsc2.clock)); + break; + default: // is_gated + if (j==i) logger.info( String.format("fixing gated clock rollover: %d ->", this.scalers.get(j).dsc2.gatedClock)); + if (is_gap) this.scalers.get(j).dsc2.gatedClock -= ROLLOVER; + else this.scalers.get(j).dsc2.gatedClock += ROLLOVER; + if (j==i) logger.info( String.format(" -> %d", this.scalers.get(j).dsc2.gatedClock)); + break; + } + if (j==i) { + if (Math.abs( ((double)diff/ROLLOVER) - 1 ) > 0.01) { + logger.warning("found " + clock_name + " rollover of unexpected size " + diff + " (expected about " + ROLLOVER + ")"); + } + } } + modified = true; + break; } - modified = true; - break; } } } } - + + public static void main(String[] args) { final String dir = System.getenv("HOME")+"/data/"; From 569c65ac62aba7adbed6a5dec3a45a687261e357 Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Thu, 9 Apr 2026 12:11:58 -0400 Subject: [PATCH 7/8] fix: rat warning --- .../java/org/jlab/detector/scalers/DaqScalersSequence.java | 5 +++-- 1 file changed, 3 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 5a2650772e..ae102fb986 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 @@ -406,8 +406,9 @@ public void fixClockRollover() { break; } if (j==i) { - if (Math.abs( ((double)diff/ROLLOVER) - 1 ) > 0.01) { - logger.warning("found " + clock_name + " rollover of unexpected size " + diff + " (expected about " + ROLLOVER + ")"); + double rat = Math.abs((double)diff/ROLLOVER) - 1; + if (Math.abs(rat) > 0.001) { + logger.warning("found " + clock_name + " rollover of unexpected size; off by " + rat*100 + "%"); } } } From b9eafed16f7835257df306ca2b2bb3042d26eb67 Mon Sep 17 00:00:00 2001 From: Christopher Dilks Date: Thu, 9 Apr 2026 12:13:19 -0400 Subject: [PATCH 8/8] fix: increase thresh --- .../main/java/org/jlab/detector/scalers/DaqScalersSequence.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ae102fb986..49f71ddf6a 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 @@ -407,7 +407,7 @@ public void fixClockRollover() { } if (j==i) { double rat = Math.abs((double)diff/ROLLOVER) - 1; - if (Math.abs(rat) > 0.001) { + if (Math.abs(rat) > 0.005) { logger.warning("found " + clock_name + " rollover of unexpected size; off by " + rat*100 + "%"); } }