/* read adc125 data with random trigger check if a channel is over a given threshold and write those channels with all samples to data file adctest2.cc new feature use ccdb_online data base to retreive DAC values and determine sparsification values. */ #include #include #include "adctest2.h" extern "C"{ #include #include #include #include #include #include #include "math.h" #include "time.h" #include "sys/types.h" #include extern int nfa125; extern int fa125A32Base; extern int tiA32Base; DMA_MEM_ID vmeIN,vmeOUT; extern unsigned int *dma_dabufp; } //UINT32 F125DATA[40000]; #define FA125_ADDR (5<<19) #define TI_ADDR (21<<19) ofstream OUTF; ofstream OUTFPed; void myReadoutCode(); void mkpedestals(); unsigned int START; int HOSTROC = 0; int NADCSAMPLES = 100; int THRESHOLD = 300; int NADCS = 1; int TIMETEST = 0; int NEVENT = 0; int RAWDATA = 0; int DEBUG =0; int DEBUGGER = 0; int NOSPARS = 0; int NODAC = 0; int DOPEDS = 10000; unsigned int timelaps = 0; unsigned int Pedestal[20][72]; int ADCSamples[20][72][200]; int OT[20][72]; float Ped[20][72]; int EventCounter = 0; int Thresholds[20][72]; float PedSum[20][72]; float PedSum2[20][72]; float PedSumCntr[20][72]; int PedestalCounter = 0; int DAC_Values[20][72]; int ERRORCounter = 0; int ERRORLOG = 10000; int main(int argc, char *argv[]) { int Nevents = 1000; int iFlag; int stat; char ofnam[128]; char ofnamped[128]; char CrateName[128] = "One"; char ifnam[128]; char DataDir[128] = "/gluonraid1/Users/zihlmann/FDCDATA"; printf("\nJLAB f125ADC pedestal Tests\n"); printf("----------------------------\n"); int k=0; int SLOT=3; int TIMING = 30; if (argc<2) { cout<length; int SLOTNUM = 0; int EVENT = -1; int CHANNEL = -1; int WSize = 0; int idx = 0; int pedcnt = 0; float adc1, adc2; int DATAReady=0; int EventsInBlock=0; int TriggerTime_1=0; int TriggerTime_2=0; int TrueSize=0; if (DEBUGGER){ OUTF<<"EVENT "<(NADCS*3866+40))){ //if ((eventLen<7730) || (eventLen>7800)){ //if ((eventLen<950) || (eventLen>970)){ OUTF<<"EVENT "<data[Indx]); if (DEBUG) OUTF<>27) == 0x10) { // Block Header SLOTNUM = ((data& 0x7C00000)>>22); if (SLOTNUM<11){ SLOTNUM -=3; } else { SLOTNUM -= 5; } EventsInBlock = (data & 0x000FF); if (DEBUG) OUTF<<"Block Header"<>27) == 0x12) { // Event Header EVENT = data & 0x003FFFFF; if (DEBUG) OUTF<<"Event Header"<>27) == 0x13) { // Trigger Time TriggerTime_1 = (data & 0x00FFFFFF); data = (unsigned int)LSWAP(outEvent->data[Indx+1]); //OUTF<>27) == 0x14) { // Window Raw Data header CHANNEL = ((data & 0x7F00000)>>20) - 1; // flash is couning channels from 1 to 72 need 0 to 71 WSize = (data & 0xFFF); if (DEBUGGER){ if (DATAReady!=0){ OUTF<<"EVENT "<>27) == 0x1d){// End of event if (DEBUG) OUTF<<"End of EVENT"<>27) == 0x1f){ if (DEBUG) OUTF<<"Filler Word"<>27) == 0x11){ if (DEBUG) OUTF<<"Block Trailer"<>27) == 0x18){ if (DEBUG) OUTF<<"0x18 Unknown type"<>27) == 0x19){ if (DEBUG) OUTF<<"Streaming RAW DATA!! WHY???"<>27) == 0x16){ if (DEBUG) OUTF<<"Puls RAW DATA!! WHY???"<>27) == 0x15){ if (DEBUG) OUTF<<"Window SUM!! WHY???"<>27) == 0x1e){ if (DEBUG) OUTF<<"DATA NOT VALID!! WHY???"<>27) == 0x17){ if (DEBUG) OUTF<<"PULSE INTEGRAL!! WHY???"<>27) == 0x16){ if (DEBUG) OUTF<<"Puls RAW DATA!! WHY???"<>27) == 0x15){ if (DEBUG) OUTF<<"Window SUM!! WHY???"<>27) == 0x1a){ if (DEBUG) OUTF<<"UNKNOWN!! WHY???"<>27) == 0x1b){ if (DEBUG) OUTF<<"UNDEFINED TYPE!! WHY???"<>27) == 0x1c){ if (DEBUG) OUTF<<"SCALER HEADER!! WHY???"<0) { // Window Raw Data values if (DEBUG){ OUTF<<"The actual DATA!"<> 16; ADCSamples[SLOTNUM][CHANNEL][idx++] = (data & 0x1FFF); adc1 = (float) ((data & 0x1FFF0000) >> 16); adc2 = (float) (data & 0x1FFF); //cout<9){ Ped[SLOTNUM][CHANNEL] /= 10.; PedSum[SLOTNUM][CHANNEL] += Ped[SLOTNUM][CHANNEL]; PedSum2[SLOTNUM][CHANNEL] += (Ped[SLOTNUM][CHANNEL]*Ped[SLOTNUM][CHANNEL]); PedSumCntr[SLOTNUM][CHANNEL] += 1.; } } else { float v1 = adc1 - Ped[SLOTNUM][CHANNEL]; float v2 = adc2 - Ped[SLOTNUM][CHANNEL]; if ((v1>Thresholds[SLOTNUM][CHANNEL] || v2>Thresholds[SLOTNUM][CHANNEL])){ OT[SLOTNUM][CHANNEL] = 1; } } } else { if (DEBUG) OUTF<<"Other stuff"<10){ SLOT += 2; } for (int k=0;k<72;k++){ //float mu = PedSum[n][k]/(float)EventCounter; //float r = PedSum[n][k]/((float)EventCounter-1.); //float sig = sqrt( PedSum2[n][k]/((float)EventCounter-1) - mu*r ); float mu=0,r=0,sig=0; if (PedSumCntr[n][k]>1){ mu = PedSum[n][k] / PedSumCntr[n][k]; r = PedSum[n][k] / ( PedSumCntr[n][k] - 1. ); sig = sqrt( PedSum2[n][k]/( PedSumCntr[n][k] - 1. ) - mu*r ); } OUTFPed<