00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <stdio.h>
00020 #include <math.h>
00021
00022 #define DEFINE_TESTS // must be defined prior to midas.h
00023
00024
00025 #include "midas.h"
00026 #include "experim.h"
00027 #include "analyzer.h"
00028
00029
00030 #include <TH1D.h>
00031
00032 #ifndef PI
00033 #define PI 3.14159265359
00034 #endif
00035
00036
00037
00038 ADC_SUMMING_PARAM adc_summing_param;
00039
00040
00041
00042 DEF_TEST(low_sum);
00043 DEF_TEST(high_sum);
00044
00045
00046
00047 INT adc_summing(EVENT_HEADER *, void *);
00048 INT adc_summing_init(void);
00049 INT adc_summing_bor(INT run_number);
00050
00051 ADC_SUMMING_PARAM_STR(adc_summing_param_str);
00052
00053 ANA_MODULE adc_summing_module = {
00054 "ADC summing",
00055 "Stefan Ritt",
00056 adc_summing,
00057 NULL,
00058 NULL,
00059 adc_summing_init,
00060 NULL,
00061 &adc_summing_param,
00062 sizeof(adc_summing_param),
00063 adc_summing_param_str,
00064 };
00065
00066
00067
00068 static TH1D *hAdcSum, *hAdcAvg;
00069
00070
00071
00072 INT adc_summing_init(void)
00073 {
00074
00075 hAdcSum = h1_book<TH1D>("ADCSUM", "ADC sum", 500, 0, 10000);
00076
00077
00078 open_subfolder("Average");
00079 hAdcAvg = h1_book<TH1D>("ADCAVG", "ADC average", 500000, 0, 10000);
00080 close_subfolder();
00081
00082 return SUCCESS;
00083 }
00084
00085
00086
00087 INT adc_summing(EVENT_HEADER * pheader, void *pevent)
00088 {
00089 INT i, j, n_adc;
00090 float *cadc;
00091 ASUM_BANK *asum;
00092
00093
00094 n_adc = bk_locate(pevent, "CADC", &cadc);
00095 if (n_adc == 0)
00096 return 1;
00097
00098
00099 bk_create(pevent, "ASUM", TID_STRUCT, &asum);
00100
00101
00102 asum->sum = 0.f;
00103 for (i = j = 0; i < n_adc; i++)
00104 if (cadc[i] > adc_summing_param.adc_threshold) {
00105 asum->sum += cadc[i];
00106 j++;
00107 }
00108
00109
00110 asum->average = j > 0 ? asum->sum / j : 0;
00111
00112
00113 SET_TEST(low_sum, asum->sum < 1000);
00114 SET_TEST(high_sum, asum->sum > 1000);
00115
00116
00117 hAdcSum->Fill(asum->sum, 1);
00118
00119
00120 hAdcAvg->Fill(asum->average);
00121
00122
00123 bk_close(pevent, asum + 1);
00124
00125 return SUCCESS;
00126 }