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   $Log: adcsum.c,v $
00013   Revision 1.10  2004/01/08 08:40:08  midas
00014   Implemented standard indentation
00015 
00016   Revision 1.9  2003/11/14 13:43:10  midas
00017   Fixed type
00018 
00019   Revision 1.8  2003/04/28 15:33:05  midas
00020   Fixed compiler warnings
00021 
00022   Revision 1.7  2003/04/25 14:49:46  midas
00023   Removed HBOOK code
00024 
00025   Revision 1.6  2003/04/23 15:09:29  midas
00026   Added 'average' in ASUM bank
00027 
00028   Revision 1.5  2003/04/22 15:00:27  midas
00029   Worked on ROOT histo booking
00030 
00031   Revision 1.4  2003/04/21 04:02:13  olchansk
00032   replace MANA_LITE with HAVE_HBOOK and HAVE_ROOT
00033   implement ROOT-equivalents of the sample HBOOK code
00034   implement example of adding custom branches to the analyzer root output file
00035 
00036   Revision 1.3  2002/05/10 05:22:59  pierre
00037   add MANA_LITE #ifdef
00038 
00039   Revision 1.2  1998/10/12 12:18:58  midas
00040   Added Log tag in header
00041 
00042 
00043 \********************************************************************/
00044 
00045 /*-- Include files -------------------------------------------------*/
00046 
00047 /* standard includes */
00048 #include <stdio.h>
00049 #include <math.h>
00050 
00051 /* midas includes */
00052 #include "midas.h"
00053 #include "experim.h"
00054 #include "analyzer.h"
00055 
00056 /* root includes */
00057 #include <TH1F.h>
00058 #include <TDirectory.h>
00059 
00060 #ifndef PI
00061 #define PI 3.14159265359
00062 #endif
00063 
00064 /*-- Parameters ----------------------------------------------------*/
00065 
00066 ADC_SUMMING_PARAM adc_summing_param;
00067 
00068 /*-- Module declaration --------------------------------------------*/
00069 
00070 INT adc_summing(EVENT_HEADER *, void *);
00071 INT adc_summing_init(void);
00072 INT adc_summing_bor(INT run_number);
00073 
00074 ADC_SUMMING_PARAM_STR(adc_summing_param_str);
00075 
00076 ANA_MODULE adc_summing_module = {
00077    "ADC summing",               /* module name           */
00078    "Stefan Ritt",               /* author                */
00079    adc_summing,                 /* event routine         */
00080    NULL,                        /* BOR routine           */
00081    NULL,                        /* EOR routine           */
00082    adc_summing_init,            /* init routine          */
00083    NULL,                        /* exit routine          */
00084    &adc_summing_param,          /* parameter structure   */
00085    sizeof(adc_summing_param),   /* structure size        */
00086    adc_summing_param_str,       /* initial parameters    */
00087 };
00088 
00089 /*-- Module-local variables-----------------------------------------*/
00090 
00091 extern TDirectory *gManaHistsDir;
00092 
00093 static TH1F *gAdcSumHist;
00094 
00095 /*-- init routine --------------------------------------------------*/
00096 
00097 INT adc_summing_init(void)
00098 {
00099    /* book sum histo */
00100    gAdcSumHist = (TH1F *) gManaHistsDir->GetList()->FindObject("ADCSUM");
00101 
00102    if (gAdcSumHist == NULL)
00103       gAdcSumHist = new TH1F("ADCSUM", "ADC sum", 500, 0, 10000);
00104 
00105    return SUCCESS;
00106 }
00107 
00108 /*-- event routine -------------------------------------------------*/
00109 
00110 INT adc_summing(EVENT_HEADER * pheader, void *pevent)
00111 {
00112    INT i, j, n_adc;
00113    float *cadc;
00114    ASUM_BANK *asum;
00115 
00116    /* look for CADC bank, return if not present */
00117    n_adc = bk_locate(pevent, "CADC", &cadc);
00118    if (n_adc == 0)
00119       return 1;
00120 
00121    /* create ADC sum bank */
00122    bk_create(pevent, "ASUM", TID_STRUCT, &asum);
00123 
00124    /* sum all channels above threashold */
00125    asum->sum = 0.f;
00126    for (i = j = 0; i < n_adc; i++)
00127       if (cadc[i] > adc_summing_param.adc_threshold) {
00128          asum->sum += cadc[i];
00129          j++;
00130       }
00131 
00132    /* calculate ADC average */
00133    asum->average = j > 0 ? asum->sum / j : 0;
00134 
00135    /* fill sum histo */
00136    gAdcSumHist->Fill(asum->sum, 1);
00137 
00138    /* close calculated bank */
00139    bk_close(pevent, asum + 1);
00140 
00141    return SUCCESS;
00142 }

Midas DOC Version 1.9.3 ---- PSI Stefan Ritt ----
Contributions: Pierre-Andre Amaudruz - Suzannah Daviel - Doxygen - Peter Green - Greg Hackman - Gertjan Hofman - Paul Knowles - Rudi Meier - Glenn Moloney - Dave Morris - Konstantin Olchanski - Renee Poutissou - Andreas Suter - Piotr Adam Zolnierczuk