-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmethods.cpp
117 lines (100 loc) · 2.17 KB
/
methods.cpp
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
107
108
109
110
111
112
113
114
115
116
117
#include "methods.h"
#include <algorithm>
#include <cmath>
void post_process::set_data(double *x)
{
data = x;
}
void post_process::set_dataSize(unsigned n)
{
data_size = n;
}
void post_process::set_nbins(unsigned n)
{
nbins = n;
}
void post_process::set_pCharge(double x)
{
pCharge = x;
}
double *post_process::get_data()
{
return data;
}
unsigned int post_process::get_dataSize()
{
return data_size;
}
unsigned int post_process::get_nbins()
{
return nbins;
}
double post_process::get_pCharge()
{
return pCharge;
}
double post_process::get_binWidth()
{
return bin_width;
}
void post_process::histc()
{
//sort data by default compare function (i<j)
std::sort(data, data+data_size);
data_max = data[data_size-1];
data_min = data[0];
bin_width = (data_max-data_min)/(double)nbins;
double *count_bins = new double [nbins];
double *x1_bins = new double [nbins];
double *x2_bins = new double [nbins];
double level_bins_low, level_bins_up;
level_bins_low = data_min;
unsigned int i = 0, j = 0, count_n;
while (i < nbins)
{
count_n = 0;
level_bins_up = level_bins_low + bin_width;
while (j < data_size && data[j] < level_bins_up){count_n++;++j;}
count_bins[i] = count_n;
x1_bins [i] = level_bins_low;
x2_bins [i] = level_bins_up;
level_bins_low = level_bins_up;
++i;
}
histc_data_y = count_bins;
histc_data_x1 = x1_bins;
histc_data_x2 = x2_bins;
}
double *post_process::get_histc_x1()
{
return histc_data_x1;
}
double *post_process::get_histc_x2()
{
return histc_data_x2;
}
double *post_process::get_histc_y()
{
return histc_data_y;
}
double post_process::get_peakCurrent()
{
histc(); // histc data, store histc data in histc_data_xy
double peak_current = 0, current_i;
for(unsigned int i = 0;i< nbins; i++)
{
current_i = histc_data_y[i]*pCharge/data_size/bin_width;
if(current_i > peak_current)peak_current = current_i;
}
return peak_current;
}
double post_process::get_bunching(int n, double wavelength) // calculate b[n]
{
double sum_r =0, sum_i = 0, nck = n*C0*2*PI/wavelength;
for(unsigned int i = 0;i < data_size; i++)
{
sum_r += cos(nck*data[i]);
sum_i += sin(nck*data[i]);
}
return sqrt(sum_r*sum_r+sum_i*sum_i)/data_size;
}