mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-06 18:10:40 +02:00
adding 16 bit rate correction in eiger
This commit is contained in:
parent
c678199802
commit
d904f7b32e
@ -59,7 +59,7 @@ using namespace std;
|
||||
#define COULD_NOT_PULSE_CHIP 0x0000000000100000ULL
|
||||
#define COULD_NOT_SET_RATE_CORRECTION 0x0000000000200000ULL
|
||||
#define DETECTOR_NETWORK_PARAMETER 0x0000000000400000ULL
|
||||
#define RATE_CORRECTION_NOT_32BIT 0x0000000000800000ULL
|
||||
#define RATE_CORRECTION_NOT_32or16BIT 0x0000000000800000ULL
|
||||
#define RATE_CORRECTION_NO_TAU_PROVIDED 0x0000000001000000ULL
|
||||
|
||||
// 0x00000000FFFFFFFFULL
|
||||
@ -192,8 +192,8 @@ public:
|
||||
if(slsErrorMask&DETECTOR_NETWORK_PARAMETER)
|
||||
retval.append("Could not set/get detector network parameter\n");
|
||||
|
||||
if(slsErrorMask&RATE_CORRECTION_NOT_32BIT)
|
||||
retval.append("Rate correction Deactivated, must be in 32 bit mode\n");
|
||||
if(slsErrorMask&RATE_CORRECTION_NOT_32or16BIT)
|
||||
retval.append("Rate correction Deactivated, must be in 32 or 16 bit mode\n");
|
||||
|
||||
if(slsErrorMask&RATE_CORRECTION_NO_TAU_PROVIDED)
|
||||
retval.append("Rate correction Deactivated. No default tau provided in file\n");
|
||||
|
@ -51,6 +51,7 @@ double Feb_Control_exposure_period_in_sec;
|
||||
|
||||
int64_t Feb_Control_RateTable_Tau_in_nsec = -1;
|
||||
int64_t Feb_Control_RateTable_Subexptime_in_nsec = -1;
|
||||
int64_t Feb_Control_RateTable_Exptime_in_nsec = -1;
|
||||
|
||||
unsigned int Feb_Control_trimbit_size;
|
||||
unsigned int* Feb_Control_last_downloaded_trimbits;
|
||||
@ -1371,6 +1372,7 @@ int Feb_Control_SetExposureTime(double the_exposure_time_in_sec){
|
||||
return 1;
|
||||
}
|
||||
double Feb_Control_GetExposureTime(){return Feb_Control_exposure_time_in_sec;}
|
||||
int64_t Feb_Control_GetExposureTime_in_nsec(){return (int64_t)(Feb_Control_exposure_time_in_sec*(1E9));}
|
||||
|
||||
int Feb_Control_SetSubFrameExposureTime(int64_t the_subframe_exposure_time_in_10nsec){
|
||||
Feb_Control_subframe_exposure_time_in_10nsec = the_subframe_exposure_time_in_10nsec;
|
||||
@ -1790,25 +1792,39 @@ int Feb_Control_PulseChip(int npulses){
|
||||
|
||||
int64_t Feb_Control_Get_RateTable_Tau_in_nsec(){ return Feb_Control_RateTable_Tau_in_nsec;}
|
||||
int64_t Feb_Control_Get_RateTable_Subexptime_in_nsec(){ return Feb_Control_RateTable_Subexptime_in_nsec;}
|
||||
int64_t Feb_Control_Get_RateTable_Exptime_in_nsec(){ return Feb_Control_RateTable_Exptime_in_nsec;}
|
||||
|
||||
//returns -1 if slope is too high
|
||||
int Feb_Control_SetRateCorrectionTau(int64_t tau_in_Nsec){
|
||||
|
||||
double exptime_in_sec = Feb_Control_GetExposureTime();
|
||||
double sub_expure_time_in_sec = (double)(Feb_Control_GetSubFrameExposureTime())/(double)1e9;
|
||||
|
||||
|
||||
int dr = Feb_Control_GetDynamicRange();
|
||||
double period_in_sec = sub_expure_time_in_sec;
|
||||
if(dr == 16)
|
||||
period_in_sec = exptime_in_sec;
|
||||
|
||||
double tau_in_sec = (double)tau_in_Nsec/(double)1e9;
|
||||
unsigned int np = 16384; //max slope 16 * 1024
|
||||
double b0[1024];
|
||||
double m[1024];
|
||||
|
||||
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);
|
||||
|
||||
if(tau_in_sec<0||period_in_sec<0){
|
||||
if(dr == 32)
|
||||
printf("Error tau %f and sub_exposure_time %f must be greater than 0.\n", tau_in_sec, sub_expure_time_in_sec);
|
||||
else
|
||||
printf("Error tau %f and exposure_time %f must be greater than 0.\n", tau_in_sec, exptime_in_sec);
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("\tCalculating table for tau of %lld ns.\n", tau_in_Nsec);
|
||||
int i;
|
||||
for(i=0;i<np;i++)
|
||||
Feb_Control_rate_meas[i] = i*exp(-i/sub_expure_time_in_sec*tau_in_sec);
|
||||
|
||||
Feb_Control_rate_meas[i] = i*exp(-i/period_in_sec*tau_in_sec);
|
||||
|
||||
/*
|
||||
b : index/address of block ram/rate correction table
|
||||
@ -1886,11 +1902,18 @@ int Feb_Control_SetRateCorrectionTau(int64_t tau_in_Nsec){
|
||||
|
||||
if(Feb_Control_SetRateCorrectionTable(Feb_Control_rate_correction_table)){
|
||||
Feb_Control_RateTable_Tau_in_nsec = tau_in_Nsec;
|
||||
Feb_Control_RateTable_Subexptime_in_nsec = Feb_Control_GetSubFrameExposureTime();
|
||||
if(dr == 32){
|
||||
Feb_Control_RateTable_Subexptime_in_nsec = Feb_Control_GetSubFrameExposureTime();
|
||||
Feb_Control_RateTable_Exptime_in_nsec = -1;
|
||||
}else{
|
||||
Feb_Control_RateTable_Exptime_in_nsec = Feb_Control_GetExposureTime_in_nsec();
|
||||
Feb_Control_RateTable_Subexptime_in_nsec = -1;
|
||||
}
|
||||
return 1;
|
||||
}else{
|
||||
Feb_Control_RateTable_Tau_in_nsec = -1;
|
||||
Feb_Control_RateTable_Subexptime_in_nsec = -1;
|
||||
Feb_Control_RateTable_Exptime_in_nsec = -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -159,6 +159,7 @@ int Feb_Control_GetModuleNumber();
|
||||
unsigned int Feb_Control_GetNExposures();
|
||||
int Feb_Control_SetExposureTime(double the_exposure_time_in_sec);
|
||||
double Feb_Control_GetExposureTime();
|
||||
int64_t Feb_Control_GetExposureTime_in_nsec();
|
||||
int Feb_Control_SetSubFrameExposureTime(int64_t the_subframe_exposure_time_in_10nsec);
|
||||
int64_t Feb_Control_GetSubFrameExposureTime();
|
||||
int Feb_Control_SetExposurePeriod(double the_exposure_period_in_sec);
|
||||
@ -186,6 +187,7 @@ int Feb_Control_GetModuleNumber();
|
||||
|
||||
int64_t Feb_Control_Get_RateTable_Tau_in_nsec();
|
||||
int64_t Feb_Control_Get_RateTable_Subexptime_in_nsec();
|
||||
int64_t Feb_Control_Get_RateTable_Exptime_in_nsec();
|
||||
int Feb_Control_SetRateCorrectionTau(int64_t tau_in_Nsec);
|
||||
int Feb_Control_SetRateCorrectionTable(unsigned int *table);
|
||||
int Feb_Control_GetRateCorrectionVariable();
|
||||
|
@ -533,12 +533,29 @@ int64_t setRateCorrection(int64_t custom_tau_in_nsec){//in nanosec (will never b
|
||||
return 0;
|
||||
}
|
||||
|
||||
//when dynamic range changes, use old tau
|
||||
else if(custom_tau_in_nsec == -1)
|
||||
custom_tau_in_nsec = Feb_Control_Get_RateTable_Tau_in_nsec();
|
||||
|
||||
int64_t tau_in_nsec = Feb_Control_Get_RateTable_Tau_in_nsec();
|
||||
int64_t subexp_in_nsec = Feb_Control_Get_RateTable_Subexptime_in_nsec();
|
||||
int dr = Feb_Control_GetDynamicRange();
|
||||
//default for 32 bit
|
||||
int64_t ratetable_period_in_nsec = Feb_Control_Get_RateTable_Subexptime_in_nsec();
|
||||
int64_t actual_period = Feb_Control_GetSubFrameExposureTime(); //already in nsec
|
||||
//16 bit mode
|
||||
if(dr == 16){
|
||||
ratetable_period_in_nsec = Feb_Control_Get_RateTable_Exptime_in_nsec();
|
||||
actual_period = Feb_Control_GetExposureTime_in_nsec();
|
||||
}
|
||||
|
||||
//same setting
|
||||
if((tau_in_nsec == custom_tau_in_nsec) && (subexp_in_nsec == Feb_Control_GetSubFrameExposureTime())){
|
||||
if((tau_in_nsec == custom_tau_in_nsec) && (ratetable_period_in_nsec == actual_period)){
|
||||
if(dr == 32)
|
||||
printf("Rate Table already created before: Same Tau %lldns, Same subexptime %lldns\n",
|
||||
tau_in_nsec,subexp_in_nsec);
|
||||
tau_in_nsec,ratetable_period_in_nsec);
|
||||
else
|
||||
printf("Rate Table already created before: Same Tau %lldns, Same exptime %lldns\n",
|
||||
tau_in_nsec,ratetable_period_in_nsec);
|
||||
}
|
||||
//different setting, calculate table
|
||||
else{
|
||||
|
@ -4009,8 +4009,16 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t){
|
||||
setTotalProgress();
|
||||
}
|
||||
|
||||
//if eiger, rate corr on, a put statement, dr=32 &setting subexp or dr =16 & setting exptime, set ratecorr to update table
|
||||
double r;
|
||||
if((index == SUBFRAME_ACQUISITION_TIME) && (thisDetector->myDetectorType == EIGER) && (t>=0) && getRateCorrection(r)){
|
||||
if( (thisDetector->myDetectorType == EIGER) &&
|
||||
getRateCorrection(r) &&
|
||||
(t>=0) &&
|
||||
|
||||
(((index == SUBFRAME_ACQUISITION_TIME) && (thisDetector->dynamicRange == 32))||
|
||||
((index == ACQUISITION_TIME) && (thisDetector->dynamicRange == 16)))
|
||||
|
||||
&& (t>=0) && getRateCorrection(r)){
|
||||
setRateCorrection(r);
|
||||
}
|
||||
|
||||
@ -4515,8 +4523,12 @@ int slsDetector::setDynamicRange(int n){
|
||||
if (rateret==FAIL) {
|
||||
controlSocket->ReceiveDataOnly(mess,sizeof(mess));
|
||||
std::cout<< "Detector returned error: " << mess << std::endl;
|
||||
if(strstr(mess,"Rate Correction")!=NULL)
|
||||
setErrorMask((getErrorMask())|(RATE_CORRECTION_NOT_32BIT));
|
||||
if(strstr(mess,"Rate Correction")!=NULL){
|
||||
if(strstr(mess,"32")!=NULL)
|
||||
setErrorMask((getErrorMask())|(RATE_CORRECTION_NOT_32or16BIT));
|
||||
else
|
||||
setErrorMask((getErrorMask())|(COULD_NOT_SET_RATE_CORRECTION));
|
||||
}
|
||||
}
|
||||
}
|
||||
controlSocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
@ -5090,7 +5102,7 @@ int slsDetector::setRateCorrection(double t){
|
||||
if(strstr(mess,"default tau")!=NULL)
|
||||
setErrorMask((getErrorMask())|(RATE_CORRECTION_NO_TAU_PROVIDED));
|
||||
if(strstr(mess,"32")!=NULL)
|
||||
setErrorMask((getErrorMask())|(RATE_CORRECTION_NOT_32BIT));
|
||||
setErrorMask((getErrorMask())|(RATE_CORRECTION_NOT_32or16BIT));
|
||||
else
|
||||
setErrorMask((getErrorMask())|(COULD_NOT_SET_RATE_CORRECTION));
|
||||
}
|
||||
|
@ -2788,15 +2788,26 @@ int set_dynamic_range(int file_des) {
|
||||
#endif
|
||||
}
|
||||
if(ret == OK){
|
||||
int old_dr = setDynamicRange(-1);
|
||||
retval=setDynamicRange(dr);
|
||||
if (dr>=0 && retval!=dr)
|
||||
ret=FAIL;
|
||||
//look at rate correction only if dr change worked
|
||||
if((ret==OK) && (dr!=32) && (dr!=-1) && (getRateCorrectionEnable())){
|
||||
if((ret==OK) && (dr!=32) && (dr!=16) && (dr!=-1) && (getRateCorrectionEnable())){
|
||||
setRateCorrection(0);
|
||||
strcpy(mess,"Switching off Rate Correction. Must be in 32 bit mode\n");
|
||||
strcpy(mess,"Switching off Rate Correction. Must be in 32 or 16 bit mode\n");
|
||||
cprintf(RED,"%s",mess);
|
||||
rateret = FAIL;
|
||||
}else{
|
||||
//setting it if dr changed from 16 to 32 or vice versa with tau value as in rate table
|
||||
if((dr!=-1) && (old_dr != dr) && getRateCorrectionEnable() && (dr == 16 || dr == 32)){
|
||||
setRateCorrection(-1); //tau_ns will not be -1 here
|
||||
if(!getRateCorrectionEnable()){
|
||||
strcpy(mess,"Deactivating Rate Correction. Could not set it.\n");
|
||||
cprintf(RED,"%s",mess);
|
||||
ret=FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -3978,9 +3989,9 @@ int set_rate_correct(int file_des) {
|
||||
|
||||
//set rate
|
||||
else{
|
||||
//not 32 bit mode
|
||||
if((setDynamicRange(-1)!=32) && (tau_ns!=0)){
|
||||
strcpy(mess,"Rate correction Deactivated, must be in 32 bit mode\n");
|
||||
//not 32 or 16 bit mode
|
||||
if((setDynamicRange(-1)!=32) && (setDynamicRange(-1)!=16) && (tau_ns!=0)){
|
||||
strcpy(mess,"Rate correction Deactivated, must be in 32 or 16 bit mode\n");
|
||||
cprintf(RED,"%s",mess);
|
||||
ret=FAIL;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user