gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-2191-ga4742ac
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 // *********************************************
21 
22 
23 #include <sstream>
24 
28 
29 namespace Gambit
30 {
31 
32  namespace Models
33  {
34 
37  {
38  static partmap local;
39  return local;
40  }
41 
43  extern void define_particles(partmap*);
44 
47 
49  void partmap::add(str long_name, std::pair<int, int> pdgpr, int spinx2, int chargex3, int color)
50  {
51  if (has_particle(long_name))
52  {
53  model_error().raise(LOCAL_INFO,"Particle "+long_name+" is multiply defined.");
54  }
57 
59  long_name_to_chargex3[long_name] = chargex3;
61  }
62 
64  void partmap::add_SM(str long_name, std::pair<int, int> pdgpr, int spinx2, int chargex3, int color)
65  {
66  add(long_name, pdgpr, spinx2, chargex3, color);
67  SM.push_back(pdgpr);
68  }
69 
71  void partmap::add_generic(str long_name, std::pair<int, int> pdgpr, int spinx2, int chargex3, int color)
72  {
73  add(long_name, pdgpr, spinx2, chargex3, color);
74  generic.push_back(pdgpr);
75  }
76 
78  void partmap::add_with_short_pair(str long_name, std::pair<int, int> pdgpr, std::pair<str, int> shortpr, int spinx2, int chargex3, int color)
79  {
80  add(long_name, pdgpr, spinx2, chargex3, color);
81  short_name_pair_to_pdg_pair[shortpr] = pdgpr;
83  pdg_pair_to_short_name_pair[pdgpr] = shortpr;
85  }
86 
88  void partmap::add_SM_with_short_pair(str long_name, std::pair<int, int> pdgpr, std::pair<str, int> shortpr, int spinx2, int chargex3, int color)
89  {
90  add_with_short_pair(long_name, pdgpr, shortpr, spinx2, chargex3, color);
91  SM.push_back(pdgpr);
92  }
93 
95  std::pair<int, int> partmap::pdg_pair(str long_name) const
96  {
97  if (not has_particle(long_name))
98  {
99  model_error().raise(LOCAL_INFO,"Particle long name "+long_name+" is not in the particle database.");
100  }
101  return long_name_to_pdg_pair.at(long_name);
102  }
103 
105  std::pair<int, int> partmap::pdg_pair(std::pair<str,int> shortpr) const
106  {
107  return pdg_pair(shortpr.first,shortpr.second);
108  }
109 
111  std::pair<int, int> partmap::pdg_pair(str short_name, int i) const
112  {
113  std::pair<str, int> shortpr(short_name, i);
114  if (not has_particle(shortpr))
115  {
116  std::ostringstream ss;
117  ss << "Short name " << short_name << " and index " << i << " are not in the particle database.";
118  model_error().raise(LOCAL_INFO,ss.str());
119  }
120  return short_name_pair_to_pdg_pair.at(shortpr);
121  }
122 
124  str partmap::long_name(str short_name, int i) const
125  {
126  std::pair<str, int> shortpr(short_name, i);
127  if (not has_particle(std::pair<str, int>(short_name, i)))
128  {
129  std::ostringstream ss;
130  ss << "Short name " << short_name << " and index " << i << " are not in the particle database.";
131  model_error().raise(LOCAL_INFO,ss.str());
132  }
133  return short_name_pair_to_long_name.at(shortpr);
134  }
135 
137  str partmap::long_name(std::pair<int, int> pdgpr) const
138  {
139  if (not has_particle(pdgpr))
140  {
141  std::ostringstream ss;
142  ss << "Particle with PDG code " << pdgpr.first << " and context integer " << pdgpr.second << " is not in the particle database.";
143  model_error().raise(LOCAL_INFO,ss.str());
144  }
145  return pdg_pair_to_long_name.at(pdgpr);
146  }
147 
149  str partmap::long_name(int pdg_code, int context) const
150  {
151  return long_name(std::make_pair(pdg_code,context));
152  }
153 
155  std::pair<str, int> partmap::short_name_pair(str long_name) const
156  {
157  if (not has_particle(long_name))
158  {
159  model_error().raise(LOCAL_INFO,"Particle "+long_name+" is not in the particle database.");
160  }
161  if (not has_short_name(long_name))
162  {
163  model_error().raise(LOCAL_INFO,"Particle "+long_name+" does not have a short name.");
164  }
165  return long_name_to_short_name_pair.at(long_name);
166  }
167 
169  std::pair<str, int> partmap::short_name_pair(std::pair<int, int> pdgpr) const
170  {
171  if (not has_particle(pdgpr))
172  {
173  std::ostringstream ss;
174  ss << "Particle with PDG code " << pdgpr.first << " and context integer " << pdgpr.second << " is not in the particle database.";
175  model_error().raise(LOCAL_INFO,ss.str());
176  }
177  if (not has_short_name(pdgpr))
178  {
179  std::ostringstream ss;
180  ss << "Particle with PDG code " << pdgpr.first << " and context integer " << pdgpr.second << " does not have a short name.";
181  model_error().raise(LOCAL_INFO,ss.str());
182  }
183  return pdg_pair_to_short_name_pair.at(pdgpr);
184  }
185 
187  std::pair<str, int> partmap::short_name_pair(int pdg_code, int context) const
188  {
189  return short_name_pair(std::make_pair(pdg_code,context));
190  }
191 
193  const std::vector<std::pair<int, int> >& partmap::get_SM_particles() const
194  {
195  return SM;
196  }
197 
199  const std::vector<std::pair<int, int> >& partmap::get_generic_particles() const
200  {
201  return generic;
202  }
203 
206  {
207  return (long_name_to_pdg_pair.find(long_name) != long_name_to_pdg_pair.end());
208  }
209 
211  bool partmap::has_particle(str short_name, int i) const
212  {
213  return has_particle(std::make_pair(short_name,i));
214  }
215  bool partmap::has_particle(std::pair<str, int> shortpr) const
216  {
217  return (short_name_pair_to_pdg_pair.find(shortpr) != short_name_pair_to_pdg_pair.end());
218  }
219 
221  bool partmap::has_particle(std::pair<int, int> pdgpr) const
222  {
223  return (pdg_pair_to_long_name.find(pdgpr) != pdg_pair_to_long_name.end());
224  }
225 
228  {
229  return (long_name_to_short_name_pair.find(long_name) != long_name_to_short_name_pair.end());
230  }
231 
233  bool partmap::has_short_name(std::pair<int, int> pdgpr) const
234  {
235  return (pdg_pair_to_short_name_pair.find(pdgpr) != pdg_pair_to_short_name_pair.end());
236  }
237 
240  {
241  return long_name(get_antiparticle(pdg_pair(lname)));
242  }
243 
246  std::pair<str, int> partmap::get_antiparticle(std::pair<str, int> shortpr) const
247  {
248  return short_name_pair(get_antiparticle(pdg_pair(shortpr)));
249  }
250  std::pair<str, int> partmap::get_antiparticle(str name, int index) const
251  {
252  return get_antiparticle(std::make_pair(name,index));
253  }
255 
258  std::pair<int, int> partmap::get_antiparticle(std::pair<int, int> pdgpr) const
259  {
260  if (has_antiparticle(pdgpr))
261  {
263  pdgpr.first = -pdgpr.first;
264  }
267  return pdgpr;
268  }
269  std::pair<int, int> partmap::get_antiparticle(int pdgcode, int context) const
270  {
271  return get_antiparticle(std::make_pair(pdgcode,context));
272  }
274 
278  {
279  return has_antiparticle(pdg_pair(long_name));
280  }
281 
284  bool partmap::has_antiparticle(std::pair<str, int> shortpr) const
285  {
286  return has_antiparticle(pdg_pair(shortpr));
287  }
288  bool partmap::has_antiparticle(str name, int index) const
289  {
290  return has_antiparticle(std::make_pair(name,index));
291  }
293 
296  bool partmap::has_antiparticle(std::pair<int, int> pdgpr) const
297  {
299  pdgpr.first = -pdgpr.first;
300  return has_particle(pdgpr);
301  }
302  bool partmap::has_antiparticle(int pdgcode, int context) const
303  {
304  return has_antiparticle(std::make_pair(pdgcode,context));
305  }
307 
309 
313  {
314  if (not has_particle(long_name))
315  {
316  model_error().raise(LOCAL_INFO,"Particle long name "+long_name+" is not in the particle database.");
317  }
318  return (long_name_to_spinx2.find(long_name) != long_name_to_spinx2.end());
319  }
321 
324  bool partmap::has_spinx2(std::pair<int, int> pdgpr) const
325  {
326  return has_spinx2(pdg_pair(long_name(pdgpr)));
327  }
328  bool partmap::has_spinx2(int pdg_code, int context) const
329  {
330  return has_spinx2(std::make_pair(pdg_code, context));
331  }
333 
336  bool partmap::has_spinx2(std::pair<str, int> shortpr) const
337  {
338  return has_spinx2(pdg_pair(shortpr));
339  }
340  bool partmap::has_spinx2(str name, int index) const
341  {
342  return has_spinx2(std::make_pair(name, index));
343  }
345 
349  {
350  if (not has_spinx2(long_name))
351  {
352  model_error().raise(LOCAL_INFO,"Particle long name "+long_name+" does not provide any spin information (spinformation).");
353  }
354  return long_name_to_spinx2.at(long_name);
355  }
357 
360  int partmap::get_spinx2(std::pair<int, int> pdgpr) const
361  {
362  return get_spinx2(long_name(pdgpr));
363  }
364  int partmap::get_spinx2(int pdg_code, int context) const
365  {
366  return get_spinx2(std::make_pair(pdg_code,context));
367  }
369 
372  int partmap::get_spinx2(std::pair<str, int> shortpr) const
373  {
374  return get_spinx2(pdg_pair(shortpr));
375  }
376  int partmap::get_spinx2(str name, int index) const
377  {
378  return get_spinx2(std::make_pair(name, index));
379  }
381 
385  {
386  if (not has_particle(long_name))
387  {
388  model_error().raise(LOCAL_INFO,"Particle long name "+long_name+" is not in the particle database.");
389  }
390  return (long_name_to_chargex3.find(long_name) != long_name_to_chargex3.end());
391  }
393 
396  bool partmap::has_chargex3(std::pair<int, int> pdgpr) const
397  {
398  return has_chargex3(pdg_pair(long_name(pdgpr)));
399  }
400  bool partmap::has_chargex3(int pdg_code, int context) const
401  {
402  return has_chargex3(std::make_pair(pdg_code, context));
403  }
405 
408  bool partmap::has_chargex3(std::pair<str, int> shortpr) const
409  {
410  return has_chargex3(pdg_pair(shortpr));
411  }
412  bool partmap::has_chargex3(str name, int index) const
413  {
414  return has_chargex3(std::make_pair(name, index));
415  }
417 
421  {
422  if (not has_chargex3(long_name))
423  {
424  model_error().raise(LOCAL_INFO,"Particle long name "+long_name+" does not provide any charge information (chargeformation).");
425  }
426  return long_name_to_chargex3.at(long_name);
427  }
429 
432  int partmap::get_chargex3(std::pair<int, int> pdgpr) const
433  {
434  return get_chargex3(long_name(pdgpr));
435  }
436  int partmap::get_chargex3(int pdg_code, int context) const
437  {
438  return get_chargex3(std::make_pair(pdg_code,context));
439  }
441 
444  int partmap::get_chargex3(std::pair<str, int> shortpr) const
445  {
446  return get_chargex3(pdg_pair(shortpr));
447  }
448  int partmap::get_chargex3(str name, int index) const
449  {
450  return get_chargex3(std::make_pair(name, index));
451  }
453 
457  {
458  if (not has_particle(long_name))
459  {
460  model_error().raise(LOCAL_INFO,"Particle long name "+long_name+" is not in the particle database.");
461  }
462  return (long_name_to_color.find(long_name) != long_name_to_color.end());
463  }
465 
468  bool partmap::has_color(std::pair<int, int> pdgpr) const
469  {
470  return has_color(pdg_pair(long_name(pdgpr)));
471  }
472  bool partmap::has_color(int pdg_code, int context) const
473  {
474  return has_color(std::make_pair(pdg_code, context));
475  }
477 
480  bool partmap::has_color(std::pair<str, int> shortpr) const
481  {
482  return has_color(pdg_pair(shortpr));
483  }
484  bool partmap::has_color(str name, int index) const
485  {
486  return has_color(std::make_pair(name, index));
487  }
489 
493  {
494  if (not has_color(long_name))
495  {
496  model_error().raise(LOCAL_INFO,"Particle long name "+long_name+" does not provide any color information (colorformation).");
497  }
498  return long_name_to_color.at(long_name);
499  }
501 
504  int partmap::get_color(std::pair<int, int> pdgpr) const
505  {
506  return get_color(long_name(pdgpr));
507  }
508  int partmap::get_color(int pdg_code, int context) const
509  {
510  return get_color(std::make_pair(pdg_code,context));
511  }
513 
516  int partmap::get_color(std::pair<str, int> shortpr) const
517  {
518  return get_color(pdg_pair(shortpr));
519  }
520  int partmap::get_color(str name, int index) const
521  {
522  return get_color(std::make_pair(name, index));
523  }
525 
528  {
529  // Check that long and short names retrieve same information (when short name exists)
530  typedef std::map<str, std::pair<int, int> >::const_iterator it_long_name_to_pdg_pair;
531  typedef std::map<std::pair<int, int>, str>::const_iterator it_pdg_pair_to_long_name;
532  typedef std::map<std::pair<str, int>, str>::const_iterator it_short_name_pair_to_long_name;
533  //typedef std::map<std::pair<str, int>, std::pair<int, int> >::const_iterator it_short_name_pair_to_pdg_pair;
534  //typedef std::map<std::pair<int, int>, std::pair<str, int> >::const_iterator it_pdg_pair_to_short_name_pair;
535  //typedef std::map<str, std::pair<str, int> >::const_iterator it_long_name_to_short_name_pair;
536 
537  cout << "PDB: long name as key" << endl;
538  for(it_long_name_to_pdg_pair it = long_name_to_pdg_pair.begin(); it != long_name_to_pdg_pair.end(); it++) {
539  cout << " long_name_to_pdg_pair [" << it->first << "] => " << it->second << endl;
540  if(has_short_name(it->first))
541  { cout << " long_name_to_short_name_pair[" << it->first << "] => " << long_name_to_short_name_pair.at(it->first) << endl; }
542  else
543  { cout << " long_name_to_short_name_pair[" << it->first << "] => " << "Has no short name!" << endl; }
544  }
545  cout << endl << "PDB: pdg_pair as key" << endl;
546  for(it_pdg_pair_to_long_name it = pdg_pair_to_long_name.begin(); it != pdg_pair_to_long_name.end(); it++) {
547  cout << " pdg_pair_to_long_name [" << it->first << "] => " << it->second << endl;
548  if(has_short_name(it->second))
549  { cout << " pdg_pair_to_short_name[" << it->first << "] => " << pdg_pair_to_short_name_pair.at(it->first) << endl; }
550  else
551  { cout << " pdg_pair_to_short_name[" << it->first << "] => " << "Has no short name!" << endl; }
552  }
553  cout << endl << "PDB: short name pair as key" << endl;
554  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++) {
555  cout << " short_name_pair_to_long_name[" << it->first << "] => " << it->second << endl;
556  cout << " short_name_pair_to_pdg_pair [" << it->first << "] => " << short_name_pair_to_pdg_pair.at(it->first) << endl;
557  }
558  }
559 
560 
561  }
562 
563 }
564 
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:227
std::pair< str, int > short_name_pair(str) const
Retrieve the short name and index, from the long name.
Definition: partmap.cpp:155
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:239
bool has_chargex3(str) const
Check if a particle has a charge (x3) entry, using the long name.
Definition: partmap.cpp:384
void add(str, std::pair< int, int >, int, int, int)
Add a new particle to the database.
Definition: partmap.cpp:49
bool has_color(str) const
Check if a particle has a color entry, using the long name.
Definition: partmap.cpp:456
int get_spinx2(std::pair< int, int >) const
Get spin (x2) of a given particle, using the PDG code and context integer.
Definition: partmap.cpp:360
#define LOCAL_INFO
Definition: local_info.hpp:34
void add_with_short_pair(str, std::pair< int, int >, std::pair< str, int >, int, int, int)
Add a new particle to the database with a short name and an index.
Definition: partmap.cpp:78
str long_name(str, int) const
Retrieve the long name, from the short name and index.
Definition: partmap.cpp:124
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:229
void add_SM_with_short_pair(str, std::pair< int, int >, std::pair< str, int >, int, int, int)
Add a new Standard Model particle to the database with a short name and an index. ...
Definition: partmap.cpp:88
int get_chargex3(std::pair< int, int >) const
Get charge (x3) of a given particle, using the PDG code and context integer.
Definition: partmap.cpp:432
std::string str
Definition: models.hpp:49
std::pair< int, int > pdg_pair(str) const
Retrieve the PDG code and context integer, from the long name.
Definition: partmap.cpp:95
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:235
bool has_antiparticle(str) const
Check if a particle has a matching anti-particle in the database, using the long name.
Definition: partmap.cpp:277
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:239
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:199
bool has_particle(str) const
Check if a particle is in the database, using the long name.
Definition: partmap.cpp:205
bool has_spinx2(str) const
Check if a particle has a spin (x2) entry, using the long name.
Definition: partmap.cpp:312
partmap & ParticleDB()
Database accessor function.
Definition: partmap.cpp:36
void add_SM(str, std::pair< int, int >, int, int, int)
Add a new Standard Model particle to the database.
Definition: partmap.cpp:64
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:243
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:193
void add_generic(str, std::pair< int, int >, int, int, int)
Add a new generic particle class to the database.
Definition: partmap.cpp:71
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:233
Class definitions for GAMBIT particle database.
Exception objects required for standalone compilation.
std::map< str, int > long_name_to_chargex3
Map from long name to three times the charge of particle.
Definition: partmap.hpp:247
std::map< str, int > long_name_to_spinx2
Map from long name to twice the spin of particle.
Definition: partmap.hpp:245
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:237
int get_color(std::pair< int, int >) const
Get color of a given particle, using the PDG code and context integer.
Definition: partmap.cpp:504
void check_contents() const
For debugging: use to check the contents of the particle database.
Definition: partmap.cpp:527
error & model_error()
Model errors.
std::map< str, int > long_name_to_color
Map from long name to color representation of particle.
Definition: partmap.hpp:249
TODO: see if we can use this one:
Definition: Analysis.hpp:33
partmap()
Constructor.
Definition: partmap.cpp:46
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:241