Subversion Repositories f9daq

Compare Revisions

Ignore whitespace Rev 89 → Rev 90

/sipmScan/src/sipmThreshold.c
44,7 → 44,7
# define MIKRO_Y 2
# define USE_MIKRO_Z
# define MIKRO_Z 3
# define STEP_TOLERANCE 50
# define STEP_TOLERANCE 1
#endif
 
#define MAXCH 512
/sipmScan/src/sipmBias.c
34,7 → 34,7
# define NDAC 1 // CAEN C221
# define ASD8 0 // channels
# define AMPDISSH 1
# define SIPM 2
# define SIPM 15
# define CAEN_V673A 0x22220000 // IJS
//#define CAEN_V673A 0x10110000 // FMF
# define CAEN_V462 0x100300
41,13 → 41,13
#endif
 
#ifdef USE_MIKRO
# define MIKRO_COM 5
# define MIKRO_COM 3
# define MIKRO_X 1
# define USE_MIKRO_Y
# define MIKRO_Y 2
# define USE_MIKRO_Z
# define MIKRO_Z 3
# define STEP_TOLERANCE 50
# define STEP_TOLERANCE 1
#endif
 
#define MAXCH 512
57,6 → 57,8
 
#define NCH 64
#define POWERSUPPLY 66 // Power supply voltage for SiPM bias
#define OFFSETX 5600 // position of the lower right corner
#define OFFSETY 5200
 
static int p1h, pID, rID, tfID;
static int ph_tdc, ph_adc;
283,6 → 285,7
 
