/* * analysis.hpp * * Created on: Oct 13, 2009 * Author: heber */ #ifndef ANALYSIS_HPP_ #define ANALYSIS_HPP_ using namespace std; /*********************************************** includes ***********************************/ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include // STL headers #include #include "defs.hpp" #include "atom.hpp" /****************************************** forward declarations *****************************/ class BoundaryTriangleSet; class element; class LinkedCell; class molecule; class Tesselation; class Vector; /********************************************** definitions *********************************/ typedef multimap > PairCorrelationMap; typedef multimap > CorrelationToPointMap; typedef multimap > CorrelationToSurfaceMap; typedef map BinPairMap; /********************************************** declarations *******************************/ PairCorrelationMap *PairCorrelation( ofstream *out, molecule *mol, element *type1, element *type2 ); CorrelationToPointMap *CorrelationToPoint( ofstream *out, molecule *mol, element *type, Vector *point ); CorrelationToSurfaceMap *CorrelationToSurface( ofstream *out, molecule *mol, element *type, Tesselation *Surface, LinkedCell *LC ); double GetBin ( double value, double BinWidth, double BinStart ); void OutputCorrelation( ofstream *file, BinPairMap *map ); /** Searches for lowest and highest value in a given map of doubles. * \param *map map of doubles to scan * \param &min minimum on return * \param &max maximum on return */ template void GetMinMax ( T *map, double &min, double &max) { min = 0.; max = 0.; bool FirstMinFound = false; bool FirstMaxFound = false; if (map == NULL) { cerr << "Nothing to min/max, map is NULL!" << endl; return; } for (typename T::iterator runner = map->begin(); runner != map->end(); ++runner) { if ((min > runner->first) || (!FirstMinFound)) { min = runner->first; FirstMinFound = true; } if ((max < runner->first) || (!FirstMaxFound)) { max = runner->first; FirstMaxFound = true; } } }; /** Puts given correlation data into bins of given size (histogramming). * Note that BinStart and BinEnd are desired to fill the complete range, even where Bins are zero. If this is * not desired, give equal BinStart and BinEnd and the map will contain only Bins where the count is one or greater. * Also note that the range is given inclusive, i.e. [ BinStart, BinEnd ]. * \param *out output stream for debugging * \param *map map of doubles to count * \param BinWidth desired width of the binds * \param BinStart first bin * \param BinEnd last bin * \return Map of doubles (the bins) with counts as values */ template BinPairMap *BinData ( ofstream *out, T *map, double BinWidth, double BinStart, double BinEnd ) { BinPairMap *outmap = new BinPairMap; double bin = 0.; double start = 0.; double end = 0.; pair BinPairMapInserter; if (map == NULL) { cerr << "Nothing to bin, is NULL!" << endl; return outmap; } if (BinStart == BinEnd) { // if same, find range ourselves GetMinMax( map, start, end); } else { // if not, initialise range to zero start = BinStart; end = BinEnd; for (double runner = start; runner <= end; runner += BinWidth) outmap->insert( pair (runner, 0.) ); } for (typename T::iterator runner = map->begin(); runner != map->end(); ++runner) { bin = GetBin (runner->first, BinWidth, start); BinPairMapInserter = outmap->insert ( pair (bin, 1) ); if (!BinPairMapInserter.second) { // bin already present, increase BinPairMapInserter.first->second += 1; } } return outmap; }; #endif /* ANALYSIS_HPP_ */