Thermal-FIST  1.3
Package for hadron resonance gas model applications
ThermalParticleSystem.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 THERMALPARTICLESYSTEM_H
9 #define THERMALPARTICLESYSTEM_H
10 
11 #include <map>
12 #include <vector>
13 #include <set>
14 #include <fstream>
15 
17 
18 namespace thermalfist {
19 
30  {
31  public:
32 
42  ThermalParticleSystem(const std::string& InputFile = "", bool GenAntiP = true, double mcut = -1.) { Initialize(InputFile, std::string(""), GenAntiP, mcut); }
43 
54  ThermalParticleSystem(const std::string& InputFile, const std::string& DecayFile, bool GenAntiP = true, double mcut = -1.) { Initialize(InputFile, DecayFile, GenAntiP, mcut); }
55 
56 
78  const std::vector<std::string>& ListFiles,
79  const std::vector<std::string>& DecayFiles = std::vector<std::string>(0),
80  const std::set<std::string>& flags = std::set<std::string>(),
81  double mcut = -1.);
82 
88 
97 
103  void ProcessDecays();
104 
115  void FillDecayProperties();
116 
121  void FillDecayThresholds();
122 
130  void FillResonanceDecays();
131 
138 
139 
143  typedef std::pair<double, int> SingleDecayContribution;
144 
146  typedef std::vector<SingleDecayContribution> DecayContributionsToParticle;
147 
150  typedef std::vector<DecayContributionsToParticle> DecayContributionsToAllParticles;
151 
155  typedef std::pair< std::vector<double>, int> SingleDecayCumulantsContribution;
156 
158  typedef std::vector<SingleDecayCumulantsContribution> DecayCumulantsContributionsToParticle;
159 
162  typedef std::vector<DecayCumulantsContributionsToParticle> DecayCumulantsContributionsToAllParticles;
163 
169  typedef std::pair< std::vector<double>, int> SingleDecayProbabilityDistribution;
170 
172  typedef std::vector<SingleDecayProbabilityDistribution> DecayProbabilityDistributionsToParticle;
173 
176  typedef std::vector<DecayProbabilityDistributionsToParticle> DecayProbabilityDistributionsToAllParticles;
177 
183  typedef std::vector< std::pair<double, std::vector<int> > > ResonanceFinalStatesDistribution;
184 
191  const std::vector<DecayContributionsToAllParticles>& DecayContributionsByFeeddown() const { return m_DecayContributionsByFeeddown; }
192 
201  const DecayCumulantsContributionsToAllParticles& DecayCumulants() const { return m_DecayCumulants; }
202 
209  const std::vector<ResonanceFinalStatesDistribution>& ResonanceFinalStatesDistributions() const { return m_ResonanceFinalStatesDistributions; }
210 
222  void LoadList(const std::vector<std::string>& ListFiles,
223  const std::vector<std::string>& DecayFiles = std::vector<std::string>(0),
224  const std::set<std::string>& flags = std::set<std::string>(),
225  double mcut = 1.e9);
226 
238  void LoadList(const std::string& InputFile, const std::string& DecayFile, bool GenerateAntiParticles = true, double mcut = 1.e9);
239 
252  void LoadList(const std::string& InputFile = "", bool GenerateAntiParticles = true, double mcut = -1.) { LoadList(InputFile, std::string(""), GenerateAntiParticles, mcut); }
253 
254  void AddParticlesToListFromFile(const std::string& InputFile = "", const std::set<std::string>& flags = std::set<std::string>(), double mcut = -1.);
255 
256 
262  void LoadTable(const std::string& InputFile = "", bool GenerateAntiParticles = true, double mcut = -1.) { LoadList(InputFile, GenerateAntiParticles, mcut); }
263 
271  void SetTableFromVector(const std::vector<ThermalParticle> &part_in, bool GenerateAntiParticles = true);
272 
282  void WriteTableToFile(const std::string& OutputFile = "", bool WriteAntiParticles = false);
283 
291  void LoadDecays(const std::vector<std::string>& DecayFiles, const std::set<std::string>& flags = std::set<std::string>());
292 
300  void LoadDecays(const std::string& DecaysFile = "", bool GenerateAntiParticles = true);
301 
308  void WriteDecaysToFile(const std::string& OutputFile = "", bool WriteAntiParticles = false);
309 
316 
321  void RestoreBranchingRatios();
322 
324 
330  IdealGasFunctions::QStatsCalculationType QStatsCalculationType() const { return m_QStatsCalculationType; }
332 
342  void SetClusterExpansionOrder(int order);
343 
345 
354  ThermalParticle::ResonanceWidthShape ResonanceWidthShape() const { return m_ResonanceWidthShape; }
356 
358 
365  ThermalParticle::ResonanceWidthIntegration ResonanceWidthIntegrationType() const { return m_ResonanceWidthIntegrationType; }
367 
378  std::string GetNameFromPDG(long long pdgid);
379 
382  bool hasBaryons() const { return (m_NumBaryons > 0); }
383 
386  bool hasCharged() const { return (m_NumCharged > 0); }
387 
390  bool hasStrange() const { return (m_NumStrange > 0); }
391 
394  bool hasCharmed() const { return (m_NumCharmed > 0); }
395 
397  int ComponentsNumber() const { return static_cast<int>(m_Particles.size()); }
398 
404  const std::vector<ThermalParticle>& Particles() const { return m_Particles; }
405 
407 
414  const ThermalParticle& Particle(int id) const;
415  ThermalParticle& Particle(int id);
417 
428  ThermalParticle& ParticleByPDG(long long pdgid);
429 
438  int PdgToId(long long pdgid) /*const*/ { return (m_PDGtoID.count(pdgid) > 0) ? m_PDGtoID[pdgid] : -1; }
439 
448  long long IdToPdg(int id) const { return (id >= 0 && id < static_cast<int>(m_Particles.size())) ? m_Particles[id].PdgId() : 0; }
449 
457  void AddParticle(const ThermalParticle & part);
458 
465  void RemoveParticleAt(int ind);
466 
470  bool CheckDecayChargesConservation(int ind) const;
471 
475  bool CheckDecayChannelsAreSpecified() const;
476 
482  std::vector<int> CheckDecayChargesConservationVector(int ind) const;
483 
484  bool operator==(const ThermalParticleSystem &rhs) const;
485  bool operator!=(const ThermalParticleSystem &rhs) const { return !(*this == rhs); }
486 
489  void FillPdgMap();
490 
496  };
497 
500  void SetSortMode(SortModeType type) { m_SortMode = type; FinalizeList(); ProcessDecays(); }
501 
503  SortModeType SortMode() const { return m_SortMode; }
504 
509  void FinalizeList();
510 
526 
527  static const std::string flag_no_antiparticles;
528  static const std::string flag_nostrangeness;
529  static const std::string flag_nocharm;
530  static const std::string flag_nonuclei;
531  static const std::string flag_noexcitednuclei;
532 
533  private:
534  void GoResonance(int ind, int startind, double BR);
535 
536  void GoResonanceByFeeddown(int ind, int startind, double BR, Feeddown::Type feeddown);
537 
538  std::vector<double> GoResonanceDecayProbs(int ind, int goalind, bool firstdecay = false);
539 
540  std::vector<double> GoResonanceDecayProbsCharge(int ind, int nch, bool firstdecay = false);
541 
542  ResonanceFinalStatesDistribution GoResonanceDecayDistributions(int ind, bool firstdecay = false);
543 
544  bool AcceptParticle(const ThermalParticle& part, const std::set<std::string>& flags, double mcut = -1.) const;
545 
546  //void LoadTable_OldFormat(std::ifstream &fin, bool GenerateAntiParticles = true, double mcut = 1.e9);
547  void LoadTable_OldFormat(std::ifstream& fin, const std::set<std::string>& flags = std::set<std::string>(), double mcut = 1.e9);
548 
549  //void LoadTable_NewFormat(std::ifstream &fin, bool GenerateAntiParticles = true, double mcut = 1.e9);
550  void LoadTable_NewFormat(std::ifstream& fin, const std::set<std::string>& flags = std::set<std::string>(), double mcut = 1.e9);
551 
552  void ReadDecays_OldFormat(std::ifstream &fin);
553 
554  void ReadDecays_NewFormat(std::ifstream &fin);
555 
556  void Initialize(const std::vector<std::string>& ListFiles,
557  const std::vector<std::string>& DecayFiles = std::vector<std::string>(0),
558  const std::set<std::string>& flags = std::set<std::string>(),
559  double mcut = -1.);
560 
561  void Initialize(const std::string& InputFile = "", const std::string& DecayFile = "", bool GenAntiP = true, double mcut = -1.);
562 
563 
564  private:
565  std::vector<ThermalParticle> m_Particles;
566  std::map<long long, int> m_PDGtoID;
567  int m_NumBaryons;
568  int m_NumCharged;
569  int m_NumStrange;
570  int m_NumCharmed;
571 
572  int m_NumberOfParticles;
573 
574  ThermalParticle::ResonanceWidthIntegration m_ResonanceWidthIntegrationType;
575 
576  ThermalParticle::ResonanceWidthShape m_ResonanceWidthShape;
577 
578  IdealGasFunctions::QStatsCalculationType m_QStatsCalculationType;
579 
580  std::vector<DecayContributionsToAllParticles> m_DecayContributionsByFeeddown;
581 
582  DecayCumulantsContributionsToAllParticles m_DecayCumulants;
583 
584  DecayProbabilityDistributionsToAllParticles m_DecayProbabilities;
585 
586  std::vector<ResonanceFinalStatesDistribution> m_ResonanceFinalStatesDistributions;
587 
588  // Map for DP-based calculations of decay distributions
589  std::vector<ResonanceFinalStatesDistribution> m_DecayDistributionsMap;
590 
591  SortModeType m_SortMode;
592  };
593 
595  namespace CuteHRGHelper {
596  std::vector<std::string> split(const std::string &s, char delim);
597  void cutDecayDistributionsVector(std::vector<std::pair<double, std::vector<int> > > &vect, int maxsize = 1000);
598  }
599 
601  namespace ExtraParticles {
602  const ThermalParticle& Particle(int id);
603  const ThermalParticle& ParticleByPdg(long long pdg);
604  int PdgToId(long long pdg);
605  bool Init();
606  std::string NameByPdg(long long pdg);
607  }
608 
609 } // namespace thermalfist
610 
611 #endif
SortModeType
Mode list to sort particles species.
ThermalParticle::ParticleDecaysVector GetDecaysFromAntiParticle(const ThermalParticle::ParticleDecaysVector &Decays)
Generates the decay channels for an antiparticle based on the provided decay channels of a particle...
static ParticleDecayType::DecayType DecayTypeByParticleType(const ThermalParticle &part)
Determines the decay type of a given particle specie.
std::vector< std::string > split(const std::string &s, char delim)
std::string NameByPdg(long long pdg)
DecayType
Type of particle&#39;s decay.
Definition: ParticleDecay.h:60
std::vector< ParticleDecayChannel > ParticleDecaysVector
Vector of all decay channels of a particle.
const ThermalParticle & Particle(int id) const
ThermalParticle object corresponding to particle species with a provided 0-based index.
bool operator==(const ThermalParticleSystem &rhs) const
std::vector< SingleDecayCumulantsContribution > DecayCumulantsContributionsToParticle
A vector of SingleDecayCumulantsContribution where each element corresponds to a certain resonance sp...
std::pair< std::vector< double >, int > SingleDecayCumulantsContribution
int PdgToId(long long pdgid)
Transforms PDG ID to a 0-based particle id number.
Class containing the particle list.
std::string GetNameFromPDG(long long pdgid)
Get the name of particle species with the specified PDG ID.
static const std::string flag_no_antiparticles
void LoadList(const std::vector< std::string > &ListFiles, const std::vector< std::string > &DecayFiles=std::vector< std::string >(0), const std::set< std::string > &flags=std::set< std::string >(), double mcut=1.e9)
Loads the particle list from file.
void cutDecayDistributionsVector(std::vector< std::pair< double, std::vector< int > > > &vect, int maxsize=1000)
ThermalParticleSystem(const std::string &InputFile="", bool GenAntiP=true, double mcut=-1.)
Construct a new ThermalParticleSystem object.
int ComponentsNumber() const
Number of different particle species in the list.
void SetResonanceWidthShape(ThermalParticle::ResonanceWidthShape shape)
Set (or get) the ThermalParticle::ResonanceWidthShape for all particles.
std::vector< SingleDecayProbabilityDistribution > DecayProbabilityDistributionsToParticle
A vector of SingleDecayProbabilityDistribution where each element corresponds to a certain resonance ...
void WriteDecaysToFile(const std::string &OutputFile="", bool WriteAntiParticles=false)
Writes the decay channels to a file.
ThermalParticle::ResonanceWidthShape ResonanceWidthShape() const
void NormalizeBranchingRatios()
Normalize branching ratios for all particles such that they add up to 100%.
void FillResonanceDecaysByFeeddown()
Same as FillResonanceDecays() but separately for weak, electromagnetic, and strong decay feeddowns...
void SetCalculationType(IdealGasFunctions::QStatsCalculationType type)
Sets the CalculationType() method to evaluate quantum statistics.
void SetTableFromVector(const std::vector< ThermalParticle > &part_in, bool GenerateAntiParticles=true)
Sets the particle list from a provided vector of ThermalParticle objects.
ThermalParticleSystem(const std::string &InputFile, const std::string &DecayFile, bool GenAntiP=true, double mcut=-1.)
Construct a new ThermalParticleSystem object.
std::vector< std::pair< double, std::vector< int > > > ResonanceFinalStatesDistribution
const ThermalParticle & ParticleByPdg(long long pdg)
ResonanceWidthIntegration
Treatment of finite resonance widths.
void SetClusterExpansionOrder(int order)
Set the number of terms in the cluster expansion method.
std::vector< DecayContributionsToParticle > DecayContributionsToAllParticles
Class containing all information about a particle specie.
std::pair< std::vector< double >, int > SingleDecayProbabilityDistribution
ResonanceWidthShape
Relativistic vs non-relativistic Breit-Wigner shape.
std::vector< SingleDecayContribution > DecayContributionsToParticle
A vector of SingleDecayContribution where each element corresponds to a certain resonance species...
std::vector< DecayProbabilityDistributionsToParticle > DecayProbabilityDistributionsToAllParticles
void FillDecayThresholds()
Computes mass thresholds of all decay channels of all particles. Obsolete.
const std::vector< ThermalParticle > & Particles() const
Returns the vector of all particle species.
void RemoveParticleAt(int ind)
Removes particle specie with specified 0-based particle id number from the list.
IdealGasFunctions::QStatsCalculationType QStatsCalculationType() const
const std::vector< ResonanceFinalStatesDistribution > & ResonanceFinalStatesDistributions() const
Final state particle number distributions for resonance decays.
void FillDecayProperties()
Computes and fills decay channels of all particles with extra information.
const DecayCumulantsContributionsToAllParticles & DecayCumulants() const
Cumulants of particle number distributions of from decays.
bool operator!=(const ThermalParticleSystem &rhs) const
void LoadDecays(const std::vector< std::string > &DecayFiles, const std::set< std::string > &flags=std::set< std::string >())
Load the decay channels for all particles from a file.
void FillResonanceDecays()
Computes the decay contributions of decaying resonances to all particle yields.
~ThermalParticleSystem(void)
Destroy the ThermalParticleSystem object.
void LoadTable(const std::string &InputFile="", bool GenerateAntiParticles=true, double mcut=-1.)
Same as LoadList()
std::vector< int > CheckDecayChargesConservationVector(int ind) const
const std::vector< DecayContributionsToAllParticles > & DecayContributionsByFeeddown() const
void AddParticlesToListFromFile(const std::string &InputFile="", const std::set< std::string > &flags=std::set< std::string >(), double mcut=-1.)
std::vector< DecayCumulantsContributionsToParticle > DecayCumulantsContributionsToAllParticles
ThermalParticle::ResonanceWidthIntegration ResonanceWidthIntegrationType() const
void ProcessDecays()
Computes the decay contributions of decaying resonances to all particle yields.
QStatsCalculationType
Identifies whether quantum statistics are to be computed using the cluster expansion or numerical int...
void LoadList(const std::string &InputFile="", bool GenerateAntiParticles=true, double mcut=-1.)
Loads the particle list from file.
void SetResonanceWidthIntegrationType(ThermalParticle::ResonanceWidthIntegration type)
Set (or get) the ThermalParticle::ResonanceWidthIntegration scheme for all particles.
void AddParticle(const ThermalParticle &part)
Adds a new particle specie to the list.
The main namespace where all classes and functions of the Thermal-FIST library reside.
std::pair< double, int > SingleDecayContribution
void WriteTableToFile(const std::string &OutputFile="", bool WriteAntiParticles=false)
Writes the particle list to file.
long long IdToPdg(int id) const
Transforms 0-based particle id number to a PDG ID.
static const std::string flag_noexcitednuclei
static const std::string flag_nostrangeness
void RestoreBranchingRatios()
Restore the original values of all the branching ratios.
SortModeType SortMode() const
Current mode to sort particle species.
ThermalParticle & ParticleByPDG(long long pdgid)
ThermalParticle object corresponding to particle species with a provided PDG ID.