source: trunk/Mars/hawc/processing/threshold.C@ 20032

Last change on this file since 20032 was 20030, checked in by tbretz, 4 years ago
Do not do any splitting of the aux data in the script files, instead add the commas in the root macros (simplification)
File size: 2.8 KB
Line 
1#include <algorithm>
2
3void threshold(const char *fname, double beg=0, double end=100000)
4{
5 fits file(fname);
6
7 //file.PrintColumns();
8 //file.PrintKeys();
9
10 Double_t time;
11 UShort_t adc;
12 UInt_t dead, run;
13 float temp;
14 UInt_t qos;
15 UInt_t counter_ch[8];
16 UInt_t counter_sum[2];
17 UShort_t dac_ch[8];
18 UShort_t dac_sum[2];
19 float dt_sec[2];
20 file.SetPtrAddress("QoS", &qos);
21 file.SetPtrAddress("Time", &time);
22 file.SetPtrAddress("counter_ch", counter_ch);
23 file.SetPtrAddress("counter_sum", counter_sum);
24 file.SetPtrAddress("dac_ch", dac_ch);
25 file.SetPtrAddress("dac_sum", dac_sum);
26 file.SetPtrAddress("dt_sec", dt_sec);
27
28 UInt_t offset = file.GetUInt("MJDREF");
29 if (beg < 30000)
30 beg+=offset;
31 if (end < 30000)
32 end+=offset;
33
34 double min_dac_ch = 65535;
35 double avg_dac_ch = 0;
36 double max_dac_ch = 0;
37
38 double dac_ch_min = 65535;
39 double dac_ch_med = 0;
40 double dac_ch_max = 0;
41
42 double min_dac_sum = 65535;
43 double max_dac_sum = 0;
44
45 double dac_sum_min = 65535;
46 double dac_sum_max = 0;
47
48 double rate_ch[8] = {0,0,0,0,0,0,0,0};
49 double rate_sum[2] = {0,0};
50
51 int count = 0;
52
53 double diff = -1;
54
55 double sum_dt = 0;
56
57
58 while (file.GetNextRow())
59 {
60 time += offset;
61
62 if (time>end)
63 break;
64
65 dac_ch_min = TMath::MinElement(8, dac_ch);
66 dac_ch_med = TMath::Median( 8, dac_ch);
67 dac_ch_max = TMath::MaxElement(8, dac_ch);
68 dac_sum_min = TMath::Min(dac_sum[0], dac_sum[1]);
69 dac_sum_max = TMath::Min(dac_sum[0], dac_sum[1]);
70
71 if (time<beg)
72 {
73 diff = beg-time;
74 continue;
75 }
76
77 avg_dac_ch += dac_ch_med;
78 count++;
79
80 min_dac_ch = TMath::Min(min_dac_ch, dac_ch_min);
81 max_dac_ch = TMath::Max(max_dac_ch, dac_ch_max);
82
83 min_dac_sum = TMath::Min(min_dac_sum, dac_sum_min);
84 max_dac_sum = TMath::Max(max_dac_sum, dac_sum_max);
85
86 for (int i=0;i<8; i++)
87 rate_ch[i] += counter_ch[i];
88 rate_sum[0] += counter_sum[0];
89 rate_sum[1] += counter_sum[1];
90
91 sum_dt += dt_sec[0];
92 }
93
94 if (count==0)
95 {
96 if (diff<5./24/3600)
97 return;
98
99 cout << "result " << dac_ch_min << ", " << dac_ch_med << ", " << dac_ch_max << ", " << dac_sum_min << ", " << dac_sum_max;
100 cout << ", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL" << endl;
101 return;
102 }
103
104 avg_dac_ch /= count;
105
106
107 cout << "result " << min_dac_ch << ", " << avg_dac_ch << ", " << max_dac_ch << ", " << min_dac_sum << ", " << max_dac_sum;
108 for (int i=0;i<8; i++)
109 cout << ", " << rate_ch[i] / sum_dt;
110 cout << ", " << rate_sum[0] / sum_dt;
111 cout << ", " << rate_sum[1] / sum_dt;
112 cout << endl;
113}
Note: See TracBrowser for help on using the repository browser.