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());
40 edm::LogInfo(
"CustomPhysics") <<
"Reading Custom Particle and G4DecayTable from " << filePath;
42 G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
44 line.erase(0, line.find_first_not_of(
" \t"));
45 if (line.length()==0 || line.at(0) ==
'#')
continue;
46 if (ToLower(line).find(
"block") < line.npos &&
47 ToLower(line).find(
"mass") < line.npos) {
48 edm::LogInfo(
"CustomPhysics") <<
" Retrieving mass table.";
51 if(line.find(
"DECAY")<line.npos){
55 std::stringstream lineStream(line);
56 lineStream >> tmpString >> pdgId >>
width;
57 edm::LogInfo(
"CustomPhysics") <<
"G4DecayTable: pdgID, width " << pdgId <<
", " <<
width;
58 G4DecayTable* aDecayTable = getDecayTable(&
configFile, pdgId);
59 G4ParticleDefinition *aParticle = theParticleTable->FindParticle(pdgId);
60 G4ParticleDefinition *aAntiParticle = theParticleTable->FindAntiParticle(pdgId);
61 if (!aParticle)
continue;
62 aParticle->SetDecayTable(aDecayTable);
63 aParticle->SetPDGStable(
false);
64 aParticle->SetPDGLifeTime(1.0/(width*
GeV)*6.582122
e-22*
MeV*
s);
65 if(aAntiParticle && aAntiParticle->GetPDGEncoding()!=
pdgId){
66 aAntiParticle->SetDecayTable(getAntiDecayTable(pdgId,aDecayTable));
67 aAntiParticle->SetPDGStable(
false);
68 aAntiParticle->SetPDGLifeTime(1.0/(width*GeV)*6.582122
e-22*
MeV*s);
77 if(
abs(pdgCode)%100 <14 &&
abs(pdgCode) / 1000000 == 0){
78 edm::LogError(
"") <<
"Pdg code too low " << pdgCode <<
" "<<
abs(pdgCode) / 1000000;
84 G4String pType=
"custom";
86 G4double spectatormass;
87 G4ParticleDefinition* spectator;
94 double massGeV =mass*
GeV;
97 if (name.compare(0,4,
"~HIP") == 0)
100 if ((name.compare(0,7,
"~HIPbar") == 0)) {
std::string str = name.substr (7); charge=eplus*atoi(str.c_str())/3.;}
101 else {
std::string str = name.substr (4); charge=eplus*atoi(str.c_str())*-1./3.; }
103 if (name.compare(0,9,
"anti_~HIP") == 0)
106 if ((name.compare(0,12,
"anti_~HIPbar") == 0)) {
std::string str = name.substr (12); charge=eplus*atoi(str.c_str())*-1./3.;}
107 else {
std::string str = name.substr (9); charge=eplus*atoi(str.c_str())*1./3.; }
118 double lifetime = -1;
134 G4DecayTable *decaytable =
NULL;
135 G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
138 parity, conjugation, isospin, isospinZ,
139 gParity, pType, lepton, baryon, pdgCode,
140 stable, lifetime, decaytable);
142 if(pType ==
"rhadron" && name!=
"~g"){
143 G4String cloudname = name+
"cloud";
144 G4String cloudtype = pType+
"cloud";
145 spectator = theParticleTable->FindParticle(1000021);
146 spectatormass = spectator->GetPDGMass();
147 G4double cloudmass = mass-spectatormass/
GeV;
149 cloudname, cloudmass * GeV , 0.0*
MeV, 0 ,
158 <<particle->
GetCloud()->GetParticleName()
161 <<particle->GetPDGMass()/GeV<<
" Gev, "
162 <<particle->
GetCloud()->GetPDGMass()/GeV<<
" GeV and "
164 }
else if(pType ==
"mesonino" || pType ==
"sbaryon") {
166 if(pdgCode < 0 ) sign=-1;
168 G4String cloudname = name+
"cloud";
169 G4String cloudtype = pType+
"cloud";
171 spectator = theParticleTable->FindParticle(1000006*sign);
175 spectator = theParticleTable->FindParticle(1000005*sign);
178 edm::LogError(
"CustomPhysics")<<
" Cannot find spectator parton";
181 spectatormass = spectator->GetPDGMass();
182 G4double cloudmass = mass-spectatormass/
GeV;
184 cloudname, cloudmass * GeV , 0.0*
MeV, 0 ,
193 <<particle->
GetCloud()->GetParticleName()
196 <<particle->GetPDGMass()/GeV<<
" Gev, "
197 <<particle->
GetCloud()->GetPDGMass()/GeV<<
" GeV and "
204 m_particles.insert(particle);
214 while (getline(*configFile,line)) {
215 line.erase(0, line.find_first_not_of(
" \t"));
216 if (line.length()==0 || line.at(0) ==
'#')
continue;
217 if (ToLower(line).find(
"block") < line.npos) {
218 edm::LogInfo(
"CustomPhysics") <<
" Finished the Mass Table ";
221 std::stringstream sstr(line);
222 sstr >> pdgId >> mass >> tmp >>
name;
224 edm::LogInfo(
"CustomPhysics") <<
"Calling addCustomParticle for pdgId: " << pdgId
225 <<
", mass " << mass <<
", name " <<
name;
226 addCustomParticle(pdgId, fabs(mass), name);
228 int pdgIdPartner = pdgId%100;
229 G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
230 G4ParticleDefinition *aParticle = theParticleTable->FindParticle(pdgIdPartner);
232 edm::LogInfo(
"CustomPhysics") <<
"Found aParticle = " << aParticle
233 <<
", pdgId = " << pdgId
234 <<
", pdgIdPartner = " << pdgIdPartner
240 !CustomPDGParser::s_isstopHadron(pdgId) &&
247 int sign = aParticle->GetAntiPDGEncoding()/pdgIdPartner;
248 edm::LogInfo(
"CustomPhysics") <<
"Found sign = " << sign
249 <<
", aParticle->GetAntiPDGEncoding() " << aParticle->GetAntiPDGEncoding()
250 <<
", pdgIdPartner = " << pdgIdPartner;
253 <<aParticle->GetAntiPDGEncoding()
254 <<
" b "<<pdgIdPartner;
255 aParticle->DumpTable();
257 if(sign==-1 && pdgId!=25 && pdgId!=35 && pdgId!=36 && pdgId!=37 && pdgId!=1000039){
259 edm::LogInfo(
"CustomPhysics") <<
"Calling addCustomParticle for antiparticle with pdgId: " << -pdgId
260 <<
", mass " << mass <<
", name " <<
tmp;
261 addCustomParticle(-pdgId, mass, tmp);
262 theParticleTable->FindParticle(pdgId)->SetAntiPDGEncoding(-pdgId);
264 else theParticleTable->FindParticle(pdgId)->SetAntiPDGEncoding(pdgId);
267 if(pdgId==1000039) theParticleTable->FindParticle(pdgId)->SetAntiPDGEncoding(pdgId);
268 if(pdgId==1000024 || pdgId==1000037 || pdgId==37) {
270 edm::LogInfo(
"CustomPhysics") <<
"Calling addCustomParticle for antiparticle (2) with pdgId: " << -pdgId
271 <<
", mass " << mass <<
", name " <<
tmp;
272 addCustomParticle(-pdgId, mass, tmp);
273 theParticleTable->FindParticle(pdgId)->SetAntiPDGEncoding(-pdgId);
283 std::vector<int> pdg(4);
285 std::vector<std::string>
name(4);
287 G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
289 std::string parentName = theParticleTable->FindParticle(pdgId)->GetParticleName();
290 G4DecayTable *decaytable=
new G4DecayTable();
292 while(getline(*configFile,line)) {
294 line.erase(0, line.find_first_not_of(
" \t"));
295 if (line.length()==0)
continue;
296 if (line.at(0) ==
'#' &&
297 ToLower(line).find(
"br") < line.npos &&
298 ToLower(line).find(
"nda") < line.npos)
continue;
299 if (line.at(0) ==
'#') {
300 edm::LogInfo(
"CustomPhysics") <<
" Finished the Decay Table ";
307 std::stringstream sstr(line);
308 sstr >> br >> nDaughters;
309 edm::LogInfo(
"CustomPhysics") <<
" Branching Ratio: " << br <<
", Number of Daughters: " << nDaughters;
310 if (nDaughters > 4) {
311 edm::LogError(
"CustomPhysics") <<
"Number of daughters is too large (max = 4): " << nDaughters <<
" for pdgId: " <<
pdgId;
314 for(
int i=0;
i<nDaughters;
i++) {
318 for (
int i=0;
i<nDaughters;
i++) {
319 if (!theParticleTable->FindParticle(pdg[
i])) {
320 edm::LogWarning(
"CustomPhysics")<<pdg[
i]<<
" CustomParticleFactory::getDecayTable(): not found in the table!";
323 name[
i] = theParticleTable->FindParticle(pdg[i])->GetParticleName();
326 G4PhaseSpaceDecayChannel *aDecayChannel =
new G4PhaseSpaceDecayChannel(parentName, br, nDaughters,
327 name[0],name[1],name[2],name[3]);
328 decaytable->Insert(aDecayChannel);
337 std::vector<std::string>
name(4);
338 G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
340 std::string parentName = theParticleTable->FindParticle(-pdgId)->GetParticleName();
341 G4DecayTable *decaytable=
new G4DecayTable();
343 for(
int i=0;
i<theDecayTable->entries();
i++){
345 G4VDecayChannel *theDecayChannel = theDecayTable->GetDecayChannel(
i);
346 for(
int j=0;
j<theDecayChannel->GetNumberOfDaughters();
j++){
347 int id = theDecayChannel->GetDaughter(
j)->GetAntiPDGEncoding();
348 std::string nameTmp = theParticleTable->FindParticle(
id)->GetParticleName();
351 G4PhaseSpaceDecayChannel *aDecayChannel =
352 new G4PhaseSpaceDecayChannel(parentName,
353 theDecayChannel->GetBR(),
354 theDecayChannel->GetNumberOfDaughters(),
355 name[0],name[1],name[2],name[3]);
356 decaytable->Insert(aDecayChannel);
365 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)