18 #include <G4ParticleTable.hh>
19 #include "G4DecayTable.hh"
20 #include <G4PhaseSpaceDecayChannel.hh>
21 #include "G4ProcessManager.hh"
23 using namespace CLHEP;
30 return (m_particles.find(particle)!=m_particles.end());
41 <<
"CustomParticleFactory: Reading Custom Particle and G4DecayTable from \n"
44 G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
46 line.erase(0, line.find_first_not_of(
" \t"));
47 if (line.length()==0 || line.at(0) ==
'#')
continue;
48 if (ToLower(line).find(
"block") < line.npos &&
49 ToLower(line).find(
"mass") < line.npos) {
50 edm::LogInfo(
"SimG4CoreCustomPhysics") <<
"CustomParticleFactory: Retrieving mass table.";
53 if(line.find(
"DECAY")<line.npos){
57 std::stringstream lineStream(line);
58 lineStream >> tmpString >> pdgId >>
width;
61 <<
"CustomParticleFactory: entry to G4DecayTable: pdgID, width " << pdgId <<
", " <<
width;
62 G4DecayTable* aDecayTable = getDecayTable(&
configFile, pdgId);
63 G4ParticleDefinition *aParticle = theParticleTable->FindParticle(pdgId);
64 G4ParticleDefinition *aAntiParticle = theParticleTable->FindAntiParticle(pdgId);
65 if (!aParticle)
continue;
66 aParticle->SetDecayTable(aDecayTable);
67 aParticle->SetPDGStable(
false);
68 aParticle->SetPDGLifeTime(1.0/(width*
GeV)*6.582122
e-22*
MeV*
s);
69 if(aAntiParticle && aAntiParticle->GetPDGEncoding()!=
pdgId){
70 aAntiParticle->SetDecayTable(getAntiDecayTable(pdgId,aDecayTable));
71 aAntiParticle->SetPDGStable(
false);
72 aAntiParticle->SetPDGLifeTime(1.0/(width*GeV)*6.582122
e-22*
MeV*s);
80 if(
abs(pdgCode)%100 <14 &&
abs(pdgCode) / 1000000 == 0){
81 edm::LogError(
"") <<
"Pdg code too low " << pdgCode <<
" "<<
abs(pdgCode) / 1000000;
86 G4String pType=
"custom";
88 G4double spectatormass = 0.0;
89 G4ParticleDefinition* spectator =
nullptr;
96 double massGeV =mass*
GeV;
99 if (name.compare(0,4,
"~HIP") == 0)
101 if ((name.compare(0,7,
"~HIPbar") == 0)) {
103 charge=eplus*atoi(str.c_str())/3.;
106 charge=eplus*atoi(str.c_str())*-1./3.;
109 if (name.compare(0,9,
"anti_~HIP") == 0)
111 if ((name.compare(0,12,
"anti_~HIPbar") == 0)) {
113 charge=eplus*atoi(str.c_str())*-1./3.;
116 charge=eplus*atoi(str.c_str())*1./3.;
128 double lifetime = -1;
130 G4DecayTable *decaytable =
nullptr;
131 G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
134 parity, conjugation, isospin, isospinZ,
135 gParity, pType, lepton, baryon, pdgCode,
136 stable, lifetime, decaytable);
138 if(pType ==
"rhadron" && name!=
"~g"){
139 G4String cloudname = name+
"cloud";
140 G4String cloudtype = pType+
"cloud";
141 spectator = theParticleTable->FindParticle(1000021);
142 spectatormass = spectator->GetPDGMass();
143 G4double cloudmass = mass-spectatormass/
GeV;
145 cloudname, cloudmass * GeV , 0.0*
MeV, 0 ,
154 <<
"CustomParticleFactory: " <<name<<
" being assigned "
155 <<particle->
GetCloud()->GetParticleName()
156 <<
" and "<<particle->
GetSpectator()->GetParticleName() <<
"\n"
157 <<
" Masses: "<<particle->GetPDGMass()/GeV<<
" Gev, "
158 <<particle->
GetCloud()->GetPDGMass()/GeV<<
" GeV and "
160 }
else if(pType ==
"mesonino" || pType ==
"sbaryon") {
162 if(pdgCode < 0 ) sign=-1;
164 G4String cloudname = name+
"cloud";
165 G4String cloudtype = pType+
"cloud";
167 spectator = theParticleTable->FindParticle(1000006*sign);
171 spectator = theParticleTable->FindParticle(1000005*sign);
174 edm::LogError(
"SimG4CoreCustomPhysics")<<
"CustomParticleFactory: Cannot find spectator parton";
177 if(spectator) spectatormass = spectator->GetPDGMass();
178 G4double cloudmass = mass-spectatormass/
GeV;
180 cloudname, cloudmass * GeV , 0.0*
MeV, 0 ,
189 <<
"CustomParticleFactory: "<<name<<
" being assigned "
190 <<particle->
GetCloud()->GetParticleName()
191 <<
" and "<<particle->
GetSpectator()->GetParticleName() <<
"\n"
193 <<particle->GetPDGMass()/GeV<<
" Gev, "
194 <<particle->
GetCloud()->GetPDGMass()/GeV<<
" GeV and "
201 m_particles.insert(particle);
211 while (getline(*configFile,line)) {
212 line.erase(0, line.find_first_not_of(
" \t"));
213 if (line.length()==0 || line.at(0) ==
'#')
continue;
214 if (ToLower(line).find(
"block") < line.npos) {
216 <<
"CustomParticleFactory: Finished the Mass Table ";
219 std::stringstream sstr(line);
220 sstr >> pdgId >> mass >> tmp >>
name;
223 <<
"CustomParticleFactory: Calling addCustomParticle for pdgId: " << pdgId
224 <<
", mass " << mass <<
", name " <<
name;
225 addCustomParticle(pdgId, fabs(mass), name);
227 int pdgIdPartner = pdgId%100;
228 G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
229 G4ParticleDefinition *aParticle = theParticleTable->FindParticle(pdgIdPartner);
232 <<
"CustomParticleFactory: Found aParticle = " << aParticle
233 <<
", pdgId = " << pdgId
234 <<
", pdgIdPartner = " << pdgIdPartner
240 !CustomPDGParser::s_isstopHadron(pdgId) &&
247 int sign = aParticle->GetAntiPDGEncoding()/pdgIdPartner;
249 <<
"CustomParticleFactory: Found sign = " << sign
250 <<
", aParticle->GetAntiPDGEncoding() " << aParticle->GetAntiPDGEncoding()
251 <<
", pdgIdPartner = " << pdgIdPartner;
254 <<
"CustomParticleFactory: sgn= "<<sign<<
" a "
255 <<aParticle->GetAntiPDGEncoding()<<
" b "<<pdgIdPartner;
256 aParticle->DumpTable();
258 if(sign==-1 && pdgId!=25 && pdgId!=35 && pdgId!=36 && pdgId!=37 && pdgId!=1000039){
261 <<
"CustomParticleFactory: Calling addCustomParticle for antiparticle with pdgId: "
262 << -pdgId <<
", mass " << mass <<
", name " <<
tmp;
263 addCustomParticle(-pdgId, mass, tmp);
264 theParticleTable->FindParticle(pdgId)->SetAntiPDGEncoding(-pdgId);
266 else theParticleTable->FindParticle(pdgId)->SetAntiPDGEncoding(pdgId);
269 if(pdgId==1000039) theParticleTable->FindParticle(pdgId)->SetAntiPDGEncoding(pdgId);
270 if(pdgId==1000024 || pdgId==1000037 || pdgId==37) {
273 <<
"CustomParticleFactory: Calling addCustomParticle for antiparticle (2) with pdgId: "
274 << -pdgId <<
", mass " << mass <<
", name " <<
tmp;
275 addCustomParticle(-pdgId, mass, tmp);
276 theParticleTable->FindParticle(pdgId)->SetAntiPDGEncoding(-pdgId);
285 std::vector<int> pdg(4);
287 std::vector<std::string>
name(4);
289 G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
291 std::string parentName = theParticleTable->FindParticle(pdgId)->GetParticleName();
292 G4DecayTable *decaytable=
new G4DecayTable();
294 while(getline(*configFile,line)) {
296 line.erase(0, line.find_first_not_of(
" \t"));
297 if (line.length()==0)
continue;
298 if (line.at(0) ==
'#' &&
299 ToLower(line).find(
"br") < line.npos &&
300 ToLower(line).find(
"nda") < line.npos)
continue;
301 if (line.at(0) ==
'#') {
302 edm::LogInfo(
"SimG4CoreCustomPhysics") <<
"CustomParticleFactory: Finished the Decay Table ";
309 std::stringstream sstr(line);
310 sstr >> br >> nDaughters;
312 <<
"CustomParticleFactory: Branching Ratio: " << br <<
", Number of Daughters: " << nDaughters;
313 if (nDaughters > 4) {
315 <<
"CustomParticleFactory: Number of daughters is too large (max = 4): " << nDaughters
316 <<
" for pdgId: " <<
pdgId;
319 for(
int i=0;
i<nDaughters;
i++) {
321 edm::LogInfo(
"SimG4CoreCustomPhysics") <<
"CustomParticleFactory: Daughter ID " << pdg[
i];
322 const G4ParticleDefinition*
part = theParticleTable->FindParticle(pdg[
i]);
325 <<
"CustomParticleFactory: particle with PDG code"<<pdg[
i] <<
" not found!";
328 name[
i] = part->GetParticleName();
331 G4PhaseSpaceDecayChannel *aDecayChannel =
new G4PhaseSpaceDecayChannel(parentName, br, nDaughters,
332 name[0],name[1],name[2],name[3]);
333 decaytable->Insert(aDecayChannel);
340 std::vector<std::string>
name(4);
341 G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
343 std::string parentName = theParticleTable->FindParticle(-pdgId)->GetParticleName();
344 G4DecayTable *decaytable=
new G4DecayTable();
346 for(
int i=0;
i<theDecayTable->entries();
i++){
347 G4VDecayChannel *theDecayChannel = theDecayTable->GetDecayChannel(
i);
348 int nd =
std::min(4, theDecayChannel->GetNumberOfDaughters());
349 for(
int j=0;
j<nd; ++
j){
350 int id = theDecayChannel->GetDaughter(
j)->GetAntiPDGEncoding();
351 const G4ParticleDefinition*
part = theParticleTable->FindParticle(
id);
354 <<
"CustomParticleFactory: antiparticle with PDG code"<<
id <<
" not found!";
357 name[
i] = part->GetParticleName();
359 G4PhaseSpaceDecayChannel *aDecayChannel =
360 new G4PhaseSpaceDecayChannel(parentName,
361 theDecayChannel->GetBR(), nd,
362 name[0],name[1],name[2],name[3]);
363 decaytable->Insert(aDecayChannel);
371 str.at(
i) = std::tolower(str.at(
i),loc);
static std::set< G4ParticleDefinition * > m_particles
static double s_charge(int pdg)
static bool s_isSbaryon(int pdg)
void SetCloud(G4ParticleDefinition *theCloud)
G4ParticleDefinition * GetCloud()
static void loadCustomParticles(const std::string &filePath)
static bool s_isMesonino(int pdg)
static bool s_isSLepton(int pdg)
Abs< T >::type abs(const T &t)
static std::string ToLower(std::string str)
void SetSpectator(G4ParticleDefinition *theSpectator)
static double s_spin(int pdg)
G4ParticleDefinition * GetSpectator()
static void getMassTable(std::ifstream *configFile)
static G4DecayTable * getDecayTable(std::ifstream *configFile, int pdgId)
static void addCustomParticle(int pdgCode, double mass, const std::string &name)
static G4DecayTable * getAntiDecayTable(int pdgId, G4DecayTable *theDecayTable)
static bool s_isRHadron(int pdg)
std::vector< std::vector< double > > tmp
static bool s_issbottomHadron(int pdg)
static bool isCustomParticle(G4ParticleDefinition *particle)
static bool s_isstopHadron(int pdg)