MINT2
QuarkContent.cpp
Go to the documentation of this file.
1 #include "Mint/QuarkContent.h"
2 #include <vector>
3 #include <iostream>
4 
5 using namespace std;
6 
7 char QuarkContent::_names[6] = {'d', 'u', 's', 'c', 'b', 't'};
8 char QuarkContent::_NAMES[6] = {'D', 'U', 'S', 'C', 'B', 'T'};
9 map<char, int> QuarkContent::_positions;
10 
12  : MINT::PolymorphVector<int>(6, 0)
13 {
14  initPositions();
15 }
16 
18  : MINT::PolymorphVector<int>(other)
19 {}
20 
22  if(_positions.empty()){
23  for(int i=0; i < 6; i++) _positions[_names[i]]=i;
24  for(int i=0; i < 6; i++) _positions[_NAMES[i]]=i;
25  }
26  return true;
27 }
28 
30  for(unsigned int i=0; i < this->size(); i++){
31  (*this)[i] *= -1;
32  }
33 }
34 
35 bool QuarkContent::initFromString(const string& str){
36  for(unsigned int i=0; i < this->size(); i++){
37  (*this)[i]=0;
38  }
39  unsigned int pos =str.find("non-qQ");
40  if(pos < str.size())return true;
41 
42  std::string localQ = str;
43  pos = localQ.find("sqrt");
44  if(pos < localQ.size()){
45  localQ.replace(pos, 4, "");
46  }
47  //cout << "str : " << str << " localQ " << localQ << endl;
48 
49  for(unsigned int i=0; i < localQ.size(); i++){
50  if('d' == localQ[i]) (*this)[0]++;
51  if('D' == localQ[i]) (*this)[0]--;
52  if('u' == localQ[i]) (*this)[1]++;
53  if('U' == localQ[i]) (*this)[1]--;
54  if('s' == localQ[i]) (*this)[2]++;
55  if('S' == localQ[i]) (*this)[2]--;
56  if('c' == localQ[i]) (*this)[3]++;
57  if('C' == localQ[i]) (*this)[3]--;
58  if('b' == localQ[i]) (*this)[4]++;
59  if('B' == localQ[i]) (*this)[4]--;
60  if('t' == localQ[i]) (*this)[5]++;
61  if('T' == localQ[i]) (*this)[5]--;
62  }
63  return true;
64 }
65 
66 int QuarkContent::content(long int quarkNumber) const{
67  return content( (int) quarkNumber);
68 }
69 int QuarkContent::content(int quarkNumber) const{
70  if(quarkNumber < 0) return 0;
71  return content( (unsigned int) quarkNumber);
72 }
73 int QuarkContent::content(unsigned int quarkNumber) const{
74  if(quarkNumber >= this->size()) return 0;
75  return (*this)[quarkNumber];
76 }
77 
78 int QuarkContent::content(const std::string& quarkName) const{
79  if(quarkName.empty()) return 0;
80  return content(quarkName[0]);
81 }
82 
83 int QuarkContent::content(char quarkName) const{
84  return content(positionFromName(quarkName));
85 }
87  if(i < 0 || i >=6) return 'X';
88  else return _names[i];
89 }
91  map<char, int>::const_iterator it = _positions.find(c);
92  if(_positions.end() == it) return -9999;
93  else return it->second;
94 }
95 
96 void QuarkContent::print(std::ostream& os) const{
97  for(unsigned int i=0; i < this->size(); i++){
98  os << "(" << nameFromPosition(i) << ":" << (*this)[i] << ")";
99  if(i + 1< this->size()) os << " ";
100  }
101 }
102 
104  unsigned int max = this->size();
105  if(rhs.size() < max) max = rhs.size();
106  for(unsigned int i=0; i < max; i++){
107  (*this)[i] += rhs[i];
108  }
109  return *this;
110 }
112  unsigned int max = this->size();
113  if(rhs.size() < max) max = rhs.size();
114  for(unsigned int i=0; i < max; i++){
115  (*this)[i] -= rhs[i];
116  }
117  return *this;
118 }
119 
121  QuarkContent returnVal(*this);
122  returnVal += rhs;
123  return returnVal;
124 }
126  QuarkContent returnVal(*this);
127  returnVal -= rhs;
128  return returnVal;
129 }
130 std::ostream& operator<<(std::ostream& st, const QuarkContent& qc){
131  qc.print(st);
132  return st;
133 }
QuarkContent & operator+=(const QuarkContent &rhs)
QuarkContent operator-(const QuarkContent &rhs) const
std::ostream & operator<<(std::ostream &st, const QuarkContent &qc)
static char _NAMES[6]
Definition: QuarkContent.h:11
char nameFromPosition(int i) const
static char _names[6]
Definition: QuarkContent.h:10
static bool initPositions()
static std::map< char, int > _positions
Definition: QuarkContent.h:12
QuarkContent & operator-=(const QuarkContent &rhs)
int content(int quarkNumber) const
QuarkContent operator+(const QuarkContent &rhs) const
bool initFromString(const std::string &str)
unsigned int size() const
void print(std::ostream &os=std::cout) const
int positionFromName(char c) const