// tsncom26.cc // Nick Macks (macks@fnal.gov), Summer 2002 // CLHEP: HepVector*HepMatrix multiplication // (In order to perform vector*matrix in CLHEP we have to transpose // the vector. However, when we transpose a HepVector we get back a // HepMatrix. Thus, we end up performing matrix*matrix multiplication // and not vector*matrix.) #include "CLHEP/Matrix/Vector.h" #include "CLHEP/Matrix/Matrix.h" using namespace std; // Function declarations void Identification(); void GetDimensions(int&); void Describe(const int&); void BuildMatrix(HepMatrix&, const int&); void BuildVector(HepVector&, const int&); void Show(const HepMatrix&, const HepVector&); void GetCalcs(int&); void GetRuns(int&); void Calculate(HepMatrix&, HepVector&, const int&, const int&, const int&); // Package ID void Identification() { cout << "Using CLHEP\n"; } // Ask for the desired dimensions void GetDimensions(int& dimension) { cout << "Enter the desired dimension(1-6): "; cin >> dimension; while ( (dimension < 1) || (dimension > 6) ) { cout << "Enter an integer between 1 and 6: "; cin >> dimension; } } // Describe how the matrix and the vector were defined void Describe(const int& dimension) { cout << "Matrix was defined 'HepMatrix (" << dimension << ", " << dimension << ")'\n"; cout << "Vector was defined 'HepVector (" << dimension << ")'\n"; } // Build the matrix void BuildMatrix(HepMatrix& matrix, const int& dimension) { for (int i=0; i j) matrix[i][j] = 2 + i*2 + j*(dimension*2); } } } // Build the vector void BuildVector(HepVector& vector, const int& dimension) { for (int i=0; i> N; } // Get the number of runs void GetRuns(int& run) { cout << "How many runs? "; cin >> run; cout << "\n"; } // Multiply the HepMatrix with the HepVector void Calculate(HepMatrix& matrix, HepVector& vector, const int& dimension, const int& N, const int& runs) { // Define a counter int counter = 0; // Define a HepMatrix to hold the transpose of the HepVector HepMatrix transpose (dimension, dimension); // Transpose the HepVector so you can do vector*matrix transpose = vector.T(); // Define a vector to hold the result HepVector product_vector (dimension); // Define a HepMatrix to hold the transpose of the product_vector HepMatrix product (dimension, dimension); // Transpose the product vector product = product_vector.T(); // Loop "run" times for (int r=0; r