Belle II Software development
PedeSteering.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <alignment/dataobjects/PedeSteering.h>
10
11#include <fstream>
12
13using namespace Belle2;
14using namespace std;
15
16string PedeSteering::make(string filename)
17{
18 command("end");
19 if (filename == "")
20 filename = name;
21 ofstream file(filename.c_str());
22 file << "! Steerig file for Pede generated by PedeSteering class !" << endl;
23 file << "Cfiles" << endl;
24 for (const string& cfile : files)
25 file << cfile << endl;
26
27 file << endl;
28
29 for (const string& cmd : commands)
30 file << cmd << endl;
31
32 file.close();
33 return filename;
34}
35void PedeSteering::command(const std::string& line)
36{
37 commands.push_back(line);
38}
39void PedeSteering::import(string filename)
40{
41 commands.clear();
42 ifstream file(filename);
43 if (!file.is_open())
44 return;
45
46 string commandLine;
47 while (getline(file, commandLine))
48 command(commandLine);
49}
50
51void PedeSteering::fixParameters(const vector< int >& labels,
52 const vector< double >& values,
53 const vector< double >& presigmas)
54{
55 command("Parameters");
56 bool useValues = (labels.size() == values.size());
57 bool usePresigmas = (labels.size() == presigmas.size());
58
59 for (unsigned int i = 0; i < labels.size(); i++) {
60 double value = 0.;
61 double presigma = -1.;
62 if (useValues)
63 value = values[i];
64 if (usePresigmas)
65 presigma = presigmas[i];
66
67 command(to_string(labels[i]) + " " + to_string(value) + " " + to_string(presigma));
68 }
69}
70
71void PedeSteering::addFile(std::string filename, double weight)
72{
73 if (weight != 1.)
74 filename = filename + " -- " + std::to_string(weight);
75 bool exists = false;
76 for (const auto& file : files)
77 if (file == filename)
78 exists = true;
79 if (!exists)
80 files.push_back(filename);
81}
82
83/*
84void PedeSteering::addConstraint(double constraint, vector< int > labels, vector< double > coefficients) {
85 command("Constraint " + to_string(constraint));
86 if (labels.size() != coefficients.size())
87 return;
88
89 for (unsigned int i = 0; i < labels.size(); i++) {
90 command(to_string(labels[i]) + " " + to_string(coefficients[i]));
91 }
92}
93*/
94
std::string make(std::string filename="")
Compose and write out steering file.
std::vector< std::string > files
list of binary files
void fixParameters(const std::vector< int > &labels, const std::vector< double > &values={}, const std::vector< double > &presigmas={})
Fix parameter values and set presigmas.
std::string name
Name of steering (used as default filename)
void import(std::string filename)
Load commands from existing text file.
void command(const std::string &line)
Add command to the steering.
std::vector< std::string > commands
list command lines
void addFile(std::string filename, double weight=1.)
Add a file (optionally with weight) to list of binary files.
Abstract base class for different kinds of events.
STL namespace.