CHROMA
inline_barspec_db_w.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /*! \file
3  * \brief Inline hadron spectrum calculations
4  *
5  * Hadron spectrum calculations
6  */
7 
8 #ifndef __inline_barspec_h__
9 #define __inline_barspec_h__
10 
11 #include <map>
12 #include <vector>
13 
14 #include "chromabase.h"
15 //#include "../utils/gammaRotations.h"
16 #include "util/ferm/diractodr.h"
17 
19 
20 namespace Chroma
21 {
22  /*! \ingroup inlinehadron */
23  namespace InlineBarSpecEnv
24  {
25  bool registerAll();
26 
27 
28  //! Parameter structure
29  /*! \ingroup inlinehadron */
30  struct Params
31  {
32  Params();
33  Params(XMLReader& xml_in, const std::string& path);
34  void writeXML(XMLWriter& xml_out, const std::string& path);
35 
36  unsigned long frequency;
37 
38  struct SpinTerms_t{
39  multi1d<int> spin ;
40  double weight ;
41  };
42 
43  struct SpinWF_t{
44  double norm ;
45  multi1d<SpinTerms_t> terms ;
46  } ;
47 
48 
49  struct Operators_t{
51 
53  };
54 
55  struct State_t{
57  multi1d<std::string> flavor ;
58  multi1d<Operators_t> ops ; // holds the operators
59  int spin ;
61  };
62  struct Param_t
63  {
64  //bool MesonP; // Meson spectroscopy
65  //bool CurrentP; // Meson currents
66  //bool BaryonP; // Baryons spectroscopy
67 
68  bool time_rev; // Use time reversal in baryon spectroscopy
69 
70  int mom2_max; // (mom)^2 <= mom2_max. mom2_max=7 in szin.
71  bool avg_equiv_mom; // average over equivalent momenta
72 
73  multi1d<State_t> states ; // holds the states
74 
75  std::string ensemble ; // a std::string describing this ensemble
76  } param;
77 
79  {
80  std::string gauge_id; /*!< Input gauge field */
81 
82  struct Props_t
83  {
88  };
89 
90  multi1d<Props_t> props;
91 
93 
94  std::string xml_file; // Alternate XML file pattern
95 
96  };
97 
98 
99  namespace BarSpec
100  {
101  std::vector<int> permutation(int k, const std::vector<int>& s) ;
102  int permutation_sign(int k, int n) ;
103 
104  class SpinWF_t{
105  private:
106 
107  int factorial(int n){
108  int f = 1 ;
109  for(int i(1);i<=n;i++)
110  f *= i ;
111  return f ;
112  }
113 
114 
115  public:
116  double norm ;
117  std::vector<Params::SpinTerms_t> terms ;
118 
120  for(int t(0);t<ss.terms.size();t++)
121  terms.push_back(ss.terms[t]) ;
122  //make spin components zero based
123  for(int t(0);t<terms.size();t++){
124  for(int s(0);s<terms[t].spin.size();s++)
125  terms[t].spin[s]--;
126  }
127  }
128 
129  void permutations(const multi1d<std::string>& flavor){
130 
131  //std::map<std::string,int> f_count;
132  std::map<std::string,std::vector<int> > f_pos; // positions of active flavors
133  //find the common flavors
134  // f_pos : list of positions on which each flavor appears
135  // labels : holds the list of unique flavors in the operator
136  std::vector<std::string> labels;
137  for(int f(0);f<flavor.size();f++){
138  if(f_pos.find(flavor[f]) == f_pos.end()){
139  labels.push_back(flavor[f]);
140  }
141  f_pos[flavor[f]].push_back(f);
142  }
143 
144  std::vector<Params::SpinTerms_t> perm_terms ;
145  for(int f(0);f<labels.size();f++){
146  int Nterms = terms.size();
147  //std::vector<SpinTerms_t> tmp_terms = terms ;
148  // perform up qark permutations of each term
149  int Nperms = factorial(f_pos[labels[f]].size()) ;
150  QDPIO::cout<<" SpinWF_t::"<<__func__
151  <<": Flavor "<<labels[f]<<" needs "<<Nperms
152  <<": permutations"<<std::endl ;
153  if(Nperms>1){
154  for(int t(0);t<Nterms;t++){
155  Params::SpinTerms_t foo = terms[t] ;
156  std::vector<int> spin ;
157  for(int i(0);i<f_pos[labels[f]].size();i++)
158  spin.push_back(terms[t].spin[f_pos[labels[f]][i]]);
159  //QDPIO::cout<<"Original : " ;
160  //for(int m(0);m<spin.size();m++)
161  //QDPIO::cout<<spin[m]<<" " ;
162  //QDPIO::cout<<std::endl ;
163  for(int k(0);k<Nperms;k++){
164  std::vector<int> perm = permutation(k,spin);
165  //for(int m(0);m<perm.size();m++)
166  // QDPIO::cout<<perm[m]<<" " ;
167  //QDPIO::cout<<std::endl ;
168 
169  for(int i(0);i<f_pos[labels[f]].size();i++)
170  foo.spin[f_pos[labels[f]][i]] = perm[i] ;
171  perm_terms.push_back(foo) ;
172  }//loop over permutations
173  }// loop over terms
174  }// If Nperms>1
175  }// loop over flavors
176  terms = perm_terms ;
177  // Check what we did ...
178  for(int t(0);t<terms.size();t++){
179  QDPIO::cout<<" SpinWF_t::"<<__func__
180  <<": weight: "<<terms[t].weight<<" | " ;
181  QDPIO::cout<<"spin : " ;
182  for(int m(0);m<terms[t].spin.size();m++)
183  QDPIO::cout<<flavor[m]<<"("<<terms[t].spin[m]<<") " ;
184  QDPIO::cout<<">"<<std::endl ;
185 
186  }
187  //QDPIO::cout<<"Done with permutations"<<std::endl ;
188  }
189 
190  } ;
191 
192  //My own propagator class
193  template<int N>
195  {
196  public:
197  multi2d<multi2d<LatticeComplex> > p ;
198 
200  p.resize(N,N);
201  for(int s(0);s<N;s++)
202  for(int ss(0);ss<N;ss++)
203  p(s,ss).resize(Nc,Nc) ;
204  }
205 
206  void ConvertProp(const LatticePropagator& prop, int spin_offset){
207  QDPIO::cout<<__func__<<": Converting to Dirac Basis"<<std::endl ;
208  SpinMatrix U = DiracToDRMat();
209  LatticePropagator foo = adj(U)*prop*U ;
210 
211  p.resize(N,N);
212  int Noff = N+spin_offset;
213  if(Noff>Ns)
214  Noff=Ns ;
215  for(int s(spin_offset);s<Noff;s++)
216  for(int ss(0);ss<Noff;ss++){
217  p(s,ss).resize(Nc,Nc) ;
218  LatticeColorMatrix Cmat = peekSpin(foo,s,ss) ;
219  for(int c(0);c<Nc;c++)
220  for(int cc(0);cc<Nc;cc++)
221  p(s,ss)(c,cc) = peekColor(Cmat,c,cc);
222  }
223 
224  }
225 
226  void ConvertProp(const LatticePropagator& prop){
227  ConvertProp(prop,0);
228  }
229 
230  void ConvertPropUpper(const LatticePropagator& prop){
231  ConvertProp(prop,0);
232  }
233 
234  void ConvertPropLowerr(const LatticePropagator& prop){
235  ConvertProp(prop,2);
236  }
237 
238  };
239 
241  typedef BasePropagator<Ns/2> NRPropagator ;
242 
243 
244  void contract(LatticeComplex& latC,
245  const RPropagator& q1,
246  const RPropagator& q2,
247  const RPropagator& q3,
248  const SpinWF_t& snk,
249  const SpinWF_t& src);
250 
251 
252 
253 
254  }// namespace BarSpec
255 
256 
257  //! Inline measurement of hadron spectrum
258  /*! \ingroup inlinehadron */
260  {
261  public:
263  InlineMeas(const Params& p) : params(p) {}
264 
265  unsigned long getFrequency(void) const {return params.frequency;}
266 
267  //! Do the measurement
268  void operator()(const unsigned long update_no,
269  XMLWriter& xml_out);
270 
271  protected:
272  //! Do the measurement
273  void func(const unsigned long update_no,
274  XMLWriter& xml_out);
275 
276  private:
278  };
279 
280  } // namespace InlineBarSpecEnv
281 
282 } // namespace Chroma
283 
284 #endif
Abstract inline measurements.
Primary include file for CHROMA library code.
void ConvertPropUpper(const LatticePropagator &prop)
void ConvertProp(const LatticePropagator &prop, int spin_offset)
void ConvertPropLowerr(const LatticePropagator &prop)
void ConvertProp(const LatticePropagator &prop)
void permutations(const multi1d< std::string > &flavor)
std::vector< Params::SpinTerms_t > terms
Inline measurement of hadron spectrum.
unsigned long getFrequency(void) const
Tell me how often I should measure this beastie.
void operator()(const unsigned long update_no, XMLWriter &xml_out)
Do the measurement.
void func(const unsigned long update_no, XMLWriter &xml_out)
Do the measurement.
Basis rotation matrix from Dirac to Degrand-Rossi (and reverse)
SpinMatrixD DiracToDRMat()
The Dirac to Degrand-Rossi spin transformation matrix (and reverse)
Definition: diractodr.cc:22
std::map< std::string, SinkPropContainer_t > prop
unsigned n
Definition: ldumul_w.cc:36
static int m[4]
Definition: make_seeds.cc:16
int t
Definition: meslate.cc:37
std::vector< int > permutation(int k, const std::vector< int > &s)
void contract(LatticeComplex &latC, const RPropagator &q1, const RPropagator &q2, const RPropagator &q3, const SpinWF_t &snk, const SpinWF_t &src)
bool registerAll()
Register all the factories.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
Double c
Definition: invbicg.cc:108
int i
Definition: pbg5p_w.cc:55
int k
Definition: invbicg.cc:119
multi1d< LatticeFermion > s(Ncb)
::std::string string
Definition: gtest.h:1979
void writeXML(XMLWriter &xml_out, const std::string &path)
struct Chroma::InlineBarSpecEnv::Params::Param_t param
struct Chroma::InlineBarSpecEnv::Params::NamedObject_t named_obj
multi1d< LatticeColorMatrix > U