source: branches/MarsISDCBranchBasedOn17887/fact/processing/drstemp.C@ 18477

Last change on this file since 18477 was 17145, checked in by tbretz, 11 years ago
The macro can now handle files with 82 entries in the 'temp' column as well as 160.
File size: 3.3 KB
Line 
1void drstemp82(fits &file, double beg, double end)
2{
3 UInt_t offset = file.GetUInt("MJDREF");
4 if (beg < 30000)
5 beg+=offset;
6 if (end < 30000)
7 end+=offset;
8
9 double time;
10 file.SetPtrAddress("Time", &time);
11
12 float *temp = file.SetPtrAddress("temp");
13
14 double avgmin = 0;
15 double avgmax = 0;
16 double rmsmin = 0;
17 double rmsmax = 0;
18
19 int cnt = 0;
20
21 double lastavgmin = -1;
22 double lastavgmax = -1;
23 double lastrmsmin = -1;
24 double lastrmsmax = -1;
25
26 double diff = -1;
27
28 while (file.GetNextRow())
29 {
30 time += offset;
31
32 if (time>end)
33 break;
34
35 double mn = 0;
36 double mx = 0;
37 double rn = 0;
38 double rx = 0;
39 for (int i=1; i<=40; i++)
40 {
41 mn += temp[i];
42 rn += temp[i]*temp[i];
43
44 mx += temp[i+41];
45 rx += temp[i+41]*temp[i+41];
46 }
47 mn /= 40;
48 mx /= 40;
49 rn /= 40;
50 rx /= 40;
51
52 if (time<beg)
53 {
54 lastavgmin = mn;
55 lastavgmax = mx;
56 lastrmsmin = sqrt(rn-mn*mn);
57 lastrmsmax = sqrt(rx-mx*mx);
58 diff = beg-time;
59 continue;
60 }
61
62 avgmin += mn;
63 avgmax += mx;
64
65 rmsmin += sqrt(rn-mn*mn);
66 rmsmax += sqrt(rx-mx*mx);
67
68 cnt ++;
69 }
70
71 if (cnt==0)
72 {
73 if (diff<5./24/3600)
74 return;
75
76 cout << "result " << lastavgmin << " " << lastavgmax << " " << lastrmsmin << " " << lastrmsmax << endl;
77 return;
78 }
79
80 avgmin /= cnt;
81 avgmax /= cnt;
82 rmsmin /= cnt;
83 rmsmax /= cnt;
84
85 cout << "result " << avgmin << " " << avgmax << " " << rmsmin << " " << rmsmax << endl;
86}
87
88void drstemp160(fits &file, double beg, double end)
89{
90 UInt_t offset = file.GetUInt("MJDREF");
91 if (beg < 30000)
92 beg+=offset;
93 if (end < 30000)
94 end+=offset;
95
96 double time;
97 file.SetPtrAddress("Time", &time);
98
99 float *temp = file.SetPtrAddress("temp");
100
101 double avg = 0;
102 double rms = 0;
103
104 int cnt = 0;
105
106 double lastavg = -1;
107 double lastrms = -1;
108
109 double diff = -1;
110
111 while (file.GetNextRow())
112 {
113 time += offset;
114
115 if (time>end)
116 break;
117
118 double mn = 0;
119 double rn = 0;
120 for (int i=0; i<=160; i++)
121 {
122 mn += temp[i];
123 rn += temp[i]*temp[i];
124 }
125 mn /= 160;
126 rn /= 160;
127
128 if (time<beg)
129 {
130 lastavg = mn;
131 lastrms = sqrt(rn-mn*mn);
132 diff = beg-time;
133 continue;
134 }
135
136 avg += mn;
137 rms += sqrt(rn-mn*mn);
138
139 cnt ++;
140 }
141
142 if (cnt==0)
143 {
144 if (diff<5./24/3600)
145 return;
146
147 cout << "result " << lastavg << " " << lastavg << " " << lastrms << " " << lastrms << endl;
148 return;
149 }
150
151 avg /= cnt;
152 rms /= cnt;
153
154 cout << "result " << avg << " " << avg << " " << rms << " " << rms << endl;
155}
156
157void drstemp(const char *fname, double beg=0, double end=100000)
158{
159 fits file(fname);
160
161 //file.PrintColumns();
162 //file.PrintKeys();
163
164 float temp[160];
165 if (file.SetPtrAddress("temp", temp, 82))
166 {
167 drstemp82(file, beg, end);
168 return;
169 }
170
171 file.SetPtrAddress("temp", temp, 160);
172 drstemp160(file, beg, end);
173}
Note: See TracBrowser for help on using the repository browser.