gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-252-gf9a3f78
a Global And Modular Bsm Inference Tool
partmap.cpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
17 
18 
19 #include <sstream>
20 
24 
25 namespace Gambit
26 {
27 
28  namespace Models
29  {
30 
33  {
34  static partmap local;
35  return local;
36  }
37 
39  extern void define_particles(partmap*);
40 
43 
45  void partmap::add(str long_name, std::pair<int, int> pdgpr)
46  {
47  if (has_particle(long_name))
48  {
49  model_error().raise(LOCAL_INFO,"Particle "+long_name+" is multiply defined.");
50  }
53  }
54 
56  void partmap::add_SM(str long_name, std::pair<int, int> pdgpr)
57  {
58  add(long_name, pdgpr);
59  SM.push_back(pdgpr);
60  }
61 
63  void partmap::add_generic(str long_name, std::pair<int, int> pdgpr)
64  {
65  add(long_name, pdgpr);
66  generic.push_back(pdgpr);
67  }
68 
70  void partmap::add_with_short_pair(str long_name, std::pair<int, int> pdgpr, std::pair<str, int> shortpr)
71  {
72  add(long_name, pdgpr);
73  short_name_pair_to_pdg_pair[shortpr] = pdgpr;
75  pdg_pair_to_short_name_pair[pdgpr] = shortpr;
77  }
78 
80  void partmap::add_SM_with_short_pair(str long_name, std::pair<int, int> pdgpr, std::pair<str, int> shortpr)
81  {
82  add_with_short_pair(long_name, pdgpr, shortpr);
83  SM.push_back(pdgpr);
84  }
85 
87  std::pair<int, int> partmap::pdg_pair(str long_name) const
88  {
89  if (not has_particle(long_name))
90  {
91  model_error().raise(LOCAL_INFO,"Particle long name "+long_name+" is not in the particle database.");
92  }
93  return long_name_to_pdg_pair.at(long_name);
94  }
95 
97  std::pair<int, int> partmap::pdg_pair(std::pair<str,int> shortpr) const
98  {
99  return pdg_pair(shortpr.first,shortpr.second);
100  }
101 
103  std::pair<int, int> partmap::pdg_pair(str short_name, int i) const
104  {
105  std::pair<str, int> shortpr(short_name, i);
106  if (not has_particle(shortpr))
107  {
108  std::ostringstream ss;
109  ss << "Short name " << short_name << " and index " << i << " are not in the particle database.";
110  model_error().raise(LOCAL_INFO,ss.str());
111  }
112  return short_name_pair_to_pdg_pair.at(shortpr);
113  }
114 
116  str partmap::long_name(str short_name, int i) const
117  {
118  std::pair<str, int> shortpr(short_name, i);
119  if (not has_particle(std::pair<str, int>(short_name, i)))
120  {
121  std::ostringstream ss;
122  ss << "Short name " << short_name << " and index " << i << " are not in the particle database.";
123  model_error().raise(LOCAL_INFO,ss.str());
124  }
125  return short_name_pair_to_long_name.at(shortpr);
126  }
127 
129  str partmap::long_name(std::pair<int, int> pdgpr) const
130  {
131  if (not has_particle(pdgpr))
132  {
133  std::ostringstream ss;
134  ss << "Particle with PDG code " << pdgpr.first << " and context integer " << pdgpr.second << " is not in the particle database.";
135  model_error().raise(LOCAL_INFO,ss.str());
136  }
137  return pdg_pair_to_long_name.at(pdgpr);
138  }
139 
141  str partmap::long_name(int pdg_code, int context) const
142  {
143  return long_name(std::make_pair(pdg_code,context));
144  }
145 
147  std::pair<str, int> partmap::short_name_pair(str long_name) const
148  {
149  if (not has_particle(long_name))
150  {
151  model_error().raise(LOCAL_INFO,"Particle "+long_name+" is not in the particle database.");
152  }
153  if (not has_short_name(long_name))
154  {
155  model_error().raise(LOCAL_INFO,"Particle "+long_name+" does not have a short name.");
156  }
157  return long_name_to_short_name_pair.at(long_name);
158  }
159 
161  std::pair<str, int> partmap::short_name_pair(std::pair<int, int> pdgpr) const
162  {
163  if (not has_particle(pdgpr))
164  {
165  std::ostringstream ss;
166  ss << "Particle with PDG code " << pdgpr.first << " and context integer " << pdgpr.second << " is not in the particle database.";
167  model_error().raise(LOCAL_INFO,ss.str());
168  }
169  if (not has_short_name(pdgpr))
170  {
171  std::ostringstream ss;
172  ss << "Particle with PDG code " << pdgpr.first << " and context integer " << pdgpr.second << " does not have a short name.";
173  model_error().raise(LOCAL_INFO,ss.str());
174  }
175  return pdg_pair_to_short_name_pair.at(pdgpr);
176  }
177 
179  std::pair<str, int> partmap::short_name_pair(int pdg_code, int context) const
180  {
181  return short_name_pair(std::make_pair(pdg_code,context));
182  }
183 
185  const std::vector<std::pair<int, int> >& partmap::get_SM_particles() const
186  {
187  return SM;
188  }
189 
191  const std::vector<std::pair<int, int> >& partmap::get_generic_particles() const
192  {
193  return generic;
194  }
195 
198  {
199  return (long_name_to_pdg_pair.find(long_name) != long_name_to_pdg_pair.end());
200  }
201 
203  bool partmap::has_particle(str short_name, int i) const
204  {
205  return has_particle(std::make_pair(short_name,i));
206  }
207  bool partmap::has_particle(std::pair<str, int> shortpr) const
208  {
209  return (short_name_pair_to_pdg_pair.find(shortpr) != short_name_pair_to_pdg_pair.end());
210  }
211 
213  bool partmap::has_particle(std::pair<int, int> pdgpr) const
214  {
215  return (pdg_pair_to_long_name.find(pdgpr) != pdg_pair_to_long_name.end());
216  }
217 
220  {
221  return (long_name_to_short_name_pair.find(long_name) != long_name_to_short_name_pair.end());
222  }
223 
225  bool partmap::has_short_name(std::pair<int, int> pdgpr) const
226  {
227  return (pdg_pair_to_short_name_pair.find(pdgpr) != pdg_pair_to_short_name_pair.end());
228  }
229 
232  {
233  return long_name(get_antiparticle(pdg_pair(lname)));
234  }
235 
238  std::pair<str, int> partmap::get_antiparticle(std::pair<str, int> shortpr) const
239  {
240  return short_name_pair(get_antiparticle(pdg_pair(shortpr)));
241  }
242  std::pair<str, int> partmap::get_antiparticle(str name, int index) const
243  {
244  return get_antiparticle(std::make_pair(name,index));
245  }
247 
250  std::pair<int, int> partmap::get_antiparticle(std::pair<int, int> pdgpr) const
251  {
252  if (has_antiparticle(pdgpr))
253  {
255  pdgpr.first = -pdgpr.first;
256  }
259  return pdgpr;
260  }
261  std::pair<int, int> partmap::get_antiparticle(int pdgcode, int context) const
262  {
263  return get_antiparticle(std::make_pair(pdgcode,context));
264  }
266 
270  {
271  return has_antiparticle(pdg_pair(long_name));
272  }
273 
276  bool partmap::has_antiparticle(std::pair<str, int> shortpr) const
277  {
278  return has_antiparticle(pdg_pair(shortpr));
279  }
280  bool partmap::has_antiparticle(str name, int index) const
281  {
282  return has_antiparticle(std::make_pair(name,index));
283  }
285 
288  bool partmap::has_antiparticle(std::pair<int, int> pdgpr) const
289  {
291  pdgpr.first = -pdgpr.first;
292  return has_particle(pdgpr);
293  }
294  bool partmap::has_antiparticle(int pdgcode, int context) const
295  {
296  return has_antiparticle(std::make_pair(pdgcode,context));
297  }
299 
302  {
303  // Check that long and short names retrieve same information (when short name exists)
304  typedef std::map<str, std::pair<int, int> >::const_iterator it_long_name_to_pdg_pair;
305  typedef std::map<std::pair<int, int>, str>::const_iterator it_pdg_pair_to_long_name;
306  typedef std::map<std::pair<str, int>, str>::const_iterator it_short_name_pair_to_long_name;
307  //typedef std::map<std::pair<str, int>, std::pair<int, int> >::const_iterator it_short_name_pair_to_pdg_pair;
308  //typedef std::map<std::pair<int, int>, std::pair<str, int> >::const_iterator it_pdg_pair_to_short_name_pair;
309  //typedef std::map<str, std::pair<str, int> >::const_iterator it_long_name_to_short_name_pair;
310 
311  cout << "PDB: long name as key" << endl;
312  for(it_long_name_to_pdg_pair it = long_name_to_pdg_pair.begin(); it != long_name_to_pdg_pair.end(); it++) {
313  cout << " long_name_to_pdg_pair [" << it->first << "] => " << it->second << endl;
314  if(has_short_name(it->first))
315  { cout << " long_name_to_short_name_pair[" << it->first << "] => " << long_name_to_short_name_pair.at(it->first) << endl; }
316  else
317  { cout << " long_name_to_short_name_pair[" << it->first << "] => " << "Has no short name!" << endl; }
318  }
319  cout << endl << "PDB: pdg_pair as key" << endl;
320  for(it_pdg_pair_to_long_name it = pdg_pair_to_long_name.begin(); it != pdg_pair_to_long_name.end(); it++) {
321  cout << " pdg_pair_to_long_name [" << it->first << "] => " << it->second << endl;
322  if(has_short_name(it->second))
323  { cout << " pdg_pair_to_short_name[" << it->first << "] => " << pdg_pair_to_short_name_pair.at(it->first) << endl; }
324  else
325  { cout << " pdg_pair_to_short_name[" << it->first << "] => " << "Has no short name!" << endl; }
326  }
327  cout << endl << "PDB: short name pair as key" << endl;
328  for(it_short_name_pair_to_long_name it = short_name_pair_to_long_name.begin(); it != short_name_pair_to_long_name.end(); it++) {
329  cout << " short_name_pair_to_long_name[" << it->first << "] => " << it->second << endl;
330  cout << " short_name_pair_to_pdg_pair [" << it->first << "] => " << short_name_pair_to_pdg_pair.at(it->first) << endl;
331  }
332  }
333 
334 
335  }
336 
337 }
338 
Define overloadings of the stream operator for various containers.
bool has_short_name(str) const
Check if a particle has a short name, using the long name.
Definition: partmap.cpp:219
std::pair< str, int > short_name_pair(str) const
Retrieve the short name and index, from the long name.
Definition: partmap.cpp:147
std::map< std::pair< int, int >, std::pair< str, int > > pdg_pair_to_short_name_pair
Map from PDG code and context integer to short name and index.
Definition: partmap.hpp:151
#define LOCAL_INFO
Definition: local_info.hpp:34
str long_name(str, int) const
Retrieve the long name, from the short name and index.
Definition: partmap.cpp:116
void add_SM_with_short_pair(str, std::pair< int, int >, std::pair< str, int >)
Add a new Standard Model particle to the database with a short name and an index. ...
Definition: partmap.cpp:80
void define_particles(partmap *)
Declare redirected constructor.
std::vector< std::pair< int, int > > SM
All SM particles in the database, by PDG code and context integer.
Definition: partmap.hpp:141
void add_SM(str, std::pair< int, int >)
Add a new Standard Model particle to the database.
Definition: partmap.cpp:56
std::string str
Definition: models.hpp:49
void add(str, std::pair< int, int >)
Add a new particle to the database.
Definition: partmap.cpp:45
std::pair< int, int > pdg_pair(str) const
Retrieve the PDG code and context integer, from the long name.
Definition: partmap.cpp:87
std::map< std::pair< int, int >, str > pdg_pair_to_long_name
Map from PDG code and context integer to long name.
Definition: partmap.hpp:147
bool has_antiparticle(str) const
Check if a particle has a matching anti-particle in the database, using the long name.
Definition: partmap.cpp:269
str get_antiparticle(str) const
Get the matching anti-particle long name for a particle in the database, using the long name...
Definition: partmap.cpp:231
const std::vector< std::pair< int, int > > & get_generic_particles() const
Get a vector PDG codes and context integers of generic particle classes in the database.
Definition: partmap.cpp:191
bool has_particle(str) const
Check if a particle is in the database, using the long name.
Definition: partmap.cpp:197
void add_with_short_pair(str, std::pair< int, int >, std::pair< str, int >)
Add a new particle to the database with a short name and an index.
Definition: partmap.cpp:70
partmap & ParticleDB()
Database accessor function.
Definition: partmap.cpp:32
std::map< std::pair< str, int >, str > short_name_pair_to_long_name
Map from short name and index to long name.
Definition: partmap.hpp:155
const std::vector< std::pair< int, int > > & get_SM_particles() const
Get a vector PDG codes and context integers of Standard Model particles in the database.
Definition: partmap.cpp:185
std::map< str, std::pair< int, int > > long_name_to_pdg_pair
Map from long name to PDG code and context integer.
Definition: partmap.hpp:145
Class definitions for GAMBIT particle database.
Exception objects required for standalone compilation.
std::map< std::pair< str, int >, std::pair< int, int > > short_name_pair_to_pdg_pair
Map from short name and index to PDG code and context integer.
Definition: partmap.hpp:149
void check_contents() const
For debugging: use to check the contents of the particle database.
Definition: partmap.cpp:301
void add_generic(str, std::pair< int, int >)
Add a new generic particle class to the database.
Definition: partmap.cpp:63
error & model_error()
Model errors.
TODO: see if we can use this one:
Definition: Analysis.hpp:33
partmap()
Constructor.
Definition: partmap.cpp:42
std::map< str, std::pair< str, int > > long_name_to_short_name_pair
Map from long name to short name and index.
Definition: partmap.hpp:153