Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-06 09:25:33

0001 // -*- C++ -*- defining S-matrix class for Ninja.  It is used to store
0002 // invariants s[i,j] defined as:
0003 //
0004 //   s[i,j] = (vi[i]-vi[j])^2
0005 //
0006 // where vi[i] is the internal momentum of the i-th loop denominator
0007 //
0008 //   Denom[i] = (q+vi[i])^2 - m[i]^2.
0009 //
0010 // If an S-matrix is provided by the user, the computation of Master
0011 // Integrals by the integral libraries might become more accurate.
0012 
0013 
0014 #ifndef NINJA_S_MAT_H
0015 #define NINJA_S_MAT_H
0016 
0017 #include <ninja/types.hh>
0018 
0019 namespace ninja {
0020 
0021   class SMatrix {
0022   public:
0023 
0024     // Default constructor
0025     SMatrix() : data_(0), n_rows_(0), owns_data_(false) {}
0026 
0027     // Constructor from number of rows.  This is the only constructor
0028     // which allocates data.  The destructor will free the allocated
0029     // memory only if either this constructor or the allocate method
0030     // was called.
0031     explicit SMatrix(int n)
0032       : data_(new Real[n*n]), n_rows_(n), owns_data_(true) {}
0033 
0034     // Constructor from number of rows and pointer to data
0035     SMatrix(int n, Real * data_ptr)
0036       : data_(data_ptr), n_rows_(data_ptr ? n : 0), owns_data_(false) {}
0037 
0038     // Copy constructor
0039     SMatrix(const SMatrix & s_mat)
0040       : data_(s_mat.data_), n_rows_(s_mat.n_rows_), owns_data_(false) {}
0041 
0042     // Destructor.  It deallocates data only if it was allocated in
0043     // this instance.  Once this is called, if the instance had been
0044     // newly-allocated before, all its copies are invalidated.  It is
0045     // up to the user making sure no such copies survive after this
0046     // happens.  On the other hand, if the instance was itself a copy
0047     // no action is performed on the data upon destruction of this
0048     // instance.
0049     ~SMatrix()
0050     {
0051       if (owns_data_)
0052         delete [] data_;
0053     }
0054 
0055     // Assign (equivalent to copy constructor)
0056     SMatrix & operator= (const SMatrix & s_mat)
0057     {
0058       if (owns_data_)
0059         delete [] data_;
0060       data_ = s_mat.data_;
0061       n_rows_ = data_ ? s_mat.n_rows_ : 0;
0062       owns_data_ = false;
0063       return *this;
0064     }
0065 
0066     // Allocate memory for the matrix.  The destructor will later free
0067     // the allocated memory automatically.
0068     SMatrix & allocate(int n)
0069     {
0070       if (owns_data_)
0071         delete [] data_;
0072       n_rows_ = n;
0073       data_ = new Real[n*n];
0074       owns_data_ = true;
0075       return *this;
0076     }
0077 
0078     //  Does same thing as the destructor
0079     void clear()
0080     {
0081       if (owns_data_)
0082         delete [] data_;
0083       data_ = 0;
0084       owns_data_ = false;
0085     }
0086 
0087     // copy data from another matrix
0088     void copy(const SMatrix & s_mat) {
0089       if (s_mat.data_) {
0090         allocate(s_mat.n_rows_);
0091         for (int i=0; i<n_rows_*n_rows_; ++i)
0092           data_[i] = s_mat.data_[i];
0093       } else {
0094         clear();
0095       }
0096     }
0097 
0098     // Pointer to data_
0099     Real * data()
0100     {
0101       return data_;
0102     }
0103 
0104     // Check wheter there's no data_
0105     bool isNull()
0106     {
0107       return (! data_);
0108     }
0109 
0110     // Fill the whole matrix with the same value
0111     SMatrix & fill(Real value)
0112     {
0113       for (int i=0; i<n_rows_*n_rows_; ++i)
0114         data_[i] = value;
0115       return *this;
0116     }
0117 
0118     // Fill the matrix from the internal kinematics and set to zero
0119     // elememnts smaller than ir_threshold.
0120     SMatrix & fillFromKinematics(const RealMomentum pi[],
0121                                  Real ir_threshold = 0)
0122     {
0123       Real temp;
0124       for (int i=0; i<n_rows_; ++i) {
0125         (*this)(i,i) = Real();
0126         for (int j=i+1; j<n_rows_; ++j) {
0127           temp = mp2(pi[i]-pi[j]);
0128           (*this)(i,j) = (*this)(j,i) =  abs(temp) < ir_threshold ? 0
0129                                                      : temp;
0130         }
0131       }
0132       return *this;
0133     }
0134 
0135     // Element access via s_mat(i,j)
0136     Real operator() (unsigned i, unsigned j) const
0137     {
0138       return data_[i*n_rows_+j];
0139     }
0140     Real & operator() (unsigned i, unsigned j)
0141     {
0142       return data_[i*n_rows_+j];
0143     }
0144 
0145   private:
0146 
0147     Real * data_;
0148     int n_rows_;
0149     bool owns_data_;
0150 
0151   }; // SMatrix
0152 
0153 } // namespace ninja
0154 
0155 #endif // NINJA_S_MAT_H