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,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
Expand All @@ -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));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.size(); ++j) {
if (j==i) System.out.print( String.format("FIXING CLOCK ROLLOVER: %d %d -> ",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.size(); ++j) {
switch (clk) {
case is_ungated:
if (j==i) logger.info( String.format("fixing ungated clock rollover: %d ->", 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/";
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=125e6; // for RG-A spring 2018 6.4 GeV data
this.read(bank);
this.calibrate(fcupTable,slmTable,seconds);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -110,4 +110,4 @@ public final void read(Bank bank) {
}
}

}
}
Loading