gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-2191-ga4742ac
a Global And Modular Bsm Inference Tool
particle_harvester Namespace Reference

Functions

def create_entry (macro, particle_list)
 
def main (argv)
 

Variables

string toolsfile = "./Utils/scripts/harvesting_tools.py"
 

Function Documentation

◆ create_entry()

def particle_harvester.create_entry (   macro,
  particle_list 
)
Create the correct entry to add to particle_database.cpp. The 
argument "macro" should be one of the macros in particle_macros.hpp.

Definition at line 34 of file particle_harvester.py.

References Gambit::ColliderBit.print().

Referenced by main().

34 def create_entry(macro, particle_list):
35 
36  '''Create the correct entry to add to particle_database.cpp. The
37  argument "macro" should be one of the macros in particle_macros.hpp.'''
38 
39  # Output to add to the particle database.
40  output = "\n "
41 
42  for i in range(0, len(particle_list)):
43 
44  entry = particle_list[i]
45 
46  PDG = entry['PDG_context']
47 
48  # Count how many particles appear in the PDG_context lists.
49  numlists = sum(1 for x in PDG if isinstance(x, list))
50 
51  if numlists == 0:
52  PDGbar = [-PDG[0], PDG[1]]
53  else:
54  PDGbar = [[-i[0], i[1]] for i in PDG]
55 
56  # Add description (C++ comment) if it exists
57  if 'description' in entry:
58  output += "\n // " + str(entry['description']) + "\n "
59 
60  # Get the spin x2 (return -1 if it is absent; i.e. for generic particles)
61  spinx2 = -1
62  if 'spinx2' in entry:
63  spinx2 = entry['spinx2']
64 
65  # If the spin isn't an integer, throw an error
66  if not isinstance(spinx2, int):
67  print('Spin (x2) for particle with name {}').format(entry['name'])
68  print('is not an integer. Please check particle_database.yaml.')
69  sys.exit()
70 
71  # Get the color (return -1 if it is absent; i.e. for generic particles)
72  color = -1
73  if 'color' in entry:
74  color = entry['color']
75 
76  # If we do not recognise the color assignment, throw an error
77  if color not in [-1, 1, 3, 6, 8]:
78  print(('Color for particle with name {}').format(entry['name']))
79  print(('given as {}. GAMBIT only knows [1, 3, 6, 8].').format(color))
80  print('Please check particle_database.yaml.')
81  sys.exit()
82 
83  chargex3 = -1
84  # Get the electric charge x3 (return -1 if it is absent, i.e. for generic particles)
85  if 'chargex3' in entry:
86  chargex3 = entry['chargex3']
87 
88  # If the electric charge (x3) isn't an integer, throw an error
89  if not isinstance(spinx2, int):
90  print('Charge (x3) for particle {}').format(entry['name'])
91  print('is not an integer. Please check particle_database.yaml.')
92  sys.exit()
93 
94  # Add the macro plus the particle name, plus the PDG-context pair.
95  output += macro + '("{0}", {1}, {2}, {3}, {4})\n '.format(str(entry['name']), str(PDG).replace(']',')').replace('[','('), str(spinx2), str(chargex3), str(color))
96 
97  # If the YAML file says there is a conjugate particle, add the name of it and the negative PDG-context pair
98  if 'conjugate' in entry:
99  output += macro + '("{0}", {1}, {2}, {3}, {4})\n '.format(str(entry['conjugate']), str(PDGbar).replace(']',')').replace('[','('), str(spinx2), str(chargex3), str(color))
100 
101  return output
102 
void print(MixMatrix A)
Helper function to print a matrix.
def create_entry(macro, particle_list)
std::string str
Shorthand for a standard string.
Definition: Analysis.hpp:35
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

def particle_harvester.main (   argv)

Definition at line 103 of file particle_harvester.py.

References create_entry().

103 def main(argv):
104 
105  with open("./config/particle_database.yaml", "r") as f:
106 
107  try:
108  data = yaml.safe_load(f)
109  except yaml.YAMLerror as exc:
110  print (exc)
111 
112  # These correspond to the five macros in particle_macros.hpp.
113  SM_particles = data['StandardModel']['Particles'] # add_SM_particle
114  SM_sets = data['StandardModel']['Sets'] # add_SM_partcle_set
115  BSM_particles = data['OtherModels']['Particles'] # add_particle
116  BSM_sets = data['OtherModels']['Sets'] # add_particle_set
117  Generic = data['OtherModels']['Generic'] # add_generic_particle
118 
119  towrite = "\
120 // GAMBIT: Global and Modular BSM Inference Tool\n\
121 // *********************************************\n\
122 /// \\file \n\
123 /// \n\
124 /// Compile-time generation of particle \n\
125 /// database. \n\
126 /// \n\
127 /// This file was automatically generated by \n\
128 /// particle_harvester.py. Do not modify. \n\
129 /// \n\
130 /// Do not add to this if you want to add new \n\
131 /// particles -- just add the particles to the \n\
132 /// include/gambit/Models/particle_database.yaml \n\
133 /// file, and be confident that the particle \n\
134 /// harvester will add it to the database. \n\
135 /// \n\
136 /// *********************************************\n\
137 /// \n\
138 /// Authors (add name and date if you modify): \n\
139 /// \n\
140 /// \\author The GAMBIT Collaboration \n\
141 /// \date "+datetime.datetime.now().strftime("%I:%M%p on %B %d, %Y")+"\n\
142 /// \n\
143 /// *********************************************\n\
144  \n\
145 // Automatically-generated particle database. \n\
146  \n\
147  \n\
148 #include \"gambit/Models/partmap.hpp\" \n\
149 #include \"gambit/Models/particle_macros.hpp\" \n\
150  \n\
151 namespace Gambit \n\
152 { \n\
153  \n\
154  namespace Models \n\
155  { \n\
156  \n\
157  void define_particles(partmap* particles) \n\
158  { \n"
159  towrite+= create_entry("add_SM_particle", SM_particles)
160 
161  towrite+= create_entry("add_SM_particle_set", SM_sets)
162 
163  towrite+= create_entry("add_particle", BSM_particles)
164 
165  towrite+= create_entry("add_particle_set", BSM_sets)
166 
167  towrite+= create_entry("add_generic_particle", Generic)
168 
169  towrite+=" \n\
170  } \n\
171  \n\
172  } \n\
173  \n\
174 } \n"
175 
176 
177  with open("./Models/src/particle_database.cpp","w") as f:
178  f.write(towrite)
179 
180 # Handle command line arguments (verbosity)
def create_entry(macro, particle_list)
Here is the call graph for this function:

Variable Documentation

◆ toolsfile

string particle_harvester.toolsfile = "./Utils/scripts/harvesting_tools.py"

Definition at line 31 of file particle_harvester.py.