1 | /*
|
---|
2 | * analysis.hpp
|
---|
3 | *
|
---|
4 | * Created on: Oct 13, 2009
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #ifndef ANALYSIS_HPP_
|
---|
9 | #define ANALYSIS_HPP_
|
---|
10 |
|
---|
11 | using namespace std;
|
---|
12 |
|
---|
13 | /*********************************************** includes ***********************************/
|
---|
14 |
|
---|
15 | // include config.h
|
---|
16 | #ifdef HAVE_CONFIG_H
|
---|
17 | #include <config.h>
|
---|
18 | #endif
|
---|
19 |
|
---|
20 | #include <fstream>
|
---|
21 |
|
---|
22 | // STL headers
|
---|
23 | #include <map>
|
---|
24 |
|
---|
25 | #include "defs.hpp"
|
---|
26 |
|
---|
27 | #include "atom.hpp"
|
---|
28 |
|
---|
29 | /****************************************** forward declarations *****************************/
|
---|
30 |
|
---|
31 | class BoundaryTriangleSet;
|
---|
32 | class element;
|
---|
33 | class LinkedCell;
|
---|
34 | class molecule;
|
---|
35 | class Tesselation;
|
---|
36 | class Vector;
|
---|
37 |
|
---|
38 | /********************************************** definitions *********************************/
|
---|
39 |
|
---|
40 | typedef multimap<double, pair<atom *, atom *> > PairCorrelationMap;
|
---|
41 | typedef multimap<double, pair<atom *, Vector *> > CorrelationToPointMap;
|
---|
42 | typedef multimap<double, pair<atom *, BoundaryTriangleSet *> > CorrelationToSurfaceMap;
|
---|
43 | typedef map<double, int> BinPairMap;
|
---|
44 |
|
---|
45 | /********************************************** declarations *******************************/
|
---|
46 |
|
---|
47 | PairCorrelationMap *PairCorrelation( ofstream *out, molecule *mol, element *type1, element *type2 );
|
---|
48 | CorrelationToPointMap *CorrelationToPoint( ofstream *out, molecule *mol, element *type, Vector *point );
|
---|
49 | CorrelationToSurfaceMap *CorrelationToSurface( ofstream *out, molecule *mol, element *type, Tesselation *Surface, LinkedCell *LC );
|
---|
50 | double GetBin ( double value, double BinWidth, double BinStart );
|
---|
51 | void OutputCorrelation( ofstream *file, BinPairMap *map );
|
---|
52 |
|
---|
53 |
|
---|
54 | /** Searches for lowest and highest value in a given map of doubles.
|
---|
55 | * \param *map map of doubles to scan
|
---|
56 | * \param &min minimum on return
|
---|
57 | * \param &max maximum on return
|
---|
58 | */
|
---|
59 | template <typename T> void GetMinMax ( T *map, double &min, double &max)
|
---|
60 | {
|
---|
61 | min = 0.;
|
---|
62 | max = 0.;
|
---|
63 | bool FirstMinFound = false;
|
---|
64 | bool FirstMaxFound = false;
|
---|
65 |
|
---|
66 | if (map == NULL) {
|
---|
67 | cerr << "Nothing to min/max, map is NULL!" << endl;
|
---|
68 | return;
|
---|
69 | }
|
---|
70 |
|
---|
71 | for (typename T::iterator runner = map->begin(); runner != map->end(); ++runner) {
|
---|
72 | if ((min > runner->first) || (!FirstMinFound)) {
|
---|
73 | min = runner->first;
|
---|
74 | FirstMinFound = true;
|
---|
75 | }
|
---|
76 | if ((max < runner->first) || (!FirstMaxFound)) {
|
---|
77 | max = runner->first;
|
---|
78 | FirstMaxFound = true;
|
---|
79 | }
|
---|
80 | }
|
---|
81 | };
|
---|
82 |
|
---|
83 | /** Puts given correlation data into bins of given size (histogramming).
|
---|
84 | * Note that BinStart and BinEnd are desired to fill the complete range, even where Bins are zero. If this is
|
---|
85 | * not desired, give equal BinStart and BinEnd and the map will contain only Bins where the count is one or greater.
|
---|
86 | * Also note that the range is given inclusive, i.e. [ BinStart, BinEnd ].
|
---|
87 | * \param *out output stream for debugging
|
---|
88 | * \param *map map of doubles to count
|
---|
89 | * \param BinWidth desired width of the binds
|
---|
90 | * \param BinStart first bin
|
---|
91 | * \param BinEnd last bin
|
---|
92 | * \return Map of doubles (the bins) with counts as values
|
---|
93 | */
|
---|
94 | template <typename T> BinPairMap *BinData ( ofstream *out, T *map, double BinWidth, double BinStart, double BinEnd )
|
---|
95 | {
|
---|
96 | BinPairMap *outmap = new BinPairMap;
|
---|
97 | double bin = 0.;
|
---|
98 | double start = 0.;
|
---|
99 | double end = 0.;
|
---|
100 | pair <BinPairMap::iterator, bool > BinPairMapInserter;
|
---|
101 |
|
---|
102 | if (map == NULL) {
|
---|
103 | cerr << "Nothing to bin, is NULL!" << endl;
|
---|
104 | return outmap;
|
---|
105 | }
|
---|
106 |
|
---|
107 | if (BinStart == BinEnd) { // if same, find range ourselves
|
---|
108 | GetMinMax( map, start, end);
|
---|
109 | } else { // if not, initialise range to zero
|
---|
110 | start = BinStart;
|
---|
111 | end = BinEnd;
|
---|
112 | for (double runner = start; runner <= end; runner += BinWidth)
|
---|
113 | outmap->insert( pair<double, int> (runner, 0.) );
|
---|
114 | }
|
---|
115 |
|
---|
116 | for (typename T::iterator runner = map->begin(); runner != map->end(); ++runner) {
|
---|
117 | bin = GetBin (runner->first, BinWidth, start);
|
---|
118 | BinPairMapInserter = outmap->insert ( pair<double, int> (bin, 1) );
|
---|
119 | if (!BinPairMapInserter.second) { // bin already present, increase
|
---|
120 | BinPairMapInserter.first->second += 1;
|
---|
121 | }
|
---|
122 | }
|
---|
123 |
|
---|
124 | return outmap;
|
---|
125 | };
|
---|
126 |
|
---|
127 | #endif /* ANALYSIS_HPP_ */
|
---|