Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hdv_mainframe.h
Go to the documentation of this file.
1 
2 #ifndef _HDV_MAINFRAME_H_
3 #define _HDV_MAINFRAME_H_
4 
5 // This class is made into a ROOT dictionary ala rootcint.
6 // Therefore, do NOT include anything Hall-D specific here.
7 // It is OK to do that in the .cc file, just not here in the
8 // header.
9 
10 #include <iostream>
11 #include <cmath>
12 #include <string>
13 #include <vector>
14 #include <map>
15 
16 #include <TGClient.h>
17 #include <TGButton.h>
18 #include <TCanvas.h>
19 #include <TText.h>
20 #include <TRootEmbeddedCanvas.h>
21 #include <TTUBE.h>
22 #include <TNode.h>
23 #include <TGComboBox.h>
24 #include <TPolyLine.h>
25 #include <TEllipse.h>
26 #include <TMarker.h>
27 #include <TVector3.h>
28 #include <TGLabel.h>
29 #include <TTimer.h>
30 
31 class hdv_mainframe;
32 class trk_mainframe;
33 class hdv_optionsframe;
34 class hdv_debugerframe;
35 class hdv_fulllistframe;
36 class hdv_endviewAframe;
37 class hdv_endviewBframe;
38 class DKinematicData;
39 #if !(defined(__CINT__) || defined(__CLING__))
40 #include "trk_mainframe.h"
41 #include "hdv_optionsframe.h"
42 #include "hdv_debugerframe.h"
43 #include "hdv_fulllistframe.h"
44 #include "hdv_endviewAframe.h"
45 #include "hdv_endviewBframe.h"
46 #endif
47 
48 class hdv_mainframe:public TGMainFrame {
49 
50  public:
51  hdv_mainframe(const TGWindow *p, UInt_t w, UInt_t h);
53 
54  enum coordsys_t{
55  COORD_XY = 1,
57  };
58 
59  void ReadPreferences(void);
60  void SavePreferences(void);
61  void SetRange(void);
62 
63  // Slots for ROOT GUI
64  void DoQuit(void);
65  void DoNext(void);
66  void DoPrev(void);
67  void DoStop(void);
68  void DoCont(void);
69  void DoTimer(void);
70 
71  void DoOpenTrackInspector(void);
72  void DoOpenOptionsWindow(void);
73  void DoOpenFullListWindow(void);
74  void DoOpenTOFInspector(void);
75  void DoOpenFCALInspector(void);
76  void DoOpenBCALInspector(void);
77  void DoOpenDebugerWindow(void);
78  void DoBcalDispFrame(void);
79  void DoUpdateBcalDisp(void);
80 
82  void DoClearOptionsWindowPointer(void);
83  void DoClearTOFInspectorPointer(void);
84  void DoClearFCALInspectorPointer(void);
85  void DoClearBCALInspectorPointer(void);
86 
87  void DoEndViewAEvent(TVirtualPad* pad, TObject* obj, Int_t event);
88  void DoEndViewBEvent(TVirtualPad* pad, TObject* obj, Int_t event);
89 
90  void DoPanXpos(void);
91  void DoPanXneg(void);
92  void DoPanYpos(void);
93  void DoPanYneg(void);
94  void DoPanZpos(void);
95  void DoPanZneg(void);
96 
97  void DoZoomIn(void);
98  void DoZoomOut(void);
99  void DoReset(void);
100  void DoMyRedraw(void);
101  void DoSetDelay(Int_t);
102  void DoSetCoordinates(Int_t);
103  void DoUpdateTrackLabels(void);
104 
105  void DrawDetectorsXY(void);
106  void DrawDetectorsRPhi(void);
107  void DrawAxes(TCanvas *c, vector<TObject*> &graphics, const char *xlab, const char *ylab);
108  void DrawScale(TCanvas *c, vector<TObject*> &graphics);
109  void DrawLabel(TCanvas *c, vector<TObject*> &graphics, const char *txt);
110 
111 
112  // Other (non-slot) methods
113  void SetEvent(ULong64_t id);
114  void SetRun(Int_t id);
115  void SetTrig(char *trigstring);
116  void SetSource(string source);
117  bool GetDrawCandidates(void){return draw_candidates;}
118  bool GetDrawTracks(void){return draw_tracks;}
119  bool GetDrawThrowns(void){return draw_throwns;}
123  TCanvas* GetBcalDispFrame(void){return bcaldispmf;}
124  map<string, vector<TGLabel*> >& GetThrownLabels(void){return thrownlabs;}
125  map<string, vector<TGLabel*> >& GetReconstructedLabels(void){return reconlabs;}
126 
127  void SetCandidateFactories(vector<string> &facnames);
128  void SetWireBasedTrackFactories(vector<string> &facnames);
129  void SetTimeBasedTrackFactories(vector<string> &facnames);
130  void SetReconstructedFactories(vector<string> &facnames);
131  void SetChargedTrackFactories(vector<string> &facnames);
133  void SetBcalDispFrame(TCanvas* d){bcaldispmf = d;}
135 
136  bool GetCheckButton(string who);
137  void AddCheckButtons(map<string, TGCheckButton*> &checkbuttons);
138  const char* GetFactoryTag(string who);
139  void GetReconFactory(string &name, string &tag);
140  TPolyLine* GetFCALPolyLine(int channel);
141  TPolyLine* GetFCALPolyLine(float x, float y);
142  TPolyLine* GetCCALPolyLine(int row, int col);
143  TPolyLine* GetBCALPolyLine(int mod, int layer, int sector);
144  TPolyLine* GetTOFPolyLine(int translate_side, int tof_ch);
145 
146  void AddGraphicsSideA(vector<TObject*> &v);
147  void AddGraphicsSideB(vector<TObject*> &v);
148  void AddGraphicsEndA(vector<TObject*> &v);
149  void AddGraphicsEndB(vector<TObject*> &v);
150 
151 
152  private:
153 
157  TCanvas *bcaldispmf;
161 
162  TRootEmbeddedCanvas *sideviewA;
163  TRootEmbeddedCanvas *sideviewB;
164  TRootEmbeddedCanvas *endviewA;
165  TRootEmbeddedCanvas *endviewB;
166 
167  TGLabel *event, *run, *trig, *source;
168 
169  TGComboBox *timetracksfactory;
170  TGComboBox *wiretracksfactory;
171  TGComboBox *candidatesfactory;
172  TGComboBox *chargedtracksfactory;
173  TGComboBox *reconfactory;
174  TGComboBox *delay;
175 
176  TGTextButton *next, *prev;
177 
178  TGGroupFrame *throwninfo;
179  TGGroupFrame *reconinfo;
180 
184 
189 
190  double zoom_factor;
191  double r0, phi0, x0, y0, z0;
194 
195  vector<TObject*> graphics_sideA;
196  vector<TObject*> graphics_sideB;
197  vector<TObject*> graphics_endA;
198  vector<TObject*> graphics_endB;
199 
200  map<string, vector<TGLabel*> > thrownlabs;
201  map<string, vector<TGLabel*> > reconlabs;
202  map<string, TGCheckButton*> checkbuttons;
203  map<int, TPolyLine*> fcalblocks;
204  map<int, TPolyLine*> bcalblocks;
205  map<int, TPolyLine*> ccalblocks;
206  map<int, map<int, TPolyLine*> > tofblocks;
207 
208  TTimer *timer;
209  long sleep_time; // in milliseconds
210 
211  template<typename T> void FillPoly(T *sA, T *sB, T *eA, vector<TVector3> &v);
212 
213  ClassDef(hdv_mainframe,1)
214 };
215 
216 // The following line is supposed to avoid the warning messages about:
217 // "dereferencing type-punned pointer will break strict-aliasing rules"
218 #if (defined(__CINT__) || defined(__CLING__))
219 
220 #pragma link C++ class hdv_mainframe+;
221 #endif
222 
223 //---------------
224 // FillPoly
225 //---------------
226 template<typename T>
227 void hdv_mainframe::FillPoly(T *sA, T *sB, T *eA, vector<TVector3> &v)
228 {
229  /// Fill sA, sB, and eA with the space points given in v. This is done
230  /// via repeated calls to the SetNextPoint method of T which
231  /// should be of type TPolyLine or TPolyMarker.
232  /// We do this in a template since both have a SetNextPoint() method
233  /// and we really want this code to do the same thing for both cases.
234  /// Note that if the SetNextPoint method were inherited from the base class,
235  /// we wouldn't have to do this with a template!
236 
237  for(unsigned int i=0; i<v.size(); i++){
238  TVector3 &pt = v[i];
239  if(coordinatetype == COORD_XY){
240  sA->SetNextPoint(pt.Z(), pt.X());
241  sB->SetNextPoint(pt.Z(), pt.Y());
242  eA->SetNextPoint(pt.X(), pt.Y());
243  }else{
244  double phi = pt.Phi();
245  if(phi==0 && i==0 && v.size()>1){
246  // If the first trajectory point is at phi=0, then change it to be
247  // the same as the second trajectory point. This is to avoid having
248  // a long line on R/phi plots from phi=0.
249  phi = v[i+1].Phi();
250  }
251  if(phi<0.0)phi+=2.0*3.14159265;
252  sA->SetNextPoint(pt.Z(), pt.Perp());
253  sB->SetNextPoint(pt.Z(), phi);
254  eA->SetNextPoint(phi, pt.Perp());
255  }
256  }
257 
258  // Push graphics objects into containers
259  graphics_sideA.push_back(sA);
260  graphics_sideB.push_back(sB);
261  graphics_endA.push_back(eA);
262 
263  // OK, here's something not too pleasant. When wires are drawn, they
264  // specified as 2 points in space. For wires that are not perfectly
265  // parallel to the z direction, they will have some extent in R
266  // and may even have a funny shape if they extend in z as well.
267  // We must catch these here and replace them with several points
268  // in order to properly represent them in R.
269  if(coordinatetype == COORD_RPHI && typeid(T)==typeid(TPolyLine) && v.size()==2){
270  unsigned int Npoints = 30;
271  TVector3 s = (v[1] - v[0]);
272  s *= 1.0/(double)(Npoints-1);
273  double last_phi=0.0;
274  for(unsigned int i=1; i<Npoints; i++){
275  TVector3 pt = v[0] + ((double)i)*s;
276  double phi = pt.Phi();
277  if(phi<0.0)phi+=2.0*M_PI;
278 
279  // If the phi angle suddenly jumps by a large amount then assume
280  // we crossed the boundary and create a second TPolyLine so
281  // we don't have a long line across all of phi where no wire actually
282  // exists.
283  //
284  // Note the ugly use of reinterpret_cast below. This is because the
285  // type of sB and eB are TPolyMarkers in the T=TPolyMarker version
286  // of this method and TPolyMarker doesn't have
287  // a SetPolyLine method. We need to clear the points from
288  // our new TPolyLine (note that T should be guaranteed to be
289  // TPolyLine in here because of the typeid check above.)
290  if(fabs(phi-last_phi)>M_PI){
291  sB = new T(*sB);
292  eA = new T(*eA);
293  reinterpret_cast<TPolyLine*>(sB)->SetPolyLine(0); // clear all old points
294  reinterpret_cast<TPolyLine*>(eA)->SetPolyLine(0); // clear all old points
295  graphics_sideB.push_back(sB);
296  graphics_endA.push_back(eA);
297  }
298  last_phi = phi;
299 
300  sA->SetPoint(i, pt.Z(), pt.Perp());
301  sB->SetNextPoint(pt.Z(), phi);
302  eA->SetNextPoint(phi, pt.Perp());
303  }
304  }
305 }
306 
307 
308 #endif //_HDV_MAINFRAME_H_
void DoPanXpos(void)
TRootEmbeddedCanvas * sideviewA
hdv_fulllistframe * GetFullListFrame(void)
void SetReconstructedFactories(vector< string > &facnames)
void DoEndViewBEvent(TVirtualPad *pad, TObject *obj, Int_t event)
void DrawLabel(TCanvas *c, vector< TObject * > &graphics, const char *txt)
void DrawAxes(TCanvas *c, vector< TObject * > &graphics, const char *xlab, const char *ylab)
void DoOpenOptionsWindow(void)
hdv_fulllistframe * fulllistmf
TCanvas * GetBcalDispFrame(void)
void DoPanZneg(void)
void DoUpdateTrackLabels(void)
TGComboBox * chargedtracksfactory
void SetTrig(char *trigstring)
void DoOpenFCALInspector(void)
Int_t layer
void DoSetDelay(Int_t)
bool GetCheckButton(string who)
map< string, TGCheckButton * > checkbuttons
TPad * pad
Definition: psc_mon.C:73
Double_t x[NCHANNELS]
Definition: st_tw_resols.C:39
void DoClearBCALInspectorPointer(void)
void DrawDetectorsXY(void)
void SetBcalDispFrame(TCanvas *d)
void DoOpenFullListWindow(void)
void AddGraphicsSideA(vector< TObject * > &v)
#define c
TGTextButton * prev
TPolyLine * GetCCALPolyLine(int row, int col)
#define y
void DoTimer(void)
bool draw_trajectories
void DoReset(void)
void DoSetCoordinates(Int_t)
void SetEvent(ULong64_t id)
void FillPoly(T *sA, T *sB, T *eA, vector< TVector3 > &v)
map< int, TPolyLine * > bcalblocks
map< int, TPolyLine * > fcalblocks
void DoQuit(void)
vector< TObject * > graphics_endA
void DoOpenBCALInspector(void)
void SetTimeBasedTrackFactories(vector< string > &facnames)
void DoNext(void)
string default_track
void DoClearTOFInspectorPointer(void)
void DoClearFCALInspectorPointer(void)
void DoCont(void)
double default_canvas_width
hdv_debugerframe * debugermf
map< string, vector< TGLabel * > > reconlabs
void AddGraphicsEndA(vector< TObject * > &v)
double zoom_factor
TGTextButton * next
string default_candidate
void AddGraphicsEndB(vector< TObject * > &v)
map< int, map< int, TPolyLine * > > tofblocks
TRootEmbeddedCanvas * endviewB
void DoPanYpos(void)
map< string, vector< TGLabel * > > & GetThrownLabels(void)
map< int, TPolyLine * > ccalblocks
hdv_endviewBframe * endviewBmf
void DoPanYneg(void)
void DoOpenDebugerWindow(void)
double canvas_width
TGLabel * source
TPolyLine * GetBCALPolyLine(int mod, int layer, int sector)
string default_reconstructed
void DoOpenTrackInspector(void)
TPolyLine * GetFCALPolyLine(int channel)
TGComboBox * reconfactory
void DoPrev(void)
void DoOpenTOFInspector(void)
void DoClearOptionsWindowPointer(void)
TGLabel * trig
vector< TObject * > graphics_sideA
void SetChargedTrackFactories(vector< string > &facnames)
TTimer * timer
bool GetDrawTrajectories(void)
trk_mainframe * trkmf
vector< TObject * > graphics_endB
void SetRange(void)
void DoZoomIn(void)
void GetReconFactory(string &name, string &tag)
bool GetDrawCandidates(void)
void DoZoomOut(void)
void DoClearTrackInspectorPointer(void)
map< string, vector< TGLabel * > > thrownlabs
void SetRun(Int_t id)
TGComboBox * delay
void ReadPreferences(void)
void DoPanXneg(void)
void SetDebugerFrame(hdv_debugerframe *d)
map< string, vector< TGLabel * > > & GetReconstructedLabels(void)
TGLabel * event
void SetFullListFrame(hdv_fulllistframe *d)
void DoMyRedraw(void)
hdv_debugerframe * GetDebugerFrame(void)
TGComboBox * candidatesfactory
TGGroupFrame * reconinfo
void DoStop(void)
hdv_optionsframe * optionsmf
void DrawDetectorsRPhi(void)
void DrawScale(TCanvas *c, vector< TObject * > &graphics)
void SavePreferences(void)
vector< TObject * > graphics_sideB
hdv_mainframe(const TGWindow *p, UInt_t w, UInt_t h)
void DoUpdateBcalDisp(void)
bool GetDrawThrowns(void)
TCanvas * bcaldispmf
TGLabel * run
void AddGraphicsSideB(vector< TObject * > &v)
coordsys_t coordinatetype
void DoEndViewAEvent(TVirtualPad *pad, TObject *obj, Int_t event)
hdv_endviewAframe * endviewAmf
void AddCheckButtons(map< string, TGCheckButton * > &checkbuttons)
void SetSource(string source)
void SetWireBasedTrackFactories(vector< string > &facnames)
void DoPanZpos(void)
TPolyLine * GetTOFPolyLine(int translate_side, int tof_ch)
TGComboBox * timetracksfactory
TGGroupFrame * throwninfo
void SetCandidateFactories(vector< string > &facnames)
const char * GetFactoryTag(string who)
TGComboBox * wiretracksfactory
TRootEmbeddedCanvas * endviewA
TRootEmbeddedCanvas * sideviewB
bool GetDrawTracks(void)
void DoBcalDispFrame(void)