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 (string& cfile : files)
25 file << cfile << endl;
26
27 file << endl;
28
29 for (string& command : commands)
30 file << command << endl;
31
32 file.close();
33 return filename;
34}
35void PedeSteering::command(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(vector< int > labels, vector< double > values, vector< double > presigmas)
52{
53 command("Parameters");
54 bool useValues = (labels.size() == values.size());
55 bool usePresigmas = (labels.size() == presigmas.size());
56
57 for (unsigned int i = 0; i < labels.size(); i++) {
58 double value = 0.;
59 double presigma = -1.;
60 if (useValues)
61 value = values[i];
62 if (usePresigmas)
63 presigma = presigmas[i];
64
65 command(to_string(labels[i]) + " " + to_string(value) + " " + to_string(presigma));
66 }
67}
68
69void PedeSteering::addFile(std::string filename, double weight)
70{
71 if (weight != 1.)
72 filename = filename + " -- " + std::to_string(weight);
73 bool exists = false;
74 for (auto file : files)
75 if (file == filename)
76 exists = true;
77 if (!exists)
78 files.push_back(filename);
79}
80
81/*
82void PedeSteering::addConstraint(double constraint, vector< int > labels, vector< double > coefficients) {
83 command("Constraint " + to_string(constraint));
84 if (labels.size() != coefficients.size())
85 return;
86
87 for (unsigned int i = 0; i < labels.size(); i++) {
88 command(to_string(labels[i]) + " " + to_string(coefficients[i]));
89 }
90}
91*/
92
93
std::string make(std::string filename="")
Compose and write out steering file.
Definition: PedeSteering.cc:16
std::vector< std::string > files
list of binary files
Definition: PedeSteering.h:59
void fixParameters(std::vector< int > labels, std::vector< double > values={}, std::vector< double > presigmas={})
Fix parameter values and set presigmas.
Definition: PedeSteering.cc:51
std::string name
Name of steering (used as default filename)
Definition: PedeSteering.h:61
void import(std::string filename)
Load commands from existing text file.
Definition: PedeSteering.cc:39
void command(std::string line)
Add command to the steering.
Definition: PedeSteering.cc:35
std::vector< std::string > commands
list command lines
Definition: PedeSteering.h:57
void addFile(std::string filename, double weight=1.)
Add a file (optionally with weight) to list of binary files.
Definition: PedeSteering.cc:69
Abstract base class for different kinds of events.
STL namespace.