| 1 | /* ======================================================================== *\
|
|---|
| 2 | !
|
|---|
| 3 | ! *
|
|---|
| 4 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
|---|
| 5 | ! * Software. It is distributed to you in the hope that it can be a useful
|
|---|
| 6 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
|---|
| 7 | ! * It is distributed WITHOUT ANY WARRANTY.
|
|---|
| 8 | ! *
|
|---|
| 9 | ! * Permission to use, copy, modify and distribute this software and its
|
|---|
| 10 | ! * documentation for any purpose is hereby granted without fee,
|
|---|
| 11 | ! * provided that the above copyright notice appear in all copies and
|
|---|
| 12 | ! * that both that copyright notice and this permission notice appear
|
|---|
| 13 | ! * in supporting documentation. It is provided "as is" without express
|
|---|
| 14 | ! * or implied warranty.
|
|---|
| 15 | ! *
|
|---|
| 16 | !
|
|---|
| 17 | !
|
|---|
| 18 | ! Author(s): Thomas Bretz, 11/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
|
|---|
| 19 | !
|
|---|
| 20 | ! Copyright: MAGIC Software Development, 2002-2003
|
|---|
| 21 | !
|
|---|
| 22 | !
|
|---|
| 23 | \* ======================================================================== */
|
|---|
| 24 |
|
|---|
| 25 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 26 | //
|
|---|
| 27 | // MEventRateCalc
|
|---|
| 28 | //
|
|---|
| 29 | // This task calculates the event rates from the event times and numbers.
|
|---|
| 30 | //
|
|---|
| 31 | // The algorithm is explained in Process()
|
|---|
| 32 | //
|
|---|
| 33 | // Input Containers:
|
|---|
| 34 | // MTime
|
|---|
| 35 | //
|
|---|
| 36 | // Output Containers:
|
|---|
| 37 | // MEventRate
|
|---|
| 38 | // MTimeRate [MTime] (missing)
|
|---|
| 39 | //
|
|---|
| 40 | // FIXME: For convinience we could implement a mode which always takes
|
|---|
| 41 | // n events to calculate the event rate and sets the corresponding
|
|---|
| 42 | // time. This mode could be used to UPADTE files with the event
|
|---|
| 43 | // rate.
|
|---|
| 44 | //
|
|---|
| 45 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 46 | #include "MEventRateCalc.h"
|
|---|
| 47 |
|
|---|
| 48 | #include "MParList.h"
|
|---|
| 49 |
|
|---|
| 50 | #include "MLog.h"
|
|---|
| 51 | #include "MLogManip.h"
|
|---|
| 52 |
|
|---|
| 53 | #include "MTime.h"
|
|---|
| 54 | #include "MEventRate.h"
|
|---|
| 55 |
|
|---|
| 56 | ClassImp(MEventRateCalc);
|
|---|
| 57 |
|
|---|
| 58 | using namespace std;
|
|---|
| 59 |
|
|---|
| 60 | // --------------------------------------------------------------------------
|
|---|
| 61 | //
|
|---|
| 62 | // Default constructor.
|
|---|
| 63 | //
|
|---|
| 64 | MEventRateCalc::MEventRateCalc(const char *name, const char *title)
|
|---|
| 65 | : fTimes(1000)
|
|---|
| 66 | {
|
|---|
| 67 | fName = name ? name : "MEventRateCalc";
|
|---|
| 68 | fTitle = title ? title : "Calculate trigger rate";
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | // --------------------------------------------------------------------------
|
|---|
| 72 | //
|
|---|
| 73 | // The PreProcess searches for the following input containers:
|
|---|
| 74 | // MTime
|
|---|
| 75 | //
|
|---|
| 76 | // The PreProcess searches for the following input containers:
|
|---|
| 77 | // MEventRate
|
|---|
| 78 | //
|
|---|
| 79 | // Reset all times in the buffer
|
|---|
| 80 | //
|
|---|
| 81 | Int_t MEventRateCalc::PreProcess(MParList *pList)
|
|---|
| 82 | {
|
|---|
| 83 | fTime = (MTime*)pList->FindObject("MTime");
|
|---|
| 84 | if (!fTime)
|
|---|
| 85 | {
|
|---|
| 86 | *fLog << err << "MTime not found... aborting." << endl;
|
|---|
| 87 | return kFALSE;
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | fRate = (MEventRate*)pList->FindCreateObj("MEventRate");
|
|---|
| 91 | if (!fRate)
|
|---|
| 92 | return kFALSE;
|
|---|
| 93 |
|
|---|
| 94 | memset(fTimes.GetArray(), 0, sizeof(Double_t)*fTimes.GetSize());
|
|---|
| 95 |
|
|---|
| 96 | return kTRUE;
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | // --------------------------------------------------------------------------
|
|---|
| 100 | //
|
|---|
| 101 | // Calculate the events rate as (t1-t0)/n while t1 is the n-th event after
|
|---|
| 102 | // t0. If there are not yet enough events in the buffer n is the number
|
|---|
| 103 | // of available events. Otherwise the number setup in SetNumEvents.
|
|---|
| 104 | //
|
|---|
| 105 | Int_t MEventRateCalc::Process()
|
|---|
| 106 | {
|
|---|
| 107 | const ULong_t exec = GetNumExecutions()-1;
|
|---|
| 108 |
|
|---|
| 109 | const UInt_t n = fTimes.GetSize();
|
|---|
| 110 |
|
|---|
| 111 | const UInt_t n1 = exec;
|
|---|
| 112 | const UInt_t n2 = exec>=n ? exec+1 : 0;
|
|---|
| 113 |
|
|---|
| 114 | fTimes[n1%n] = *fTime;
|
|---|
| 115 |
|
|---|
| 116 | const UInt_t cnt = n1<n2 ? n : n1-n2;
|
|---|
| 117 |
|
|---|
| 118 | const Double_t rate = (Double_t)cnt/(fTimes[n1%n]-fTimes[n2%n]);
|
|---|
| 119 |
|
|---|
| 120 | fRate->SetRate(exec>1?rate:0, cnt);
|
|---|
| 121 | fRate->SetReadyToSave();
|
|---|
| 122 |
|
|---|
| 123 | return kTRUE;
|
|---|
| 124 | }
|
|---|