Skip to content

Commit 69eb0f3

Browse files
authored
Merge pull request #52 from vlvovch/devel
Toward version 1.5.2
2 parents 03bbc53 + 69f845e commit 69eb0f3

File tree

8 files changed

+144
-8
lines changed

8 files changed

+144
-8
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
66

7+
## [Version 1.5.2]
8+
9+
Date: 2025-07-23
10+
11+
This update mainly fixes a couple of bugs in event generator mode (thanks to [A. Ohlson](https://github.com/aohlson)).
12+
Namely, it fixes a bug causing infinite loop in the event generator when the number of particles in the event is zero.
13+
This can happen when simulating low-multiplicity proton-proton collisions with local charge conservation.
14+
It also fixes an issue with initialization of Breit-Wigner distributions in the event generator, which could cause invalid_argument exceptions.
15+
16+
## Bugfixes
17+
- Fixed a bug in the event generator causing infinite loop when the number of particles in the event is zero
18+
- Fixed an issue with initialization of Breit-Wigner distributions by properly checking if the width is zero
19+
20+
## Enhancements
21+
- Implemented $m \to 0$ limit for quantum statistics calculations using cluster expansion
22+
- Added additional flag checks for ThermalModelCanonical calculations
23+
724
## [Version 1.5.1]
825

926
Date: 2025-07-06
@@ -350,7 +367,10 @@ Date: 2018-08-02
350367

351368
**The first public version of Thermal-FIST**
352369

370+
[Version 1.5.2]: https://github.com/vlvovch/Thermal-FIST/compare/v1.5.1...v1.5.2
371+
353372
[Version 1.5.1]: https://github.com/vlvovch/Thermal-FIST/compare/v1.5...v1.5.1
373+
354374
[Version 1.5]: https://github.com/vlvovch/Thermal-FIST/compare/v1.4.2...v1.5
355375

356376
[Version 1.4.2]: https://github.com/vlvovch/Thermal-FIST/compare/v1.4.1...v1.4.2

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ project (ThermalFIST)
88
# The version number.
99
set (ThermalFIST_VERSION_MAJOR 1)
1010
set (ThermalFIST_VERSION_MINOR 5)
11-
set (ThermalFIST_VERSION_DEVEL 1)
11+
set (ThermalFIST_VERSION_DEVEL 2)
1212

1313
# configure a header file to pass some of the CMake settings
1414
# to the source code

include/HRGBase/ThermalModelBase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,7 @@ namespace thermalfist {
11451145
int PdgToId(long long pdgid) const { return m_TPS->PdgToId(pdgid); }
11461146

11471147
/// Reset all flags which correspond to a calculation status
1148-
void ResetCalculatedFlags();
1148+
virtual void ResetCalculatedFlags();
11491149

11501150
/// Whether densities had been calculated with
11511151
/// the CalculateDensities() method

include/HRGBase/ThermalModelCanonical.h

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ namespace thermalfist {
127127
*
128128
* \param conserve true -- canonically, false -- grand-canonically
129129
*/
130-
virtual void ConserveBaryonCharge(bool conserve = true) { m_BCE = static_cast<int>(conserve); }
130+
virtual void ConserveBaryonCharge(bool conserve = true) { m_BCE = static_cast<int>(conserve); m_PartialZCalculated = false; }
131131

132132
/**
133133
* \brief Specifies whether the electric charge is treated canonically.
@@ -136,7 +136,7 @@ namespace thermalfist {
136136
*
137137
* \param conserve true -- canonically, false -- grand-canonically
138138
*/
139-
virtual void ConserveElectricCharge(bool conserve = true) { m_QCE = static_cast<int>(conserve); }
139+
virtual void ConserveElectricCharge(bool conserve = true) { m_QCE = static_cast<int>(conserve); m_PartialZCalculated = false; }
140140

141141
/**
142142
* \brief Specifies whether the strangeness charge is treated canonically.
@@ -145,7 +145,7 @@ namespace thermalfist {
145145
*
146146
* \param conserve true -- canonically, false -- grand-canonically
147147
*/
148-
virtual void ConserveStrangeness(bool conserve = true) { m_SCE = static_cast<int>(conserve); }
148+
virtual void ConserveStrangeness(bool conserve = true) { m_SCE = static_cast<int>(conserve); m_PartialZCalculated = false; }
149149

150150
/**
151151
* \brief Specifies whether the charm charge is treated canonically.
@@ -154,7 +154,7 @@ namespace thermalfist {
154154
*
155155
* \param conserve true -- canonically, false -- grand-canonically
156156
*/
157-
virtual void ConserveCharm(bool conserve = true) { m_CCE = static_cast<int>(conserve); }
157+
virtual void ConserveCharm(bool conserve = true) { m_CCE = static_cast<int>(conserve); m_PartialZCalculated = false; }
158158

159159
virtual bool IsConservedChargeCanonical(ConservedCharge::Name charge) const;
160160

@@ -182,6 +182,27 @@ namespace thermalfist {
182182
*/
183183
void SetIntegrationIterationsMultiplier(int multiplier) { (multiplier > 0 ? m_IntegrationIterationsMultiplier = multiplier : m_IntegrationIterationsMultiplier = 1); }
184184

185+
/*
186+
* \brief Reset all flags which correspond to a calculation status
187+
*/
188+
virtual void ResetCalculatedFlags() {
189+
ThermalModelBase::ResetCalculatedFlags();
190+
ResetPartialZCalculated();
191+
}
192+
/*
193+
* \brief Reset the flags indicating whether the partial partition functions are calculated
194+
*/
195+
void ResetPartialZCalculated() { m_PartialZCalculated = false; m_PartialZCalculatedFlucts = false; }
196+
197+
/*
198+
* \brief Whether the partial partition functions are calculated
199+
*/
200+
bool IsPartialZCalculated() const { return m_PartialZCalculated; }
201+
202+
/*
203+
* \brief Whether the partial partition functions are calculated with fluctuations
204+
*/
205+
bool IsPartialZCalculatedFlucts() const { return m_PartialZCalculatedFlucts; }
185206

186207
// Override functions begin
187208

@@ -310,6 +331,9 @@ namespace thermalfist {
310331
* \brief Flag indicating whether the analytical calculation of baryon fugacity is used.
311332
*/
312333
bool m_Banalyt;
334+
335+
bool m_PartialZCalculated;
336+
bool m_PartialZCalculatedFlucts;
313337
};
314338

315339
} // namespace thermalfist

include/HRGBase/Utility.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
#include <string>
19+
#include <map>
1920

2021
namespace thermalfist {
2122

@@ -28,6 +29,43 @@ namespace thermalfist {
2829

2930
};
3031

32+
// Read parameters from a file
33+
/**
34+
* Records the parameters from a file into a map.
35+
*
36+
* The file should contain the parameters in the format:
37+
*
38+
* # comment
39+
* var1 val1 # comment
40+
* var2 val2
41+
* ...
42+
*
43+
* where var1, var2, ... are the parameter names and val1, val2, ... are the parameter values.
44+
*
45+
* The function returns the map with the parameters.
46+
* It overrides the parameters in @params with the parameters from the file.
47+
*
48+
* @param filename The name of the file with the parameters.
49+
* @param params The map with the existing/default parameters.
50+
*
51+
*/
52+
std::map<std::string, std::string> ReadParametersFromFile(const std::string& filename, const std::map<std::string, std::string>& params = {});
53+
54+
/**
55+
* Records the parameters from command line arguments into a map.
56+
*
57+
* --var1 val1 --var2 val2 ...
58+
*
59+
* where var1, var2, ... are the parameter names and val1, val2, ... are the parameter values.
60+
*
61+
* The function writes the parameters to the map.
62+
*
63+
* @param argc The number of command line arguments.
64+
* @param argv The array of command line arguments.
65+
* @param params The map with the existing/default parameters.
66+
*
67+
*/
68+
void ParametersFromArgs(int argc, char* argv[], std::map<std::string, std::string>& params);
3169

3270
// For C99 compatibility
3371
long long stringToLongLong(const std::string &str);

src/examples/NeutronStars/NeutronStars-CSHRG.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ map<string, double> params = {
4141
};
4242

4343
// Read the parameters from file
44-
void ReadParametersFromFile(const std::string &filename)
44+
void ReadParametersFromFileNS(const std::string &filename)
4545
{
4646
if (filename == "")
4747
return;
@@ -77,7 +77,7 @@ int main(int argc, char *argv[])
7777
string params_file = "";
7878
if (argc > 1)
7979
params_file = argv[1];
80-
ReadParametersFromFile(params_file);
80+
ReadParametersFromFileNS(params_file);
8181

8282
bool include_leptons = (params["include_leptons"] != 0.);
8383

src/library/HRGBase/ThermalModelCanonical.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ namespace thermalfist {
3737
m_modelgce = NULL;
3838

3939
m_Banalyt = false;
40+
m_PartialZCalculated = false;
41+
m_PartialZCalculatedFlucts = false;
4042
}
4143

4244

@@ -119,6 +121,7 @@ namespace thermalfist {
119121
ind++;
120122
}
121123

124+
m_PartialZCalculatedFlucts = computeFluctuations;
122125
}
123126

124127
void ThermalModelCanonical::SetStatistics(bool stats) {
@@ -590,6 +593,8 @@ Obtained: %lf\n\
590593
for (size_t iN = 0; iN < m_PartialZ.size(); ++iN) {
591594
m_Corr[iN] = m_PartialZ[iN] / m_PartialZ[m_QNMap[QuantumNumbers(0, 0, 0, 0)]];
592595
}
596+
597+
m_PartialZCalculated = true;
593598
}
594599

595600
double ThermalModelCanonical::ParticleScaledVariance(int part)
@@ -740,6 +745,11 @@ Obtained: %lf\n\
740745
}
741746

742747
void ThermalModelCanonical::CalculateFluctuations() {
748+
if (!m_PartialZCalculatedFlucts) {
749+
CalculateQuantumNumbersRange(true);
750+
CalculatePrimordialDensities();
751+
}
752+
743753
CalculateTwoParticleCorrelations();
744754
CalculateSusceptibilityMatrix();
745755
CalculateTwoParticleFluctuationsDecays();

src/library/HRGBase/Utility.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
#include <iostream>
1111
#include <sstream>
12+
#include <fstream>
13+
#include <limits>
1214

1315
#include "ThermalFISTConfig.h"
1416

@@ -156,6 +158,48 @@ namespace thermalfist {
156158
return ret * mn;
157159
}
158160

161+
std::map<std::string, std::string> ReadParametersFromFile(const std::string& filename, const std::map<std::string, std::string>& params) {
162+
std::map<std::string, std::string> ret = params;
163+
std::ifstream fin(filename);
164+
165+
if (!fin.is_open()) {
166+
std::cout << "Cannot open parameters file!" << "\n";
167+
return ret;
168+
}
169+
170+
std::string var;
171+
std::cout << "Reading input parameters from file " << filename << "\n";
172+
while (fin >> var) {
173+
if (var.size() == 0 || var[0] == '#') {
174+
fin.ignore((std::numeric_limits<std::streamsize>::max)(), '\n');
175+
continue;
176+
}
177+
178+
std::cout << "Reading input parameter " << var << " = ";
179+
std::string val;
180+
fin >> val;
181+
std::cout << val << std::endl;
182+
ret[var] = val;
183+
}
184+
fin.close();
185+
return ret;
186+
}
187+
188+
189+
void ParametersFromArgs(int argc, char *argv[], std::map<std::string, std::string> &params)
190+
{
191+
for(int i = 1; i < argc - 1; i++) {
192+
std::string arg = argv[i];
193+
if (arg.size() <= 2 || arg[0] != '-' || arg[1] != '-') {
194+
continue;
195+
}
196+
std::string var = arg.substr(2);
197+
std::string val = argv[i + 1];
198+
params[var] = val;
199+
i++;
200+
}
201+
}
202+
159203
// Time keeping
160204
// Windows
161205
#ifdef _WIN32

0 commit comments

Comments
 (0)