Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-04-07 08:08:30

0001 // ConstrainedFitter.h
0002 #ifndef CONSTRAINEDFITTER_H
0003 #define CONSTRAINEDFITTER_H
0004 
0005 #include <iostream>
0006 #include <vector>
0007 #include "TF1.h"
0008 #include "TH1.h"
0009 #include "TMinuit.h"
0010 
0011 #include "CustomHistogramFit/FitFunctions.h"
0012 
0013 class ConstrainedFitter {
0014 public:
0015   ConstrainedFitter(TH1* hist, std::vector<FitFunctions::FitModel> models);
0016   ~ConstrainedFitter();
0017   void SetInitialParams(const std::vector<double>& params);
0018   void SetParamBounds(const std::vector<std::pair<double, double>>& bounds);
0019   void SetFitRange(const std::vector<std::pair<double, double>>& fitRange) { fitRange_ = fitRange; }
0020   void PerformFit();
0021   void PrintResults();
0022   
0023   TF1* GetFitFunction() { return fitFunction_; }
0024   
0025  private:
0026   TH1* hist_;
0027   TF1* fitFunction_;
0028   std::string modelName_;
0029   int nParams_;
0030   std::vector<double> initialParams_;
0031   std::vector<std::pair<double, double>> paramBounds_;
0032   std::vector<std::string> paramNames_;
0033   double paramStep_;
0034 
0035   // (Potentially discontinuous) fitting range
0036   std::vector<std::pair<double,double>> fitRange_;
0037 
0038   // Vector of model functions
0039   std::vector<FitFunctions::modelFunction> singleModelFuns_;
0040   std::vector<int> singleNParams_;
0041   
0042   // Combined model function
0043   std::function<double(const double*, const double*)> CombinedModelFun_;
0044   
0045   void InitializeFunction();
0046 
0047   // Combine all input models in a single sum function
0048   double CombineModelFunctions(const double *x, const double *par);
0049 
0050   // Should be non-static to access hist_, fitFunction_, nParams_ ...
0051   double Chi2Function(const double *par);
0052 };
0053 
0054 #endif