| 1,3 → 1,5 |
| #include "H1D.h" |
| #include "H2D.h" |
| #include <formatio.h> |
| #include <utility.h> |
| #include <ansi_c.h> |
| 14,6 → 16,7 |
| |
| static int daq_on; |
| static int ph, p2,plothandle[4]= {0,0,0,0}; |
| static int scanplothandle; |
| static int tfID; |
| static int controlID; |
| |
| 21,6 → 24,7 |
| |
| static CmtThreadPoolHandle poolHandle = 0; |
| |
| static float gSum[4]={0,0,0,0}; |
| int main (int argc, char *argv[]) { |
| short port; |
| if (InitCVIRTE (0, argv, 0) == 0) |
| 101,6 → 105,7 |
| } |
| |
| |
| static float xs[4][1024]; |
| int CVICALLBACK daq(void *functionData) { |
| |
| |
| 121,8 → 126,9 |
| int neveold = 0; |
| double rate; |
| int *args = (int *) functionData; |
| double twin[2]; |
| |
| GetCtrlVal(ph, PANEL_FILENAME, filename ); |
| |
| GetCtrlVal(ph, PANEL_CH0, &imask[0] ); |
| GetCtrlVal(ph, PANEL_CH1, &imask[1] ); |
| GetCtrlVal(ph, PANEL_CH2, &imask[2] ); |
| 146,7 → 152,8 |
| GetCtrlVal(ph,PANEL_TRGPOLARITY, &trgpolarity); |
| GetCtrlVal(ph,PANEL_RANGE, &range); |
| |
| |
| GetCtrlVal(ph,PANEL_TWIN0, &twin[0]); |
| GetCtrlVal(ph,PANEL_TWIN1, &twin[1]); |
| //printf("mask=0x%x\n",mask); |
| |
| DRSSetMask( (unsigned char)( mask & 0xF ) ); |
| 165,8 → 172,13 |
| FILE *fp= NULL; |
| |
| if (enabledoutput) { |
| if (args[0]) fp = fopen(filename,"wb"); |
| else fp = fopen(filename,"ab"); |
| if (args[0]) { |
| GetCtrlVal(ph, PANEL_FILENAME, filename ); |
| fp = fopen(filename,"wb"); |
| } else { |
| GetCtrlVal(p2, SCAN_FILENAME, filename ); |
| fp = fopen(filename,"ab"); |
| } |
| } |
| |
| static unsigned char *buffer; |
| 187,8 → 199,11 |
| if (!DRSInit()) { |
| time(&tstart); |
| told=tstart; |
| int i=0; |
| for (i=0; i<neve; i++) { |
| int nev=0; |
| for (int k = 0;k<4;k++){ |
| gSum[k]=0; |
| } |
| for (int i=0; i<neve; i++) { |
| start_timer(1);// 1 s timeout |
| int retval = DRSRead(0); |
| stop_timer(); |
| 195,6 → 210,7 |
| int nb = ( retval == 0 && fp ) ? DRSToBuffer( buffer , i ) : 0; |
| SetCtrlVal(ph,PANEL_CEVE,i); |
| if (retval) i--; |
| nev++; |
| if (!daq_on) break; |
| time(&t); |
| if (t!=told ) { |
| 207,25 → 223,33 |
| // Save data |
| if (nb>0 && fp) fwrite(buffer, 1,nb ,fp); |
| // Plot Data |
| if (i % pfreq == 0) for (int k=0; k<4; k++) { |
| if (! (mask & ( 0x1<<k )) ) continue; |
| float *t=DRSGetTime(k); |
| float *x=DRSGetWave(k); |
| for (int k=0; k<4; k++) { |
| if ( (mask & ( 0x1<<k )) ){ |
| float *t=DRSGetTime(k); |
| float *x=DRSGetWave(k); |
| ; |
| for (int j=0 ; j<1024 ; j++) { |
| xs[k][j]= x[j]*1e-3; |
| |
| if (t[j]> twin[0] && t[j] < twin[1]) gSum[k]+= fabs(xs[k][j]); |
| if (verbose) printf("[%d] %d. x= %3.2f y=%3.2f\n", k, i, t[j], x[j] ); |
| //h[k]->Fill( t[i], x[i]*1e-3); |
| } |
| |
| const int col[4]= {VAL_WHITE,VAL_RED,VAL_GREEN,VAL_BLUE}; |
| if (plothandle[k]) DeleteGraphPlot (ph, PANEL_GRAPH, plothandle[k], VAL_IMMEDIATE_DRAW); |
| plothandle[k] = PlotXY (ph, PANEL_GRAPH, t, x, 1024, VAL_FLOAT, VAL_FLOAT, VAL_THIN_LINE, VAL_NO_POINT, VAL_SOLID, 1, col[k]); |
| |
| for (int i=0 ; i<1024 ; i++) { |
| if (verbose) printf("[%d] %d. x= %3.2f y=%3.2f\n", k, i, t[i], x[i] ); |
| //h[k]->Fill( t[i], x[i]*1e-3); |
| if (i % pfreq == 0) { |
| |
| const int col[4]= {VAL_WHITE,VAL_RED,VAL_GREEN,VAL_BLUE}; |
| if (plothandle[k]) DeleteGraphPlot (ph, PANEL_GRAPH, plothandle[k], VAL_IMMEDIATE_DRAW); |
| plothandle[k] = PlotXY (ph, PANEL_GRAPH, t, xs[k], 1024, VAL_FLOAT, VAL_FLOAT, VAL_THIN_LINE, VAL_NO_POINT, VAL_SOLID, 1, col[k]); |
| } |
| } |
| |
| } |
| |
| |
| } |
| time(&t); |
| printf("%d events in %2.2f min (%d s) %s",i+1, (double)(t-tstart)/60.,t-tstart, ctime(&t)); |
| printf("%d events in %2.2f min (%d s) %s",nev, (double)(t-tstart)/60.,t-tstart, ctime(&t)); |
| DRSEnd(); |
| } |
| |
| 255,13 → 279,13 |
| int enabledoutput; |
| |
| FILE *fp; |
| GetCtrlVal(ph, PANEL_FILENAME, filename ); |
| GetCtrlVal(p2, SCAN_FILENAME, filename ); |
| |
| GetCtrlVal(ph,PANEL_ENABLEDOUTPUT, &enabledoutput); |
| |
| if ( GetFileInfo(filename,&size) ) { |
| MessagePopup ("Warning", "File exist. Remove it first or choose another file"); |
| return 0; |
| MessagePopup ("Warning","File exist. Remove it first or choose another file"); |
| return 0; |
| } |
| GetCtrlVal(p2, SCAN_STEPX, &dx[0]); |
| GetCtrlVal(p2, SCAN_STEPY, &dx[1]); |
| 269,8 → 293,15 |
| GetCtrlVal(p2, SCAN_NSTEPSY, &nx[1]); |
| GetCtrlVal(p2, SCAN_STARTX, &x0[0]); |
| GetCtrlVal(p2, SCAN_STARTY, &x0[1]); |
| |
| |
| for (int k=0;k<4;k++) { |
| H2D_Init(k, "charge","Induced charge", |
| nx[0], x0[0] - dx[0]*0.5 ,x0[0] + dx[0] * ( nx[0] - 0.5) , |
| nx[1], x0[1] - dx[1]*0.5 ,x0[1] + dx[1] * ( nx[1] - 0.5)); |
| H1D_Init(k, "charge","Induced charge projection x", |
| nx[0], x0[0] - dx[0]*0.5 ,x0[0] + dx[0] * ( nx[0] - 0.5) ); |
| H1D_Init(100 + k, "charge","Induced charge projection y", |
| nx[1], x0[1] - dx[1]*0.5 ,x0[1] + dx[1] * ( nx[1] - 0.5) ); |
| } |
| if (enabledoutput) { |
| fp = fopen(filename,"ab"); |
| if (fp) { |
| 320,6 → 351,13 |
| |
| #endif |
| daq(functionData); |
| |
| for (int k=0;k<4;k++) { |
| H2D_Fill(k, ix[0], ix[1] , gSum[k] ); |
| H1D_Fill(k, ix[0] , gSum[k] ); |
| H1D_Fill(100+ k, ix[1] , gSum[k] ); |
| } |
| PlotScanHistogramCB(0,0,EVENT_COMMIT,NULL, 0,0); |
| if (!daq_on) break; |
| } |
| if (!daq_on) break; |
| 490,3 → 528,42 |
| } |
| return 0; |
| } |
| |
| int CVICALLBACK PlotScanHistogramCB (int panel, int control, int event, |
| void *callbackData, int eventData1, int eventData2) { |
| int hid=0; |
| int nx; |
| int ny; |
| switch (event) { |
| case EVENT_COMMIT: |
| GetCtrlVal (p2, SCAN_CHANNEL, &hid); |
| GetCtrlVal(p2, SCAN_NSTEPSX, &nx); |
| GetCtrlVal(p2, SCAN_NSTEPSY, &ny); |
| if (nx>1 && ny>1) { |
| H2D_Draw(hid,p2,SCAN_GRAPH,&scanplothandle); |
| printf("redraw 2d\n"); |
| } else { |
| if (nx>1) { |
| printf("redraw 1d x\n"); |
| H1D_Draw(hid,p2,SCAN_GRAPH,&scanplothandle); |
| } |
| if (ny>1) { |
| printf("redraw 1d x\n"); |
| H1D_Draw(100+hid,p2,SCAN_GRAPH,&scanplothandle); |
| } |
| } |
| break; |
| } |
| return 0; |
| } |
| |
| int CVICALLBACK OpenGuiCB (int panel, int control, int event, |
| void *callbackData, int eventData1, int eventData2) { |
| switch (event) { |
| case EVENT_COMMIT: |
| DisplayPanel (ph); |
| DisplayPanel (p2); |
| break; |
| } |
| return 0; |
| } |