Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MakeEigensystem.cc
Go to the documentation of this file.
1 #include "TFile.h"
2 #include "TH1F.h"
3 #include "TH2F.h"
4 #include "TMatrixT.h"
5 #include "TMatrixTSym.h"
6 #include "TMatrixDSymEigen.h"
7 #include "TVectorT.h"
8 
9 #include <iostream>
10 
11 using namespace std;
12 
13 int main( int argc, char** argv ){
14 
15 if(string(argv[1]) == "help" || string(argv[1]) == "-help" || string(argv[1]) == "--help" || string(argv[1]) == "-h") {
16  cout << "This program expects the following argument(s) in order: " << endl;
17  cout << "Argument 1: path to merged gain_factor_matrices.root" << endl;
18  return 0;
19 }
20 
21 if(argc != 2) {
22  cout << "Error: you must specify the path to your gain_factor_matrices.root file!!!" << endl;
23  return 0;
24 }
25 
26 TFile* myfile = new TFile(argv[1]);
27 TH1F* h1D_mC = (TH1F*)myfile->Get("h2D_mC");
28 
29 int n_channels = h1D_mC->GetNbinsX();
30 int n_channelsy = h1D_mC->GetNbinsY();
31 
32  if (n_channels != n_channelsy) {
33  cout << "*** Non-square matrix***, nchannels=" << n_channels << " nchannelsy=" << n_channelsy << endl;
34  return -1;
35  }
36  else {
37  cout << "Found square matrix m_mc, nchannels=" << n_channels << endl;
38  }
39 
40 TMatrixDSym m_mC;
41 
42 m_mC.ResizeTo(n_channels,n_channels);
43  //Generate Matrices back from TH1F and TH2F's
44 
45 cout << "Generating Matrix from imported TH1F..." << endl;
46 for(int i = 0 ; i<n_channels; ++i) {
47  for( int j = 0 ; j<n_channels; ++j) {
48  m_mC[i][j]=h1D_mC->GetBinContent(i+1,j+1);
49  }
50 }
51 
52 
53 cout << "Getting Eigensystem (this will take a while...) \n";
54 TMatrixDSymEigen mC_eigen(m_mC);
55 TVectorD eval = mC_eigen.GetEigenValues();
56 TMatrixD evec = mC_eigen.GetEigenVectors();
57 cout << "Filling Histograms... \n";
58 
59 
60 double mymin=eval.Min();
61 double mymax=eval.Max();
62 
63  TH1F* h1_evals = new TH1F( "h1_evals", "Eigenvalues of C Matrix by Channel Number",n_channels, 0., n_channels );
64  TH2F* h2_evecs = new TH2F( "h2_evecs DO NOT PLOT", "Eigenvectors (good luck drawing this)", n_channels, 0., n_channels, n_channels,0.,n_channels );
65  TH1F* eig = new TH1F( "Eigenvalues, unordered", "Eigenvalues of C matrix" ,100, mymin, mymax/12. );
66 
67 
68 
69 for(int i = 0 ; i<n_channels; ++i) {
70 
71  if(eval[i]>0.0 &&eval[i]<10000.0) h1_evals->SetBinContent(i+1,eval[i]);
72  eig->Fill(eval[i]);
73  for(int j = 0 ; j<n_channels; ++j) {
74  h2_evecs->SetBinContent(i+1,j+1,evec[i][j]);
75  }
76 }
77 
78  TFile* m_rootFile = new TFile( "C_Eigensystem.root", "RECREATE" );
79 
80  m_rootFile->cd();
81  h1_evals->Write();
82  h2_evecs->Write();
83  eig->Write();
84  m_rootFile->Close();
85 
86 
87 cout << "done" << endl;
88 
89  return 0;
90 
91 }
int main(int argc, char *argv[])
Definition: gendoc.cc:6