Belle II Software development
PedeResult Class Reference

Class to process Pede result file(s) More...

#include <PedeResult.h>

Classes

struct  parameterData
 Struct to hold data for a parameter. More...
 

Public Member Functions

 PedeResult ()
 Default constructor, use read(...) to init the object.
 
 PedeResult (const std::string &filename)
 Constructor which loads given file.
 
void read (std::string filename="millepede.res")
 Reads the result file and inits the object.
 
void readEigenFile (std::string filename="millepede.eve")
 Reads file with eigen-vector/numbers.
 
bool isValid ()
 Was the object initialized properly from a result file?
 
void dump ()
 Dump the content to std::cout.
 
int getNoParameters () const
 Get number of parameters in result (for looping over)
 
int getNoDeterminedParameters () const
 Get number of determined parameters (with correction)
 
int getParameterIndex (int parameterLabel)
 Get index of parameter with given label.
 
unsigned int getParameterLabel (unsigned int parameterIndex)
 Get label of parameter at index.
 
double getParameterCorrection (unsigned int parameterIndex)
 Get determined correction of parameter at index.
 
double getParameterError (unsigned int parameterIndex)
 Get correction error of parameter at index.
 
double getParameterPresigma (unsigned int parameterIndex)
 Get presigma of parameter at index.
 
bool isParameterFixed (unsigned int parameterIndex)
 Is parameter at given index fixed?
 
bool isParameterDetermined (unsigned int parameterIndex)
 Is parameter at given index determined?
 
int getNoEigenPairs () const
 Get the number of eigenvectors(numbers) in eigen file.
 
double getEigenNumber (unsigned int eigenPairIndex)
 Get eigennumber at given index.
 
double getEigenVectorElement (unsigned int eigenPairIndex, unsigned int parameterIndex)
 Get eigenvector at given index.
 

Private Member Functions

bool outOfBounds (int iparam)
 Is index out of valid range?
 

Private Attributes

std::vector< parameterDatadata
 Vector with all the parameter data.
 
std::vector< double > eigenNumbers
 Vector of loaded eigennumbers.
 
bool valid
 Flag to check if data wa loaded.
 
std::map< int, int > labelIndices
 Map to link parameter labels and their indices in result.
 
int noDeterminedParams {0}
 Number of parameters actually determined.
 

Detailed Description

Class to process Pede result file(s)

Definition at line 22 of file PedeResult.h.

Constructor & Destructor Documentation

◆ PedeResult() [1/2]

PedeResult ( )
inline

Default constructor, use read(...) to init the object.

Definition at line 25 of file PedeResult.h.

25: data(), eigenNumbers(), valid(false), labelIndices() {}
bool valid
Flag to check if data wa loaded.
Definition: PedeResult.h:105
std::map< int, int > labelIndices
Map to link parameter labels and their indices in result.
Definition: PedeResult.h:107
std::vector< double > eigenNumbers
Vector of loaded eigennumbers.
Definition: PedeResult.h:103
std::vector< parameterData > data
Vector with all the parameter data.
Definition: PedeResult.h:101

◆ PedeResult() [2/2]

PedeResult ( const std::string &  filename)
explicit

Constructor which loads given file.

Parameters
filenameName of the result file (millepede.res)

Definition at line 126 of file PedeResult.cc.

126 : data(), eigenNumbers(), valid(false), labelIndices()
127 {
128 read(filename);
129 }
void read(std::string filename="millepede.res")
Reads the result file and inits the object.
Definition: PedeResult.cc:95

Member Function Documentation

◆ dump()

void dump ( )

Dump the content to std::cout.

Definition at line 176 of file PedeResult.cc.

177 {
178 for (auto pdata : data) {
179 std::cout << pdata.index << " : " << pdata.label << " corr: " << pdata.correction << " err: " << pdata.error << " presigma: " <<
180 pdata.presigma << endl;
181 }
182 }

◆ getEigenNumber()

double getEigenNumber ( unsigned int  eigenPairIndex)

Get eigennumber at given index.

Definition at line 161 of file PedeResult.cc.

