-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEvent.cc
106 lines (91 loc) · 1.53 KB
/
Event.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "Event.hh"
#include <gsl/gsl_randist.h>
Event::Event(ShapingCurve *s, gsl_rng *r, double noise)
{
noiseLevel = noise;
rng = r;
shape = s;
numHits = 0;
}
Event::~Event()
{
}
void Event::addHit(double time, double height)
{
times[numHits] = time;
heights[numHits] = height;
numHits++;
}
double Event::getSignal(double time)
{
double signal = 0;
int i;
for (i=0; i<numHits; i++)
{
signal += heights[i]*shape->getHeight(time-times[i]);
}
signal += gsl_ran_gaussian(rng,noiseLevel);
return signal;
}
double Event::Evaluate(double *x, double *p)
{
double signal = 0;
int i;
for (i=0; i<numHits; i++)
{
signal += heights[i]*shape->getHeight(x[0]-times[i]);
}
return signal;
}
int Event::getNumHits()
{
return numHits;
}
void Event::clear()
{
numHits = 0;
}
void Event::getTimes(double *t)
{
int i;
for (i=0;i<numHits;i++)
t[i] = times[i];
}
void Event::getHeights(double *h)
{
int i;
for (i=0;i<numHits;i++)
h[i] = heights[i];
}
void Event::sortHits()
{
int i,mark,min;
double tmp_t, tmp_a;
for (mark=0; mark<numHits; mark++)
{
min = mark;
for (i=min+1;i<numHits;i++)
if (times[i]<times[min]) min=i;
if (min!=mark)
{
tmp_t = times[min];
tmp_a = heights[min];
times[min] = times[mark];
heights[min] = heights[mark];
times[mark] = tmp_t;
heights[mark] = tmp_a;
}
}
}
void Event::print()
{
int i;
printf("Times:\t\t");
for (i=0;i<numHits;i++)
printf("%lf\t",times[i]);
printf("\n");
printf("Heights:\t");
for (i=0;i<numHits;i++)
printf("%lf\t",heights[i]);
printf("\n");
}