libatomprobe
Library for Atom Probe Tomography (APT) computation
composition.cpp
Go to the documentation of this file.
1 /* composition.cpp: Composition calculation
2  * Copyright (C) 2020 Daniel Haley
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
18 
19 #include <cstdlib>
20 
22 #include "helper/helpFuncs.h"
23 
24 namespace AtomProbe
25 {
26 using std::vector;
27 
28 //Take count information and convert it to compositional basis
29 void computeComposition(const vector<unsigned int> &countData, vector<float> &compositionData)
30 {
31  unsigned int totalCount=0;
32  for(size_t ui=0;ui<countData.size();ui++)
33  totalCount+=countData[ui];
34 
35  compositionData.resize(countData.size(),0);
36  float factor = 1.0f/totalCount;
37  for(size_t uj=0;uj<countData.size();uj++)
38  compositionData[uj] = factor*countData[uj];
39 }
40 
41 #ifdef DEBUG
42 bool testComposition()
43 {
44  vector<unsigned int> nCounts = { 3, 7, 2};
45 
46  vector<float> compData;
47  computeComposition(nCounts,compData);
48 
49  TEST_Q(TOL_EQ(compData[0] == 3.0/12.0,0.01));
50  TEST_Q(TOL_EQ(compData[1] == 7.0/12.0,0.01));
51  TEST_Q(TOL_EQ(compData[2] == 2.0/12.0,0.01));
52 
53  return true;
54 }
55 #endif
56 
57 }
58 
59 
void computeComposition(const std::vector< unsigned int > &countData, std::vector< float > &compositionData)
Definition: composition.cpp:29