libatomprobe
Library for Atom Probe Tomography (APT) computation
histogram.h
Go to the documentation of this file.
1 /*
2  * histogram.h : atom probe data histogramming header
3  * Copyright (C) 2015 Daniel Haley
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
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU 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 
19 #ifndef ATOMPROBE_HISTOGRAM_H
20 #define ATOMPROBE_HISTOGRAM_H
21 #include <vector>
22 
25 
26 #include <gsl/gsl_histogram.h>
27 #include <limits>
28 
29 namespace AtomProbe {
30 
32 // be in the correct ordering, usually as-loaded from file, (ie hitMultiplicity must be set correctly).
48 bool correlationHistogram(const std::vector<EPOS_ENTRY> &eposIons,
49  std::vector<std::vector<unsigned int> > &histogram,float stepMass,
50  float endMass, bool lowerTriangular=false);
51 
53 // using an incomplete vector of EPOS entries. Note that EPOS entries
54 // that lead in with a zero deltapulse will be ignored.
68 bool accumulateCorrelationHistogram(const std::vector<EPOS_ENTRY> &eposIons,
69  std::vector<std::vector<unsigned int> > &histogram, float stepMass,
70  float endMass, bool lowerTriangular=true);
71 
74 template<class T>
75 void linearHistogram(const std::vector<T> &data, T start,
76  T end, T step, std::vector<T> &histVals)
77 {
78  ASSERT(start < end);
79  ASSERT(step > std::numeric_limits<T>::epsilon());
80 
81  gsl_histogram *h = gsl_histogram_alloc((end-start)/step);
82  gsl_histogram_set_ranges_uniform(h,start,end);
83 
84  for(size_t ui=0; ui<data.size();ui++)
85  gsl_histogram_increment(h,data[ui]);
86 
87  //Copy out data
88  histVals.resize(h->n);
89 #pragma omp parallel for
90  for(size_t ui=0;ui<h->n; ui++)
91  histVals[ui]=h->bin[ui];
92 
93  gsl_histogram_free(h);
94 }
95 
96 }
97 
98 #endif
bool accumulateCorrelationHistogram(const std::vector< EPOS_ENTRY > &eposIons, std::vector< std::vector< unsigned int > > &histogram, float stepMass, float endMass, bool lowerTriangular=true)
Increments a correlation histogram, as per correlationHistogram,.
Definition: histogram.cpp:119
void linearHistogram(const std::vector< T > &data, T start, T end, T step, std::vector< T > &histVals)
Definition: histogram.h:75
#define ASSERT(f)
bool correlationHistogram(const std::vector< EPOS_ENTRY > &eposIons, std::vector< std::vector< unsigned int > > &histogram, float stepMass, float endMass, bool lowerTriangular=false)
Generates an ion "correlation histogram" from a vector of EPOS ions. The input vector MUST ...
Definition: histogram.cpp:85