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..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 @@ -74,6 +74,12 @@ 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())); + // 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 final double fcup_atten = fcupTable.getDoubleValue("atten",0,0,0); // attenuation @@ -97,6 +103,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=%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/DaqScalersSequence.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/scalers/DaqScalersSequence.java index 2741112635..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 @@ -361,27 +361,66 @@ public boolean validateOrdering() { * 2. Assume any subsequent clock decrease is a rollover. */ public void fixClockRollover() { - 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; - if (previous.clock > next.clock) { - 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)); + // 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; + } + 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) { + double rat = Math.abs((double)diff/ROLLOVER) - 1; + if (Math.abs(rat) > 0.005) { + logger.warning("found " + clock_name + " rollover of unexpected size; off by " + rat*100 + "%"); + } + } + } + modified = true; + break; } - modified = true; - break; } } } } - + + public static void main(String[] args) { final String dir = System.getenv("HOME")+"/data/"; 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..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; + 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); } @@ -110,4 +110,4 @@ public final void read(Bank bank) { } } -} \ No newline at end of file +}