MIDAS
Loading...
Searching...
No Matches
adcsum_module.cxx
Go to the documentation of this file.
1/********************************************************************\
2
3 Name: adcsum.c
4 Created by: Stefan Ritt
5
6 Contents: Example analyzer module for ADC summing. This module
7 looks for a bank named CADC and produces an ASUM
8 bank which contains the sum of all ADC values. The
9 ASUM bank is a "structured" bank. It has been defined
10 in the ODB and transferred to experim.h.
11
12 $Id:$
13
14\********************************************************************/
15
16/*-- Include files -------------------------------------------------*/
17
18/* standard includes */
19#include <stdio.h>
20#include <math.h>
21
22//#define DEFINE_TESTS // must be defined prior to midas.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
33/*-- Parameters ----------------------------------------------------*/
34
36
37/*-- Tests ---------------------------------------------------------*/
38
39//DEF_TEST(low_sum);
40//DEF_TEST(high_sum);
41
42#if 0
43/*-- Module declaration --------------------------------------------*/
44
46
48 "ADC summing", /* module name */
49 "Stefan Ritt", /* author */
50 adc_summing, /* event routine */
51 NULL, /* BOR routine */
52 NULL, /* EOR routine */
53 adc_summing_init, /* init routine */
54 NULL, /* exit routine */
55 &adc_summing_param, /* parameter structure */
56 sizeof(adc_summing_param), /* structure size */
57 adc_summing_param_str, /* initial parameters */
58};
59#endif
60
61/*-- Module-local variables-----------------------------------------*/
62
63//static TH1D *hAdcSum, *hAdcAvg;
64
65#if 0
66
67/*-- init routine --------------------------------------------------*/
68
70{
71 /* book ADC sum histo */
72 hAdcSum = h1_book<TH1D>("ADCSUM", "ADC sum", 500, 0, 10000);
73
74 /* book ADC average in separate subfolder */
75 open_subfolder("Average");
76 hAdcAvg = h1_book<TH1D>("ADCAVG", "ADC average", 500000, 0, 10000);
78
79 return SUCCESS;
80}
81
82/*-- event routine -------------------------------------------------*/
83
84
85INT adc_summing(EVENT_HEADER * pheader, void *pevent)
86{
87 INT i, j, n_adc;
88 float *cadc;
90
91 /* look for CADC bank, return if not present */
92 n_adc = bk_locate(pevent, "CADC", &cadc);
93 if (n_adc == 0)
94 return 1;
95
96 /* create ADC sum bank */
97 bk_create(pevent, "ASUM", TID_STRUCT, (void**)&asum);
98
99 /* sum all channels above threashold */
100 asum->sum = 0.f;
101 for (i = j = 0; i < n_adc; i++)
103 asum->sum += cadc[i];
104 j++;
105 }
106
107 /* calculate ADC average */
108 asum->average = j > 0 ? asum->sum / j : 0;
109
110 /* evaluate tests */
111 SET_TEST(low_sum, asum->sum < 1000);
112 SET_TEST(high_sum, asum->sum > 1000);
113
114 /* fill sum histo */
115 hAdcSum->Fill(asum->sum, 1);
116
117 /* fill average histo */
118 hAdcAvg->Fill(asum->average);
119
120 /* close calculated bank */
121 bk_close(pevent, asum + 1);
122
123 return SUCCESS;
124}
125#endif
126
127//
128// MIDAS analyzer example 2: ROOT analyzer
129//
130// K.Olchanski
131//
132
133#include <stdio.h>
134
135#include "manalyzer.h"
136#include "midasio.h"
137
138#include "TH1D.h"
139
140struct AdcSum: public TARunObject
141{
144
146 : TARunObject(runinfo)
147 {
148 printf("AdcSum::ctor!\n");
149
150 runinfo->fRoot->fOutputFile->cd(); // select correct ROOT directory
151
152 /* book ADC sum histo */
153 fAdcSum = new TH1D("ADCSUM", "ADC sum", 500, 0, 10000);
154
155 /* book ADC average in separate subfolder */
156 TDirectory *subdir = runinfo->fRoot->fOutputFile->mkdir("Average");
157 subdir->cd();
158
159 fAdcAvg = new TH1D("ADCAVG", "ADC average", 500000, 0, 10000);
160
161 runinfo->fRoot->fOutputFile->cd(); // select correct ROOT directory
162 }
163
165 {
166 printf("AdcSum::dtor!\n");
167 }
168
170 {
171 printf("BeginRun, run %d, file %s\n", runinfo->fRunNo, runinfo->fFileName.c_str());
172 }
173
175 {
176 printf("EndRun, run %d\n", runinfo->fRunNo);
177 }
178
180 {
181 printf("Analyze, run %d, event serno %d, id 0x%04x, data size %d\n", runinfo->fRunNo, event->serial_number, (int)event->event_id, event->data_size);
182
183 TMBank* bcadc = event->FindBank("CADC");
184 if (!bcadc)
185 return flow;
186
187 float* cadc = (float*)event->GetBankData(bcadc);
188 if (!cadc)
189 return flow;
190
191 int n_adc = bcadc->data_size / sizeof(float);
192 if (n_adc == 0)
193 return flow;
194
196
197 /* sum all channels above threashold */
198 asum.sum = 0.f;
199 int j = 0;
200 for (int i = 0; i < n_adc; i++)
202 asum.sum += cadc[i];
203 j++;
204 }
205
206 /* calculate ADC average */
207 asum.average = j > 0 ? asum.sum / j : 0;
208
209 /* evaluate tests */
210 //SET_TEST(low_sum, asum.sum < 1000);
211 //SET_TEST(high_sum, asum.sum > 1000);
212
213 /* fill sum histo */
214 fAdcSum->Fill(asum.sum, 1);
215
216 /* fill average histo */
217 fAdcAvg->Fill(asum.average);
218
219 /* create ADC sum bank */
220 event->AddBank("ASUM", TID_STRUCT, (char*)&asum, sizeof(asum));
221
222 return flow;
223 }
224};
225
226class AdcSumFactory: public TAFactory
227{
228public:
229 void Init(const std::vector<std::string> &args)
230 {
231 printf("Init!\n");
232 }
233
234 void Finish()
235 {
236 printf("Finish!\n");
237 }
238
240 {
241 printf("NewRunObject, run %d, file %s\n", runinfo->fRunNo, runinfo->fFileName.c_str());
242 return new AdcSum(runinfo);
243 }
244};
245
247
248/* emacs
249 * Local Variables:
250 * tab-width: 8
251 * c-basic-offset: 3
252 * indent-tabs-mode: nil
253 * End:
254 */
RUNINFO runinfo
Definition analyzer.cxx:49
INT adc_summing_init(void)
Definition adcsum.cxx:73
ANA_MODULE adc_summing_module
Definition adcsum.cxx:54
static TH1D * hAdcAvg
Definition adcsum.cxx:69
static TH1D * hAdcSum
Definition adcsum.cxx:69
INT adc_summing(EVENT_HEADER *, void *)
Definition adcsum.cxx:88
ADC_SUMMING_PARAM adc_summing_param
static TARegister tar(new AdcSumFactory)
TARunObject * NewRunObject(TARunInfo *runinfo)
void Init(const std::vector< std::string > &args)
#define ADC_SUMMING_PARAM_STR(_name)
Definition experim.h:80
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
#define SUCCESS
Definition mcstd.h:54
#define TID_STRUCT
Definition midas.h:348
INT i
Definition mdump.cxx:32
#define SET_TEST(t, v)
Definition midas.h:1346
void EXPRT close_subfolder(void)
int INT
Definition midas.h:129
void EXPRT open_subfolder(const char *name)
INT j
Definition odbhist.cxx:40
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
float adc_threshold
Definition experim.h:77
float sum
Definition experim.h:109
TH1D * fAdcSum
TAFlowEvent * Analyze(TARunInfo *runinfo, TMEvent *event, TAFlags *flags, TAFlowEvent *flow)
TH1D * fAdcAvg
void EndRun(TARunInfo *runinfo)
void BeginRun(TARunInfo *runinfo)
AdcSum(TARunInfo *runinfo)