00001 #include "TGraphErrors.h"
00002 #include "TMultiGraph.h"
00003 #include "TCanvas.h"
00004 #include "TLegend.h"
00005 #include "TPaveText.h"
00006 #include "TFile.h"
00007 #include "TProfile.h"
00008 #include "TStyle.h"
00009 #include "TMath.h"
00010 #include "TFrame.h"
00011
00012 #include <string>
00013 #include <iostream>
00014
00015 int fillCol=20;
00016 std::string systemName;
00017 bool drawSingleGraph = true;
00018
00019 int topX=10;
00020 int topY=50;
00021
00022 const Int_t N=10;
00023
00024
00025 void matrixOperations_do(std::string type = "", bool clhep=false, bool drawSingleGraph = false );
00026
00027 void matrixOperations(std::string type = "",bool clhep=false, bool drawSingleGraph = false ) {
00028
00029 matrixOperations_do(type,clhep,drawSingleGraph);
00030
00031
00032
00033 }
00034
00035
00036 void DrawData(char * title, TGraphErrors * h1, TGraphErrors * h2, TGraphErrors * h3 = 0, TGraphErrors * h4 = 0, TGraphErrors * h5 = 0, TGraphErrors * h6 = 0) {
00037
00038
00039 gPad->SetFillColor(fillCol);
00040 gPad->SetGrid();
00041 gPad->SetLogy();
00042 gPad->SetLogx();
00043
00044
00045 TMultiGraph * mg = new TMultiGraph();
00046
00047 h1->SetLineColor(3);
00048 h1->SetMarkerColor(3);
00049 h1->SetMarkerStyle(20);
00050 h1->SetLineWidth(2);
00051 mg->Add(h1);
00052
00053 h2->SetLineColor(4);
00054 h2->SetMarkerColor(4);
00055 h2->SetMarkerStyle(21);
00056 h2->SetLineWidth(2);
00057 mg->Add(h2);
00058
00059 if (h3 != 0 ) {
00060 h3->SetLineColor(2);
00061 h3->SetMarkerColor(2);
00062 h3->SetMarkerStyle(22);
00063 h3->SetLineWidth(2);
00064 mg->Add(h3);
00065 }
00066 if (h4!= 0) {
00067 h4->SetLineColor(5);
00068 h4->SetMarkerColor(5);
00069 h4->SetMarkerStyle(23);
00070 h4->SetLineWidth(2);
00071 mg->Add(h4);
00072 }
00073 if (h5!= 0) {
00074 h5->SetLineColor(6);
00075 h5->SetMarkerColor(6);
00076 h5->SetMarkerStyle(29);
00077 h5->SetLineWidth(2);
00078 mg->Add(h5);
00079 }
00080 if (h6!= 0) {
00081 h6->SetLineColor(7);
00082 h6->SetMarkerColor(7);
00083 h6->SetMarkerStyle(3);
00084 h6->SetLineWidth(2);
00085 mg->Add(h6);
00086 }
00087
00088
00089 TGraphErrors * hd = h1;
00090
00091
00092
00093 hd->GetYaxis()->SetTitleSize(0.05);
00094 hd->GetXaxis()->SetTitle("Matrix size ");
00095 hd->GetYaxis()->SetTitle("CPU Time ");
00096 hd->GetYaxis()->SetTitleOffset(0.7);
00097 hd->SetTitle("");
00098
00099
00100
00101 gStyle->SetOptStat(0);
00102
00103
00104 mg->Draw("alp");
00105
00106
00107 mg->GetXaxis()->SetLimits(1.8,32);
00108 mg->GetXaxis()->SetTitle("Matrix size ");
00109 mg->GetXaxis()->SetMoreLogLabels(1);
00110 mg->GetXaxis()->SetNoExponent(1);
00111 mg->GetYaxis()->SetTitle("CPU Time ");
00112 mg->GetYaxis()->SetTitleOffset(1.25);
00113
00114 TLegend * tleg = new TLegend(0.78, 0.25, 0.97 ,0.45);
00115 tleg->AddEntry(h1, "SMatrix", "p");
00116 tleg->AddEntry(h2, "TMatrix", "p");
00117 if (h3 != 0) tleg->AddEntry(h3, "SMatrix_sym", "p");
00118 if (h4 != 0) tleg->AddEntry(h4, "TMatrix_sym", "p");
00119 if (h5 != 0) tleg->AddEntry(h5, "HepMatrix", "p");
00120 if (h6 != 0) tleg->AddEntry(h6, "HepMatrix_sym", "p");
00121 tleg->Draw();
00122
00123 {
00124 TPaveText *pt1 = new TPaveText(0.78,0.15,0.97,0.2,"brNDC");
00125 pt1->AddText(systemName.c_str());
00126 pt1->SetBorderSize(1);
00127 pt1->Draw();
00128 pt1->SetFillColor(0);
00129 }
00130
00131 {
00132 TPaveText *pt1 = new TPaveText(0.3,0.91,0.7,0.98,"brNDC");
00133 pt1->AddText(title);
00134 pt1->SetBorderSize(1);
00135 pt1->Draw();
00136 pt1->SetFillColor(0);
00137 }
00138
00139 }
00140
00141 void GetData(std::string s,double * x, double * y, double * ey) {
00142 std::string fileName;
00143 if (systemName != "")
00144 fileName="testOperations_" + systemName + ".root";
00145 else
00146 fileName="testOperations.root";
00147
00148 TFile * f = new TFile(fileName.c_str());
00149 TProfile * h1 = (TProfile * ) f->Get(s.c_str() );
00150 if (h1 ==0) {
00151 std::cout << "Profile " << s << " not found !!! " << std::endl;
00152 return;
00153 }
00154 for (int i = 0; i < N; ++i) {
00155 y[i] = h1->GetBinContent(int(x[i] + 0.1) );
00156 ey[i] = h1->GetBinError(int(x[i] + 0.1) );
00157 }
00158 }
00159
00160
00161
00162 void matrixOperations_do(std::string type, bool clhep, bool drawSingleGraph) {
00163
00164
00165 systemName = type;
00166 std::string cName = "c1_" + type;
00167 std::string cTitle = "Matrix operations " + type;
00168
00169 TCanvas * c1 = new TCanvas(cName.c_str(),cTitle.c_str(),topX,topY,800*sqrt(2),800);
00170 topX+=20;
00171 topY+=20;
00172
00173 c1->Divide(3,2);
00174
00175 const int nb = N;
00176
00177 double x[N] = { 2.,3.,4.,5.,6,7.,10,15,20,30};
00178
00179 double smat[N];
00180 double tmat[N];
00181 double cmat[N];
00182 double ymat[N];
00183 double wmat[N];
00184 double zmat[N];
00185 double es[N];
00186 double et[N];
00187 double ec[N];
00188 double ey[N];
00189 double ew[N];
00190 double ez[N];
00191
00192
00193 c1->cd(1);
00194
00195 GetData("SMatrix_dot",x,smat,es);
00196 GetData("TMatrix_dot",x,tmat,et);
00197 if (clhep) GetData("HepMatrix_dot",x,cmat,ec);
00198 TGraphErrors * g10 = new TGraphErrors(nb,x, smat,0, es);
00199 TGraphErrors * g20 = new TGraphErrors(nb,x, tmat,0, et);
00200 TGraphErrors * g30 = 0;
00201 TGraphErrors * g40 = 0;
00202 TGraphErrors * g50 = 0;
00203 if (clhep) g50 = new TGraphErrors(nb,x, cmat,0, ec);
00204 DrawData("#vec{v} #upoint #vec{w}",g10,g20,g30,g40,g50);
00205
00206 c1->cd(2);
00207 GetData("SMatrix_M*V+",x,smat,es);
00208 GetData("TMatrix_M*V+",x,tmat,et);
00209 GetData("SMatrix_sym_M*V+",x,ymat,ey);
00210 GetData("TMatrix_sym_M*V+",x,wmat,ew);
00211 if (clhep) GetData("HepMatrix_M*V+",x,cmat,ec);
00212 if (clhep) GetData("HepMatrix_sym_M*V+",x,zmat,ez);
00213 TGraphErrors * g11 = new TGraphErrors(nb,x, smat,0,es);
00214 TGraphErrors * g21 = new TGraphErrors(nb,x, tmat,0,et);
00215 TGraphErrors * g31 = new TGraphErrors(nb,x, ymat,0,ey);
00216 TGraphErrors * g41 = new TGraphErrors(nb,x, wmat,0,ew);
00217 TGraphErrors * g51 = 0;
00218 TGraphErrors * g61 = 0;
00219 if (clhep) g51 = new TGraphErrors(nb,x, cmat,0, ec);
00220 if (clhep) g61 = new TGraphErrors(nb,x, zmat,0, ez);
00221 DrawData("M #upoint #vec{v} + #vec{w}",g11,g21,g31,g41,g51,g61);
00222
00223 c1->cd(3);
00224 GetData("SMatrix_prod",x,smat,es);
00225 GetData("TMatrix_prod",x,tmat,et);
00226 GetData("SMatrix_sym_prod",x,ymat,ey);
00227 GetData("TMatrix_sym_prod",x,wmat,ew);
00228 if (clhep) {
00229 GetData("HepMatrix_M*V+",x,cmat,ec);
00230 GetData("HepMatrix_sym_M*V+",x,zmat,ez);
00231 }
00232 TGraphErrors * g12 = new TGraphErrors(nb,x, smat,0,es);
00233 TGraphErrors * g22 = new TGraphErrors(nb,x, tmat,0,et);
00234 TGraphErrors * g32 = new TGraphErrors(nb,x, ymat,0,ey);
00235 TGraphErrors * g42 = new TGraphErrors(nb,x, wmat,0,ew);
00236 TGraphErrors * g52 = 0;
00237 TGraphErrors * g62 = 0;
00238 if (clhep) g52 = new TGraphErrors(nb,x, cmat,0, ec);
00239 if (clhep) g62 = new TGraphErrors(nb,x, zmat,0, ez);
00240 DrawData("v^{T} * M * v",g12,g22,g32,g42,g52,g62);
00241
00242
00243 c1->cd(4);
00244 GetData("SMatrix_M*M",x,smat,es);
00245 GetData("TMatrix_M*M",x,tmat,et);
00246 GetData("SMatrix_sym_M*M",x,ymat,ey);
00247 GetData("TMatrix_sym_M*M",x,wmat,ew);
00248 if (clhep) {
00249 GetData("HepMatrix_M*M",x,cmat,ec);
00250 GetData("HepMatrix_sym_M*M",x,zmat,ez);
00251 }
00252 TGraphErrors * g14 = new TGraphErrors(nb,x, smat,0,es);
00253 TGraphErrors * g24 = new TGraphErrors(nb,x, tmat,0,et);
00254 TGraphErrors * g34 = new TGraphErrors(nb,x, ymat,0,ey);
00255 TGraphErrors * g44 = new TGraphErrors(nb,x, wmat,0,ew);
00256 TGraphErrors * g54 = 0;
00257 TGraphErrors * g64 = 0;
00258 if (clhep) g54 = new TGraphErrors(nb,x, cmat,0, ec);
00259 if (clhep) g64 = new TGraphErrors(nb,x, zmat,0, ez);
00260 DrawData("A * B + C",g14,g24,g34,g44,g54,g64);
00261
00262 c1->cd(5);
00263 GetData("SMatrix_At*M*A",x,smat,es);
00264 GetData("TMatrix_At*M*A",x,tmat,et);
00265 GetData("SMatrix_sym_At*M*A",x,ymat,ey);
00266 GetData("TMatrix_sym_At*M*A",x,wmat,ew);
00267 if (clhep) {
00268 GetData("HepMatrix_At*M*A",x,cmat,ec);
00269 GetData("HepMatrix_sym_At*M*A",x,zmat,ez);
00270 }
00271 TGraphErrors * g15 = new TGraphErrors(nb,x, smat,0,es);
00272 TGraphErrors * g25 = new TGraphErrors(nb,x, tmat,0,et);
00273 TGraphErrors * g35 = new TGraphErrors(nb,x, ymat,0,ey);
00274 TGraphErrors * g45 = new TGraphErrors(nb,x, wmat,0,ew);
00275 TGraphErrors * g55 = 0;
00276 TGraphErrors * g65 = 0;
00277 if (clhep) g55 = new TGraphErrors(nb,x, cmat,0, ec);
00278 if (clhep) g65 = new TGraphErrors(nb,x, zmat,0, ez);
00279 DrawData("A * M * A^{T}",g15,g25,g35,g45,g55,g65);
00280
00281 c1->cd(6);
00282 GetData("SMatrix_inv",x,smat,es);
00283 GetData("TMatrix_inv",x,tmat,et);
00284 GetData("SMatrix_sym_inv",x,ymat,ey);
00285 GetData("TMatrix_sym_inv",x,wmat,ew);
00286 if (clhep) {
00287 GetData("HepMatrix_inv",x,cmat,ec);
00288 GetData("HepMatrix_sym_inv",x,zmat,ez);
00289 }
00290 TGraphErrors * g16 = new TGraphErrors(nb,x, smat,0,es);
00291 TGraphErrors * g26 = new TGraphErrors(nb,x, tmat,0,et);
00292 TGraphErrors * g36 = new TGraphErrors(nb,x, ymat,0,ey);
00293 TGraphErrors * g46 = new TGraphErrors(nb,x, wmat,0,ew);
00294 TGraphErrors * g56 = 0;
00295 TGraphErrors * g66 = 0;
00296 if (clhep) g56 = new TGraphErrors(nb,x, cmat,0, ec);
00297 if (clhep) g66 = new TGraphErrors(nb,x, zmat,0, ez);
00298 DrawData("A^{-1}",g16,g26,g36,g46,g56,g66);
00299
00300
00301
00302 c1->Update();
00303 c1->SetFillColor(fillCol);
00304 c1->GetFrame()->SetFillColor(21);
00305 c1->GetFrame()->SetBorderSize(12);
00306 c1->Modified();
00307
00308 if (drawSingleGraph) {
00309 std::string c2Name = "c2_" + type;
00310 TCanvas * c2 = new TCanvas(c2Name.c_str(),"Matrix Operations",200,10,700,600);
00311 DrawData("A * M * A^{T}",g15,g25,g35,g45,g55,g65);
00312 c2->SetRightMargin(0.028);
00313 c2->Update();
00314 }
00315
00316
00317 }