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 @@ -81,6 +81,14 @@ protected void calibrate(IndexedTable fcupTable,IndexedTable slmTable,double sec
final double slm_offset = slmTable.getDoubleValue("offset",0,0,0); // Hz
final double slm_atten = slmTable.getDoubleValue("atten",0,0,0); // attenuation

// increase clock frequency by this factor
// double clockFreqFactor = 10.0;
// seconds /= clockFreqFactor;
// liveSeconds /= clockFreqFactor;

// String prefix = String.format("TICK [%s]", this.getClass().getSimpleName());
// System.out.println(String.format("%s freq(orig)=%f seconds=%f liveSeconds=%f ", prefix, this.clockFreq, seconds, liveSeconds) + this.toString());

double q = (double)this.slm - slm_offset * seconds;
double qg = (double)this.gatedSlm - slm_offset * liveSeconds;
this.beamChargeSLM = q * slm_atten / slm_slope;
Expand All @@ -90,13 +98,17 @@ protected void calibrate(IndexedTable fcupTable,IndexedTable slmTable,double sec
if (fcup_atten<1e-8 || fcup_slope<1e-8) {
this.beamCharge = this.beamChargeSLM;
this.beamChargeGated = this.beamChargeGatedSLM;
// System.out.println(String.format("%s [slm]: %f %f", prefix, this.beamChargeGated, this.beamCharge));
}
else {
q = (double)this.fcup - fcup_offset * seconds;
qg = (double)this.gatedFcup - fcup_offset * liveSeconds;
this.beamCharge = q * fcup_atten / fcup_slope;
this.beamChargeGated = qg * fcup_atten / fcup_slope;
// System.out.println(String.format("%s [fcup]: %f %f", prefix, this.beamChargeGated, this.beamCharge));
}
// if(this.getClass().getSimpleName().equals("Dsc2Scaler"))
// System.out.println(String.format("%s %f %f %s", prefix, this.beamChargeGated, this.beamCharge, this.toString()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.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));
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.size(); ++j) {
if (j==i) System.out.print( String.format("FIXING GATED CLOCK ROLLOVER: %d -> ",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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Interval getInterval() {

@Override
public String toString() {
return String.format("i=%s h=%d q=%d %s",this.interval,this.helicity.value(),this.quartet.value(),super.toString());
return String.format("[STRUCK] i=%s h=%d q=%d %s",this.interval,this.helicity.value(),this.quartet.value(),super.toString());
}

/**
Expand Down Expand Up @@ -239,4 +239,4 @@ else if (Input.equals(Input.CLOCK, chan)) {

this.calibrate(fcupTable,slmTable);
}
}
}