ATLAS Offline Software
Static Public Member Functions | Static Private Member Functions | List of all members
CustomParticleFactory Class Reference

#include <CustomParticleFactory.h>

Collaboration diagram for CustomParticleFactory:

Static Public Member Functions

static void loadCustomParticles ()
 
static bool isCustomParticle (G4ParticleDefinition *particle)
 

Static Private Member Functions

static std::set< G4ParticleDefinition * > load ()
 

Detailed Description

Definition at line 16 of file CustomParticleFactory.h.

Member Function Documentation

◆ isCustomParticle()

bool CustomParticleFactory::isCustomParticle ( G4ParticleDefinition *  particle)
static

Definition at line 23 of file CustomParticleFactory.cxx.

24 {
25  static const std::set<G4ParticleDefinition *> particles = load();
26  return (particle!=nullptr && particles.find(particle)!=particles.end());
27 }

◆ load()

std::set< G4ParticleDefinition * > CustomParticleFactory::load ( )
staticprivate

Definition at line 35 of file CustomParticleFactory.cxx.

36 {
37  // the existing particle table
38  G4ParticleTable *theParticleTable = G4ParticleTable::GetParticleTable();
39 
40 
41  std::set<G4ParticleDefinition *> particles;
42 
43  std::ifstream configFile("particles.txt");
44  G4String pType="custom";
45  G4String pSubType="";
46  G4double spectatormass = 0;
47  G4ParticleDefinition* spectator = 0;
48  bool first = true;
49  double mass;
50  int pdgCode;
51  std::string name,line;
52  // This should be compatible IMO to SLHA
53  while (getline(configFile,line)) {
54  G4cout << "-------------------------------------------------" << G4endl;
55  std::string::size_type beg_idx,end_idx;
56 
57  beg_idx = line.find_first_not_of("\t #");
58  if (beg_idx > 0 && line[beg_idx-1] == '#') continue;
59  end_idx = line.find_first_of( "\t ", beg_idx);
60  if (end_idx == std::string::npos) continue;
61  char *endptr;
62  const std::string pdgCodeString = line.substr( beg_idx, end_idx - beg_idx );
63  pdgCode = strtol(pdgCodeString.c_str(), &endptr, 0);
64  if (endptr[0] != '\0') {
65  throw std::invalid_argument("Could not convert string to int: " + line.substr( beg_idx, end_idx - beg_idx ));
66  }
67 
68  beg_idx = line.find_first_not_of("\t ",end_idx);
69  end_idx = line.find_first_of( "\t #", beg_idx);
70  if (end_idx == std::string::npos) continue;
71  mass = atof(line.substr( beg_idx, end_idx - beg_idx ).c_str());
72 
73  beg_idx = line.find_first_not_of("\t# ",end_idx);
74  end_idx = line.length();
75  if (beg_idx==std::string::npos) beg_idx = end_idx;
76  name = line.substr( beg_idx, end_idx - beg_idx );
77  while (name.c_str()[0] == ' ') { name.erase(0,1); }
78  while (name[name.size()-1] == ' ') { name.erase(name.size()-1,1); }
79 
80  if (abs(pdgCode) / 1000000 == 0){
81  G4cout << "Pdg code too low " << pdgCode << " "<<abs(pdgCode) / 1000000 << std::endl;
82  continue;
83  }
84 
85  pType="custom";
86  if (MC::isRHadron(pdgCode)) pType = "rhadron";
87  if (MC::isSlepton(pdgCode)) pType = "sLepton";
88 
89  G4cout<<"pType: "<<pType<<G4endl;
90  G4cout<<"Charge of "<<name<<" is "<<MC::charge(pdgCode)<<G4endl;
91 
92  G4ParticleDefinition* previousDefinition = theParticleTable->FindParticle(pdgCode);
93  // if the particle has somehow already been added to the G4ParticleTable remove it
94  if (previousDefinition) {
95  G4cout << "Found a previousDefinition for " << name << "(" << pdgCode << ") in G4ParticleTable. Assuming that we want the new definition, so removing previous defnition! May cause issues elsewhere though..." << G4endl;
96  previousDefinition->DumpTable();
97  theParticleTable->Remove(previousDefinition);
98  delete previousDefinition;
99  }
100 
102  name, mass * CLHEP::GeV , 0.0*CLHEP::MeV, CLHEP::eplus * MC::charge(pdgCode),
103  MC::spin2(pdgCode), +1, 0,
104  0, 0, 0,
105  pType, 0, +1, pdgCode,
106  true, -1.0, NULL );
107  if (pType=="custom") {
108  spectatormass = mass;
109  spectator=particle;
110  particle->SetCloud(0);
111  particle->SetSpectator(0);
112  }
113  if (first) {
114  first = false;
115  spectatormass = mass;
116  spectator=particle;
117  particle->SetCloud(0);
118  particle->SetSpectator(0);
119  } else {
120  G4String cloudname = name+"cloud";
121  G4String cloudtype = pType+"cloud";
122  G4double cloudmass = mass-spectatormass;
123  CustomParticle *tmpParticle = new CustomParticle(
124  cloudname, cloudmass * CLHEP::GeV , 0.0*CLHEP::MeV, 0 ,
125  0, +1, 0,
126  0, 0, 0,
127  cloudtype, 0, +1, 0,
128  true, -1.0, NULL );
129  particle->SetCloud(tmpParticle);
130  particle->SetSpectator(spectator);
131 
132  G4cout << name << " being assigned cloud " << particle->GetCloud()->GetParticleName() << " and spectator " << particle->GetSpectator()->GetParticleName() << G4endl;
133  G4cout << "Masses: "
134  << particle->GetPDGMass()/CLHEP::GeV << " Gev, "
135  << particle->GetCloud()->GetPDGMass()/CLHEP::GeV << " GeV and "
136  << particle->GetSpectator()->GetPDGMass()/CLHEP::GeV << " GeV."
137  << G4endl;
138  }
139 
140  particles.insert(particle);
141  }
142  configFile.close();
143  G4cout << "-------------------------------------------------" << G4endl;
144 
145  // Reading decays from file
146  std::vector<std::vector<std::string>* > decays;
147  std::ifstream decayFile("decays.txt");
148  while (getline(decayFile,line)) {
149  std::istringstream is(line);
150  std::vector<std::string>* txtvec = new std::vector<std::string>(std::istream_iterator<std::string>(is),std::istream_iterator<std::string>());
151  decays.push_back(txtvec);
152  }
153  decayFile.close();
154 
155  // Looping over custom particles to add decays
157  name=(*part)->GetParticleName();
158  std::vector<std::vector<std::string> > mydecays;
159  for (unsigned int i = 0; i!= decays.size(); i++) {
160  if (name==(*(decays[i]))[0]) {
161  // Is this decay for me?
162  mydecays.push_back(*(decays[i]));
163  }
164  } // End of the for loop
165  if (mydecays.size()>0) { // Did I get any decays?
166  const int ndec=std::ssize(mydecays);
167  G4DecayTable* table = new G4DecayTable();
168  G4VDecayChannel** mode = new G4VDecayChannel*[ndec]{};
169  for (int i=0;i!=ndec;i++) {
170  std::vector<std::string> thisdec=mydecays[i];//deliberate copy
171  if (thisdec.empty()) continue;
172  const double branch = std::stod(thisdec.back()); // Reading branching ratio
173  thisdec.pop_back(); // Removing the number from the vector
174  for (const auto & thisString:thisdec) G4cout<<thisString<<G4endl;
175  if (thisdec.size()==3) {
176  mode[i] = new G4PhaseSpaceDecayChannel(thisdec[0],branch,2,thisdec[1],thisdec[2]);
177  } else if (thisdec.size()==4) {
178  mode[i] = new G4PhaseSpaceDecayChannel(thisdec[0],branch,3,thisdec[1],thisdec[2],thisdec[3]);
179  } else {
180  G4cout<<"Decay chain invalid!!!"<<std::endl;
181  }
182  }
183  for (G4int index=0; index <ndec; index++ ) { table->Insert(mode[index]); }
184  delete [] mode;
185  (*part)->SetDecayTable(table);
186  }
187  }
188  return particles;
189 }

