// calibrate RC offset parameters for CAEN TDCs #include #include extern "C"{ #include #include #include #include #include #include #include "math.h" #include "time.h" #include "sys/types.h" #include #include "sighandle.h" extern int Nc1190; extern int tiA32Base; DMA_MEM_ID vmeIN,vmeOUT; extern unsigned int *dma_dabufp; extern DMANODE *the_event; } unsigned int scanmask=0; unsigned int START; unsigned int timelaps = 0; using namespace std; void myReadoutCode(); void decodethedata(UINT32 data); #define TI_ADDR (21<<19) int DEBUG = 0; int BLOCKLEVEL = 1; int BUFFERLEVEL = 1; int TESTONLY = 1; int Nevents = 10000; int EventCounter = 0; int NTDCS = 6; int Channel17[4]; int Channel31[4]; int found17; int found31; int RCBits17[4]; int RCBits31[4]; int AllLoops[4]; double TheDiff = 9999.; int TheMinimum = 0xfffff; void initcounters(){ for (int n=0;n<4;n++){ Channel17[n] = 0; Channel31[n] = 0; RCBits17[n] = 0; RCBits31[n] = 0; } found17 = 0; found31 = 0; } int RCAdjust = 0; int ThisOne = 0; int main(int argc, char *argv[]) { int stat; AllLoops[0] = 0; AllLoops[1] = 0; AllLoops[2] = 0; AllLoops[3] = 0; for (int k=0;k0){ //cout<<"Event : "<length; EventCounter++; found17 = 0; found31 = 0; //cout<<"Event "<data[Indx]); //unsigned int data = outEvent->data[Indx]; decodethedata(data); //if(Indx>20) break; } //printf("%s: nwords = %d eventLen = %d\n",__FUNCTION__,nwords,eventLen); int needToStop = 0; if (EventCounter==8000){ EventCounter = 0; //double ratio17[4]; double ratio31[4]; for (int s=0;s<4;s++){ //ratio17[s] = (double)Channel17[s] /4000.; ratio31[s] = (double)Channel31[s] /8000.; } //cout<<"Ratios 17: "<5){ LoopCounter = 0; if (ThisOne){ needToStop = 10; } RCAdjust++; if (RCAdjust > 0xfff){ needToStop = 10; } else { for (int k=0; k<4; k++){ int val = tdc1190GetRCadjust(5, k); //cout<<"RC Value is at "<1){ Nevents = 0; tiDisableTriggerSource(0); } if (EventCounter >= Nevents){ Nevents = 0; tiDisableTriggerSource(0); cout<<"Found the minum at RCAdjust = 0x"<>27; //cout<>26; chan = (data & 0x03e00000)>>21; measurement = (data & 0x001fffff); tdcNum = geo - 3; if ((tdcNum==5) && (chan==16) && (!found17)){ int bit = measurement & 0x3; Channel17[bit]++; found17 = 1; } if ((tdcNum==5) && (chan==31) && (!found31)){ int bit = measurement & 0x3; Channel31[bit]++; found31 = 1; } if (DEBUG){ printf("%8X - TDC MEASUREMENT - %s tdc=%d chan=%2d time=0x%08x\n", data, isTrailing?"T":"L", tdcNum, chan, measurement); } break; case 1: /* TDC Header */ tdc = (data & 0x03000000)>>24; eventID = (data & 0x00fff000)>>12; bunchID = (data & 0x00000fff); if (DEBUG>1){ printf("%8X - TDC HEADER - tdc=%d eventID=%d bunchID=%d\n", data, tdc, eventID, bunchID); } break; case 3: /* TDC Trailer */ tdc = (data & 0x03000000)>>24; eventID = (data & 0x00fff000)>>12; wordCount = (data & 0x00000fff); if (DEBUG>2){ printf("%8X - TDC TRAILER - tdc=%d eventID=%d wordCount=%d\n", data, tdc, eventID, wordCount); } break; case 4: /* TDC Error */ tdc = (data & 0x03000000)>>24; errorFlags = (data & 0x00007fff); if (DEBUG>3){ printf("%8X - TDC ERROR - 0x%05x\n", data, errorFlags); } break; case 8: /* Global Header */ evCount = (data & 0x07ffffe0)>>5; geo = (data & 0x0000001f); if (DEBUG>4){ printf("%8X - GLOBAL HEADER - geo = %d evCount = %d\n", data, geo, evCount); } break; case 16: /* Global Trailer */ status = (data & 0x07000000)>>24; wordCount = (data & 0x001fffe0)>>5; geo = (data & 0x0000001f); trigLost = status & 0x1; outBufferOverflow = status & 0x2; tdcError = status & 0x4; if (DEBUG>5){ printf("%8X - GLOBAL TRAILER - geo = %d status = %d %s%s%s wordCount = %d\n", data, geo, status, trigLost?"T":"", outBufferOverflow?"O":"", tdcError?"E":"", wordCount); } break; case 17: /* Global Trigger Time Tag */ triggerTime = (data & 0x07ffffff); if (DEBUG>6){ printf("%8X - GLOBAL TRIGGER TIME TAG - time = %08x\n", data, triggerTime); } break; case 24: /* Filler */ if (DEBUG) printf("%8X - FILLER\n", data); break; default: if (DEBUG>7){ printf("%8X: UNKNOWN DATA TYPE %d (0x%x)\n", data, datatype, datatype); } } }