162 {
163 if (eigenPairIndex >= eigenNumbers.size()) return 0.;
164 return eigenNumbers[eigenPairIndex];
165 }

◆ getEigenVectorElement()

double getEigenVectorElement ( unsigned int  eigenPairIndex,
unsigned int  parameterIndex 
)

Get eigenvector at given index.

Definition at line 166 of file PedeResult.cc.

167 {
168 if (outOfBounds(parameterIndex))
169 return 0.;
170 parameterData& element = data[parameterIndex];
171 if (eigenPairIndex >= element.eigenweights.size())
172 return 0.;
173
174 return data[parameterIndex].eigenweights[eigenPairIndex];
175 }
bool outOfBounds(int iparam)
Is index out of valid range?
Definition: PedeResult.h:64

◆ getNoDeterminedParameters()

int getNoDeterminedParameters ( ) const
inline

Get number of determined parameters (with correction)

Definition at line 40 of file PedeResult.h.

40{return noDeterminedParams;}
int noDeterminedParams
Number of parameters actually determined.
Definition: PedeResult.h:109

◆ getNoEigenPairs()

int getNoEigenPairs ( ) const
inline

Get the number of eigenvectors(numbers) in eigen file.

Definition at line 56 of file PedeResult.h.

56{return eigenNumbers.size();}

◆ getNoParameters()

int getNoParameters ( ) const
inline

Get number of parameters in result (for looping over)

Definition at line 38 of file PedeResult.h.

38{return data.size();}

◆ getParameterCorrection()

double getParameterCorrection ( unsigned int  parameterIndex)

Get determined correction of parameter at index.

Definition at line 136 of file PedeResult.cc.

137 {
138 if (outOfBounds(parameterIndex)) return 0.;
139 return data[parameterIndex].correction;
140 }

◆ getParameterError()

double getParameterError ( unsigned int  parameterIndex)

Get correction error of parameter at index.

Definition at line 141 of file PedeResult.cc.

142 {
143 if (outOfBounds(parameterIndex)) return 0.;
144 return data[parameterIndex].error;
145 }

◆ getParameterIndex()

int getParameterIndex ( int  parameterLabel)

Get index of parameter with given label.

Definition at line 27 of file PedeResult.cc.

28 {
29 auto index = labelIndices.find(parameterLabel);
30 if (index != labelIndices.end())
31 return index->second;
32 else
33 return -1;
34 }

◆ getParameterLabel()

unsigned int getParameterLabel ( unsigned int  parameterIndex)

Get label of parameter at index.

Definition at line 131 of file PedeResult.cc.

132 {
133 if (outOfBounds(parameterIndex)) return 0;
134 return data[parameterIndex].label;
135 }

◆ getParameterPresigma()

double getParameterPresigma ( unsigned int  parameterIndex)

Get presigma of parameter at index.

Definition at line 146 of file PedeResult.cc.

147 {
148 if (outOfBounds(parameterIndex)) return 0.;
149 return data[parameterIndex].presigma;
150 }

◆ isParameterDetermined()

bool isParameterDetermined ( unsigned int  parameterIndex)

Is parameter at given index determined?

Definition at line 156 of file PedeResult.cc.

157 {
158 if (outOfBounds(parameterIndex)) return false;
159 return !isParameterFixed(parameterIndex) && data[parameterIndex].correction != 0. && data[parameterIndex].error != 0.;
160 }
bool isParameterFixed(unsigned int parameterIndex)
Is parameter at given index fixed?
Definition: PedeResult.cc:151

◆ isParameterFixed()

bool isParameterFixed ( unsigned int  parameterIndex)

Is parameter at given index fixed?

Definition at line 151 of file PedeResult.cc.

152 {
153 if (outOfBounds(parameterIndex)) return false;
154 return data[parameterIndex].presigma < 0;
155 }

◆ isValid()

bool isValid ( )
inline

Was the object initialized properly from a result file?

Definition at line 34 of file PedeResult.h.

34{return valid;}

◆ outOfBounds()

bool outOfBounds ( int  iparam)
inlineprivate

Is index out of valid range?

Definition at line 64 of file PedeResult.h.

