Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-06 09:20:03

0001 
0002 /***********************************************************************
0003 * Copyright 1998-2020 CERN for the benefit of the EvtGen authors       *
0004 *                                                                      *
0005 * This file is part of EvtGen.                                         *
0006 *                                                                      *
0007 * EvtGen is free software: you can redistribute it and/or modify       *
0008 * it under the terms of the GNU General Public License as published by *
0009 * the Free Software Foundation, either version 3 of the License, or    *
0010 * (at your option) any later version.                                  *
0011 *                                                                      *
0012 * EvtGen is distributed in the hope that it will be useful,            *
0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
0015 * GNU General Public License for more details.                         *
0016 *                                                                      *
0017 * You should have received a copy of the GNU General Public License    *
0018 * along with EvtGen.  If not, see <https://www.gnu.org/licenses/>.     *
0019 ***********************************************************************/
0020 
0021 #ifndef __EVTSPINAMP_HH__
0022 #define __EVTSPINAMP_HH__
0023 
0024 #include "EvtGenBase/EvtComplex.hh"
0025 #include "EvtGenBase/EvtSpinType.hh"
0026 
0027 #include <vector>
0028 using std::vector;
0029 
0030 #include <cstdarg>
0031 
0032 class EvtSpinAmp;
0033 EvtSpinAmp operator*( const EvtComplex&, const EvtSpinAmp& );
0034 EvtSpinAmp operator*( const EvtSpinAmp&, const EvtComplex& );
0035 EvtSpinAmp operator/( const EvtSpinAmp&, const EvtComplex& );
0036 
0037 class EvtSpinAmp {
0038     friend EvtSpinAmp operator*( const EvtComplex&, const EvtSpinAmp& );
0039     friend EvtSpinAmp operator*( const EvtSpinAmp&, const EvtComplex& );
0040     friend EvtSpinAmp operator/( const EvtSpinAmp&, const EvtComplex& );
0041     friend std::ostream& operator<<( std::ostream&, const EvtSpinAmp& );
0042 
0043   public:
0044     EvtSpinAmp(){};
0045     EvtSpinAmp( const vector<EvtSpinType::spintype>& );
0046     EvtSpinAmp( const vector<EvtSpinType::spintype>&, const EvtComplex& );
0047     EvtSpinAmp( const vector<EvtSpinType::spintype>&, const vector<EvtComplex>& );
0048     EvtSpinAmp( const EvtSpinAmp& );
0049 
0050     ~EvtSpinAmp(){};
0051 
0052     // Input to the index functions are twice the magnetic quantum number
0053     EvtComplex& operator()( const vector<int>& );
0054     const EvtComplex& operator()( const vector<int>& ) const;
0055     EvtComplex& operator()( int, ... );
0056     const EvtComplex& operator()( int, ... ) const;
0057 
0058     EvtSpinAmp& operator=( const EvtSpinAmp& );
0059 
0060     EvtSpinAmp operator+( const EvtSpinAmp& ) const;
0061     EvtSpinAmp& operator+=( const EvtSpinAmp& );
0062 
0063     EvtSpinAmp operator-( const EvtSpinAmp& ) const;
0064     EvtSpinAmp& operator-=( const EvtSpinAmp& );
0065 
0066     // Direct Product
0067     EvtSpinAmp operator*(const EvtSpinAmp&)const;
0068     EvtSpinAmp& operator*=( const EvtSpinAmp& );
0069 
0070     EvtSpinAmp& operator*=( const EvtComplex& );
0071     EvtSpinAmp& operator/=( const EvtComplex& );
0072 
0073     // Contraction of amplitudes
0074     void intcont( size_t, size_t );
0075     void extcont( const EvtSpinAmp&, int, int );
0076 
0077     // assign this value to every member in the container
0078     void assign( const EvtComplex& val ) { _elem.assign( _elem.size(), val ); }
0079 
0080     // get the order of the container
0081     size_t rank() const { return _twospin.size(); }
0082 
0083     // get the dimension vector of the container
0084     const vector<unsigned int>& dims() const { return _twospin; }
0085 
0086     // set the elements and the dimensions of the vector - useful for something
0087     // things eventough it is usually not the cleanest solution
0088     void addspin( int twospin ) { _twospin.push_back( twospin ); }
0089     void setelem( const vector<EvtComplex>& elem ) { _elem = elem; }
0090 
0091     bool iterate( vector<int>& index ) const;
0092     vector<int> iterinit() const;
0093 
0094     bool allowed( const vector<int>& index ) const;
0095     bool iterateallowed( vector<int>& index ) const;
0096     vector<int> iterallowedinit() const;
0097 
0098   private:
0099     void checkindexargs( const vector<int>& index ) const;
0100     void checktwospin( const vector<unsigned int>& twospin ) const;
0101     int findtrueindex( const vector<int>& index ) const;
0102     vector<unsigned int> calctwospin(
0103         const vector<EvtSpinType::spintype>& type ) const;
0104 
0105     vector<EvtSpinType::spintype> _type;
0106     vector<unsigned int> _twospin;
0107     vector<EvtComplex> _elem;
0108 };
0109 
0110 #endif    // __EVTSPINAMP__