Jpp  15.0.1-rc.2-highQE
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 
25  string outputFile;
26  string mestimator;
27  bool debug;
28 
29  try {
30 
31  JParser<> zap("Example program to plot various M-Estimators.");
32 
33  zap['o'] = make_field(outputFile) = "mestimator.root";
34  zap['M'] = make_field(mestimator) = "normal", "lorentzian", "tukey", "linear";
35  zap['d'] = make_field(debug);
36 
37  zap(argc, argv);
38  }
39  catch(const exception &error) {
40  FATAL(error.what() << endl);
41  }
42 
43 
44  using namespace JPP;
45 
46  JMEstimator* me = NULL;
47 
48  if (mestimator == "normal")
49  me = new JMEstimatorNormal();
50  else if (mestimator == "lorentzian")
51  me = new JMEstimatorLorentzian();
52  else if (mestimator == "tukey")
53  me = new JMEstimatorTukey(5.0);
54  else if (mestimator == "linear")
55  me = new JMEstimatorLinear();
56  else
57  FATAL("Missing M-Estimator.");
58 
59 
60  TFile out(outputFile.c_str(), "recreate");
61 
62  TH1D h0("rho", NULL, 4000, -10.0, +10.0);
63  TH1D h1("psi", NULL, 4000, -10.0, +10.0);
64 
65  for (int i = 1; i <= h0.GetNbinsX(); ++i) {
66 
67  const double x = h0.GetBinCenter(i);
68 
69  const double rho = me->getRho(x);
70  const double psi = me->getPsi(x);
71 
72  h0.SetBinContent(i, rho);
73  h1.SetBinContent(i, psi);
74  }
75 
76  delete me;
77 
78  out.Write();
79  out.Close();
80 }
Utility class to parse command line options.
Definition: JParser.hh:1500
int main(int argc, char *argv[])
Definition: Main.cc:15
mestimator
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:63
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Utility class to parse command line options.
Maximum likelihood estimator (M-estimators).