adcsum.c

Go to the documentation of this file.
00001 /********************************************************************\
00002 
00003   Name:         adcsum.c
00004   Created by:   Stefan Ritt
00005 
00006   Contents:     Example analyzer module for ADC summing. This module
00007                 looks for a bank named CADC and produces an ASUM
00008                 bank which contains the sum of all ADC values. The
00009                 ASUM bank is a "structured" bank. It has been defined
00010                 in the ODB and transferred to experim.h.
00011 
00012   $Id: adcsum.c 2753 2005-10-07 14:55:31Z ritt $
00013 
00014 \********************************************************************/
00015 
00016 /*-- Include files -------------------------------------------------*/
00017 
00018 /* standard includes */
00019 #include <stdio.h>
00020 #include <math.h>
00021 
00022 #define DEFINE_TESTS // must be defined prior to midas.h
00023 
00024 /* midas includes */
00025 #include "midas.h"
00026 #include "experim.h"
00027 #include "analyzer.h"
00028 
00029 /* root includes */
00030 #include <TH1D.h>
00031 
00032 #ifndef PI
00033 #define PI 3.14159265359
00034 #endif
00035 
00036 /*-- Parameters ----------------------------------------------------*/
00037 
00038 ADC_SUMMING_PARAM adc_summing_param;
00039 
00040 /*-- Tests ---------------------------------------------------------*/
00041 
00042 DEF_TEST(low_sum);
00043 DEF_TEST(high_sum);
00044 
00045 /*-- Module declaration --------------------------------------------*/
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",               /* module name           */
00055    "Stefan Ritt",               /* author                */
00056    adc_summing,                 /* event routine         */
00057    NULL,                        /* BOR routine           */
00058    NULL,                        /* EOR routine           */
00059    adc_summing_init,            /* init routine          */
00060    NULL,                        /* exit routine          */
00061    &adc_summing_param,          /* parameter structure   */
00062    sizeof(adc_summing_param),   /* structure size        */
00063    adc_summing_param_str,       /* initial parameters    */
00064 };
00065 
00066 /*-- Module-local variables-----------------------------------------*/
00067 
00068 static TH1D *hAdcSum, *hAdcAvg;
00069 
00070 /*-- init routine --------------------------------------------------*/
00071 
00072 INT adc_summing_init(void)
00073 {
00074    /* book ADC sum histo */
00075    hAdcSum = h1_book<TH1D>("ADCSUM", "ADC sum", 500, 0, 10000);
00076 
00077    /* book ADC average in separate subfolder */
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 /*-- event routine -------------------------------------------------*/
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    /* look for CADC bank, return if not present */
00094    n_adc = bk_locate(pevent, "CADC", &cadc);
00095    if (n_adc == 0)
00096       return 1;
00097 
00098    /* create ADC sum bank */
00099    bk_create(pevent, "ASUM", TID_STRUCT, &asum);
00100 
00101    /* sum all channels above threashold */
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    /* calculate ADC average */
00110    asum->average = j > 0 ? asum->sum / j : 0;
00111 
00112    /* evaluate tests */
00113    SET_TEST(low_sum, asum->sum < 1000);
00114    SET_TEST(high_sum, asum->sum > 1000);
00115 
00116    /* fill sum histo */
00117    hAdcSum->Fill(asum->sum, 1);
00118 
00119    /* fill average histo */
00120    hAdcAvg->Fill(asum->average);
00121 
00122    /* close calculated bank */
00123    bk_close(pevent, asum + 1);
00124 
00125    return SUCCESS;
00126 }

Midas DOC Version 1.9.5 ---- PSI Stefan Ritt ----
Contributions: Pierre-Andre Amaudruz - Sergio Ballestrero - Suzannah Daviel - Doxygen - Peter Green - Qing Gu - Greg Hackman - Gertjan Hofman - Paul Knowles - Rudi Meier - Glenn Moloney - Dave Morris - John M O'Donnell - Konstantin Olchanski - Renee Poutissou - Tamsen Schurman - Andreas Suter - Jan M.Wouters - Piotr Adam Zolnierczuk