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;
120 G4DecayTable *decaytable =
NULL;
121 G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
124 parity, conjugation, isospin, isospinZ,
125 gParity, pType, lepton, baryon, pdgCode,
126 stable, lifetime, decaytable);
128 if(pType ==
"rhadron" && name!=
"~g"){
129 G4String cloudname = name+
"cloud";
130 G4String cloudtype = pType+
"cloud";
131 spectator = theParticleTable->FindParticle(1000021);
132 spectatormass = spectator->GetPDGMass();
133 G4double cloudmass = mass-spectatormass/
GeV;
135 cloudname, cloudmass * GeV , 0.0*
MeV, 0 ,
144 <<particle->
GetCloud()->GetParticleName()
147 <<particle->GetPDGMass()/GeV<<
" Gev, "
148 <<particle->
GetCloud()->GetPDGMass()/GeV<<
" GeV and "
150 }
else if(pType ==
"mesonino" || pType ==
"sbaryon") {
152 if(pdgCode < 0 ) sign=-1;
154 G4String cloudname = name+
"cloud";
155 G4String cloudtype = pType+
"cloud";
157 spectator = theParticleTable->FindParticle(1000006*sign);
161 spectator = theParticleTable->FindParticle(1000005*sign);
164 edm::LogError(
"CustomPhysics")<<
" Cannot find spectator parton";
167 spectatormass = spectator->GetPDGMass();
168 G4double cloudmass = mass-spectatormass/
GeV;
170 cloudname, cloudmass * GeV , 0.0*
MeV, 0 ,
179 <<particle->
GetCloud()->GetParticleName()
182 <<particle->GetPDGMass()/GeV<<
" Gev, "
183 <<particle->
GetCloud()->GetPDGMass()/GeV<<
" GeV and "
190 m_particles.insert(particle);
200 while (getline(*configFile,line)) {
201 line.erase(0, line.find_first_not_of(
" \t"));
202 if (line.length()==0 || line.at(0) ==
'#')
continue;
203 if (ToLower(line).find(
"block") < line.npos) {
204 edm::LogInfo(
"CustomPhysics") <<
" Finished the Mass Table ";
207 std::stringstream sstr(line);
208 sstr >> pdgId >> mass >> tmp >>
name;
210 edm::LogInfo(
"CustomPhysics") <<
"Calling addCustomParticle for pdgId: " << pdgId
211 <<
", mass " << mass <<
", name " <<
name;
212 addCustomParticle(pdgId, fabs(mass), name);
214 int pdgIdPartner = pdgId%100;
215 G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
216 G4ParticleDefinition *aParticle = theParticleTable->FindParticle(pdgIdPartner);
218 edm::LogInfo(
"CustomPhysics") <<
"Found aParticle = " << aParticle
219 <<
", pdgId = " << pdgId
220 <<
", pdgIdPartner = " << pdgIdPartner
226 !CustomPDGParser::s_isstopHadron(pdgId) &&
233 int sign = aParticle->GetAntiPDGEncoding()/pdgIdPartner;
234 edm::LogInfo(
"CustomPhysics") <<
"Found sign = " << sign
235 <<
", aParticle->GetAntiPDGEncoding() " << aParticle->GetAntiPDGEncoding()
236 <<
", pdgIdPartner = " << pdgIdPartner;
239 <<aParticle->GetAntiPDGEncoding()
240 <<
" b "<<pdgIdPartner;
241 aParticle->DumpTable();
243 if(sign==-1 && pdgId!=25 && pdgId!=35 && pdgId!=36 && pdgId!=37 && pdgId!=1000039){
245 edm::LogInfo(
"CustomPhysics") <<
"Calling addCustomParticle for antiparticle with pdgId: " << -pdgId
246 <<
", mass " << mass <<
", name " <<
tmp;
247 addCustomParticle(-pdgId, mass, tmp);
248 theParticleTable->FindParticle(pdgId)->SetAntiPDGEncoding(-pdgId);
250 else theParticleTable->FindParticle(pdgId)->SetAntiPDGEncoding(pdgId);
253 if(pdgId==1000039) theParticleTable->FindParticle(pdgId)->SetAntiPDGEncoding(pdgId);
254 if(pdgId==1000024 || pdgId==1000037 || pdgId==37) {
256 edm::LogInfo(
"CustomPhysics") <<
"Calling addCustomParticle for antiparticle (2) with pdgId: " << -pdgId
257 <<
", mass " << mass <<
", name " <<
tmp;
258 addCustomParticle(-pdgId, mass, tmp);
259 theParticleTable->FindParticle(pdgId)->SetAntiPDGEncoding(-pdgId);
269 std::vector<int> pdg(4);
271 std::vector<std::string>
name(4);
273 G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
275 std::string parentName = theParticleTable->FindParticle(pdgId)->GetParticleName();
276 G4DecayTable *decaytable=
new G4DecayTable();
278 while(getline(*configFile,line)) {
280 line.erase(0, line.find_first_not_of(
" \t"));
281 if (line.length()==0)
continue;
282 if (line.at(0) ==
'#' &&
283 ToLower(line).find(
"br") < line.npos &&
284 ToLower(line).find(
"nda") < line.npos)
continue;
285 if (line.at(0) ==
'#') {
286 edm::LogInfo(
"CustomPhysics") <<
" Finished the Decay Table ";
293 std::stringstream sstr(line);
294 sstr >> br >> nDaughters;
295 edm::LogInfo(
"CustomPhysics") <<
" Branching Ratio: " << br <<
", Number of Daughters: " << nDaughters;
296 if (nDaughters > 4) {
297 edm::LogError(
"CustomPhysics") <<
"Number of daughters is too large (max = 4): " << nDaughters <<
" for pdgId: " <<
pdgId;
300 for(
int i=0;
i<nDaughters;
i++) {
304 for (
int i=0;
i<nDaughters;
i++) {
305 if (!theParticleTable->FindParticle(pdg[
i])) {
306 edm::LogWarning(
"CustomPhysics")<<pdg[
i]<<
" CustomParticleFactory::getDecayTable(): not found in the table!";
309 name[
i] = theParticleTable->FindParticle(pdg[i])->GetParticleName();
312 G4PhaseSpaceDecayChannel *aDecayChannel =
new G4PhaseSpaceDecayChannel(parentName, br, nDaughters,
313 name[0],name[1],name[2],name[3]);
314 decaytable->Insert(aDecayChannel);
323 std::vector<std::string>
name(4);
324 G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
326 std::string parentName = theParticleTable->FindParticle(-pdgId)->GetParticleName();
327 G4DecayTable *decaytable=
new G4DecayTable();
329 for(
int i=0;
i<theDecayTable->entries();
i++){
331 G4VDecayChannel *theDecayChannel = theDecayTable->GetDecayChannel(
i);
332 for(
int j=0;
j<theDecayChannel->GetNumberOfDaughters();
j++){
333 int id = theDecayChannel->GetDaughter(
j)->GetAntiPDGEncoding();
334 std::string nameTmp = theParticleTable->FindParticle(
id)->GetParticleName();
337 G4PhaseSpaceDecayChannel *aDecayChannel =
338 new G4PhaseSpaceDecayChannel(parentName,
339 theDecayChannel->GetBR(),
340 theDecayChannel->GetNumberOfDaughters(),
341 name[0],name[1],name[2],name[3]);
342 decaytable->Insert(aDecayChannel);
351 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)