/* This script is calculating the New Voltages needed for BB scintillators base on the Gain Curves measured in the TestLab. The procedure as following: 1. Calculate the desired voltages for each scintillator based on the Gain Curves. 2. Take a measurement with the calculated voltages. 3. find the punch through points / elastic protons. 4. Run this script with updated information for the included scripts. 5. Apply the new voltages, and check the ADC channel. 6. Make additional iterations if needed read_hv_mapping.C - read the mapping DB. read_voltages.C - read the voltages saved by HV GUI. read_gains.C - read the gain curves parameters from DB file read_adc.C - read the punch through points for E and dE planes */ #include #include "read_hv_mapping.C" #include "read_voltages.C" #include "read_gains.C" #include "read_adc.C" void main() { //================= read_hv_mapping.C ====================== int EL_crate[24]={0}, EL_slot[24]={0}, EL_ch[24]={0}; int ER_crate[24]={0}, ER_slot[24]={0}, ER_ch[24]={0}; int dEL_crate[24]={0}, dEL_slot[24]={0}, dEL_ch[24]={0}; int dER_crate[24]={0}, dER_slot[24]={0}, dER_ch[24]={0}; //================== read_voltages.C ====================== const int V_rows=16,V_cols=12; // Number of rows and col (number of channels in card). in the *.set file float Voltages[V_rows][V_cols]={0}; // Matrix of voltages as it appears in *.set file int crate[20]={0},sl[20]={0}; // crate - is a HV crate. This info is read from the *.set file //=================== read_gains.C ====================== double c_EL[24]={0},c_ER[24]={0},c_dEL[24]={0},c_dER[24]={0}; // K*V**n+const : K = c_ , n = p_ , const = cnst_ double cnst_EL[24]={0},cnst_ER[24]={0},cnst_dEL[24]={0},cnst_dER[24]={0}; int p_EL[24],p_ER[24],p_dEL[24],p_dER[24]; //=================== read_adc.C ====================== float EL[24]={0}, ER[24]={0}, dEL[24]={0}, dER[24]={0}; // ADC values. //===================================================== read_hv_mapping(&EL_crate[], &EL_slot[], &EL_ch[], &ER_crate[], &ER_slot[], &ER_ch[], &dEL_crate[], &dEL_slot[], &dEL_ch[], &dER_crate[], &dER_slot[], &dER_ch[]); read_voltages( &Voltages[][],V_rows,V_cols,&crate[],&sl[]); read_gains(&c_EL[],&c_ER[],&c_dEL[],&c_dER[],&cnst_EL[],&cnst_ER[],&cnst_dEL[],&cnst_dER[],&p_EL[],&p_ER[],&p_dEL[],&p_dER[]); read_adc( &EL[], &ER[], &dEL[], &dER[]); //=============================================================================================== int i,j,k; float EL_V_new[24]={0},ER_V_new[24]={0},dEL_V_new[24]={0},dER_V_new[24]={0}; int el_crate,el_slt,el_ch, er_crate,er_slt,er_ch, del_crate,del_slt,del_ch, der_crate,der_slt,der_ch; float V_el, ADC_el_expected, ADC_el_actual, D_el, V_el_th, D_ADC_el, D_V_el, V_er, ADC_er_expected, ADC_er_actual, D_er, V_er_th, D_ADC_er, D_V_er, V_del, ADC_del_expected, ADC_del_actual, D_del, V_del_th, D_ADC_del, D_V_del, V_der, ADC_der_expected, ADC_der_actual, D_der, V_der_th, D_ADC_der, D_V_der; float slope; for(i=0;i<24;i++) { int el_crate=EL_crate[i]; int el_slt=EL_slot[i]; int el_ch=EL_ch[i]; if(crate[EL_slot[i]] == el_crate) //check if the mapping match the actual crate { V_el=Voltages[el_slt][el_ch]; } else cout<<"PROBLEM 1"<