1 #ifndef _SINE_SUBTRACT_H 2 #define _SINE_SUBTRACT_H 4 #ifdef DONT_HAVE_MINUIT2 5 #warning "Need Minuit2 for SineSubtract." 106 #include "Minuit2/Minuit2Minimizer.h" 107 #include "FFTtools.h" 156 SineFitterLimits(
double maxA_relative_to_guess_ = 4,
double minA_relative_to_guess_ = 0.25,
157 double max_n_df_relative_to_guess_ = 1,
double phase_start_error_ = TMath::Pi() / 16,
158 double amp_start_error_ = 0.1,
double freq_start_error_ = 0.1) :
191 void setGuess(
double f,
int ntrace,
const double *ph,
double amp);
202 void doFit(
int ntrace,
const int * nsamples,
const double ** x,
const double **y,
const double * w = 0,
const double ** env = 0);
211 const double*
getAmp()
const {
return &[0];}
234 ROOT::Minuit2::Minuit2Minimizer * minimizer() {
return &min; }
246 i = i < 0 ? grEvalRecords.size() - 1 : i;
247 if(i >= 0 && i < grEvalRecords.size()){
248 return grEvalRecords[i];
252 size_t nEvalRecords(){
return grEvalRecords.size();}
253 void SetDoEvalRecord(
bool doEvalRecord){fDoEvalRecord = doEvalRecord;}
254 Bool_t GetDoEvalRecord()
const {
return fDoEvalRecord;}
255 void deleteEvalRecords();
258 ROOT::Minuit2::Minuit2Minimizer min;
260 double eval(
const double *p);
262 std::vector<double> phase;
263 std::vector<double> amp;
265 std::vector<double> phase_err;
266 std::vector<double> amp_err;
268 std::vector<TGraph*> grEvalRecords;
271 double min_amp_mean, max_amp_mean;
272 double min_amp_guess, max_amp_guess;
273 SineFitterLimits limits;
277 #ifndef __CINT__ //CINT is stupid about subclasses 284 class SineFitFn :
public ROOT::Math::IGradientFunctionMultiDim
292 virtual ~SineFitFn();
303 void setXY(
int ntraces,
const int * nsamples,
const double **xx,
const double **yy,
const double * w = 0,
const double ** env = 0);
306 virtual double DoEval(
const double *p)
const;
309 virtual double DoDerivative(
const double *p,
unsigned int coord)
const;
312 unsigned NDim()
const {
return 1+2*nt; }
315 virtual ROOT::Math::IBaseFunctionMultiDim * Clone()
const;
322 #ifdef SINE_SUBTRACT_USE_FLOATS 326 const double **xp, **yp, ***envp;
327 #elif defined(SINE_SUBTRACT_FORCE_ALIGNED) 331 const double **xp, **yp, **envp;
372 std::vector<std::vector<double> >
amps;
404 SineSubtract(
int max_iter_without_reduction = 3,
double min_power_reduction = 0.05,
bool store =
false);
416 SineSubtract(
const TGraph * freq_dependent_min_power_reduction,
int max_iter_without_reduction = 3,
bool store =
false);
431 TGraph * subtractCW(
const TGraph * g,
double dt,
const SineSubtractResult* result = NULL);
446 void subtractCW(
int ng, TGraph ** g,
double dt,
const double * w = 0,
const SineSubtractResult* result = NULL);
453 void setFreqLimits(
double min,
double max) { fmin.clear(); fmin.push_back(min); fmax.clear(); fmax.push_back(max); }
461 void setFreqLimits(
int nbands,
const double * min,
const double * max) { fmin.clear(); fmax.clear();
for (
int i = 0; i < nbands;i++) { fmin.push_back(min[i]); fmax.push_back(max[i]); }; }
511 LS_OVERSAMPLE_FACTOR,
580 enum ENV_HILBERT_Params
582 ENV_HILBERT_FIT_ORDER,
597 ENV_PEAK_MINDISTANCE,
624 TGraph* storedEnvelope(
int i,
int c) {
return env_gs[c][i]; }
636 int getNGraphs()
const {
return r.
phases.size(); }
660 void setMaxIterationsWithoutReduction(
int max) { maxiter = max; }
688 void makePlots(TCanvas * cpower = 0,TCanvas *cspectra = 0,
int ncols = 4)
const;
699 void makeSlides(
const char * title =
"SineSubtract",
const char * prefix =
"sinsub",
const char * outdir =
".",
const char* format =
"png",
bool standalone =
true)
const;
706 double nfail_exponent;
707 int max_successful_iter;
709 std::vector<double> fmin;
710 std::vector<double> fmax;
711 double min_power_reduction;
712 std::vector<std::vector<TGraph*> > gs;
713 std::vector<std::vector<TGraph*> > env_gs;
714 std::vector<TGraph*> spectra;
715 SineSubtractResult r;
720 double * power_estimator_params;
722 double * peak_option_params;
726 double * envelope_option_params;
728 const TGraph * g_min_power;
735 int findMaxFreq(
int Nfreq,
const double * freq,
const double * mag,
const int * nfails)
const;
736 bool allowedFreq(
double f,
double df)
const;