//if (dsave) {
sprintf(dfile,"%s_file%02d.dat",dfile0,fcount);
SetCtrlVal(p1h, P1_FCOUNT, fcount);
fp = fopen (dfile, "wb");
time (&runrec.time);
301,6 → 304,7
SetCtrlVal(p1h, P1_SBIAS, biasrec.bias/1000.0);
status = fwrite(&biasrec, 1, biasrec.len, fp);
if (print) printf("BIASREC status %d len %d bias %d\n", status, biasrec.len, biasrec.bias);
wait_loop(10000);
// Set ASD threshold voltage
thrrec.threshold = (unsigned long) ceil(thresholdLow*1000); // threshold in mV
309,6 → 313,7
SetCtrlVal(p1h, P1_SASD8THR, thrrec.threshold/1000.0);
status = fwrite(&thrrec, 1, thrrec.len, fp);
if (print) printf("THRREC status %d len %d threshold %d\n", status, thrrec.len, thrrec.threshold);
wait_loop(10000);
for (posrec.ix=0; posrec.ix<runrec.nx; posrec.ix++) {
posrec.xset = runrec.x0 + posrec.ix*runrec.dx;
315,8 → 320,9
#ifdef USE_MIKRO
//printf("MIKRO_MoveTo (1, x);%d\n",posrec.x);
do {
MIKRO_MoveTo (MIKRO_X, posrec.xset);
MIKRO_MoveTo (MIKRO_X, OFFSETX + posrec.xset);
MIKRO_GetPosition(MIKRO_X, &mikroX);
mikroX -= OFFSETX;
} while (abs(posrec.xset - mikroX) > STEP_TOLERANCE);
//printf("->MIKRO_MoveTo (1, x);%d\n",posrec.xset);
#endif
329,8 → 335,9
#ifdef USE_MIKRO_Y
//printf("MIKRO_MoveTo (2, y);%d\n",y);
do {
MIKRO_MoveTo (MIKRO_Y, posrec.yset);
MIKRO_MoveTo (MIKRO_Y, OFFSETY + posrec.yset);
MIKRO_GetPosition(MIKRO_Y, &mikroY);
mikroY -= OFFSETY;
} while (abs(posrec.yset - mikroY) > STEP_TOLERANCE);
//printf("->MIKRO_MoveTo (2, y);%d\n",posrec.yset);
#endif
465,6 → 472,7
status = fwrite (&endrec, 1, endrec.len, fp);
fcount+=1;
sprintf(dfile,"%s_file%02d.dat",dfile0,fcount);
SetCtrlVal(p1h, P1_FCOUNT, fcount);
fclose(fp);
fp = fopen (dfile, "wb");
}
491,9 → 499,11
} // y loop
if (!daq_on) break;
thrrec.threshold += thresholdStep*1000;
wait_loop(10000);
} // threhsold loop
if (!daq_on) break;
biasrec.bias += runrec.biasStep;
wait_loop(10000);
} // bias loop
SetDac(SIPM, 0); // safety
539,7 → 549,8
{
int i,j,status,refon;
long int xpos, ypos, zpos;
char dfile[300];
char dfile[256];
char message[128];
FILE *fp;
typedef struct {
579,6 → 590,11
DisplayPanel (p1h);
SetCtrlAttribute (p1h, P1_PLCH, ATTR_MAX_VALUE, NCH-1);
sprintf(message, "%d", OFFSETX);
SetCtrlVal (p1h, P1_OFFSETX, message);
sprintf(message, "%d", OFFSETY);
SetCtrlVal (p1h, P1_OFFSETY, message);
GetCtrlVal(p1h, P1_ADCHLSAVE, &runrec.xy);
SetCtrlVal(p1h, P1_ADCHL, runrec.xy-2);
 
/sipmScan/src/analysisScan.cpp
17,7 → 17,7
#include "TStyle.h"
#include "TCanvas.h"
#include "TLine.h"
#include "zlib.h"
//#include "zlib.h"
 
// ------------------------------------------------------------------------------
 
30,8 → 30,8
#define NCH 64
#define TDC_BIN 1.0416 // 1 TDC bin in ns
#define MIKRO_BIN 0.49609/1000. //1 mikro step in mm; stage MM3MF
#define OFFSETX 5220 // Right edge of SiPM+Lightguide
#define OFFSETY 5860 // Lower edge of SiPM+Lightguide
#define OFFSETX 0 // Right edge of SiPM+Lightguide
#define OFFSETY 0 // Lower edge of SiPM+Lightguide
 
#define RUNREC_ID 1
#define ENDREC_ID 2
84,14 → 84,18
 
double padCenter[NCH][2];
 
// Test if the hit(x,y) lies inside the coordinates of the channel
// file with pad centers (without offset) should be provided
int position(int, int, int);
 
// ------------------------------------------------------------------------------
 
int analysisScan(char* dfile0="test", int dbg=0, double tdcCut=5.0)
int analysisScan(char* dfile0="test", double c_tdcOffset=97, double tdcCut=5.0, int dbg=0)
{
 
const double c_tdcOffset = +97*TDC_BIN; // ns, SiPM4
//const double c_tdcOffset = +98*TDC_BIN; // ns
c_tdcOffset *= TDC_BIN; //ns
printf(" Data to root conversion program\nUsage:\nd2r(input file name <without .dat>, debug on/off, TDC cut +-[ns])\n\n");
printf(" OFFSETS: \n x: %d\n y: %d\n t:%f\n", OFFSETX, OFFSETY, c_tdcOffset);
156,7 → 160,7
char hname[256];
//double tdc;
TH2F *htdc;
TH2F* h_correctedTDC;
TH2F* h_correctedTDC;
TH1F *hnhitsx[NCH], *hnhitsy[NCH];
TH2F *h2d[NCH];
166,12 → 170,9
unsigned int readbuf[READBUFFERLENGTH];
unsigned int buf[READBUFFERLENGTH];
//data file
gzFile dfp;
//gzFile dfp;
FILE *dfp;
char dfile[256];
int ftype=0;
int fcount=1;
190,7 → 191,8
printf(" Cannot find data file for %s !!!\n", dfile0);
return -1;
}
dfp=gzopen(dfile,"rb");
//dfp=gzopen(dfile,"rb");
dfp=fopen(dfile,"rb");
} while(!dfp);
printf("Opened data file %s\n", dfile);
219,9 → 221,11
int status;
while(1) {
if(gzeof(dfp)) end_of_file = 1;
 
gzread(dfp, (voidp)&readbuf, 2*ulsize);
//if(gzeof(dfp)) end_of_file = 1;
if(feof(dfp)) end_of_file = 1;
//gzread(dfp, (voidp)&readbuf, 2*ulsize);
fread((void*)&readbuf, 2*ulsize, 1, dfp);
rec_id=readbuf[0];
rec_len=readbuf[1];
232,7 → 236,8
switch(rec_id)
{
case RUNREC_ID:
gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize));
//gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize));
fread((void*)&readbuf[2], (rec_len-2*ulsize), 1, dfp);
runrec = (RUNREC*) readbuf;
run = *runrec;
298,7 → 303,8
break;
case POSREC_ID:
gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize));
//gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize));
fread((void*)&readbuf[2], (rec_len-2*ulsize), 1, dfp);
posrec = (POSREC *) readbuf;
pos=*posrec;
312,7 → 318,8
break;
case EVTREC_ID:
gzread(dfp, (voidp)&readbuf[2], ulsize); // last field of event record
//gzread(dfp, (voidp)&readbuf[2], ulsize); // last field of event record
fread((void*)&readbuf[2], ulsize, 1, dfp);
evtrec = (EVTREC *) readbuf;
//evtrec->nev = buf[0];
//if (rec_len < 0 || rec_len > 10000) {
321,7 → 328,8
return(0);
}
nb = rec_len - 3*ulsize; // no. of bytes to read
gzread(dfp, (voidp)&buf, nb);
//gzread(dfp, (voidp)&buf, nb);
fread((void*)&buf, nb, 1, dfp);
if(dbg) {
printf("EVTREC_ID\n");
342,10 → 350,10
if (dbg) printf("Buffer pointer %d\n", ii);
unsigned int *dbuf = (unsigned int *)&buf[ii];
//if (n%1000==0)
if (dbg) printf("%d 0x%03x Len=%d\n",evtrec->nev,recid,len);
if (dbg) printf("%d 0x%03x Len=%d\n",evtrec->nev,recid,len);
//unsigned short edge;
//int nhits;
if (recid==0x140 || recid==0x141) {
if (recid==0x140 || recid==0x141) {
for (int i=0; i<len; i++) {
int data = dbuf[i] & 0xFFFF ;
int edge_type = (dbuf[i]>>16)&0x1 ;
423,7 → 431,8
break;
case THRREC_ID:
status = gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize));
//status = gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize));
status = fread((void*)&readbuf[2], (rec_len-2*ulsize), 1, dfp);
thrrec = (THRREC*) readbuf;
thr = *thrrec;
if (dbg) printf("THRREC id = %d len = %d threshold %d\n",
431,7 → 440,8
break;
case ENDREC_ID:
gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize));
//gzread(dfp, (voidp)&readbuf[2], (rec_len-2*ulsize));
fread((void*)&readbuf[2], (rec_len-2*ulsize), 1, dfp);
endrec = (ENDREC *) readbuf;
if(dbg) {
452,9 → 462,11
break;
}
if(dfp) gzclose(dfp);
//if(dfp) gzclose(dfp);
if(dfp) fclose(dfp);
dfp=gzopen(dfile,"rb");
//dfp=gzopen(dfile,"rb");
dfp=fopen(dfile,"rb");
if(!dfp) {
printf(" Cannot open data file: %s ---> Exiting\n", dfile);
end_of_file = 1;
478,8 → 490,9
}
 
if(dfp) {
gzclose(dfp);
delete dfp;
//gzclose(dfp);
fclose(dfp);
//delete dfp;
}
if(dbg) return 1;
if(rootfile) {
487,7 → 500,7
rootfile->Write();
printf("Saved to %s\n", fnameroot);
rootfile->Close();
delete rootfile;
//delete rootfile;
}
return 1;
/sipmScan/src/sipmScan.c
24,6 → 24,8
#include <ansi_c.h>
#include <utility.h>
#include <analysis.h>
#include <time.h>
//#include <zlib.h>
 
#include "c:\HOME\dino\sipmScan\include\sipmScan_ui.h"
 
33,7 → 35,7
# define NDAC 1
# define ASD8 0 // channels
# define AMPDISSH 1
# define SIPM 2
# define SIPM 15
//# define CAEN_V673A 0x10110000 // FMF
# define CAEN_V673A 0x22220000 // IJS
# define CAEN_V462 0x100300
40,7 → 42,7
#endif
 
#ifdef USE_MIKRO
# define MIKRO_COM 5
# define MIKRO_COM 3
# define MIKRO_X 1
# define USE_MIKRO_Y
# define MIKRO_Y 2
49,7 → 51,7
# define STEP_TOLERANCE 1
#endif
 
#define MAXCH 512
#define MAXCH 128
#define MAX_THREADS 10
 
#define IWAIT 200
66,6 → 68,9
static int poolHandle = 0;
static int ntics,dummy;
 
static int offsetX = 5600;
static int offsetY = 5400;
 
/************************************************************/
void wait_loop(unsigned long iloop)
 
208,8 → 213,10
GetSystemTime(&start_hours, &start_minutes, &start_seconds);
//cur_time_s = start_hours*3600 + start_minutes*60 + start_seconds;
time(&cur_time_s);
end_time_s = cur_time_s + step_minutes*60;
printf("START:%2d-%2d-%2d (cur_time = %u s, end_time = %u s)\n", start_hours, start_minutes, start_seconds, cur_time_s, end_time_s);
end_time_s = cur_time_s + (int) (runrec.nx * runrec.ny * runrec.nev/10000.0 * 4.5); // expected seconds
printf("START:%2d-%2d-%2d (cur_time = %u s, end_time = %u s)\n", start_hours, start_minutes, start_seconds, cur_time_s, end_time_s);
SetCtrlAttribute(p1h, P1_EXPTIME, ATTR_DIMMED, 0);
SetCtrlVal(p1h, P1_EXPTIME, ctime(&end_time_s));
 
//GetCtrlVal (p1h, P1_DSAVE, &dsave);
//if (dsave) {
236,6 → 243,7
 
//if (dsave) {
sprintf(dfile,"%s_file%02d.dat",dfile0,fcount);
SetCtrlVal(p1h, P1_FCOUNT,fcount);
fp = fopen (dfile, "wb");
time (&runrec.time);
245,36 → 253,42
fseed = runrec.time & 0x7fffffff;
Uniform (1, fseed, &fracg);
}
// vertical moving stage loop
for (posrec.iy=0; posrec.iy<runrec.ny; posrec.iy++) {
posrec.yset = runrec.y0 + posrec.iy*runrec.dy;
#ifdef USE_MIKRO_Y
if (print) printf("MIKRO_MoveTo (2, y);%d\n",posrec.yset);
do {
MIKRO_MoveTo (MIKRO_Y, offsetY + posrec.yset);
MIKRO_GetPosition(MIKRO_Y, &mikroY);
mikroY -= offsetY;
if (print) printf("%d\n", abs(posrec.yset - mikroY));
} while (abs(posrec.yset - mikroY) > STEP_TOLERANCE);
if (print) printf("->MIKRO_MoveTo (2, y);%d\n",posrec.yset);
#endif
posrec.yset = mikroY;
SetCtrlVal (p1h, P1_Y, posrec.yset);
SetCtrlVal (p1h, P1_IY, posrec.iy);
 
for (posrec.ix=0; posrec.ix<runrec.nx; posrec.ix++) {
posrec.xset = runrec.x0 + posrec.ix*runrec.dx;
// horizontal moving stage loop
for (posrec.ix=0; posrec.ix<runrec.nx; posrec.ix++) {
posrec.xset = runrec.x0 + posrec.ix*runrec.dx;
#ifdef USE_MIKRO
do {
if (print) printf("MIKRO_MoveTo (1, x);%d\n",posrec.xset);
MIKRO_MoveTo (MIKRO_X, posrec.xset);
MIKRO_MoveTo (MIKRO_X, offsetX + posrec.xset);
MIKRO_GetPosition(MIKRO_X, &mikroX);
mikroX -= offsetX;
if (print) printf("%d\n", abs(posrec.xset - mikroX));
} while (abs(posrec.xset - mikroX) > STEP_TOLERANCE);
#endif
posrec.xset = mikroX; // true value
posrec.xset = mikroX; // true value
SetCtrlVal (p1h, P1_X, posrec.xset);
SetCtrlVal (p1h, P1_IX, posrec.ix);
for (posrec.iy=0; posrec.iy<runrec.ny; posrec.iy++) {
posrec.yset = runrec.y0 + posrec.iy*runrec.dy;
#ifdef USE_MIKRO_Y
if (print) printf("MIKRO_MoveTo (2, y);%d\n",posrec.yset);
do {
MIKRO_MoveTo (MIKRO_Y, posrec.yset);
MIKRO_GetPosition(MIKRO_Y, &mikroY);
if (print) printf("%d\n", abs(posrec.yset - mikroY));
} while (abs(posrec.yset - mikroY) > STEP_TOLERANCE);
if (print) printf("->MIKRO_MoveTo (2, y);%d\n",posrec.yset);
#endif
posrec.yset = mikroY;
SetCtrlVal (p1h, P1_Y, posrec.yset);
SetCtrlVal (p1h, P1_IY, posrec.iy);
//if (dsave) {
if (fmax && (ftell(fp) > fmax)) {
 
 
//if (dsave) {
if (fmax && (ftell(fp) > fmax)) {
fcount+=1;
sprintf(dfile,"%s_file%02d.dat",dfile0,fcount);
fclose(fp);
370,7 → 384,7
} else {
if (ntrig==0) {
fprintf(stderr,"-----------------> no trigger");
break;
//break;
} else {
if (print) fprintf(stderr,"-----------------> wrong number of triggers in chips V673a !!!\n");
}
398,6 → 412,7
status = fwrite (&endrec, 1, endrec.len, fp);
fcount+=1;
sprintf(dfile,"%s_file%02d.dat",dfile0,fcount);
SetCtrlVal(p1h, P1_FCOUNT,fcount);
fclose(fp);
fp = fopen (dfile, "wb");
}
419,9 → 434,9
} while (evtrec.nev++<runrec.nev && daq_on);
if (!daq_on) break;
} // x loop
} // y loop
if (!daq_on) break;
} // y loop
} // x loop
//if (dsave) {
time (&endrec.time);
464,7 → 479,8
{
int i,j,status,refon;
long int xpos, ypos, zpos;
char dfile[300];
char dfile[512];
char message[256];
FILE *fp;
typedef struct {
504,6 → 520,9
DisplayPanel (p1h);
SetCtrlAttribute (p1h, P1_PLCH, ATTR_MAX_VALUE, NCH-1);
SetCtrlVal (p1h, P1_OFFSETX, offsetX);
SetCtrlVal (p1h, P1_OFFSETY, offsetY);
GetCtrlVal(p1h, P1_ADCHLSAVE, &runrec.xy);
SetCtrlVal(p1h, P1_ADCHL, runrec.xy-2);
 
511,6 → 530,8
QueueUserEvent (1000, p1h, P1_ASD8THR);
QueueUserEvent (1000, p1h, P1_AMPDISSHTHR);
QueueUserEvent (1000, p1h, P1_BIAS);
QueueUserEvent (1000, p1h, P1_OFFSETX);
QueueUserEvent (1000, p1h, P1_OFFSETY);
printf("BIAS offset set to: %d\n", POWERSUPPLY);
530,12 → 551,27
if (daq_on) {
CmtScheduleThreadPoolFunction (poolHandle, daq_run, (void *)&dummy, &tfID);
} else {
CmtWaitForThreadPoolFunctionCompletion (poolHandle, tfID,
OPT_TP_PROCESS_EVENTS_WHILE_WAITING);
CmtWaitForThreadPoolFunctionCompletion (poolHandle, tfID, OPT_TP_PROCESS_EVENTS_WHILE_WAITING);
CmtReleaseThreadPoolFunctionID (poolHandle, tfID);
}
break;
case P1_XMIN:
if (!daq_on) {
GetCtrlVal (p1h, P1_XMIN, &xpos);
//backlash
MIKRO_MoveTo(MIKRO_X, xpos+offsetX-1000);
Delay(0.01);
MIKRO_MoveTo(MIKRO_X, xpos+offsetX);
}
break;
case P1_YMIN:
if (!daq_on) {
GetCtrlVal(p1h, P1_YMIN, &ypos);
MIKRO_MoveTo(MIKRO_Y, ypos+offsetY-1000);
Delay(0.01);
MIKRO_MoveTo(MIKRO_Y, ypos+offsetY);
}
break;
case P1_ZSET:
if (!daq_on) {
GetCtrlVal (p1h, P1_ZSET, &zpos);
569,11 → 605,11
#ifdef USE_MIKRO
MIKRO_GetPosition(MIKRO_X,&xpos);
Delay(0.01);
SetCtrlVal (p1h, P1_X, xpos);
SetCtrlVal (p1h, P1_X, xpos-offsetX);
#ifdef USE_MIKRO_Y
MIKRO_GetPosition(MIKRO_Y,&ypos);
Delay(0.01);
SetCtrlVal (p1h, P1_Y, ypos);
SetCtrlVal (p1h, P1_Y, ypos-offsetY);
#endif
#ifdef USE_MIKRO_Z
MIKRO_GetPosition(MIKRO_Z,&zpos);
641,6 → 677,20
SetDac(SIPM, value);
}
break;
// reset SiPM bias to initial power supply voltage
case P1_BIASOFF:
{
SetDac(SIPM, 0);
SetCtrlVal(p1h, P1_SBIAS, (double) POWERSUPPLY);
}
case P1_OFFSETX:
{
GetCtrlVal(p1h, P1_OFFSETX, &offsetX);
}
case P1_OFFSETY:
{
GetCtrlVal(p1h, P1_OFFSETY, &offsetY);
}
}