CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CustomParticleFactory.cc
Go to the documentation of this file.
1 #include <fstream>
2 #include <iomanip>
3 #include <iostream>
4 #include <string>
5 #include <vector>
6 #include <sstream>
7 #include <set>
8 
12 
16 
17 #include <G4ParticleTable.hh>
18 #include "G4DecayTable.hh"
19 #include <G4PhaseSpaceDecayChannel.hh>
20 #include "G4ProcessManager.hh"
21 
22 
24 std::set<G4ParticleDefinition *> CustomParticleFactory::m_particles;
25 
26 bool CustomParticleFactory::isCustomParticle(G4ParticleDefinition *particle)
27 {
28  return (m_particles.find(particle)!=m_particles.end());
29 }
30 
31 void CustomParticleFactory::loadCustomParticles(const std::string & filePath){
32  if(loaded) return;
33  loaded = true;
34 
35  std::ifstream configFile(filePath.c_str());
36 
37  std::string line;
38  // This should be compatible IMO to SLHA
39  G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
40  while(getline(configFile,line)){
41  if(line.find("PDG code")<line.npos) getMassTable(&configFile);
42  if(line.find("DECAY")<line.npos){
43  int pdgId;
44  double width;
45  std::string tmpString;
46  std::stringstream lineStream(line);
47  lineStream>>tmpString>>pdgId>>width;
48  G4DecayTable* aDecayTable = getDecayTable(&configFile, pdgId);
49  G4ParticleDefinition *aParticle = theParticleTable->FindParticle(pdgId);
50  G4ParticleDefinition *aAntiParticle = theParticleTable->FindAntiParticle(pdgId);
51  if(!aParticle) continue;
52  aParticle->SetDecayTable(aDecayTable);
53  aParticle->SetPDGStable(false);
54  aParticle->SetPDGLifeTime(1.0/(width*GeV)*6.582122e-22*MeV*s);
55  if(aAntiParticle && aAntiParticle->GetPDGEncoding()!=pdgId){
56  //aAntiParticle->SetDecayTable(getAntiDecayTable(pdgId,aDecayTable));
57  aAntiParticle->SetPDGStable(false);
58  aParticle->SetPDGLifeTime(1.0/(width*GeV)*6.582122e-22*MeV*s);
59  }
60  }
61  }
62 }
63 
64 
65 void CustomParticleFactory::addCustomParticle(int pdgCode, double mass, const std::string & name){
66 
67 
68  if(abs(pdgCode)%100 <14 && abs(pdgCode) / 1000000 == 0){
69  edm::LogError("") << "Pdg code too low " << pdgCode << " "<<abs(pdgCode) / 1000000 << std::endl;
70  return;
71  }
72 
73 
75  G4String pType="custom";
76  G4String pSubType="";
77  G4double spectatormass;
78  G4ParticleDefinition* spectator;
80  if(CustomPDGParser::s_isRHadron(pdgCode)) pType = "rhadron";
81  if(CustomPDGParser::s_isSLepton(pdgCode)) pType = "sLepton";
82  if(CustomPDGParser::s_isMesonino(pdgCode)) pType = "mesonino";
83  if(CustomPDGParser::s_isSbaryon(pdgCode)) pType = "sbaryon";
84 
85  double massGeV =mass*GeV;
86  double width = 0.0*MeV;
87  double charge = eplus* CustomPDGParser::s_charge(pdgCode);
88  if (name.compare(0,4,"~HIP") == 0)
89  {
90 
91  if ((name.compare(0,7,"~HIPbar") == 0)) {std::string str = name.substr (7); charge=eplus*atoi(str.c_str())/3.;}
92  else {std::string str = name.substr (4); charge=eplus*atoi(str.c_str())*-1./3.; }
93  }
94  if (name.compare(0,9,"anti_~HIP") == 0)
95  {
96 
97  if ((name.compare(0,12,"anti_~HIPbar") == 0)) {std::string str = name.substr (12); charge=eplus*atoi(str.c_str())*-1./3.;}
98  else {std::string str = name.substr (9); charge=eplus*atoi(str.c_str())*1./3.; }
99  }
100  int spin = (int)CustomPDGParser::s_spin(pdgCode)-1;
101  int parity = +1;
102  int conjugation = 0;
103  int isospin = 0;
104  int isospinZ = 0;
105  int gParity = 0;
106  int lepton = 0; //FIXME:
107  int baryon = 1; //FIXME:
108  bool stable = true;
109  double lifetime = -1;
110 
111  G4DecayTable *decaytable = NULL;
112  G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
113 
114  CustomParticle *particle = new CustomParticle(name, massGeV, width, charge, spin,
115  parity, conjugation, isospin, isospinZ,
116  gParity, pType, lepton, baryon, pdgCode,
117  stable, lifetime, decaytable);
118 
119  if(pType == "rhadron" && name!="~g"){
120  G4String cloudname = name+"cloud";
121  G4String cloudtype = pType+"cloud";
122  spectator = theParticleTable->FindParticle(1000021);
123  spectatormass = spectator->GetPDGMass();
124  G4double cloudmass = mass-spectatormass/GeV;
125  CustomParticle *tmpParticle = new CustomParticle(
126  cloudname, cloudmass * GeV , 0.0*MeV, 0 ,
127  0, +1, 0,
128  0, 0, 0,
129  cloudtype, 0, +1, 0,
130  true, -1.0, NULL );
131  particle->SetCloud(tmpParticle);
132  particle->SetSpectator(spectator);
133 
134  edm::LogInfo("CustomPhysics")<<name<<" being assigned "
135  <<particle->GetCloud()->GetParticleName()
136  <<" and "<<particle->GetSpectator()->GetParticleName()<<std::endl;
137  edm::LogInfo("CustomPhysics")<<"Masses: "
138  <<particle->GetPDGMass()/GeV<<" Gev, "
139  <<particle->GetCloud()->GetPDGMass()/GeV<<" GeV and "
140  <<particle->GetSpectator()->GetPDGMass()/GeV<<" GeV."
141  <<std::endl;
142  }else if(pType == "mesonino" || pType == "sbaryon")
143  {
144  int sign=1;
145  if(pdgCode < 0 ) sign=-1;
146 
147  G4String cloudname = name+"cloud";
148  G4String cloudtype = pType+"cloud";
150  {
151  spectator = theParticleTable->FindParticle(1000006*sign);
152  }
153  else
154  {
156  spectator = theParticleTable->FindParticle(1000005*sign);
157  }
158  else
159  {
160  spectator = 0;
161  edm::LogError("CustomPhysics")<< " Cannot find spectator parton";
162  }
163  }
164  spectatormass = spectator->GetPDGMass();
165  G4double cloudmass = mass-spectatormass/GeV;
166  CustomParticle *tmpParticle = new CustomParticle(
167  cloudname, cloudmass * GeV , 0.0*MeV, 0 ,
168  0, +1, 0,
169  0, 0, 0,
170  cloudtype, 0, +1, 0,
171  true, -1.0, NULL );
172  particle->SetCloud(tmpParticle);
173  particle->SetSpectator(spectator);
174 
175  edm::LogInfo("CustomPhysics")<<name<<" being assigned "
176  <<particle->GetCloud()->GetParticleName()
177  <<" and "<<particle->GetSpectator()->GetParticleName()<<std::endl;
178  edm::LogInfo("CustomPhysics")<<"Masses: "
179  <<particle->GetPDGMass()/GeV<<" Gev, "
180  <<particle->GetCloud()->GetPDGMass()/GeV<<" GeV and "
181  <<particle->GetSpectator()->GetPDGMass()/GeV<<" GeV."
182  <<std::endl;
183  }
184  else{
185  particle->SetCloud(0);
186  particle->SetSpectator(0);
187  }
188  m_particles.insert(particle);
189 }
190 
192 
193  int pdgId;
194  double mass;
195  std::string name, tmp;
196  std::string line;
197  // This should be compatible IMO to SLHA
198  while(getline(*configFile,line))
199  {
200  if(tmp.find("Blo")<tmp.npos) break;
201  std::stringstream sstr(line);
202  sstr >>pdgId>>mass>>tmp>>name;
203 
204  addCustomParticle(pdgId, fabs(mass), name);
206  int pdgIdPartner = pdgId%100;
207  G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
208  G4ParticleDefinition *aParticle = theParticleTable->FindParticle(pdgIdPartner);
209  //Add antiparticles for SUSY particles only, not for rHadrons.
210  if(aParticle && !CustomPDGParser::s_isRHadron(pdgId) && !CustomPDGParser::s_isstopHadron(pdgId)&& pdgId!=1000006 && pdgId!=-1000006 && pdgId!=25 && pdgId!=35 && pdgId!=36 && pdgId!=37){
211  int sign = aParticle->GetAntiPDGEncoding()/pdgIdPartner;
212  if(abs(sign)!=1) {
213  std::cout<<"sgn: "<<sign<<" a "
214  <<aParticle->GetAntiPDGEncoding()
215  <<" b "<<pdgIdPartner
216  <<std::endl;
217  aParticle->DumpTable();
218  }
219  if(sign==-1 && pdgId!=25 && pdgId!=35 && pdgId!=36 && pdgId!=37 && pdgId!=1000039){
220  tmp = "anti_"+name;
221  addCustomParticle(-pdgId, mass, tmp);
222  theParticleTable->FindParticle(pdgId)->SetAntiPDGEncoding(-pdgId);
223  }
224  else theParticleTable->FindParticle(pdgId)->SetAntiPDGEncoding(pdgId);
225  }
226 
227  if(pdgId==1000039) theParticleTable->FindParticle(pdgId)->SetAntiPDGEncoding(pdgId);
228  if(pdgId==1000024 || pdgId==1000037 || pdgId==37) {
229  tmp = "anti_"+name;
230  addCustomParticle(-pdgId, mass, tmp);
231  theParticleTable->FindParticle(pdgId)->SetAntiPDGEncoding(-pdgId);
232  }
233 
234 /* getline(*configFile,tmp);
235  char text[100];
236  configFile->get(text,3);
237  tmp.clear();
238  tmp.append(text);
239  if(tmp.find("Bl")<tmp.npos) break;*/
240  }
241 }
242 
243 G4DecayTable* CustomParticleFactory::getDecayTable(std::ifstream *configFile, int pdgId) {
244 
245  double br;
246  int nDaughters;
247  std::vector<int> pdg(4);
248  std::string tmp;
249  std::vector<std::string> name(4);
250 
251  G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
252 
253  std::string parentName = theParticleTable->FindParticle(pdgId)->GetParticleName();
254  G4DecayTable *decaytable= new G4DecayTable();
255 
256  getline(*configFile,tmp);
257 
258  while(!configFile->eof()){
259  pdg.clear();
260  name.clear();
261  (*configFile)>>br>>nDaughters;
262  for(int i=0;i<nDaughters;i++) (*configFile)>>pdg[i];
263  getline(*configFile,tmp);
264  for(int i=0;i<nDaughters;i++){
265  if(!theParticleTable->FindParticle(pdg[i])){
266  //std::cout<<pdg[i]<<" CustomParticleFactory::getDecayTable(): not found in the table!"<<std::endl;
267  continue;
268  }
269  name[i] = theParticleTable->FindParticle(pdg[i])->GetParticleName();
270  }
272  G4PhaseSpaceDecayChannel *aDecayChannel = new G4PhaseSpaceDecayChannel(parentName, br, nDaughters,
273  name[0],name[1],name[2],name[3]);
274  decaytable->Insert(aDecayChannel);
275 
277 
278  char text[200];
279  configFile->get(text,2);
280  tmp.clear();
281  tmp.append(text);
282  if(tmp.find("#")<tmp.npos) break;
283  }
284 
285  return decaytable;
286 }
287 
288 G4DecayTable* CustomParticleFactory::getAntiDecayTable(int pdgId, G4DecayTable *theDecayTable) {
289 
290  std::vector<std::string> name(4);
291  G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
292 
293  std::string parentName = theParticleTable->FindParticle(-pdgId)->GetParticleName();
294  G4DecayTable *decaytable= new G4DecayTable();
295 
296  for(int i=0;i<theDecayTable->entries();i++){
297  //G4PhaseSpaceDecayChannel *theDecayChannel = theDecayTable->GetDecayChannel(i);
298  G4VDecayChannel *theDecayChannel = theDecayTable->GetDecayChannel(i);
299  for(int j=0;j<theDecayChannel->GetNumberOfDaughters();j++){
300  int id = theDecayChannel->GetDaughter(j)->GetAntiPDGEncoding();
301  std::string nameTmp = theParticleTable->FindParticle(id)->GetParticleName();
302  name[j] = nameTmp;
303  }
304  G4PhaseSpaceDecayChannel *aDecayChannel =
305  new G4PhaseSpaceDecayChannel(parentName,
306  theDecayChannel->GetBR(),
307  theDecayChannel->GetNumberOfDaughters(),
308  name[0],name[1],name[2],name[3]);
309  decaytable->Insert(aDecayChannel);
310  }
311  return decaytable;
312 }
int i
Definition: DBlmapReader.cc:9
static std::set< G4ParticleDefinition * > m_particles
static double s_charge(int pdg)
static const int stable
Definition: TopGenEvent.h:11
static bool s_isSbaryon(int pdg)
void SetCloud(G4ParticleDefinition *theCloud)
#define abs(x)
Definition: mlp_lapack.h:159
G4ParticleDefinition * GetCloud()
#define NULL
Definition: scimark2.h:8
double charge(const std::vector< uint8_t > &Ampls)
static void loadCustomParticles(const std::string &filePath)
static bool s_isMesonino(int pdg)
static bool s_isSLepton(int pdg)
tuple br
Definition: scaleCards.py:54
int j
Definition: DBlmapReader.cc:9
tuple text
Definition: runonSM.py:42
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
Definition: MVATrainer.cc:100
static bool s_issbottomHadron(int pdg)
static bool isCustomParticle(G4ParticleDefinition *particle)
tuple mass
Definition: scaleCards.py:27
tuple cout
Definition: gather_cfg.py:121
static bool s_isstopHadron(int pdg)
float spin(float ph)