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());
37 std::ifstream configFile(filePath.c_str());
41 <<
"CustomParticleFactory: Reading Custom Particle and G4DecayTable from \n" 44 G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
45 while(getline(configFile,line)){
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.";
51 getMassTable(&configFile);
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;
144 G4DecayTable *decaytable =
nullptr;
145 G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
148 parity, conjugation, isospin, isospinZ,
149 gParity, pType, lepton, baryon, pdgCode,
150 stable, lifetime, decaytable);
152 if(pType ==
"rhadron" && name!=
"~g"){
153 G4String cloudname = name+
"cloud";
154 G4String cloudtype = pType+
"cloud";
155 spectator = theParticleTable->FindParticle(1000021);
156 spectatormass = spectator->GetPDGMass();
157 G4double cloudmass = mass-spectatormass/
GeV;
159 cloudname, cloudmass * GeV , 0.0*
MeV, 0 ,
168 <<
"CustomParticleFactory: " <<name<<
" being assigned " 169 <<particle->
GetCloud()->GetParticleName()
170 <<
" and "<<particle->
GetSpectator()->GetParticleName() <<
"\n" 171 <<
" Masses: "<<particle->GetPDGMass()/GeV<<
" Gev, " 172 <<particle->
GetCloud()->GetPDGMass()/GeV<<
" GeV and " 174 }
else if(pType ==
"mesonino" || pType ==
"sbaryon") {
176 if(pdgCode < 0 ) sign=-1;
178 G4String cloudname = name+
"cloud";
179 G4String cloudtype = pType+
"cloud";
181 spectator = theParticleTable->FindParticle(1000006*sign);
185 spectator = theParticleTable->FindParticle(1000005*sign);
188 edm::LogError(
"SimG4CoreCustomPhysics")<<
"CustomParticleFactory: Cannot find spectator parton";
191 if(spectator) spectatormass = spectator->GetPDGMass();
192 G4double cloudmass = mass-spectatormass/
GeV;
194 cloudname, cloudmass * GeV , 0.0*
MeV, 0 ,
203 <<
"CustomParticleFactory: "<<name<<
" being assigned " 204 <<particle->
GetCloud()->GetParticleName()
205 <<
" and "<<particle->
GetSpectator()->GetParticleName() <<
"\n" 207 <<particle->GetPDGMass()/GeV<<
" Gev, " 208 <<particle->
GetCloud()->GetPDGMass()/GeV<<
" GeV and " 215 m_particles.insert(particle);
225 while (getline(*configFile,line)) {
226 line.erase(0, line.find_first_not_of(
" \t"));
227 if (line.length()==0 || line.at(0) ==
'#')
continue;
228 if (ToLower(line).find(
"block") < line.npos) {
230 <<
"CustomParticleFactory: Finished the Mass Table ";
233 std::stringstream sstr(line);
234 sstr >> pdgId >> mass >> tmp >>
name;
237 <<
"CustomParticleFactory: Calling addCustomParticle for pdgId: " << pdgId
238 <<
", mass " << mass <<
", name " <<
name;
239 addCustomParticle(pdgId, fabs(mass), name);
241 int pdgIdPartner = pdgId%100;
242 G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
243 G4ParticleDefinition *aParticle = theParticleTable->FindParticle(pdgIdPartner);
246 <<
"CustomParticleFactory: Found aParticle = " << aParticle
247 <<
", pdgId = " << pdgId
248 <<
", pdgIdPartner = " << pdgIdPartner
254 !CustomPDGParser::s_isstopHadron(pdgId) &&
261 int sign = aParticle->GetAntiPDGEncoding()/pdgIdPartner;
263 <<
"CustomParticleFactory: Found sign = " << sign
264 <<
", aParticle->GetAntiPDGEncoding() " << aParticle->GetAntiPDGEncoding()
265 <<
", pdgIdPartner = " << pdgIdPartner;
268 <<
"CustomParticleFactory: sgn= "<<sign<<
" a " 269 <<aParticle->GetAntiPDGEncoding()<<
" b "<<pdgIdPartner;
270 aParticle->DumpTable();
272 if(sign==-1 && pdgId!=25 && pdgId!=35 && pdgId!=36 && pdgId!=37 && pdgId!=1000039){
275 <<
"CustomParticleFactory: Calling addCustomParticle for antiparticle with pdgId: " 276 << -pdgId <<
", mass " << mass <<
", name " <<
tmp;
277 addCustomParticle(-pdgId, mass, tmp);
278 theParticleTable->FindParticle(pdgId)->SetAntiPDGEncoding(-pdgId);
280 else theParticleTable->FindParticle(pdgId)->SetAntiPDGEncoding(pdgId);
283 if(pdgId==1000039) theParticleTable->FindParticle(pdgId)->SetAntiPDGEncoding(pdgId);
284 if(pdgId==1000024 || pdgId==1000037 || pdgId==37) {
287 <<
"CustomParticleFactory: Calling addCustomParticle for antiparticle (2) with pdgId: " 288 << -pdgId <<
", mass " << mass <<
", name " <<
tmp;
289 addCustomParticle(-pdgId, mass, tmp);
290 theParticleTable->FindParticle(pdgId)->SetAntiPDGEncoding(-pdgId);
299 std::vector<int> pdg(4);
301 std::vector<std::string>
name(4);
303 G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
305 std::string parentName = theParticleTable->FindParticle(pdgId)->GetParticleName();
306 G4DecayTable *decaytable=
new G4DecayTable();
308 while(getline(*configFile,line)) {
310 line.erase(0, line.find_first_not_of(
" \t"));
311 if (line.length()==0)
continue;
312 if (line.at(0) ==
'#' &&
313 ToLower(line).find(
"br") < line.npos &&
314 ToLower(line).find(
"nda") < line.npos)
continue;
315 if (line.at(0) ==
'#') {
316 edm::LogInfo(
"SimG4CoreCustomPhysics") <<
"CustomParticleFactory: Finished the Decay Table ";
323 std::stringstream sstr(line);
324 sstr >> br >> nDaughters;
326 <<
"CustomParticleFactory: Branching Ratio: " << br <<
", Number of Daughters: " << nDaughters;
327 if (nDaughters > 4) {
329 <<
"CustomParticleFactory: Number of daughters is too large (max = 4): " << nDaughters
330 <<
" for pdgId: " <<
pdgId;
333 for(
int i=0;
i<nDaughters;
i++) {
335 edm::LogInfo(
"SimG4CoreCustomPhysics") <<
"CustomParticleFactory: Daughter ID " << pdg[
i];
336 const G4ParticleDefinition*
part = theParticleTable->FindParticle(pdg[
i]);
339 <<
"CustomParticleFactory: particle with PDG code"<<pdg[
i] <<
" not found!";
342 name[
i] = part->GetParticleName();
345 G4PhaseSpaceDecayChannel *aDecayChannel =
new G4PhaseSpaceDecayChannel(parentName, br, nDaughters,
346 name[0],name[1],name[2],name[3]);
347 decaytable->Insert(aDecayChannel);
354 std::vector<std::string>
name(4);
355 G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
357 std::string parentName = theParticleTable->FindParticle(-pdgId)->GetParticleName();
358 G4DecayTable *decaytable=
new G4DecayTable();
360 for(
int i=0;
i<theDecayTable->entries();
i++){
361 G4VDecayChannel *theDecayChannel = theDecayTable->GetDecayChannel(
i);
362 int nd =
std::min(4, theDecayChannel->GetNumberOfDaughters());
363 for(
int j=0;
j<nd; ++
j){
364 int id = theDecayChannel->GetDaughter(
j)->GetAntiPDGEncoding();
365 const G4ParticleDefinition*
part = theParticleTable->FindParticle(
id);
368 <<
"CustomParticleFactory: antiparticle with PDG code"<<
id <<
" not found!";
371 name[
i] = part->GetParticleName();
373 G4PhaseSpaceDecayChannel *aDecayChannel =
374 new G4PhaseSpaceDecayChannel(parentName,
375 theDecayChannel->GetBR(), nd,
376 name[0],name[1],name[2],name[3]);
377 decaytable->Insert(aDecayChannel);
385 str.at(
i) = std::tolower(str.at(
i),
loc);
static bool s_isDphoton(int pdg)
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)