1 | void ontime(const char *fname, double beg=0, double end=100000)
|
---|
2 | {
|
---|
3 | //open the file
|
---|
4 | fits file(fname);
|
---|
5 |
|
---|
6 | //file.PrintColumns();
|
---|
7 | //file.PrintKeys();
|
---|
8 |
|
---|
9 | //allocate variables to read data into
|
---|
10 | Double_t time;
|
---|
11 | Float_t OnTime, ElTime, TriggerRate;
|
---|
12 | file.SetPtrAddress("Time", &time);
|
---|
13 | file.SetPtrAddress("OnTime", &OnTime);
|
---|
14 | file.SetPtrAddress("ElapsedTime", &ElTime);
|
---|
15 | file.SetPtrAddress("TriggerRate", &TriggerRate);
|
---|
16 |
|
---|
17 | //some file MJDREF offset fun. Before a given day, the MJDREF was not subtracted correctly.
|
---|
18 | //Also, see the logbook for more details (there are also some broken files)
|
---|
19 | UInt_t offset = file.GetUInt("MJDREF");
|
---|
20 | if (beg < 30000)
|
---|
21 | beg+=offset;
|
---|
22 | if (end < 30000)
|
---|
23 | end+=offset;
|
---|
24 |
|
---|
25 | //variables to calculate stuff with
|
---|
26 | double SumOnTime = 0.; //Sum up the OnTime_i for later effective on calculation
|
---|
27 | double SumElTime = 0.; //sum up ElTime_i for later effective on calculation
|
---|
28 |
|
---|
29 | double SumOnEl = 0.; //Sum of the OnTime_i / ElapsedTime_i
|
---|
30 | double SumOnEl2 = 0.; //Sum of the (OnTime_i / ElapsedTime_i)^2,
|
---|
31 | //both values needed for variance of the effective on timeseries
|
---|
32 |
|
---|
33 | double EffectiveOn = 0.; //this will be the one effective on value
|
---|
34 | double EffectiveOnRMS = 0.; //this will be variance(effective on)
|
---|
35 | int counter = 0; //cnt the number of non zero ElTime datapoints
|
---|
36 |
|
---|
37 | double TriggerTimeOver125 = 0.; //this will be the time in sec the Trigger
|
---|
38 | //is above 125Hz
|
---|
39 |
|
---|
40 | //loop over all rows in slow-file
|
---|
41 | while (file.GetNextRow())
|
---|
42 | {
|
---|
43 | //add the offset, as the data is saved with the offset subtracted
|
---|
44 | time += offset;
|
---|
45 |
|
---|
46 | //if the end of the run is reached, break
|
---|
47 | if (time>end)
|
---|
48 | break;
|
---|
49 |
|
---|
50 | //if the data is before the beginning of the run, continue
|
---|
51 | if (time<beg)
|
---|
52 | {
|
---|
53 | continue;
|
---|
54 | }
|
---|
55 |
|
---|
56 | //sum the data for the mean effective on
|
---|
57 | SumOnTime += OnTime;
|
---|
58 | SumElTime += ElTime;
|
---|
59 |
|
---|
60 | //sum the data for the variance of the effective on timeseries, check for zero elapsed time
|
---|
61 | if (ElTime>0){
|
---|
62 | SumOnEl += OnTime/ElTime;
|
---|
63 | SumOnEl2 += OnTime/ElTime*OnTime/ElTime;
|
---|
64 | counter++;
|
---|
65 | //cout << "OnTime:" << OnTime << " # ElTime:" << ElTime << " # OnTime/ElTime:" << OnTime/ElTime << " # (OnTime/ElTime)^2:" << OnTime/ElTime*OnTime/ElTime << " # Counter:" << counter << endl;
|
---|
66 | }
|
---|
67 |
|
---|
68 | //sum the time the trigger is over 125Hz
|
---|
69 | if (TriggerRate>125.){
|
---|
70 | TriggerTimeOver125 += ElTime;
|
---|
71 | }
|
---|
72 |
|
---|
73 | }
|
---|
74 |
|
---|
75 | //cout << "SumOnEl2:" << SumOnEl2 << " # SumOnEl:" << SumOnEl << " # (SumOnEl2/counter-(SumOnEl/counter*SumOnEl/counter)): " << (SumOnEl2/counter-(SumOnEl/counter*SumOnEl/counter)) << endl;
|
---|
76 |
|
---|
77 | //calculate the return values, watch out for traps when doing math operations!
|
---|
78 | EffectiveOn = SumElTime>0 ? SumOnTime/SumElTime : 0.;
|
---|
79 | EffectiveOnRMS = counter>0 ? (SumOnEl2/counter-
|
---|
80 | (SumOnEl/counter*SumOnEl/counter)) : 0.;
|
---|
81 | EffectiveOnRMS = EffectiveOnRMS>0 ? sqrt(EffectiveOnRMS) : 0;
|
---|
82 |
|
---|
83 | //check for crap data, which happenes sometimes...
|
---|
84 | if (EffectiveOn>1.) EffectiveOn = 1.;
|
---|
85 | if (EffectiveOnRMS>0.5) EffectiveOnRMS = 0.5;
|
---|
86 |
|
---|
87 | //return fun. The style from daniela (grep the output) requires an non scientific notation,
|
---|
88 | //i.e. withour exponential+ therefore set the precision to ~double with fixed width after decimal point
|
---|
89 | cout << setiosflags(ios::fixed) << setprecision(12) << "result " << EffectiveOn << " " << EffectiveOnRMS << " " << SumOnTime << " " << TriggerTimeOver125 << endl;
|
---|
90 | }
|
---|