| 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 | // It is under construction: More information comming soon....
|
|---|
| 32 | //
|
|---|
| 33 | //
|
|---|
| 34 | // Input Containers:
|
|---|
| 35 | // MTime
|
|---|
| 36 | //
|
|---|
| 37 | // Output Containers:
|
|---|
| 38 | // MEventRate
|
|---|
| 39 | // MTimeRate [MTime] (missing)
|
|---|
| 40 | //
|
|---|
| 41 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 42 | #include "MEventRateCalc.h"
|
|---|
| 43 |
|
|---|
| 44 | #include "MParList.h"
|
|---|
| 45 |
|
|---|
| 46 | #include "MLog.h"
|
|---|
| 47 | #include "MLogManip.h"
|
|---|
| 48 |
|
|---|
| 49 | #include "MTime.h"
|
|---|
| 50 | #include "MEventRate.h"
|
|---|
| 51 |
|
|---|
| 52 | ClassImp(MEventRateCalc);
|
|---|
| 53 |
|
|---|
| 54 | using namespace std;
|
|---|
| 55 |
|
|---|
| 56 | // --------------------------------------------------------------------------
|
|---|
| 57 | //
|
|---|
| 58 | // Default constructor.
|
|---|
| 59 | //
|
|---|
| 60 | MEventRateCalc::MEventRateCalc(const char *name, const char *title)
|
|---|
| 61 | : /*fNumEvents(10000),*/ fTimes(1000)
|
|---|
| 62 | {
|
|---|
| 63 | fName = name ? name : "MEventRateCalc";
|
|---|
| 64 | fTitle = title ? title : "Calculate trigger rate";
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | // --------------------------------------------------------------------------
|
|---|
| 68 | //
|
|---|
| 69 | // The PreProcess searches for the following input containers:
|
|---|
| 70 | // ...
|
|---|
| 71 | //
|
|---|
| 72 | Int_t MEventRateCalc::PreProcess(MParList *pList)
|
|---|
| 73 | {
|
|---|
| 74 | fTime = (MTime*)pList->FindObject("MTime");
|
|---|
| 75 | if (!fTime)
|
|---|
| 76 | {
|
|---|
| 77 | *fLog << err << "MTime not found... aborting." << endl;
|
|---|
| 78 | return kFALSE;
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | fRate = (MEventRate*)pList->FindCreateObj("MEventRate");
|
|---|
| 82 | if (!fRate)
|
|---|
| 83 | return kFALSE;
|
|---|
| 84 |
|
|---|
| 85 | //fEvtNumber = 0;
|
|---|
| 86 |
|
|---|
| 87 | memset(fTimes.GetArray(), 0, sizeof(Double_t)*fTimes.GetSize());
|
|---|
| 88 |
|
|---|
| 89 | return kTRUE;
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | // --------------------------------------------------------------------------
|
|---|
| 93 | //
|
|---|
| 94 | //
|
|---|
| 95 | Int_t MEventRateCalc::Process()
|
|---|
| 96 | {
|
|---|
| 97 | const ULong_t exec = GetNumExecutions()-1;
|
|---|
| 98 |
|
|---|
| 99 | const UInt_t n = fTimes.GetSize();
|
|---|
| 100 |
|
|---|
| 101 | const UInt_t n1 = exec;
|
|---|
| 102 | const UInt_t n2 = exec>=n ? exec+1 : 0;
|
|---|
| 103 |
|
|---|
| 104 | fTimes[n1%n] = *fTime;
|
|---|
| 105 |
|
|---|
| 106 | const UInt_t cnt = n1<n2 ? n : n1-n2;
|
|---|
| 107 |
|
|---|
| 108 | const Double_t rate = (Double_t)cnt/(fTimes[n1%n]-fTimes[n2%n]);
|
|---|
| 109 |
|
|---|
| 110 | fRate->SetRate(exec>1?rate:0, cnt);
|
|---|
| 111 | fRate->SetReadyToSave();
|
|---|
| 112 |
|
|---|
| 113 | // *fLog << inf << " --- Event Rate [Hz]: " << rate << " (" << cnt << ")" << endl;
|
|---|
| 114 |
|
|---|
| 115 | return kTRUE;
|
|---|
| 116 | }
|
|---|