9#include <framework/particledb/EvtGenDatabasePDG.h>
10#include <framework/particledb/EvtGenParticlePDG.h>
11#include <framework/logging/Logger.h>
12#include <framework/gearbox/Unit.h>
13#include <framework/gearbox/Const.h>
14#include <framework/utilities/FileSystem.h>
21#include <TInterpreter.h>
27 static bool instanceCreated =
false;
28 if (!instanceCreated) {
31 gInterpreter->Declare(
"#include <framework/particledb/EvtGenParticlePDG.h>");
35 instance->ReadEvtGenTable();
36 instanceCreated =
true;
37 if (instance != TDatabasePDG::Instance())
38 B2FATAL(
"EvtGenDatabasePDG created too late!");
45 Double_t charge,
const char* ParticleClass, Int_t PDGcode, Int_t Anti, Int_t TrackingCode,
46 Double_t Lifetime, Double_t Spin, Double_t maxWidth, Int_t pythiaID)
57 TParticlePDG* old = GetParticle(PDGcode);
60 B2ERROR(
"EvtGenDatabasePDG::AddParticle: particle with PDGcode=" << PDGcode <<
" already defined");
64 if (std::strpbrk(name,
" \t\n\v\f\r")) {
65 B2ERROR(
"EvtGenDatabasePDG::AddParticle: invalid particle name '" << name <<
"'. Names may not contain Whitespace");
69 auto* p =
new EvtGenParticlePDG(name, title, mass, stable, width, charge, ParticleClass,
70 PDGcode, Anti, TrackingCode, Lifetime, Spin, maxWidth, pythiaID);
72 fParticleList->Add(p);
74 fPdgMap->Add((Long_t)PDGcode, (Long_t)p);
76 TParticleClassPDG* pclass = GetParticleClass(ParticleClass);
79 pclass =
new TParticleClassPDG(ParticleClass);
80 fListOfClasses->Add(pclass);
83 pclass->AddParticle(p);
92 if (defaultFilename.empty())
93 B2FATAL(
"Cannot find the default particle database file (evt.pdl).");
95 filename = defaultFilename.c_str();
97 if (filename != defaultFilename) {
98 B2RESULT(
"Loading non-standard evt.pdl file '" << filename <<
"'");
103 if (fParticleList ==
nullptr) {
105 fParticleList =
new THashList;
106 fListOfClasses =
new TObjArray;
109 fParticleList->Delete();
110 fListOfClasses->Delete();
115 std::ifstream indec(filename);
117 char cmnd[100], xxxx[100], pname[100];
119 double mass, pwidth, pmaxwidth;
125 B2ERROR(
"EvtGenDatabasePDG::ReadEvtGenTable: Could not particle data file '" << filename <<
"'");
129 std::map<int, TParticlePDG*> pdgToPartMap;
137 if (ch ==
'\n') indec.get(ch);
141 while (indec.get(ch1), ch1 !=
'\n');
147 if (strcmp(cmnd,
"end")) {
149 if (!strcmp(cmnd,
"add")) {
151 indec >> xxxx >> xxxx >> pname >> stdhepid;
152 indec >> mass >> pwidth >> pmaxwidth >> chg3 >> spin2 >> ctau >> lundkc;
155 TParticlePDG* part =
AddParticle(pname, pname, mass,
false, pwidth, chg3,
"Unknown", stdhepid, 0, 0,
156 ctau / c_mm_per_s, spin2 / 2.0, pmaxwidth, lundkc);
157 pdgToPartMap[stdhepid] = part;
159 B2FATAL(
"EvtGenDatabasePDG::ReadPDGTable: Problem creating particle '" << pname <<
"'");
163 }
while (strcmp(cmnd,
"end"));
166 for (
auto entry : pdgToPartMap) {
167 int pdg = entry.first;
168 TParticlePDG* part = entry.second;
170 const auto& antiPartIter = pdgToPartMap.find(-pdg);
171 if (antiPartIter != pdgToPartMap.end()) {
173 part->SetAntiParticle(antiPartIter->second);
176 part->SetAntiParticle(part);
185 for (TObject* obj : *fParticleList) {
188 B2FATAL(
"EvtGenDatabasePDG::WriteEvtgenTable: Particle does not inherit from EventGenParticlePDG");
190 out <<
"add p Particle " << part->GetName() <<
" " << part->PdgCode()
191 <<
" " << std::scientific << std::setprecision(7) << part->Mass()
192 <<
" " << std::scientific << std::setprecision(7) << part->Width()
193 <<
" " << std::scientific << std::setprecision(7) << part->MaxWidth()
194 <<
" " << (int)(part->Charge())
195 <<
" " << (
int)(part->Spin() * 2)
196 <<
" " << std::scientific << std::setprecision(7) << part->Lifetime() * c_mm_per_s
197 <<
" " << part->PythiaID()
201 out <<
"end" << std::endl << std::flush;
206 std::ofstream out(filename);
208 B2FATAL(
"Cannot write evtgen pdl to '" << filename <<
"'");
static const double speedOfLight
[cm/ns]
Replacement for TDatabasePDG that is filled from EvtGen's evt.pdl.
static EvtGenDatabasePDG * Instance()
Instance method that loads the EvtGen table.
void WriteEvtGenTable(std::ostream &out)
Write current database as EvtGen table to a stream.
EvtGenDatabasePDG()
singleton.
void ReadEvtGenTable(const char *filename=nullptr)
Read EvtGen table.
TParticlePDG * AddParticle(const char *name, const char *title, Double_t mass, Bool_t stable, Double_t width, Double_t charge, const char *ParticleClass, Int_t PDGcode, Int_t Anti, Int_t TrackingCode) override
override old AddParticle
Helper class for setting additional TParticlePDG members and storing the ones it doesn't have yet.
static std::string findFile(const std::string &path, bool silent=false)
Search for given file or directory in local or central release directory, and return absolute path if...
static const double mm
[millimeters]
static const double s
[second]
Abstract base class for different kinds of events.