AlcapDAQ  1
ucb_common.h
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <math.h>
5 #include "midas.h"
6 #include "Mql.h"
7 #include "MqlArray.h"
8 
9 // ###############################################################
10 
11 // MuSC Constants
12 static const int kMuSCBookendWidth = 40500; // ns
13 static const int k25usPP = 25000; // ns
14 static const int k35usPP = 35000; // ns
15 static const int k40usPP = 40000; // ns
16 // MuPC1 Constants
17 static const int kMuPC1XClusterMaxGap = 2;
18 static const int kMuPC1XClusterInterval = 260; // ns
19 static const int kMuPC1XSparkSizeCutoff = 21;
20 static const int kMuPC1YClusterMaxGap = 2;
21 static const int kMuPC1YClusterInterval = 260; // ns
22 static const int kMuPC1YSparkSizeCutoff = 21;
23 // TPC Constants
24 static const int kTPCFirstAmpAnode = 5;
25 static const int kTPCLastAmpAnode = 73;
26 static const int kTPCAnodeFlag = 1;
27 static const int kTPCStripFlag = 2;
28 static const double kTPCXDimension = 140.0; // mm
29 static const double kTPCYDimension = 120.0; // mm
30 static const double kTPCZDimension = 300.0; // mm
31 static const double kTPCXOffset = 0.0; // mm
32 static const double kTPCYOffset = -2.0; // mm
33 static const double kTPCZOffset = 8.5; // mm
34 static const double kTPCMWPCOffset = 375.0; // ns
35 static const double kTPCMaxDriftTime = 22420.0; // ns
36 static const double kTPCSVDriftInterval = (kTPCMaxDriftTime-kTPCMWPCOffset); // ns
37 // TPC Segment Search Definitions
38 static const int kSegMaxNumClusters = 5;
39 static const int kSegMinClustSep = 2;
40 static const int kSegMaxNumEndpts = 5;
41 static const int kSegUpFlag = 1;
42 static const int kSegDownFlag = -1;
43 // ePC1 Constants
44 static const double kePC1ActiveLength = 580; // mm
45 static const int kePC1InnerStripClusterMaxGap = 2;
46 static const int kePC1InnerStripClusterMaxSize = 11;
47 static const int kePC1InnerStripADInterval1 = 245; // ns
48 static const int kePC1InnerStripClusterTInterval1 = 240; // ns
49 static const int kePC1InnerStripADInterval2 = 1000; // ns
50 static const int kePC1InnerStripClusterTInterval2 = 300; // ns
51 static const int kePC1InnerStripSparkSizeCutoff = 90;
52 static const double kePC1InnerStripDiameter = 376; // mm
53 static const double kePC1InnerStripCircum = (M_PI * kePC1InnerStripDiameter); // mm
54 static const double kePC1InnerStripPhiOffset = -0.048; // rad
55 static const double kePC1InnerStripScrew = 46.194; // degrees
56 static const double kePC1InnerStripTanScrew = 1.0426;
57 static const int kePC1AnodeClusterMaxGap = 1;
58 static const int kePC1AnodeClusterMaxSize = 10;
59 static const int kePC1AnodeADInterval1 = 215; // ns
60 static const int kePC1AnodeClusterTInterval1 = 210; // ns
61 static const int kePC1AnodeADInterval2 = 900; // ns
62 static const int kePC1AnodeClusterTInterval2 = 300; // ns
63 static const int kePC1AnodeSparkSizeCutoff = 110;
64 static const double kePC1AnodeDiameter = 384; // mm
65 static const double kePC1AnodeAbsPhiOffset = -1.411; // rad
66 static const int kePC1OuterStripClusterMaxGap = 2;
67 static const int kePC1OuterStripClusterMaxSize = 11;
68 static const int kePC1OuterStripADInterval1 = 215; // ns
69 static const int kePC1OuterStripClusterTInterval1 = 210; // ns
70 static const int kePC1OuterStripADInterval2 = 1000; // ns
71 static const int kePC1OuterStripClusterTInterval2 = 300; // ns
72 static const int kePC1OuterStripSparkSizeCutoff = 90;
73 static const double kePC1OuterStripDiameter = 392; // mm
74 static const double kePC1OuterStripCircum = (M_PI * kePC1OuterStripDiameter); // mm
75 static const double kePC1OuterStripPhiOffset = -0.171; // rad
76 static const double kePC1OuterStripScrew = 43.811; // degrees
77 static const double kePC1OuterStripTanScrew = 0.9593;
78 static const double kePC1HardcutLowZLimit = -300; // mm
79 static const double kePC1HardcutHighZLimit = 300; // mm
80 // ePC2 Constants
81 static const double kePC2ActiveLength = 800; // mm
82 static const int kePC2InnerStripClusterMaxGap = 1;
83 static const int kePC2InnerStripClusterMaxSize = 10;
84 static const int kePC2InnerStripADInterval1 = 245; // ns
85 static const int kePC2InnerStripClusterTInterval1 = 240; // ns
86 static const int kePC2InnerStripADInterval2 = 1000; // ns
87 static const int kePC2InnerStripClusterTInterval2 = 300; // ns
88 static const int kePC2InnerStripSparkSizeCutoff = 110;
89 static const double kePC2InnerStripDiameter = 632; // mm
90 static const double kePC2InnerStripCircum = (M_PI * kePC2InnerStripDiameter); // mm
91 static const double kePC2InnerStripPhiOffset = 0.026; // rad
92 static const double kePC2InnerStripScrew = 45.738; // degrees
93 static const double kePC2InnerStripTanScrew = 1.026;
94 static const int kePC2AnodeClusterMaxGap = 1;
95 static const int kePC2AnodeClusterMaxSize = 10;
96 static const int kePC2AnodeADInterval1 = 245; // ns
97 static const int kePC2AnodeClusterTInterval1 = 240; // ns
98 static const int kePC2AnodeADInterval2 = 1000; // ns
99 static const int kePC2AnodeClusterTInterval2 = 300; // ns
100 static const int kePC2AnodeSparkSizeCutoff = 110;
101 static const double kePC2AnodeDiameter = 640; // mm
102 static const double kePC2AnodeAbsPhiOffset = -1.501; // rad
103 static const int kePC2OuterStripClusterMaxGap = 1;
104 static const int kePC2OuterStripClusterMaxSize = 10;
105 static const int kePC2OuterStripADInterval1 = 245; // ns
106 static const int kePC2OuterStripClusterTInterval1 = 240; // ns
107 static const int kePC2OuterStripADInterval2 = 900; // ns
108 static const int kePC2OuterStripClusterTInterval2 = 300; // ns
109 static const int kePC2OuterStripSparkSizeCutoff = 110;
110 static const double kePC2OuterStripDiameter = 648; // mm
111 static const double kePC2OuterStripCircum = (M_PI * kePC2OuterStripDiameter); // mm
112 static const double kePC2OuterStripPhiOffset = -0.003; // rad
113 static const double kePC2OuterStripScrew = 44.308; // degrees
114 static const double kePC2OuterStripTanScrew = 0.976;
115 static const double kePC2HardcutLowZLimit = -410; // mm
116 static const double kePC2HardcutHighZLimit = 410; // mm
117 // eSC Constants
118 static const int keSCNumGondolas = 16;
119 static const int keSCClusterInterval = 65; // ns
120 static const int keSCSparkSizeCutoff = 55;
121 static const double keSCDiameter = 772; // mm
122 static const double keSCActiveLength = 900; // mm
123 static const double keSCAbsPhiOffset = (M_PI / 2.0); // rad
124 extern double keSCInnerTOffset[keSCNumGondolas+1];
125 extern double keSCInnerTSigma[keSCNumGondolas+1];
126 extern double keSCOuterTOffset[keSCNumGondolas+1];
127 extern double keSCOuterTSigma[keSCNumGondolas+1];
128 extern double keSCGondolaTOffset[keSCNumGondolas+1];
129 extern double keSCGondolaTSigma[keSCNumGondolas+1];
130 extern double keSCCaenCompTOffset;
131 extern double keSCCaenCompTSigma;
132 // Miscellaneous
133 static const int kSparkCutDeadtime = 50000; // ns
134 static const double kEPS = 0.001;
135 static const double kePC1eSCPhiSigma = 0.20; // rad
136 static const double kePC2eSCPhiSigma = 0.13; // rad
137 static const double PV_wall_radius = 140; // mm
138 
139 
140 // ###############################################################
141 
142 typedef struct cluster_info {
145 } cluster_info;
146 
147 typedef struct endpoint_info {
150  int row;
151 } endpoint_info;
152 
153 //typedef struct segment_elt {
154 //#include "SEGS.h"
155 //} segment_elt;
156 
157 //typedef struct track_elt {
158 //#include "TRKS.h"
159 //} track_elt;
160 
161 //typedef struct mu_track_elt {
162 //#include "MUTK.h"
163 //} mu_track_elt;
164 
165 //typedef struct impurity_capture_elt {
166 //#include "CAPT.h"
167 //} impurity_capture_elt;
168 
169 //typedef struct ePC1_spark_info_elt {
170 //#include "E1CS.h"
171 //} ePC1_spark_info_elt;
172 
173 //typedef struct ePC2_spark_info_elt {
174 //#include "E2CS.h"
175 //} ePC2_spark_info_elt;
176 
177 typedef struct XYZ {
178  double x, y, z;
179 } XYZ;
180 
181 typedef struct RPZ {
182  double r, phi, z;
183 } RPZ;
184 
185 typedef struct RPT {
186  double r, phi, theta;
187 } RPT;
188 
189 typedef struct TPCextrap {
190  double x, xprime, y, yprime, r;
191 } TPCextrap;
192 
193 typedef struct muscatter_struct {
195  double spread;
196  double impact;
197  double length;
199  double angle;
201 
202 
203 // ###############################################################
204 
205 bool hit_search_TPCstack(stack_elt *stackArray,
206  int index,
207  int THRESHCODE,
208  int ROWTYPE,
209  int row1,
210  int row2,
211  int MINROW,
212  int MAXROW);
213 void segment_search_TPCstack(stack_elt *stackArray,
214  int num_stack_elts,
215  int index,
216  int *leftmost,
217  int *rightmost,
218  int *nendpts,
219  endpoint_info *endptA,
220  int start_row,
221  int THRESHCODE,
222  int ROWTYPE,
223  int DIR,
224  int ROWS_AHEAD,
225  int STRETCH);
227  int num_stack_elts,
228  int index,
229  int *leftmost,
230  int *rightmost,
231  int *nendpts,
232  endpoint_info *endptA,
233  int start_row,
234  int THRESHCODE,
235  int ROWTYPE,
236  int DIR,
237  int ROWS_AHEAD,
238  int STRETCH,
239  int *ELcount,
240  int *EHcount);
241 XYZ fillXYZ(double x, double y, double z);
242 RPZ fillRPZ(double radius, double phi, double z);
243 RPT fillRPT(double radius, double phi, double theta);
244 XYZ convertRPZtoXYZ(RPZ RPZpoint);
245 XYZ convertRPTtoXYZ(RPT RPTpoint);
246 RPZ convertXYZtoRPZ(XYZ XYZpoint);
247 double dotproductXYZ(XYZ vector1,
248  XYZ vector2);
249 double magnitudeXYZ(XYZ vectorXYZ);
250 double ePC_anode_phi_fcn(int ePCNumber, double anode);
251 double ePC_inner_strip_z(int ePCNumber, double anode_phi, double inner_strip);
252 double ePC_outer_strip_z(int ePCNumber, double anode_phi, double outer_strip);
253 bool ePC1ePC2_PhiCoinc(double ePC1AbsPhi,
254  double ePC2AbsPhi,
255  double max_phi_diff);
256 bool ePCeSC_PhiCoinc(int ePCNumber, double ePC_phi, int eSC_gondola);
260  XYZ ePC2,
261  double x_coord,
262  double y_coord,
263  double radius);
264 bool ePC1ePC2eSC_PhiCoinc(RPZ ePC1ePC2_eSCInt, int gondola);
265 double calculate_eSC_cosmic_angle(int gondolaA, int gondolaB);
266 RPT calculate_ePC1ePC2_chord(XYZ p1, XYZ p2, XYZ p3, XYZ p4);
267 XYZ calculate_muDet_eDet_impact(double endstrip,
268  double drifttime,
269  double endanode,
270  XYZ ePC1,
271  XYZ ePC2);
272 XYZ calculate_TPC_subvolume_indices(double endstrip,
273  double drifttime,
274  double endanode,
275  int numXsubdivisions,
276  int numYsubdivisions,
277  int numZsubdivisions);
278 TPCextrap muSC_TPC_extrapolate(char *plane, double muSCTime,
279  double beginstrip, double endstrip,
280  double beginLtime, double endLtime,
281  double beginanode, double endanode);
283  double driftLtime,
284  int mustop_anode);
285 muscatter_struct search_for_muscatter_track(EVENT_HEADER *pheader,
286  void *pevent,
287  double driftLtime,
288  double driftRtime,
289  int mustop_Lindex,
290  int mustop_Rindex,
291  int mustop_anode,
292  int mustop_mostLindex,
293  int mustop_mostRindex);
295  double spread,
296  double impact,
297  double length,
298  double maxfracdistance,
299  double angle);