kalman.C

Go to the documentation of this file.
00001 #include "Riostream.h"
00002 #include "TFile.h"
00003 #include "TCanvas.h"
00004 #include "TSystem.h"
00005 #include "TPaveLabel.h"
00006 #include "TText.h"
00007 #include "TLine.h"
00008 #include "Math/SMatrix.h"
00009 
00010 #include <string>
00011 
00012 bool gUseCPUTime = false; //default use real time
00013    
00014 using namespace ROOT::Math; 
00015 void kalman_do(const char * machine,int sym, int cut);
00016 const int nx = 9;
00017 const int ny = 7;
00018 const Int_t n=nx*ny;
00019 
00020 void kalman(std::string machine = "",int sym=1,int cut =6) {
00021 
00022   cout << "loading lib smatrix" << std::endl; 
00023   gSystem->Load("libSmatrix");
00024 
00025   std::string fname = "kalman";
00026   if (machine != "" )
00027      fname = "kalman_" + machine;
00028  
00029      
00030   kalman_do(fname.c_str(),sym,cut);
00031 //   kalman_do("kalman_slc3_5.10b_cand",sym,cut);
00032 //   kalman_do("kalman_win32_5.10b_cand",sym,cut);
00033 //   kalman_do("kalman_macg5_5.10b_cand",sym,cut);
00034 }   
00035 
00036 int read_data(const char *  machine, double * s, double * ss, double * t) { 
00037 
00038   char filename[100];
00039   sprintf(filename,"%s.root",machine);
00040   TFile * file = new TFile(filename,machine); 
00041   if (file == 0) return -1; 
00042   SMatrix<double,9,7,ROOT::Math::MatRepStd<double,9,7> > *ms; 
00043   SMatrix<double,9,7,ROOT::Math::MatRepStd<double,9,7> > *mss; 
00044   SMatrix<double,9,7,ROOT::Math::MatRepStd<double,9,7> > *mt; 
00045   if (!gUseCPUTime) {
00046      file->GetObject("SMatrix",ms);   
00047      file->GetObject("SMatrix_sym",mss);   
00048      file->GetObject("TMatrix",mt); 
00049   }
00050   else { 
00051      // use CPU time (the object have a name with _2)
00052      file->GetObject("SMatrix_2",ms);   
00053      file->GetObject("SMatrix_sym_2",mss);   
00054      file->GetObject("TMatrix_2",mt); 
00055   }
00056   if (ms == 0 || mss == 0 || mt == 0) return -1;
00057   for (int i=0; i<n; ++i){
00058     s[i]  = ms->apply(i);
00059     ss[i] = mss->apply(i);
00060     t[i]  = mt->apply(i);
00061   }
00062 
00063   file->Close(); 
00064   delete file; 
00065   return 0; 
00066 }
00067   
00068 
00069 
00070 void kalman_do(const char *machine,int sym, int cut) {
00071    //testing SMatrix[nx,ny]  2<=nx<=10,   2<=ny<<8
00072    //sym =0  shade cases where SMatrix is faster than TMatrix
00073    //sym =1  shade cases where SMatrix_Sym is faster than TMatrix
00074                   
00075       
00076    static Int_t xtop = 0, ytop = 0;
00077    xtop += 10; ytop += 10;
00078    TCanvas *c1 = 0;
00079    char tmachine[50];
00080    
00081    double s[n]; 
00082    double ss[n]; 
00083    double t[n]; 
00084  
00085    sprintf(tmachine,"%s",machine);
00086    c1 = new TCanvas(machine,machine,xtop,ytop,800,650);
00087    if (read_data(machine,s,ss,t)) return;
00088  
00089    c1->SetHighLightColor(19);
00090    int i,j;
00091    double xmin = 0.1;
00092    double xmax = 0.9;
00093    double ymin = 0.2;
00094    double ymax = 0.9;
00095    double dx = (xmax-xmin)/nx;
00096    double dy = (ymax-ymin)/ny;
00097    TPaveLabel *pl=0;
00098    TBox box;
00099    if (sym == 0) box.SetFillColor(kBlack);
00100    else          box.SetFillColor(kBlue);
00101    box.SetFillStyle(3002);
00102    for (i=0;i<nx;i++) {
00103      for (j=0;j<ny;j++) {
00104          if (sym == 0) {
00105             if (s[ny*i+j] > t[ny*i+j]) continue;
00106             box.DrawBox(xmin+i*dx,ymax-(j+1)*dy,xmin+(i+1)*dx,ymax-j*dy);
00107             pl = new TPaveLabel(xmin+5*dx,0.025,xmax,0.075,"SMatrix better than TMatrix","brNDC");
00108          } else {
00109             if (ss[ny*i+j] > t[ny*i+j]) continue;
00110             box.DrawBox(xmin+i*dx,ymax-(j+1)*dy,xmin+(i+1)*dx,ymax-j*dy);
00111             pl = new TPaveLabel(xmin+5*dx,0.025,xmax,0.075,"SMatrix_Sym better than TMatrix","brNDC");
00112          }
00113          pl->SetFillStyle(box.GetFillStyle());
00114          pl->SetFillColor(box.GetFillColor());
00115          pl->Draw();
00116       }
00117    }
00118 
00119 
00120    TLine line;
00121    TText tss,ts,tt;
00122    tss.SetTextColor(kBlue);
00123    tss.SetTextSize(0.031);
00124    ts.SetTextColor(kBlack);
00125    ts.SetTextSize(0.031);
00126    tt.SetTextColor(kRed);
00127    tt.SetTextSize(0.031);
00128    char text[10];
00129    ts.SetTextAlign(22);
00130    for (i=0;i<=nx;i++) {
00131       line.DrawLine(xmin+i*dx,ymin,xmin+i*dx,ymax);
00132       if(i==nx) continue;
00133       sprintf(text,"%d",i+2);
00134       ts.DrawText(xmin+(i+0.5)*dx,ymax+0.1*dy,text);
00135    }
00136    ts.SetTextAlign(32);
00137    for (i=0;i<=ny;i++) {
00138       line.DrawLine(xmin,ymax-i*dy,xmax,ymax-i*dy);
00139       if(i==ny) continue;
00140       sprintf(text,"%d",i+2);
00141       ts.DrawText(xmin-0.1*dx,ymax-(i+0.5)*dy,text);
00142    }
00143    tss.SetTextAlign(22);
00144    ts.SetTextAlign(22);
00145    tt.SetTextAlign(22);
00146    double sums1  = 0; 
00147    double sumss1 = 0; 
00148    double sumt1  = 0; 
00149    double sums2  = 0; 
00150    double sumss2 = 0; 
00151    double sumt2  = 0; 
00152    for (i=0;i<nx;i++) {
00153      for (j=0;j<ny;j++) {
00154          sprintf(text,"%6.2f",ss[ny*i+j]);
00155          tss.DrawText(xmin+(i+0.5)*dx,ymax -(j+0.22)*dy,text);
00156          sprintf(text,"%6.2f",s[ny*i+j]);
00157          ts.DrawText(xmin+(i+0.5)*dx,ymax -(j+0.5)*dy,text);
00158          sprintf(text,"%6.2f",t[ny*i+j]);
00159          tt.DrawText(xmin+(i+0.5)*dx,ymax -(j+0.78)*dy,text);
00160          if ( i <=cut-2 && j <=cut-2) { 
00161             sums1  += s[ny*i+j];
00162             sumss1 += ss[ny*i+j];
00163             sumt1  += t[ny*i+j];
00164          }
00165          else { 
00166             sums2  += s[ny*i+j];
00167             sumss2 += ss[ny*i+j];
00168             sumt2  += t[ny*i+j];
00169          }
00170       }
00171    }
00172    tss.DrawText(xmin+0.5*dx,0.05,"SMatrix_Sym");
00173    ts.DrawText (xmin+2.5*dx,0.05,"SMatrix");
00174    tt.DrawText (xmin+4*dx,0.05,"TMatrix");
00175    ts.SetTextSize(0.05);
00176    char title[100];
00177    sprintf(title,"TestKalman [nx,ny] : %s",tmachine);
00178    ts.DrawText(0.5,0.96,title);
00179 
00180 
00181    // summary boxes 
00182 
00183    double ylow = 0.082;
00184 
00185    tt.SetTextAlign(22);
00186    tss.SetTextColor(kBlue);
00187    tss.SetTextSize(0.031);
00188    ts.SetTextColor(kBlack);
00189    ts.SetTextSize(0.031);
00190    tt.SetTextColor(kRed);
00191    tt.SetTextSize(0.031);
00192 
00193    TText tl;
00194    tl.SetTextColor(kBlack);
00195    tl.SetTextSize(0.04);
00196    tt.SetTextAlign(22);
00197 
00198    i = 2;
00199    sprintf(text,"N1,N2 <= %d",cut);
00200    tl.DrawText (xmin+i*dx-0.15,ylow+0.04,text);
00201    if (sym == 0) { 
00202      if (sums1 <= sumt1) 
00203        box.DrawBox(xmin+i*dx,ylow,xmin+(i+1)*dx,ylow+dy);
00204    }  
00205    else {  
00206      if (sumss1 <= sumt1) 
00207        box.DrawBox(xmin+i*dx,ylow,xmin+(i+1)*dx,ylow+dy);
00208    }
00209    sprintf(text,"%6.2f",sumss1);
00210    tss.DrawText(xmin+(i+0.5)*dx,ylow+0.078,text);
00211    sprintf(text,"%6.2f",sums1);
00212    ts.DrawText(xmin+(i+0.5)*dx,ylow+0.05,text);
00213    sprintf(text,"%6.2f",sumt1);
00214    tt.DrawText(xmin+(i+0.5)*dx,ylow+0.022,text);
00215 
00216 
00217    i = 5; 
00218    sprintf(text,"N1,N2 >  %d",cut);
00219    tl.DrawText (xmin+i*dx-0.15,ylow+0.04,text);
00220    if (sym == 0) { 
00221      if (sums2 <= sumt2) 
00222        box.DrawBox(xmin+i*dx,ylow,xmin+(i+1)*dx,ylow+dy);
00223    }  
00224    else {  
00225      if (sumss2 <= sumt2) 
00226        box.DrawBox(xmin+i*dx,ylow,xmin+(i+1)*dx,ylow+dy);
00227    }
00228    sprintf(text,"%6.2f",sumss2);
00229    tss.DrawText(xmin+(i+0.5)*dx,ylow+0.078,text);
00230    sprintf(text,"%6.2f",sums2);
00231    ts.DrawText(xmin+(i+0.5)*dx,ylow+0.05,text);
00232    sprintf(text,"%6.2f",sumt2);
00233    tt.DrawText(xmin+(i+0.5)*dx,ylow+0.022,text);
00234 
00235    i= 8; 
00236    tl.DrawText (xmin+i*dx-0.15,ylow+0.04,"All N1,N2 ");
00237    if (sym == 0) { 
00238      if (sums1+sums2 <= sumt1+sumt2) 
00239        box.DrawBox(xmin+i*dx,ylow,xmin+(i+1)*dx,ylow+dy);
00240    }  
00241    else {  
00242      if (sumss1+sumss2 <= sumt1+sumt2) 
00243        box.DrawBox(xmin+i*dx,ylow,xmin+(i+1)*dx,ylow+dy);
00244    }
00245    sprintf(text,"%6.2f",sumss1+sumss2);
00246    tss.DrawText(xmin+(i+0.5)*dx,ylow+0.078,text);
00247    sprintf(text,"%6.2f",sums1+sums2);
00248    ts.DrawText(xmin+(i+0.5)*dx,ylow+0.05,text);
00249    sprintf(text,"%6.2f",sumt1+sumt2);
00250    tt.DrawText(xmin+(i+0.5)*dx,ylow+0.022,text);
00251 }
00252         

Generated on Tue Jul 5 14:43:10 2011 for ROOT_528-00b_version by  doxygen 1.5.1