◆ loadCustomParticles()

void CustomParticleFactory::loadCustomParticles ( )
static

Definition at line 29 of file CustomParticleFactory.cxx.

30 {
31  // tickle the loading of the particles if it wasn't done yet
32  isCustomParticle(nullptr);
33 }

The documentation for this class was generated from the following files:
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:17
checkFileSG.line
line
Definition: checkFileSG.py:75
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
taskman.configFile
configFile
Definition: taskman.py:311
Base_Fragment.mass
mass
Definition: Sherpa_i/share/common/Base_Fragment.py:59
index
Definition: index.py:1
SUSY_SimplifiedModel_PreInclude.decays
dictionary decays
Definition: SUSY_SimplifiedModel_PreInclude.py:12
python.SystemOfUnits.MeV
int MeV
Definition: SystemOfUnits.py:154
lumiFormat.i
int i
Definition: lumiFormat.py:85
EvtGen_Fragment.decayFile
decayFile
Definition: EvtGen_Fragment.py:27
Preparation.mode
mode
Definition: Preparation.py:94
CustomParticleFactory::isCustomParticle
static bool isCustomParticle(G4ParticleDefinition *particle)
Definition: CustomParticleFactory.cxx:23
CustomParticleFactory::load
static std::set< G4ParticleDefinition * > load()
Definition: CustomParticleFactory.cxx:35
CxxUtils::atof
double atof(std::string_view str)
Converts a string into a double / float.
Definition: Control/CxxUtils/Root/StringUtils.cxx:91
CustomParticle
Definition: CustomParticle.h:17
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
python.ext.table_printer.table
list table
Definition: table_printer.py:81
charge
double charge(const T &p)
Definition: AtlasPID.h:756
isSlepton
bool isSlepton(const T &p)
Definition: AtlasPID.h:425
spin2
int spin2(const T &p)
Definition: AtlasPID.h:845
RTTAlgmain.branch
branch
Definition: RTTAlgmain.py:61
DeMoScan.first
bool first
Definition: DeMoScan.py:536
LArG4FSStartPointFilter.particles
list particles
Definition: LArG4FSStartPointFilter.py:84
isRHadron
bool isRHadron(const T &p)
Definition: AtlasPID.h:871
python.SystemOfUnits.eplus
int eplus
Definition: SystemOfUnits.py:137