MIDAS
Loading...
Searching...
No Matches
adccalib.cxx
Go to the documentation of this file.
1/********************************************************************\
2
3 Name: adccalib.c
4 Created by: Stefan Ritt
5
6 Contents: Example analyzer module for ADC calibration. Looks
7 for ADC0 bank, subtracts pedestals and applies gain
8 calibration. The resulting values are appended to
9 the event as an CADC bank ("calibrated ADC"). The
10 pedestal values and software gains are stored in
11 adccalib_param structure which was defined in the ODB
12 and transferred to experim.h.
13
14 $Id:$
15
16\********************************************************************/
17
18/*-- Include files -------------------------------------------------*/
19
20/* standard includes */
21#include <stdio.h>
22#include <time.h>
23
24/* midas includes */
25#include "midas.h"
26#include "rmidas.h"
27#include "experim.h"
28#include "analyzer.h"
29
30/* root includes */
31#include <TH1D.h>
32#include <TTree.h>
33
34/*-- Parameters ----------------------------------------------------*/
35
37extern EXP_PARAM exp_param;
38extern RUNINFO runinfo;
39
40/*-- Module declaration --------------------------------------------*/
41
42INT adc_calib(EVENT_HEADER *, void *);
46
47ADC_CALIBRATION_PARAM_STR(adc_calibration_param_str);
48
50 "ADC calibration", /* module name */
51 "Stefan Ritt", /* author */
52 adc_calib, /* event routine */
53 adc_calib_bor, /* BOR routine */
54 adc_calib_eor, /* EOR routine */
55 adc_calib_init, /* init routine */
56 NULL, /* exit routine */
57 &adccalib_param, /* parameter structure */
58 sizeof(adccalib_param), /* structure size */
59 adc_calibration_param_str, /* initial parameters */
60};
61
62/*-- module-local variables ----------------------------------------*/
63
64static TH1D *hAdcHists[N_ADC];
65
66/*-- init routine --------------------------------------------------*/
67
68#define ADC_N_BINS 500
69#define ADC_X_LOW 0
70#define ADC_X_HIGH 4000
71
73{
74 char name[256];
75 int i;
76
77 /* book CADC histos */
78
79 for (i = 0; i < N_ADC; i++) {
80 char title[256];
81
82 sprintf(name, "CADC%02d", i);
83 sprintf(title, "ADC %d", i);
84
86 }
87
88 return SUCCESS;
89}
90
91/*-- BOR routine ---------------------------------------------------*/
92
97
98/*-- eor routine ---------------------------------------------------*/
99
101{
102 return SUCCESS;
103}
104
105/*-- event routine -------------------------------------------------*/
106
107INT adc_calib(EVENT_HEADER * pheader, void *pevent)
108{
109 INT i;
110 WORD *pdata;
111 float *cadc;
112
113 /* look for ADC0 bank, return if not present */
114 if (!bk_locate(pevent, "ADC0", &pdata))
115 return 1;
116
117 /* create calibrated ADC bank */
118 bk_create(pevent, "CADC", TID_FLOAT, (void**)&cadc);
119
120 /* zero cadc bank */
121 for (i = 0; i < N_ADC; i++)
122 cadc[i] = 0.f;
123
124 /* subtract pedestal */
125 for (i = 0; i < N_ADC; i++)
126 cadc[i] = (float) ((double) pdata[i] - adccalib_param.pedestal[i] + 0.5);
127
128 /* apply software gain calibration */
129 for (i = 0; i < N_ADC; i++)
131
132 /* fill ADC histos if above threshold */
133 for (i = 0; i < N_ADC; i++)
134 if (cadc[i] > (float) adccalib_param.histo_threshold)
135 hAdcHists[i]->Fill(cadc[i], 1);
136
137 /* close calculated bank */
138 bk_close(pevent, cadc + N_ADC);
139
140 return SUCCESS;
141}
#define ADC_N_BINS
Definition adccalib.cxx:68
static TH1D * hAdcHists[N_ADC]
Definition adccalib.cxx:64
INT adc_calib(EVENT_HEADER *, void *)
Definition adccalib.cxx:107
ADC_CALIBRATION_PARAM adccalib_param
Definition adccalib.cxx:36
#define ADC_X_LOW
Definition adccalib.cxx:69
ANA_MODULE adc_calib_module
Definition adccalib.cxx:49
EXP_PARAM exp_param
Definition analyzer.cxx:51
#define ADC_X_HIGH
Definition adccalib.cxx:70
INT adc_calib_bor(INT run_number)
Definition adccalib.cxx:93
RUNINFO runinfo
Definition analyzer.cxx:49
INT adc_calib_init(void)
Definition adccalib.cxx:72
INT adc_calib_eor(INT run_number)
Definition adccalib.cxx:100
#define N_ADC
Definition deferredfe.c:49
#define ADC_CALIBRATION_PARAM_STR(_name)
Definition experim.h:46
INT bk_close(void *event, void *pdata)
Definition midas.cxx:16780
INT bk_locate(const void *event, const char *name, void *pdata)
Definition midas.cxx:16889
void bk_create(void *event, const char *name, WORD type, void **pdata)
Definition midas.cxx:16561
unsigned short int WORD
Definition mcstd.h:49
#define SUCCESS
Definition mcstd.h:54
#define TID_FLOAT
Definition midas.h:341
INT run_number[2]
Definition mana.cxx:246
INT i
Definition mdump.cxx:32
int INT
Definition midas.h:129
#define name(x)
Definition midas_macro.h:24
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
float software_gain[8]
Definition experim.h:42