libatomprobe
Library for Atom Probe Tomography (APT) computation
correlationhist.cpp
Go to the documentation of this file.
1 /* correlationhist.cpp : Sample program to create a cross-correlation histogram
2  * Copyright (C) 2015 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  */
17 
18 //This example creates an ion cross-correlation histogram
19 // as described by Saxey et al.
20 // DOI : 10.1016/j.ultramic.2010.11.021
21 
22 
23 #include <iostream>
24 
25 #include "atomprobe/atomprobe.h"
26 
27 using namespace std;
28 using namespace AtomProbe;
29 
30 
31 void dumpHistogram(std::vector<std::vector< unsigned int> > &hist, float step)
32 {
33 
34  //write the mass headings
35  for(unsigned int ui=0;ui<hist.size();ui++)
36  {
37  cout << step*ui << "\t";
38 
39  for(unsigned int uj=0;uj<hist.size();uj++)
40  {
41  cout << hist[ui][uj] << "\t";
42  }
43 
44  cout << endl;
45  }
46 }
47 
48 int main(int argc, char *argv[])
49 {
50  //Check for correct program usage
51  if(argc != 3)
52  {
53  //print error message, and exit
54  cerr << "USAGE : " << argv[0] << " EPOSFILE MASS_STEP" << endl;
55  return 1;
56  }
57 
58  //Get the user-specified histogram step size
59  float stepSize;
60  if(stream_cast(stepSize,argv[2]))
61  {
62  cerr << "Unable to understand stepsize :" << argv[2] << endl;
63  return 1;
64  }
65 
66  if(stepSize <=0)
67  {
68  cerr << "Stepsize must be nonzero and positive " << endl;
69  return 2;
70  }
71 
72  //Load the file
73  std::string filename = argv[1];
74  cerr << "Processing file :" << filename << endl;
75 
76  vector<vector<unsigned int> > histogram;
77  unsigned int offset=0;
78  unsigned int entriesLeft;
79  const float END_MASS=300;
80 
81  ProgressBar pb;
82  pb.setLength(50);
83  pb.init();
84 
85  while(true)
86  {
87 
88  const unsigned int CHUNK_SIZE=1e4;
89  vector<EPOS_ENTRY> eposIons;
90  unsigned int errCode;
91  if((errCode=chunkLoadEposFile(eposIons,filename.c_str(),CHUNK_SIZE,
92  offset,entriesLeft)))
93  {
94  pb.finish();
95  cerr << "Unable to load file :" << filename << endl;
96  cerr << " reason :" << errCode << endl;
97  return 2;
98  }
99 
100  offset++;
101 
102  //Update progress
103  pb.update(100.0f*(float)offset/(float)(offset+entriesLeft/CHUNK_SIZE));
104 
105  if(!entriesLeft)
106  break;
107 
108 
110  (eposIons,histogram,stepSize,END_MASS))
111  {
112  cerr << "Correlation histogram generation failed. Are ions sequenced correctly??" << endl;
113  return 2;
114 
115  }
116  }
117 
118 
119 
120 
121  dumpHistogram(histogram,stepSize);
122 
123 }
124 
125 
126 
int main(int argc, char *argv[])
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
STL namespace.
void finish()
Finalise the progress bar. It is not necessary for the progress to be set to 100%, this is done for you.
Definition: progress.cpp:52
void init()
Draw the initial progress bar.
Definition: progress.cpp:35
void dumpHistogram(std::vector< std::vector< unsigned int > > &hist, float step)
void setLength(unsigned int l)
Set the number of markers in the progress bar.
Definition: progress.h:40
bool stream_cast(T1 &result, const T2 &obj)
Template function to cast and object to another by the stringstream.
Definition: stringFuncs.h:32
void update(unsigned int newProgress)
Draw the progress bar as needed, using the given progress value [0,100].
Definition: progress.cpp:58
size_t chunkLoadEposFile(std::vector< EPOS_ENTRY > &outData, const char *filename, unsigned int chunkSize, unsigned int chunkOffset, unsigned int &nEntriesLeft)
Load an "EPOS" file, with a maximum chunk size.
Definition: dataFiles.cpp:765