Jpp  18.0.0-rc.3
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 
14 #include "Jeep/JParser.hh"
15 #include "Jeep/JMessage.hh"
16 
17 
18 /**
19  * \file
20  *
21  * Auxiliary application to fit mechanical constants.
22  * \author mdejong
23  */
24 int main(int argc, char **argv)
25 {
26  using namespace std;
27  using namespace JPP;
28 
29  string inputFile;
30  string outputFile;
31  int debug;
32 
33  try {
34 
35  JParser<> zap("Auxiliary application to fit mechanical constants.");
36 
37  zap['f'] = make_field(inputFile, "input file; see https://git.km3net.de/calibration/input_tables");
38  zap['o'] = make_field(outputFile) = "mechanics.root";
39  zap['d'] = make_field(debug) = 1;
40 
41  zap(argc, argv);
42  }
43  catch(const exception &error) {
44  FATAL(error.what() << endl);
45  }
46 
47 
48  const double error = 0.2;
49 
50  TGraphErrors g1;
51 
52  double xmax = 0.0;
53  double ymax = 0.0;
54 
55  {
56  ifstream in(inputFile.c_str());
57 
58  string buffer;
59 
60  getline(in, buffer);
61 
62  DEBUG("Header " << buffer << endl);
63 
64  const locale loc(in.getloc(), new JWhiteSpacesFacet(in.getloc(), ", \t\r\n"));
65 
66  in.imbue(loc);
67 
68  for (double x, y; in >> x >> y; ) {
69 
70  AddPoint(&g1, x, y, 0.0, error);
71 
72  if (x > xmax) {
73  xmax = x;
74  ymax = y;
75  }
76  }
77 
78  in.close();
79  }
80 
81  DEBUG("Number of points " << g1.GetN() << endl);
82 
83 
84  TF1 f1("f1", "[0]*(x + [1]*log(1.0 - [2]*x))");
85 
86  f1.SetParameter(0, ymax / xmax);
87  f1.SetParameter(1, 0.25 * xmax);
88  f1.SetParameter(2, 0.50 / xmax);
89 
90  g1.Fit(&f1);
91  g1.SetName("g1");
92 
93  cout << inputFile << endl;
94 
95  cout << "T_x = " << FIXED(5,2) << f1.GetParameter(0) << " [s^2/m^2] * v_x^2" << endl;
96 
97  cout << "b [m] " << FIXED(7,3) << f1.GetParameter(1) << endl;
98  cout << "a [m^-1] " << FIXED(7,5) << f1.GetParameter(2) << endl;
99 
100  TFile out(outputFile.c_str(), "recreate");
101 
102  out << g1;
103 
104  out.Write();
105  out.Close();
106 }
const double xmax
Definition: JQuadrature.cc:24
Utility class to parse command line options.
Definition: JParser.hh:1514
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:1989
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
Utility class to parse command line options.
char * loc(char *orig)
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] 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:46
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