// tsncom31.cc // Nick Macks (macks@fnal.gov), Summer 2002 // CovMatrices: CovMatrixX trace calculation #include "CovMatrices/CovMatrix2.h" #include "CovMatrices/CovMatrix3.h" #include "CovMatrices/CovMatrix4.h" #include "CovMatrices/CovMatrix5.h" #include "CovMatrices/CovMatrix6.h" using namespace std; using CovMatrices::CovMatrix2; using CovMatrices::CovMatrix3; using CovMatrices::CovMatrix4; using CovMatrices::CovMatrix5; using CovMatrices::CovMatrix6; // Function declarations void Identification(); void GetDimension(int&); void Describe(const int&); void BuildCovMatrix2(CovMatrix2&); void BuildCovMatrix3(CovMatrix3&); void BuildCovMatrix4(CovMatrix4&); void BuildCovMatrix5(CovMatrix5&); void BuildCovMatrix6(CovMatrix6&); void Show2(const CovMatrix2&); void Show3(const CovMatrix3&); void Show4(const CovMatrix4&); void Show5(const CovMatrix5&); void Show6(const CovMatrix6&); void GetCalcs(int&); void GetRuns(int&); void Calculate2(CovMatrix2&, const int&, const int&); void Calculate3(CovMatrix3&, const int&, const int&); void Calculate4(CovMatrix4&, const int&, const int&); void Calculate5(CovMatrix5&, const int&, const int&); void Calculate6(CovMatrix6&, const int&, const int&); // Package ID void Identification() { cout << "Using CovMatrices\n"; } // Ask for the desired dimension void GetDimension(int& dimension) { cout << "Enter the desired dimension(2-6): "; cin >> dimension; while ( (dimension < 2) || (dimension > 6) ) { cout << "Enter an integer between 2 and 6: "; cin >> dimension; } } // Describe how the matrix was defined void Describe(const int& dimension) { cout << "Matrix was defined 'CovMatrix" << dimension << "'\n"; } // Built a 2-dimension CovMatrix void BuildCovMatrix2(CovMatrix2& matrix2) { for (int i=0; i<2; ++i) { for (int j=0; j<2; ++j) { if (i == j) matrix2(i,j) = 1000 + i*100; else if (i > j) matrix2(i,j) = 2 + i*2 + j*(2*2); } } } // Built a 3-dimension CovMatrix void BuildCovMatrix3(CovMatrix3& matrix3) { for (int i=0; i<3; ++i) { for (int j=0; j<3; ++j) { if (i == j) matrix3(i,j) = 1000 + i*100; else if (i > j) matrix3(i,j) = 2 + i*2 + j*(3*2); } } } // Built a 4-dimension CovMatrix void BuildCovMatrix4(CovMatrix4& matrix4) { for (int i=0; i<4; ++i) { for (int j=0; j<4; ++j) { if (i == j) matrix4(i,j) = 1000 + i*100; else if (i > j) matrix4(i,j) = 2 + i*2 + j*(4*2); } } } // Built a 5-dimension CovMatrix void BuildCovMatrix5(CovMatrix5& matrix5) { for (int i=0; i<5; ++i) { for (int j=0; j<5; ++j) { if (i == j) matrix5(i,j) = 1000 + i*100; else if (i > j) matrix5(i,j) = 2 + i*2 + j*(5*2); } } } // Built a 6-dimension CovMatrix void BuildCovMatrix6(CovMatrix6& matrix6) { for (int i=0; i<6; ++i) { for (int j=0; j<6; ++j) { if (i == j) matrix6(i,j) = 1000 + i*100; else if (i > j) matrix6(i,j) = 2 + i*2 + j*(6*2); } } } // Show the 2-dimensional CovMatrix void Show2(const CovMatrix2& matrix2) { cout << "Using matrix =\n" << matrix2 << "\n"; } // Show the 3-dimensional CovMatrix void Show3(const CovMatrix3& matrix3) { cout << "Using matrix =\n" << matrix3 << "\n"; } // Show the 4-dimensional CovMatrix void Show4(const CovMatrix4& matrix4) { cout << "Using matrix =\n" << matrix4 << "\n"; } // Show the 5-dimensional CovMatrix void Show5(const CovMatrix5& matrix5) { cout << "Using matrix =\n" << matrix5 << "\n"; } // Show the 6-dimensional CovMatrix void Show6(const CovMatrix6& matrix6) { cout << "Using matrix =\n" << matrix6 << "\n"; } // Get the number of times to calculate the trace void GetCalcs(int& N) { cout << "How many trace calculations? "; cin >> N; } // Get the number of runs void GetRuns(int& run) { cout << "How many runs? "; cin >> run; cout << "\n"; } // Calculate the trace of a 2-dimensional matrix void Calculate2(CovMatrix2& matrix2, const int& N, const int& runs) { // Define a counter int counter2 = 0; // Define a double to hold the trace value double trace2 = 0.; // Loop "run" times for (int r=0; r