Thermal-FIST  1.3
Package for hadron resonance gas model applications
ThermalModelFit.h
Go to the documentation of this file.
1 /*
2  * Thermal-FIST package
3  *
4  * Copyright (c) 2014-2019 Volodymyr Vovchenko
5  *
6  * GNU General Public License (GPLv3 or later)
7  */
8 #ifndef THERMALMODELFIT_H
9 #define THERMALMODELFIT_H
10 
17 #include <string>
18 
21 #include "HRGBase/xMath.h"
22 #include "HRGPCE/ThermalModelPCE.h"
23 
24 namespace thermalfist {
25 
52  {
53  public:
61 
63  ~ThermalModelFit(void);
64 
71  void SetFitFlag(const std::string& name, bool flag) {
72  m_Parameters.SetParameterFitFlag(name, flag);
73  }
74 
75 
76 
79  void SetData(const std::vector<FittedQuantity> & inData) {
80  m_Quantities.resize(0);
81  m_Ratios.resize(0);
82  m_Multiplicities.resize(0);
83  AddData(inData);
84  }
85 
87  void SetQuantities(const std::vector<FittedQuantity> & inQuantities) { SetData(inQuantities); }
88 
92  void AddData(const std::vector<FittedQuantity> & inData) {
93  for (size_t i = 0; i < inData.size(); ++i)
94  AddDataPoint(inData[i]);
95  }
96 
98  void AddQuantities(const std::vector<FittedQuantity> & inQuantities) { AddData(inQuantities); }
99 
103  void AddDataPoint(const FittedQuantity& inDataPoint) {
104  m_Quantities.push_back(inDataPoint);
105  if (inDataPoint.type == FittedQuantity::Ratio)
106  m_Ratios.push_back(inDataPoint.ratio);
107  else
108  m_Multiplicities.push_back(inDataPoint.mult);
109  }
110 
112  void AddQuantity(const FittedQuantity& inQuantity) { AddDataPoint(inQuantity); }
113 
115  void ClearData() { m_Quantities.resize(0); }
116 
119 
121  void SetRatios(const std::vector<ExperimentRatio> & inRatios) {
123  m_Ratios = inRatios;
124  }
125 
126  void AddRatios(const std::vector<ExperimentRatio> & inRatios) {
127  m_Ratios.insert(m_Ratios.end(), inRatios.begin(), inRatios.end());
128  for (size_t i = 0; i < inRatios.size(); i++) {
129  m_Quantities.push_back(FittedQuantity(inRatios[i]));
130  }
131  }
132 
133  void AddRatio(const ExperimentRatio& inRatio) {
134  m_Ratios.push_back(inRatio);
135  m_Quantities.push_back(FittedQuantity(inRatio));
136  }
137 
138  void ClearRatios() { m_Ratios.resize(0); }
139 
140  void PrintRatios();
141 
142  void SetMultiplicities(const std::vector<ExperimentMultiplicity> & inMultiplicities) {
143  m_Multiplicities = inMultiplicities;
144  }
145 
146  void AddMultiplicities(const std::vector<ExperimentMultiplicity> & inMultiplicities) {
147  m_Multiplicities.insert(m_Multiplicities.end(), inMultiplicities.begin(), inMultiplicities.end());
148  for (size_t i = 0; i < inMultiplicities.size(); i++) {
149  m_Quantities.push_back(FittedQuantity(inMultiplicities[i]));
150  }
151  }
152 
153  void AddMultiplicity(const ExperimentMultiplicity& inMultiplicity) {
154  m_Multiplicities.push_back(inMultiplicity);
155  m_Quantities.push_back(FittedQuantity(inMultiplicity));
156  }
157 
158  void ClearMultiplicities() { m_Multiplicities.resize(0); }
160 
162  void PrintParameters();
164 
165  void PrintMultiplicities();
166 
167  void PrintYields();
168 
169  void PrintYieldsTable(std::string filename = "Yield.dat");
170 
171  void PrintYieldsTable2(std::string filename = "Yield.dat");
172 
173  void PrintYieldsLatex(std::string filename = "Yield.dat", std::string name = "A+A");
174 
175  void PrintYieldsLatexAll(std::string filename = "Yield.dat", std::string name = "A+A", bool asymm = false);
177 
179  void PrintFitLog(std::string filename = "", std::string comment = "Thermal fit", bool asymm = false);
180 
181  //double chi2Ndf(double T, double muB);
182 
198  ThermalModelFitParameters PerformFit(bool verbose = true, bool AsymmErrors = false);
199 
201  int GetNdf() const;
202 
204  void Increment() { m_Iters++; }
205 
208  const ThermalModelFitParameters& Parameters() const { return m_Parameters; }
209 
211  void SetParameters(const ThermalModelFitParameters& params) { m_Parameters = params; }
212 
214  void SetParameter(const std::string & name, const FitParameter & param) { m_Parameters.SetParameter(name, param); }
215 
217  void SetParameter(const std::string & name, double val, double err, double xmin, double xmax) { m_Parameters.SetParameter(name, val, err, xmin, xmax); }
218 
220  void SetParameterValue(const std::string & name, double value) { m_Parameters.SetParameterValue(name, value); }
221 
223  void SetParameterFitFlag(const std::string & name, bool toFit) { m_Parameters.SetParameterFitFlag(name, toFit); }
224 
225 
226  const ThermalModelFitParametersExtended& ExtendedParameters() const { return m_ExtendedParameters; }
227 
230  ThermalModelBase* model() { return m_model; }
231 
234  ThermalModelPCE* modelpce() { return m_modelpce; }
235 
238  void SetSBConstraint(double SB) {
239  if (m_model != NULL)
240  m_model->SetSoverB(SB);
241  m_model->ConstrainMuB(true);
242  }
243 
246  void SetQBConstraint(double QB) {
247  if (m_model != NULL)
248  m_model->SetQoverB(QB);
249  m_model->ConstrainMuQ(true);
250  }
251 
253  double SoverB() const { return m_model->SoverB(); }
255  double QoverB() const { return m_model->QoverB(); }
256 
259  const std::vector<ExperimentMultiplicity>& Multiplicities() const { return m_Multiplicities; }
260 
263  const std::vector<ExperimentRatio>& Ratios() const { return m_Ratios; }
264 
266  const std::vector<FittedQuantity>& FittedQuantities() const { return m_Quantities; }
267 
271  int& Iters() { return m_Iters; }
272 
273  double& Chi2() { return m_Chi2; }
274 
275  double& BT() { return m_BT; }
276 
277  double& QT() { return m_QT; }
278 
279  double& ST() { return m_ST; }
280 
281  double& CT() { return m_CT; }
282 
283  double& ModelData(int index) { return m_ModelData[index]; }
284 
285  int ModelDataSize() const { return m_ModelData.size(); }
286 
287  void ClearModelData() { m_ModelData.clear(); }
288 
289  int& Ndf() { return m_Ndf; }
293  void FixVcOverV(bool fix) { m_FixVcToV = fix; }
296  bool FixVcOverV() const { return m_FixVcToV; }
298 
300  void SetVcOverV(double VcOverV) { m_VcOverV = VcOverV; }
305  double VcOverV() const { return m_VcOverV; }
307 
309  void UseTkin(bool YieldsAtTkin) { m_YieldsAtTkin = YieldsAtTkin; }
310  bool UseTkin() const { return m_YieldsAtTkin; }
311 
313  void UseSahaForNuclei(bool UseSaha) { m_SahaForNuclei = UseSaha; }
314 
316  void PCEFreezeLongLived(bool FreezeLongLived) { m_PCEFreezeLongLived = FreezeLongLived; }
317 
319  void SetPCEWidthCut(double WidthCut) { m_PCEWidthCut = WidthCut; }
320 
322  std::pair< double, double > ModelDescriptionAccuracy() const;
323 
325  static std::vector<FittedQuantity> loadExpDataFromFile(const std::string & filename);
326 
327  static void saveExpDataToFile(const std::vector<FittedQuantity> & outQuantities, const std::string & filename);
328 
329  private:
330  static std::string GetCurrentTime();
331 
332  static std::vector<FittedQuantity> loadExpDataFromFile_OldFormat(std::fstream & fin);
333 
334  static std::vector<FittedQuantity> loadExpDataFromFile_NewFormat(std::fstream & fin);
335 
336  ThermalModelFitParameters m_Parameters;
337  ThermalModelFitParametersExtended m_ExtendedParameters;
338  ThermalModelBase *m_model;
339  ThermalModelPCE *m_modelpce;
340  std::vector<ExperimentMultiplicity> m_Multiplicities;
341  std::vector<ExperimentRatio> m_Ratios;
342  std::vector<FittedQuantity> m_Quantities;
343  int m_Iters;
344  double m_Chi2;
345  double m_BT;
346  double m_QT;
347  double m_ST;
348  double m_CT;
349  std::vector<double> m_ModelData;
350  int m_Ndf;
351  bool m_FixVcToV;
352  double m_VcOverV;
353 
354  bool m_YieldsAtTkin;
355  bool m_SahaForNuclei;
356  bool m_PCEFreezeLongLived;
357  double m_PCEWidthCut;
358  };
359 
360 } // namespace thermalfist
361 
362 #endif
Abstract base class for an HRG model implementation.
void Increment()
Used by MINUIT.
void SetVcOverV(double VcOverV)
void SetRatios(const std::vector< ExperimentRatio > &inRatios)
const std::vector< ExperimentRatio > & Ratios() const
void UseSahaForNuclei(bool UseSaha)
Sets whether the nuclear abundances are evaluated in PCE using the Saha equation. ...
Class implementing HRG in partial chemical equilibrium.
void ClearData()
Clear the fitted data.
Contains structures describing the yields and ratios used in thermal fits.
void SetPCEWidthCut(double WidthCut)
Sets the resonance width cut for freezeing the yields of long-lived resonances.
FittedQuantityType type
Whether it is a yield (multiplicity) or a ratio.
void AddData(const std::vector< FittedQuantity > &inData)
Add more data to fit.
void SetParameter(const std::string &name, const FitParameter &param)
Sets the fit parameter with a given name.
void AddRatio(const ExperimentRatio &inRatio)
void SetQuantities(const std::vector< FittedQuantity > &inQuantities)
Same as SetData()
void ClearQuantities()
Same as ClearData()
const ThermalModelFitParametersExtended & ExtendedParameters() const
Structure describing the measurement to be fitted or compared to model.
~ThermalModelFit(void)
Destroy the Thermal Model Fit object.
ThermalModelBase * model()
void UseTkin(bool YieldsAtTkin)
Sets whether the yields should be evaluated at Tkin using partial chemical equilibrium.
void AddRatios(const std::vector< ExperimentRatio > &inRatios)
void AddMultiplicities(const std::vector< ExperimentMultiplicity > &inMultiplicities)
void PrintYieldsLatex(std::string filename="Yield.dat", std::string name="A+A")
void SetQoverB(double QB)
The electric-to-baryon charge ratio to be used to constrain the electric chemical potential...
Contains some extra mathematical functions used in the code.
void AddMultiplicity(const ExperimentMultiplicity &inMultiplicity)
Class implementing the thermal model fit procedure.
void PrintFitLog(std::string filename="", std::string comment="Thermal fit", bool asymm=false)
Prints the result of the fitting procedure to a file.
ExperimentMultiplicity mult
The yield data. Used if type is FittedQuantityType::Multiplicity.
void SetParameters(const ThermalModelFitParameters &params)
Sets the fit parameters.
ExperimentRatio ratio
The ratio data. Used if type is FittedQuantityType::Ratio.
Structure containing the experimental ratio of yields to be fitted.
void PCEFreezeLongLived(bool FreezeLongLived)
Sets whether the yields of long-lived resonance are frozen in the PCE.
ThermalModelFit(ThermalModelBase *model)
Construct a new ThermalModelFit object.
const std::vector< ExperimentMultiplicity > & Multiplicities() const
Extended structure for calculating uncertainties in non-fit quantities resulting from uncertanties in...
const ThermalModelFitParameters & Parameters() const
double & ModelData(int index)
ThermalModelPCE * modelpce()
void SetParameterFitFlag(const std::string &name, bool toFit)
Sets whether the fit parameter with a given name is fitted.
int GetNdf() const
Number of degrees of freedom in the fit.
void SetParameterFitFlag(const std::string &name, bool toFit)
Set whether the FitParameter with a given name should be fitted.
Structure holding information about parameters of a thermal fit.
Structure for an arbitrary fit parameter.
void SetSoverB(double SB)
The entropy per baryon ratio to be used to constrain the baryon chemical potential.
void PrintYieldsTable2(std::string filename="Yield.dat")
void SetData(const std::vector< FittedQuantity > &inData)
Sets the data to fit.
void PrintYieldsLatexAll(std::string filename="Yield.dat", std::string name="A+A", bool asymm=false)
void AddQuantities(const std::vector< FittedQuantity > &inQuantities)
Same as AddData()
static std::vector< FittedQuantity > loadExpDataFromFile(const std::string &filename)
Load the experimental data from a file.
void SetParameterValue(const std::string &name, double value)
Set the value of the FitParameter with a given name.
void SetMultiplicities(const std::vector< ExperimentMultiplicity > &inMultiplicities)
static void saveExpDataToFile(const std::vector< FittedQuantity > &outQuantities, const std::string &filename)
ThermalModelFitParameters PerformFit(bool verbose=true, bool AsymmErrors=false)
The thermal fit procedure.
void AddQuantity(const FittedQuantity &inQuantity)
Same as AddDataPoint()
void PrintYieldsTable(std::string filename="Yield.dat")
void SetFitFlag(const std::string &name, bool flag)
Set whether FitParameter with a given name should be fitted.
const std::vector< FittedQuantity > & FittedQuantities() const
Return a vector of the fitted quantities (data)
void PrintParameters()
Print function.
void AddDataPoint(const FittedQuantity &inDataPoint)
Add one more data point to fit.
Structure containing the experimental yield (multiplicity) to be fitted.
The main namespace where all classes and functions of the Thermal-FIST library reside.
void SetParameter(const std::string &name, double val, double err, double xmin, double xmax)
Sets the fit parameter with a given name.
void SetParameter(const std::string &name, const FitParameter &param)
Set the FitParameter with a given name from a copy.
void SetParameterValue(const std::string &name, double value)
Sets the (initial) value for the fit parameter with a given name.
std::pair< double, double > ModelDescriptionAccuracy() const
Returns a relative error of the data description (and its uncertainty estimate)