283 std::vector<Double_t> events_;
284 Float_t fit_range_low_;
285 Float_t fit_range_high_;
286 Float_t display_bin_width_kev_;
288 Bool_t use_flat_background_;
290 Bool_t use_low_exp_tail_;
291 Bool_t use_low_lin_tail_;
292 Bool_t use_high_exp_tail_;
294 Bool_t use_manual_init_;
298 Bool_t refit_after_load_ = kFALSE;
301 Double_t tail_ratio_max_ = 100.0;
302 std::vector<Double_t> manual_params_;
305 RooDataSet *unbinned_data_;
306 RooAddPdf *total_pdf_;
309 std::vector<RooFitPeakModel> peaks_;
311 std::vector<RooAbsArg *> owned_args_;
313 std::vector<RooFitChannelConfig> sim_channels_;
314 std::vector<RooFitParamLink> sim_links_;
315 std::vector<RooFitSeparationConstraint> sim_sep_constraints_;
316 RooArgSet sim_constraint_set_;
317 std::map<TString, FitResult> sim_seeds_;
318 std::map<TString, std::vector<RooFitPeakModel>> sim_channel_peaks_;
319 std::map<TString, RooFitBackgroundModel> sim_channel_bkg_;
320 std::map<TString, RooAbsPdf *> sim_channel_pdfs_;
321 std::map<TString, RooDataSet *> sim_channel_data_;
322 std::map<TString, TString> sim_channel_range_names_;
323 RooCategory *sim_category_;
324 RooSimultaneous *sim_pdf_;
325 RooDataSet *sim_combined_data_;
329 void BuildDisplayHistogram();
330 void BuildUnbinnedData();
331 static RooDataSet *BuildUnbinnedDataFrom(
const std::vector<Double_t> &events,
333 RooRealVar *ResolveOrCreate(
const TString &channel,
const TString ¶m_name,
334 std::map<TString, RooRealVar *> ®istry,
335 Double_t init_val, Double_t lo, Double_t hi);
337 std::map<TString, RooRealVar *> ®istry);
338 void ApplySeedToChannel(
const TString &channel);
339 void ApplyChannelMuLocks();
340 void ApplyChannelBkgLocks();
341 void ApplyChannelShapeLocks();
342 void SaveSimInteractiveParams(
const TString &input_name,
343 const TString &base_label);
344 Bool_t LoadSimInteractiveParams(
const TString &input_name,
345 const TString &base_label);
346 TString ParamFullName(
const TString &channel,
const TString ¶m);
347 TString SourceForTarget(
const TString &target);
348 void BuildSeparationConstraints();
349 Double_t ComputeChannelChi2(
const TString &channel,
350 const std::vector<RooFitPeakModel> &peaks,
352 void PlotChannel(
const TString &channel, Int_t num_peaks,
353 const std::vector<RooFitPeakModel> &peaks,
355 const TString &base_label,
const TString &chi2_label);
358 Double_t EstimateBackground();
360 void BuildPeak(Int_t peak_idx, Double_t mu_init, Double_t sigma_init,
361 Double_t peak_height, Double_t range_width);
362 void BuildBackground(Double_t bkg_estimate, Double_t peak_height,
363 Double_t range_width);
364 void BuildTotalModel();
365 void ConfigureComponentFlagsForPeak(Int_t peak_idx);
367 void FixComponent(Int_t peak_idx,
const TString &component);
368 void ReleaseComponent(Int_t peak_idx,
const TString &component);
369 Bool_t ComponentIsActive(Int_t peak_idx,
const TString &component);
371 std::vector<RooRealVar *> CollectFloatingParams();
372 std::vector<RooRealVar *> CollectAllParams();
373 RooFitResult *RunFit(Bool_t quiet);
374 Double_t ComputeReducedChi2(RooFitResult *fit_result, Int_t &ndof);
376 void SnapshotParams(std::vector<Double_t> &vals, std::vector<Double_t> &errs,
377 std::vector<Bool_t> &consts);
378 void RestoreParams(
const std::vector<Double_t> &vals,
379 const std::vector<Double_t> &errs,
380 const std::vector<Bool_t> &consts);
381 void TestLowSideGroup(Int_t peak_idx, Double_t &best_chi2,
382 std::vector<Double_t> &best_vals,
383 std::vector<Double_t> &best_errs,
384 std::vector<Bool_t> &best_const);
385 void TestHighTailIndependent(Int_t peak_idx, Double_t &best_chi2,
386 std::vector<Double_t> &best_vals,
387 std::vector<Double_t> &best_errs,
388 std::vector<Bool_t> &best_const);
394 std::vector<FitParameterDiagnostic>
395 ExtractParameterDiagnostics(
const TString &channel);
398 std::vector<FitParameterDiagnostic> ExtractParameterDiagnosticsSingle();
400 void SaveInteractiveParams(
const TString &input_name,
401 const TString &peak_name);
402 Bool_t LoadInteractiveParams(
const TString &input_name,
403 const TString &peak_name);
404 void AdoptSavedRange(
const TString &input_name,
const TString &peak_name);
405 void AdoptSavedSimRange(
const TString &input_name,
const TString &base_label);
407 void SortPeaksByMu(Int_t num_peaks);
408 void AppendPeakGraphs(std::vector<TGraph *> &components, Int_t peak_idx,
409 Style_t line_style, RooAbsPdf *background_pdf,
410 Double_t bkg_yield_val, Int_t npts, Double_t x_step,
413 void RegisterOwned(RooAbsArg *arg);
442 RooFitUtils(
const std::vector<Double_t> &events, Float_t fit_range_low,
443 Float_t fit_range_high, Float_t display_bin_width_kev,
444 Bool_t use_flat_background = kFALSE, Bool_t use_step = kFALSE,
445 Bool_t use_low_exp_tail = kFALSE,
446 Bool_t use_low_lin_tail = kFALSE,
447 Bool_t use_high_exp_tail = kFALSE);
458 const TString &branch_name);
468 Float_t fit_range_low,
469 Float_t fit_range_high,
470 Float_t display_bin_width_kev);
484 const std::vector<Double_t> &events,
485 Float_t fit_range_low,
486 Float_t fit_range_high,
487 Float_t display_bin_width_kev);
492 use_flat_background_ = use_flat_background;
496 void SetStep(Bool_t use_step = kTRUE) { use_step_ = use_step; }
500 use_low_exp_tail_ = use_low_exp_tail;
505 use_low_lin_tail_ = use_low_lin_tail;
510 use_high_exp_tail_ = use_high_exp_tail;
525 interactive_ = interactive;
536 void SetFitDebug(Bool_t fit_debug = kTRUE) { fit_debug_ = fit_debug; }
588 use_manual_init_ = kFALSE;
589 manual_params_.clear();
599 const TString label =
"");
607 const TString label =
"");
615 const TString label =
"");
646 Double_t mu1_init, Double_t mu2_init,
647 Bool_t link_sigma = kFALSE);
710 const TString &name,
const std::vector<Double_t> &events,
711 Float_t fit_range_low, Float_t fit_range_high,
712 Float_t display_bin_width_kev, Int_t num_peaks,
713 const std::vector<Double_t> &mu_inits,
714 Bool_t use_flat_background = kFALSE, Bool_t use_step = kFALSE,
715 Bool_t use_low_exp_tail = kFALSE, Bool_t use_low_lin_tail = kFALSE,
716 Bool_t use_high_exp_tail = kFALSE,
717 const std::vector<Bool_t> &mu_fixed = std::vector<Bool_t>(),
718 Bool_t bkg_yield_fixed = kFALSE, Bool_t bkg_slope_fixed = kFALSE,
719 Bool_t lock_shape_after_seed = kFALSE,
720 const std::vector<Bool_t> &use_step_per_peak = std::vector<Bool_t>(),
721 const std::vector<Bool_t> &shape_lock_per_peak = std::vector<Bool_t>());
727 void LinkParameter(
const TString &target,
const TString &source);
744 Int_t peak_lo, Double_t delta, Double_t sigma);
756 void LinkPeakShape(
const TString &target_channel, Int_t target_peak,
757 const TString &source_channel, Int_t source_peak);
785 const TString &base_label);
806 void DumpChannelCSV(
const TString &channel,
const TString &csv_path,