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