Thermal-FIST 1.5
Package for hadron resonance gas model applications
Loading...
Searching...
No Matches
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
16
17#include <string>
18
21#include "HRGBase/xMath.h"
23
24namespace 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
122 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
163 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; }
291
293
295 void FixVcOverV(bool fix) { m_FixVcToV = fix; }
296 bool FixVcOverV() const { return m_FixVcToV; }
298
300
304 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 void PCEAnnihilation(bool Annihilation) { m_PCEAnnihilation = Annihilation; }
323
325 void SetPCEPionAnnihilationNumber(double PionAnnihilationNumber) { m_PCEPionAnnihilationNumber = PionAnnihilationNumber; }
326
328 std::pair< double, double > ModelDescriptionAccuracy() const;
329
331 static std::vector<FittedQuantity> loadExpDataFromFile(const std::string & filename);
332
333 static void saveExpDataToFile(const std::vector<FittedQuantity> & outQuantities, const std::string & filename);
334
335 private:
336 static std::string GetCurrentTime();
337
338 static std::vector<FittedQuantity> loadExpDataFromFile_OldFormat(std::fstream & fin);
339
340 static std::vector<FittedQuantity> loadExpDataFromFile_NewFormat(std::fstream & fin);
341
342 ThermalModelFitParameters m_Parameters;
343 ThermalModelFitParametersExtended m_ExtendedParameters;
344 ThermalModelBase *m_model;
345 ThermalModelPCE *m_modelpce;
346 std::vector<ExperimentMultiplicity> m_Multiplicities;
347 std::vector<ExperimentRatio> m_Ratios;
348 std::vector<FittedQuantity> m_Quantities;
349 int m_Iters;
350 double m_Chi2;
351 double m_BT;
352 double m_QT;
353 double m_ST;
354 double m_CT;
355 std::vector<double> m_ModelData;
356 int m_Ndf;
357 bool m_FixVcToV;
358 double m_VcOverV;
359
360 bool m_YieldsAtTkin;
361 bool m_SahaForNuclei;
362 bool m_PCEFreezeLongLived;
363 double m_PCEWidthCut;
364 bool m_PCEAnnihilation;
365 double m_PCEPionAnnihilationNumber;
366 };
367
368} // namespace thermalfist
369
370#endif
map< string, double > params
Contains structures describing the yields and ratios used in thermal fits.
Abstract base class for an HRG model implementation.
void AddRatios(const std::vector< ExperimentRatio > &inRatios)
const std::vector< FittedQuantity > & FittedQuantities() const
Return a vector of the fitted quantities (data)
void PCEFreezeLongLived(bool FreezeLongLived)
Sets whether the yields of long-lived resonance are frozen in the PCE.
void AddQuantity(const FittedQuantity &inQuantity)
Same as AddDataPoint()
double & ModelData(int index)
void PrintYieldsLatexAll(std::string filename="Yield.dat", std::string name="A+A", bool asymm=false)
void PrintYieldsLatex(std::string filename="Yield.dat", std::string name="A+A")
void SetParameter(const std::string &name, const FitParameter &param)
Sets the fit parameter with a given name.
void ClearData()
Clear the fitted data.
~ThermalModelFit(void)
Destroy the Thermal Model Fit object.
const std::vector< ExperimentMultiplicity > & Multiplicities() const
void SetParameterFitFlag(const std::string &name, bool toFit)
Sets whether the fit parameter with a given name is fitted.
const std::vector< ExperimentRatio > & Ratios() const
void PrintFitLog(std::string filename="", std::string comment="Thermal fit", bool asymm=false)
Prints the result of the fitting procedure to a file.
void SetData(const std::vector< FittedQuantity > &inData)
Sets the data to fit.
void SetParameters(const ThermalModelFitParameters &params)
Sets the fit parameters.
void SetParameter(const std::string &name, double val, double err, double xmin, double xmax)
Sets the fit parameter with a given name.
void SetQuantities(const std::vector< FittedQuantity > &inQuantities)
Same as SetData()
ThermalModelFit(ThermalModelBase *model)
Construct a new ThermalModelFit object.
void AddMultiplicities(const std::vector< ExperimentMultiplicity > &inMultiplicities)
void PrintParameters()
Print function.
void Increment()
Used by MINUIT.
void ClearQuantities()
Same as ClearData()
void AddData(const std::vector< FittedQuantity > &inData)
Add more data to fit.
static std::vector< FittedQuantity > loadExpDataFromFile(const std::string &filename)
Load the experimental data from a file.
const ThermalModelFitParametersExtended & ExtendedParameters() const
void UseTkin(bool YieldsAtTkin)
Sets whether the yields should be evaluated at Tkin using partial chemical equilibrium.
void AddDataPoint(const FittedQuantity &inDataPoint)
Add one more data point to fit.
void AddMultiplicity(const ExperimentMultiplicity &inMultiplicity)
int GetNdf() const
Number of degrees of freedom in the fit.
void SetRatios(const std::vector< ExperimentRatio > &inRatios)
void AddRatio(const ExperimentRatio &inRatio)
void PCEAnnihilation(bool Annihilation)
Sets whether to include baryon annihilation in PCE.
void AddQuantities(const std::vector< FittedQuantity > &inQuantities)
Same as AddData()
void SetPCEWidthCut(double WidthCut)
Sets the resonance width cut for freezeing the yields of long-lived resonances.
void SetParameterValue(const std::string &name, double value)
Sets the (initial) value for the fit parameter with a given name.
void SetPCEPionAnnihilationNumber(double PionAnnihilationNumber)
Sets the average number of pions in baryon annihilation.
static void saveExpDataToFile(const std::vector< FittedQuantity > &outQuantities, const std::string &filename)
std::pair< double, double > ModelDescriptionAccuracy() const
Returns a relative error of the data description (and its uncertainty estimate)
const ThermalModelFitParameters & Parameters() const
void UseSahaForNuclei(bool UseSaha)
Sets whether the nuclear abundances are evaluated in PCE using the Saha equation.
ThermalModelFitParameters PerformFit(bool verbose=true, bool AsymmErrors=false)
The thermal fit procedure.
void PrintYieldsTable2(std::string filename="Yield.dat")
void SetVcOverV(double VcOverV)
void SetFitFlag(const std::string &name, bool flag)
Set whether FitParameter with a given name should be fitted.
void SetMultiplicities(const std::vector< ExperimentMultiplicity > &inMultiplicities)
void PrintYieldsTable(std::string filename="Yield.dat")
Class implementing HRG in partial chemical equilibrium.
The main namespace where all classes and functions of the Thermal-FIST library reside.
Definition CosmicEoS.h:9
Structure containing the experimental yield (multiplicity) to be fitted.
Structure containing the experimental ratio of yields to be fitted.
Structure for an arbitrary fit parameter.
Structure describing the measurement to be fitted or compared to model.
ExperimentRatio ratio
The ratio data. Used if type is FittedQuantityType::Ratio.
FittedQuantityType type
Whether it is a yield (multiplicity) or a ratio.
ExperimentMultiplicity mult
The yield data. Used if type is FittedQuantityType::Multiplicity.
Extended structure for calculating uncertainties in non-fit quantities resulting from uncertanties in...
Structure holding information about parameters of a thermal fit.
Contains some extra mathematical functions used in the code.