Low-Energy Muon (LEM) Experiment  0.5.2
pileup_ana_module.cxx
Go to the documentation of this file.
1 /********************************************************************\
2 
3  Name: pileup_ana_module.c
4  Created by: Thomas Prokscha
5  Date: 05-Oct-2005
6 
7  Contents: Analyzer module for LEM pileup data
8 
9 \********************************************************************/
10 
11 /*-- Include files -------------------------------------------------*/
12 
13 /* standard includes */
14 #include <stdio.h>
15 #include <time.h>
16 #include <string.h>
17 #include <math.h>
18 
19 /* midas includes */
20 #include "midas.h"
21 #include "rmidas.h"
22 #include "v1190.h"
23 #include "experim.h"
24 #include "nemu_experim.h"
25 
26 #ifdef HAVE_HBOOK
27 #include <cfortran.h>
28 #include <hbook.h>
29 #else
30 /* root includes */
31 #include <TH1F.h>
32 #include <TH2F.h>
33 #include <TTree.h>
34 #endif
35 
36 /*-- ODB Parameters ------------------------------------------------*/
37 extern RUNINFO runinfo;
39 PILEUPANAMODULE_PARAM_STR(pileup_ana_param_str);
40 
41 /*-- Module declaration --------------------------------------------*/
42 INT pileup_init(void);
43 INT pileup_ana(EVENT_HEADER*,void*);
44 INT pileup_bor(INT run_number);
45 INT pileup_eor(INT run_number);
46 
47 
48 ANA_MODULE pileup_ana_module = {
49  "PileUpAnaModule", /* module name */
50  "Thomas Prokscha", /* author */
51  pileup_ana, /* event routine */
52  pileup_bor, /* BOR routine */
53  pileup_eor, /* EOR routine */
54  pileup_init, /* init routine */
55  NULL, /* exit routine */
56  &pileup_ana_param, /* parameter structure */
57  sizeof(pileup_ana_param), /* structure size */
58  (const char **)pileup_ana_param_str, /* initial parameters */
59 };
60 
61 /*-- other global variables ----------------------------------------*/
62 #define N_PUHIST 4
63 #ifndef HAVE_HBOOK
64 static TH1F* hPUHist[N_PUHIST];
65 //the following objects are from mana.c
66 extern TFolder *gManaHistosFolder;
67 extern TObjArray *gHistoFolderStack;
68 #endif
69 
70 /*-- INIT routine --------------------------------------------------*/
71 INT pileup_init(void)
72 {
73  extern char runname[256];
74  char title[256], name[256];
75  int nbin;
76  float xlow, xhigh;
77 
78  for (int i=0; i<N_PUHIST; i++){
79  sprintf(name, "hPileUp%02d", i);
80  sprintf(title, "%s Run %s_%04d", pileup_ana_param.histotitles.pileuptitles[i], runname, runinfo.run_number);
81  nbin = pileup_ana_param.histobinning.histonbin[i];
82  xlow = pileup_ana_param.histobinning.histoxlow[i];
83  xhigh = pileup_ana_param.histobinning.histoxup[i];
84  hPUHist[i] = H1_BOOK(name, title, nbin, xlow, xhigh);
85  }
86 
87  return SUCCESS;
88 }
89 
90 /*-- BOR routine ---------------------------------------------------*/
91 
92 INT pileup_bor(INT run_number)
93 {
94  char title[256];
95  extern char runname[256];
96 
97  for (int i=0; i<N_PUHIST; i++){
98  sprintf(title, "%s Run %s_%04d", pileup_ana_param.histotitles.pileuptitles[i], runname, run_number);
99  hPUHist[i]->SetTitle(title);
100  }
101 
102  return SUCCESS;
103 }
104 
105 /*-- EOR routine ---------------------------------------------------*/
106 
107 INT pileup_eor(INT run_number)
108 {
109  return SUCCESS;
110 }
111 
112 /*-- event routine -------------------------------------------------*/
119 INT pileup_ana(EVENT_HEADER *pheader, void *pevent)
120 {
121  INT n, ind, counter[N_TDC_CHANNELS];
122  DWORD *ptdc;
123  float tdc_data[N_TDC_CHANNELS][DATA_N_HITS], pu_time;
124  LEM_DATA *lem_data;
125 
126  /* look for TDC0 bank */
127  n = bk_locate(pevent, "TDC0", &ptdc);
128  if (n == 0 )
129  return 1;
130 
131  memset(&counter, 0x00, sizeof(counter));
132  memset(&tdc_data, 0x00, sizeof(tdc_data));
133 
134  for (int i=1; i<n; i++){ // i=0 is a control word, including the event length
135  lem_data = (LEM_DATA *) &ptdc[i];
136 
137  switch ( lem_data->channel ){
138  case TD:
139  ind = TD;
140  tdc_data[ind][counter[ind]] = (float) lem_data->data;
141  if ( counter[ind] > 0 && counter[ind] < 3 ){ //use 1st and 2nd pile up hits
142  pu_time = tdc_data[ind][counter[ind]] - tdc_data[ind][0];
143  if ( pu_time < 0) pu_time = pu_time + TDC_BIT_RANGE;
144  hPUHist[counter[ind]-1]->Fill(pu_time,1.);
145  }
146  counter[ind]++;
147  break;
148 
149  case MCP2F:
150  ind = MCP2F;
151  tdc_data[ind][counter[ind]] = (float) lem_data->data;
152  if ( counter[ind] > 0 && counter[ind] < 3 ){//use 1st and 2nd pile up hits
153  pu_time = tdc_data[ind][counter[ind]] - tdc_data[ind][0];
154  if ( pu_time < 0) pu_time = pu_time + TDC_BIT_RANGE;
155  hPUHist[counter[ind]+1]->Fill(pu_time,1.);
156  }
157  counter[ind]++;
158  break;
159 
160  default:
161  break;
162  }
163  }
164 
165  return SUCCESS;
166 }
167 /* ----------------------------------------------------------------------------*\
168  EOF pileup_ana_module.c
169 \* ----------------------------------------------------------------------------*/
WORD channel
Definition: nemu_experim.h:93
ANA_MODULE pileup_ana_module
struct PILEUPANAMODULE_PARAM::@12 histotitles
char runname[256]
Definition: analyzer.cxx:79
#define TDC_BIT_RANGE
2^19 is the bit range of the TDC in 100ps and 200ps mode
Definition: nemu_experim.h:70
struct PILEUPANAMODULE_PARAM::@13 histobinning
TObjArray * gHistoFolderStack
RUNINFO runinfo
Definition: analyzer.cxx:83
INT pileup_ana(EVENT_HEADER *, void *)
#define MCP2F
Definition: nemu_experim.h:49
#define DATA_N_HITS
max. of DATA_N_HITS in data file
Definition: nemu_experim.h:66
PILEUPANAMODULE_PARAM_STR(pileup_ana_param_str)
INT pileup_eor(INT run_number)
char pileuptitles[4][32]
Definition: experim.h:368
PILEUPANAMODULE_PARAM pileup_ana_param
TFolder * gManaHistosFolder
INT32 histonbin[4]
Definition: experim.h:371
static TH1F * hPUHist[N_PUHIST]
#define N_TDC_CHANNELS
number of TDC channels
Definition: nemu_experim.h:64
DWORD data
Definition: nemu_experim.h:92
#define TD
Definition: nemu_experim.h:17
INT pileup_bor(INT run_number)
#define N_PUHIST
float histoxlow[4]
Definition: experim.h:372
INT pileup_init(void)