11 #include <framework/particledb/EvtGenDatabasePDG.h>
12 #include <framework/particledb/EvtGenParticlePDG.h>
13 #include <framework/logging/Logger.h>
14 #include <framework/gearbox/Unit.h>
15 #include <framework/gearbox/Const.h>
16 #include <framework/utilities/FileSystem.h>
21 #include <THashList.h>
23 #include <TInterpreter.h>
29 static bool instanceCreated =
false;
30 if (!instanceCreated) {
33 gInterpreter->Declare(
"#include <framework/particledb/EvtGenParticlePDG.h>");
37 instance->ReadEvtGenTable();
38 instanceCreated =
true;
39 if (instance != TDatabasePDG::Instance())
40 B2FATAL(
"EvtGenDatabasePDG created too late!");
47 Double_t charge,
const char* ParticleClass, Int_t PDGcode, Int_t Anti, Int_t TrackingCode,
48 Double_t Lifetime, Double_t Spin, Double_t maxWidth, Int_t pythiaID)
59 TParticlePDG* old = GetParticle(PDGcode);
62 B2ERROR(
"EvtGenDatabasePDG::AddParticle: particle with PDGcode=" << PDGcode <<
" already defined");
66 if (std::strpbrk(name,
" \t\n\v\f\r")) {
67 B2ERROR(
"EvtGenDatabasePDG::AddParticle: invalid particle name '" << name <<
"'. Names may not contain Whitespace");
71 auto* p =
new EvtGenParticlePDG(name, title, mass, stable, width, charge, ParticleClass,
72 PDGcode, Anti, TrackingCode, Lifetime, Spin, maxWidth, pythiaID);
74 fParticleList->Add(p);
76 fPdgMap->Add((Long_t)PDGcode, (Long_t)p);
78 TParticleClassPDG* pclass = GetParticleClass(ParticleClass);
81 pclass =
new TParticleClassPDG(ParticleClass);
82 fListOfClasses->Add(pclass);
85 pclass->AddParticle(p);
94 if (defaultFilename.empty())
95 B2FATAL(
"Cannot find the default particle database file (evt.pdl).");
97 filename = defaultFilename.c_str();
99 if (filename != defaultFilename) {
100 B2RESULT(
"Loading non-standard evt.pdl file '" << filename <<
"'");
105 if (fParticleList ==
nullptr) {
107 fParticleList =
new THashList;
108 fListOfClasses =
new TObjArray;
111 fParticleList->Delete();
112 fListOfClasses->Delete();
117 std::ifstream indec(filename);
119 char cmnd[100], xxxx[100], pname[100];
121 double mass, pwidth, pmaxwidth;
127 B2ERROR(
"EvtGenDatabasePDG::ReadEvtGenTable: Could not particle data file '" << filename <<
"'");
131 std::map<int, TParticlePDG*> pdgToPartMap;
139 if (ch ==
'\n') indec.get(ch);
143 while (indec.get(ch1), ch1 !=
'\n');
149 if (strcmp(cmnd,
"end")) {
151 if (!strcmp(cmnd,
"add")) {
153 indec >> xxxx >> xxxx >> pname >> stdhepid;
154 indec >> mass >> pwidth >> pmaxwidth >> chg3 >> spin2 >> ctau >> lundkc;
157 TParticlePDG* part =
AddParticle(pname, pname, mass,
false, pwidth, chg3,
"Unknown", stdhepid, 0, 0,
158 ctau / c_mm_per_s, spin2 / 2.0, pmaxwidth, lundkc);
159 pdgToPartMap[stdhepid] = part;
161 B2FATAL(
"EvtGenDatabasePDG::ReadPDGTable: Problem creating particle '" << pname <<
"'");
165 }
while (strcmp(cmnd,
"end"));
168 for (
auto entry : pdgToPartMap) {
169 int pdg = entry.first;
170 TParticlePDG* part = entry.second;
172 const auto& antiPartIter = pdgToPartMap.find(-pdg);
173 if (antiPartIter != pdgToPartMap.end()) {
175 part->SetAntiParticle(antiPartIter->second);
178 part->SetAntiParticle(part);
187 for (TObject* obj : *fParticleList) {
190 B2FATAL(
"EvtGenDatabasePDG::WriteEvtgenTable: Particle does not inherit from EventGenParticlePDG");
192 out <<
"add p Particle " << part->GetName() <<
" " << part->PdgCode()
193 <<
" " << std::scientific << std::setprecision(7) << part->Mass()
194 <<
" " << std::scientific << std::setprecision(7) << part->Width()
195 <<
" " << std::scientific << std::setprecision(7) << part->MaxWidth()
196 <<
" " << (int)(part->Charge())
197 <<
" " << (
int)(part->Spin() * 2)
198 <<
" " << std::scientific << std::setprecision(7) << part->Lifetime() * c_mm_per_s
199 <<
" " << part->PythiaID()
203 out <<
"end" << std::endl << std::flush;
208 std::ofstream out(filename);
210 B2FATAL(
"Cannot write evtgen pdl to '" << filename <<
"'");