evtgen is hosted by Hepforge, IPPP Durham
EvtGen  2.0.0
Monte Carlo generator of particle decays, in particular the weak decays of heavy flavour particles such as B mesons.
EvtAmp.cpp
Go to the documentation of this file.
1 
2 /***********************************************************************
3 * Copyright 1998-2020 CERN for the benefit of the EvtGen authors *
4 * *
5 * This file is part of EvtGen. *
6 * *
7 * EvtGen is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * EvtGen is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with EvtGen. If not, see <https://www.gnu.org/licenses/>. *
19 ***********************************************************************/
20 
21 #include "EvtGenBase/EvtAmp.hh"
22 
23 #include "EvtGenBase/EvtComplex.hh"
24 #include "EvtGenBase/EvtId.hh"
25 #include "EvtGenBase/EvtPDL.hh"
27 #include "EvtGenBase/EvtPatches.hh"
28 #include "EvtGenBase/EvtReport.hh"
30 
31 #include <assert.h>
32 #include <iostream>
33 #include <math.h>
34 using std::endl;
35 
37 {
38  _ndaug = 0;
39  _pstates = 0;
40  _nontrivial = 0;
41 }
42 
43 EvtAmp::EvtAmp( const EvtAmp& amp )
44 {
45  int i;
46 
47  _ndaug = amp._ndaug;
48  _pstates = amp._pstates;
49  for ( i = 0; i < _ndaug; i++ ) {
50  dstates[i] = amp.dstates[i];
51  _dnontrivial[i] = amp._dnontrivial[i];
52  }
54 
55  int namp = 1;
56 
57  for ( i = 0; i < _nontrivial; i++ ) {
58  _nstate[i] = amp._nstate[i];
59  namp *= _nstate[i];
60  }
61 
62  for ( i = 0; i < namp; i++ ) {
63  assert( i < 125 );
64  _amp[i] = amp._amp[i];
65  }
66 }
67 
68 void EvtAmp::init( EvtId p, int ndaugs, EvtId* daug )
69 {
70  setNDaug( ndaugs );
71  int ichild;
72  int daug_states[100], parstates;
73  for ( ichild = 0; ichild < ndaugs; ichild++ ) {
74  daug_states[ichild] = EvtSpinType::getSpinStates(
75  EvtPDL::getSpinType( daug[ichild] ) );
76  }
77 
79 
80  setNState( parstates, daug_states );
81 }
82 
83 void EvtAmp::setNDaug( int n )
84 {
85  _ndaug = n;
86 }
87 
88 void EvtAmp::setNState( int parent_states, int* daug_states )
89 {
90  _nontrivial = 0;
91  _pstates = parent_states;
92 
93  if ( _pstates > 1 ) {
95  _nontrivial++;
96  }
97 
98  int i;
99 
100  for ( i = 0; i < _ndaug; i++ ) {
101  dstates[i] = daug_states[i];
102  _dnontrivial[i] = -1;
103  if ( daug_states[i] > 1 ) {
104  _nstate[_nontrivial] = daug_states[i];
106  _nontrivial++;
107  }
108  }
109 
110  if ( _nontrivial > 5 ) {
111  EvtGenReport( EVTGEN_ERROR, "EvtGen" )
112  << "Too many nontrivial states in EvtAmp!" << endl;
113  }
114 }
115 
116 void EvtAmp::setAmp( int* ind, const EvtComplex& a )
117 {
118  int nstatepad = 1;
119  int position = ind[0];
120 
121  for ( int i = 1; i < _nontrivial; i++ ) {
122  nstatepad *= _nstate[i - 1];
123  position += nstatepad * ind[i];
124  }
125  assert( position < 125 );
126  _amp[position] = a;
127 }
128 
129 const EvtComplex& EvtAmp::getAmp( int* ind ) const
130 {
131  int nstatepad = 1;
132  int position = ind[0];
133 
134  for ( int i = 1; i < _nontrivial; i++ ) {
135  nstatepad *= _nstate[i - 1];
136  position += nstatepad * ind[i];
137  }
138 
139  return _amp[position];
140 }
141 
143 {
144  EvtSpinDensity rho;
145  rho.setDim( _pstates );
146 
147  EvtComplex temp;
148 
149  int i, j, n;
150 
151  if ( _pstates == 1 ) {
152  if ( _nontrivial == 0 ) {
153  rho.set( 0, 0, _amp[0] * conj( _amp[0] ) );
154  return rho;
155  }
156 
157  n = 1;
158 
159  temp = EvtComplex( 0.0 );
160 
161  for ( i = 0; i < _nontrivial; i++ ) {
162  n *= _nstate[i];
163  }
164 
165  for ( i = 0; i < n; i++ ) {
166  temp += _amp[i] * conj( _amp[i] );
167  }
168 
169  rho.set( 0, 0, temp );
170  ;
171 
172  return rho;
173 
174  }
175 
176  else {
177  for ( i = 0; i < _pstates; i++ ) {
178  for ( j = 0; j < _pstates; j++ ) {
179  temp = EvtComplex( 0.0 );
180 
181  int kk;
182 
183  int allloop = 1;
184  for ( kk = 0; kk < _ndaug; kk++ ) {
185  allloop *= dstates[kk];
186  }
187 
188  for ( kk = 0; kk < allloop; kk++ ) {
189  temp += _amp[_pstates * kk + i] *
190  conj( _amp[_pstates * kk + j] );
191  }
192 
193  // if (_nontrivial>3){
194  //EvtGenReport(EVTGEN_ERROR,"EvtGen") << "Can't handle so many states in EvtAmp!"<<endl;
195  //}
196 
197  rho.set( i, j, temp );
198  }
199  }
200  return rho;
201  }
202 }
203 
205 {
206  EvtSpinDensity rho;
207 
208  rho.setDim( _pstates );
209 
210  if ( _pstates == 1 ) {
211  rho.set( 0, 0, EvtComplex( 1.0, 0.0 ) );
212  return rho;
213  }
214 
215  int k;
216 
217  EvtAmp ampprime;
218 
219  ampprime = ( *this );
220 
221  for ( k = 0; k < _ndaug; k++ ) {
222  if ( dstates[k] != 1 ) {
223  ampprime = ampprime.contract( _dnontrivial[k], rho_list[k + 1] );
224  }
225  }
226 
227  return ampprime.contract( 0, ( *this ) );
228 }
229 
231 {
232  EvtSpinDensity rho;
233 
234  rho.setDim( dstates[i] );
235 
236  int k;
237 
238  if ( dstates[i] == 1 ) {
239  rho.set( 0, 0, EvtComplex( 1.0, 0.0 ) );
240 
241  return rho;
242  }
243 
244  EvtAmp ampprime;
245 
246  ampprime = ( *this );
247 
248  if ( _pstates != 1 ) {
249  ampprime = ampprime.contract( 0, rho_list[0] );
250  }
251 
252  for ( k = 0; k < i; k++ ) {
253  if ( dstates[k] != 1 ) {
254  ampprime = ampprime.contract( _dnontrivial[k], rho_list[k + 1] );
255  }
256  }
257 
258  return ampprime.contract( _dnontrivial[i], ( *this ) );
259 }
260 
262 {
263  EvtAmp temp;
264 
265  int i, j;
266  temp._ndaug = _ndaug;
267  temp._pstates = _pstates;
268  temp._nontrivial = _nontrivial;
269 
270  for ( i = 0; i < _ndaug; i++ ) {
271  temp.dstates[i] = dstates[i];
272  temp._dnontrivial[i] = _dnontrivial[i];
273  }
274 
275  if ( _nontrivial == 0 ) {
276  EvtGenReport( EVTGEN_ERROR, "EvtGen" )
277  << "Should not be here EvtAmp!" << endl;
278  }
279 
280  for ( i = 0; i < _nontrivial; i++ ) {
281  temp._nstate[i] = _nstate[i];
282  }
283 
284  EvtComplex c;
285 
286  int index[10];
287  for ( i = 0; i < 10; i++ ) {
288  index[i] = 0;
289  }
290 
291  int allloop = 1;
292  int indflag, ii;
293  for ( i = 0; i < _nontrivial; i++ ) {
294  allloop *= _nstate[i];
295  }
296 
297  for ( i = 0; i < allloop; i++ ) {
298  c = EvtComplex( 0.0 );
299  int tempint = index[k];
300  for ( j = 0; j < _nstate[k]; j++ ) {
301  index[k] = j;
302  c += rho.get( j, tempint ) * getAmp( index );
303  }
304  index[k] = tempint;
305 
306  temp.setAmp( index, c );
307 
308  indflag = 0;
309  for ( ii = 0; ii < _nontrivial; ii++ ) {
310  if ( indflag == 0 ) {
311  if ( index[ii] == ( _nstate[ii] - 1 ) ) {
312  index[ii] = 0;
313  } else {
314  indflag = 1;
315  index[ii] += 1;
316  }
317  }
318  }
319  }
320  return temp;
321 }
322 
324 {
325  int i, j, l;
326 
327  EvtComplex temp;
328  EvtSpinDensity rho;
329 
330  rho.setDim( _nstate[k] );
331 
332  int allloop = 1;
333  int indflag, ii;
334  for ( i = 0; i < _nontrivial; i++ ) {
335  allloop *= _nstate[i];
336  }
337 
338  int index[10];
339  int index1[10];
340  // int l;
341  for ( i = 0; i < _nstate[k]; i++ ) {
342  for ( j = 0; j < _nstate[k]; j++ ) {
343  if ( _nontrivial == 0 ) {
344  EvtGenReport( EVTGEN_ERROR, "EvtGen" )
345  << "Should not be here1 EvtAmp!" << endl;
346  rho.set( 0, 0, EvtComplex( 1.0, 0.0 ) );
347  return rho;
348  }
349 
350  for ( ii = 0; ii < 10; ii++ ) {
351  index[ii] = 0;
352  index1[ii] = 0;
353  }
354  index[k] = i;
355  index1[k] = j;
356 
357  temp = EvtComplex( 0.0 );
358 
359  for ( l = 0; l < int( allloop / _nstate[k] ); l++ ) {
360  temp += getAmp( index ) * conj( amp2.getAmp( index1 ) );
361  indflag = 0;
362  for ( ii = 0; ii < _nontrivial; ii++ ) {
363  if ( ii != k ) {
364  if ( indflag == 0 ) {
365  if ( index[ii] == ( _nstate[ii] - 1 ) ) {
366  index[ii] = 0;
367  index1[ii] = 0;
368  } else {
369  indflag = 1;
370  index[ii] += 1;
371  index1[ii] += 1;
372  }
373  }
374  }
375  }
376  }
377  rho.set( i, j, temp );
378  }
379  }
380 
381  return rho;
382 }
383 
384 EvtAmp EvtAmp::contract( int, const EvtAmp&, const EvtAmp& )
385 {
386  //Do we need this method?
387  EvtAmp tmp;
388  EvtGenReport( EVTGEN_DEBUG, "EvtGen" )
389  << "EvtAmp::contract not written yet" << endl;
390  return tmp;
391 }
392 
394 {
395  int i, list[10];
396  for ( i = 0; i < 10; i++ ) {
397  list[i] = 0;
398  }
399 
400  EvtGenReport( EVTGEN_DEBUG, "EvtGen" )
401  << "Number of daugthers:" << _ndaug << endl;
402  EvtGenReport( EVTGEN_DEBUG, "EvtGen" )
403  << "Number of states of the parent:" << _pstates << endl;
404  EvtGenReport( EVTGEN_DEBUG, "EvtGen" ) << "Number of states on daughters:";
405  for ( i = 0; i < _ndaug; i++ ) {
406  EvtGenReport( EVTGEN_DEBUG, "EvtGen" ) << dstates[i] << " ";
407  }
408  EvtGenReport( EVTGEN_DEBUG, "EvtGen" ) << endl;
409  EvtGenReport( EVTGEN_DEBUG, "EvtGen" ) << "Nontrivial index of daughters:";
410  for ( i = 0; i < _ndaug; i++ ) {
411  EvtGenReport( EVTGEN_DEBUG, "EvtGen" ) << _dnontrivial[i] << " ";
412  }
413  EvtGenReport( EVTGEN_DEBUG, "EvtGen" ) << endl;
414  EvtGenReport( EVTGEN_DEBUG, "EvtGen" )
415  << "number of nontrivial states:" << _nontrivial << endl;
416  EvtGenReport( EVTGEN_DEBUG, "EvtGen" )
417  << "Nontrivial particles number of states:";
418  for ( i = 0; i < _nontrivial; i++ ) {
419  EvtGenReport( EVTGEN_DEBUG, "EvtGen" ) << _nstate[i] << " ";
420  }
421  EvtGenReport( EVTGEN_DEBUG, "EvtGen" ) << endl;
422  EvtGenReport( EVTGEN_DEBUG, "EvtGen" ) << "Amplitudes:" << endl;
423  if ( _nontrivial == 0 ) {
424  list[0] = 0;
425  EvtGenReport( EVTGEN_DEBUG, "EvtGen" ) << getAmp( list ) << endl;
426  }
427 
428  int allloop[10];
429  for ( i = 0; i < 10; i++ ) {
430  allloop[i] = 0;
431  }
432 
433  allloop[0] = 1;
434  for ( i = 0; i < _nontrivial; i++ ) {
435  if ( i == 0 ) {
436  allloop[i] *= _nstate[i];
437  } else {
438  allloop[i] = allloop[i - 1] * _nstate[i];
439  }
440  }
441  int index = 0;
442  for ( i = 0; i < allloop[_nontrivial - 1]; i++ ) {
443  EvtGenReport( EVTGEN_DEBUG, "EvtGen" ) << getAmp( list ) << " ";
444  if ( i == allloop[index] - 1 ) {
445  index++;
446  EvtGenReport( EVTGEN_DEBUG, "EvtGen" ) << endl;
447  }
448  }
449 
450  EvtGenReport( EVTGEN_DEBUG, "EvtGen" )
451  << "-----------------------------------" << endl;
452 }
453 
454 void EvtAmp::vertex( const EvtComplex& c )
455 {
456  int list[1];
457  list[0] = 0;
458  setAmp( list, c );
459 }
460 
461 void EvtAmp::vertex( int i, const EvtComplex& c )
462 {
463  int list[1];
464  list[0] = i;
465  setAmp( list, c );
466 }
467 
468 void EvtAmp::vertex( int i, int j, const EvtComplex& c )
469 {
470  int list[2];
471  list[0] = i;
472  list[1] = j;
473  setAmp( list, c );
474 }
475 
476 void EvtAmp::vertex( int i, int j, int k, const EvtComplex& c )
477 {
478  int list[3];
479  list[0] = i;
480  list[1] = j;
481  list[2] = k;
482  setAmp( list, c );
483 }
484 
485 void EvtAmp::vertex( int* i1, const EvtComplex& c )
486 {
487  setAmp( i1, c );
488 }
489 
491 {
492  int i;
493 
494  _ndaug = amp._ndaug;
495  _pstates = amp._pstates;
496  for ( i = 0; i < _ndaug; i++ ) {
497  dstates[i] = amp.dstates[i];
498  _dnontrivial[i] = amp._dnontrivial[i];
499  }
500  _nontrivial = amp._nontrivial;
501 
502  int namp = 1;
503 
504  for ( i = 0; i < _nontrivial; i++ ) {
505  _nstate[i] = amp._nstate[i];
506  namp *= _nstate[i];
507  }
508 
509  for ( i = 0; i < namp; i++ ) {
510  assert( i < 125 );
511  _amp[i] = amp._amp[i];
512  }
513 
514  return *this;
515 }
EvtSpinDensity getBackwardSpinDensity(EvtSpinDensity *rho_list)
Definition: EvtAmp.cpp:204
static EvtSpinType::spintype getSpinType(EvtId i)
Definition: EvtPDL.cpp:377
EvtAmp()
Definition: EvtAmp.cpp:36
std::ostream & EvtGenReport(EvtGenSeverity severity, const char *facility=0)
Definition: EvtReport.cpp:33
Evt3Rank3C conj(const Evt3Rank3C &t2)
Definition: Evt3Rank3C.cpp:172
const EvtComplex & get(int i, int j) const
int _nontrivial
Definition: EvtAmp.hh:104
static int getSpinStates(spintype stype)
Definition: EvtSpinType.cpp:57
EvtSpinDensity getSpinDensity()
Definition: EvtAmp.cpp:142
void setNState(int parent_states, int *daug_states)
Definition: EvtAmp.cpp:88
const EvtComplex & getAmp(int *ind) const
Definition: EvtAmp.cpp:129
Definition: EvtId.hh:27
void vertex(const EvtComplex &amp)
Definition: EvtAmp.cpp:454
int _ndaug
Definition: EvtAmp.hh:92
int _dnontrivial[10]
Definition: EvtAmp.hh:101
Definition: EvtAmp.hh:30
int _pstates
Definition: EvtAmp.hh:95
EvtAmp & operator=(const EvtAmp &amp)
Definition: EvtAmp.cpp:490
EvtSpinDensity contract(int i, const EvtAmp &a)
Definition: EvtAmp.cpp:323
void dump()
Definition: EvtAmp.cpp:393
void set(int i, int j, const EvtComplex &rhoij)
EvtComplex _amp[125]
Definition: EvtAmp.hh:89
EvtSpinDensity getForwardSpinDensity(EvtSpinDensity *rho_list, int k)
Definition: EvtAmp.cpp:230
void setDim(int n)
int dstates[10]
Definition: EvtAmp.hh:98
void setAmp(int *ind, const EvtComplex &amp)
Definition: EvtAmp.cpp:116
void init(EvtId p, int ndaug, EvtId *daug)
Definition: EvtAmp.cpp:68
void setNDaug(int n)
Definition: EvtAmp.cpp:83
int _nstate[5]
Definition: EvtAmp.hh:107