8 #include "G4ParticleTable.hh" 9 #include "G4DecayTable.hh" 10 #include "G4PhaseSpaceDecayChannel.hh" 11 #include "G4ProcessManager.hh" 12 #include "G4ParticleDefinition.hh" 13 #include "G4SystemOfUnits.hh" 22 #ifdef G4MULTITHREADED 23 G4Mutex CustomParticleFactory::customParticleFactoryMutex = G4MUTEX_INITIALIZER;
35 #ifdef G4MULTITHREADED 36 G4MUTEXLOCK(&customParticleFactoryMutex);
42 std::ifstream configFile(filePath.c_str());
46 <<
"CustomParticleFactory: Reading Custom Particle and G4DecayTable from \n" 49 G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
50 while(getline(configFile, line)){
51 line.erase(0, line.find_first_not_of(
" \t"));
52 if (line.length()==0 || line.at(0) ==
'#') {
continue; }
54 if (
ToLower(line).find(
"block") < line.npos &&
55 ToLower(line).find(
"mass") < line.npos) {
56 edm::LogInfo(
"SimG4CoreCustomPhysics") <<
"CustomParticleFactory: Retrieving mass table.";
59 if(line.find(
"DECAY")<line.npos) {
63 std::stringstream lineStream(line);
64 lineStream >> tmpString >> pdgId >>
width;
67 <<
"CustomParticleFactory: entry to G4DecayTable: pdgID, width " 68 << pdgId <<
", " <<
width;
69 G4DecayTable* aDecayTable =
getDecayTable(&configFile, pdgId);
70 G4ParticleDefinition *aParticle = theParticleTable->FindParticle(pdgId);
71 G4ParticleDefinition *aAntiParticle = theParticleTable->FindAntiParticle(pdgId);
72 if (!aParticle) {
continue; }
73 aParticle->SetDecayTable(aDecayTable);
74 aParticle->SetPDGStable(
false);
76 if(aAntiParticle && aAntiParticle->GetPDGEncoding() !=
pdgId){
78 aAntiParticle->SetPDGStable(
false);
79 aAntiParticle->SetPDGLifeTime(1.0/(width*CLHEP::GeV)*6.582122
e-22*
CLHEP::MeV*CLHEP::s);
83 #ifdef G4MULTITHREADED 84 G4MUTEXUNLOCK(&customParticleFactoryMutex);
93 <<
"Pdg code too low " << pdgCode <<
" "<<
std::abs(pdgCode)/1000000;
98 G4String pType=
"custom";
100 G4double spectatormass = 0.0;
101 G4ParticleDefinition* spectator =
nullptr;
111 if (name.compare(0,4,
"~HIP") == 0)
113 if ((name.compare(0,7,
"~HIPbar") == 0)) {
115 charge=CLHEP::eplus*atoi(str.c_str())/3.;
118 charge=-CLHEP::eplus*atoi(str.c_str())/3.;
121 if (name.compare(0,9,
"anti_~HIP") == 0)
123 if ((name.compare(0,12,
"anti_~HIPbar") == 0)) {
125 charge=-CLHEP::eplus*atoi(str.c_str())/3.;
128 charge=CLHEP::eplus*atoi(str.c_str())/3.;
140 double lifetime = -1;
156 G4DecayTable *decaytable =
nullptr;
157 G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
160 parity, conjugation, isospin, isospinZ,
161 gParity, pType, lepton, baryon, pdgCode,
162 stable, lifetime, decaytable);
164 if(pType ==
"rhadron" && name!=
"~g"){
165 G4String cloudname = name+
"cloud";
166 G4String cloudtype = pType+
"cloud";
167 spectator = theParticleTable->FindParticle(1000021);
168 spectatormass = spectator->GetPDGMass();
169 G4double cloudmass = massGeV - spectatormass;
171 cloudname, cloudmass, 0.0, 0,
175 true, -1.0,
nullptr );
180 <<
"CustomParticleFactory: " <<name<<
" being assigned spectator" 181 << spectator->GetParticleName() <<
" and cloud " <<cloudname <<
"\n" 182 <<
" Masses: "<<mass<<
" Gev, " 183 <<spectatormass/CLHEP::GeV<<
" GeV and "<<cloudmass/CLHEP::GeV<<
" GeV.";
184 }
else if(pType ==
"mesonino" || pType ==
"sbaryon") {
186 if(pdgCode < 0 ) sign=-1;
188 G4String cloudname = name+
"cloud";
189 G4String cloudtype = pType+
"cloud";
191 spectator = theParticleTable->FindParticle(1000006*sign);
195 spectator = theParticleTable->FindParticle(1000005*sign);
198 edm::LogError(
"SimG4CoreCustomPhysics")<<
"CustomParticleFactory: Cannot find spectator parton";
201 if(spectator) { spectatormass = spectator->GetPDGMass(); }
202 G4double cloudmass = massGeV - spectatormass;
204 cloudname, cloudmass, 0.0, 0 ,
208 true, -1.0,
nullptr);
213 <<
"CustomParticleFactory: " <<name<<
" being assigned spectator" 214 << spectator->GetParticleName() <<
" and cloud " <<cloudname <<
"\n" 215 <<
" Masses: "<<mass<<
" Gev, " 216 <<spectatormass/CLHEP::GeV<<
" GeV and "<<cloudmass/CLHEP::GeV<<
" GeV.";
232 while (getline(*configFile,line)) {
233 line.erase(0, line.find_first_not_of(
" \t"));
234 if (line.length()==0 || line.at(0) ==
'#')
continue;
235 if (
ToLower(line).find(
"block") < line.npos) {
237 <<
"CustomParticleFactory: Finished the Mass Table ";
240 std::stringstream sstr(line);
241 sstr >> pdgId >> mass >> tmp >>
name;
246 <<
"CustomParticleFactory: Calling addCustomParticle for pdgId: " << pdgId
247 <<
", mass " << mass <<
" GeV, name " <<
name;
250 int pdgIdPartner = pdgId%100;
251 G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
252 G4ParticleDefinition *aParticle = theParticleTable->FindParticle(pdgIdPartner);
255 <<
"CustomParticleFactory: Found aParticle = " << aParticle
256 <<
", pdgId = " << pdgId
257 <<
", pdgIdPartner = " << pdgIdPartner
263 !CustomPDGParser::s_isstopHadron(pdgId) &&
270 int sign = aParticle->GetAntiPDGEncoding()/pdgIdPartner;
272 <<
"CustomParticleFactory: Found sign = " << sign
273 <<
", aParticle->GetAntiPDGEncoding() " << aParticle->GetAntiPDGEncoding()
274 <<
", pdgIdPartner = " << pdgIdPartner;
277 <<
"CustomParticleFactory: sgn= "<<sign<<
" a " 278 <<aParticle->GetAntiPDGEncoding()<<
" b "<<pdgIdPartner;
279 aParticle->DumpTable();
281 if(sign==-1 && pdgId!=25 && pdgId!=35 && pdgId!=36 && pdgId!=37 && pdgId!=1000039){
284 <<
"CustomParticleFactory: Calling addCustomParticle for antiparticle with pdgId: " 285 << -pdgId <<
", mass " << mass <<
" GeV, name " <<
tmp;
287 theParticleTable->FindParticle(pdgId)->SetAntiPDGEncoding(-pdgId);
289 else theParticleTable->FindParticle(pdgId)->SetAntiPDGEncoding(pdgId);
292 if(pdgId==1000039) theParticleTable->FindParticle(pdgId)->SetAntiPDGEncoding(pdgId);
293 if(pdgId==1000024 || pdgId==1000037 || pdgId==37) {
296 <<
"CustomParticleFactory: Calling addCustomParticle for antiparticle (2) with pdgId: " 297 << -pdgId <<
", mass " << mass <<
" GeV, name " <<
tmp;
299 theParticleTable->FindParticle(pdgId)->SetAntiPDGEncoding(-pdgId);
308 std::vector<int> pdg(4);
310 std::vector<std::string>
name(4);
312 G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
314 std::string parentName = theParticleTable->FindParticle(pdgId)->GetParticleName();
315 G4DecayTable *decaytable=
new G4DecayTable();
317 while(getline(*configFile,line)) {
319 line.erase(0, line.find_first_not_of(
" \t"));
320 if (line.length()==0)
continue;
321 if (line.at(0) ==
'#' &&
322 ToLower(line).find(
"br") < line.npos &&
323 ToLower(line).find(
"nda") < line.npos)
continue;
324 if (line.at(0) ==
'#') {
325 edm::LogInfo(
"SimG4CoreCustomPhysics") <<
"CustomParticleFactory: Finished the Decay Table ";
332 std::stringstream sstr(line);
333 sstr >> br >> nDaughters;
335 <<
"CustomParticleFactory: Branching Ratio: " << br <<
", Number of Daughters: " << nDaughters;
336 if (nDaughters > 4) {
338 <<
"CustomParticleFactory: Number of daughters is too large (max = 4): " << nDaughters
339 <<
" for pdgId: " <<
pdgId;
342 for(
int i=0;
i<nDaughters;
i++) {
344 edm::LogInfo(
"SimG4CoreCustomPhysics") <<
"CustomParticleFactory: Daughter ID " << pdg[
i];
345 const G4ParticleDefinition*
part = theParticleTable->FindParticle(pdg[
i]);
348 <<
"CustomParticleFactory: particle with PDG code"<<pdg[
i] <<
" not found!";
351 name[
i] = part->GetParticleName();
354 G4PhaseSpaceDecayChannel *aDecayChannel =
new G4PhaseSpaceDecayChannel(parentName, br, nDaughters,
355 name[0],name[1],name[2],name[3]);
356 decaytable->Insert(aDecayChannel);
363 std::vector<std::string>
name(4);
364 G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
366 std::string parentName = theParticleTable->FindParticle(-pdgId)->GetParticleName();
367 G4DecayTable *decaytable=
new G4DecayTable();
369 for(
int i=0;
i<theDecayTable->entries();
i++){
370 G4VDecayChannel *theDecayChannel = theDecayTable->GetDecayChannel(
i);
371 int nd =
std::min(4, theDecayChannel->GetNumberOfDaughters());
372 for(
int j=0; j<nd; ++j){
373 int id = theDecayChannel->GetDaughter(j)->GetAntiPDGEncoding();
374 const G4ParticleDefinition*
part = theParticleTable->FindParticle(
id);
377 <<
"CustomParticleFactory: antiparticle with PDG code"<<
id <<
" not found!";
380 name[j] = part->GetParticleName();
382 G4PhaseSpaceDecayChannel *aDecayChannel =
383 new G4PhaseSpaceDecayChannel(parentName,
384 theDecayChannel->GetBR(), nd,
385 name[0],name[1],name[2],name[3]);
386 decaytable->Insert(aDecayChannel);
394 str.at(
i) = std::tolower(str.at(
i),
loc);
static bool s_isDphoton(int pdg)
static double s_charge(int pdg)
static bool s_isSbaryon(int pdg)
void SetCloud(G4ParticleDefinition *theCloud)
void loadCustomParticles(const std::string &filePath)
static std::vector< G4ParticleDefinition * > m_particles
static bool s_isMesonino(int pdg)
static bool s_isSLepton(int pdg)
Abs< T >::type abs(const T &t)
std::string ToLower(std::string str)
void SetSpectator(G4ParticleDefinition *theSpectator)
static double s_spin(int pdg)
void getMassTable(std::ifstream *configFile)
G4DecayTable * getDecayTable(std::ifstream *configFile, int pdgId)
void addCustomParticle(int pdgCode, double mass, const std::string &name)
G4DecayTable * getAntiDecayTable(int pdgId, G4DecayTable *theDecayTable)
static bool s_isRHadron(int pdg)
std::vector< std::vector< double > > tmp
const std::vector< G4ParticleDefinition * > & GetCustomParticles()
static bool s_issbottomHadron(int pdg)
static bool s_isstopHadron(int pdg)