Jpp  17.0.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JMEstimator.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 
5 #include "TROOT.h"
6 #include "TFile.h"
7 #include "TH1D.h"
8 
9 #include "JFit/JMEstimator.hh"
10 
11 #include "Jeep/JParser.hh"
12 #include "Jeep/JMessage.hh"
13 
14 
15 /**
16  * \file
17  *
18  * Example program to plot various M-Estimators.
19  * \author mdejong
20  */
21 int main(int argc, char **argv)
22 {
23  using namespace std;
24  using namespace JPP;
25 
26  string outputFile;
27  string mestimator;
28  int debug;
29 
30  try {
31 
32  JParser<> zap("Example program to plot various M-Estimators.");
33 
34  zap['o'] = make_field(outputFile) = "mestimator.root";
35  zap['M'] = make_field(mestimator) = "normal", "lorentzian", "tukey", "linear";
36  zap['d'] = make_field(debug) = 2;
37 
38  zap(argc, argv);
39  }
40  catch(const exception &error) {
41  FATAL(error.what() << endl);
42  }
43 
44 
45  JMEstimator* me = NULL;
46 
47  if (mestimator == "normal")
48  me = new JMEstimatorNormal();
49  else if (mestimator == "lorentzian")
50  me = new JMEstimatorLorentzian();
51  else if (mestimator == "tukey")
52  me = new JMEstimatorTukey(5.0);
53  else if (mestimator == "linear")
54  me = new JMEstimatorLinear();
55  else
56  FATAL("Missing M-Estimator.");
57 
58 
59  TFile out(outputFile.c_str(), "recreate");
60 
61  TH1D h0("rho", NULL, 4000, -10.0, +10.0);
62  TH1D h1("psi", NULL, 4000, -10.0, +10.0);
63 
64  for (int i = 1; i <= h0.GetNbinsX(); ++i) {
65 
66  const double x = h0.GetBinCenter(i);
67 
68  const double rho = me->getRho(x);
69  const double psi = me->getPsi(x);
70 
71  h0.SetBinContent(i, rho);
72  h1.SetBinContent(i, psi);
73  }
74 
75  delete me;
76 
77  out.Write();
78  out.Close();
79 }
Utility class to parse command line options.
Definition: JParser.hh:1500
int main(int argc, char *argv[])
Definition: Main.cc:15
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:71
string outputFile
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
int debug
debug level
Definition: JSirene.cc:66
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Utility class to parse command line options.
Maximum likelihood estimator (M-estimators).