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.9  2004/01/08 08:40:08  midas
00016   Implemented standard indentation
00017 
00018   Revision 1.8  2003/04/25 14:49:46  midas
00019   Removed HBOOK code
00020 
00021   Revision 1.7  2003/04/23 15:09:47  midas
00022   Removed user branch
00023 
00024   Revision 1.6  2003/04/22 15:00:27  midas
00025   Worked on ROOT histo booking
00026 
00027   Revision 1.5  2003/04/21 04:02:13  olchansk
00028   replace MANA_LITE with HAVE_HBOOK and HAVE_ROOT
00029   implement ROOT-equivalents of the sample HBOOK code
00030   implement example of adding custom branches to the analyzer root output file
00031 
00032   Revision 1.4  2003/04/21 03:51:41  olchansk
00033   kludge misunderstanding of the ADC0 bank size.
00034 
00035   Revision 1.3  2002/05/10 05:22:47  pierre
00036   add MANA_LITE #ifdef
00037 
00038   Revision 1.2  1998/10/12 12:18:58  midas
00039   Added Log tag in header
00040 
00041 
00042 \********************************************************************/
00043 
00044 /*-- Include files -------------------------------------------------*/
00045 
00046 /* standard includes */
00047 #include <stdio.h>
00048 #include <time.h>
00049 
00050 /* midas includes */
00051 #include "midas.h"
00052 #include "experim.h"
00053 #include "analyzer.h"
00054 
00055 /* root includes */
00056 #include <TH1F.h>
00057 #include <TTree.h>
00058 #include <TDirectory.h>
00059 
00060 /*-- Parameters ----------------------------------------------------*/
00061 
00062 ADC_CALIBRATION_PARAM adccalib_param;
00063 extern EXP_PARAM exp_param;
00064 extern RUNINFO runinfo;
00065 
00066 /*-- Module declaration --------------------------------------------*/
00067 
00068 INT adc_calib(EVENT_HEADER *, void *);
00069 INT adc_calib_init(void);
00070 INT adc_calib_bor(INT run_number);
00071 INT adc_calib_eor(INT run_number);
00072 
00073 ADC_CALIBRATION_PARAM_STR(adc_calibration_param_str);
00074 
00075 ANA_MODULE adc_calib_module = {
00076    "ADC calibration",           /* module name           */
00077    "Stefan Ritt",               /* author                */
00078    adc_calib,                   /* event routine         */
00079    adc_calib_bor,               /* BOR routine           */
00080    adc_calib_eor,               /* EOR routine           */
00081    adc_calib_init,              /* init routine          */
00082    NULL,                        /* exit routine          */
00083    &adccalib_param,             /* parameter structure   */
00084    sizeof(adccalib_param),      /* structure size        */
00085    adc_calibration_param_str,   /* initial parameters    */
00086 };
00087 
00088 /*-- module-local variables ----------------------------------------*/
00089 
00090 extern TDirectory *gManaHistsDir;
00091 
00092 static TH1F *gAdcHists[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       gAdcHists[i] = (TH1F *) gManaHistsDir->GetList()->FindObject(name);
00114 
00115       if (gAdcHists[i] == NULL)
00116          gAdcHists[i] = new TH1F(name, title, ADC_N_BINS, ADC_X_LOW, ADC_X_HIGH);
00117    }
00118 
00119    return SUCCESS;
00120 }
00121 
00122 /*-- BOR routine ---------------------------------------------------*/
00123 
00124 INT adc_calib_bor(INT run_number)
00125 {
00126    return SUCCESS;
00127 }
00128 
00129 /*-- eor routine ---------------------------------------------------*/
00130 
00131 INT adc_calib_eor(INT run_number)
00132 {
00133    return SUCCESS;
00134 }
00135 
00136 /*-- event routine -------------------------------------------------*/
00137 
00138 INT adc_calib(EVENT_HEADER * pheader, void *pevent)
00139 {
00140    INT i;
00141    WORD *pdata;
00142    float *cadc;
00143 
00144    /* look for ADC0 bank, return if not present */
00145    if (!bk_locate(pevent, "ADC0", &pdata))
00146       return 1;
00147 
00148    /* create calibrated ADC bank */
00149    bk_create(pevent, "CADC", TID_FLOAT, &cadc);
00150 
00151    /* zero cadc bank */
00152    for (i = 0; i < N_ADC; i++)
00153       cadc[i] = 0.f;
00154 
00155    /* subtract pedestal */
00156    for (i = 0; i < N_ADC; i++)
00157       cadc[i] = (float) ((double) pdata[i] - adccalib_param.pedestal[i] + 0.5);
00158 
00159    /* apply software gain calibration */
00160    for (i = 0; i < N_ADC; i++)
00161       cadc[i] *= adccalib_param.software_gain[i];
00162 
00163    /* fill ADC histos if above threshold */
00164    for (i = 0; i < N_ADC; i++)
00165       if (cadc[i] > (float) adccalib_param.histo_threshold)
00166          gAdcHists[i]->Fill(cadc[i], 1);
00167 
00168    /* close calculated bank */
00169    bk_close(pevent, cadc + N_ADC);
00170 
00171    return SUCCESS;
00172 }

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