00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <stdio.h>
00022 #include <time.h>
00023
00024
00025 #include "midas.h"
00026 #include "experim.h"
00027 #include "analyzer.h"
00028
00029
00030 #include <TH1D.h>
00031 #include <TTree.h>
00032
00033
00034
00035 ADC_CALIBRATION_PARAM adccalib_param;
00036 extern EXP_PARAM exp_param;
00037 extern RUNINFO runinfo;
00038
00039
00040
00041 INT adc_calib(EVENT_HEADER *, void *);
00042 INT adc_calib_init(void);
00043 INT adc_calib_bor(INT run_number);
00044 INT adc_calib_eor(INT run_number);
00045
00046 ADC_CALIBRATION_PARAM_STR(adc_calibration_param_str);
00047
00048 ANA_MODULE adc_calib_module = {
00049 "ADC calibration",
00050 "Stefan Ritt",
00051 adc_calib,
00052 adc_calib_bor,
00053 adc_calib_eor,
00054 adc_calib_init,
00055 NULL,
00056 &adccalib_param,
00057 sizeof(adccalib_param),
00058 adc_calibration_param_str,
00059 };
00060
00061
00062
00063 static TH1D *hAdcHists[N_ADC];
00064
00065
00066
00067 #define ADC_N_BINS 500
00068 #define ADC_X_LOW 0
00069 #define ADC_X_HIGH 4000
00070
00071 INT adc_calib_init(void)
00072 {
00073 char name[256];
00074 int i;
00075
00076
00077
00078 for (i = 0; i < N_ADC; i++) {
00079 char title[256];
00080
00081 sprintf(name, "CADC%02d", i);
00082 sprintf(title, "ADC %d", i);
00083
00084 hAdcHists[i] = h1_book<TH1D>(name, title, ADC_N_BINS, ADC_X_LOW, ADC_X_HIGH);
00085 }
00086
00087 return SUCCESS;
00088 }
00089
00090
00091
00092 INT adc_calib_bor(INT run_number)
00093 {
00094 return SUCCESS;
00095 }
00096
00097
00098
00099 INT adc_calib_eor(INT run_number)
00100 {
00101 return SUCCESS;
00102 }
00103
00104
00105
00106 INT adc_calib(EVENT_HEADER * pheader, void *pevent)
00107 {
00108 INT i;
00109 WORD *pdata;
00110 float *cadc;
00111
00112
00113 if (!bk_locate(pevent, "ADC0", &pdata))
00114 return 1;
00115
00116
00117 bk_create(pevent, "CADC", TID_FLOAT, &cadc);
00118
00119
00120 for (i = 0; i < N_ADC; i++)
00121 cadc[i] = 0.f;
00122
00123
00124 for (i = 0; i < N_ADC; i++)
00125 cadc[i] = (float) ((double) pdata[i] - adccalib_param.pedestal[i] + 0.5);
00126
00127
00128 for (i = 0; i < N_ADC; i++)
00129 cadc[i] *= adccalib_param.software_gain[i];
00130
00131
00132 for (i = 0; i < N_ADC; i++)
00133 if (cadc[i] > (float) adccalib_param.histo_threshold)
00134 hAdcHists[i]->Fill(cadc[i], 1);
00135
00136
00137 bk_close(pevent, cadc + N_ADC);
00138
00139 return SUCCESS;
00140 }