17 #include "G4DecayTable.hh"
18 #include "G4ParticleTable.hh"
19 #include "G4PhaseSpaceDecayChannel.hh"
23 static const std::set<G4ParticleDefinition *>
particles =
load();
36 G4ParticleTable *theParticleTable = G4ParticleTable::GetParticleTable();
39 std::set<G4ParticleDefinition *>
particles;
42 G4String pType=
"custom";
44 G4double spectatormass = 0;
45 G4ParticleDefinition* spectator = 0;
52 G4cout <<
"-------------------------------------------------" << G4endl;
53 std::string::size_type beg_idx,end_idx;
55 beg_idx =
line.find_first_not_of(
"\t #");
56 if (beg_idx > 0 &&
line[beg_idx-1] ==
'#')
continue;
57 end_idx =
line.find_first_of(
"\t ", beg_idx);
58 if (end_idx == std::string::npos)
continue;
60 const std::string pdgCodeString =
line.substr( beg_idx, end_idx - beg_idx );
61 pdgCode = strtol(pdgCodeString.c_str(), &endptr, 0);
62 if (endptr[0] !=
'\0') {
63 throw std::invalid_argument(
"Could not convert string to int: " +
line.substr( beg_idx, end_idx - beg_idx ));
66 beg_idx =
line.find_first_not_of(
"\t ",end_idx);
67 end_idx =
line.find_first_of(
"\t #", beg_idx);
68 if (end_idx == std::string::npos)
continue;
69 mass =
atof(
line.substr( beg_idx, end_idx - beg_idx ).c_str());
71 beg_idx =
line.find_first_not_of(
"\t# ",end_idx);
72 end_idx =
line.length();
73 if (beg_idx==std::string::npos) beg_idx = end_idx;
74 name =
line.substr( beg_idx, end_idx - beg_idx );
75 while (
name.c_str()[0] ==
' ') {
name.erase(0,1); }
78 if (abs(pdgCode) / 1000000 == 0){
79 G4cout <<
"Pdg code too low " << pdgCode <<
" "<<abs(pdgCode) / 1000000 << std::endl;
89 G4cout<<
"pType: "<<pType<<G4endl;
92 G4ParticleDefinition* previousDefinition = theParticleTable->FindParticle(pdgCode);
94 if (previousDefinition) {
95 G4cout <<
"Found a previousDefinition for " <<
name <<
"(" << pdgCode <<
") in G4ParticleTable. Assuming that we want the new definition, so removing previous defnition! May cause issues elsewhere though..." << G4endl;
96 previousDefinition->DumpTable();
97 theParticleTable->Remove(previousDefinition);
98 delete previousDefinition;
105 pType, 0, +1, pdgCode,
107 if (pType==
"custom") {
108 spectatormass =
mass;
115 spectatormass =
mass;
120 G4String cloudname =
name+
"cloud";
121 G4String cloudtype = pType+
"cloud";
122 G4double cloudmass =
mass-spectatormass;
132 G4cout <<
name <<
" being assigned cloud " <<
particle->GetCloud()->GetParticleName() <<
" and spectator " <<
particle->GetSpectator()->GetParticleName() << G4endl;
143 G4cout <<
"-------------------------------------------------" << G4endl;
146 std::vector<std::vector<std::string>* >
decays;
149 std::istringstream is(
line);
150 std::vector<std::string>* txtvec =
new std::vector<std::string>(std::istream_iterator<std::string>(is),std::istream_iterator<std::string>());
157 name=(*part)->GetParticleName();
158 std::vector<std::vector<std::string> > mydecays;
159 for (
unsigned int i = 0;
i!=
decays.size();
i++) {
162 mydecays.push_back(*(
decays[
i]));
165 if (mydecays.size()>0) {
166 const int ndec=std::ssize(mydecays);
167 G4DecayTable*
table =
new G4DecayTable();
168 G4VDecayChannel**
mode =
new G4VDecayChannel*[ndec]{};
169 for (
int i=0;
i!=ndec;
i++) {
170 std::vector<std::string> thisdec=mydecays[
i];
171 if (thisdec.empty())
continue;
172 const double branch = std::stod(thisdec.back());
174 for (
const auto & thisString:thisdec) G4cout<<thisString<<G4endl;
175 if (thisdec.size()==3) {
176 mode[
i] =
new G4PhaseSpaceDecayChannel(thisdec[0],
branch,2,thisdec[1],thisdec[2]);
177 }
else if (thisdec.size()==4) {
178 mode[
i] =
new G4PhaseSpaceDecayChannel(thisdec[0],
branch,3,thisdec[1],thisdec[2],thisdec[3]);
180 G4cout<<
"Decay chain invalid!!!"<<std::endl;
185 (*part)->SetDecayTable(
table);