Particle Identification and Tracking
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
common_src
include
histogram2d.h
Go to the documentation of this file.
1
//Copyright 2009 Thomas A Caswell
2
//tcaswell@uchicago.edu
3
//http://jfi.uchicago.edu/~tcaswell
4
//
5
//This program is free software; you can redistribute it and/or modify
6
//it under the terms of the GNU General Public License as published by
7
//the Free Software Foundation; either version 3 of the License, or (at
8
//your option) any later version.
9
//
10
//This program is distributed in the hope that it will be useful, but
11
//WITHOUT ANY WARRANTY; without even the implied warranty of
12
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
//General Public License for more details.
14
//
15
//You should have received a copy of the GNU General Public License
16
//along with this program; if not, see <http://www.gnu.org/licenses>.
17
//
18
//Additional permission under GNU GPL version 3 section 7
19
//
20
//If you modify this Program, or any covered work, by linking or
21
//combining it with MATLAB (or a modified version of that library),
22
//containing parts covered by the terms of MATLAB User License, the
23
//licensors of this Program grant you additional permission to convey
24
//the resulting work.
25
#ifndef HIST2
26
#define HIST2
27
28
#include <vector>
29
#include <exception>
30
#include <iostream>
31
32
#include "
part_def.h
"
33
34
namespace
utilities{
35
//forward declare
36
class
Generic_wrapper_base;
37
43
class
Histogram2D
{
44
public
:
49
template
<
class
T>
50
void
add_data_point
(T in1,T in2);
51
55
std::vector<int>
get_bin_values
();
56
57
/*
58
Returns a vector of the edges in the bins, has length number_bins + 1
59
*/
60
// std::vector<double> get_bin_edges();
61
65
void
print
();
66
67
// int get_over_count(){
68
// return over_count_;
69
// }
70
71
72
// int get_under_count(){
73
// return under_count_;
74
// }
78
Histogram2D
(
int
num_bins1,
double
bottom1 ,
double
top1,
int
num_bins2,
double
bottom2 ,
double
top2);
79
88
void
output_to_wrapper
(Generic_wrapper_base * wrapper_out);
89
90
91
92
~Histogram2D
(){};
93
97
void
add_data_point
(
const
utilities::Tuple<float,2>
& in );
98
99
protected
:
103
std::vector<int>
hist_array_
;
104
105
106
107
111
int
under_count1_
;
112
116
int
over_count1_
;
117
121
int
number_bins1_
;
122
126
double
top_edge1_
;
127
131
double
bottom_edge1_
;
132
136
double
bin_width1_
;
137
138
142
int
under_count2_
;
143
147
int
over_count2_
;
148
152
int
number_bins2_
;
153
157
double
top_edge2_
;
158
162
double
bottom_edge2_
;
163
167
double
bin_width2_
;
168
private
:
169
170
171
};
172
173
template
<
class
T>
174
void
Histogram2D::add_data_point
(T in1,T in2){
175
using
std::cout;
176
using
std::endl;
177
double
tmp_in1 = (double) in1;
178
double
tmp_in2 = (double) in2;
179
if
(tmp_in1 <
bottom_edge1_
){
180
++
under_count1_
;
181
return
;
182
}
183
if
(tmp_in1>=
top_edge1_
){
184
++
over_count1_
;
185
return
;
186
}
187
if
(tmp_in2 <
bottom_edge2_
){
188
++
under_count2_
;
189
return
;
190
}
191
if
(tmp_in2>=
top_edge2_
){
192
++
over_count2_
;
193
return
;
194
}
195
196
int
bin1 =(int)((tmp_in1 -
bottom_edge1_
)/
bin_width1_
);
197
int
bin2 =(int)((tmp_in2 -
bottom_edge2_
)/
bin_width2_
);
198
199
200
// ++(*(hist_array_ptr_ + ((int)((tmp_in - bottom_edge_)/bin_width_))));
201
// cout<<in<<"\t"<<((int)((tmp_in - bottom_edge_)/bin_width_))<<endl;
202
try
203
{
204
++
hist_array_
.at(bin2*
number_bins1_
+ bin1);
205
}
206
catch
(std::exception & e)
207
{
208
cout<<e.what()<<endl;
209
cout<<tmp_in1<<
"\t"
210
<<
bottom_edge1_
<<
"\t"
211
<<
bin_width1_
<<
"\t"
<<endl;
212
cout<<tmp_in2<<
"\t"
213
<<
bottom_edge2_
<<
"\t"
214
<<
bin_width2_
<<
"\t"
<<endl;
215
216
}
217
}
218
219
220
221
222
}
223
224
#endif
Generated on Tue Sep 10 2013 17:07:21 for Particle Identification and Tracking by
1.8.4