mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-13 13:27:14 +02:00
almost done
This commit is contained in:
@ -56,6 +56,7 @@ using namespace std;
|
|||||||
#define COULD_NOT_PULSE_PIXEL 0x0000000000040000ULL
|
#define COULD_NOT_PULSE_PIXEL 0x0000000000040000ULL
|
||||||
#define COULD_NOT_PULSE_PIXEL_NMOVE 0x0000000000080000ULL
|
#define COULD_NOT_PULSE_PIXEL_NMOVE 0x0000000000080000ULL
|
||||||
#define COULD_NOT_PULSE_CHIP 0x0000000000100000ULL
|
#define COULD_NOT_PULSE_CHIP 0x0000000000100000ULL
|
||||||
|
#define COULD_NOT_SET_RATE_CORRECTION 0x0000000000200000ULL
|
||||||
|
|
||||||
// 0x00000000FFFFFFFFULL
|
// 0x00000000FFFFFFFFULL
|
||||||
/** @short class returning all error messages for error mask */
|
/** @short class returning all error messages for error mask */
|
||||||
@ -177,6 +178,10 @@ public:
|
|||||||
if(slsErrorMask&COULD_NOT_PULSE_CHIP)
|
if(slsErrorMask&COULD_NOT_PULSE_CHIP)
|
||||||
retval.append("Could not pulse chip\n");
|
retval.append("Could not pulse chip\n");
|
||||||
|
|
||||||
|
if(slsErrorMask&COULD_NOT_SET_RATE_CORRECTION)
|
||||||
|
retval.append("Could not set rate correction\n");
|
||||||
|
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -43,11 +43,15 @@ unsigned int Feb_Control_triggerMode; //internal timer, external start,
|
|||||||
unsigned int Feb_Control_externalEnableMode; //external enabling engaged and it's polarity
|
unsigned int Feb_Control_externalEnableMode; //external enabling engaged and it's polarity
|
||||||
unsigned int Feb_Control_subFrameMode;
|
unsigned int Feb_Control_subFrameMode;
|
||||||
|
|
||||||
|
|
||||||
unsigned int Feb_Control_nimages;
|
unsigned int Feb_Control_nimages;
|
||||||
double Feb_Control_exposure_time_in_sec;
|
double Feb_Control_exposure_time_in_sec;
|
||||||
int Feb_Control_subframe_exposure_time_in_10nsec;
|
int Feb_Control_subframe_exposure_time_in_10nsec;
|
||||||
double Feb_Control_exposure_period_in_sec;
|
double Feb_Control_exposure_period_in_sec;
|
||||||
|
|
||||||
|
int Feb_Control_RateTable_Tau_in_nsec = -1;
|
||||||
|
int Feb_Control_RateTable_Subexptime_in_nsec = -1;
|
||||||
|
|
||||||
unsigned int Feb_Control_trimbit_size;
|
unsigned int Feb_Control_trimbit_size;
|
||||||
unsigned int* Feb_Control_last_downloaded_trimbits;
|
unsigned int* Feb_Control_last_downloaded_trimbits;
|
||||||
|
|
||||||
@ -1382,7 +1386,7 @@ int Feb_Control_SetSubFrameExposureTime(int the_subframe_exposure_time_in_10nsec
|
|||||||
printf("Sub Frame Exposure time set to: %d\n",Feb_Control_subframe_exposure_time_in_10nsec);
|
printf("Sub Frame Exposure time set to: %d\n",Feb_Control_subframe_exposure_time_in_10nsec);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
int Feb_Control_GetSubFrameExposureTime(){return Feb_Control_subframe_exposure_time_in_10nsec;}
|
int Feb_Control_GetSubFrameExposureTime(){return Feb_Control_subframe_exposure_time_in_10nsec*10;}
|
||||||
|
|
||||||
int Feb_Control_SetExposurePeriod(double the_exposure_period_in_sec){
|
int Feb_Control_SetExposurePeriod(double the_exposure_period_in_sec){
|
||||||
Feb_Control_exposure_period_in_sec = the_exposure_period_in_sec;
|
Feb_Control_exposure_period_in_sec = the_exposure_period_in_sec;
|
||||||
@ -1792,35 +1796,110 @@ int Feb_Control_PulseChip(int npulses){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int Feb_Control_PrintCorrectedValues(){
|
|
||||||
int i;
|
int Feb_Control_Get_RateTable_Tau_in_nsec(){ return Feb_Control_RateTable_Tau_in_nsec;}
|
||||||
int delta, slope, base, lsb, corr;
|
int Feb_Control_Get_RateTable_Subexptime_in_nsec(){ return Feb_Control_RateTable_Subexptime_in_nsec;}
|
||||||
for (i=0; i < 4096; i++)
|
|
||||||
{
|
int Feb_Control_SetRateCorrectionTau(int tau_in_Nsec){
|
||||||
lsb = i&3;
|
|
||||||
base = Feb_Control_rate_correction_table[i>>2] & 0x3fff;
|
double sub_expure_time_in_sec = (double)(Feb_Control_GetSubFrameExposureTime())/(double)1e9;
|
||||||
slope = ((Feb_Control_rate_correction_table[i>>2] & 0x3c000) >> 14);
|
double tau_in_sec = (double)tau_in_Nsec/(double)1e9;
|
||||||
delta = slope*lsb;
|
unsigned int np = 16384; //max slope 16 * 1024
|
||||||
corr = delta+base;
|
double b0[1024];
|
||||||
printf("Readout Input: %d,\tBase:%d,\tSlope:%d,\tLSB:%d,\tDelta:%d\tResult:%d\tReal:%f\n",
|
double m[1024];
|
||||||
i, base, slope, lsb, delta, corr, Feb_Control_rate_meas[i]);
|
|
||||||
|
|
||||||
|
if(tau_in_sec<0||sub_expure_time_in_sec<0){
|
||||||
|
printf("Error tau %f and sub_expure_time %f must be greater than 0.\n", tau_in_sec, sub_expure_time_in_sec);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
return 1;
|
|
||||||
|
printf("\tCalculating table for tau of %f ns.\n", tau_in_Nsec);
|
||||||
|
|
||||||
|
for(int i=0;i<np;i++)
|
||||||
|
Feb_Control_rate_meas[i] = i*exp(-i/sub_expure_time_in_sec*tau_in_sec);
|
||||||
|
|
||||||
|
/*
|
||||||
|
b : index/address of block ram/rate correction table
|
||||||
|
b0 : base in vhdl
|
||||||
|
m : slope in vhdl
|
||||||
|
|
||||||
|
Firmware:
|
||||||
|
data_in(11..2) -> memory address --> memory
|
||||||
|
data_in( 1..0) -> lsb
|
||||||
|
|
||||||
|
mem_data_out(13.. 0) -> base
|
||||||
|
mem_data_out(17..14) -> slope
|
||||||
|
|
||||||
|
delta = slope*lsb
|
||||||
|
corr = base+delta
|
||||||
|
*/
|
||||||
|
|
||||||
|
int next_i=0;
|
||||||
|
|
||||||
|
b0[0] = 0;
|
||||||
|
m[0] = 1;
|
||||||
|
|
||||||
|
for(int b=1;b<1024;b++){
|
||||||
|
if(m[b-1]<14.5){
|
||||||
|
double s=0,sx=0,sy=0,sxx=0,sxy=0;
|
||||||
|
for(;;next_i++){
|
||||||
|
if(next_i>=np){
|
||||||
|
cprintf(BG_RED,"Error bin problem ???\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
double x = Feb_Control_rate_meas[next_i] - b*4;
|
||||||
|
double y = next_i;
|
||||||
|
printf("Start Loop x: %f,\t y: %f,\t s: %f,\t sx: %f,\t sy: %f,\t sxx: %f,\t sxy: %f,\t "
|
||||||
|
"next_i: %d,\t b: %d,\t Feb_Control_rate_meas[next_i]: %f\n",
|
||||||
|
x, y, s, sx, sy, sxx, sxy, next_i, b, Feb_Control_rate_meas[next_i]);
|
||||||
|
|
||||||
|
if(x < -0.5) continue;
|
||||||
|
if(x > 3.5) break;
|
||||||
|
s += 1;
|
||||||
|
sx += x;
|
||||||
|
sy += y;
|
||||||
|
sxx += x*x;
|
||||||
|
sxy += x*y;
|
||||||
|
printf("End Loop x: %f,\t y: %f,\t s: %f,\t sx: %f,\t sy: %f,\t sxx: %f,\t sxy: %f,\t "
|
||||||
|
"next_i: %d,\t b: %d,\t Feb_Control_rate_meas[next_i]: %f\n",
|
||||||
|
x, y, s, sx, sy, sxx, sxy, next_i, b, Feb_Control_rate_meas[next_i]);
|
||||||
|
}
|
||||||
|
double delta = s*sxx - sx*sx;
|
||||||
|
b0[b] = (sxx*sy - sx*sxy)/delta;
|
||||||
|
m[b] = (s*sxy - sx*sy) /delta;
|
||||||
|
|
||||||
|
if(m[b]<0||m[b]>15)
|
||||||
|
m[b]=15;
|
||||||
|
printf("After Loop s: %f,\t sx: %f,\t sy: %f,\t sxx: %f,\t sxy: %f,\t "
|
||||||
|
"next_i: %d,\t b: %d,\t Feb_Control_rate_meas[next_i]: %f\n",
|
||||||
|
s, sx, sy, sxx, sxy, next_i, b, Feb_Control_rate_meas[next_i]);
|
||||||
|
// cout<<s<<" "<<sx<<" "<<sy<<" "<<sxx<<" "<<" "<<sxy<<" "<<delta<<" "<<m[b]<<" "<<b0[b]<<endl;
|
||||||
|
}else{
|
||||||
|
b0[b] = b0[b-1] + 4*m[b-1];
|
||||||
|
m[b] = m[b-1];
|
||||||
|
printf("else\n");
|
||||||
|
}
|
||||||
|
Feb_Control_rate_correction_table[b] = (((int)(m[b]+0.5)&0xf)<<14) | ((int)(b0[b]+0.5)&0x3fff);
|
||||||
|
printf("After Loop 4*b: %d\tbase:%d\tslope:%d\n",4*b, (int)(b0[b]+0.5), (int)(m[b]+0.5) );
|
||||||
|
}
|
||||||
|
|
||||||
|
if(SetRateCorrectionTable(Feb_Control_rate_correction_table)){
|
||||||
|
Feb_Control_RateTable_Tau_in_nsec = tau_in_Nsec;
|
||||||
|
Feb_Control_RateTable_Subexptime_in_nsec = Feb_Control_GetSubFrameExposureTime();
|
||||||
|
return 1;
|
||||||
|
}else{
|
||||||
|
Feb_Control_RateTable_Tau_in_nsec = -1;
|
||||||
|
Feb_Control_RateTable_Subexptime_in_nsec = -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Feb_Control_SetRateCorrectionVariable(int activate_rate_correction){
|
|
||||||
if(activate_rate_correction){
|
|
||||||
Feb_Control_subFrameMode |= DAQ_NEXPOSURERS_ACTIVATE_RATE_CORRECTION;
|
|
||||||
printf("Rate correction activated.\n");
|
|
||||||
printf("Note, the rate correction will only be applied when the detector is run in auto summing 12 bit mode.\n");
|
|
||||||
}else{
|
|
||||||
Feb_Control_subFrameMode &= ~DAQ_NEXPOSURERS_ACTIVATE_RATE_CORRECTION;
|
|
||||||
printf("Rate correction deactivated.\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int Feb_Control_SetRateCorrectionTable(unsigned int *table){
|
int Feb_Control_SetRateCorrectionTable(unsigned int *table){
|
||||||
if(!table){
|
if(!table){
|
||||||
@ -1836,110 +1915,47 @@ int Feb_Control_SetRateCorrectionTable(unsigned int *table){
|
|||||||
if(!Feb_Interface_WriteMemoryInLoops(Module_GetTopLeftAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)||
|
if(!Feb_Interface_WriteMemoryInLoops(Module_GetTopLeftAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)||
|
||||||
!Feb_Interface_WriteMemoryInLoops(Module_GetTopRightAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)||
|
!Feb_Interface_WriteMemoryInLoops(Module_GetTopRightAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)||
|
||||||
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
||||||
printf(" some errror!\n");
|
cprintf(BG_RED,"Error in Top Writing to Memory ::Feb_Control_SetRateCorrectionTable\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
if(!Feb_Interface_WriteMemoryInLoops(Module_GetBottomLeftAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)||
|
if(!Feb_Interface_WriteMemoryInLoops(Module_GetBottomLeftAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)||
|
||||||
!Feb_Interface_WriteMemoryInLoops(Module_GetBottomRightAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)||
|
!Feb_Interface_WriteMemoryInLoops(Module_GetBottomRightAddress(&modules[Feb_Control_current_index]),1,0,1024,Feb_Control_rate_correction_table)||
|
||||||
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
!Feb_Control_StartDAQOnlyNWaitForFinish(5000)){
|
||||||
printf(" some errror!\n");
|
cprintf(BG_RED,"Error in Bottom Writing to Memory ::Feb_Control_SetRateCorrectionTable\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
SetRateCorrectionVariable(1,print_info);
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int Feb_Control_SetRateCorrectionTau(double tau){
|
|
||||||
//sub_expure_time should be known
|
|
||||||
|
|
||||||
unsigned int np = 16384; //max slope 16 * 1024
|
void Feb_Control_SetRateCorrectionVariable(int activate_rate_correction){
|
||||||
double b0[1024];
|
if(activate_rate_correction){
|
||||||
double m[1024];
|
Feb_Control_subFrameMode |= DAQ_NEXPOSURERS_ACTIVATE_RATE_CORRECTION;
|
||||||
|
printf("Rate correction activated.\n");
|
||||||
|
printf("Note, the rate correction will only be applied when the detector is run in auto summing 12 bit mode.\n");
|
||||||
|
}else{
|
||||||
|
Feb_Control_subFrameMode &= ~DAQ_NEXPOSURERS_ACTIVATE_RATE_CORRECTION;
|
||||||
|
printf("Rate correction deactivated.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(tau<0||sub_expure_time<0)
|
|
||||||
{
|
int Feb_Control_PrintCorrectedValues(){
|
||||||
printf("Error tau %f and sub_expure_time %f must be greater than 0.\n", tau, sub_expure_time);
|
int i;
|
||||||
return 0;
|
int delta, slope, base, lsb, corr;
|
||||||
|
for (i=0; i < 4096; i++){
|
||||||
|
lsb = i&3;
|
||||||
|
base = Feb_Control_rate_correction_table[i>>2] & 0x3fff;
|
||||||
|
slope = ((Feb_Control_rate_correction_table[i>>2] & 0x3c000) >> 14);
|
||||||
|
delta = slope*lsb;
|
||||||
|
corr = delta+base;
|
||||||
|
printf("Readout Input: %d,\tBase:%d,\tSlope:%d,\tLSB:%d,\tDelta:%d\tResult:%d\tReal:%f\n",
|
||||||
|
i, base, slope, lsb, delta, corr, Feb_Control_rate_meas[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\tCalculating table for tau of %f ns.\n", tau*1e9);
|
|
||||||
|
|
||||||
// Basic rate correction table
|
|
||||||
for(int i=0;i<np;i++)
|
|
||||||
meas[i] = i*exp(-i/sub_expure_time*tau);
|
|
||||||
|
|
||||||
|
|
||||||
// b : index/address of block ram/rate correction table
|
|
||||||
// b0 : base in vhdl
|
|
||||||
// m : slope in vhdl
|
|
||||||
//
|
|
||||||
// Firmware:
|
|
||||||
// data_in(11..2) -> memory address --> memory
|
|
||||||
// data_in( 1..0) -> lsb
|
|
||||||
//
|
|
||||||
// mem_data_out(13.. 0) -> base
|
|
||||||
// mem_data_out(17..14) -> slope
|
|
||||||
//
|
|
||||||
// delta = slope*lsb
|
|
||||||
// corr = base+delta
|
|
||||||
|
|
||||||
int next_i=0;
|
|
||||||
|
|
||||||
b0[0] = 0;
|
|
||||||
m[0] = 1;
|
|
||||||
|
|
||||||
for(int b=1;b<1024;b++)
|
|
||||||
{
|
|
||||||
if(m[b-1]<14.5)
|
|
||||||
{
|
|
||||||
double s=0,sx=0,sy=0,sxx=0,sxy=0;
|
|
||||||
for(;;next_i++)
|
|
||||||
{
|
|
||||||
if(next_i>=np)
|
|
||||||
{
|
|
||||||
printf("Error bin problem ???????\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
double x = meas[next_i] - b*4;
|
|
||||||
double y = next_i;
|
|
||||||
printf("Start Loop x: %f,\t y: %f,\t s: %f,\t sx: %f,\t sy: %f,\t sxx: %f,\t sxy: %f,\t next_i: %d,\t b: %d,\t meas[next_i]: %f\n", x, y, s, sx, sy, sxx, sxy, next_i, b, meas[next_i]);
|
|
||||||
|
|
||||||
if(x < -0.5) continue;
|
|
||||||
if(x > 3.5) break;
|
|
||||||
s += 1;
|
|
||||||
sx += x;
|
|
||||||
sy += y;
|
|
||||||
sxx += x*x;
|
|
||||||
sxy += x*y;
|
|
||||||
printf("End Loop x: %f,\t y: %f,\t s: %f,\t sx: %f,\t sy: %f,\t sxx: %f,\t sxy: %f,\t next_i: %d,\t b: %d,\t meas[next_i]: %f\n", x, y, s, sx, sy, sxx, sxy, next_i, b, meas[next_i]);
|
|
||||||
}
|
|
||||||
double delta = s*sxx - sx*sx;
|
|
||||||
b0[b] = (sxx*sy - sx*sxy)/delta;
|
|
||||||
m[b] = (s*sxy - sx*sy) /delta;
|
|
||||||
|
|
||||||
if(m[b]<0||m[b]>15)
|
|
||||||
m[b]=15;
|
|
||||||
printf("After Loop s: %f,\t sx: %f,\t sy: %f,\t sxx: %f,\t sxy: %f,\t next_i: %d,\t b: %d,\t meas[next_i]: %f\n", s, sx, sy, sxx, sxy, next_i, b, meas[next_i]);
|
|
||||||
// cout<<s<<" "<<sx<<" "<<sy<<" "<<sxx<<" "<<" "<<sxy<<" "<<delta<<" "<<m[b]<<" "<<b0[b]<<endl;
|
|
||||||
}else
|
|
||||||
{
|
|
||||||
b0[b] = b0[b-1] + 4*m[b-1];
|
|
||||||
m[b] = m[b-1];
|
|
||||||
printf("else\n");
|
|
||||||
}
|
|
||||||
rate_correction_table[b] = (((int)(m[b]+0.5)&0xf)<<14) | ((int)(b0[b]+0.5)&0x3fff);
|
|
||||||
printf("After Loop 4*b: %d\tbase:%d\tslope:%d\n",4*b, (int)(b0[b]+0.5), (int)(m[b]+0.5) );
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -184,11 +184,11 @@ int Feb_Control_GetModuleNumber();
|
|||||||
int Feb_Control_ClockRowClock(unsigned int ntimes);
|
int Feb_Control_ClockRowClock(unsigned int ntimes);
|
||||||
int Feb_Control_PulseChip(int npulses);
|
int Feb_Control_PulseChip(int npulses);
|
||||||
|
|
||||||
int Feb_Control_PrintCorrectedValues();
|
int Feb_Control_Get_RateTable_Tau_in_nsec();
|
||||||
void Feb_Control_SetRateCorrectionVariable(int activate_rate_correction);
|
int Feb_Control_Get_RateTable_Subexptime_in_nsec();
|
||||||
|
int Feb_Control_SetRateCorrectionTau(double tau_in_Nsec);
|
||||||
int Feb_Control_SetRateCorrectionTable(unsigned int *table);
|
int Feb_Control_SetRateCorrectionTable(unsigned int *table);
|
||||||
int Feb_Control_SetRateCorrectionTau(double tau);
|
void Feb_Control_SetRateCorrectionVariable(int activate_rate_correction);
|
||||||
|
int Feb_Control_PrintCorrectedValues();
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -163,7 +163,7 @@ int initDetector(){
|
|||||||
setIODelay(650,0);
|
setIODelay(650,0);
|
||||||
setTiming(AUTO_TIMING);
|
setTiming(AUTO_TIMING);
|
||||||
//SetPhotonEnergyCalibrationParameters(-5.8381e-5,1.838515,5.09948e-7,-4.32390e-11,1.32527e-15);
|
//SetPhotonEnergyCalibrationParameters(-5.8381e-5,1.838515,5.09948e-7,-4.32390e-11,1.32527e-15);
|
||||||
//SetRateCorrection(0); //deactivate rate correction
|
setRateCorrection(0); //deactivate rate correction
|
||||||
int enable[2] = {0,1};
|
int enable[2] = {0,1};
|
||||||
setExternalGating(enable);//disable external gating
|
setExternalGating(enable);//disable external gating
|
||||||
Feb_Control_SetInTestModeVariable(0);
|
Feb_Control_SetInTestModeVariable(0);
|
||||||
@ -491,11 +491,34 @@ int pulseChip(int n){
|
|||||||
|
|
||||||
int setRateCorrection(int n){
|
int setRateCorrection(int n){
|
||||||
if(n>=0){
|
if(n>=0){
|
||||||
;
|
if(n>0){
|
||||||
Feb_Control_PrintCorrectedValues();
|
int tau_in_nsec = Feb_Control_Get_RateTable_Tau_in_nsec();
|
||||||
|
int subexp_in_nsec = Feb_Control_Get_RateTable_Subexptime_in_nsec();
|
||||||
|
//same setting
|
||||||
|
if(tau_in_nsec == n) && (subexp_in_nsec == Feb_Control_GetSubFrameExposureTime()){
|
||||||
|
printf("Same Tau %dns, Same subexptime %dns = Same setting, not rewriting rate correction table\n");
|
||||||
|
}
|
||||||
|
//different setting, calculate table
|
||||||
|
else if(!Feb_Control_SetRateCorrectionTau(n)){
|
||||||
|
cprintf(RED,"Rate correction failed. Deactivating rate correction\n");
|
||||||
|
SetRateCorrectionVariable(0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
//activating rate correction
|
||||||
|
SetRateCorrectionVariable(1);
|
||||||
|
Feb_Control_PrintCorrectedValues();
|
||||||
|
}else{
|
||||||
|
//deactivating rate correction
|
||||||
|
SetRateCorrectionVariable(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
//return tau if it is a valid value (written to memory properly)
|
||||||
|
int tau_in_nsec = Feb_Control_GetTau_in_nsec();
|
||||||
|
if(tau_in_nsec>=0)
|
||||||
|
return tau_in_nsec;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -788,7 +811,7 @@ int64_t setTimer(enum timerIndex ind, int64_t val){
|
|||||||
printf(" Setting sub exp time: %dns\n",(int)val/10);
|
printf(" Setting sub exp time: %dns\n",(int)val/10);
|
||||||
Feb_Control_SetSubFrameExposureTime(val/10);
|
Feb_Control_SetSubFrameExposureTime(val/10);
|
||||||
}
|
}
|
||||||
return (Feb_Control_GetSubFrameExposureTime()*10);
|
return (Feb_Control_GetSubFrameExposureTime());
|
||||||
|
|
||||||
|
|
||||||
case FRAME_PERIOD:
|
case FRAME_PERIOD:
|
||||||
|
@ -2416,27 +2416,44 @@ int multiSlsDetector::flatFieldCorrect(double* datain, double *errin, double* da
|
|||||||
int multiSlsDetector::setRateCorrection(double t){
|
int multiSlsDetector::setRateCorrection(double t){
|
||||||
// double tdead[]=defaultTDead;
|
// double tdead[]=defaultTDead;
|
||||||
|
|
||||||
if (t==0) {
|
if (getDetectorsType() == MYTHEN){
|
||||||
thisMultiDetector->correctionMask&=~(1<<RATE_CORRECTION);
|
if (t==0) {
|
||||||
|
thisMultiDetector->correctionMask&=~(1<<RATE_CORRECTION);
|
||||||
if(getDetectorsType() == MYTHEN)
|
|
||||||
return thisMultiDetector->correctionMask&(1<<RATE_CORRECTION);
|
return thisMultiDetector->correctionMask&(1<<RATE_CORRECTION);
|
||||||
|
} else
|
||||||
|
thisMultiDetector->correctionMask|=(1<<RATE_CORRECTION);
|
||||||
|
}
|
||||||
|
|
||||||
} else
|
|
||||||
thisMultiDetector->correctionMask|=(1<<RATE_CORRECTION);
|
|
||||||
|
|
||||||
|
int ret, ret1=-100;
|
||||||
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
|
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
|
||||||
|
|
||||||
if (detectors[idet]) {
|
if (detectors[idet]) {
|
||||||
detectors[idet]->setRateCorrection(t);
|
ret=detectors[idet]->setRateCorrection(t);
|
||||||
if(detectors[idet]->getErrorMask())
|
if(detectors[idet]->getErrorMask())
|
||||||
setErrorMask(getErrorMask()|(1<<idet));
|
setErrorMask(getErrorMask()|(1<<idet));
|
||||||
|
if (ret1==-100)
|
||||||
|
ret1=ret;
|
||||||
|
else if (ret!=ret1)
|
||||||
|
ret1=-1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
std::cout<< "Setting rate correction with dead time "<< thisMultiDetector->tDead << std::endl;
|
if(getDetectorsType() == MYTHEN)
|
||||||
|
std::cout<< "Setting rate correction with dead time "<< thisMultiDetector->tDead << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//mismatch between detectors
|
||||||
|
if(ret1 == -1)
|
||||||
|
return ret1;
|
||||||
|
|
||||||
|
if (getDetectorsType() != MYTHEN){
|
||||||
|
if (ret1==0) {
|
||||||
|
thisMultiDetector->correctionMask&=~(1<<RATE_CORRECTION);
|
||||||
|
return thisMultiDetector->correctionMask&(1<<RATE_CORRECTION);
|
||||||
|
} else
|
||||||
|
thisMultiDetector->correctionMask|=(1<<RATE_CORRECTION);
|
||||||
|
}
|
||||||
return thisMultiDetector->correctionMask&(1<<RATE_CORRECTION);
|
return thisMultiDetector->correctionMask&(1<<RATE_CORRECTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4971,28 +4971,68 @@ int slsDetector::flatFieldCorrect(double* datain, double *errin, double* dataout
|
|||||||
};
|
};
|
||||||
|
|
||||||
int slsDetector::setRateCorrection(double t){
|
int slsDetector::setRateCorrection(double t){
|
||||||
double tdead[]=defaultTDead;
|
|
||||||
|
|
||||||
if (t==0) {
|
if (getDetectorsType() == MYTHEN){
|
||||||
|
double tdead[]=defaultTDead;
|
||||||
|
if (t==0) {
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
std::cout<< "unsetting rate correction" << std::endl;
|
std::cout<< "unsetting rate correction" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
thisDetector->correctionMask&=~(1<<RATE_CORRECTION);
|
thisDetector->correctionMask&=~(1<<RATE_CORRECTION);
|
||||||
} else {
|
} else {
|
||||||
thisDetector->correctionMask|=(1<<RATE_CORRECTION);
|
thisDetector->correctionMask|=(1<<RATE_CORRECTION);
|
||||||
if (t>0)
|
if (t>0)
|
||||||
thisDetector->tDead=t;
|
thisDetector->tDead=t;
|
||||||
else {
|
else {
|
||||||
if (thisDetector->currentSettings<3 && thisDetector->currentSettings>-1)
|
if (thisDetector->currentSettings<3 && thisDetector->currentSettings>-1)
|
||||||
thisDetector->tDead=tdead[thisDetector->currentSettings];
|
thisDetector->tDead=tdead[thisDetector->currentSettings];
|
||||||
else
|
else
|
||||||
thisDetector->tDead=0;
|
thisDetector->tDead=0;
|
||||||
}
|
}
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
std::cout<< "Setting rate correction with dead time "<< thisDetector->tDead << std::endl;
|
std::cout<< "Setting rate correction with dead time "<< thisDetector->tDead << std::endl;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
return thisDetector->correctionMask&(1<<RATE_CORRECTION);
|
return thisDetector->correctionMask&(1<<RATE_CORRECTION);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int fnum=F_SET_RATE_CORRECT;
|
||||||
|
int ret=FAIL;
|
||||||
|
char mess[1000]="";
|
||||||
|
int64_t arg = t*1e9;
|
||||||
|
int64_t retval = -1;
|
||||||
|
#ifdef VERBOSE
|
||||||
|
std::cout<< "Setting Rate Correction to " << arg << endl;
|
||||||
|
#endif
|
||||||
|
if (thisDetector->onlineFlag==ONLINE_FLAG) {
|
||||||
|
if (connectControl() == OK){
|
||||||
|
controlSocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||||
|
controlSocket->SendDataOnly(&arg,sizeof(arg));
|
||||||
|
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||||
|
if (ret!=FAIL) {
|
||||||
|
controlSocket->ReceiveDataOnly(&retval,sizeof(retval));
|
||||||
|
if(retval<0)
|
||||||
|
thisDetector->correctionMask&=~(1<<RATE_CORRECTION);
|
||||||
|
else if(retval>0)
|
||||||
|
thisDetector->correctionMask|=(1<<RATE_CORRECTION);
|
||||||
|
else
|
||||||
|
thisDetector->correctionMask&=~(1<<RATE_CORRECTION);
|
||||||
|
|
||||||
|
thisDetector->tDead = (double)retval/(double)1e9;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||||
|
std::cout<< "Detector returned error: " << mess << std::endl;
|
||||||
|
thisDetector->correctionMask&=~(1<<RATE_CORRECTION);
|
||||||
|
thisDetector->tDead = 0;
|
||||||
|
}
|
||||||
|
disconnectControl();
|
||||||
|
if (ret==FORCE_UPDATE)
|
||||||
|
updateDetector();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return thisDetector->correctionMask&(1<<RATE_CORRECTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user