64{if (iparam < 0) return true; if ((unsigned int)iparam >= data.size()) return true; return false;}

◆ read()

void read ( std::string  filename = "millepede.res")

Reads the result file and inits the object.

Definition at line 95 of file PedeResult.cc.

96 {
97 string line;
98 ifstream res(filename);
99 // skip comment line
100 getline(res, line);
101
103 data.clear();
104 labelIndices.clear();
105 int index(-1);
106
107 while (getline(res, line)) {
108 ++index;
109 int label = -1;
110 double param = 0.;
111 double presigma = 0.;
112 double differ = 0.;
113 double error = 0.;
114 stringstream ss;
115 ss << line;
116 ss >> label >> param >> presigma >> differ >> error;
117 data.push_back(parameterData(index, label, param, error, presigma));
118 labelIndices.insert(make_pair(label, index));
119 if (isParameterDetermined(index))
121 }
122
123 if (data.size() > 0)
124 valid = true;
125 }
bool isParameterDetermined(unsigned int parameterIndex)
Is parameter at given index determined?
Definition: PedeResult.cc:156

◆ readEigenFile()

void readEigenFile ( std::string  filename = "millepede.eve")

Reads file with eigen-vector/numbers.

Definition at line 35 of file PedeResult.cc.

36 {
37 if (!valid)
38 return;
39
40 string line;
41 ifstream file(filename);
42
43 if (!file.is_open())
44 return;
45
46 int eigenPairIndex = -1;
47
48 for (auto& pData : data) {
49 pData.eigenweights.clear();
50 pData.eigenweights.reserve(20);
51 }
52
53 while (getline(file, line)) {
54 cout << line << endl;
55 stringstream ss;
56 ss << line;
57 string tmp1, tmp2, tmp3;
58 int eigenPairNumber;
59 double eigenvalue;
60 ss >> tmp1 >> eigenPairNumber >> tmp2 >> tmp3 >> eigenvalue;
61 cout << tmp1 << " " << tmp2 << " " << tmp3 << " " << eigenPairNumber << " " << eigenvalue << endl;
62 if (tmp1 == "Eigenvector")
63 ++eigenPairIndex;
64 else
65 continue;
66
67 // Read elements
68 vector<pair<int, double>> elements;
69 while (getline(file, line) && line.length() > 2) {
70 int lab1 = 0;
71 int lab2 = 0;
72 int lab3 = 0;
73 double w1, w2, w3;
74 stringstream triplet;
75 triplet << line;
76 triplet >> lab1 >> w1 >> lab2 >> w2 >> lab3 >> w3;
77 if (lab1) elements.push_back({lab1, w1});
78 if (lab2) elements.push_back({lab2, w2});
79 if (lab3) elements.push_back({lab3, w3});
80 //cout << lab1 << w1 << lab2 << w2 << lab3 << w3 << endl;
81 }
82 for (auto& pData : data) {
83 pData.eigenweights.push_back(0.);
84 }
85 for (auto el : elements) {
86 int index = getParameterIndex(el.first);
87 if (index >= 0)
88 data[index].eigenweights[eigenPairIndex] = el.second;
89 }
90 eigenNumbers.push_back(eigenvalue);
91 }
92
93
94 }
int getParameterIndex(int parameterLabel)
Get index of parameter with given label.
Definition: PedeResult.cc:27

Member Data Documentation

◆ data

std::vector<parameterData> data
private

Vector with all the parameter data.

Definition at line 101 of file PedeResult.h.

◆ eigenNumbers

std::vector<double> eigenNumbers
private

Vector of loaded eigennumbers.

Definition at line 103 of file PedeResult.h.

◆ labelIndices

std::map<int, int> labelIndices
private

Map to link parameter labels and their indices in result.

Definition at line 107 of file PedeResult.h.

◆ noDeterminedParams

int noDeterminedParams {0}
private

Number of parameters actually determined.

Definition at line 109 of file PedeResult.h.

◆ valid

bool valid
private

Flag to check if data wa loaded.

Definition at line 105 of file PedeResult.h.


The documentation for this class was generated from the following files: