Jpp 21.0.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JMechanics.cc
Go to the documentation of this file.
1#include <string>
2#include <iostream>
3#include <iomanip>
4#include <fstream>
5
6#include "TROOT.h"
7#include "TFile.h"
8#include "TGraphErrors.h"
9#include "TF1.h"
10
12#include "JROOT/JRootToolkit.hh"
13#include "JROOT/JMinimizer.hh"
14
15#include "JMath/JMathlib.hh"
16#include "JROOT/JRootfit.hh"
17
18#include "Jeep/JParser.hh"
19#include "Jeep/JMessage.hh"
20
21
22/**
23 * \file
24 *
25 * Auxiliary application to fit mechanical constants.
26 * \author mdejong
27 */
28int main(int argc, char **argv)
29{
30 using namespace std;
31 using namespace JPP;
32
33 string inputFile;
34 string outputFile;
35 double error;
36 bool nobuoy;
37 bool old;
38 int debug;
39
40 try {
41
42 JParser<> zap("Auxiliary application to fit mechanical constants.");
43
44 zap['f'] = make_field(inputFile, "input file; see https://git.km3net.de/calibration/input_tables");
45 zap['o'] = make_field(outputFile) = "mechanics.root";
46 zap['e'] = make_field(error, "uncertainty drag value") = 0.2;
47 zap['B'] = make_field(nobuoy, "fit without buoy");
48 zap['O'] = make_field(old, "ROOT fit based on minuit");
49 zap['d'] = make_field(debug) = 1;
50
51 zap(argc, argv);
52 }
53 catch(const exception &error) {
54 FATAL(error.what() << endl);
55 }
56
57
58 TGraphErrors g1;
59
60 double xmax = 0.0;
61 double ymax = 0.0;
62
63 {
64 ifstream in(inputFile.c_str());
65
66 string buffer;
67
68 getline(in, buffer);
69
70 DEBUG("Header " << buffer << endl);
71
72 const locale loc(in.getloc(), new JWhiteSpacesFacet(in.getloc(), ", \t\r\n"));
73
74 in.imbue(loc);
75
76 for (double x, y; in >> x >> y; ) {
77
78 DEBUG(FIXED(7,3) << x << ' '<< FIXED(9,4) << y << endl);
79
80 AddPoint(&g1, x, y, 0.0, error);
81
82 if (x > xmax) {
83 xmax = x;
84 ymax = y;
85 }
86 }
87
88 in.close();
89 }
90
91
92 // start -> final values
93
94 double Tx = ymax / xmax;
95 double a = (nobuoy ? 0.0 : 0.5 / xmax);
96 double b = (nobuoy ? 0.0 : 0.25 * xmax);
97
98
99 // fit
100
101 if (!old) {
102
103 auto f1 = P0<0>(Tx) * (X + P0<1>(b) * Log(1.0 - P0<2>(a) * X));
104
105 typedef decltype(f1) function_type;
106
108
109 const auto result = (nobuoy ? Fit(&g1, f1, {1, 2}) : Fit(&g1, f1));
110
111 result.print(cout);
112
113 setFormat<JMatrixND>(JFormat_t(12, 3, std::ios::scientific | std::ios::showpos));
114
115 cout << "Error matrix:" << endl << result.V << endl;
116
117 Tx = result.getValue(0);
118 b = result.getValue(1);
119 a = result.getValue(2);
120
121 } else {
122
123 TF1 f1("f1", "[0]*(x + [1]*log(1.0 - [2]*x))");
124
125 f1.SetParameter(0, Tx);
126 if (nobuoy) {
127 f1.FixParameter(1, b);
128 f1.FixParameter(2, a);
129 } else {
130 f1.SetParameter(1, b);
131 f1.SetParameter(2, a);
132 }
133
134 f1.SetParError(0, 0.05);
135 f1.SetParError(1, 1.0e-6);
136 f1.SetParError(2, 1.0e-1); // anomalous step size works?
137 //f1.SetParError(2, 1.0e-7);
138
139 g1.Fit(&f1);
140
141 Tx = f1.GetParameter(0);
142 b = f1.GetParameter(1);
143 a = f1.GetParameter(2);
144 }
145
146
147 cout << inputFile << endl;
148
149 cout << "T_x = " << FIXED(5,2) << Tx << " [s^2/m^2] * v_x^2" << endl;
150
151 cout << "b [m] " << FIXED(7,3) << b << endl;
152 cout << "a [m^-1] " << FIXED(7,5) << a << endl;
153
154
155 TFile out(outputFile.c_str(), "recreate");
156
157 g1.SetName("g1");
158
159 out << g1;
160
161 out.Write();
162 out.Close();
163}
string outputFile
void setFormat(const JFormat_t &format)
Set format for given type.
Definition JManip.hh:714
Functional algebra.
int main(int argc, char **argv)
Definition JMechanics.cc:28
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:74
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2140
Double_t g1(const Double_t x)
Function.
Definition JQuantiles.cc:25
Auxiliary class to specify white space character(s) in currect locale.
Utility class to parse command line options.
Definition JParser.hh:1697
char * loc(char *orig)
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition log.hh:13
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448
Data structure for format specifications.
Definition JManip.hh:524
Termination class for polynomial function.
Definition JMathlib.hh:1829