This example is suitable for use with the standard MIDAS VME data acquisition system using Silena 9418 or CAEN V785 ADCs with CAEN V767 or V1190 TDCs.
The example assumes 4 ADC modules and 1 TDC module - ie a total of 128 channels. In addition to 4 statistics histograms it generates 1 ADC; 1 TDC and 1 E v/s T histogram for each of the 128 channels.
It assumes that you are using the default group assignment and that the ADCS are CAEN V785 and the TDCs are CAEN V1190. Follow the code comments if using other module types.
For other numbers of channels change the variable NUMCHANS and also change the histogram definitions for adc_, tdc_ and et_.
The TDCs generate 16 bit data and so 64K histograms are created. If you know that you will actually only use fewer bits you may wish to reduce the size of the tdc_ histograms. Note that the et_ histograms are compressed from 4K x 64K to 256 x 256 by compressing the energy by a factor of 16 and the time by a factor of 256.
*trigger
128
*oned
1..128 adc_ 4096
129..256 tdc_ 65536
1000 stat 4096
1001 mult 1024
1002 invalid 65536
1003 twod 128
*twod
513..640 et_ 256
*vars
*sort
#include < stdio.h >
#include < stdlib.h >
#define NUMCHANS 128
#define ADC_GroupBase 32 /* This assumes that there are 4 CAEN V785 ADCs. For Silena 9418 ADCs change group 32 to group 1 */
#define TDC_GroupBase 24 /* This assumes that there is 1 CAEN V1190 TDC. For CAEN V767 change group 24 to group 16 */
#define ADC_NUM (NUMCHANS+31)/32
#define TDC_NUM (NUMCHANS+127)/128
#define NUMADCS ADC_NUM*32 /* up to 4 * 32 channel ADC modules and 1 * 128 channel TDC module */
#define NUMTDCS TDC_NUM*128
int data[NUMADCS+NUMTDCS];
short hit[NUMADCS+NUMTDCS];
int events;
int init(void)
{
events=0;
return 0;
}
int sortin(void)
{
int i, j;
int group, item;
int module;
int num;
int valid;
events++;
for (j=0; j < NUMADCS+NUMTDCS; j++) hit[j]=0; /* zero hit array */
if ( mult > 0 && mult < 1024 )
{
inc1d( MULT, mult );
}
for ( i = 0; i < mult; i++ )
{
valid = 0;
group = gid[i] & 255;
item = (gid[i] >> 8) & 63;
inc1d( STAT, (group*64)+item);
if (group >= ADC_GroupBase && group < (ADC_GroupBase+ADC_NUM))
{
module = group - ADC_GroupBase; /* value is 0 -> (ADC_Num-1) */
if (item > 32) {printf ("bad data 0x%x\n", gid[i]); break;}
num = (module*32) + item; /* value is 0 -> NUMADCS-1 */
hit[num] = 1;
data[num] = gdata[i];
valid++;
inc1d(num+1, gdata[i]);
}
if (group >= TDC_GroupBase && group < (TDC_GroupBase+(TDC_NUM*2)))
{
module = group - TDC_GroupBase; /* value is 0 -> (TDC_Num-1) */
num = (module*64) + item + NUMADCS; /* value is NUMADCS -> (2*NUMADCS)-1 */
hit[num] = 1;
data[num] = gdata[i];
valid++;
inc1d(num+1, gdata[i]);
}
if (valid==0) inc1d(INVALID, gid[i] & 0x0000ffff); /* so we know that we don't understand this */
for (j=0; j < NUMADCS; j++)
{
/* 16 = 4K/256; 256 = 64K/256 */
if (hit[j] == 1 && hit[j+NUMADCS] == 1) {inc2d(513+j, data[j]/16, data[j+NUMADCS]/256); inc1d(TWOD,j);}
}
}
return 0;
}
int finish(void)
{
printf("Sorted %d events\n", events);
return 0;
}