| 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 TriggerTimeOver100 = 0.; //this will be the time in sec the Trigger
|
|---|
| 38 | double TriggerTimeOver125 = 0.; //is above 100Hz,125Hz,...
|
|---|
| 39 | double TriggerTimeOver150 = 0.;
|
|---|
| 40 | double TriggerTimeOver175 = 0.;
|
|---|
| 41 |
|
|---|
| 42 | double SumRate = 0.; //for calculating the sqrt(var) of the trigger rate
|
|---|
| 43 | double SumRate2 = 0.; //same
|
|---|
| 44 | double TriggerRateRms = 0.;
|
|---|
| 45 | int ratecounter = 0;
|
|---|
| 46 |
|
|---|
| 47 | //loop over all rows in slow-file
|
|---|
| 48 | while (file.GetNextRow())
|
|---|
| 49 | {
|
|---|
| 50 | //add the offset, as the data is saved with the offset subtracted
|
|---|
| 51 | time += offset;
|
|---|
| 52 |
|
|---|
| 53 | //if the end of the run is reached, break
|
|---|
| 54 | if (time>end)
|
|---|
| 55 | break;
|
|---|
| 56 |
|
|---|
| 57 | //if the data is before the beginning of the run, continue
|
|---|
| 58 | if (time<beg)
|
|---|
| 59 | {
|
|---|
| 60 | continue;
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | //sum the data for the mean effective on
|
|---|
| 64 | SumOnTime += OnTime;
|
|---|
| 65 | SumElTime += ElTime;
|
|---|
| 66 |
|
|---|
| 67 | //sum the data for the variance of the effective on timeseries, check for zero elapsed time
|
|---|
| 68 | if (ElTime>0){
|
|---|
| 69 | SumOnEl += OnTime/ElTime;
|
|---|
| 70 | SumOnEl2 += OnTime/ElTime*OnTime/ElTime;
|
|---|
| 71 | counter++;
|
|---|
| 72 | //cout << "OnTime:" << OnTime << " # ElTime:" << ElTime << " # OnTime/ElTime:" << OnTime/ElTime << " # (OnTime/ElTime)^2:" << OnTime/ElTime*OnTime/ElTime << " # Counter:" << counter << endl;
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | //to calculate the sqrt(var) of the rate
|
|---|
| 76 | SumRate +=TriggerRate;
|
|---|
| 77 | SumRate2 +=TriggerRate*TriggerRate;
|
|---|
| 78 | ratecounter +=1;
|
|---|
| 79 |
|
|---|
| 80 | //sum the time the triggerate is over 100Hz, 125Hz,...
|
|---|
| 81 | if (TriggerRate>100.){
|
|---|
| 82 | TriggerTimeOver100 += ElTime;
|
|---|
| 83 |
|
|---|
| 84 | if (TriggerRate>125.){
|
|---|
| 85 | TriggerTimeOver125 += ElTime;
|
|---|
| 86 |
|
|---|
| 87 | if (TriggerRate>1500.){
|
|---|
| 88 | TriggerTimeOver150 += ElTime;
|
|---|
| 89 |
|
|---|
| 90 | if (TriggerRate>175.){
|
|---|
| 91 | TriggerTimeOver175 += ElTime;
|
|---|
| 92 |
|
|---|
| 93 | }
|
|---|
| 94 | }
|
|---|
| 95 | }
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | //cout << "SumOnEl2:" << SumOnEl2 << " # SumOnEl:" << SumOnEl << " # (SumOnEl2/counter-(SumOnEl/counter*SumOnEl/counter)): " << (SumOnEl2/counter-(SumOnEl/counter*SumOnEl/counter)) << endl;
|
|---|
| 101 |
|
|---|
| 102 | //calculate the return values, watch out for traps when doing math operations!
|
|---|
| 103 | EffectiveOn = SumElTime>0 ? SumOnTime/SumElTime : 0.;
|
|---|
| 104 | EffectiveOnRMS = counter>0 ? (SumOnEl2/counter-
|
|---|
| 105 | (SumOnEl/counter*SumOnEl/counter)) : 0.;
|
|---|
| 106 | EffectiveOnRMS = EffectiveOnRMS>0 ? sqrt(EffectiveOnRMS) : 0;
|
|---|
| 107 | TriggerRateRms = ratecounter>0? (SumRate2/ratecounter-
|
|---|
| 108 | (SumRate/ratecounter*SumRate/ratecounter)) : 0.;
|
|---|
| 109 | TriggerRateRms = TriggerRateRms>0 ? sqrt(TriggerRateRms) : 0;
|
|---|
| 110 |
|
|---|
| 111 | //check for crap data, which happenes sometimes...
|
|---|
| 112 | if (EffectiveOn>1.) EffectiveOn = 1.;
|
|---|
| 113 | if (EffectiveOnRMS>0.5) EffectiveOnRMS = 0.5;
|
|---|
| 114 | if (TriggerRateRms>1000) TriggerRateRms = 0.;
|
|---|
| 115 |
|
|---|
| 116 | //return fun. The style from daniela (grep the output) requires an non scientific notation,
|
|---|
| 117 | //i.e. withour exponential+ therefore set the precision to ~double with fixed width after decimal point
|
|---|
| 118 | cout << setiosflags(ios::fixed) << setprecision(12)
|
|---|
| 119 | << "result "
|
|---|
| 120 | << EffectiveOn << " "
|
|---|
| 121 | << EffectiveOnRMS << " "
|
|---|
| 122 | << SumOnTime << " "
|
|---|
| 123 | << TriggerTimeOver100 << " "
|
|---|
| 124 | << TriggerTimeOver125 << " "
|
|---|
| 125 | << TriggerTimeOver150 << " "
|
|---|
| 126 | << TriggerTimeOver175 << " "
|
|---|
| 127 | << TriggerRateRms << " "
|
|---|
| 128 | << endl;
|
|---|
| 129 | }
|
|---|