AlcapDAQ  1
common.h
Go to the documentation of this file.
1 #include "midas.h"
2 #include <math.h>
3 
4 #include "TPCcommon.h"
5 
6 // ###############################################################
7 
8 // DAQ Constants
9 static const int kMaxEvents = 31000;
10 static const int kMaxCrates = 8;
11 static const int kMaxTDC400s = 9;
12 static const int kMaxCaens = 3;
13 static const int kMaxComps = 3;
14 static const int kMaxCompFpgas = 26;
15 static const int kMaxFadcs = 4;
16 static const int kMaxFadcTriggers = 5; // max triggers per block
17 static const int kMaxCamacAdcs = 10;
18 static const int kNumCaenChannels = 128;
19 static const int kNumCompFpgaChannels = 64;
20 static const int kNumFadcChannels = 4;
21 static const int kMaxNumTPCPads = 80;
22 
23 // extern double kFadcPedestalOffset[(kMaxFadcs*kNumFadcChannels)+1];
24 // extern double kFadcPedestalSigma[(kMaxFadcs*kNumFadcChannels)+1];
25 
26 // CAEN trailing edge and rollover check parameters
27 static const int kCaenTrailingEdgeLimit = 100;
28 extern double rolloverPeriod;
29 extern double rolloverWidth;
30 static const int kNumRollovers = 3;
31 static const int kNumRolloverPairs = 3;
32 extern double rolloverTimeOffset[kNumRollovers];
33 
34 // MuPC Constants
35 static const int kMuPC1NumXWires = 24;
36 static const int kMuPC1NumYWires = 24;
37 
38 // MuSC and MuSCA Parameters
39 static const int kMuSCADInterval = 29; // ns
40 static const int kMuSCloADInterval = 29; // ns
41 static const int kMuSCAD2Interval = 120; // ns
42 static const int kMuSCAADInterval = 90; // ns
43 static const int kMuSCMismatchThreshold = 3;
44 static const int kMuSCSignalsTCoincHalfWidth = 20; // ns
45 extern double muSCCopy2TimeOffset;
46 extern double muSCATimeOffset;
47 extern double muSCGateBTimeOffset;
48 extern double muSCGateBBarTimeOffset;
49 extern double muSCRoutedTimeOffset[4];
50 
51 // ePC Constants
52 static const int kePC1NumInnerStrips = 192;
53 static const int kePC1NumAnodes = 512;
54 static const int kePC1NumOuterStrips = 192;
55 static const int kePC2NumInnerStrips = 320;
56 static const int kePC2NumAnodes = 1024;
57 static const int kePC2NumOuterStrips = 320;
58 
59 // Spark thresholds used in the "skimming" process
60 static const int kePC1AnodeSparkSizeLowCutoff = 35;
61 static const int kePC1AnodeSparkSizeHighCutoff = 490;
62 static const int kePC1IstripSparkSizeLowCutoff = 35;
63 static const int kePC1IstripSparkSizeHighCutoff = 180;
64 static const int kePC1OstripSparkSizeLowCutoff = 35;
65 static const int kePC1OstripSparkSizeHighCutoff = 180;
66 static const int kePC2AnodeSparkSizeLowCutoff = 35;
67 static const int kePC2AnodeSparkSizeHighCutoff = 990;
68 static const int kePC2IstripSparkSizeLowCutoff = 35;
69 static const int kePC2IstripSparkSizeHighCutoff = 300;
70 static const int kePC2OstripSparkSizeLowCutoff = 35;
71 static const int kePC2OstripSparkSizeHighCutoff = 300;
72 static const int keSCSparkSizeLowCutoff = 10;
73 static const int keSCSparkSizeHighCutoff = 55;
74 static const int kMuPC1XSparkSizeLowCutoff = 10;
75 static const int kMuPC1XSparkSizeHighCutoff = 24;
76 static const int kMuPC1YSparkSizeLowCutoff = 10;
77 static const int kMuPC1YSparkSizeHighCutoff = 24;
78 
79 // eSC CAEN/COMP consistency cuts
80 static const int keSCCaenOnlyCutThreshold = 10;
81 static const int keSCCompOnlyCutThreshold = 25;
82 
83 // Time intervals associated with skimming
84 static const double kSkimPP = 25000;
85 static const double kSkimInterval = 55000;
86 static const double kGeneralSkimInterval = 200000;
87 
88 // Miscellaneous
89 static const double kPi = M_PI;
90 static const double k2Pi = (2.0 * M_PI);
91 static const bool ON = 1;
92 static const bool OFF = 0;
93 
94 // ###############################################################
95 
96 typedef struct caen_word {
97  unsigned int time:20, edge:1, r2:2, start:1, channel:7, r1:1;
98 } caen_word;
99 
100 typedef union comp_word {
101  struct {
102  unsigned int time:24, fpga:6, a:1, b:1;
103  } r1;
104  unsigned char bytes[4];
105  unsigned int word;
106 } comp_word;
107 
108 typedef struct channel_hit {
109 #include "HITS.h"
110 } channel_hit;
111 
112 typedef struct caen_hit {
113 #include "CAET.h"
114 } caen_hit;
115 
116 typedef struct adc_hit {
117 #include "ADCS.h"
118 } adc_hit;
119 
120 typedef struct fadc_word {
121  unsigned char channel[4];
122 } fadc_word;
123 
124 typedef struct FADC_info {
125 #include "FDCR.h"
126 } FADC_info;
127 
128 typedef struct TPCWFD_info {
129 #include "TPCW.h"
130 } TPCWFD_info;
131 
132 //typedef struct NEUTRON_info {
133 //#include "NDET.h"
134 //} NEUTRON_info;
135 
136 typedef struct ndet_elt {
137 #include "NDET.h"
138 } ndet_elt;
139 
140 typedef struct TPC_map_elt {
141  int tdc400;
142  int word;
143  unsigned short bitmask;
144  int bitshift;
145 } TPC_map_elt;
146 
147 typedef struct tdc400_word {
148  unsigned short time;
149  union {
150  unsigned short words[3];
151  unsigned char bytes[6];
152  } bits;
153 } tdc400_word;
154 
155 typedef struct td_elt {
156  double time;
157  unsigned short word[3];
158 } td_elt;
159 
160 typedef struct thresh_bits {
161  unsigned short Aword[6]; // anode sections
162  unsigned short Sword[3]; // strip sections
163 } thresh_bits;
164 
165 typedef struct stack_elt {
166  double time;
167  bool thrbits[3];
168  thresh_bits thr[3];
169 } stack_elt;
170 
171 typedef struct tpc_spark_word {
172 #include "TSPK.h"
174 
175 typedef struct skim_elt {
176 #include "SKIM.h"
177 } skim_elt;
178 
179 
180 // ###############################################################
181 
182 bool parameter_exists(int par);
183 void print_TPCstack_interval(void *pevent, long index1, long index2);
184 void print_TPCstack_interval_by_time(void *pevent, double time1, double time2);
185 void print_TPCstack_section(void *pevent, long index);
186 void print_TPCstack_section_by_time(void *pevent, double time);
187 bool has_Ehigh_and_strip_hits(EVENT_HEADER *pheader, void *pevent, double time);
188 bool has_VH_hit(EVENT_HEADER *pheader, void *pevent, double time);