From 578bb236c946ca2b1e82593564c8fe3bfbce0f9c Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Fri, 18 Sep 2026 18:49:46 -0400 Subject: [PATCH 1/6] do not ignore struck scaler readings with gated clock equal to zero as it can happen due to dead time --- .../src/main/java/org/jlab/detector/scalers/StruckScalers.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/StruckScalers.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/StruckScalers.java index ee28e0b744..ee766c6969 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/StruckScalers.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/StruckScalers.java @@ -158,7 +158,7 @@ private void disentangle() { for (int ii=0; ii0) { - if (this.get(ii).gatedClock>0 && this.get(ii+2).gatedClock<0) { + if (this.get(ii).gatedClock>=0 && this.get(ii+2).gatedClock<0) { d.put(this.get(ii+2), this.get(ii)); } } From e468b61353a56f931c4c336ec458aa92dba23373 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Fri, 18 Sep 2026 18:59:20 -0400 Subject: [PATCH 2/6] strip reafings starting from the end of the list (bug fix) --- .../src/main/java/org/jlab/detector/scalers/StruckScalers.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/StruckScalers.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/StruckScalers.java index ee766c6969..a74b8cb109 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/StruckScalers.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/StruckScalers.java @@ -194,7 +194,7 @@ private void add() { * @param interval the type of helicity interval to preserve */ private void strip(HelicityInterval interval) { - for (int ii=0; ii=0; ii--) { if (this.get(ii).getHelicityInterval(this.helTable) != interval) { this.remove(ii); } From 869cde540877bb7faa33f94de400a98088991e57 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Mon, 21 Sep 2026 17:48:32 -0400 Subject: [PATCH 3/6] make requirements for building struck scaler readouts more tight --- .../jlab/detector/scalers/StruckScalers.java | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/StruckScalers.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/StruckScalers.java index a74b8cb109..05091ca16d 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/StruckScalers.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/StruckScalers.java @@ -102,6 +102,8 @@ else if (Input.equals(Input.CLOCK, chan)) { break; case StruckScaler.SLOT_UNGATED: if (Input.equals(Input.FCUP, chan)) { + reading.helicity = HelicityBit.createFromRawBit(bank.getByte("helicity",k)); + reading.quartet = HelicityBit.createFromRawBit(bank.getByte("quartet",k)); reading.fcup = bank.getLong("value",k); } else if (Input.equals(Input.SLM, chan)) { @@ -115,6 +117,12 @@ else if (Input.equals(Input.CLOCK, chan)) { break; } } + + // ignore banks with more than the tegular 4 ( (tsettle+tstable) x (gated+ungated) ) readings + // or unbalance between gated/ungated readngs (allow difference by 1) + if(this.size()>(Interval.values().length-1)*StruckScaler.NSLOT || + Math.abs(this.count(StruckScaler.SLOT_GATED)-count(StruckScaler.SLOT_UNGATED))<=1) + this.clear(); } /** @@ -147,6 +155,31 @@ private void copyGate(int source, int destination) { this.copyGate(this.get(source), this.get(destination)); } + /** + * Counts the number of raw readouts for the selected slot + * @param slot the index of the slot + * @return the number + **/ + private int count(int slot) { + int nslot = 0; + for (StruckScaler ss : this) { + switch(slot) { + case StruckScaler.SLOT_GATED: + if(ss.gatedClock>=0 && ss.clock<0) + nslot++; + break; + case StruckScaler.SLOT_UNGATED: + if(ss.gatedClock<0 && ss.clock>=0) + nslot++; + break; + default: + break; + } + } + return nslot; + } + + /** * When there's one interval in a RAW::scaler bank, that interval is * represented by (6) contiguous bank rows. But when there's multiple @@ -156,7 +189,12 @@ private void copyGate(int source, int destination) { private void disentangle() { HashMap d = new HashMap<>(); for (int ii=0; ii0) { if (this.get(ii).gatedClock>=0 && this.get(ii+2).gatedClock<0) { d.put(this.get(ii+2), this.get(ii)); From 2ad5ff555fc73a1c042c95de70eea93d79823691 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Tue, 22 Sep 2026 15:18:14 -0400 Subject: [PATCH 4/6] assign scaler helicity based on closest (instead of previous) timestamp in the helicity sequence --- .../detector/helicity/HelicitySequence.java | 34 +++++++++++++++++-- .../helicity/HelicitySequenceDelayed.java | 22 +++++++++++- .../helicity/HelicitySequenceManager.java | 22 ++++++++++++ .../org/jlab/detector/serial/SerialUtil.java | 12 +++---- 4 files changed, 81 insertions(+), 9 deletions(-) diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/helicity/HelicitySequence.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/helicity/HelicitySequence.java index 11ff2f9ea0..d3ac8ff806 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/helicity/HelicitySequence.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/helicity/HelicitySequence.java @@ -158,6 +158,24 @@ protected final int searchIndex(long timestamp) { final int n = index<0 ? -index-2 : index; return n; } + + /** + * Get the state index of a TI timestamp, based on the closest timestamp + * within the measured sequence. + * This returns invalid (-1) if the timestamp is not contained within + * the range of measured states. + * @param timestamp TI timestamp (i.e. RUN::config.timestamp) + * @return index + */ + protected final int findClosestIndex(long timestamp) { + int index = this.searchIndex(timestamp); + if(index<0 || index==this.size()-1) + return -1; + if(timestamp<(this.getTimestamp(index)+this.getTimestamp(index+1))/2) + return index; + else + return index+1; + } /** * Get the state index of a TI timestamp, based only on the first measured @@ -224,9 +242,21 @@ public HelicityBit search(long timestamp) { * @return the helicity state, null if timestamp is outside of measured range */ public HelicityBit search(long timestamp,int offset) { - final int index = this.searchIndex(timestamp)+offset; + final int index = this.searchIndex(timestamp); + if (index < 0) return HelicityBit.UDF; + else return this.get(index+offset); + } + + /** + * Find the state corresponding to a given timestamp in the measured sequence. + * @param timestamp TI timestamp (i.e. RUN::config.timestamp) + * @param offset number of states offset + * @return the helicity state, null if timestamp is outside of measured range + */ + public HelicityBit findClosest(long timestamp,int offset) { + final int index = this.findClosestIndex(timestamp); if (index < 0) return HelicityBit.UDF; - else return this.getState(index).getHelicity(); + else return this.get(index+offset); } /** diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/helicity/HelicitySequenceDelayed.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/helicity/HelicitySequenceDelayed.java index c843cb886e..9f60b5c1f6 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/helicity/HelicitySequenceDelayed.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/helicity/HelicitySequenceDelayed.java @@ -134,7 +134,27 @@ public HelicityBit search(long timestamp) { * @return the helicity bit */ public HelicityBit search(long timestamp,int offset) { - return this.get(super.searchIndex(timestamp)+offset); + int index = super.searchIndex(timestamp); + if(index>0) + return this.get(index+offset); + else + return HelicityBit.UDF; + } + + /** + * Get the delay-corrected state of a TI timestamp by finding the closest + * timestamp in the measured sequence + * + * @param timestamp TI-timestamp (i.e. RUN::config.timestamp) + * @param offset number of states offset + * @return the helicity bit + */ + public HelicityBit findClosest(long timestamp,int offset) { + int index = super.findClosestIndex(timestamp); + if(index>0) + return this.get(index+offset); + else + return HelicityBit.UDF; } /** diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/helicity/HelicitySequenceManager.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/helicity/HelicitySequenceManager.java index 2c4536787a..599135a841 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/helicity/HelicitySequenceManager.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/helicity/HelicitySequenceManager.java @@ -118,6 +118,28 @@ public HelicityBit search(Event event,int offset) { return this.search(rcfgBank.getInt("run",0),rcfgBank.getLong("timestamp",0),offset); } + /** + * @param runno run number + * @param timestamp TI timestamp + * @param offset number of states offset + * @return helicity for given run number and timestamp plus offset + */ + public HelicityBit findClosest(int runno, long timestamp,int offset) { + if (seqMap.containsKey(runno)) return seqMap.get(runno).findClosest(timestamp,offset); + return HelicityBit.UDF; + } + + /** + * @param event HIPO event + * @param offset number of states offset + * @return helicity for given event plus offset + */ + public HelicityBit findClosest(Event event,int offset) { + event.read(this.rcfgBank); + if (rcfgBank.getRows()<1) return HelicityBit.UDF; + return this.findClosest(rcfgBank.getInt("run",0),rcfgBank.getLong("timestamp",0),offset); + } + public HelicityBit predictGenerated(int runno, long timestamp) { if (seqMap.containsKey(runno)) return seqMap.get(runno).predictGenerated(timestamp); return HelicityBit.UDF; diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/serial/SerialUtil.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/serial/SerialUtil.java index 8967760c25..3efd38af79 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/serial/SerialUtil.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/serial/SerialUtil.java @@ -53,11 +53,11 @@ public static void assignScalerHelicity(Event event, Bank bank, HelicitySequence final int offset = bank.getRows() - row - 1 + readoutStateOffset; // Assign delay-corrected helicity to this HEL::scaler row: - bank.putByte("helicity",row,seq.search(event,offset).value()); + bank.putByte("helicity",row,seq.findClosest(event,offset).value()); if (seq.getHalfWavePlate(event)) - bank.putByte("helicityRaw",0,(byte)(-1*seq.search(event,offset).value())); + bank.putByte("helicityRaw",0,(byte)(-1*seq.findClosest(event,offset).value())); else - bank.putByte("helicityRaw",0,seq.search(event,offset).value()); + bank.putByte("helicityRaw",0,seq.findClosest(event,offset).value()); } } @@ -84,11 +84,11 @@ public static void assignScalerHelicity(Long timestamp, Bank bank, HelicitySeque final int offset = bank.getRows() - row - 1 + readoutStateOffset; // Assign delay-corrected helicity to this HEL::scaler row: - bank.putByte("helicity",row,seq.search(timestamp,offset).value()); + bank.putByte("helicity",row,seq.findClosest(timestamp,offset).value()); if (seq.getHalfWavePlate()) - bank.putByte("helicityRaw",0,(byte)(-1*seq.search(timestamp,offset).value())); + bank.putByte("helicityRaw",0,(byte)(-1*seq.findClosest(timestamp,offset).value())); else - bank.putByte("helicityRaw",0,seq.search(timestamp,offset).value()); + bank.putByte("helicityRaw",0,seq.findClosest(timestamp,offset).value()); } } From f710706792c537496bdc660f9c874bb5d12e2418 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Tue, 22 Sep 2026 17:29:54 -0400 Subject: [PATCH 5/6] bug fix --- .../src/main/java/org/jlab/detector/scalers/StruckScaler.java | 1 + 1 file changed, 1 insertion(+) 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..624d07c337 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 @@ -30,6 +30,7 @@ public class StruckScaler extends DaqScaler { public HelicityBit getQuartet() { return this.quartet; } // These slots corrspond to gated/ungated scalers in RAW::scaler. + public static final int NSLOT=2; public static final int SLOT_GATED=0; public static final int SLOT_UNGATED=1; From d34f4977b8ec2efe3a3ee1836cbce8c4ab7adbd3 Mon Sep 17 00:00:00 2001 From: Raffaella De Vita Date: Tue, 22 Sep 2026 17:53:50 -0400 Subject: [PATCH 6/6] bug fix --- .../src/main/java/org/jlab/detector/scalers/StruckScalers.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/StruckScalers.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/StruckScalers.java index 05091ca16d..694bfa7fa9 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/StruckScalers.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/StruckScalers.java @@ -121,7 +121,7 @@ else if (Input.equals(Input.CLOCK, chan)) { // ignore banks with more than the tegular 4 ( (tsettle+tstable) x (gated+ungated) ) readings // or unbalance between gated/ungated readngs (allow difference by 1) if(this.size()>(Interval.values().length-1)*StruckScaler.NSLOT || - Math.abs(this.count(StruckScaler.SLOT_GATED)-count(StruckScaler.SLOT_UNGATED))<=1) + Math.abs(this.count(StruckScaler.SLOT_GATED)-count(StruckScaler.SLOT_UNGATED))>1) this.clear(); }