Blame |
Last modification |
View Log
| RSS feed
/*CMZ : 23/02/2008 09.20.45 by Samo Korpar*/
/*CMZ : 0.02/00 04/07/2001 00.52.00 by Samo Korpar*/
/*CMZ : 0.01/00 29/11/99 13.07.26 by Samo Korpar*/
/*CMZ : 0.00/00 08/10/99 13.05.24 by Samo Korpar*/
/*-- Author :*/
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <time.h>
#include <tcl.h>
#include <tk.h>
extern int hvslow
(char *sn
);
extern int hvslowChannel
(char *sn
);
/*KEEP,evdp,T=C++.*/
#include "evdp.h"
/*KEEP,evd,T=C++.*/
#include "evd.h"
/*KEND.*/
#include <blt.h>
#define CMDLEN 300
/* parameters for the detector display */
#define FPXOFF 4
#define FPYOFF 17
#define SMXOFF 49
#define SMYOFF 138
#define BBXS 8
#define BBYS 8
#define SMXS 48
#define SMYS 128
static int curev
;
static char hotchannels
[MAXFED
][128];
static int m4x
[16],m4y
[16],m4c
[4][4];
static int m16x
[4][16],m16y
[4][16],m16a
[8][8],m16c
[8][8];
static int m4pm
[16],m4pc
[16],m16pm
[4][16],m16pc
[4][16];
static FPL_data fplch
[14][6][16];
static FED_data fedch
[MAXFED
][64];
static FED_record fedr
[MAXFED
];
static FED_hist hits
;
#ifdef __cplusplus
extern "C" {
#endif
void mask_hot
(int fed
, char *data
)
{
int i
;
for (i
=0;i
<128;i
++)
*(data
++)&=hotchannels
[fed
][i
];
return;
}
int find_hot
()
{
int i
, j
, k
, ii
, jj
, nr
, pos
, nh
, nhot
;
int sm
, pr
=0, pc
=0, ch
=0;
unsigned int nev
;
unsigned char b
, *hch
;
FILE
*fhot
;
hch
=(unsigned char *) hotchannels
;
for (i
=0;i
<128*MAXFED
;i
++) *(hch
++)=0xFF;
for (k
=0;k
<MAXFED
;k
++)
for (i
=0;i
<64;i
++)
for (j
=0;j
<16;j
++)
hits.
data[k
][i
][j
]=0;
if (reopen_data_file
()) exit(1);
nev
=0;
while ((nr
=get_nextev
(fedr
, 0x500, 0)) && (nev
<1000))
{
nh
=0;
for (k
=0;k
<nr
;k
++)
for (ii
=0;ii
<128;ii
++)
{
i
=ii
/2;
if (fedr
[k
].
data[ii
] && fedch
[fedr
[k
].
fedid][i
].
pmt)
for (jj
=0,j
=8*(ii
%2),b
=1;jj
<8;jj
++,j
++,b
<<=1)
if (fedr
[k
].
data[ii
]&b
) nh
++;
}
if (nh
> 1000) continue;
for (k
=0;k
<nr
;k
++)
for (ii
=0;ii
<128;ii
++)
{
i
=ii
/2;
if (fedr
[k
].
data[ii
] && fedch
[fedr
[k
].
fedid][i
].
pmt)
for (jj
=0,j
=8*(ii
%2),b
=1;jj
<8;jj
++,j
++,b
<<=1)
if (fedr
[k
].
data[ii
]&b
) hits.
data[fedr
[k
].
fedid][i
][j
]++;
}
nev
++;
}
if ((nev
/=10) < 5) return 1;
fhot
=fopen("hotchannels","w");
nhot
=0;
for (k
=0;k
<MAXFED
;k
++)
for (ii
=0;ii
<128;ii
++)
{
i
=ii
/2;
for (jj
=0,j
=8*(ii
%2),b
=1;jj
<8;jj
++,j
++,b
<<=1)
if (hits.
data[k
][i
][j
] > nev
)
{
nhot
++;
sm
=fedch
[k
][i
].
sm;
switch (fedch
[k
][i
].
pmt)
{
case 4:
pr
=2*fedch
[k
][i
].
bbr+m4pm
[j
]/2;
pc
=2*fedch
[k
][i
].
bbc+m4pm
[j
]%2;
ch
=m4pc
[j
];
break;
case 16:
pr
=2*fedch
[k
][i
].
bbr+m16pm
[fedch
[k
][i
].
asd][j
]/2;
pc
=2*fedch
[k
][i
].
bbc+m16pm
[fedch
[k
][i
].
asd][j
]%2;
ch
=m16pc
[fedch
[k
][i
].
asd][j
];
break;
}
if (sm
>6)
{
sm
=20-sm
;
pr
=31-pr
;
pc
=11-pc
;
}
fprintf(fhot
, "%d%.2d%.2d%.2d 1\n", sm
, pr
, pc
, ch
);
hotchannels
[k
][ii
]&=(~b
);
}
}
fclose(fhot
);
fhot
=fopen("hotchannels.raw","w");
fwrite ((void *) hotchannels
, 1, MAXFED
*128, fhot
);
fclose(fhot
);
printf("%d hot channels found\n", nhot
);
if (reclose_data_file
()) exit(1);
return 0;
}
int Evd_evinit
( ClientData clientData
, Tcl_Interp
*interp
,
int argc
, CONST
char *argv
[])
{
int pmt
, asd
, sm
, bbr
, bbc
, mb
, db
, con
, x0
, y0
, fx0
, fy0
, pmc
;
int status
, i
, j
, k
, ii
, jj
, ccon
, fpon
, casd
, px
, py
;
float sc
;
char cmd
[CMDLEN
], s1
[10];
FILE
*fid
;
sscanf(argv
[3]," %f ", &sc
);
sscanf(Tcl_GetVar
(interp
, "evmap", TCL_GLOBAL_ONLY
), " %d ", &fpon
);
sprintf(cmd
, "%s/m4wiremap.dat",
Tcl_GetVar
(interp
, "config_dir", TCL_GLOBAL_ONLY
));
if ((fid
=fopen(cmd
, "r")) == NULL
) {
fprintf(stderr
,"%s %d: File not found %s\n",__FILE__
, __LINE__
, cmd
);
return TCL_ERROR
;
}
while ( fgets( cmd
, 100, fid
) != NULL
)
if ((status
=sscanf( cmd
," %d %d %d ",&pmt
,&pmc
,&con
))==3)
{
/* printf("con=%d pmt=%d pmc=%d\n",con,pmt,pmc); */
m4pm
[con
]=pmt
;
m4pc
[con
]=pmc
;
if (fpon
)
{
px
=2*(pmt
%2)+1-(pmc
%2);
py
=3-(2*(pmt
/2)+1-(pmc
/2));
}
else
{
px
=2*(pmt
%2)+(pmc
%2);
py
=3-(2*(pmt
/2)+(pmc
/2));
}
m4c
[px
][py
]=con
;
/* printf("px=%d py=%d con=%d \n", px, py, con); fflush(stdout); */
m4x
[con
]=2*px
;
m4y
[con
]=2*py
;
}
fclose(fid
);
sprintf(cmd
, "%s/m16wiremap.dat",
Tcl_GetVar
(interp
, "config_dir", TCL_GLOBAL_ONLY
));
if ((fid
=fopen(cmd
, "r")) == NULL
) return TCL_ERROR
;
while ( fgets( cmd
, 100, fid
) != NULL
)
if ((status
=sscanf(cmd
," %d %d ASD%d %d ",&pmt
,&pmc
,&asd
,&con
))==4)
{
/* printf("asd=%d con=%d pmt=%d bbc=%d\n",asd,con,pmt,pmc); */
m16pm
[asd
][con
]=pmt
;
m16pc
[asd
][con
]=pmc
;
if (fpon
)
{
px
=4*(pmt
%2)+3-(pmc
%4);
py
=7-(4*(pmt
/2)+3-(pmc
/4));
}
else
{
px
=4*(pmt
%2)+(pmc
%4);
py
=7-(4*(pmt
/2)+(pmc
/4));
}
m16a
[px
][py
]=asd
;
m16c
[px
][py
]=con
;
m16x
[asd
][con
]=px
;
m16y
[asd
][con
]=py
;
}
fclose(fid
);
for (i
=0;i
<MAXFED
;i
++)
for (j
=0;j
<64;j
++)
{
fedch
[i
][j
].
pmt=0;
fedch
[i
][j
].
fx0=3+140*(i
%2)+(j
/16)*34;
fedch
[i
][j
].
fy0=5+(i
/2)*52+(j
%16)*3;
}
for (i
=0;i
<14;i
++)
for (j
=0;j
<6;j
++)
for (k
=0;k
<16;k
++)
{
fplch
[i
][j
][k
].
pmt=0;
fplch
[i
][j
][k
].
mb[0]=-1;
fplch
[i
][j
][k
].
mb[1]=-1;
fplch
[i
][j
][k
].
mb[2]=-1;
fplch
[i
][j
][k
].
mb[3]=-1;
fplch
[i
][j
][k
].
sn[0][0][0]=0;
fplch
[i
][j
][k
].
sn[0][1][0]=0;
fplch
[i
][j
][k
].
sn[1][0][0]=0;
fplch
[i
][j
][k
].
sn[1][1][0]=0;
}
for (i
=0;i
<14;i
++)
{
x0
=FPXOFF
+SMXOFF
*(i
%7);
y0
=FPYOFF
+SMYOFF
*(i
/7);
sprintf (cmd
, "%s create rectangle %f %f %f %f "
"-fill #AABBCC -outline \"\" -tags \"sm\"",
argv
[1], sc
*x0
, sc
*y0
, sc
*(x0
+SMXS
), sc
*(y0
+SMYS
));
Tcl_Eval
(interp
, cmd
);
}
sprintf(cmd
, "%s/ASD.dat",
Tcl_GetVar
(interp
, "config_dir", TCL_GLOBAL_ONLY
));
if ((fid
=fopen(cmd
, "r")) == NULL
) return TCL_ERROR
;
while ( fgets( cmd
, 100, fid
) != NULL
)
if ((status
=sscanf( cmd
," M%d ASD%d %d %d %d %d %d %d ",
&pmt
,&asd
,&sm
,&bbr
,&bbc
,&mb
,&db
,&con
))==8)
{
if (sm
>6)
{
sm
=20-sm
;
bbr
=15-bbr
;
bbc
=5-bbc
;
}
ccon
=db
*16+con
;
x0
=FPXOFF
+SMXOFF
*(sm
%7)+BBXS
*bbc
;
y0
=FPYOFF
+SMYS
+SMYOFF
*(sm
/7)-BBYS
*(bbr
+1);
fx0
=fedch
[mb
][ccon
].
fx0;
fy0
=fedch
[mb
][ccon
].
fy0;
if (fedch
[mb
][ccon
].
pmt)
{
printf("evinit: channel already mapped\n");
printf(">>\n");
}
else if (fplch
[sm
][bbc
][bbr
].
mb[asd
] != -1)
{
printf("evinit: area already mapped\n");
printf(">>\n");
}
else
{
fedch
[mb
][ccon
].
pmt=pmt
;
fedch
[mb
][ccon
].
asd=asd
;
fedch
[mb
][ccon
].
sm=sm
;
fedch
[mb
][ccon
].
bbr=bbr
;
fedch
[mb
][ccon
].
bbc=bbc
;
fedch
[mb
][ccon
].
x0=x0
;
fedch
[mb
][ccon
].
y0=y0
;
fplch
[sm
][bbc
][bbr
].
pmt=pmt
;
fplch
[sm
][bbc
][bbr
].
mb[asd
]=mb
;
fplch
[sm
][bbc
][bbr
].
wi[asd
]=ccon
;
if (!asd
)
{
fplch
[sm
][bbc
][bbr
].
x0=x0
;
fplch
[sm
][bbc
][bbr
].
y0=y0
;
}
/*
fplch[sm][bbc][bbr].x0=fx0;
fplch[sm][bbc][bbr].y0=fy0;
*/
/* printf("mb=%d con=%d pmt=%d\n",mb,con,pmt); */
}
switch (pmt
)
{
case 4:
sprintf (cmd
, "%s create rectangle %f %f %f %f "
"-fill $m4color -outline \"\" -tags \"m4\"",
argv
[1], sc
*x0
, sc
*y0
, sc
*(x0
+BBXS
), sc
*(y0
+BBYS
));
Tcl_Eval
(interp
, cmd
);
sscanf((char *) Tcl_GetStringResult
(interp
)," %d ", &fedch
[mb
][ccon
].
id);
sprintf (cmd
, "%s create rectangle %d %d %d %d "
"-fill $m4color -outline \"\" -tags \"m4\"",
argv
[2], fx0
, fy0
, fx0
+32, fy0
+2);
Tcl_Eval
(interp
, cmd
);
sscanf((char *) Tcl_GetStringResult
(interp
)," %d ", &fplch
[sm
][bbc
][bbr
].
id[asd
]);
break;
case 16:
if (fpon
) casd
=asd
^1; else casd
=asd
;
sprintf (cmd
, "%s create rectangle %f %f %f %f "
"-fill $m16color -outline \"\" -tags \"m16\"",
argv
[1], sc
*(x0
+casd
*BBXS
/4), sc
*y0
,
sc
*(x0
+(casd
+1)*BBXS
/4), sc
*(y0
+BBYS
));
Tcl_Eval
(interp
, cmd
);
sscanf( (char *) Tcl_GetStringResult
(interp
)," %d ", &fedch
[mb
][ccon
].
id);
sprintf (cmd
, "%s create rectangle %d %d %d %d "
"-fill $m16color -outline \"\" -tags \"m16\"",
argv
[2], fx0
, fy0
, fx0
+32, fy0
+2);
Tcl_Eval
(interp
, cmd
);
sscanf((char *) Tcl_GetStringResult
(interp
)," %d ", &fplch
[sm
][bbc
][bbr
].
id[asd
]);
}
}
fclose(fid
);
sprintf(cmd
, "%s/pm.dat",
Tcl_GetVar
(interp
, "config_dir", TCL_GLOBAL_ONLY
));
if ((fid
=fopen(cmd
, "r")) == NULL
) return TCL_ERROR
;
while ( fgets( cmd
, 100, fid
) != NULL
)
if (cmd
[1]=='#')
{
fgets( cmd
, 100, fid
);
if ((fgets( cmd
, 100, fid
))&&
((status
=sscanf(cmd
,"\t type R5600-00-M%d", &pmt
))==1))
if ((fgets( cmd
, 100, fid
))&&
((status
=sscanf(cmd
,"\t serial_no\t%s", s1
))==1))
if ((fgets( cmd
, 100, fid
))&&
((status
=sscanf(cmd
,"\t position\t%d\t%d\t%d", &sm
, &bbr
, &bbc
))==3))
{
if (sm
>6)
{
sm
=20-sm
;
bbr
=31-bbr
;
bbc
=11-bbc
;
}
strcpy(fplch
[sm
][bbc
/2][bbr
/2].
sn[bbc
%2][bbr
%2], s1
);
}
}
fclose(fid
);
for (i
=0;i
<14;i
++)
for (j
=0;j
<6;j
++)
for (k
=0;k
<16;k
++)
/* if (fplch[i][j][k].pmt) */
for (ii
=0;ii
<2;ii
++)
for (jj
=0;jj
<2;jj
++)
if (fplch
[i
][j
][k
].
sn[ii
][jj
][0]=='e')
{
sprintf (cmd
, "%s create rectangle %f %f %f %f "
"-fill #FFFF77 -outline \"\" -tags \"empty\"",
argv
[1],
sc
*(fplch
[i
][j
][k
].
x0+ii
*BBXS
/2),
sc
*(fplch
[i
][j
][k
].
y0+(1-jj
)*BBYS
/2),
sc
*(fplch
[i
][j
][k
].
x0+(ii
+1)*BBXS
/2),
sc
*(fplch
[i
][j
][k
].
y0+(2-jj
)*BBYS
/2));
Tcl_Eval
(interp
, cmd
);
}
return TCL_OK
;
}
int Evd_evopen
( ClientData clientData
, Tcl_Interp
*interp
,
int argc
, CONST
char *argv
[])
{
int evhot
;
char fname
[200];
FILE
*fhot
;
strcpy(fname
,argv
[1]);
if (open_data_file
(fname
)) return TCL_ERROR
;
curev
=1;
sscanf(Tcl_GetVar
(interp
, "evhot", TCL_GLOBAL_ONLY
), " %d ", &evhot
);
if (evhot
)
{
(void) find_hot
();
}
else
{
if ((fhot
=fopen("hotchannels.raw","r")))
{
(void) fread ((void *) hotchannels
, 1, MAXFED
*128, fhot
);
fclose(fhot
);
}
else (void) find_hot
();
}
return TCL_OK
;
}
int Evd_evgoto
( ClientData clientData
, Tcl_Interp
*interp
,
int argc
, CONST
char *argv
[])
{
int pos
;
sscanf(argv
[1]," %d ", &curev
);
pos
=goto_event
(curev
);
if (pos
!= curev
)
{
goto_event
(pos
);
curev
=pos
;
}
return TCL_OK
;
}
int Evd_evclose
( ClientData clientData
, Tcl_Interp
*interp
,
int argc
, CONST
char *argv
[])
{
if (close_data_file
()) return TCL_ERROR
;
return TCL_OK
;
}
int Evd_evplot
( ClientData clientData
, Tcl_Interp
*interp
,
int argc
, CONST
char *argv
[])
{
int i
, j
, k
, ii
, jj
, nr
, nhits
, map
, bx
, evmask
;
float sc
;
unsigned char b
;
char cmd
[CMDLEN
];
sscanf(argv
[2]," %f ", &sc
);
sscanf(Tcl_GetVar
(interp
, "evmap", TCL_GLOBAL_ONLY
), " %d ", &map
);
sscanf(Tcl_GetVar
(interp
, "evmask", TCL_GLOBAL_ONLY
), " %d ", &evmask
);
nhits
=0;
if ((nr
=get_nextev
(fedr
, 0x500, 1)))
{
bx
=fedr
[0].
bxn;
for (k
=0;k
<nr
;k
++) if (fedr
[k
].
fedid<MAXFED
)
{
if (evmask
) mask_hot
(fedr
[k
].
fedid,(char *)fedr
[k
].
data);
if (bx
!=fedr
[k
].
bxn)
printf("bx=%d, bxn=%d\n", bx
, fedr
[k
].
bxn);
for (ii
=0;ii
<128;ii
++)
{
i
=ii
/2;
if (fedr
[k
].
data[ii
])
for (jj
=0,j
=8*(ii
%2),b
=1;jj
<8;jj
++,j
++,b
<<=1)
if (fedr
[k
].
data[ii
]&b
)
switch (fedch
[fedr
[k
].
fedid][i
].
pmt)
{
case 4:
nhits
++;
sprintf (cmd
, "%s create rectangle %f %f %f %f "
"-fill $evcolor -outline \"\" -tags \"ev\"",
argv
[1],
sc
*(fedch
[fedr
[k
].
fedid][i
].
x0+m4x
[j
]),
sc
*(fedch
[fedr
[k
].
fedid][i
].
y0+m4y
[j
]),
sc
*(fedch
[fedr
[k
].
fedid][i
].
x0+m4x
[j
]+BBXS
/4),
sc
*(fedch
[fedr
[k
].
fedid][i
].
y0+m4y
[j
]+BBYS
/4));
Tcl_Eval
(interp
, cmd
);
if (!map
)
{
sprintf (cmd
, "%s create rectangle %d %d %d %d "
"-fill $evcolor -outline \"\" -tags \"ev\"",
argv
[3],
fedch
[fedr
[k
].
fedid][i
].
fx0+2*j
,
fedch
[fedr
[k
].
fedid][i
].
fy0,
fedch
[fedr
[k
].
fedid][i
].
fx0+2*j
+2,
fedch
[fedr
[k
].
fedid][i
].
fy0+2);
Tcl_Eval
(interp
, cmd
);
}
break;
case 16:
nhits
++;
sprintf (cmd
, "%s create rectangle %f %f %f %f "
"-fill $evcolor -outline \"\" -tags \"ev\"",
argv
[1],
sc
*(fedch
[fedr
[k
].
fedid][i
].
x0+
m16x
[fedch
[fedr
[k
].
fedid][i
].
asd][j
]),
sc
*(fedch
[fedr
[k
].
fedid][i
].
y0+
m16y
[fedch
[fedr
[k
].
fedid][i
].
asd][j
]),
sc
*(fedch
[fedr
[k
].
fedid][i
].
x0+
m16x
[fedch
[fedr
[k
].
fedid][i
].
asd][j
]+BBXS
/8),
sc
*(fedch
[fedr
[k
].
fedid][i
].
y0+
m16y
[fedch
[fedr
[k
].
fedid][i
].
asd][j
]+BBYS
/8));
Tcl_Eval
(interp
, cmd
);
if (!map
)
{
sprintf (cmd
, "%s create rectangle %d %d %d %d "
"-fill $evcolor -outline \"\" -tags \"ev\"",
argv
[3],
fedch
[fedr
[k
].
fedid][i
].
fx0+2*j
,
fedch
[fedr
[k
].
fedid][i
].
fy0,
fedch
[fedr
[k
].
fedid][i
].
fx0+2*j
+2,
fedch
[fedr
[k
].
fedid][i
].
fy0+2);
Tcl_Eval
(interp
, cmd
);
}
}
}
}
sprintf(cmd
, ".ev.tb.curev delete 0 end ");
Tcl_Eval
(interp
, cmd
);
sprintf(cmd
, ".ev.tb.curev insert 0 \"%d\" ", curev
);
Tcl_Eval
(interp
, cmd
);
sprintf(cmd
, ".ev.det delete te ; set ura [clock format %d "
"-format \"%%a %%b %%d %%H:%%M:%%S %%Y\"] ; "
".ev.det create text [expr $evmag*345] [expr $evmag*10] "
"-text \"EVENT: %d %d %d $ura\" "
"-fill \"#c0c000\" -anchor e -font $tfont -tags te ",
evdata.
event_time, logh.
evt, evdata.
run_number,
evdata.
exp_number);
/* logh.dtm, logh.evt, logh.run, logh.exp); */
Tcl_Eval
(interp
, cmd
);
sprintf((char *) Tcl_GetStringResult
(interp
), "evplot: event#=%d #hits=%d #feds=%d bx=%d",
(curev
++), nhits
, nr
, evdata.
physBX);
}
else
{
Tcl_Eval
(interp
, "tk_messageBox -message "
"\"RUN WITHOUT RICH\" -icon warning -type ok");
}
return TCL_OK
;
}
int Evd_evscan
( ClientData clientData
, Tcl_Interp
*interp
,
int argc
, CONST
char *argv
[])
{
int i
, j
, k
, ii
, jj
, nr
, pos
, nh
, pbx
, norm
, dif
, evmask
, sreset
;
unsigned short b
;
uint32_t prev
[5000];
double nhy
[2000] ,nbx
[220] ,hbx
[220], nco4y
[101], nco16y
[101];
double nrepy
[100], nrep64y
[100];
char cmd
[CMDLEN
];
sscanf(Tcl_GetVar
(interp
, "evmask", TCL_GLOBAL_ONLY
), " %d ", &evmask
);
sscanf(Tcl_GetVar
(interp
, "sreset", TCL_GLOBAL_ONLY
), " %d ", &sreset
);
for (i
=0;i
<5000;i
++) prev
[i
]=0;
for (i
=0;i
<2000;i
++) nhy
[i
]=0.
;
for (i
=0;i
<220;i
++)
{
nbx
[i
]=0.
;
hbx
[i
]=0.
;
}
for (i
=0;i
<101;i
++)
{
nco4y
[i
]=0.
;
nco16y
[i
]=0.
;
}
for (i
=0;i
<100;i
++)
{
nrepy
[i
]=0.
;
nrep64y
[i
]=0.
;
}
/* if (Blt_GetVector(interp, "nhy", &nhyV) != TCL_OK) return TCL_ERROR;
*/
if (sreset
)
{
for (k
=0;k
<MAXFED
;k
++)
for (i
=0;i
<64;i
++)
for (j
=0;j
<16;j
++)
hits.
data[k
][i
][j
]=0;
hits.
evt=0;
}
if (reopen_data_file
()) return TCL_ERROR
;
while ((nr
=get_nextev
(fedr
, 0x500, 0)))
{
nh
=0;
for (k
=0;k
<nr
;k
++)
{
if (evmask
) mask_hot
(fedr
[k
].
fedid,(char *)fedr
[k
].
data);
for (ii
=0;ii
<128;ii
++)
{
i
=ii
/2;
if (fedr
[k
].
data[ii
])
for (jj
=0,j
=8*(ii
%2),b
=1;jj
<8;jj
++,j
++,b
<<=1)
if (fedr
[k
].
data[ii
]&b
)
{
if (fedch
[fedr
[k
].
fedid][i
].
pmt) nh
++;
hits.
data[fedr
[k
].
fedid][i
][j
]++;
}
}
}
hits.
evt++;
pbx
=evdata.
physBX;
if ( (unsigned short) pbx
> 219) pbx
=219;
nbx
[pbx
]+=1.
;
hbx
[pbx
]+=(double)nh
;
nh
/=10;
if (nh
> 1999) nh
=1999;
nhy
[nh
]+=1.
;
if (nh
<5000)
{
if (prev
[nh
])
{
dif
=hits.
evt-prev
[nh
];
if (dif
<100) nrepy
[dif
]++;
if ((dif
>>=6)<100) nrep64y
[dif
]++;
}
prev
[nh
]=hits.
evt;
}
}
hits.
max=0;
hits.
min=0x7fffffff;
hits.
ent=0;
norm
=hits.
evt+1;
for (i
=0;i
<MAXFED
;i
++)
for (j
=0;j
<64;j
++)
if (fedch
[i
][j
].
pmt)
for (k
=0;k
<16;k
++)
{
if (fedch
[i
][j
].
pmt == 4)
if (hits.
data[i
][j
][k
])
nco4y
[(100*hits.
data[i
][j
][k
]/norm
)+1]+=1.
;
else
nco4y
[0]+=1.
;
else
if (hits.
data[i
][j
][k
])
nco16y
[(100*hits.
data[i
][j
][k
]/norm
)+1]+=1.
;
else
nco16y
[0]+=1.
;
hits.
ent+=hits.
data[i
][j
][k
];
if (hits.
data[i
][j
][k
]>hits.
max) hits.
max=hits.
data[i
][j
][k
];
if (hits.
data[i
][j
][k
]<hits.
min) hits.
min=hits.
data[i
][j
][k
];
}
for (i
=0;i
<2000;i
++)
{
sprintf(cmd
, "set nhy(%d) %f ", i
, nhy
[i
]);
Tcl_Eval
(interp
, cmd
);
}
for (i
=0;i
<220;i
++)
{
sprintf(cmd
, "set nbxy(%d) %f ", i
, nbx
[i
]);
Tcl_Eval
(interp
, cmd
);
if (nbx
[i
]) hbx
[i
]/=nbx
[i
];
sprintf(cmd
, "set hbxy(%d) %f ", i
, hbx
[i
]);
Tcl_Eval
(interp
, cmd
);
}
for (i
=0;i
<101;i
++)
{
sprintf(cmd
, "set nco4y(%d) %f ", i
, nco4y
[i
]);
Tcl_Eval
(interp
, cmd
);
sprintf(cmd
, "set nco16y(%d) %f ", i
, nco16y
[i
]);
Tcl_Eval
(interp
, cmd
);
}
for (i
=0;i
<100;i
++)
{
sprintf(cmd
, "set nrepy(%d) %f ", i
, nrepy
[i
]);
Tcl_Eval
(interp
, cmd
);
sprintf(cmd
, "set nrep64y(%d) %f ", i
, nrep64y
[i
]);
Tcl_Eval
(interp
, cmd
);
}
/* if (Blt_ResetVector(nhyV, nhyd, 2000, 2000, TCL_VOLATILE) != TCL_OK)
return TCL_ERROR; */
if (reclose_data_file
()) return TCL_ERROR
;
return TCL_OK
;
}
int Evd_evscanplot
( ClientData clientData
, Tcl_Interp
*interp
,
int argc
, CONST
char *argv
[])
{
int i
, j
, k
, coli
, map
, rev
, evm4n
;
float sc
, sm
, norm
, norm1
, evn
;
char col
[17][10]={"000000","111111","222222","333333",
"444444","555555","666666","777777",
"888888","999999","AAAAAA","BBBBBB",
"CCCCCC","DDDDDD","EEEEEE","FFFFFF","FF0000"};
char cmd
[CMDLEN
];
sscanf(argv
[2]," %f ", &sc
);
sscanf(argv
[3]," %f ", &sm
);
sscanf(Tcl_GetVar
(interp
, "evnorm", TCL_GLOBAL_ONLY
), " %f ", &evn
);
sscanf(Tcl_GetVar
(interp
, "evm4norm", TCL_GLOBAL_ONLY
), " %d ", &evm4n
);
sscanf(Tcl_GetVar
(interp
, "evreverse", TCL_GLOBAL_ONLY
), " %d ", &rev
);
sscanf(Tcl_GetVar
(interp
, "evmap", TCL_GLOBAL_ONLY
), " %d ", &map
);
if (evn
) norm
=sm
*(float)(hits.
evt)/100.
;
else norm
=sm
*(float)(hits.
max)/100.
;
for (i
=0;i
<MAXFED
;i
++)
for (j
=0;j
<64;j
++)
{
if (evm4n
&& (fedch
[i
][j
].
pmt==4))
norm1
=4.
*norm
;
else
norm1
=norm
;
for (k
=0;k
<16;k
++)
if (hits.
data[i
][j
][k
]||map
)
{
coli
=(int)(16.
*(float)hits.
data[i
][j
][k
]/norm1
);
if (rev
) coli
^=0xF;
if (coli
>16) coli
=16;
if (coli
<0) coli
=0;
if (!map
)
{
sprintf (cmd
, "%s create rectangle %d %d %d %d "
"-fill #%s -outline \"\" -tags \"sc c%d\"",
argv
[4],
fedch
[i
][j
].
fx0+2*k
,
fedch
[i
][j
].
fy0,
fedch
[i
][j
].
fx0+2*k
+2,
fedch
[i
][j
].
fy0+2,
col
[coli
], coli
);
Tcl_Eval
(interp
, cmd
);
}
switch (fedch
[i
][j
].
pmt)
{
case 4:
sprintf (cmd
, "%s create rectangle %f %f %f %f "
"-fill #%s -outline \"\" -tags \"sc c%d\"",
argv
[1],
sc
*(fedch
[i
][j
].
x0+m4x
[k
]),
sc
*(fedch
[i
][j
].
y0+m4y
[k
]),
sc
*(fedch
[i
][j
].
x0+m4x
[k
]+BBXS
/4),
sc
*(fedch
[i
][j
].
y0+m4y
[k
]+BBYS
/4),
col
[coli
], coli
);
Tcl_Eval
(interp
, cmd
);
break;
case 16:
sprintf (cmd
, "%s create rectangle %f %f %f %f "
"-fill #%s -outline \"\" -tags \"sc c%d\"",
argv
[1],
sc
*(fedch
[i
][j
].
x0+
m16x
[fedch
[i
][j
].
asd][k
]),
sc
*(fedch
[i
][j
].
y0+
m16y
[fedch
[i
][j
].
asd][k
]),
sc
*(fedch
[i
][j
].
x0+
m16x
[fedch
[i
][j
].
asd][k
]+BBXS
/8),
sc
*(fedch
[i
][j
].
y0+
m16y
[fedch
[i
][j
].
asd][k
]+BBYS
/8),
col
[coli
], coli
);
Tcl_Eval
(interp
, cmd
);
break;
}
}
}
sprintf((char *) Tcl_GetStringResult
(interp
), "scan: #events=%u avg=%.2f channel:"
" max=%u min=%u",
hits.
evt, (float)hits.
ent/(float)hits.
evt,
hits.
max, hits.
min);
return TCL_OK
;
}
int Evd_evstatl
( ClientData clientData
, Tcl_Interp
*interp
,
int argc
, CONST
char *argv
[])
{
int hv
,hvch
;
int x
, y
, wid
, fpon
, scan
;
int mb
, db
, con
, ch
, ccon
, sm
, bbr
, bbc
, asd
, px
, py
;
float sc
, x0
, x1
, y0
, y1
;
char cmd
[CMDLEN
], *sn
;
sscanf(argv
[1]," %d ", &wid
);
sscanf(argv
[2]," %d ", &x
);
sscanf(argv
[3]," %d ", &y
);
Tcl_Eval
(interp
, ".ev.det delete hl");
Tcl_Eval
(interp
, ".ev.fed delete hl");
sscanf(Tcl_GetVar
(interp
, "evmap", TCL_GLOBAL_ONLY
), " %d ", &fpon
);
sscanf(Tcl_GetVar
(interp
, "new_scan", TCL_GLOBAL_ONLY
), " %d ", &scan
);
switch (wid
)
{
case 0:
sscanf(argv
[4]," %f ", &sc
);
x
=x
/(int)sc
-FPXOFF
;
y
=y
/(int)sc
-FPYOFF
;
/* if (x<0 || x>=FPXOFF+7*SMXOFF || y<0 || y>=FPYOFF+2*SMYOFF) break; */
if (x
<0 || x
>=7*SMXOFF
|| y
<0 || y
>=2*SMYOFF
) break;
sm
=x
/SMXOFF
+7*(y
/SMYOFF
);
bbr
=(y
%SMYOFF
)/BBYS
;
bbc
=(x
%SMXOFF
)/BBXS
;
px
=(x
%SMXOFF
)%BBXS
;
py
=(y
%SMYOFF
)%BBYS
;
if ((sm
<14)&&(bbr
<16)&&(bbc
<6)&&(px
<16)&&(py
<16))
{
bbr
=15-bbr
;
asd
=0;
ch
=m4c
[px
/2][py
/2];
sn
=fplch
[sm
][bbc
][bbr
].
sn[px
/4][1-py
/4];
Tcl_SetVar
(interp
, "pmtsntmp", sn
, TCL_GLOBAL_ONLY
);
switch(fplch
[sm
][bbc
][bbr
].
pmt)
{
case 16:
asd
=m16a
[px
][py
];
ch
=m16c
[px
][py
];
case 4:
if ((mb
=fplch
[sm
][bbc
][bbr
].
mb[asd
]) == -1) break;
ccon
=fplch
[sm
][bbc
][bbr
].
wi[asd
];
db
=ccon
/16;
con
=ccon
%16;
sprintf(cmd
, ".ev.fed coords %d", fplch
[sm
][bbc
][bbr
].
id[asd
]);
Tcl_Eval
(interp
, cmd
);
sscanf((char *) Tcl_GetStringResult
(interp
), " %f %f %f %f ", &x0
, &y0
, &x1
, &y1
);
x0
-=1.
; y0
-=1.
; x1
+=1.
; y1
+=1.
;
sprintf(cmd
, ".ev.fed create rectangle %f %f %f %f "
"-fill \"\" -outline #FF00FF -width 2 -tags \"hl\"",
x0
, y0
, x1
, y1
);
Tcl_Eval
(interp
, cmd
);
sprintf(cmd
, ".ev.det coords %d", fedch
[mb
][ccon
].
id);
Tcl_Eval
(interp
, cmd
);
sscanf((char *) Tcl_GetStringResult
(interp
), " %f %f %f %f ", &x0
, &y0
, &x1
, &y1
);
x0
-=1.
; y0
-=1.
; x1
+=1.
; y1
+=1.
;
sprintf(cmd
, ".ev.det create rectangle %f %f %f %f "
"-fill \"\" -outline #FF00FF -width 2 -tags \"hl\"",
x0
, y0
, x1
, y1
);
Tcl_Eval
(interp
, cmd
);
hv
=-1;
hvch
=-1;
if (!scan
)
sprintf((char *) Tcl_GetStringResult
(interp
), "mb:%2d db:%d con:%2d sm:%2d"
" r:%2d c:%d asd:%d ch:%2d SN:%s hv:%3d hvch%3d entr:%d",
mb
, db
, con
, sm
, bbr
, bbc
, asd
, ch
, sn
, hv
,hvch
,
hits.
data[mb
][ccon
][ch
]);
else
sprintf((char *) Tcl_GetStringResult
(interp
),
"mb:%2d db:%d con:%2d sm:%2d r:%2d c:%d asd:%d ch:%2d SN:%s hv:%3d hvch%3d",
mb
, db
, con
, sm
, bbr
, bbc
, asd
, ch
, sn
, hv
,hvch
);
break;
}
}
break;
case 1:
y
-=5;
x
-=3;
if (x
<0 || y
<0) break;
mb
=2*(y
/52)+x
/140;
con
=(y
%52)/3;
db
=(x
%140)/34;
ch
=(x
%34)/2;
if ((mb
<28)&&(db
<4)&&(con
<16)&&(ch
<16))
{
ccon
=db
*16+con
;
if (fedch
[mb
][ccon
].
pmt)
{
sm
=fedch
[mb
][ccon
].
sm;
bbr
=fedch
[mb
][ccon
].
bbr;
bbc
=fedch
[mb
][ccon
].
bbc;
asd
=fedch
[mb
][ccon
].
asd;
sprintf(cmd
, ".ev.det coords %d", fedch
[mb
][ccon
].
id);
Tcl_Eval
(interp
, cmd
);
sscanf((char *) Tcl_GetStringResult
(interp
), " %f %f %f %f ", &x0
, &y0
, &x1
, &y1
);
x0
-=1.
; y0
-=1.
; x1
+=1.
; y1
+=1.
;
sprintf(cmd
, ".ev.det create rectangle %f %f %f %f "
"-fill \"\" -outline #FF00FF -width 2 -tags \"hl\"",
x0
, y0
, x1
, y1
);
Tcl_Eval
(interp
, cmd
);
sprintf(cmd
, ".ev.fed coords %d", fplch
[sm
][bbc
][bbr
].
id[asd
]);
Tcl_Eval
(interp
, cmd
);
sscanf((char *) Tcl_GetStringResult
(interp
), " %f %f %f %f ", &x0
, &y0
, &x1
, &y1
);
x0
-=1.
; y0
-=1.
; x1
+=1.
; y1
+=1.
;
sprintf(cmd
, ".ev.fed create rectangle %f %f %f %f "
"-fill \"\" -outline #FF00FF -width 2 -tags \"hl\"",
x0
, y0
, x1
, y1
);
Tcl_Eval
(interp
, cmd
);
if (!scan
)
sprintf((char *) Tcl_GetStringResult
(interp
), "mb:%2d db:%d con:%2d sm:%2d"
" r:%2d c:%d asd:%d ch:%2d entr:%d",
mb
, db
, con
, sm
, bbr
, bbc
, asd
, ch
,
hits.
data[mb
][ccon
][ch
]);
else
sprintf((char *) Tcl_GetStringResult
(interp
),
"mb:%2d db:%d con:%2d sm:%2d r:%2d c:%d asd:%d ch:%2d",
mb
, db
, con
, sm
, bbr
, bbc
, asd
, ch
);
}
}
break;
}
return TCL_OK
;
}
int Evd_evdump
( ClientData clientData
, Tcl_Interp
*interp
,
int argc
, CONST
char *argv
[])
{
FILE
*fout
;
if (reopen_data_file
()) return TCL_ERROR
;
if ((fout
=fopen(argv
[1], "w"))==NULL
) return TCL_ERROR
;
while (dump_cmp
(fout
, 0x500));
if (fclose(fout
)==EOF
) return TCL_ERROR
;
if (reclose_data_file
()) return TCL_ERROR
;
return TCL_OK
;
}
/*
int Evd_proto( ClientData clientData, Tcl_Interp *interp,
int argc, CONST char *argv[])
{
return TCL_OK;
}
*/
int Evd_Init
(Tcl_Interp
*interp
)
{
if (is_little_endian
())
printf("Evd running on LittleEndian machine\n");
else
printf("Evd running on BigEndian machine\n");
Tcl_PkgProvide
(interp
, "Evd", "1.0");
Tcl_CreateCommand
(interp
, "evinit", Evd_evinit
, (ClientData
) NULL
,
(Tcl_CmdDeleteProc
*) NULL
);
Tcl_CreateCommand
(interp
, "evopen", Evd_evopen
, (ClientData
) NULL
,
(Tcl_CmdDeleteProc
*) NULL
);
Tcl_CreateCommand
(interp
, "evgoto", Evd_evgoto
, (ClientData
) NULL
,
(Tcl_CmdDeleteProc
*) NULL
);
Tcl_CreateCommand
(interp
, "evclose", Evd_evclose
, (ClientData
) NULL
,
(Tcl_CmdDeleteProc
*) NULL
);
Tcl_CreateCommand
(interp
, "evplot", Evd_evplot
, (ClientData
) NULL
,
(Tcl_CmdDeleteProc
*) NULL
);
Tcl_CreateCommand
(interp
, "evscan", Evd_evscan
, (ClientData
) NULL
,
(Tcl_CmdDeleteProc
*) NULL
);
Tcl_CreateCommand
(interp
, "evscanplot", Evd_evscanplot
, (ClientData
) NULL
,
(Tcl_CmdDeleteProc
*) NULL
);
Tcl_CreateCommand
(interp
, "evstatl", Evd_evstatl
, (ClientData
) NULL
,
(Tcl_CmdDeleteProc
*) NULL
);
Tcl_CreateCommand
(interp
, "evdump", Evd_evdump
, (ClientData
) NULL
,
(Tcl_CmdDeleteProc
*) NULL
);
return TCL_OK
;
}
#ifdef __cplusplus
}
#endif