ROOTPWA
plotGui.C
Go to the documentation of this file.
1 //
2 // Author: Ilka Antcheva 1/12/2006
3 
4 // This macro gives an example of how to create a list box
5 // and how to set and use its multiple selection feature.
6 // To run it do either:
7 // .x listBox.C
8 // .x listBox.C++
9 
10 #include <TApplication.h>
11 #include <TGClient.h>
12 #include <TGButton.h>
13 #include <TGListBox.h>
14 #include <TList.h>
15 #include <TFile.h>
16 #include <TTree.h>
17 #include <TAxis.h>
18 #include <TCanvas.h>
19 #include <TGraphErrors.h>
20 
21 #include "fitResult.h"
22 #include <string>
23 #include <vector>
24 #include <iostream>
25 #include <limits>
26 //#include <stringstream>
27 
28 using namespace rpwa;
29 using namespace std;
30 
31 class MyMainFrame : public TGMainFrame {
32 
33 private:
34  TGListBox *fListBox;
35  TGListBox *fListBox2;
36  TGCheckButton *fCheckMulti;
37  TList *fSelected;
38  TTree *fTree;
39  std::vector<std::string> fwavenames;
40 
41 public:
42  MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h, TTree* tree);
43  virtual ~MyMainFrame();
44  void DoExit();
45  void DoSelect();
46  void HandleButtons();
47  void PrintSelected();
48 
49  ClassDef(MyMainFrame, 0)
50 };
51 
53 {
54  Printf("Slot DoSelect()");
55 }
56 
58 {
59  Printf("Slot DoExit()");
60  gApplication->Terminate(0);
61 }
62 
63 MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h, TTree* tree) :
64  TGMainFrame(p, w, h)
65 {
66 
67  // analyze tree
68  fTree=tree;
69  //tree->Print();
70  fitResult* res=0;//new fitResult();
71  string branchname("fitResult_v2");
72  if(tree->FindBranch(branchname.c_str())==NULL){
73  cerr << "Invalid branch ."<<branchname<<endl;
74  throw;
75  }
76 
77  tree->SetBranchAddress(branchname.c_str(),&res);
78  cout << "Entries: " <<tree->GetEntries() << endl;
79  tree->GetEntry(1);
80  // get list of waves
81 
82 
83 
84  fwavenames=res->waveNames();
85 
86 
87 
88  // Create main frame
89 
90  fListBox = new TGListBox(this, 89);
91  fListBox2 = new TGListBox(this, 88);
92  fSelected = new TList;
93 
94  for (int i = 0; i < fwavenames.size(); ++i) {
95  cout << fwavenames[i] << endl;
96  fListBox->AddEntry(fwavenames[i].c_str(), i);
97  fListBox2->AddEntry(fwavenames[i].c_str(), i);
98  }
99  fListBox->Resize(400,250);
100  fListBox2->Resize(400,250);
101 
102  AddFrame(fListBox, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 5, 5, 5, 5));
103  AddFrame(fListBox2, new TGLayoutHints(kLHintsTop | kLHintsRight| kLHintsExpandX, 5, 5, 5, 5));
104 
105 
106 
107  fCheckMulti = new TGCheckButton(this, "&Mutliple selection", 10);
108  AddFrame(fCheckMulti, new TGLayoutHints(kLHintsTop | kLHintsLeft,
109  5, 5, 5, 5));
110  fCheckMulti->Connect("Clicked()", "MyMainFrame", this, "HandleButtons()");
111  // Create a horizontal frame containing button(s)
112  TGHorizontalFrame *hframe = new TGHorizontalFrame(this, 400, 20, kFixedWidth);
113  TGTextButton *show = new TGTextButton(hframe, "&Show");
114  show->SetToolTipText("Click here to print the selection you made");
115  show->Connect("Pressed()", "MyMainFrame", this, "PrintSelected()");
116  hframe->AddFrame(show, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
117  TGTextButton *exit = new TGTextButton(hframe, "&Exit ");
118  exit->Connect("Pressed()", "MyMainFrame", this, "DoExit()");
119  hframe->AddFrame(exit, new TGLayoutHints(kLHintsExpandX, 5, 5, 3, 4));
120  AddFrame(hframe, new TGLayoutHints(kLHintsExpandX, 2, 2, 5, 1));
121 
122  // Set a name to the main frame
123  SetWindowName("List Box");
124  MapSubwindows();
125 
126  // Initialize the layout algorithm via Resize()
127  Resize(GetDefaultSize());
128 
129  // Map main frame
130  MapWindow();
131  fListBox->Select(0);
132  fListBox2->Select(0);
133 }
134 
136 {
137  // Clean up main frame...
138  Cleanup();
139  if (fSelected) {
140  fSelected->Delete();
141  delete fSelected;
142  }
143 }
144 
146 {
147  // Handle check button.
148  Int_t id;
149  TGButton *btn = (TGButton *) gTQSender;
150  id = btn->WidgetId();
151 
152  printf("HandleButton: id = %d\n", id);
153 
154  //if (id == 10)
155  // fListBox->SetMultipleSelections(fCheckMulti->GetState());
156 }
157 
158 
160 {
161  // Writes selected entries in TList if multiselection.
162  string w1=fwavenames[fListBox->GetSelected()];
163  string w2=fwavenames[fListBox2->GetSelected()];
164  cout << w1 << endl;
165  cout << w2 << endl;
166  // Produce plots
167  unsigned int n=fTree->GetEntries();
168 
169  Int_t colour=1;
170  double binwidth=0.060;
171 
172  TGraphErrors* gph = new TGraphErrors(n*3);
173  stringstream graphName;
174  graphName << "PHI"<<w1<<"---"<<"PHI"<<w2;
175  cout << "creating graph " << graphName.str() << endl;
176  gph->SetName (graphName.str().c_str());
177  gph->SetTitle(graphName.str().c_str());
178  gph->SetMarkerStyle(21);
179  gph->SetMarkerSize(0.5);
180  gph->SetMarkerColor(colour);
181  gph->SetLineColor(colour);
182  TGraphErrors* gRe = new TGraphErrors(n);
183  graphName.str("");
184  graphName.clear();
185  graphName << "RE_"<<w1<<"---"<<""<<w2;
186  cout << "creating graph " << graphName.str() << endl;
187  gRe->SetName (graphName.str().c_str());
188  gRe->SetTitle(graphName.str().c_str());
189  gRe->SetMarkerStyle(21);
190  gRe->SetMarkerSize(0.5);
191  gRe->SetMarkerColor(colour);
192  gRe->SetLineColor(colour);
193 
194  TGraphErrors* gIm = new TGraphErrors(n);
195  graphName.str("");
196  graphName.clear();
197  graphName << "IM_"<<w1<<"---"<<""<<w2;
198  cout << "creating graph " << graphName.str() << endl;
199  gIm->SetName (graphName.str().c_str());
200  gIm->SetTitle(graphName.str().c_str());
201  gIm->SetMarkerStyle(21);
202  gIm->SetMarkerSize(0.5);
203  gIm->SetMarkerColor(colour);
204  gIm->SetLineColor(colour);
205 
206  TGraphErrors* g1 = new TGraphErrors(n);
207  graphName.str("");
208  graphName.clear();
209  graphName<<"g"<<w1;
210  g1->SetName (graphName.str().c_str());
211  g1->SetTitle(graphName.str().c_str());
212  g1->SetMarkerStyle(21);
213  g1->SetMarkerSize(0.5);
214  TGraphErrors* g2 = new TGraphErrors(n);
215  graphName.str("");
216  graphName.clear();
217  graphName<<"g"<<w2;
218  g2->SetName (graphName.str().c_str());
219  g2->SetTitle(graphName.str().c_str());
220  g2->SetMarkerStyle(21);
221  g2->SetMarkerSize(0.5);
222 
223 
224 
225 
226  fitResult* result=0;
227  fTree->SetBranchAddress("fitResult_v2",&result);
228 
229 
230 
231  for(unsigned int i=0;i<n;++i){
232  fTree->GetEntry(i);
233 
234  if(!result->converged())continue;
235  if(!result->hasHessian())continue;
236 
237  double intensity1=result->intensity(w1.c_str());
238  if((numeric_limits<double>::has_infinity && intensity1 == numeric_limits<double>::infinity()) || intensity1!=intensity1)continue;
239 
240  g1->SetPoint(i,
241  result->massBinCenter()*0.001,
242  intensity1);
243  g1->SetPointError(i,
244  binwidth*0.5,
245  result->intensityErr(w1.c_str()));
246 
247  double intensity2=result->intensity(w2.c_str());
248  if((numeric_limits<double>::has_infinity && intensity2 == numeric_limits<double>::infinity()) || intensity2!=intensity2)continue;
249 
250  g2->SetPoint(i,
251  result->massBinCenter()*0.001,
252  intensity2);
253 
254  g2->SetPointError(i,
255  binwidth*0.5,
256  result->intensityErr(w2.c_str()));
257 
258 
259  double ph=result->phase(w1.c_str(),w2.c_str());
260  double pherr=result->phaseErr(w1.c_str(),w2.c_str());
261  // check if we should make a transformation by 2pi
262  // this is needed because of cyclical variable phi
263  if(i>11){
264  double mpre;
265  double phpre;
266  gph->GetPoint(i-3,mpre,phpre);
267  double diff1=fabs(ph-phpre);
268  double diff2=fabs(ph+360-phpre);
269  double diff3=fabs(ph-360-phpre);
270  if(diff2<diff1 && diff2<diff3)ph+=360;
271  else if(diff3<diff1 && diff3<diff2)ph-=360;
272  }
273 
274 
275 
276  gph->SetPoint(i*3,
277  result->massBinCenter()*0.001,
278  ph);
279  gph->SetPointError(i*3,
280  binwidth*0.5,
281  pherr);
282 
283  // add point +- 360 degree
284  gph->SetPoint(i*3+1,
285  result->massBinCenter()*0.001,
286  ph+360);
287  gph->SetPointError(i*3+1,
288  binwidth*0.5,
289  pherr);
290 
291  gph->SetPoint(i*3+2,
292  result->massBinCenter()*0.001,
293  ph-360);
294  gph->SetPointError(i*3+2,
295  binwidth*0.5,
296  pherr);
297 
298  unsigned int wi1=result->waveIndex(w1);
299  unsigned int wi2=result->waveIndex(w2);
300  complex<double> rho=result->spinDensityMatrixElem(wi1,wi2);
301  TMatrixT<double> rhoCov=result->spinDensityMatrixElemCov(wi1,wi2);
302  gRe->SetPoint(i,
303  result->massBinCenter()*0.001,
304  rho.real());
305  gRe->SetPointError(i,
306  binwidth*0.5,
307  sqrt(rhoCov[0][0]));
308 
309 
310  gIm->SetPoint(i,
311  result->massBinCenter()*0.001,
312  rho.imag());
313 
314  gIm->SetPointError(i,
315  binwidth*0.5,
316  sqrt(rhoCov[1][1]));
317  }// end loop over bins
318 
319 
320  // plot graphs
321 
322  TCanvas*c=new TCanvas("c","c",10,10,1200,800);
323  c->Divide(2,3);
324  c->cd(1);
325  gph->Draw("AP");
326  gph->GetXaxis()->SetTitle("5#pi mass (GeV/c^2)");
327  gph->GetYaxis()->SetTitle("Phase difference");
328  gph->GetYaxis()->SetRangeUser(-270,270);
329  c->cd(3);
330  g1->Draw("AP");
331  g1->GetXaxis()->SetTitle("5#pi mass (GeV/c^2)");
332  g1->GetYaxis()->SetTitle("Intensity");
333  c->cd(5);
334  g2->Draw("AP");
335  g2->GetXaxis()->SetTitle("5#pi mass (GeV/c^2)");
336  g2->GetYaxis()->SetTitle("Intensity");
337 
338  c->cd(2);
339  gRe->Draw("AP");
340  gRe->GetXaxis()->SetTitle("5#pi mass (GeV/c^2)");
341  gRe->GetYaxis()->SetTitle("Re(#rho_{ij})");
342  c->cd(4);
343  gIm->Draw("AP");
344  gIm->GetXaxis()->SetTitle("5#pi mass (GeV/c^2)");
345  gIm->GetYaxis()->SetTitle("Im(#rho_{ij})");
346 
347 }
348 
349 void plotGui(TString infilename)
350 {
351 
352  // load fitResult tree
353  TFile* infile=TFile::Open(infilename,"READ");
354  if(infile==NULL){
355  cerr << "File " << infilename << " not found!"<< endl;
356  return;
357  }
358  TTree* pwa=(TTree*)infile->FindObjectAny("pwa");
359  if(pwa==NULL){
360  cerr << "Tree not found!"<< endl;
361  return;
362  }
363 
364  // Popup the GUI...
365  new MyMainFrame(gClient->GetRoot(), 20, 20, pwa);
366 }