source: trunk/MagicSoft/Mars/manalysis/MEventRateCalc.cc@ 4733

Last change on this file since 4733 was 2917, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 3.8 KB
Line 
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-2004
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//
34// rate = Number of events / time in which the events were recorded
35// r = N / t
36// s = t / N = 1 / r mean time interval between consecutive events
37//
38// for an exponential distribution of the time differences d between
39// consecutive events:
40//
41// s = <d>
42// sigma(d) = <d> = s
43// delta(s) = sigma(d) /sqrt(N) = s / sqrt(N)
44// delta(s) / s = 1 / sqrt(N)
45//
46// delta(r) / r = delta(s) / s = 1 / sqrt(N)
47//
48//
49// Input Containers:
50// MTime
51//
52// Output Containers:
53// MEventRate
54// MTimeRate [MTime] (missing)
55//
56// FIXME: For convinience we could implement a mode which always takes
57// n events to calculate the event rate and sets the corresponding
58// time. This mode could be used to UPADTE files with the event
59// rate.
60//
61//////////////////////////////////////////////////////////////////////////////
62#include "MEventRateCalc.h"
63
64#include "MParList.h"
65
66#include "MLog.h"
67#include "MLogManip.h"
68
69#include "MTime.h"
70#include "MEventRate.h"
71
72ClassImp(MEventRateCalc);
73
74using namespace std;
75
76// --------------------------------------------------------------------------
77//
78// Default constructor.
79//
80MEventRateCalc::MEventRateCalc(const char *name, const char *title)
81 : fTimes(1000)
82{
83 fName = name ? name : "MEventRateCalc";
84 fTitle = title ? title : "Calculate trigger rate";
85}
86
87// --------------------------------------------------------------------------
88//
89// The PreProcess searches for the following input containers:
90// MTime
91//
92// The PreProcess searches for the following input containers:
93// MEventRate
94//
95// Reset all times in the buffer
96//
97Int_t MEventRateCalc::PreProcess(MParList *pList)
98{
99 fTime = (MTime*)pList->FindObject("MTime");
100 if (!fTime)
101 {
102 *fLog << err << "MTime not found... aborting." << endl;
103 return kFALSE;
104 }
105
106 fRate = (MEventRate*)pList->FindCreateObj("MEventRate");
107 if (!fRate)
108 return kFALSE;
109
110 fTimes.Reset();
111
112 return kTRUE;
113}
114
115// --------------------------------------------------------------------------
116//
117// Calculate the events rate as (t1-t0)/n while t1 is the n-th event after
118// t0. If there are not yet enough events in the buffer n is the number
119// of available events. Otherwise the number setup in SetNumEvents.
120//
121Int_t MEventRateCalc::Process()
122{
123 const ULong_t exec = GetNumExecutions()-1;
124
125 const UInt_t n = fTimes.GetSize();
126
127 const UInt_t n1 = exec;
128 const UInt_t n2 = exec>=n ? exec+1 : 0;
129
130 fTimes[n1%n] = *fTime;
131
132 const UInt_t cnt = n1<n2 ? n : n1-n2;
133
134 const Double_t rate = (Double_t)cnt/(fTimes[n1%n]-fTimes[n2%n]);
135
136 fRate->SetRate(exec>1?rate:0, cnt);
137 fRate->SetReadyToSave();
138
139 return kTRUE;
140}
Note: See TracBrowser for help on using the repository browser.