Jpp  18.6.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 "Jeep/JParser.hh"
16 #include "Jeep/JMessage.hh"
17 
18 
19 /**
20  * \file
21  *
22  * Auxiliary application to fit mechanical constants.
23  * \author mdejong
24  */
25 int main(int argc, char **argv)
26 {
27  using namespace std;
28  using namespace JPP;
29 
30  string inputFile;
31  string outputFile;
32  int debug;
33 
34  try {
35 
36  JParser<> zap("Auxiliary application to fit mechanical constants.");
37 
38  zap['f'] = make_field(inputFile, "input file; see https://git.km3net.de/calibration/input_tables");
39  zap['o'] = make_field(outputFile) = "mechanics.root";
40  zap['d'] = make_field(debug) = 1;
41 
42  zap(argc, argv);
43  }
44  catch(const exception &error) {
45  FATAL(error.what() << endl);
46  }
47 
48 
49  const double error = 0.2;
50 
51  TGraphErrors g1;
52 
53  double xmax = 0.0;
54  double ymax = 0.0;
55 
56  {
57  ifstream in(inputFile.c_str());
58 
59  string buffer;
60 
61  getline(in, buffer);
62 
63  DEBUG("Header " << buffer << endl);
64 
65  const locale loc(in.getloc(), new JWhiteSpacesFacet(in.getloc(), ", \t\r\n"));
66 
67  in.imbue(loc);
68 
69  for (double x, y; in >> x >> y; ) {
70 
71  AddPoint(&g1, x, y, 0.0, error);
72 
73  if (x > xmax) {
74  xmax = x;
75  ymax = y;
76  }
77  }
78 
79  in.close();
80  }
81 
82  DEBUG("Number of points " << g1.GetN() << endl);
83 
84 
85  TF1 f1("f1", "[0]*(x + [1]*log(1.0 - [2]*x))");
86 
87  f1.SetParameter(0, ymax / xmax);
88  f1.SetParameter(1, 0.25 * xmax);
89  f1.SetParameter(2, 0.50 / xmax);
90 
91  g1.Fit(&f1);
92  g1.SetName("g1");
93 
94  cout << inputFile << endl;
95 
96  cout << "T_x = " << FIXED(5,2) << f1.GetParameter(0) << " [s^2/m^2] * v_x^2" << endl;
97 
98  cout << "b [m] " << FIXED(7,3) << f1.GetParameter(1) << endl;
99  cout << "a [m^-1] " << FIXED(7,5) << f1.GetParameter(2) << endl;
100 
101  TFile out(outputFile.c_str(), "recreate");
102 
103  out << g1;
104 
105  out.Write();
106  out.Close();
107 }
const double xmax
Definition: JQuadrature.cc:24
Utility class to parse command line options.
Definition: JParser.hh:1711
int main(int argc, char *argv[])
Definition: Main.cc:15
void AddPoint(TGraph *g1, const Double_t x, const Double_t y)
Add point to TGraph.
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
string outputFile
const JPolynome f1(1.0, 2.0, 3.0)
Function.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2158
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:478
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
then fatal The output file must have the wildcard in the e g root fi eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:48
Utility class to parse command line options.
char * loc(char *orig)
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
Double_t g1(const Double_t x)
Function.
Definition: JQuantiles.cc:25