/************************************************************************* \ Name: HVCalib.cc Created by: Luisa Sabrina Stark Schneebeli, April 2009 sabrina.stark@phys.ethz.ch Contents: Class reading the calibration table for DAC to HV values \*************************************************************************/ #include #include #include #include #include "HVCalib.h" using namespace std; HVCalib::HVCalib(HVConfig* hvConfig) { char calibfile[80], dLine[6000]; int idac, idacOld, istep, ihv1000, ihvOld; bool first = true; float hv1000,dac; double intpart; Config = hvConfig; iDACMin = Config->DACMin; fHVCalibSlope = Config->fHVCalibSlope; NDACValues = Config->DACMax - Config->DACMin; NHVValues = 10*NDACValues; HVArray = new double*** [Config->NumHVBoards]; DACArray = new int*** [Config->NumHVBoards]; for(int i=0; iNumHVBoards; i++) { HVArray[i] = new double** [NUM_CHAINS]; DACArray[i] = new int** [NUM_CHAINS]; for(int j=0; jNumHVBoards; i++){ for(int j=0; jfUSBDevice[i],65+j,1); ifstream fin(calibfile); while(fin){ fin >> dac; idacOld = 0; if ((int) dac >= Config->DACMin) { if (first){ iDACMin = (int) dac; first = false; } idac = (int)dac - iDACMin; istep = idac - idacOld; for(int k=0; k=NDACValues) break; fin>>HVArray[i][j][k][idac]; for (int l=1; l 11240-iDACMin) // return; } } idacOld = idac; } else{ fin.getline(dLine,6000,'\n'); // Skip low voltage region } } } } for(int i=0; iNumHVBoards; i++){ for(int j=0; j= 0.5){ ihv1000 = (int)((hv1000>=0)?ceil(hv1000):floor(hv1000)); } else ihv1000 = (int)((hv1000<0)?ceil(hv1000):floor(hv1000)); if (ihv1000 <= ihvOld) continue; else if (ihv1000 > ihvOld){ for (int m=0; m<(ihv1000-ihvOld); m++){ DACArray[i][j][k][ihvOld+m] = l+iDACMin; //printf("HV = %d, HVArr = %f, DACArray = %d, m = %d. \n",ihvOld+m,HVArray[i][j][k][l],DACArray[i][j][k][ihvOld+m],m); // printf("DACArray[i][j][k][0] = %d\n", DACArray[i][j][k][0]); } ihvOld = ihv1000; } } } } } } ///////////////////////////////////////////////////////////////////////// HVCalib::~HVCalib() { for(int i=0; iNumHVBoards; i++) { for(int j=0; j= 0.5){ ihv = (int) (hv1000>=0 ? ceil(hv1000) : floor(hv1000)); } else { ihv = (int) (hv1000<0 ? ceil(hv1000) : floor(hv1000)); } if (ihv >= NHVValues) ihv = NHVValues; return DACArray[board][chain][channel][ihv]; } }