source: molecuilder/src/analysis_correlation.hpp@ 8b6ee4

Last change on this file since 8b6ee4 was d70bf6, checked in by Frederik Heber <heber@…>, 16 years ago

Added case 'C' to ParseCommandLineOptions with CorrelationToSurface().

  • new case 'C' with CorrelationToSurface()
  • lots of changes in ParseCommandLineOptions() as all of the tests for ...[0] != '-' were wrong for numbers (e.g. -t -1. 0. 0. in translation case)
  • small fix to BinData() as 0. was given instead of 0 for second argument of outmap (but should be integer)
  • Property mode set to 100644
File size: 4.1 KB
Line 
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
11using 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
31class BoundaryTriangleSet;
32class element;
33class LinkedCell;
34class molecule;
35class Tesselation;
36class Vector;
37
38/********************************************** definitions *********************************/
39
40typedef multimap<double, pair<atom *, atom *> > PairCorrelationMap;
41typedef multimap<double, pair<atom *, Vector *> > CorrelationToPointMap;
42typedef multimap<double, pair<atom *, BoundaryTriangleSet *> > CorrelationToSurfaceMap;
43typedef map<double, int> BinPairMap;
44
45/********************************************** declarations *******************************/
46
47PairCorrelationMap *PairCorrelation( ofstream *out, molecule *mol, element *type1, element *type2 );
48CorrelationToPointMap *CorrelationToPoint( ofstream *out, molecule *mol, element *type, Vector *point );
49CorrelationToSurfaceMap *CorrelationToSurface( ofstream *out, molecule *mol, element *type, Tesselation *Surface, LinkedCell *LC );
50double GetBin ( double value, double BinWidth, double BinStart );
51void OutputCorrelation( ofstream *file, BinPairMap *map );
52void OutputPairCorrelation( ofstream *file, BinPairMap *map );
53void OutputCorrelationToPoint( ofstream *file, BinPairMap *map );
54void OutputCorrelationToSurface( ofstream *file, BinPairMap *map );
55
56
57/** Searches for lowest and highest value in a given map of doubles.
58 * \param *map map of doubles to scan
59 * \param &min minimum on return
60 * \param &max maximum on return
61 */
62template <typename T> void GetMinMax ( T *map, double &min, double &max)
63{
64 min = 0.;
65 max = 0.;
66 bool FirstMinFound = false;
67 bool FirstMaxFound = false;
68
69 if (map == NULL) {
70 cerr << "Nothing to min/max, map is NULL!" << endl;
71 return;
72 }
73
74 for (typename T::iterator runner = map->begin(); runner != map->end(); ++runner) {
75 if ((min > runner->first) || (!FirstMinFound)) {
76 min = runner->first;
77 FirstMinFound = true;
78 }
79 if ((max < runner->first) || (!FirstMaxFound)) {
80 max = runner->first;
81 FirstMaxFound = true;
82 }
83 }
84};
85
86/** Puts given correlation data into bins of given size (histogramming).
87 * Note that BinStart and BinEnd are desired to fill the complete range, even where Bins are zero. If this is
88 * not desired, give equal BinStart and BinEnd and the map will contain only Bins where the count is one or greater.
89 * Also note that the range is given inclusive, i.e. [ BinStart, BinEnd ].
90 * \param *out output stream for debugging
91 * \param *map map of doubles to count
92 * \param BinWidth desired width of the binds
93 * \param BinStart first bin
94 * \param BinEnd last bin
95 * \return Map of doubles (the bins) with counts as values
96 */
97template <typename T> BinPairMap *BinData ( ofstream *out, T *map, double BinWidth, double BinStart, double BinEnd )
98{
99 BinPairMap *outmap = new BinPairMap;
100 double bin = 0.;
101 double start = 0.;
102 double end = 0.;
103 pair <BinPairMap::iterator, bool > BinPairMapInserter;
104
105 if (map == NULL) {
106 cerr << "Nothing to bin, is NULL!" << endl;
107 return outmap;
108 }
109
110 if (BinStart == BinEnd) { // if same, find range ourselves
111 GetMinMax( map, start, end);
112 } else { // if not, initialise range to zero
113 start = BinStart;
114 end = BinEnd;
115 for (double runner = start; runner <= end; runner += BinWidth)
116 outmap->insert( pair<double, int> (runner, 0) );
117 }
118
119 for (typename T::iterator runner = map->begin(); runner != map->end(); ++runner) {
120 bin = GetBin (runner->first, BinWidth, start);
121 BinPairMapInserter = outmap->insert ( pair<double, int> (bin, 1) );
122 if (!BinPairMapInserter.second) { // bin already present, increase
123 BinPairMapInserter.first->second += 1;
124 }
125 }
126
127 return outmap;
128};
129
130#endif /* ANALYSIS_HPP_ */
Note: See TracBrowser for help on using the repository browser.