GUI.C 4.66 KB
Newer Older
1
2
3
4
#include "GUI.h"
#include "TApplication.h"
#include "TPolyLine3D.h"
#include "TSystem.h"
5
#include "TROOT.h"
6
7
8
9

GUI::GUI(bool debugging)
: Algorithm("GUI"){
  debug = debugging;
Daniel Hynds's avatar
Daniel Hynds committed
10
  updateNumber = 1;
11
12
}

13
void startDisplay(void* gui){
14
  
15
16
17
  // Make the TApplicaitons to allow canvases to stay open (for some reason we need two instances for it to work...)
  TApplication* app1 = new TApplication("example",0, 0);
  TApplication* app2 = new TApplication("example",0, 0);
18
  
19
20
21
22
23
24
  // Create the new canvases
  double nDetectors = ((GUI*)gui)->nDetectors;
  ((GUI*)gui)->trackCanvas = new TCanvas("TrackCanvas","Track canvas");
//  ((GUI*)gui)->trackCanvas->Divide();
  ((GUI*)gui)->hitmapCanvas = new TCanvas("HitMapCanvas","Hit map canvas");
  ((GUI*)gui)->hitmapCanvas->Divide(ceil(nDetectors/2.),2);
25
26
  ((GUI*)gui)->globalHitmapCanvas = new TCanvas("GlobalHitmapCanvas","Global hit map canvas");
  ((GUI*)gui)->globalHitmapCanvas->Divide(ceil(nDetectors/2.),2);
27
28
  ((GUI*)gui)->residualsCanvas = new TCanvas("ResidualsCanvas","Residuals canvas");
  ((GUI*)gui)->residualsCanvas->Divide(ceil(nDetectors/2.),2);
29

30
31
  // Run the TApplication
  app2->Run(true);
32
33
34
35
36
  
}

void GUI::initialise(Parameters* par){
 
37
  // Make the local pointer to the global parameters
38
39
  parameters = par;
  
40
41
  // Check the number of devices
  nDetectors = parameters->nDetectors;
42
  
43
44
45
	// Make the thread which will run the display
  displayThread = new TThread("displayThread", startDisplay, (void*) this);
  displayThread->Run();
46
  sleep(2);
47

48
49
50
51
52
53
54
  // Loop over all detectors and load the histograms that we will use
  for(int det = 0; det<parameters->nDetectors; det++){
    string detectorID = parameters->detectors[det];
    string hitmapHisto = "/tbAnalysis/TestAlgorithm/hitmap_"+detectorID;
    hitmap[detectorID] = (TH2F*)gDirectory->Get(hitmapHisto.c_str());
    string residualHisto = "/tbAnalysis/BasicTracking/residualsX_"+detectorID;
    residuals[detectorID] = (TH1F*)gDirectory->Get(residualHisto.c_str());
55
56
    string globalHitmapHisto = "/tbAnalysis/TestAlgorithm/clusterPositionGlobal_"+detectorID;
    globalHitmap[detectorID] = (TH2F*)gDirectory->Get(globalHitmapHisto.c_str());
57
  }
58

59
60
  // Set event counter
  eventNumber = 0;
61
62
}

Daniel Hynds's avatar
Daniel Hynds committed
63
StatusCode GUI::run(Clipboard* clipboard){
64

65
66
  gSystem->ProcessEvents();
  
67
68
69
70
71
72
73
74
75
  //-----------------------------------------
  // Draw the objects on the tracking canvas
  //-----------------------------------------

  trackCanvas->cd();
  TH1F* trackChi2 = (TH1F*)gDirectory->Get("/tbAnalysis/BasicTracking/trackChi2");
  trackChi2->DrawCopy();

  // Update the canvas
76
77
78
79
  if(eventNumber%updateNumber == 0){
//    sleep(0.5);
    trackCanvas->Update();
  }
80
  
81
82
83
  //-----------------------------------------
  // Draw the objects on the hitmap canvas
  //-----------------------------------------
84
  
85
86
87
88
89
90
91
  // Update the canvas
  if(eventNumber == 0){
    for(int det = 0; det<parameters->nDetectors; det++){
      string detectorID = parameters->detectors[det];
    	hitmap[detectorID]->SetTitle(detectorID.c_str());
    	hitmapCanvas->cd(det+1);
      hitmap[detectorID]->Draw("colz");
92
93
    }
  }
94
  // Update the canvas
95
96
97
98
  if(eventNumber%updateNumber == 0) {
    hitmapCanvas->Paint();
    hitmapCanvas->Update();
  }
99
100
101
102

  //-----------------------------------------
  // Draw the objects on the globalHitmap canvas
  //-----------------------------------------
103
  
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
  // Update the canvas
  if(eventNumber == 0){
    for(int det = 0; det<parameters->nDetectors; det++){
      string detectorID = parameters->detectors[det];
      globalHitmap[detectorID]->SetTitle(detectorID.c_str());
      globalHitmapCanvas->cd(det+1);
      globalHitmap[detectorID]->Draw("colz");
    }
  }
  // Update the canvas
  if(eventNumber%updateNumber == 0) {
    globalHitmapCanvas->Paint();
    globalHitmapCanvas->Update();
  }

119
120
121
  //-----------------------------------------
  // Draw the objects on the residuals canvas
  //-----------------------------------------
122
  
123
124
125
126
127
128
129
130
131
132
  // Loop over all detectors and load the hitmap
  if(eventNumber == 0){
    for(int det = 0; det<parameters->nDetectors; det++){
      string detectorID = parameters->detectors[det];
      residuals[detectorID]->SetTitle(detectorID.c_str());
      residualsCanvas->cd(det+1);
      residuals[detectorID]->Draw();
    }
  }
  // Update the canvas
133
134
135
136
  if(eventNumber%updateNumber == 0){
    residualsCanvas->Paint();
    residualsCanvas->Update();
  }
137
138

  eventNumber++;
Daniel Hynds's avatar
Daniel Hynds committed
139
  return Success;
140
141
142
143
144
145
  
  // Old code to allow updating of a TBrowser (TBrowser in 5.34 not thread safe, so removed)
  //  ((TCanvas*)gROOT->GetListOfCanvases()->At(0))->Paint();
  //  ((TCanvas*)gROOT->GetListOfCanvases()->At(0))->Update();
  //  gSystem->ProcessEvents();

146
147
148
149
}
  

void GUI::finalise(){
150
151

  // Kill the display thread
152
//  displayThread->Kill();
153

154
155
}