Logo ROOT   6.10/09
Reference Guide
kalman.C
Go to the documentation of this file.
1 #include "Riostream.h"
2 #include "TFile.h"
3 #include "TCanvas.h"
4 #include "TSystem.h"
5 #include "TPaveLabel.h"
6 #include "TText.h"
7 #include "TLine.h"
8 #include "Math/SMatrix.h"
9 
10 #include <string>
11 
12 bool gUseCPUTime = false; //default use real time
13 
14 using namespace ROOT::Math;
15 void kalman_do(const char * machine,int sym, int cut);
16 const int nx = 9;
17 const int ny = 7;
18 const Int_t n=nx*ny;
19 
20 void kalman(std::string machine = "",int sym=1,int cut =6) {
21 
22  cout << "loading lib smatrix" << std::endl;
23  gSystem->Load("libSmatrix");
24 
25  std::string fname = "kalman";
26  if (machine != "" )
27  fname = "kalman_" + machine;
28 
29 
30  kalman_do(fname.c_str(),sym,cut);
31  // kalman_do("kalman_slc3_5.10b_cand",sym,cut);
32  // kalman_do("kalman_win32_5.10b_cand",sym,cut);
33  // kalman_do("kalman_macg5_5.10b_cand",sym,cut);
34 }
35 
36 int read_data(const char * machine, double * s, double * ss, double * t) {
37 
38  char filename[100];
39  sprintf(filename,"%s.root",machine);
40  TFile * file = new TFile(filename,machine);
41  if (file == 0) return -1;
45  if (!gUseCPUTime) {
46  file->GetObject("SMatrix",ms);
47  file->GetObject("SMatrix_sym",mss);
48  file->GetObject("TMatrix",mt);
49  }
50  else {
51  // use CPU time (the object have a name with _2)
52  file->GetObject("SMatrix_2",ms);
53  file->GetObject("SMatrix_sym_2",mss);
54  file->GetObject("TMatrix_2",mt);
55  }
56  if (ms == 0 || mss == 0 || mt == 0) return -1;
57  for (int i=0; i<n; ++i){
58  s[i] = ms->apply(i);
59  ss[i] = mss->apply(i);
60  t[i] = mt->apply(i);
61  }
62 
63  file->Close();
64  delete file;
65  return 0;
66 }
67 
68 
69 
70 void kalman_do(const char *machine,int sym, int cut) {
71  //testing SMatrix[nx,ny] 2<=nx<=10, 2<=ny<<8
72  //sym =0 shade cases where SMatrix is faster than TMatrix
73  //sym =1 shade cases where SMatrix_Sym is faster than TMatrix
74 
75 
76  static Int_t xtop = 0, ytop = 0;
77  xtop += 10; ytop += 10;
78  TCanvas *c1 = 0;
79  char tmachine[50];
80 
81  double s[n];
82  double ss[n];
83  double t[n];
84 
85  sprintf(tmachine,"%s",machine);
86  c1 = new TCanvas(machine,machine,xtop,ytop,800,650);
87  if (read_data(machine,s,ss,t)) return;
88 
89  c1->SetHighLightColor(19);
90  int i,j;
91  double xmin = 0.1;
92  double xmax = 0.9;
93  double ymin = 0.2;
94  double ymax = 0.9;
95  double dx = (xmax-xmin)/nx;
96  double dy = (ymax-ymin)/ny;
97  TPaveLabel *pl=0;
98  TBox box;
99  if (sym == 0) box.SetFillColor(kBlack);
100  else box.SetFillColor(kBlue);
101  box.SetFillStyle(3002);
102  for (i=0;i<nx;i++) {
103  for (j=0;j<ny;j++) {
104  if (sym == 0) {
105  if (s[ny*i+j] > t[ny*i+j]) continue;
106  box.DrawBox(xmin+i*dx,ymax-(j+1)*dy,xmin+(i+1)*dx,ymax-j*dy);
107  pl = new TPaveLabel(xmin+5*dx,0.025,xmax,0.075,"SMatrix better than TMatrix","brNDC");
108  } else {
109  if (ss[ny*i+j] > t[ny*i+j]) continue;
110  box.DrawBox(xmin+i*dx,ymax-(j+1)*dy,xmin+(i+1)*dx,ymax-j*dy);
111  pl = new TPaveLabel(xmin+5*dx,0.025,xmax,0.075,"SMatrix_Sym better than TMatrix","brNDC");
112  }
113  pl->SetFillStyle(box.GetFillStyle());
114  pl->SetFillColor(box.GetFillColor());
115  pl->Draw();
116  }
117  }
118 
119 
120  TLine line;
121  TText tss,ts,tt;
122  tss.SetTextColor(kBlue);
123  tss.SetTextSize(0.031);
124  ts.SetTextColor(kBlack);
125  ts.SetTextSize(0.031);
126  tt.SetTextColor(kRed);
127  tt.SetTextSize(0.031);
128  char text[20];
129  ts.SetTextAlign(22);
130  for (i=0;i<=nx;i++) {
131  line.DrawLine(xmin+i*dx,ymin,xmin+i*dx,ymax);
132  if(i==nx) continue;
133  sprintf(text,"%d",i+2);
134  ts.DrawText(xmin+(i+0.5)*dx,ymax+0.1*dy,text);
135  }
136  ts.SetTextAlign(32);
137  for (i=0;i<=ny;i++) {
138  line.DrawLine(xmin,ymax-i*dy,xmax,ymax-i*dy);
139  if(i==ny) continue;
140  sprintf(text,"%d",i+2);
141  ts.DrawText(xmin-0.1*dx,ymax-(i+0.5)*dy,text);
142  }
143  tss.SetTextAlign(22);
144  ts.SetTextAlign(22);
145  tt.SetTextAlign(22);
146  double sums1 = 0;
147  double sumss1 = 0;
148  double sumt1 = 0;
149  double sums2 = 0;
150  double sumss2 = 0;
151  double sumt2 = 0;
152  for (i=0;i<nx;i++) {
153  for (j=0;j<ny;j++) {
154  sprintf(text,"%6.2f",ss[ny*i+j]);
155  tss.DrawText(xmin+(i+0.5)*dx,ymax -(j+0.22)*dy,text);
156  sprintf(text,"%6.2f",s[ny*i+j]);
157  ts.DrawText(xmin+(i+0.5)*dx,ymax -(j+0.5)*dy,text);
158  sprintf(text,"%6.2f",t[ny*i+j]);
159  tt.DrawText(xmin+(i+0.5)*dx,ymax -(j+0.78)*dy,text);
160  if ( i <=cut-2 && j <=cut-2) {
161  sums1 += s[ny*i+j];
162  sumss1 += ss[ny*i+j];
163  sumt1 += t[ny*i+j];
164  }
165  else {
166  sums2 += s[ny*i+j];
167  sumss2 += ss[ny*i+j];
168  sumt2 += t[ny*i+j];
169  }
170  }
171  }
172  tss.DrawText(xmin+0.5*dx,0.05,"SMatrix_Sym");
173  ts.DrawText (xmin+2.5*dx,0.05,"SMatrix");
174  tt.DrawText (xmin+4*dx,0.05,"TMatrix");
175  ts.SetTextSize(0.05);
176  char title[100];
177  sprintf(title,"TestKalman [nx,ny] : %s",tmachine);
178  ts.DrawText(0.5,0.96,title);
179 
180 
181  // summary boxes
182 
183  double ylow = 0.082;
184 
185  tt.SetTextAlign(22);
186  tss.SetTextColor(kBlue);
187  tss.SetTextSize(0.031);
188  ts.SetTextColor(kBlack);
189  ts.SetTextSize(0.031);
190  tt.SetTextColor(kRed);
191  tt.SetTextSize(0.031);
192 
193  TText tl;
194  tl.SetTextColor(kBlack);
195  tl.SetTextSize(0.04);
196  tt.SetTextAlign(22);
197 
198  i = 2;
199  sprintf(text,"N1,N2 <= %d",cut);
200  tl.DrawText (xmin+i*dx-0.15,ylow+0.04,text);
201  if (sym == 0) {
202  if (sums1 <= sumt1)
203  box.DrawBox(xmin+i*dx,ylow,xmin+(i+1)*dx,ylow+dy);
204  }
205  else {
206  if (sumss1 <= sumt1)
207  box.DrawBox(xmin+i*dx,ylow,xmin+(i+1)*dx,ylow+dy);
208  }
209  sprintf(text,"%6.2f",sumss1);
210  tss.DrawText(xmin+(i+0.5)*dx,ylow+0.078,text);
211  sprintf(text,"%6.2f",sums1);
212  ts.DrawText(xmin+(i+0.5)*dx,ylow+0.05,text);
213  sprintf(text,"%6.2f",sumt1);
214  tt.DrawText(xmin+(i+0.5)*dx,ylow+0.022,text);
215 
216 
217  i = 5;
218  sprintf(text,"N1,N2 > %d",cut);
219  tl.DrawText (xmin+i*dx-0.15,ylow+0.04,text);
220  if (sym == 0) {
221  if (sums2 <= sumt2)
222  box.DrawBox(xmin+i*dx,ylow,xmin+(i+1)*dx,ylow+dy);
223  }
224  else {
225  if (sumss2 <= sumt2)
226  box.DrawBox(xmin+i*dx,ylow,xmin+(i+1)*dx,ylow+dy);
227  }
228  sprintf(text,"%6.2f",sumss2);
229  tss.DrawText(xmin+(i+0.5)*dx,ylow+0.078,text);
230  sprintf(text,"%6.2f",sums2);
231  ts.DrawText(xmin+(i+0.5)*dx,ylow+0.05,text);
232  sprintf(text,"%6.2f",sumt2);
233  tt.DrawText(xmin+(i+0.5)*dx,ylow+0.022,text);
234 
235  i= 8;
236  tl.DrawText (xmin+i*dx-0.15,ylow+0.04,"All N1,N2 ");
237  if (sym == 0) {
238  if (sums1+sums2 <= sumt1+sumt2)
239  box.DrawBox(xmin+i*dx,ylow,xmin+(i+1)*dx,ylow+dy);
240  }
241  else {
242  if (sumss1+sumss2 <= sumt1+sumt2)
243  box.DrawBox(xmin+i*dx,ylow,xmin+(i+1)*dx,ylow+dy);
244  }
245  sprintf(text,"%6.2f",sumss1+sumss2);
246  tss.DrawText(xmin+(i+0.5)*dx,ylow+0.078,text);
247  sprintf(text,"%6.2f",sums1+sums2);
248  ts.DrawText(xmin+(i+0.5)*dx,ylow+0.05,text);
249  sprintf(text,"%6.2f",sumt1+sumt2);
250  tt.DrawText(xmin+(i+0.5)*dx,ylow+0.022,text);
251 }
252 
const int nx
Definition: kalman.C:16
float xmin
Definition: THbookFile.cxx:93
virtual TBox * DrawBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Draw this box with new coordinates.
Definition: TBox.cxx:189
TLine * line
return c1
Definition: legend1.C:41
Definition: Rtypes.h:56
float ymin
Definition: THbookFile.cxx:93
Create a Box.
Definition: TBox.h:24
Definition: Rtypes.h:55
virtual TLine * DrawLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Draw this line with new coordinates.
Definition: TLine.cxx:93
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Definition: TSystem.cxx:1825
int Int_t
Definition: RtypesCore.h:41
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Definition: TAttFill.h:39
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition: fillpatterns.C:1
void kalman(std::string machine="", int sym=1, int cut=6)
Definition: kalman.C:20
SMatrix: a generic fixed size D1 x D2 Matrix class.
TText * tt
Definition: textangle.C:16
const int ny
Definition: kalman.C:17
Base class for several text objects.
Definition: TText.h:23
int read_data(const char *machine, double *s, double *ss, double *t)
Definition: kalman.C:36
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
Definition: TAttText.h:41
A Pave (see TPave) with a text centered in the Pave.
Definition: TPaveLabel.h:20
float ymax
Definition: THbookFile.cxx:93
R__EXTERN TSystem * gSystem
Definition: TSystem.h:539
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:37
const Int_t n
Definition: kalman.C:18
A simple line.
Definition: TLine.h:23
void kalman_do(const char *machine, int sym, int cut)
Definition: kalman.C:70
float xmax
Definition: THbookFile.cxx:93
The Canvas class.
Definition: TCanvas.h:31
virtual void Draw(Option_t *option="")
Draw this pavelabel with its current attributes.
Definition: TPaveLabel.cxx:77
T apply(unsigned int i) const
access the parse tree with the index starting from zero and following the C convention for the order ...
Definition: SMatrix.icc:621
TText * text
bool gUseCPUTime
Definition: kalman.C:12
virtual Color_t GetFillColor() const
Return the fill area color.
Definition: TAttFill.h:30
Definition: file.py:1
virtual TText * DrawText(Double_t x, Double_t y, const char *text)
Draw this text with new coordinates.
Definition: TText.cxx:176
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition: TAttText.h:43
Definition: Rtypes.h:56
virtual Style_t GetFillStyle() const
Return the fill area style.
Definition: TAttFill.h:31
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition: TAttText.h:46
#define sym(otri1, otri2)
Definition: triangle.c:932
void SetHighLightColor(Color_t col)
Definition: TCanvas.h:207