Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hdv_endviewAframe.cc
Go to the documentation of this file.
1 
2 #include <iostream>
3 #include <iomanip>
4 #include <sstream>
5 #include <cmath>
6 #include <fstream>
7 using namespace std;
8 
9 #include <pthread.h>
10 
11 #include <TRACKING/DMCThrown.h>
12 #include "hdv_endviewAframe.h"
13 #include "hdview2.h"
14 #include "MyProcessor.h"
15 #include "FDC/DFDCGeometry.h"
16 #include "FCAL/DFCALGeometry.h"
17 #include "DVector2.h"
18 #include "HDGEOMETRY/DGeometry.h"
19 #include <PID/DNeutralParticle.h>
20 
21 #include <TPolyMarker.h>
22 #include <TLine.h>
23 #include <TMarker.h>
24 #include <TBox.h>
25 #include <TVector3.h>
26 #include <TGeoVolume.h>
27 #include <TGeoManager.h>
28 #include <TGLabel.h>
29 #include <TGComboBox.h>
30 #include <TGButton.h>
31 #include <TGButtonGroup.h>
32 #include <TGTextEntry.h>
33 #include <TArrow.h>
34 #include <TLatex.h>
35 #include <TColor.h>
36 #include <TG3DLine.h>
37 
38 extern JApplication *japp;
39 //TGeoVolume *MOTHER = NULL;
40 //TGeoCombiTrans *MotherRotTrans = NULL;
41 
42 extern int GO;
43 
44 
45 //-------------------
46 // Constructor
47 //-------------------
48 hdv_endviewAframe::hdv_endviewAframe(hdv_mainframe *hdvmf, const TGWindow *p, UInt_t w, UInt_t h):TGMainFrame(p,w,h)
49 {
50  this->hdvmf = hdvmf;
51 
52  // First, define all of the of the graphics objects. Below that, make all
53  // of the connections to the methods so these things will work!
54 
55  // The main GUI window is divided into three sections, top, middle, and bottom.
56  // Create those frames here.
57  TGLayoutHints *lhints = new TGLayoutHints(kLHintsNormal, 2,2,2,2);
58  TGLayoutHints *chints = new TGLayoutHints(kLHintsCenterY|kLHintsCenterX, 2,2,2,2);
59  TGLayoutHints *xhints = new TGLayoutHints(kLHintsNormal|kLHintsExpandX, 2,2,2,2);
60  TGLayoutHints *yhints = new TGLayoutHints(kLHintsNormal|kLHintsExpandY|kLHintsCenterY, 2,2,2,2);
61  TGLayoutHints *thints = new TGLayoutHints(kLHintsTop|kLHintsCenterX|kLHintsExpandX, 2,2,0,0);
62  TGHorizontalFrame *topframe = new TGHorizontalFrame(this, w, h);
63  TGHorizontalFrame *botframe = new TGHorizontalFrame(this, w, h);
64  AddFrame(topframe, lhints);
65  AddFrame(botframe, chints);
66 
67  TGGroupFrame *canvasframe = new TGGroupFrame(topframe, "BCAL", kVerticalFrame);
68  TGGroupFrame *controls = new TGGroupFrame(topframe, "", kVerticalFrame);
69  topframe->AddFrame(canvasframe, lhints);
70  topframe->AddFrame(controls, lhints);
71 
72  TGGroupFrame *viewcontrols = new TGGroupFrame(controls, "Controls", kVerticalFrame);
73  controls->AddFrame(viewcontrols, lhints);
74  // TGGroupFrame *colorcode = new TGGroupFrame(controls, "Color code", kVerticalFrame);
75  // controls->AddFrame(colorcode, lhints);
76  TGGroupFrame *bcalColorCodes = new TGGroupFrame(controls, "BCAL colors", kVerticalFrame);
77  controls->AddFrame(bcalColorCodes, lhints);
78 
79  //------------- View canvas
80  ecanvas = new TRootEmbeddedCanvas("endviewA Large Canvas", canvasframe, w, h, kSunkenFrame, GetWhitePixel());
81  canvasframe->AddFrame(ecanvas, chints);
82 
83  //------------- Pan buttons
84  TGGroupFrame *panframe = new TGGroupFrame(viewcontrols, "Pan", kHorizontalFrame);
85  TGTextButton *panxneg = new TGTextButton(panframe, "-X");
86  TGVerticalFrame *panupdn = new TGVerticalFrame(panframe);
87  TGTextButton *panypos = new TGTextButton(panupdn, "+Y");
88  TGTextButton *panyneg = new TGTextButton(panupdn, "-Y");
89  TGTextButton *panxpos = new TGTextButton(panframe, "X+");
90 
91  viewcontrols->AddFrame(panframe, yhints);
92  panframe->AddFrame(panxneg, chints);
93  panframe->AddFrame(panupdn, chints);
94  panupdn->AddFrame(panypos, chints);
95  panupdn->AddFrame(panyneg, chints);
96  panframe->AddFrame(panxpos, chints);
97 
98  panxneg->Connect("Clicked()","hdv_mainframe",hdvmf,"DoPanXneg()");
99  panyneg->Connect("Clicked()","hdv_mainframe",hdvmf,"DoPanYneg()");
100  panxpos->Connect("Clicked()","hdv_mainframe",hdvmf,"DoPanXpos()");
101  panypos->Connect("Clicked()","hdv_mainframe",hdvmf,"DoPanYpos()");
102 
103  //------------- Zoom buttons
104  TGGroupFrame *zoomframe = new TGGroupFrame(viewcontrols, "ZOOM", kHorizontalFrame);
105  viewcontrols->AddFrame(zoomframe, thints);
106  TGTextButton *zoomout = new TGTextButton(zoomframe, " - ");
107  TGTextButton *zoomin = new TGTextButton(zoomframe, " + ");
108  zoomframe->AddFrame(zoomout, xhints);
109  zoomframe->AddFrame(zoomin, xhints);
110 
111  zoomout->Connect("Clicked()","hdv_mainframe",hdvmf,"DoZoomOut()");
112  zoomin->Connect("Clicked()","hdv_mainframe",hdvmf,"DoZoomIn()");
113 
114  //------------- Reset button
115  TGTextButton *reset = new TGTextButton(viewcontrols, "Reset");
116  viewcontrols->AddFrame(reset, chints);
117  reset->Connect("Clicked()","hdv_mainframe", hdvmf, "DoReset()");
118 
119  //------------- SaveAs message
120  stringstream ss;
121  ss<<"To save the canvas to\n";
122  ss<<"a file, right click\n";
123  ss<<"and select \"SaveAs\"\n";
124  ss<<"from the menu. File type\n";
125  ss<<"will be determined by\n";
126  ss<<"the suffix of the file\n";
127  ss<<"name.\n";
128  TGLabel *saveas = new TGLabel(viewcontrols, ss.str().c_str());
129  viewcontrols->AddFrame(saveas, chints);
130 
131  // color lables BCAL
132  TGLabel* BCCLables[9];
133  unsigned int BCccodes[9] = {0x0000FF,0x7700FF,0xFF00FF,0xFF0077,0xFF0000,0xFF7700,0xFFFF00,0xFFFF77,0xFFFFFF};
134  for (int i=0;i<9;i++) {
135  double e = pow(10,((8-(double)i)/2.0));
136  char str1[128];
137  if (e >= 1000) {
138  sprintf(str1,"%7.2f GeV",e/1000.);
139  } else {
140  sprintf(str1,"%7.1f MeV",e);
141  }
142  BCCLables[i] = new TGLabel(bcalColorCodes, (const char*)str1);
143  //BCCLables[i]->SetTextColor(1);
144  BCCLables[i]->SetBackgroundColor(BCccodes[i]);
145  bcalColorCodes->AddFrame(BCCLables[i],lhints);
146  }
147 
148  // // color code frame
149  // TGLabel* FCCLables[9];
150  // unsigned int ccodes[9] = {0xFF0033,0xFF2233,0xFF4433,0xFF6633,0xFF8833,0xFFaa33,0xFFcc33,0xFFee33,0xFFFFaa};
151  // for (int i=0;i<9;i++) {
152  // double E = pow(10.,((1. - (double)i*0.11)*log10(1./0.005)));
153  // char str1[128];
154  // sprintf(str1,"%5.1f MeV",E);
155  // FCCLables[i] = new TGLabel(colorcode, (const char*)str1);
156  // FCCLables[i]->SetBackgroundColor(ccodes[i]);
157  // colorcode->AddFrame(FCCLables[i],lhints);
158  // }
159 
160 
161 
162 
163  //========== Dismiss Button ===========
164  TGTextButton *dismiss = new TGTextButton(botframe, "dismiss");
165  botframe->AddFrame(dismiss, chints);
166 
167  //&&&&&&&&&&&&&&&& Connections
168  dismiss->Connect("Clicked()","hdv_endviewAframe", this, "DoDismiss()");
169  this->Connect("CloseWindow()", "hdv_endviewAframe", this, "DoDismiss()");
170  this->DontCallClose();
171  // Finish up and map the window
172  SetWindowName("Hall-D Event Viewer BCAL View");
173  SetIconName("HDView");
174 
175 
176  MapSubwindows();
177  Resize(GetDefaultSize());
178  panframe->Resize();
179  saveas->Resize();
180  viewcontrols->Resize();
181 }
182 
183 //-------------------
184 // DoDismiss
185 //-------------------
187 {
188  UnmapWindow();
189 }
190 
191 //-------------------
192 // SetRange
193 //-------------------
194 void hdv_endviewAframe::SetRange(double xlo, double ylo, double xhi, double yhi)
195 {
196  ecanvas->GetCanvas()->cd();
197  ecanvas->GetCanvas()->Range(xlo, ylo, xhi, yhi);
198 }
199 
200 //-------------------
201 // DrawObjects
202 //-------------------
203 void hdv_endviewAframe::DrawObjects(vector<TObject*> &graphics_endA)
204 {
205  if(!IsMapped())return;
206 
207  ecanvas->GetCanvas()->cd(0);
208  // for(unsigned int i=0; i<graphics_endA.size(); i++)graphics_endA[i]->Draw("f");
209  // for(unsigned int i=0; i<graphics_endA.size(); i++)graphics_endA[i]->Draw();
210  for(unsigned int i=0; i<graphics_endA.size(); i++){
211  TPolyLine *l = dynamic_cast<TPolyLine*>(graphics_endA[i]);
212  if(l && l->GetFillStyle()!=0){
213  graphics_endA[i]->Draw("f");
214  }else{
215  graphics_endA[i]->Draw("");
216  }
217  }
218  ecanvas->GetCanvas()->Update();
219 }
220 
TRootEmbeddedCanvas * ecanvas
sprintf(text,"Post KinFit Cut")
void DrawObjects(vector< TObject * > &graphics_endA)
JApplication * japp
hdv_endviewAframe(hdv_mainframe *hdvmf, const TGWindow *p, UInt_t w, UInt_t h)
TEllipse * e
void SetRange(double xlo, double ylo, double xhi, double yhi)
int GO
Definition: hdview2.cc:10
hdv_mainframe * hdvmf
hdv_mainframe * hdvmf