Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,40 @@ public void add(DaqScaler other) {
protected void calibrate(IndexedTable fcupTable,IndexedTable slmTable,double seconds,double liveSeconds) {

if (this.clock > 0) {

// complain if a hard-coded clock frequency was used
String prefix = String.format("clockbug [%s]", this.getClass().getSimpleName());
boolean clockbug = false;
if(Math.abs(this.clockFreq - ((1e6)+1)) < 0.1) {
System.err.println(String.format("%s: used hard-coded clockFreq from Dsc2Scaler(bank,table,table,seconds)", prefix));
clockbug = true;
}
else if(Math.abs(this.clockFreq - ((1e6)+2)) < 0.1) {
System.err.println(String.format("%s: used hard-coded clockFreq from StruckScaler()", prefix));
clockbug = true;
}
else if(Math.abs(this.clockFreq - ((1e6)+3)) < 0.1) {
System.err.println(String.format("%s: used hard-coded clockFreq from StruckScaler(table,table,table)", prefix));
clockbug = true;
}
else
System.err.println(String.format("%s: clockFreq OK (value=%f)", prefix, this.clockFreq));

// the hard-coded clock frequency is 1 MHz, but if it was used, it'll be 1 MHz + a few Hz; correct it now, along
// with the `seconds` and `liveSeconds`
if(clockbug) {
seconds *= this.clockFreq / 1e6;
liveSeconds *= this.clockFreq / 1e6;
this.clockFreq = 1e6;
}

// print the clock
System.err.println(String.format("%s: toString: %s", prefix, this.toString()));

// ==================================================================================
// original code
// ==================================================================================

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
Expand All @@ -97,6 +131,36 @@ protected void calibrate(IndexedTable fcupTable,IndexedTable slmTable,double sec
this.beamCharge = q * fcup_atten / fcup_slope;
this.beamChargeGated = qg * fcup_atten / fcup_slope;
}

// ==================================================================================

// print the beamCharge from the original code
System.err.println(String.format("%s: clockFreq@%f beamCharge=%f beamChargeGated=%f", prefix, this.clockFreq, this.beamCharge, this.beamChargeGated));

// now redo the calculation as if the clock frequency were 100 kHz
double clockFreq100 = 100000;
double seconds100 = seconds * this.clockFreq / clockFreq100;
double liveSeconds100 = liveSeconds * this.clockFreq / clockFreq100;
double beamCharge100;
double beamChargeGated100;

double q100 = (double)this.slm - slm_offset * seconds100;
double qg100 = (double)this.gatedSlm - slm_offset * liveSeconds100;
double beamChargeSLM100 = q100 * slm_atten / slm_slope;
double beamChargeGatedSLM100 = qg100 * slm_atten / slm_slope;
// double livetime100 = (double)this.gatedClock / this.clock;

if (fcup_atten<1e-8 || fcup_slope<1e-8) {
beamCharge100 = beamChargeSLM100;
beamChargeGated100 = beamChargeGatedSLM100;
}
else {
q100 = (double)this.fcup - fcup_offset * seconds100;
qg100 = (double)this.gatedFcup - fcup_offset * liveSeconds100;
beamCharge100 = q100 * fcup_atten / fcup_slope;
beamChargeGated100 = qg100 * fcup_atten / fcup_slope;
}
System.err.println(String.format("%s: clockFreq@%f beamCharge=%f beamChargeGated=%f", prefix, clockFreq100, beamCharge100, beamChargeGated100));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)+1;
this.read(bank);
this.calibrate(fcupTable,slmTable,seconds);
}
Expand Down Expand Up @@ -110,4 +110,4 @@ public final void read(Bank bank) {
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public final Interval getStableInterval(Bank bank, IndexedTable helTable) {
}

public StruckScaler() {
this.clockFreq = 1e6;
this.clockFreq = (1e6)+2;
}

/**
Expand All @@ -178,7 +178,7 @@ public StruckScaler() {
public StruckScaler(Bank bank,IndexedTable fcupTable, IndexedTable slmTable, IndexedTable helTable) {

// the STRUCK's clock is 1 MHz
this.clockFreq = 1e6;
this.clockFreq = (1e6)+3;

// Here we're going to assume the stable period is the same Struck
// period throughout a single readout. Almost always correct ...
Expand Down Expand Up @@ -239,4 +239,4 @@ else if (Input.equals(Input.CLOCK, chan)) {

this.calibrate(fcupTable,slmTable);
}
}
}
28 changes: 28 additions & 0 deletions scan.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// a more general monitor, for things like <sinPhiH> or helicity
// - this reads DST files or skim files
// - can be run on slurm
// - note: search for 'CUT' to find which cuts are applied

import org.jlab.jnp.hipo4.io.HipoReader;
import org.jlab.jnp.hipo4.data.Event;
import org.jlab.jnp.hipo4.data.Bank;
import org.jlab.jnp.hipo4.data.SchemaFactory;

def filename = args[0];

HipoReader reader = new HipoReader();
reader.setTags(0);
reader.open(filename);
SchemaFactory schema = reader.getSchemaFactory();

while(reader.hasNext()) {
Bank scalerBank = new Bank(schema.getSchema("RUN::scaler"));
Event event = new Event();
reader.nextEvent(event);
event.read(scalerBank);
if(scalerBank.getRows()>0) {
System.out.println("beamCharge=${scalerBank.getFloat('fcup', 0)} beamChargeGated=${scalerBank.getFloat('fcupgated', 0)}");
}
}

reader.close();
19 changes: 19 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -euo pipefail
sep() { echo '=================================================================================='; }
# ./build-coatjava.sh -T8 --clara
rm -vfr tmp
coatjava/bin/run-clara \
-y etc/services/rgd-clarode.yml \
-t 8 \
-n 500 \
-c ./clara \
-o ./tmp \
validation/advanced-tests/data/evio/rg-d/clas_018779.evio.01339
sep
grep \
--color \
'^clockbug.*' \
$(find tmp/log -type f -name '*dpe.log')
sep
run-groovy scan.groovy tmp/rec_clas_018779.evio.01339.hipo
Loading