adccalib.c

Go to the documentation of this file.
00001 /********************************************************************\
00002 
00003   Name:         adccalib.c
00004   Created by:   Stefan Ritt
00005 
00006   Contents:     Example analyzer module for ADC calibration. Looks
00007                 for ADC0 bank, subtracts pedestals and applies gain
00008                 calibration. The resulting values are appended to 
00009                 the event as an CADC bank ("calibrated ADC"). The
00010                 pedestal values and software gains are stored in
00011                 adccalib_param structure which was defined in the ODB
00012                 and transferred to experim.h.
00013 
00014   $Log: adccalib.c,v $
00015   Revision 1.10  2004/09/23 19:22:49  midas
00016   Use new histo booking
00017 
00018   Revision 1.9  2004/01/08 08:40:08  midas
00019   Implemented standard indentation
00020 
00021   Revision 1.8  2003/04/25 14:49:46  midas
00022   Removed HBOOK code
00023 
00024   Revision 1.7  2003/04/23 15:09:47  midas
00025   Removed user branch
00026 
00027   Revision 1.6  2003/04/22 15:00:27  midas
00028   Worked on ROOT histo booking
00029 
00030   Revision 1.5  2003/04/21 04:02:13  olchansk
00031   replace MANA_LITE with HAVE_HBOOK and HAVE_ROOT
00032   implement ROOT-equivalents of the sample HBOOK code
00033   implement example of adding custom branches to the analyzer root output file
00034 
00035   Revision 1.4  2003/04/21 03:51:41  olchansk
00036   kludge misunderstanding of the ADC0 bank size.
00037 
00038   Revision 1.3  2002/05/10 05:22:47  pierre
00039   add MANA_LITE #ifdef
00040 
00041   Revision 1.2  1998/10/12 12:18:58  midas
00042   Added Log tag in header
00043 
00044 
00045 \********************************************************************/
00046 
00047 /*-- Include files -------------------------------------------------*/
00048 
00049 /* standard includes */
00050 #include <stdio.h>
00051 #include <time.h>
00052 
00053 /* midas includes */
00054 #include "midas.h"
00055 #include "experim.h"
00056 #include "analyzer.h"
00057 
00058 /* root includes */
00059 #include <TH1F.h>
00060 #include <TTree.h>
00061 
00062 /*-- Parameters ----------------------------------------------------*/
00063 
00064 ADC_CALIBRATION_PARAM adccalib_param;
00065 extern EXP_PARAM exp_param;
00066 extern RUNINFO runinfo;
00067 
00068 /*-- Module declaration --------------------------------------------*/
00069 
00070 INT adc_calib(EVENT_HEADER *, void *);
00071 INT adc_calib_init(void);
00072 INT adc_calib_bor(INT run_number);
00073 INT adc_calib_eor(INT run_number);
00074 
00075 ADC_CALIBRATION_PARAM_STR(adc_calibration_param_str);
00076 
00077 ANA_MODULE adc_calib_module = {
00078    "ADC calibration",           /* module name           */
00079    "Stefan Ritt",               /* author                */
00080    adc_calib,                   /* event routine         */
00081    adc_calib_bor,               /* BOR routine           */
00082    adc_calib_eor,               /* EOR routine           */
00083    adc_calib_init,              /* init routine          */
00084    NULL,                        /* exit routine          */
00085    &adccalib_param,             /* parameter structure   */
00086    sizeof(adccalib_param),      /* structure size        */
00087    adc_calibration_param_str,   /* initial parameters    */
00088 };
00089 
00090 /*-- module-local variables ----------------------------------------*/
00091 
00092 static TH1F *hAdcHists[N_ADC];
00093 
00094 /*-- init routine --------------------------------------------------*/
00095 
00096 #define ADC_N_BINS   500
00097 #define ADC_X_LOW      0
00098 #define ADC_X_HIGH  4000
00099 
00100 INT adc_calib_init(void)
00101 {
00102    char name[256];
00103    int i;
00104 
00105    /* book CADC histos */
00106 
00107    for (i = 0; i < N_ADC; i++) {
00108       char title[256];
00109 
00110       sprintf(name, "CADC%02d", i);
00111       sprintf(title, "ADC %d", i);
00112 
00113       hAdcHists[i] = H1_BOOK(name, title, ADC_N_BINS, ADC_X_LOW, ADC_X_HIGH);
00114    }
00115 
00116    return SUCCESS;
00117 }
00118 
00119 /*-- BOR routine ---------------------------------------------------*/
00120 
00121 INT adc_calib_bor(INT run_number)
00122 {
00123    return SUCCESS;
00124 }
00125 
00126 /*-- eor routine ---------------------------------------------------*/
00127 
00128 INT adc_calib_eor(INT run_number)
00129 {
00130    return SUCCESS;
00131 }
00132 
00133 /*-- event routine -------------------------------------------------*/
00134 
00135 INT adc_calib(EVENT_HEADER * pheader, void *pevent)
00136 {
00137    INT i;
00138    WORD *pdata;
00139    float *cadc;
00140 
00141    /* look for ADC0 bank, return if not present */
00142    if (!bk_locate(pevent, "ADC0", &pdata))
00143       return 1;
00144 
00145    /* create calibrated ADC bank */
00146    bk_create(pevent, "CADC", TID_FLOAT, &cadc);
00147 
00148    /* zero cadc bank */
00149    for (i = 0; i < N_ADC; i++)
00150       cadc[i] = 0.f;
00151 
00152    /* subtract pedestal */
00153    for (i = 0; i < N_ADC; i++)
00154       cadc[i] = (float) ((double) pdata[i] - adccalib_param.pedestal[i] + 0.5);
00155 
00156    /* apply software gain calibration */
00157    for (i = 0; i < N_ADC; i++)
00158       cadc[i] *= adccalib_param.software_gain[i];
00159 
00160    /* fill ADC histos if above threshold */
00161    for (i = 0; i < N_ADC; i++)
00162       if (cadc[i] > (float) adccalib_param.histo_threshold)
00163          hAdcHists[i]->Fill(cadc[i], 1);
00164 
00165    /* close calculated bank */
00166    bk_close(pevent, cadc + N_ADC);
00167 
00168    return SUCCESS;
00169 }

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 - John M O'Donnell - Konstantin Olchanski - Renee Poutissou - Andreas Suter - Jan M.Wouters - Piotr Adam Zolnierczuk