Jpp  18.4.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JGandalfFitAlaMinuitToGauss.cc File Reference

Program to test JFIT::JGandalf algorithm. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include "TROOT.h"
#include "TFile.h"
#include "TF1.h"
#include "TH1D.h"
#include "TMath.h"
#include "JMath/JModel.hh"
#include "JMath/JConstants.hh"
#include "JFit/JGandalf.hh"
#include "JTools/JElement.hh"
#include "JTools/JQuantile.hh"
#include "JROOT/JRootToolkit.hh"
#include "Jeep/JTimer.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Program to test JFIT::JGandalf algorithm.

Author
mdejong

Definition in file JGandalfFitAlaMinuitToGauss.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 109 of file JGandalfFitAlaMinuitToGauss.cc.

110 {
111  using namespace std;
112  using namespace JPP;
113 
114  string outputFile;
115  int numberOfEvents;
116  JGauss gauss;
117  JGauss precision;
118  int debug;
119 
120  try {
121 
122  JParser<> zap("Program to test JGandalf algorithm.");
123 
124  zap['o'] = make_field(outputFile) = "";
125  zap['n'] = make_field(numberOfEvents) = 100;
126  zap['@'] = make_field(gauss) = JGauss(0.0, 1.0, 1000.0, 100.0);
127  zap['e'] = make_field(precision) = JGauss(0.05, 0.05, 25.0, 25.0);
128  zap['d'] = make_field(debug) = 3;
129 
130  zap(argc, argv);
131  }
132  catch(const exception& error) {
133  FATAL(error.what() << endl);
134  }
135 
136  using namespace JFIT;
137 
138  ASSERT(numberOfEvents > 0);
139 
141 
142  TF1 fs("fs", "exp(-0.5 * (x-[0])*(x-[0]) / ([1]*[1]))");
143  TF1 fb("fb", "1.0");
144 
145  fs.FixParameter(0, gauss[0]);
146  fs.FixParameter(1, gauss[1]);
147 
148  const Int_t nx = 21;
149  const Double_t xmin = -5.0;
150  const Double_t xmax = +5.0;
151 
152  JQuantile Q[] = { JQuantile("mean "),
153  JQuantile("sigma "),
154  JQuantile("signal "),
155  JQuantile("background") };
156 
157  TH1D H[] = { TH1D("ha", "", 101, -0.1, +0.1),
158  TH1D("hb", "", 101, -0.1, +0.1),
159  TH1D("hc", "", 101, -100.0, +100.0),
160  TH1D("hd", "", 101, -100.0, +100.0) };
161 
162  JTimer timer;
163 
164  for (int i = 0; i != numberOfEvents; ++i) {
165 
166  STATUS("event: " << setw(10) << i << '\r'); DEBUG(endl);
167 
168  TH1D h0("h0", NULL, nx, xmin, xmax);
169 
170  h0.Sumw2();
171 
172  h0.FillRandom("fs", (Int_t) gauss[2]);
173  h0.FillRandom("fb", (Int_t) gauss[3]);
174 
176 
177  for (Int_t i = 1; i <= h0.GetNbinsX(); ++i) {
178  data.push_back(JElement_t(h0.GetBinCenter (i),
179  h0.GetBinContent(i)));
180  }
181 
182  JGandalf<JGauss> fit;
183 
184  fit.parameters.resize(4);
185 
186  for (size_t i = 0; i != 4; ++i) {
187  fit.parameters[i] = i;
188  }
189 
190  fit.value = JGauss(h0.GetMean(),
191  h0.GetRMS(),
192  h0.GetEntries() * (xmax - xmin) / nx - h0.GetMinimum(),
193  h0.GetMinimum());
194 
195  DEBUG("Start value " << fit.value << endl);
196 
197  timer.start();
198 
199  const double chi2 = fit(g1, data.begin(), data.end());
200 
201  timer.stop();
202 
203  DEBUG("Final value " << fit.value << endl);
204  DEBUG("Chi2 " << chi2 << endl);
205 
206  const double Y[] = { fit.value[0] - gauss[0],
207  fit.value[1] - gauss[1],
208  fit.value[2] * nx / (xmax - xmin) - gauss[2],
209  fit.value[3] * nx - gauss[3] };
210 
211  for (int i = 0; i != sizeof(Q)/sizeof(Q[0]); ++i) {
212  Q[i].put (Y[i]);
213  H[i].Fill(Y[i]);
214  }
215  }
216 
217  for (int i = 0; i != sizeof(Q)/sizeof(Q[0]); ++i) {
218  NOTICE((i == 0 ? longprint : shortprint) << Q[i]);
219  }
220 
221  if (debug >= notice_t) {
222  timer.print(cout, true, micro_t);
223  }
224 
225  if (outputFile != "") {
226 
227  TFile out(outputFile.c_str(), "recreate");
228 
229  for (int i = 0; i != sizeof(H)/sizeof(H[0]); ++i) {
230  out << H[i];
231  }
232 
233  out.Write();
234  out.Close();
235  }
236 
237  for (int i = 0; i != sizeof(Q)/sizeof(Q[0]); ++i) {
238  ASSERT(fabs(Q[i].getMean()) < Q[i].getSTDev());
239  }
240 
241  ASSERT(Q[0].getSTDev() < precision[0]);
242  ASSERT(Q[1].getSTDev() < precision[1]);
243  ASSERT(Q[2].getSTDev() < precision[2]);
244  ASSERT(Q[3].getSTDev() < precision[3]);
245 
246  return 0;
247 }
const double xmax
Definition: JQuadrature.cc:24
Utility class to parse command line options.
Definition: JParser.hh:1514
Q(UTCMax_s-UTCMin_s)-livetime_s
micro
Definition: JScale.hh:29
#define STATUS(A)
Definition: JMessage.hh:63
notice
Definition: JMessage.hh:32
static const double H
Planck constant [eV s].
then fatal Wrong number of arguments fi set_variable STRING $argv[1] set_variable DETECTORXY_TXT $WORKDIR $DETECTORXY_TXT tail read X Y CHI2 RMS printf optimum n $X $Y $CHI2 $RMS awk v Y
string outputFile
double getMean(vector< double > &v)
get mean of vector content
Gauss function object.
Definition: JGauss.hh:173
Place holder for custom implementation.
Definition: JKatoomba_t.hh:726
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
Auxiliary class for CPU timing and usage.
Definition: JTimer.hh:32
#define NOTICE(A)
Definition: JMessage.hh:64
std::ostream & shortprint(std::ostream &out)
Set short printing.
Definition: JManip.hh:144
std::ostream & longprint(std::ostream &out)
Set long printing.
Definition: JManip.hh:172
#define FATAL(A)
Definition: JMessage.hh:67
const double xmin
Definition: JQuadrature.cc:23
Auxiliary data structure for average.
Definition: JKatoomba_t.hh:76
then set_variable NUMBER_OF_TESTS else set_variable NUMBER_OF_TESTS fi function gauss()
then if[[!-f $DETECTOR]] then JDetector sh $DETECTOR fi cat $WORKDIR trigger_parameters txt<< EOFtrigger3DMuon.enabled=1;trigger3DMuon.numberOfHits=5;trigger3DMuon.gridAngle_deg=1;ctMin=0.0;TMaxLocal_ns=15.0;EOF set_variable TRIGGEREFFICIENCY_TRIGGERED_EVENTS_ONLY INPUT_FILES=() for((i=1;$i<=$NUMBER_OF_RUNS;++i));do JSirene.sh $DETECTOR $JPP_DATA/genhen.km3net_wpd_V2_0.evt.gz $WORKDIR/sirene_ ${i}.root JTriggerEfficiency.sh $DETECTOR $DETECTOR $WORKDIR/sirene_ ${i}.root $WORKDIR/trigger_efficiency_ ${i}.root $WORKDIR/trigger_parameters.txt $JPP_DATA/PMT_parameters.txt INPUT_FILES+=($WORKDIR/trigger_efficiency_ ${i}.root) done for ANGLE_DEG in $ANGLES_DEG[*];do set_variable SIGMA_NS 3.0 set_variable OUTLIERS 3 set_variable OUTPUT_FILE $WORKDIR/matrix\[${ANGLE_DEG}\deg\].root $JPP_DIR/examples/JReconstruction-f"$INPUT_FILES[*]"-o $OUTPUT_FILE-S ${SIGMA_NS}-A ${ANGLE_DEG}-O ${OUTLIERS}-d ${DEBUG}--!fiif[[$OPTION=="plot"]];then if((0));then for H1 in h0 h1;do JPlot1D-f"$WORKDIR/matrix["${^ANGLES_DEG}" deg].root:${H1}"-y"1 2e3"-Y-L TR-T""-\^"number of events [a.u.]"-> o chi2
Definition: JMatrixNZ.sh:106
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