This example implements a simultaneous fit using three unidimensional Gaussian functions, with the mean as a common parameter
#ifndef SIMULTANEOUS_FIT_INL_
#define SIMULTANEOUS_FIT_INL_
#include <iostream>
#include <assert.h>
#include <time.h>
#include <chrono>
#include <random>
#include <algorithm>
#include <tclap/CmdLine.h>
#include "Minuit2/FunctionMinimum.h"
#include "Minuit2/MnUserParameterState.h"
#include "Minuit2/MnPrint.h"
#include "Minuit2/MnMigrad.h"
#include "Minuit2/MnMinimize.h"
try {
TCLAP::CmdLine cmd("Command line arguments for ", '=');
TCLAP::ValueArg < size_t >
EArg(
"n",
"number-of-events",
"Number of events", true, 10e6, "size_t");
} catch (TCLAP::ArgException &e) {
std::cerr << "error: " << e.error() << " for arg " << e.argId()
<< std::endl;
}
{
return bool (x >=
min) && (x<
max);
};
ROOT::Minuit2::MnPrint::SetGlobalLevel(3);
MnMigrad migrad(sim_fcn, sim_fcn.GetParameters().GetMnState(),
strategy);
std::cout << sim_fcn.GetParameters().GetMnState() << std::endl;
auto start = std::chrono::high_resolution_clock::now();
FunctionMinimum minimum = FunctionMinimum( migrad(500, 1));
auto stop = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli>
elapsed = stop -
start;
std::cout << " minimum: " << minimum << std::endl;
std::cout << "-----------------------------------------"<<std::endl;
std::cout <<
"| Time (ms) ="<<
elapsed.count() <<std::endl;
std::cout << "-----------------------------------------"<<std::endl;
}
return 0;
}
#endif