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   $Id: adccalib.c 2753 2005-10-07 14:55:31Z ritt $
00015 
00016 \********************************************************************/
00017 
00018 /*-- Include files -------------------------------------------------*/
00019 
00020 /* standard includes */
00021 #include <stdio.h>
00022 #include <time.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 #include <TTree.h>
00032 
00033 /*-- Parameters ----------------------------------------------------*/
00034 
00035 ADC_CALIBRATION_PARAM adccalib_param;
00036 extern EXP_PARAM exp_param;
00037 extern RUNINFO runinfo;
00038 
00039 /*-- Module declaration --------------------------------------------*/
00040 
00041 INT adc_calib(EVENT_HEADER *, void *);
00042 INT adc_calib_init(void);
00043 INT adc_calib_bor(INT run_number);
00044 INT adc_calib_eor(INT run_number);
00045 
00046 ADC_CALIBRATION_PARAM_STR(adc_calibration_param_str);
00047 
00048 ANA_MODULE adc_calib_module = {
00049    "ADC calibration",           /* module name           */
00050    "Stefan Ritt",               /* author                */
00051    adc_calib,                   /* event routine         */
00052    adc_calib_bor,               /* BOR routine           */
00053    adc_calib_eor,               /* EOR routine           */
00054    adc_calib_init,              /* init routine          */
00055    NULL,                        /* exit routine          */
00056    &adccalib_param,             /* parameter structure   */
00057    sizeof(adccalib_param),      /* structure size        */
00058    adc_calibration_param_str,   /* initial parameters    */
00059 };
00060 
00061 /*-- module-local variables ----------------------------------------*/
00062 
00063 static TH1D *hAdcHists[N_ADC];
00064 
00065 /*-- init routine --------------------------------------------------*/
00066 
00067 #define ADC_N_BINS   500
00068 #define ADC_X_LOW      0
00069 #define ADC_X_HIGH  4000
00070 
00071 INT adc_calib_init(void)
00072 {
00073    char name[256];
00074    int i;
00075 
00076    /* book CADC histos */
00077 
00078    for (i = 0; i < N_ADC; i++) {
00079       char title[256];
00080 
00081       sprintf(name, "CADC%02d", i);
00082       sprintf(title, "ADC %d", i);
00083 
00084       hAdcHists[i] = h1_book<TH1D>(name, title, ADC_N_BINS, ADC_X_LOW, ADC_X_HIGH);
00085    }
00086 
00087    return SUCCESS;
00088 }
00089 
00090 /*-- BOR routine ---------------------------------------------------*/
00091 
00092 INT adc_calib_bor(INT run_number)
00093 {
00094    return SUCCESS;
00095 }
00096 
00097 /*-- eor routine ---------------------------------------------------*/
00098 
00099 INT adc_calib_eor(INT run_number)
00100 {
00101    return SUCCESS;
00102 }
00103 
00104 /*-- event routine -------------------------------------------------*/
00105 
00106 INT adc_calib(EVENT_HEADER * pheader, void *pevent)
00107 {
00108    INT i;
00109    WORD *pdata;
00110    float *cadc;
00111 
00112    /* look for ADC0 bank, return if not present */
00113    if (!bk_locate(pevent, "ADC0", &pdata))
00114       return 1;
00115 
00116    /* create calibrated ADC bank */
00117    bk_create(pevent, "CADC", TID_FLOAT, &cadc);
00118 
00119    /* zero cadc bank */
00120    for (i = 0; i < N_ADC; i++)
00121       cadc[i] = 0.f;
00122 
00123    /* subtract pedestal */
00124    for (i = 0; i < N_ADC; i++)
00125       cadc[i] = (float) ((double) pdata[i] - adccalib_param.pedestal[i] + 0.5);
00126 
00127    /* apply software gain calibration */
00128    for (i = 0; i < N_ADC; i++)
00129       cadc[i] *= adccalib_param.software_gain[i];
00130 
00131    /* fill ADC histos if above threshold */
00132    for (i = 0; i < N_ADC; i++)
00133       if (cadc[i] > (float) adccalib_param.histo_threshold)
00134          hAdcHists[i]->Fill(cadc[i], 1);
00135 
00136    /* close calculated bank */
00137    bk_close(pevent, cadc + N_ADC);
00138 
00139    return SUCCESS;
00140 }

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