38 G4ParticleTable *theParticleTable = G4ParticleTable::GetParticleTable();
41 std::set<G4ParticleDefinition *>
particles;
44 G4String pType=
"custom";
46 G4double spectatormass = 0;
47 G4ParticleDefinition* spectator = 0;
54 G4cout <<
"-------------------------------------------------" << G4endl;
55 std::string::size_type beg_idx,end_idx;
57 beg_idx =
line.find_first_not_of(
"\t #");
58 if (beg_idx > 0 &&
line[beg_idx-1] ==
'#')
continue;
59 end_idx =
line.find_first_of(
"\t ", beg_idx);
60 if (end_idx == std::string::npos)
continue;
62 const std::string pdgCodeString =
line.substr( beg_idx, end_idx - beg_idx );
63 pdgCode = strtol(pdgCodeString.c_str(), &endptr, 0);
64 if (endptr[0] !=
'\0') {
65 throw std::invalid_argument(
"Could not convert string to int: " +
line.substr( beg_idx, end_idx - beg_idx ));
68 beg_idx =
line.find_first_not_of(
"\t ",end_idx);
69 end_idx =
line.find_first_of(
"\t #", beg_idx);
70 if (end_idx == std::string::npos)
continue;
71 mass =
atof(
line.substr( beg_idx, end_idx - beg_idx ).c_str());
73 beg_idx =
line.find_first_not_of(
"\t# ",end_idx);
74 end_idx =
line.length();
75 if (beg_idx==std::string::npos) beg_idx = end_idx;
76 name =
line.substr( beg_idx, end_idx - beg_idx );
77 while (
name.c_str()[0] ==
' ') {
name.erase(0,1); }
80 if (abs(pdgCode) / 1000000 == 0){
81 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);