ROOTPWA
TLSAmpl.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <string>
3 #include "TLSAmpl.h"
4 using namespace std;
5 
6 extern ClebschGordanBox box;
7 
9 
10 TLSAmpl::TLSAmpl(Int_t RankS1, Int_t RankS2,
11  Int_t RankL, Int_t RankJ,
12  Int_t delta_, Int_t S_L,
13  Int_t cPsiInt, Int_t cPsiChi,
14  Int_t cChiPhi, Int_t cPsiPhi,
15  Int_t cPhiOme, Int_t cChiOme,
16  Int_t cPhiEps, Int_t cChiEps,
17  Int_t cNum) {
18 
19  J=RankJ;
20  L=RankL;
21  S=S_L;
22  delta=delta_;
23  ContractionNumber=cNum;
24 
25  cPsI=cPsiInt; cPsC=cPsiChi;
26  cCP=cChiPhi; cPsP=cPsiPhi;
27  cPO=cPhiOme; cCO=cChiOme;
28  cPE=cPhiEps; cCE=cChiEps;
29 
30  Int_t totalR=RankS1+RankS2+RankL+RankJ;
31  Int_t contractions=2*(cPsiInt+cPsiChi+cChiPhi+cPsiPhi);
32  Int_t even_contraction=1;
33  if ( totalR % 2 ) even_contraction=0;
34 
35  if ( ( even_contraction==1 && contractions != totalR ) ||
36  ( even_contraction==0 && contractions != totalR-3 ) ) {
37  cerr << "Invalid contraction occurred" << endl;
38  return;
39  }
40 
41  if (debugLSAmpl) {
42  cout << "LSAmpl: "<<RankS1<<" "<<RankS2<<" L="
43  <<RankL<<" "<<RankJ<<" d="<<delta<<" S="<<S_L<<" c: "
44  <<cPsiInt<<" "<<cPsiChi<<" "<<cChiPhi<<" "<<cPsiPhi << " s: "
45  <<cPhiOme<<" "<<cChiOme<<" "<<cPhiEps<<" "<<cChiEps;
46  if (even_contraction) cout << endl;
47  else cout<< " (iw)" << endl;
48  }
49 
50  TSpinWaveFunction WFS1(RankS1, 's');
51  TSpinWaveFunction WFS2(RankS2, 's');
52 
53  TTensorSum *TSS = WFS1.GetSpinCoupledTensorSum(&WFS2, delta, S_L);
54  if (debugLSAmpl==2) TSS->Print();
55 
56  if (cPsiInt) {
57  Int_t ires = TSS->SpinInnerContraction(cPsiInt);
58  if (ires==0) {
59  if (debugLSAmpl) cout << "Inner contraction is zero." << endl;
60  Nterms=0;
61  return;
62  }
63  if (debugLSAmpl==2) TSS->Print();
64  }
65 
66  TSpinWaveFunction WFL (RankL, 'l');
67  TTensorSum *TSL = WFL.GetTensorSum('c', 0);
68  if (debugLSAmpl==2) TSL->Print();
69 
70  TTensorSum *TSLS = TSS->LSContraction(TSL, cPsiChi, cChiOme, cChiEps, 'c');
71  if (TSLS->GetNterms()==0) {
72  if (debugLSAmpl) cout << "LS contraction is zero." << endl;
73  Nterms=0;
74  return;
75  }
76  if (debugLSAmpl==2) TSLS->Print();
77 
78  TSpinWaveFunction WFJ (RankJ, 'c');
79  TTensorSum *TSJ = WFJ.GetTensorSum('p', delta);
80  if (debugLSAmpl==2) TSJ->Print();
81 
82  TTensorSum *TSLSJ = TSLS->LSContraction(TSJ, cPsiPhi, cPhiOme, cPhiEps, 'p');
83 
84  if (TSLSJ->GetNterms()==0) {
85  if (debugLSAmpl) cout << "JS contraction is zero." << endl;
86  Nterms=0;
87  return;
88  }
89 
90  if (debugLSAmpl==2) TSLSJ->Print();
91 
92  TSScalar = TSLSJ->LJContraction(cChiPhi, even_contraction);
93 
94  if (debugLSAmpl==2) TSLSJ->Print();
95 
96  Nterms=TSScalar->GetNterms();
97 
98  if (Nterms==0) {
99  if (debugLSAmpl) cout << "LJ contraction is zero." << endl;
100  return;
101  }
102 
103  if (debugLSAmpl) {
104  //TSScalar->Print();
105  TSScalar->Print('s');
106  }
107 }
108 
110 
111 TLSContrib::TLSContrib(TLSContrib *b, Bool_t particle_exchange) {
112  J=b->J; L=b->L; S=b->S; cNum=b->cNum; delta=b->delta;
113  Nterms=b->Nterms;
114  NormFactor=b->NormFactor;
115  PureRelativistic=b->PureRelativistic;
116  termFracNum = new TFracNum[Nterms];
117  termg1pot = new Int_t[Nterms];
118  termg2pot = new Int_t[Nterms];
119  for (Int_t i=0; i<Nterms; i++) {
120  // force new power fields by multiplication " *1 "
121  termFracNum[i] = TFracNum_One * b->termFracNum[i];
122  if (particle_exchange) {
123  termg1pot[i] = b->termg2pot[i];
124  termg2pot[i] = b->termg1pot[i];
125  }
126  else {
127  termg1pot[i] = b->termg1pot[i];
128  termg2pot[i] = b->termg2pot[i];
129  }
130  }
131 };
132 
134  J=A->GetJ();
135  L=A->GetL();
136  S=A->GetS();
137  cNum=A->GetContraction();
138  delta=delta_;
139  SpinCG=scfac;
140 
141  Bool_t sign_reversal=false;
142  if (delta<0 && (L+S-J)%2 ) sign_reversal=true;
143 
144  Nterms=A->GetNterms();
145  termFracNum = new TFracNum[Nterms];
146  termg1pot = new Int_t[Nterms];
147  termg2pot = new Int_t[Nterms];
148 
149  NormFactor=TFracNum_Zero;
150  if (debugLSContrib) cout <<"("<<J<<")"<<L<<S<<"["<<delta<<"]"<<endl;
151  for (Int_t i=0; i<Nterms; i++) {
152  TTensorTerm *tt = A->GetTerm(i); //TSScalar->GetTerm(i);
153 
154  if (debugLSContrib)
155  cout << scfac.FracStringSqrt()<< ","
156  << tt->GetPreFac().FracStringSqrt()
157  << " L"<<L<<"S"<<S<<"J"<<J<<"Ampldelta"<<A->Getdelta()
158  <<" delta"<<delta<<", sigrev "<<sign_reversal;
159 
160  termFracNum[i] = scfac * tt->GetPreFac();
161  if (sign_reversal==true) termFracNum[i].FlipSign();
162  //TFracNum tSqr = NormFactor * termFracNum[i];
163  //if ( ! tSqrt.Sqrt() )
164  // cout << " Building LSContrib leads not to squared-fractional numbers,"
165  // << " results will be wrong!" << endl;
166 
167  TFracNum *sum = NormFactor.SumSignedRoots(&(termFracNum[i]));
168  if (sum) { NormFactor = *sum; }
169  else {
170  cerr << "TLSContrib: Normalisation not root-fractional,"
171  << " *** results will be wrong *** " << endl;
172  }
173 
174  // NormFactor=NormFactor+termFracNum[i]+TFracNum_Two*tSqrt;
175 
176  termg1pot[i] = tt->GetGamS();
177  termg2pot[i] = tt->GetGamSig();
178  if (debugLSContrib) cout << " -> Normfactor: "
179  << NormFactor.FracStringSqrt() << endl;
180 
181  }
182  if (NormFactor==TFracNum_Zero) {
183  PureRelativistic=true;
184  NormFactor=TFracNum_One;
185  }
186  else {
187  PureRelativistic=false;
188  TFracNum NormInv=NormFactor;
189  NormInv.Invert();
190  // TFracNum InvAbs=TFracNum_One * NormInv; //Bug: real copy forced by "1 *"
191  // InvAbs.Abs();
192  for (Int_t i=0; i<Nterms; i++) {
193  termFracNum[i]=termFracNum[i]*NormInv; // InvAbs;
194  }
195  }
196 }
197 
198 Int_t
199 TLSContrib::Add(TLSContrib *b, Bool_t particle_exchange) {
200  if (J!=b->J || L!=b->L || S!=b->S) {
201  cerr <<"TLSContrib::Add : Something is wrong, trying to add different"
202  <<" (J;L,S): ("<<J<<";"<<L<<","<<S<<") != ("
203  <<b->J<<";"<<b->L<<","<<b->S<<")"<<endl;
204  return -1;
205  }
206 
207  //
208  // Include normalisation factor and the factor (1/2)**2 in the squared
209  // representation of prefactors
210  //
211 
212  for (Int_t i=0; i<Nterms; i++) {
213  termFracNum[i]= TFracNum_Quarter * NormFactor *termFracNum[i];
214  }
215 
216  for (Int_t ib=0; ib<b->Nterms; ib++) {
217  Bool_t term_summed=false;
218  for (Int_t i=0; i<Nterms; i++) {
219  if ( !term_summed && cNum == b->cNum &&
220  ( (particle_exchange==true &&
221  termg1pot[i]==b->termg2pot[ib] &&
222  termg2pot[i]==b->termg1pot[ib] ) ||
223  (particle_exchange==false &&
224  termg1pot[i]==b->termg1pot[ib] &&
225  termg2pot[i]==b->termg2pot[ib] ) ) ) {
226  term_summed=true;
227  TFracNum bterm=TFracNum_Quarter * b->NormFactor * b->termFracNum[ib];
228 
229  if (J%2) bterm.FlipSign();
230 
231  TFracNum *sum = bterm.SumSignedRoots(&(termFracNum[i]));
232  if (sum) { termFracNum[i] = *sum; }
233  else {
234  cerr << "TLSContrib: Normalisation not root-fractional,"
235  << " *** results will be wrong *** " << endl;
236  }
237  }
238  }
239  if (!term_summed) {
240  Nterms++;
241  TFracNum *new_termFracNum = new TFracNum[Nterms];
242  Int_t *new_termg1pot = new Int_t[Nterms];
243  Int_t *new_termg2pot = new Int_t[Nterms];
244  for (Int_t i=0; i<Nterms-1; i++) {
245  new_termFracNum[i]=termFracNum[i];
246  new_termg1pot[i]=termg1pot[i];
247  new_termg2pot[i]=termg2pot[i];
248  }
249  new_termFracNum[Nterms-1] =
251  //if ( ! new_termFracNum[Nterms-1].Sqrt() )
252  // cout << "Square root not possible, this will lead to wrong results:"
253  // << new_termFracNum[Nterms-1].FracString() << endl;
254  //new_termFracNum[Nterms-1]=
255  // TFracNum_Half * new_termFracNum[Nterms-1] * b->NormFactor;
256  if (J%2) new_termFracNum[Nterms-1].FlipSign();
257  if ( particle_exchange ) {
258  new_termg1pot[Nterms-1] = b->termg2pot[ib];
259  new_termg2pot[Nterms-1] = b->termg1pot[ib];
260  }
261  else {
262  new_termg1pot[Nterms-1] = b->termg1pot[ib];
263  new_termg2pot[Nterms-1] = b->termg2pot[ib];
264  }
265  termFracNum=new_termFracNum;
266  termg1pot=new_termg1pot;
267  termg2pot=new_termg2pot;
268  }
269  }
270 
271  //
272  // Eliminate zero entries
273  //
274  Int_t non_zeros=0;
275  for (Int_t i=0; i<Nterms; i++)
276  if (! (termFracNum[i]==TFracNum_Zero) ) non_zeros++;
277 
278  if (non_zeros==0) {
279  Nterms=0;
280  return 0;
281  }
282  else {
283  TFracNum *new_termFracNum = new TFracNum[non_zeros];
284  Int_t *new_termg1pot = new Int_t[non_zeros];
285  Int_t *new_termg2pot = new Int_t[non_zeros];
286 
287  Int_t j=0;
288  for (Int_t i=0; i<Nterms; i++)
289  if (! (termFracNum[i]==TFracNum_Zero) ) {
290  new_termFracNum[j]=termFracNum[i];
291  new_termg1pot[j]=termg1pot[i];
292  new_termg2pot[j]=termg2pot[i];
293  j++;
294  }
295  Nterms=non_zeros;
296  termFracNum=new_termFracNum;
297  termg1pot=new_termg1pot;
298  termg2pot=new_termg2pot;
299  }
300 
301  //
302  // Recalculate Normalization Factor
303  //
304  NormFactor=TFracNum_Zero;
305  for (Int_t i=0; i<Nterms; i++) {
306  TFracNum *sum = NormFactor.SumSignedRoots(&(termFracNum[i]));
307  if (sum) { NormFactor = *sum; }
308  else {
309  cerr << "TLSContrib: Normalisation not root-fractional,"
310  << " *** results will be wrong *** " << endl;
311  }
312  }
313 
314  //
315  // Apply normalization
316  //
317  if (NormFactor==TFracNum_Zero) {
318  PureRelativistic=true;
319  NormFactor=TFracNum_One;
320  }
321  else {
322  PureRelativistic=false;
323  TFracNum NormInv=NormFactor;
324  NormInv.Invert();
325  for (Int_t i=0; i<Nterms; i++) {
326  termFracNum[i]=termFracNum[i]*NormInv;
327  }
328  }
329  return Nterms;
330 }
331 
332 Int_t
334  if (cNum==1) cout <<"g"<<"["<<cNum<<"] (";
335  if (cNum==2) cout <<"f"<<"["<<cNum<<"] (";
336  if (cNum>=3) cout <<"h"<<"["<<cNum<<"] (";
337  cout <<J<<")"<<L<<S<<"( ";
338  if (!PureRelativistic) {
339  cout << NormFactor.FracStringSqrt() << " ) ( ";
340  }
341  for (Int_t iT=0; iT<Nterms; iT++){
342  cout << termFracNum[iT].FracStringSqrt()<<" ";
343  if (termg1pot[iT]) {
344  if (termg1pot[iT]==1) cout << " gs";
345  else cout << " gs^" << termg1pot[iT];
346  }
347  if (termg2pot[iT]) {
348  if (termg2pot[iT]==1) cout << " gsig";
349  else cout << " gsig^" << termg2pot[iT];
350  }
351  }
352  cout <<" )"<< endl;
353  return 0;
354 }
355 
356 Int_t
358  cout << NormFactor.FracStringSqrt();
359  if (cNum==1) cout <<"*g";
360  if (cNum==2) cout <<"*f";
361  if (cNum==3) cout <<"*h";
362  return 0;
363 }
364 
365 Int_t
367  cout << (NormFactor * m).FracStringSqrt();
368  if (cNum==1) cout <<"*g";
369  if (cNum==2) cout <<"*f";
370  if (cNum==3) cout <<"*h";
371  return 0;
372 }
373 
374 
376  J=C->GetJ();
377  L=C->GetL();
378  S=C->GetS();
379  Nterms=1;
380  RelLS = new TLSContrib*[1];
381  RelLS[0]=C;
382  TFracNum *JdL0Sd = box.GetCG(J, L, S);
383  //cout << "delta=" << C->GetDelta()
384  // << ",S=" << S
385  // << ", 2L+1/2J+1=" << TFracNum(2*L+1,2*J+1).FracStringSqrt()
386  // << ",CG(JdL0Sd)="
387  // << JdL0Sd[CGIndex(L, 0, S, C->GetDelta())].FracStringSqrt()
388  // << ", SpinCG=" << C->GetSpinCG()->FracStringSqrt()
389  // << endl;
390  GnrPrefac = TFracNum(2*L+1,2*J+1) *
391  JdL0Sd[CGIndex(L, 0, S, C->GetDelta())] *
392  *C->GetSpinCG();
393 }
394 
396  if ( ! CheckJLS(C) ) {
397  cout << "TLSNonRel::Add not appropriate, skipping (check code)!!!" << endl;
398  return -1;
399  }
400  Nterms++;
401  TLSContrib **newRelLS = new TLSContrib*[Nterms];
402  for (Int_t i=0; i<Nterms-1; i++) {
403  newRelLS[i]=RelLS[i];
404  }
405  newRelLS[Nterms-1]=C;
406  RelLS=newRelLS;
407  return 0;
408 }
409 
411  cout << " [ " << GnrPrefac.FracStringSqrt() << " G_"<< L << S <<" ] ";
412  for (Int_t i=0; i<Nterms; i++) {
413  RelLS[i]->PrintNR();
414  }
415  cout << endl;
416  return 0;
417 }
418 
420  cout << " [ G_"<< L << S <<" ] ";
421  for (Int_t i=0; i<Nterms; i++) {
422  TFracNum GnrInv(GnrPrefac);
423  GnrInv.Invert();
424  RelLS[i]->PrintNRG(GnrInv);
425  }
426  cout << endl;
427  return 0;
428 }