-
Notifications
You must be signed in to change notification settings - Fork 3
/
observablehandler.cpp
73 lines (66 loc) · 2.79 KB
/
observablehandler.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. See the enclosed file LICENSE for a copy or if
* that was not distributed with this file, You can obtain one at
* http://mozilla.org/MPL/2.0/.
*
* Copyright 2017 Max H. Gerlach
*
* */
/*
* observablehandler.cpp
*
* Created on: Dec 13, 2012
* Author: gerlach
*/
#include "observablehandler.h"
void outputResults(const std::vector<std::unique_ptr<ScalarObservableHandler>>& obsHandlers) {
typedef std::map<std::string, num> StringNumMap;
typedef std::shared_ptr<StringNumMap> StringNumMapPtr;
StringNumMapPtr values(new StringNumMap);
StringNumMapPtr errors(new StringNumMap);
for (auto p = obsHandlers.cbegin(); p != obsHandlers.cend(); ++p) {
num val, err;
std::tie(val, err) = (*p)->evaluateJackknife();
std::string obsname = (*p)->name;
(*values)[obsname] = val;
(*errors)[obsname] = err;
}
DataMapWriter<std::string, num> output;
output.setData(values);
output.setErrors(errors);
output.addHeaderText("Monte Carlo results for observable expectation values");
output.addMetadataMap((*obsHandlers.begin())->metaModel);
output.addMetadataMap((*obsHandlers.begin())->metaMC);
output.addMeta("key", "observable");
output.addHeaderText("observable\t value \t error");
output.writeToFile("results.values");
}
void outputResults(const std::vector<std::unique_ptr<VectorObservableHandler>>& obsHandlers) {
typedef std::map<num, num> NumMap;
typedef std::shared_ptr<NumMap> NumMapPtr;
typedef DataMapWriter<num,num> NumMapWriter;
for (auto p = obsHandlers.cbegin(); p != obsHandlers.cend(); ++p) {
const std::unique_ptr<VectorObservableHandler>& obsptr = *p;
uint32_t numberIndexes = obsptr->getVectorSize();
arma::Col<num> values, errors;
std::tie(values, errors) = obsptr->evaluateJackknife();
NumMapPtr valmap(new NumMap);
NumMapPtr errmap(new NumMap);
for (uint32_t counter = 0; counter < numberIndexes; ++counter) {
num index = obsptr->indexes[counter];
valmap->insert(std::make_pair(index, values[counter]));
errmap->insert(std::make_pair(index, errors[counter]));
}
NumMapWriter output;
output.setData(valmap);
output.setErrors(errmap);
output.addHeaderText("Monte Carlo results for vector observable " + obsptr->name +
" expectation values");
output.addMetadataMap(obsptr->metaModel);
output.addMetadataMap(obsptr->metaMC);
output.addMeta("key", obsptr->indexName);
output.addMeta("observable", obsptr->name);
output.addHeaderText("key\t value \t error");
output.writeToFile("results-" + obsptr->name + ".values");
}
}