16 for(
int i=0; i<index.size()-1; ++i) {
19 os<<index[index.size()-1]<<
">"<<amp(index)<<
":";
29 for(
int i=0; i<ret._elem.size(); ++i ) {
45 for(
int i=0; i<ret._elem.size(); ++i ) {
52vector<int> EvtSpinAmp::calctwospin(
const vector<EvtSpinType::spintype>& type )
const
56 for(
int i=0; i<type.size(); ++i ) {
67 _twospin=calctwospin( type );
69 for(
int i=0; i<_twospin.size(); ++i )
72 _elem=vector<EvtComplex>(
num );
79 _twospin=calctwospin( type );
81 for(
int i=0; i<_twospin.size(); ++i )
84 _elem=vector<EvtComplex>(
num, val );
88 const vector<EvtComplex>& elem )
93 _twospin=calctwospin( type );
96 for(
int i=0; i<_twospin.size(); ++i )
99 if(_elem.size() !=
num ) {
100 report(
ERROR,
"EvtGen")<<
"Wrong number of elements input:"
101 <<_elem.size()<<
" vs. "<<
num<<endl;
109 _twospin = copy._twospin;
114void EvtSpinAmp::checktwospin(
const vector<int>& twospin )
const
116 if( _twospin == twospin )
120 <<
"Dimension or order of tensors being operated on does not match"
125void EvtSpinAmp::checkindexargs(
const vector<int>& index )
const
127 if( index.size()==0 ) {
128 report(
ERROR,
"EvtGen") <<
"EvtSpinAmp can't handle no indices" << endl;
132 if( index.size() != _twospin.size() ) {
133 report(
ERROR,
"EvtGen" ) <<
"Rank of EvtSpinAmp index does not match: "
134 <<_twospin.size()<<
" expected "<<index.size()<<
" input."<<endl;
138 for(
int i=0; i<_twospin.size(); ++i ) {
139 if( _twospin[i]>=
abs(index[i]) && _twospin[i]%2==index[i]%2 )
141 report(
ERROR,
"EvtGen")<<
"EvtSpinAmp index out of range" << endl;
143 for(
int j=0; j<_twospin.size(); ++j )
147 for(
int j=0; j<index.size(); ++j )
154int EvtSpinAmp::findtrueindex(
const vector<int>& index )
const
158 for(
int i = index.size()-1; i>0; --i ) {
159 trueindex += (index[i]+_twospin[i])/2;
160 trueindex *= _twospin[i-1]+1;
163 trueindex += (index[0]+_twospin[0])/2;
170 checkindexargs( index );
172 int trueindex = findtrueindex(index);
173 if(trueindex >= _elem.size()) {
174 report(
ERROR,
"EvtGen")<<
"indexing error "<<trueindex<<
" "<<_elem.size()<<endl;
175 for(
int i=0; i<_twospin.size(); ++i) {
180 for(
int i=0; i<index.size(); ++i) {
188 return _elem[trueindex];
193 checkindexargs( index );
195 int trueindex = findtrueindex(index);
196 if(trueindex >= _elem.size()) {
197 report(
ERROR,
"EvtGen")<<
"indexing error "<<trueindex<<
" "<<_elem.size()<<endl;
198 for(
int i=0; i<_twospin.size(); ++i) {
203 for(
int i=0; i<index.size(); ++i) {
211 return _elem[trueindex];
217 vector<int> index( _twospin.size() );
222 for(
int n=1;
n<_twospin.size(); ++
n )
223 index[
n]=va_arg( ap,
int );
227 return (*
this)( index );
232 vector<int> index( _twospin.size() );
238 for(
int n=1;
n<_twospin.size(); ++
n )
239 index[
n]=va_arg( ap,
int );
243 return (*
this)( index );
248 _twospin=
cont._twospin;
257 checktwospin(
cont._twospin );
260 for(
int i=0; i<ret._elem.size(); ++i ) {
261 ret._elem[i]+=_elem[i];
270 checktwospin(
cont._twospin );
272 for(
int i=0; i<_elem.size(); ++i )
273 _elem[i]+=
cont._elem[i];
280 checktwospin(
cont._twospin );
283 for(
int i=0; i<ret._elem.size(); ++i )
284 ret._elem[i]-=
cont._elem[i];
291 checktwospin(
cont._twospin );
293 for(
int i=0; i<_elem.size(); ++i )
294 _elem[i]-=
cont._elem[i];
302 vector<int> index(
rank()+amp2.
rank());
303 vector<int> index1(
rank()), index2(amp2.
rank());
306 amp._twospin=_twospin;
309 for(
int i=0; i<amp2._twospin.size(); ++i ) {
310 amp._twospin.push_back( amp2._twospin[i] );
311 amp._type.push_back( amp2._type[i] );
314 amp._elem = vector<EvtComplex>( _elem.size() * amp2._elem.size() );
316 for(
int i=0; i<index1.size(); ++i )
317 index[i]=index1[i]=-_twospin[i];
319 for(
int i=0; i<index2.size(); ++i )
320 index[i+
rank()]=index2[i]=-amp2._twospin[i];
323 amp( index ) = (*this)( index1 )*amp2( index2 );
324 if(!amp.
iterate( index ))
break;
326 for(
int i=0; i<index1.size(); ++i )
329 for(
int i=0; i<index2.size(); ++i )
330 index2[i]=index[i+
rank()];
345 for(
int i=0; i<_elem.size(); ++i )
353 for(
int i=0; i<_elem.size(); ++i )
361 vector<int> init( _twospin.size() );
363 for(
int i=0; i<_twospin.size(); ++i )
364 init[i]=-_twospin[i];
371 int last = _twospin.size() - 1;
374 for(
int j=0; j<last; ++j ) {
375 if( index[j] > _twospin[j] ) {
376 index[j] = -_twospin[j];
381 return abs(index[last])<=_twospin[last];
388 if( index.size() != _type.size() ) {
390 <<
"Wrong dimensino index input to allowed."<<endl;
394 for(
int i=0; i<index.size(); ++i) {
397 if(
abs(index[i])!=2)
return false;
401 <<
"EvMultibody currently cannot handle neutrinos."<<endl;
433 int newrank=
rank()-2;
435 report(
ERROR,
"EvtGen")<<
"EvtSpinAmp can't handle no indices" << endl;
439 if(_twospin[a]!=_twospin[b]) {
441 <<
"Contaction called on indices of different dimension"
444 <<
"Called on "<<_twospin[a]<<
" and "<<_twospin[b]
449 vector<int> newtwospin( newrank );
450 vector<EvtSpinType::spintype> newtype( newrank );
452 for(
int i=0, j=0; i<_twospin.size(); ++i ){
453 if(i==a || i==b)
continue;
455 newtwospin[j] = _twospin[i];
456 newtype[j] = _type[i];
461 vector<int> index(
rank() ), newindex = newamp.
iterinit();
463 for(
int i=0; i<newrank; ++i )
464 newindex[i] = -newtwospin[i];
468 for(
int i=0, j=0; i<
rank(); ++i ) {
469 if(i==a || i==b)
continue;
470 index[i]=newindex[j];
474 index[b]=index[a]=-_twospin[a];
475 newamp(newindex) = (*this)(index);
476 for(
int i=-_twospin[a]+2; i<=_twospin[a]; i+=2 ) {
478 newamp(newindex) += (*this)(index);
481 if(!newamp.
iterate(newindex))
break;
double real(const EvtComplex &c)
double abs(const EvtComplex &c)
ostream & report(Severity severity, const char *facility)
std::ostream & operator<<(std::ostream &os, const EvtSpinAmp &)
EvtSpinAmp operator*(const EvtComplex &real, const EvtSpinAmp &cont)
EvtSpinAmp operator/(const EvtSpinAmp &cont, const EvtComplex &real)
EvtComplex cont(const EvtTensor4C &t1, const EvtTensor4C &t2)
EvtComplex & operator()(const vector< int > &)
EvtSpinAmp & operator-=(const EvtSpinAmp &)
EvtSpinAmp & operator=(const EvtSpinAmp &)
vector< int > iterinit() const
bool iterate(vector< int > &index) const
bool iterateallowed(vector< int > &index) const
EvtSpinAmp & operator*=(const EvtSpinAmp &)
EvtSpinAmp operator+(const EvtSpinAmp &) const
vector< int > iterallowedinit() const
EvtSpinAmp & operator+=(const EvtSpinAmp &)
bool allowed(const vector< int > &index) const
EvtSpinAmp & operator/=(const EvtComplex &)
friend EvtSpinAmp operator*(const EvtComplex &, const EvtSpinAmp &)
void extcont(const EvtSpinAmp &, int, int)
EvtSpinAmp operator-(const EvtSpinAmp &) const
static int getSpin2(spintype stype)