FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
compare.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 #include <algorithm>
9 #include <cmath>
10 #include <fstream>
11 #include <iostream>
12 #include <vector>
13 
14 using std::cout;
15 using std::endl;
16 using std::fabs;
17 using std::ifstream;
18 using std::vector;
19 
20 int main(int argc, char* argv[])
21 {
22  // No good solution
23  // TODO
24  bool isFortranFile;
25  if (2 == argc) {
26  isFortranFile = argv[1];
27  }
28 
29  // Read the milepede output and the file with shifts created by
30  // TestMillePede to compare if the correction have been correctly calculated
31 
32  int label;
33  float value;
34  float value2;
35  vector<int> labelVector;
36  vector<float> valueVector;
37 
38  if (!isFortranFile) {
39 
40  cout << "Read file created by TestMillePede." << endl;
41 
42  ifstream vInput;
43  vInput.open("shifts.txt");
44  if (!vInput.is_open()) {
45  cout << "Could not open the input file." << endl;
46  exit(1);
47  }
48  while (1) {
49  vInput >> label >> value;
50  if (!vInput.good()) {
51  break;
52  }
53  labelVector.push_back(label);
54  valueVector.push_back(value);
55  }
56  vInput.close();
57 
58  } else {
59 
60  cout << "Read file created by pede." << endl;
61 
62  ifstream vInput;
63  vInput.open("shifts.txt");
64  if (!vInput.is_open()) {
65  cout << "Could not open the input file." << endl;
66  exit(1);
67  }
68  while (1) {
69  vInput >> label >> value >> value2;
70  if (!vInput.good()) {
71  break;
72  }
73  int label1 = 10 + label * 2;
74  labelVector.push_back(label1);
75  valueVector.push_back(value);
76  label1 = 500 + label;
77  labelVector.push_back(label1);
78  valueVector.push_back(value2);
79  }
80  vInput.close();
81  }
82 
83  for (int c = 0; c < (int)labelVector.size(); ++c) {
84  cout << "c, label,value:" << c << ", " << labelVector[c] << ", " << valueVector[c] << endl;
85  }
86 
87  std::vector<int>::iterator result;
88 
89  result = std::max_element(labelVector.begin(), labelVector.end());
90 
91  int maxValue = *result;
92 
93  float origShifts[maxValue + 1];
94  float recoShifts[maxValue + 1];
95 
96  for (int i = 0; i < maxValue + 1; ++i) {
97  origShifts[i] = 0;
98  recoShifts[i] = 0;
99  }
100 
101  for (int i = 0; i < labelVector.size(); ++i) {
102  origShifts[labelVector[i]] = valueVector[i];
103  }
104 
105  labelVector.clear();
106  valueVector.clear();
107 
108  ifstream vInput1;
109  float dummy1, dummy2, dummy3, dummy4;
110  vInput1.open("millepede.res");
111  if (!vInput1.is_open()) {
112  cout << "Could not open the input file." << endl;
113  exit(1);
114  }
115  while (1) {
116  vInput1 >> label >> value >> dummy1 >> dummy2 >> dummy3;
117  if (!vInput1.good()) {
118  break;
119  }
120  labelVector.push_back(label);
121  valueVector.push_back(value);
122  cout << label << ", " << value << endl;
123  }
124  vInput1.close();
125 
126  for (int c = 0; c < (int)labelVector.size(); ++c) {
127  cout << "c, label,value:" << c << ", " << labelVector[c] << ", " << valueVector[c] << endl;
128  }
129 
130  for (int i = 0; i < labelVector.size(); ++i) {
131  recoShifts[labelVector[i]] = valueVector[i];
132  }
133 
134  for (int i = 0; i < labelVector.size(); ++i) {
135  recoShifts[labelVector[i]] = valueVector[i];
136  }
137 
138  int numBadValues = 0;
139  int percent2 = 0;
140  int percent3 = 0;
141  int percent4 = 0;
142  for (int i = 0; i < maxValue + 1; ++i) {
143  float diff = recoShifts[i] + origShifts[i];
144  float percent = fabs(diff / origShifts[i]) * 100;
145  if (percent > 1.) {
146  cout << i << " : " << recoShifts[i] << ", " << origShifts[i] << ", " << diff << ", " << percent << endl;
147  numBadValues++;
148  }
149  if (percent > 2.) {
150  percent2++;
151  }
152  if (percent > 3.) {
153  percent3++;
154  }
155  if (percent > 4.) {
156  percent4++;
157  }
158  }
159  cout << numBadValues << " corrections with a deviation > 1%" << endl;
160  cout << percent2 << " corrections with a deviation > 2%" << endl;
161  cout << percent3 << " corrections with a deviation > 3%" << endl;
162  cout << percent4 << " corrections with a deviation > 4%" << endl;
163 }
int main(void)