Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hdv_mainframe.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 <unistd.h>
10 #include <pthread.h>
11 #include <sys/time.h>
12 
13 #include <TRACKING/DMCThrown.h>
14 #include "hdv_mainframe.h"
15 #include "hdview2.h"
16 #include "MyProcessor.h"
17 #include "FDC/DFDCGeometry.h"
18 #include "FCAL/DFCALGeometry.h"
19 #include "TOF/DTOFGeometry.h"
20 #include "DVector2.h"
21 #include "HDGEOMETRY/DGeometry.h"
22 #include <PID/DNeutralParticle.h>
23 #include <DAQ/DEPICSvalue.h>
24 
25 #include <TPolyMarker.h>
26 #include <TLine.h>
27 #include <TMarker.h>
28 #include <TBox.h>
29 #include <TVector3.h>
30 #include <TGeoVolume.h>
31 #include <TGeoManager.h>
32 #include <TGLabel.h>
33 #include <TGComboBox.h>
34 #include <TGButton.h>
35 #include <TGButtonGroup.h>
36 #include <TGTextEntry.h>
37 #include <TArrow.h>
38 #include <TLatex.h>
39 #include <TColor.h>
40 #include <TMath.h>
41 #include <TArc.h>
42 
43 extern JApplication *japp;
44 //TGeoVolume *MOTHER = NULL;
45 //TGeoCombiTrans *MotherRotTrans = NULL;
46 
47 extern int GO;
48 extern bool SKIP_EPICS_EVENTS;
49 
50 // These values are just used to draw the detectors for visualization.
51 // These should be replaced by a database lookup or something similar
52 // at some point.
53 static float BCAL_Rmin=65.0;
54 static float BCAL_Rmax = 87.46;
55 static float BCAL_MIDRAD = 77.0;
56 static float BCAL_Zlen = 390.0;
57 static float BCAL_Zmin = 212.0 - BCAL_Zlen/2.0;
58 static float BCAL_MODS = 48;
59 static float BCAL_LAYS1 = 3;
60 //static float BCAL_LAYS2 = 4;
61 static float BCAL_SECS1 = 4;
62 static float BCAL_SECS2 = 4;
63 static float BCAL_PHI_SHIFT = 0.0; // radians (will be overwritten in constructor!)
64 static float FCAL_Zlen = 45.0;
65 static float FCAL_Zmin = 622.8;
66 static float FCAL_Rmin = 6.0;
67 static float FCAL_Rmax = 212.0/2.0;
68 static float CCAL_Zlen = 18.0;
69 static float CCAL_Zmin = 876.106;
70 static float CCAL_Rmin = 2.0;
71 static float CCAL_Rmax = 24.0;
72 static float CDC_Rmin = 9.0;
73 static float CDC_Rmax = 59.0;
74 static float CDC_Zlen = 150.0;
75 static float CDC_Zmin = 17.0;
76 static float TOF_Rmax = 125.0;
77 static float TOF_Rmin = 6.0;
78 static float TOF_Zlen = 2.54;
79 static float TOF_Zmin = 618.8;
80 static float FDC_Rmin = 3.5;
81 static float FDC_Rmax = 48.5;
82 static float TARGET_Zmid = 65.0;
83 static float TARGET_Zlen = 30.0;
84 
85 // The DFCALGeometry object is not really available at the time we need it
86 // when the program first starts. Create one of our own here.
88 // ditto for DTOFGeometry
89 //static DTOFGeometry *tofgeom = new DTOFGeometry;
90 static DTOFGeometry *tofgeom = NULL;
91 
92 static vector<vector <DFDCWire *> >fdcwires;
93 
94 //-------------------
95 // Constructor
96 //-------------------
97 hdv_mainframe::hdv_mainframe(const TGWindow *p, UInt_t w, UInt_t h):TGMainFrame(p,w,h)
98 {
99  //Get pointer to DGeometry object
100  DApplication* dapp=dynamic_cast<DApplication*>(japp);
101  const DGeometry *dgeom = dapp->GetDGeometry(RUNNUMBER);
102 
103  tofgeom = new DTOFGeometry(dgeom);
104 
105  dgeom->GetFDCWires(fdcwires);
106 
107  // Get Target parameters from XML
108  double my_TARGET_Zmid = TARGET_Zmid;
109  double my_TARGET_Zlen = TARGET_Zlen;
110  dgeom->GetTargetZ(my_TARGET_Zmid);
111  dgeom->GetTargetLength(my_TARGET_Zlen);
112  TARGET_Zmid = my_TARGET_Zmid;
113  TARGET_Zlen = my_TARGET_Zlen;
114 
115  // Get overall phi shift of BCAL
116  float my_BCAL_PHI_SHIFT;
117  dgeom->GetBCALPhiShift(my_BCAL_PHI_SHIFT);
118  BCAL_PHI_SHIFT = my_BCAL_PHI_SHIFT*TMath::DegToRad(); // convert to radians
119 
120  UInt_t MainWidth = w;
121 
122  // First, define all of the of the graphics objects. Below that, make all
123  // of the connections to the methods so these things will work!
124 
125  // Use the "color wheel" rather than the classic palette.
126  //TColor::CreateColorWheel();
127 
128  // The main GUI window is divided into three sections, top, middle, and bottom.
129  // Create those frames here.
130  TGLayoutHints *hints = new TGLayoutHints(kLHintsNormal|kLHintsExpandX|kLHintsExpandY|kLHintsLeft, 5,5,5,5);
131  TGLayoutHints *lhints = new TGLayoutHints(kLHintsNormal, 2,2,2,2);
132  TGLayoutHints *rhints = new TGLayoutHints(kLHintsCenterY|kLHintsRight, 2,2,2,2);
133  TGLayoutHints *chints = new TGLayoutHints(kLHintsCenterY|kLHintsCenterX, 2,2,2,2);
134  TGLayoutHints *bhints = new TGLayoutHints(kLHintsBottom|kLHintsCenterX, 2,2,2,2);
135  //TGLayoutHints *tofhints = new TGLayoutHints(kLHintsBottom|kLHintsCenterX, 2,2,2,2);
136  TGLayoutHints *xhints = new TGLayoutHints(kLHintsNormal|kLHintsExpandX, 2,2,2,2);
137  TGLayoutHints *yhints = new TGLayoutHints(kLHintsNormal|kLHintsExpandY, 2,2,2,2);
138  TGLayoutHints *dhints = new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 0,0,0,0);
139  TGLayoutHints *ehints = new TGLayoutHints(kLHintsNormal, 2,2,0,0);
140  TGLayoutHints *thints = new TGLayoutHints(kLHintsTop|kLHintsCenterX, 2,2,0,0);
141  TGLayoutHints *lxhints = new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 2,2,0,0);
142  TGHorizontalFrame *sourceframe = new TGHorizontalFrame(this,w,20);
143  TGHorizontalFrame *topframe = new TGHorizontalFrame(this, w, 200);
144  // TGHorizontalFrame *midframe = new TGHorizontalFrame(this, w, 200);
145  TGCompositeFrame *midframe = new TGCompositeFrame(this, w, 200, kHorizontalFrame);
146  TGHorizontalFrame *botframe = new TGHorizontalFrame(this, w, 200);
147  AddFrame(sourceframe, lxhints);
148  AddFrame(topframe, lhints);
149  AddFrame(midframe, lhints);
150  AddFrame(botframe, lhints);
151 
152  //========== Source ===========
153  TGLabel *sourcelab = new TGLabel(sourceframe, "Source:");
154  sourceframe->AddFrame(sourcelab,ehints);
155  source = new TGLabel(sourceframe, "--");
156  sourceframe->AddFrame(source, lxhints);
157  source->SetTextJustify(1);
158 
159  //========== TOP FRAME ============
160  TGGroupFrame *viewcontrols = new TGGroupFrame(topframe, "View Controls", kHorizontalFrame);
161  TGGroupFrame *eventcontrols = new TGGroupFrame(topframe, "Event Controls", kHorizontalFrame);
162  TGGroupFrame *eventinfo = new TGGroupFrame(topframe, "Info", kHorizontalFrame);
163  TGGroupFrame *inspectors = new TGGroupFrame(topframe, "Inspectors", kVerticalFrame);
164  TGHorizontalFrame *programcontrols = new TGHorizontalFrame(topframe);
165  topframe->AddFrame(viewcontrols, lhints);
166  topframe->AddFrame(eventcontrols, hints);
167  topframe->AddFrame(eventinfo, yhints);
168  topframe->AddFrame(inspectors, yhints);
169  topframe->AddFrame(programcontrols, yhints);
170 
171  //-------------Pan buttons
172  TGVerticalFrame *panneg = new TGVerticalFrame(viewcontrols);
173  TGVerticalFrame *panpos = new TGVerticalFrame(viewcontrols);
174  viewcontrols->AddFrame(panneg, hints);
175  viewcontrols->AddFrame(panpos, hints);
176  TGTextButton *panxneg = new TGTextButton(panneg, "-X");
177  TGTextButton *panyneg = new TGTextButton(panneg, "-Y");
178  TGTextButton *panzneg = new TGTextButton(panneg, "-Z");
179  panneg->AddFrame(panxneg, dhints);
180  panneg->AddFrame(panyneg, dhints);
181  panneg->AddFrame(panzneg, dhints);
182 
183  TGTextButton *panxpos = new TGTextButton(panpos, "X+");
184  TGTextButton *panypos = new TGTextButton(panpos, "Y+");
185  TGTextButton *panzpos = new TGTextButton(panpos, "Z+");
186  panpos->AddFrame(panxpos, dhints);
187  panpos->AddFrame(panypos, dhints);
188  panpos->AddFrame(panzpos, dhints);
189 
190  panxneg->Connect("Clicked()","hdv_mainframe",this,"DoPanXneg()");
191  panyneg->Connect("Clicked()","hdv_mainframe",this,"DoPanYneg()");
192  panzneg->Connect("Clicked()","hdv_mainframe",this,"DoPanZneg()");
193  panxpos->Connect("Clicked()","hdv_mainframe",this,"DoPanXpos()");
194  panypos->Connect("Clicked()","hdv_mainframe",this,"DoPanYpos()");
195  panzpos->Connect("Clicked()","hdv_mainframe",this,"DoPanZpos()");
196  //------------- Zoom/Reset buttons
197  TGVerticalFrame *zoom = new TGVerticalFrame(viewcontrols);
198  viewcontrols->AddFrame(zoom, lhints);
199  TGGroupFrame *zoomframe = new TGGroupFrame(zoom, "ZOOM", kHorizontalFrame);
200  zoom->AddFrame(zoomframe, thints);
201  TGTextButton *zoomout = new TGTextButton(zoomframe, " - ");
202  TGTextButton *zoomin = new TGTextButton(zoomframe, " + ");
203  zoomframe->AddFrame(zoomout, thints);
204  zoomframe->AddFrame(zoomin, thints);
205  TGTextButton *reset = new TGTextButton(zoom, "Reset");
206  zoom->AddFrame(reset, chints);
207 
208  //-------------- Transverse Coordinates
209  TGVButtonGroup *coordinates = new TGVButtonGroup(viewcontrols,"Transverse Coordinates");
210  viewcontrols->AddFrame(coordinates, lhints);
211  TGRadioButton *xy = new TGRadioButton(coordinates, "x/y");
212  new TGRadioButton(coordinates, "r/phi");
213 
214  //-------------- Next, Previous
215  prev = new TGTextButton(eventcontrols, "<-- Prev");
216  next = new TGTextButton(eventcontrols, "Next -->");
217  TGVerticalFrame *contf = new TGVerticalFrame(eventcontrols);
218  eventcontrols->AddFrame(prev, chints);
219  eventcontrols->AddFrame(next, chints);
220  eventcontrols->AddFrame(contf, lhints);
221 
222  // continuous, delay
223  checkbuttons["continuous"] = new TGCheckButton(contf, "continuous");
224  TGHorizontalFrame *delayf = new TGHorizontalFrame(contf);
225  contf->AddFrame(checkbuttons["continuous"], lhints);
226  contf->AddFrame(delayf, lhints);
227  TGLabel *delaylab = new TGLabel(delayf, "delay:");
228  delay = new TGComboBox(delayf, "0.25");
229  delay->Resize(50,20);
230  float delays[]={0, 0.25, 0.5, 1, 2, 3, 5, 10};
231  for(int i=0; i<8; i++){
232  stringstream ss;
233  ss<<delays[i];
234  delay->AddEntry(ss.str().c_str(),i);
235  }
236  delayf->AddFrame(delaylab, lhints);
237  delayf->AddFrame(delay, lhints);
238 
239  //----------------- Event Info
240  TGVerticalFrame *eventlabs = new TGVerticalFrame(eventinfo);
241  TGVerticalFrame *eventvals = new TGVerticalFrame(eventinfo);
242  eventinfo->AddFrame(eventlabs, lhints);
243  eventinfo->AddFrame(eventvals, lhints);
244 
245  TGLabel *runlab = new TGLabel(eventlabs, "Run:");
246  TGLabel *eventlab = new TGLabel(eventlabs, "Event:");
247  TGLabel *triglab = new TGLabel(eventlabs, "GTP bits:");
248  run = new TGLabel(eventvals, "--------------");
249  event = new TGLabel(eventvals, "--------------");
250  trig = new TGLabel(eventvals, "--------------");
251  eventlabs->AddFrame(runlab, rhints);
252  eventlabs->AddFrame(eventlab,rhints);
253  eventlabs->AddFrame(triglab,rhints);
254  eventvals->AddFrame(run, lhints);
255  eventvals->AddFrame(event, lhints);
256  eventvals->AddFrame(trig, lhints);
257 
258  //----------------- Inspectors
259  TGTextButton *trackinspector = new TGTextButton(inspectors, "Track Inspector");
260  //TGTextButton *tofinspector = new TGTextButton(inspectors, "TOF Inspector");
261  //TGTextButton *bcalinspector = new TGTextButton(inspectors, "BCAL Inspector");
262  //TGTextButton *fcalinspector = new TGTextButton(inspectors, "FCAL Inspector");
263  inspectors->AddFrame(trackinspector, xhints);
264  //inspectors->AddFrame(tofinspector, xhints);
265  //inspectors->AddFrame(bcalinspector, xhints);
266  //inspectors->AddFrame(fcalinspector, xhints);
267  //tofinspector->SetEnabled(kFALSE);
268  //bcalinspector->SetEnabled(kFALSE);
269  //fcalinspector->SetEnabled(kFALSE);
270 
271  //-------------- Program Controls
272  TGTextButton *quit = new TGTextButton(programcontrols, "&Quit");
273  programcontrols->AddFrame(quit, new TGLayoutHints(kLHintsTop|kLHintsRight|kLHintsExpandX, 2,2,2,2));
274 
275  //========== MID FRAME ============
276  TGHorizontalFrame *detectorframe = new TGHorizontalFrame(midframe);
277  midframe->AddFrame(detectorframe, hints);
278 
279  //------ Detector Frame ------
280  TGVerticalFrame *sideviews = new TGVerticalFrame(detectorframe);
281  TGVerticalFrame *endviews = new TGVerticalFrame(detectorframe);
282  TGVerticalFrame *drawopts = new TGVerticalFrame(detectorframe);
283  TGVerticalFrame *caloColorCodes = new TGVerticalFrame(detectorframe);
284  detectorframe->AddFrame(sideviews, lhints);
285  detectorframe->AddFrame(endviews, lhints);
286  detectorframe->AddFrame(caloColorCodes, lhints);
287  detectorframe->AddFrame(drawopts, lhints);
288 
289  // Side views
290  int width = MainWidth/6*2;
291  TGHorizontalFrame *sideviewAframe = new TGHorizontalFrame(sideviews);
292  TGHorizontalFrame *sideviewBframe = new TGHorizontalFrame(sideviews);
293  sideviews->AddFrame(sideviewAframe, lhints);
294  sideviews->AddFrame(sideviewBframe, lhints);
295  sideviewA = new TRootEmbeddedCanvas("sideviewA Canvas", sideviewAframe, width, width/2, kSunkenFrame, GetWhitePixel());
296  sideviewB = new TRootEmbeddedCanvas("sideviewB Canvas", sideviewBframe, width, width/2, kSunkenFrame, GetWhitePixel());
297  sideviewAframe->AddFrame(sideviewA, lhints);
298  sideviewBframe->AddFrame(sideviewB, lhints);
299  sideviewA->SetScrolling(TGCanvas::kCanvasScrollBoth);
300  sideviewB->SetScrolling(TGCanvas::kCanvasScrollBoth);
301  sideviewA->SetBackgroundColor(0xafeeee);
302  sideviewB->SetBackgroundColor(0xafeeee);
303 
304  // End views
305  endviewA = new TRootEmbeddedCanvas("endviewA Canvas", endviews, width/2, width/2, kSunkenFrame, GetWhitePixel());
306  endviewB = new TRootEmbeddedCanvas("endviewB Canvas", endviews, width/2, width/2, kSunkenFrame, GetWhitePixel());
307  endviews->AddFrame(endviewA, lhints);
308  endviews->AddFrame(endviewB, lhints);
309  endviewA->SetScrolling(TGCanvas::kCanvasScrollBoth);
310  endviewB->SetScrolling(TGCanvas::kCanvasScrollBoth);
311  endviewA->GetCanvas()->SetFillColor(kGray+1);
312  endviewB->GetCanvas()->SetFillColor(kGray+1);
313 
314  // Draw opts
315  TGGroupFrame *trkdrawopts = new TGGroupFrame(drawopts, "Track Draw Options", kVerticalFrame);
316  TGGroupFrame *hitdrawopts = new TGGroupFrame(drawopts, "Hit Draw Options", kVerticalFrame);
317  drawopts->AddFrame(trkdrawopts, lhints);
318  drawopts->AddFrame(hitdrawopts, lhints);
319 
320  // Track
321  TGHorizontalFrame *candidatesf = new TGHorizontalFrame(trkdrawopts);
322  checkbuttons["candidates"] = new TGCheckButton(candidatesf, "DTrackCandidate:");
323  candidatesfactory = new TGComboBox(candidatesf, "<default>", 0);
324  candidatesfactory->Resize(80,20);
325  candidatesf->AddFrame(checkbuttons["candidates"], lhints);
326  for(int i=0; i<100; i++)candidatesfactory->AddEntry("a",i);
327  // For some reason, this is needed for ROOT >5.14 (??!!!) real entries are filled in later
328  candidatesf->AddFrame(candidatesfactory, lhints);
329  trkdrawopts->AddFrame(candidatesf, lhints);
330 
331  TGHorizontalFrame *wiretracksf = new TGHorizontalFrame(trkdrawopts);
332  checkbuttons["wiretracks"] = new TGCheckButton(wiretracksf, "DTrackWireBased:");
333  wiretracksfactory = new TGComboBox(wiretracksf, "<default>", 0);
334  wiretracksfactory->Resize(80,20);
335  wiretracksf->AddFrame(checkbuttons["wiretracks"], lhints);
336  for(int i=0; i<100; i++)wiretracksfactory->AddEntry("a",i);
337  // For some reason, this is needed for ROOT >5.14 (??!!!) real entries are filled in later
338  wiretracksf->AddFrame(wiretracksfactory, lhints);
339  trkdrawopts->AddFrame(wiretracksf, lhints);
340 
341  TGHorizontalFrame *timetracksf = new TGHorizontalFrame(trkdrawopts);
342  checkbuttons["timetracks"] = new TGCheckButton(timetracksf, "DTrackTimeBased:");
343  timetracksfactory = new TGComboBox(timetracksf, "<default>", 0);
344  timetracksfactory->Resize(80,20);
345  timetracksf->AddFrame(checkbuttons["timetracks"], lhints);
346  for(int i=0; i<100; i++)timetracksfactory->AddEntry("a",i);
347  // For some reason, this is needed for ROOT >5.14 (??!!!) real entries are filled in later
348  timetracksf->AddFrame(timetracksfactory, lhints);
349  trkdrawopts->AddFrame(timetracksf, lhints);
350  TGHorizontalFrame *chargedtracksf = new TGHorizontalFrame(trkdrawopts);
351  checkbuttons["chargedtracks"] = new TGCheckButton(chargedtracksf, "DChargedTrack:");
352  chargedtracksfactory = new TGComboBox(chargedtracksf, "<default>", 0);
353  chargedtracksfactory->Resize(80,20);
354  chargedtracksf->AddFrame(checkbuttons["chargedtracks"], lhints);
355  for(int i=0; i<100; i++)chargedtracksfactory->AddEntry("a",i);
356  // For some reason, this is needed for ROOT >5.14 (??!!!) real entries are filled in later
357  chargedtracksf->AddFrame(chargedtracksfactory, lhints);
358  trkdrawopts->AddFrame(chargedtracksf, lhints);
359 
360  checkbuttons["neutrals"] = new TGCheckButton(trkdrawopts,"DNeutralParticle");
361  checkbuttons["thrown"] = new TGCheckButton(trkdrawopts,"DMCThrown");
362  checkbuttons["trajectories"] = new TGCheckButton(trkdrawopts, "DMCTrajectoryPoint");
363  trkdrawopts->AddFrame(checkbuttons["neutrals"], lhints);
364  trkdrawopts->AddFrame(checkbuttons["thrown"], lhints);
365  trkdrawopts->AddFrame(checkbuttons["trajectories"], lhints);
366 
367  // Hit
368  checkbuttons["cdc"] = new TGCheckButton(hitdrawopts, "CDC");
369  checkbuttons["cdcdrift"] = new TGCheckButton(hitdrawopts, "CDC Drift Time");
370  checkbuttons["cdctruth"] = new TGCheckButton(hitdrawopts, "CDCTruth");
371  checkbuttons["fdcwire"] = new TGCheckButton(hitdrawopts, "FDC Wire");
372  checkbuttons["fdcpseudo"] = new TGCheckButton(hitdrawopts, "FDC Pseudo");
373  checkbuttons["fdctruth"] = new TGCheckButton(hitdrawopts, "FDCTruth");
374  checkbuttons["tof"] = new TGCheckButton(hitdrawopts, "TOF");
375  checkbuttons["toftruth"] = new TGCheckButton(hitdrawopts, "TOFTruth");
376  checkbuttons["fcal"] = new TGCheckButton(hitdrawopts, "FCAL");
377  checkbuttons["bcal"] = new TGCheckButton(hitdrawopts, "BCAL");
378  checkbuttons["ccal"] = new TGCheckButton(hitdrawopts, "CCAL");
379 
380  hitdrawopts->AddFrame(checkbuttons["cdc"], lhints);
381  hitdrawopts->AddFrame(checkbuttons["cdcdrift"], lhints);
382  hitdrawopts->AddFrame(checkbuttons["cdctruth"], lhints);
383  hitdrawopts->AddFrame(checkbuttons["fdcwire"], lhints);
384  hitdrawopts->AddFrame(checkbuttons["fdcpseudo"], lhints);
385  hitdrawopts->AddFrame(checkbuttons["fdctruth"], lhints);
386  hitdrawopts->AddFrame(checkbuttons["tof"], lhints);
387  hitdrawopts->AddFrame(checkbuttons["toftruth"], lhints);
388  hitdrawopts->AddFrame(checkbuttons["fcal"], lhints);
389  hitdrawopts->AddFrame(checkbuttons["bcal"], lhints);
390  hitdrawopts->AddFrame(checkbuttons["ccal"], lhints);
391 
392  TGTextButton *moreOptions = new TGTextButton(hitdrawopts, "More options");
393  hitdrawopts->AddFrame(moreOptions, lhints);
394 
395  // Color codes
396  TGGroupFrame *bcalColorCodes = new TGGroupFrame(caloColorCodes, "BCAL colors", kVerticalFrame);
397  TGGroupFrame *fcalColorCodes = new TGGroupFrame(caloColorCodes, "FCAL colors", kVerticalFrame);
398  TGTextButton *debuger = new TGTextButton(caloColorCodes,"Debugger");
399  TGTextButton *bcaldisp = new TGTextButton(caloColorCodes,"BcalDisp");
400 
401  caloColorCodes->AddFrame(bcalColorCodes, thints);
402  caloColorCodes->AddFrame(debuger,lhints);
403  caloColorCodes->AddFrame(bcaldisp,lhints);
404  caloColorCodes->AddFrame(fcalColorCodes, bhints);
405  bcalColorCodes->SetWidth(30);
406  fcalColorCodes->SetWidth(30);
407 
408  // color lables BCAL
409  TGLabel* BCCLables[9];
410  unsigned int BCccodes[9] = {0x0000FF,0x7700FF,0xFF00FF,0xFF0077,0xFF0000,0xFF7700,0xFFFF00,0xFFFF77,0xFFFFFF};
411  for (int i=0;i<9;i++) {
412  double e = pow(10,((8-(double)i)/2.0));
413  char str1[128];
414  if (e >= 1000) {
415  sprintf(str1,"%7.2f GeV",e/1000.);
416  } else {
417  sprintf(str1,"%7.1f MeV",e);
418  }
419  BCCLables[i] = new TGLabel(bcalColorCodes, (const char*)str1);
420  //BCCLables[i]->SetTextColor(1);
421  BCCLables[i]->SetBackgroundColor(BCccodes[i]);
422  bcalColorCodes->AddFrame(BCCLables[i],lhints);
423  }
424  // color lables FCAL
425  TGLabel* FCCLables[9];
426  unsigned int FCccodes[9] = {0x0000FF,0x7700FF,0xFF00FF,0xFF0077,0xFF0000,0xFF7700,0xFFFF00,0xFFFF77,0xFFFFFF};
427  for (int i=0;i<9;i++) {
428  double e = pow(10,((8-(double)i)/2.0));
429  char str1[128];
430  if (e >= 1000) {
431  sprintf(str1,"%7.2f GeV",e/1000.);
432  } else {
433  sprintf(str1,"%7.1f MeV",e);
434  }
435  FCCLables[i] = new TGLabel(fcalColorCodes, (const char*)str1);
436  FCCLables[i]->SetBackgroundColor(FCccodes[i]);
437  fcalColorCodes->AddFrame(FCCLables[i],lhints);
438  }
439 
440  //========== BOT FRAME ============
441  TGGroupFrame *trackinfo = new TGGroupFrame(botframe, "Track Info", kHorizontalFrame);
442  botframe->AddFrame(trackinfo, xhints);
443 
444  //------ Track Info ------
445  throwninfo = new TGGroupFrame(trackinfo, "Thrown", kHorizontalFrame);
446  reconinfo = new TGGroupFrame(trackinfo, "Reconstructed", kHorizontalFrame);
447  trackinfo->AddFrame(throwninfo, lhints);
448  trackinfo->AddFrame(reconinfo, lhints);
449 
450  // Column names
451  vector<string> colnames;
452  colnames.push_back("trk");
453  colnames.push_back("type");
454  colnames.push_back("p");
455  colnames.push_back("theta");
456  colnames.push_back("phi");
457  colnames.push_back("z");
458  colnames.push_back("chisq/Ndof");
459  colnames.push_back("Ndof");
460  colnames.push_back("FOM");
461  colnames.push_back("cand");
462 
463  // Create a vertical frame for each column and insert the label as the first item
464  for(unsigned int i=0; i<colnames.size(); i++){
465  // create frames
466  TGVerticalFrame *tf = new TGVerticalFrame(throwninfo);
467  TGVerticalFrame *rf = new TGVerticalFrame(reconinfo);
468  throwninfo->AddFrame(tf, bhints);
469  reconinfo->AddFrame(rf, bhints);
470 
471  // create column labels
472  string lab = colnames[i]+":";
473  TGLabel *tl = new TGLabel(tf, lab.c_str());
474  TGLabel *rl = new TGLabel(rf, lab.c_str());
475  if(i<6)tf->AddFrame(tl, chints);
476  rf->AddFrame(rl, chints);
477  vector<TGLabel*> tv;
478  vector<TGLabel*> rv;
479  tv.push_back(tl);
480  rv.push_back(rl);
481 
482  // Add 8 labels to each column
483  // These have to be added in reverse order so we can pack them from
484  // the bottom. Otherwise, it doesn't draw correctly.
485  for(int j=0; j<14; j++){
486  stringstream ss;
487  ss<<(5-j);
488  if(i<6)tl = new TGLabel(tf, i==0 ? ss.str().c_str():"--------");
489  rl = new TGLabel(rf, i==0 ? ss.str().c_str():"--------");
490  if(i<6)tf->AddFrame(tl, bhints);
491  rf->AddFrame(rl, bhints);
492  tv.push_back(tl);
493  rv.push_back(rl);
494  }
495 
496  // Record the label object pointers for later use
497  thrownlabs[colnames[i]] = tv;
498  reconlabs[colnames[i]] = rv;
499  }
500 
501  // Reconstruction factory and full list button
502  TGVerticalFrame *vf = new TGVerticalFrame(reconinfo);
503  reconinfo->AddFrame(vf, yhints);
504  reconfactory = new TGComboBox(vf, "DTrackCandidate:", 0);
505  reconfactory->Resize(160,20);
506  for(int i=0; i<100; i++)reconfactory->AddEntry("a",i); // For some reason, this is needed for ROOT >5.14 (??!!!) real entries are filled in later
507  vf->AddFrame(reconfactory, thints);
508 
509  TGTextButton *listall = new TGTextButton(vf, "Full List");
510  vf->AddFrame(listall, new TGLayoutHints(kLHintsBottom|kLHintsExpandX, 2,2,2,2));
511 
512  // Pointers to optional daughter windows (these must be done before ReadPreferences in
513  // order for the options they implement to be filled into checkbuttons)
514  trkmf = NULL;
515  bcaldispmf = NULL;
516  optionsmf = new hdv_optionsframe(this, NULL, 100, 100);
517  debugermf = new hdv_debugerframe(this, NULL, 800, 800);
518  fulllistmf = new hdv_fulllistframe(this, NULL, 100, 100);
519  endviewAmf = new hdv_endviewAframe(this, NULL, 600, 600);
520  endviewBmf = new hdv_endviewBframe(this, NULL, 600, 600);
521 
522  //&&&&&&&&&&&&&&&& Defaults
523  ReadPreferences();
524  xy->SetState(kButtonDown,kTRUE);
526  r0 = 50.0;
527  phi0 = M_PI;
528  x0 = 0.0;
529  y0 = 0.0;
530  z0 = 350.0;
531  zoom_factor = 1.0;
532 
533  //&&&&&&&&&&&&&&&& Connections
534  zoomin->Connect("Clicked()","hdv_mainframe", this, "DoZoomIn()");
535  zoomout->Connect("Clicked()","hdv_mainframe", this, "DoZoomOut()");
536  reset->Connect("Clicked()","hdv_mainframe", this, "DoReset()");
537 
538  coordinates->Connect("Clicked(Int_t)","hdv_mainframe", this, "DoSetCoordinates(Int_t)");
539  coordinates->Connect("Clicked(Int_t)","hdv_mainframe", this, "DoMyRedraw()");
540 
541  quit->Connect("Clicked()","hdv_mainframe", this, "DoQuit()");
542  this->Connect("CloseWindow()", "hdv_mainframe", this, "DoQuit()");
543  this->DontCallClose();
544  next->Connect("Clicked()","hdv_mainframe", this, "DoNext()");
545  prev->Connect("Clicked()","hdv_mainframe", this, "DoPrev()");
546  checkbuttons["continuous"]->Connect("Clicked()","hdv_mainframe", this, "DoCont()");
547  delay->Connect("Selected(Int_t)","hdv_mainframe", this, "DoSetDelay(Int_t)");
548 
549  trackinspector->Connect("Clicked()","hdv_mainframe", this, "DoOpenTrackInspector()");
550  moreOptions->Connect("Clicked()","hdv_mainframe", this, "DoOpenOptionsWindow()");
551  listall->Connect("Clicked()","hdv_mainframe", this, "DoOpenFullListWindow()");
552  debuger->Connect("Clicked()","hdv_mainframe", this, "DoOpenDebugerWindow()");
553  bcaldisp->Connect("Clicked()","hdv_mainframe", this, "DoBcalDispFrame()");
554  //tofinspector->Connect("Clicked()","hdv_mainframe", this, "DoOpenTOFInspector()");
555  //fcalinspector->Connect("Clicked()","hdv_mainframe", this, "DoOpenFCALInspector()");
556  //bcalinspector->Connect("Clicked()","hdv_mainframe", this, "DoOpenBCALInspector()");
557 
558  checkbuttons["candidates"]->Connect("Clicked()","hdv_mainframe", this, "DoMyRedraw()");
559  checkbuttons["wiretracks"]->Connect("Clicked()","hdv_mainframe", this, "DoMyRedraw()");
560  checkbuttons["timetracks"]->Connect("Clicked()","hdv_mainframe", this, "DoMyRedraw()");
561  checkbuttons["chargedtracks"]->Connect("Clicked()","hdv_mainframe", this, "DoMyRedraw()");
562  checkbuttons["neutrals"]->Connect("Clicked()","hdv_mainframe", this, "DoMyRedraw()");
563  checkbuttons["thrown"]->Connect("Clicked()","hdv_mainframe", this, "DoMyRedraw()");
564 
565  checkbuttons["cdc"]->Connect("Clicked()","hdv_mainframe", this, "DoMyRedraw()");
566  checkbuttons["cdcdrift"]->Connect("Clicked()","hdv_mainframe", this, "DoMyRedraw()");
567  checkbuttons["cdctruth"]->Connect("Clicked()","hdv_mainframe", this, "DoMyRedraw()");
568  checkbuttons["fdcwire"]->Connect("Clicked()","hdv_mainframe", this, "DoMyRedraw()");
569  checkbuttons["fdcpseudo"]->Connect("Clicked()","hdv_mainframe", this, "DoMyRedraw()");
570  checkbuttons["fdctruth"]->Connect("Clicked()","hdv_mainframe", this, "DoMyRedraw()");
571  checkbuttons["tof"]->Connect("Clicked()","hdv_mainframe", this, "DoMyRedraw()");
572  checkbuttons["toftruth"]->Connect("Clicked()","hdv_mainframe", this, "DoMyRedraw()");
573  checkbuttons["bcal"]->Connect("Clicked()","hdv_mainframe", this, "DoMyRedraw()");
574  checkbuttons["bcaltruth"]->Connect("Clicked()","hdv_mainframe", this, "DoMyRedraw()");
575  checkbuttons["fcal"]->Connect("Clicked()","hdv_mainframe", this, "DoMyRedraw()");
576  checkbuttons["fcaltruth"]->Connect("Clicked()","hdv_mainframe", this, "DoMyRedraw()");
577  checkbuttons["ccal"]->Connect("Clicked()","hdv_mainframe", this, "DoMyRedraw()");
578  checkbuttons["trajectories"]->Connect("Clicked()","hdv_mainframe", this, "DoMyRedraw()");
579 
580  for (Int_t n=1;n<debugermf->GetNTrCand();n++){
581  char str1[128];
582  sprintf(str1,"Candidate%d",n);
583  checkbuttons[str1]->Connect("Clicked()","hdv_mainframe", this, "DoMyRedraw()");
584  }
585 
586  for (Int_t n=1;n<debugermf->GetNTrWB();n++){
587  char str1[128];
588  sprintf(str1,"WireBased%d",n);
589  checkbuttons[str1]->Connect("Clicked()","hdv_mainframe", this, "DoMyRedraw()");
590  }
591 
592  for (Int_t n=1;n<debugermf->GetNTrTB();n++){
593  char str1[128];
594  sprintf(str1,"TimeBased%d",n);
595  checkbuttons[str1]->Connect("Clicked()","hdv_mainframe", this, "DoMyRedraw()");
596  }
597 
598  candidatesfactory->Connect("Selected(Int_t)","hdv_mainframe", this, "DoMyRedraw()");
599  wiretracksfactory->Connect("Selected(Int_t)","hdv_mainframe", this, "DoMyRedraw()");
600  timetracksfactory->Connect("Selected(Int_t)","hdv_mainframe", this, "DoMyRedraw()");
601  chargedtracksfactory->Connect("Selected(Int_t)","hdv_mainframe", this, "DoMyRedraw()");
602  reconfactory->Connect("Selected(Int_t)","hdv_mainframe", this, "DoUpdateTrackLabels()");
603 
604  endviewA->GetCanvas()->Connect("Selected(TVirtualPad*, TObject*, Int_t)", "hdv_mainframe", this, "DoEndViewAEvent(TVirtualPad*, TObject*, Int_t)");
605  endviewB->GetCanvas()->Connect("Selected(TVirtualPad*, TObject*, Int_t)", "hdv_mainframe", this, "DoEndViewBEvent(TVirtualPad*, TObject*, Int_t)");
606 
607  // Set up timer to call the DoTimer() method repeatedly
608  // so events can be automatically advanced.
609  timer = new TTimer();
610  timer->Connect("Timeout()", "hdv_mainframe", this, "DoTimer()");
611  sleep_time = 250;
612  timer->Start(sleep_time, kFALSE);
613 
614  // Finish up and map the window
615  SetWindowName("Hall-D Event Viewer");
616  SetIconName("HDView");
617  MapSubwindows();
618  Resize(GetDefaultSize());
619  MapWindow();
620 
621  // Call Resize method of some group frames to get them to shrink down to smallest size
622  viewcontrols->Resize();
623  eventinfo->Resize();
624  eventcontrols->Resize();
625  inspectors->Resize();
626 }
627 
628 //-------------------
629 // ReadPreferences
630 //-------------------
632 {
633  // Preferences file is "${HOME}/.hdview2"
634  const char *home = getenv("HOME");
635  if(!home)return;
636 
637  // Try and open file
638  string fname = string(home) + "/.hdview2";
639  ifstream ifs(fname.c_str());
640  if(!ifs.is_open())return;
641  cout<<"Reading preferences from \""<<fname<<"\" ..."<<endl;
642 
643  // Loop over lines
644  char line[1024];
645  while(!ifs.eof()){
646  ifs.getline(line, 1024);
647  if(strlen(line)==0)continue;
648  if(line[0] == '#')continue;
649  string str(line);
650 
651  // Break line into tokens
652  vector<string> tokens;
653  string buf; // Have a buffer string
654  stringstream ss(str); // Insert the string into a stream
655  while (ss >> buf)tokens.push_back(buf);
656  if(tokens.size()<1)continue;
657 
658  // Check first token to decide what to do
659  if(tokens[0] == "checkbutton"){
660  if(tokens.size()!=4)continue; // should be of form "checkbutton name = value" with white space on either side of the "="
661  map<string, TGCheckButton*>::iterator it = checkbuttons.find(tokens[1]);
662  if(it != checkbuttons.end()){
663  if(tokens[3] == "on")(it->second)->SetState(kButtonDown);
664  }
665  }
666 
667  if(tokens[0] == "DTrackCandidate"){
668  if(tokens.size()!=3)continue; // should be of form "DTrackCandidate = tag" with white space on either side of the "="
669  default_candidate = tokens[2];
670  }
671 
672  if(tokens[0] == "DTrackWireBased"){
673  if(tokens.size()!=3)continue; // should be of form "DTrackWireBased = tag" with white space on either side of the "="
674  default_track = tokens[2];
675  }
676 
677  if(tokens[0] == "DTrackTimeBased"){
678  if(tokens.size()!=3)continue; // should be of form "DTrackTimeBased = tag" with white space on either side of the "="
679  default_track = tokens[2];
680  }
681 
682  if(tokens[0] == "Reconstructed"){
683  if(tokens.size()!=3)continue; // should be of form "Reconstructed = Factory:tag" with white space on either side of the "="
684  default_reconstructed = tokens[2];
685  }
686 
687  }
688 
689  // close file
690  ifs.close();
691 }
692 
693 //-------------------
694 // SavePreferences
695 //-------------------
697 {
698  // Preferences file is "${HOME}/.hdview2"
699  const char *home = getenv("HOME");
700  if(!home)return;
701 
702  // Try deleting old file and creating new file
703  string fname = string(home) + "/.hdview2";
704  unlink(fname.c_str());
705  ofstream ofs(fname.c_str());
706  if(!ofs.is_open()){
707  cout<<"Unable to create preferences file \""<<fname<<"\"!"<<endl;
708  return;
709  }
710 
711  // Write header
712  time_t t = time(NULL);
713  ofs<<"##### hdview2 preferences file ###"<<endl;
714  ofs<<"##### Auto-generated on "<<ctime(&t)<<endl;
715  ofs<<endl;
716 
717  // Write all checkbuttons that are "on"
718  map<string, TGCheckButton*>::iterator iter;
719  for(iter=checkbuttons.begin(); iter!=checkbuttons.end(); iter++){
720  TGCheckButton *but = iter->second;
721  if(but->GetState() == kButtonDown){
722  ofs<<"checkbutton "<<(iter->first)<<" = on"<<endl;
723  }
724  }
725  ofs<<endl;
726 
727  ofs<<"DTrackCandidate = "<<(candidatesfactory->GetTextEntry()->GetText())<<endl;
728  ofs<<"DTrackWireBased = "<<(wiretracksfactory->GetTextEntry()->GetText())<<endl;
729  ofs<<"DTrackTimeBased = "<<(timetracksfactory->GetTextEntry()->GetText())<<endl;
730  ofs<<"Reconstructed = "<<(reconfactory->GetTextEntry()->GetText())<<endl;
731 
732  ofs<<endl;
733  ofs.close();
734  cout<<"Preferences written to \""<<fname<<"\""<<endl;
735 }
736 
737 //-------------------
738 // SetRange
739 //-------------------
741 {
742  // The following is for the bug
743  //endviewA->GetCanvas()->Range(-1, -1, 1, 1);
744 
745  // Set the ranges of all canvases based on
746  // the current units (x/y or r/phi) and the zoom,pan
747  // settings
748 
750  // define range in each direction in cm
751  double x_width = 350.0/zoom_factor;
752  double y_width = x_width;
753  double z_width = 2.70*x_width;
754  double xlo = x0 - x_width/2.0;
755  double xhi = x0 + x_width/2.0;
756  double ylo = y0 - y_width/2.0;
757  double yhi = y0 + y_width/2.0;
758  double zlo = z0 - z_width*0.40;
759  double zhi = z0 + z_width*0.60;
760 
761  sideviewA->GetCanvas()->cd();
762  sideviewA->GetCanvas()->Range(zlo, xlo, zhi, xhi);
763  sideviewB->GetCanvas()->cd();
764  sideviewB->GetCanvas()->Range(zlo, ylo, zhi, yhi);
765 
766  // Zoom in a little on the end views
767  double end_to_side_ratio=1.8;
768  xlo/=end_to_side_ratio;
769  xhi/=end_to_side_ratio;
770  ylo/=end_to_side_ratio;
771  yhi/=end_to_side_ratio;
772 
773  endviewA->GetCanvas()->cd();
774  endviewA->GetCanvas()->Range(xlo, ylo, xhi, yhi);
775  endviewB->GetCanvas()->cd();
776  endviewB->GetCanvas()->Range(xlo*1.3, ylo*1.3, xhi*1.3, yhi*1.3);
777  //endviewB->GetCanvas()->Range(-158, -158, 158, 158);
778  endviewAmf->SetRange(xlo, ylo, xhi, yhi);
779  endviewBmf->SetRange(xlo*1.3, ylo*1.3, xhi*1.3, yhi*1.3);
780  //endviewBmf->SetRange(-158, -158, 158, 158);
781 
782  }else{
783  // define range in each direction in cm, radians
784  double r_width = 400.0/zoom_factor;
785  //double phi_width = 2.0*M_PI/zoom_factor;
786  double z_width = 2.0*r_width/zoom_factor;
787  double rlo = r0 - r_width/2.0;
788  double rhi = r0 + r_width/2.0;
789  double zlo = z0 - z_width/2.0;
790  double zhi = z0 + z_width/2.0;
791  double philo = -0.2;
792  double phihi = 2.0*M_PI+0.2;
793 
794  sideviewA->GetCanvas()->cd();
795  sideviewA->GetCanvas()->Range(zlo, rlo, zhi, rhi);
796  sideviewB->GetCanvas()->cd();
797  sideviewB->GetCanvas()->Range(zlo, philo, zhi, phihi);
798 
799  // Zoom in a little on the end views in A
800  endviewA->GetCanvas()->cd();
801  endviewA->GetCanvas()->Range(philo, rlo/2.5, phihi, rhi/2.5);
802  endviewB->GetCanvas()->cd();
803  endviewB->GetCanvas()->Range(philo, rlo/10.0, phihi, rhi/1.9);
804  endviewAmf->SetRange(philo, rlo/2.5, phihi, rhi/2.5);
805  endviewBmf->SetRange(philo, rlo/10.0, phihi, rhi/1.9);
806  }
807 }
808 
809 //-------------------
810 // DoQuit
811 //-------------------
813 {
814  SavePreferences();
815 
816  japp->Quit();
817  japp->Fini();
818  delete japp;
819  japp = NULL;
820 
821  // This is supposed to return from the Run() method in "main()"
822  // since we call SetReturnFromRun(true), but it doesn't seem to work.
823  gApplication->Terminate(0);
824 }
825 
826 //-------------------
827 // DoNext
828 //-------------------
830 {
831  if(eventloop){
832  if(SKIP_EPICS_EVENTS){
833  while(true){
834  eventloop->OneEvent();
835  vector<const DEPICSvalue*> epicsvalues;
836  eventloop->Get(epicsvalues);
837  if(epicsvalues.empty()) break;
838  cout << "Skipping EPICS event " << eventloop->GetJEvent().GetEventNumber() << endl;
839  }
840  }else{
841  eventloop->OneEvent();
842  }
843  }
844 }
845 
846 //-------------------
847 // DoPrev
848 //-------------------
850 {
851  //eventloop->GotoEvent(current_eventnumber-1);
852  //eventloop->OneEvent();
853 }
854 
855 //-------------------
856 // DoStop
857 //-------------------
859 {
860  GO = 0;
861 }
862 
863 //-------------------
864 // DoCont
865 //-------------------
867 {
868  GO = 1;
869 }
870 
871 //-------------------
872 // DoTimer
873 //-------------------
875 {
876  /// This gets called periodically (value is set in constructor)
877  /// It is used to automatically call DoNext() periodically
878  /// so long as the global GO is set to 1.
879  if(GetCheckButton("continuous")){
880  DoNext();
881  if(sleep_time != (long)timer->GetTime())timer->SetTime(sleep_time);
882  }else{
883  if(sleep_time == 0)timer->SetTime(10);
884  }
885 }
886 
887 //-------------------
888 // DoOpenTrackInspector
889 //-------------------
891 {
892  if(trkmf==NULL){
893  trkmf = new trk_mainframe(this, NULL, 100, 100);
894  if(trkmf){
895  next->Connect("Clicked()","trk_mainframe", trkmf, "DoNewEvent()");
896  prev->Connect("Clicked()","trk_mainframe", trkmf, "DoNewEvent()");
897  }
898  }else{
899  trkmf->RaiseWindow();
900  trkmf->RequestFocus();
901  }
902 }
903 
904 //-------------------
905 // DoOpenOptionsWindow
906 //-------------------
908 {
909  if(optionsmf==NULL){
910  optionsmf = new hdv_optionsframe(this, NULL, 100, 100);
911  }else{
912  optionsmf->MapWindow();
913  optionsmf->RaiseWindow();
914  optionsmf->RequestFocus();
915  }
916 }
917 //-------------------
918 // DoOpenDebugerWindow
919 //-------------------
921 {
922  if(debugermf==NULL){
923  debugermf = new hdv_debugerframe(this, NULL, 100, 100);
924  }else{
925  debugermf->MapWindow();
926  debugermf->RaiseWindow();
927  debugermf->RequestFocus();
929  }
930 }
931 //-------------------
932 // DoOpenDebugerWindow
933 //-------------------
935 {
936  if(bcaldispmf==NULL){
937  bcaldispmf = new TCanvas("BCALHitCanvas", "BCAL Hit Distribution", 900, 900);
938  }
939 
941 }
942 //-------------------
943 // DoOpenDebugerWindow
944 //-------------------
946 {
948 
949 }
950 ///-------------------
951 // DoOpenFullListWindow
952 //-------------------
954 {
955  if(fulllistmf==NULL){
956  fulllistmf = new hdv_fulllistframe(this, NULL, 100, 100);
957  }else{
958  fulllistmf->MapWindow();
959  fulllistmf->RaiseWindow();
960  fulllistmf->RequestFocus();
962  }
963 }
964 
965 //-------------------
966 // DoOpenTOFInspector
967 //-------------------
969 {
970 
971 }
972 
973 //-------------------
974 // DoOpenFCALInspector
975 //-------------------
977 {
978 
979 }
980 
981 //-------------------
982 // DoOpenBCALInspector
983 //-------------------
985 {
986 
987 }
988 
989 //-------------------
990 // DoClearTrackInspectorPointer
991 //-------------------
993 {
994  trkmf = NULL;
995 }
996 
997 //-------------------
998 // DoClearOptionsWindowPointer
999 //-------------------
1001 {
1002  optionsmf = NULL;
1003 }
1004 
1005 //-------------------
1006 // DoClearTOFInspectorPointer
1007 //-------------------
1009 {
1010 
1011 }
1012 
1013 //-------------------
1014 // DoClearFCALInspectorPointer
1015 //-------------------
1017 {
1018 
1019 }
1020 
1021 //-------------------
1022 // DoClearBCALInspectorPointer
1023 //-------------------
1025 {
1026 
1027 }
1028 
1029 //-------------------
1030 // DoEndViewAEvent
1031 //-------------------
1032 void hdv_mainframe::DoEndViewAEvent(TVirtualPad* pad, TObject* obj, Int_t event)
1033 {
1034  // event is the mouse button pushed (1=left, 2=center, 3=right)
1035  // It seems we can't detect double clicks here.
1036  if(endviewAmf==NULL){
1037  endviewAmf = new hdv_endviewAframe(this, NULL, 100, 100);
1038  }else{
1039  endviewAmf->MapWindow();
1040  endviewAmf->RaiseWindow();
1041  endviewAmf->RequestFocus();
1042  DoMyRedraw();
1043  }
1044 }
1045 
1046 
1047 //-------------------
1048 // DoEndViewBEvent
1049 //-------------------
1050 void hdv_mainframe::DoEndViewBEvent(TVirtualPad* pad, TObject* obj, Int_t event)
1051 {
1052  // event is the mouse button pushed (1=left, 2=center, 3=right)
1053  // It seems we can't detect double clicks here.
1054  if(endviewBmf==NULL){
1055  endviewBmf = new hdv_endviewBframe(this, NULL, 100, 100);
1056  }else{
1057  endviewBmf->MapWindow();
1058  endviewBmf->RaiseWindow();
1059  endviewBmf->RequestFocus();
1060  DoMyRedraw();
1061  }
1062 }
1063 
1064 //-------------------
1065 // DoPanXpos
1066 //-------------------
1068 {
1069  x0 += 50/zoom_factor;
1070  SetRange();
1071  DoMyRedraw();
1072 }
1073 
1074 //-------------------
1075 // DoPanXneg
1076 //-------------------
1078 {
1079  x0 -= 50/zoom_factor;
1080  SetRange();
1081  DoMyRedraw();
1082 }
1083 
1084 //-------------------
1085 // DoPanYpos
1086 //-------------------
1088 {
1089  y0 += 50/zoom_factor;
1090  SetRange();
1091  DoMyRedraw();
1092 }
1093 
1094 //-------------------
1095 // DoPanYneg
1096 //-------------------
1098 {
1099  y0 -= 50/zoom_factor;
1100  SetRange();
1101  DoMyRedraw();
1102 }
1103 
1104 //-------------------
1105 // DoPanZpos
1106 //-------------------
1108 {
1109  z0 += 50/zoom_factor;
1110  SetRange();
1111  DoMyRedraw();
1112 }
1113 
1114 //-------------------
1115 // DoPanZneg
1116 //-------------------
1118 {
1119  z0 -= 50/zoom_factor;
1120  SetRange();
1121  DoMyRedraw();
1122 }
1123 
1124 //-------------------
1125 // DoZoomIn
1126 //-------------------
1128 {
1129  zoom_factor*=1.25;
1130  SetRange();
1131  DoMyRedraw();
1132  //if(gMYPROC)gMYPROC->evnt(eventloop, current_eventnumber);
1133 }
1134 
1135 //-------------------
1136 // DoZoomOut
1137 //-------------------
1139 {
1140  zoom_factor/=1.25;
1141  SetRange();
1142  DoMyRedraw();
1143  //if(gMYPROC)gMYPROC->evnt(eventloop, current_eventnumber);
1144 }
1145 
1146 //-------------------
1147 // DoReset
1148 //-------------------
1150 {
1151  x0 = 0.0;
1152  y0 = 0.0;
1153  z0 = 350.0;
1154  zoom_factor = 1.0;
1155  DoMyRedraw();
1156 }
1157 
1158 
1159 //-------------------
1160 // DoMyRedraw
1161 //-------------------
1163 {
1164  // Make sure canvases have proper ranges
1165  SetRange();
1166 
1167  // Delete any existing graphics objects
1168  for(unsigned int i=0; i<graphics_sideA.size(); i++)delete graphics_sideA[i];
1169  for(unsigned int i=0; i<graphics_sideB.size(); i++)delete graphics_sideB[i];
1170  for(unsigned int i=0; i<graphics_endA.size(); i++)delete graphics_endA[i];
1171  for(unsigned int i=0; i<graphics_endB.size(); i++)delete graphics_endB[i];
1172  graphics_sideA.clear();
1173  graphics_sideB.clear();
1174  graphics_endA.clear();
1175  graphics_endB.clear();
1176 
1177 
1178  // Draw detectors depending on coordinate system we're using
1179  if(coordinatetype == COORD_XY){
1180  DrawDetectorsXY(); // Draw Detectors
1181  }else{
1182  DrawDetectorsRPhi(); // Draw Detectors
1183  }
1184 
1185  // Collect all hits for display
1186  gMYPROC->FillGraphics();
1187 
1188  // put collected hits into appropriate views
1192 
1193  // Draw detector hits and tracks for the correct coordinates in all views
1194  vector<MyProcessor::DGraphicSet>::iterator iter = gMYPROC->graphics.begin();
1195  for(; iter!=gMYPROC->graphics.end(); iter++){
1196 
1197  if(iter->type==MyProcessor::kMarker){
1198  // Markers
1199  TPolyMarker *sA = new TPolyMarker();
1200  TPolyMarker *sB = new TPolyMarker();
1201  TPolyMarker *eA = new TPolyMarker();
1202  sA->SetMarkerColor(iter->color);
1203  sB->SetMarkerColor(iter->color);
1204  eA->SetMarkerColor(iter->color);
1205  sA->SetMarkerSize(iter->size);
1206  sB->SetMarkerSize(iter->size);
1207  eA->SetMarkerSize(iter->size);
1208  sA->SetMarkerStyle(iter->marker_style);
1209  sB->SetMarkerStyle(iter->marker_style);
1210  eA->SetMarkerStyle(iter->marker_style);
1211  FillPoly(sA, sB, eA, iter->points); // in hdv_mainframe.h
1212  }else{
1213  // Lines
1214  TPolyLine *sA = new TPolyLine();
1215  TPolyLine *sB = new TPolyLine();
1216  TPolyLine *eA = new TPolyLine();
1217  sA->SetLineColor(iter->color);
1218  sB->SetLineColor(iter->color);
1219  eA->SetLineColor(iter->color);
1220  sA->SetLineWidth((Width_t)iter->size);
1221  sB->SetLineWidth((Width_t)iter->size);
1222  eA->SetLineWidth((Width_t)iter->size);
1223  sA->SetFillStyle(0);
1224  sB->SetFillStyle(0);
1225  eA->SetFillStyle(0);
1226  FillPoly(sA, sB, eA, iter->points); // in hdv_mainframe.h
1227 
1228  // Axial CDC wires will end up as having zero length in the end view
1229  // so we draw an additional marker in the end view for those cases.
1230  if(eA->GetN()==2){
1231  double *x = eA->GetX();
1232  double *y = eA->GetY();
1233  if(fabs(x[0]-x[1])<0.1 && fabs(y[0]==y[1])<0.1){
1234  TMarker *m = new TMarker(x[0], y[0], 8);
1235  m->SetMarkerColor(iter->color);
1236  m->SetMarkerSize(0.5);
1237  graphics_endA.push_back(m);
1238  }
1239  }
1240  }
1241  }
1242 
1243  // Add in additional view-specific objects
1244  if(coordinatetype == COORD_XY){
1245  for(unsigned int i=0; i<gMYPROC->graphics_xyA.size(); i++){
1246  graphics_endA.push_back(gMYPROC->graphics_xyA[i]);
1247  }
1248  for(unsigned int i=0; i<gMYPROC->graphics_xyB.size(); i++){
1249  graphics_endB.push_back(gMYPROC->graphics_xyB[i]);
1250  }
1251  }
1252 
1253  // Draw everything
1254  endviewA->GetCanvas()->cd(0);
1255  for(unsigned int i=0; i<graphics_endA.size(); i++){
1256  TPolyLine *l = dynamic_cast<TPolyLine*>(graphics_endA[i]);
1257  if(l && l->GetFillStyle()!=0){
1258  graphics_endA[i]->Draw("f");
1259  }else{
1260  graphics_endA[i]->Draw("");
1261  }
1262  }
1263  endviewA->GetCanvas()->Update();
1264  endviewAmf->DrawObjects(graphics_endA); // duplicate drawing of objects in big window
1265 
1266  endviewB->GetCanvas()->cd(0);
1267  for(unsigned int i=0; i<graphics_endB.size(); i++)graphics_endB[i]->Draw("f");
1268  for(unsigned int i=0; i<graphics_endB.size(); i++)graphics_endB[i]->Draw();
1269  endviewB->GetCanvas()->Update();
1270  endviewBmf->DrawObjects(graphics_endB); // duplicate drawing of objects in big window
1271 
1272  sideviewA->GetCanvas()->cd(0);
1273  for(unsigned int i=0; i<graphics_sideA.size(); i++)graphics_sideA[i]->Draw();
1274  sideviewA->GetCanvas()->Update();
1275  sideviewB->GetCanvas()->cd(0);
1276  for(unsigned int i=0; i<graphics_sideB.size(); i++)graphics_sideB[i]->Draw();
1277  sideviewB->GetCanvas()->Update();
1278 
1279  // Update track labels
1281 }
1282 
1283 //-------------------
1284 // DoSetDelay
1285 //-------------------
1287 {
1288  stringstream ss;
1289  ss<<delay->GetSelectedEntry()->GetTitle();
1290  double seconds;
1291  ss>>seconds;
1292  sleep_time = (int)(1000.0*seconds);
1293  timer->SetTime(sleep_time);
1294 }
1295 
1296 //-------------------
1297 // DoSetCoordinates
1298 //-------------------
1300 {
1301  coordinatetype = (coordsys_t)id;
1302 }
1303 
1304 //-------------------
1305 // DoUpdateTrackLabels
1306 //-------------------
1308 {
1310 
1311  throwninfo->Resize();
1312  reconinfo->Resize();
1313 }
1314 
1315 //-------------------
1316 // DrawDetectorsXY
1317 //-------------------
1319 {
1320  //============== Side A
1321  {
1322  sideviewA->GetCanvas()->cd(0);
1323  sideviewA->GetCanvas()->Clear();
1324 
1325 
1326 
1327  // ------ Target ------
1328  TBox *target = new TBox(TARGET_Zmid-TARGET_Zlen/2.0, -0.5, TARGET_Zmid+TARGET_Zlen/2.0, +0.5);
1329  target->SetFillColor(13);
1330  graphics_sideA.push_back(target);
1331 
1332 
1333  // ----- BCAL ------
1334  TBox *bcal1 = new TBox(BCAL_Zmin, BCAL_Rmin, BCAL_Zmin+BCAL_Zlen, BCAL_Rmax);
1335  TBox *bcal2 = new TBox(BCAL_Zmin, -BCAL_Rmin, BCAL_Zmin+BCAL_Zlen, -BCAL_Rmax);
1336  bcal1->SetFillColor(28);
1337  bcal2->SetFillColor(28);
1338  graphics_sideA.push_back(bcal1);
1339  graphics_sideA.push_back(bcal2);
1340 
1341  // ----- CDC ------
1342  TBox *cdc1 = new TBox(CDC_Zmin, CDC_Rmin, CDC_Zmin + CDC_Zlen, CDC_Rmax);
1343  TBox *cdc2 = new TBox(CDC_Zmin, -CDC_Rmin, CDC_Zmin + CDC_Zlen, -CDC_Rmax);
1344  cdc1->SetFillColor(17);
1345  cdc2->SetFillColor(17);
1346  graphics_sideA.push_back(cdc1);
1347  graphics_sideA.push_back(cdc2);
1348 
1349  // ----- FDC ------
1350  for(int i=0; i<4; i++){
1351  // Get FDC package positions from FDC library
1352  float zu = fdcwires[i*6][0]->origin.z();
1353  float zd = fdcwires[i*6+5][0]->origin.z();
1354  TBox *fdc1 = new TBox(zu, FDC_Rmin, zd, FDC_Rmax);
1355  TBox *fdc2 = new TBox(zu, -FDC_Rmin, zd, -FDC_Rmax);
1356  fdc1->SetFillColor(21);
1357  fdc2->SetFillColor(21);
1358  graphics_sideA.push_back(fdc1);
1359  graphics_sideA.push_back(fdc2);
1360  }
1361 
1362  // ----- TOF ------
1363  TBox *tof1 = new TBox(TOF_Zmin, TOF_Rmin, TOF_Zmin+TOF_Zlen, TOF_Rmax);
1364  TBox *tof2 = new TBox(TOF_Zmin, -TOF_Rmin, TOF_Zmin+TOF_Zlen, -TOF_Rmax);
1365  tof1->SetFillColor(11);
1366  tof2->SetFillColor(11);
1367  graphics_sideA.push_back(tof1);
1368  graphics_sideA.push_back(tof2);
1369 
1370  // ----- FCAL ------
1371  TBox *fcal1 = new TBox(FCAL_Zmin, FCAL_Rmin, FCAL_Zmin+FCAL_Zlen, FCAL_Rmax);
1372  TBox *fcal2 = new TBox(FCAL_Zmin, -FCAL_Rmin, FCAL_Zmin+FCAL_Zlen, -FCAL_Rmax);
1373  fcal1->SetFillColor(40);
1374  fcal2->SetFillColor(40);
1375  graphics_sideA.push_back(fcal1);
1376  graphics_sideA.push_back(fcal2);
1377 
1378  // ----- CCAL ------
1379  TBox *ccal1 = new TBox(CCAL_Zmin, CCAL_Rmin, CCAL_Zmin+CCAL_Zlen, CCAL_Rmax);
1380  TBox *ccal2 = new TBox(CCAL_Zmin, -CCAL_Rmin, CCAL_Zmin+CCAL_Zlen, -CCAL_Rmax);
1381  ccal1->SetFillColor(42);
1382  ccal2->SetFillColor(42);
1383  graphics_sideA.push_back(ccal1);
1384  graphics_sideA.push_back(ccal2);
1385 
1386  // ------ scale ------
1387  DrawScale(sideviewA->GetCanvas(), graphics_sideA);
1388  }
1389 
1390  //============== Side B
1391  {
1392  sideviewB->GetCanvas()->cd(0);
1393  sideviewB->GetCanvas()->Clear();
1394 
1395  // Side B is exactly the same as side A so just copy it
1396  for(unsigned int i=0; i<graphics_sideA.size(); i++){
1397  graphics_sideB.push_back(graphics_sideA[i]->Clone());
1398  }
1399  }
1400 
1401  //============== End A
1402  {
1403  endviewB->GetCanvas()->cd(0);
1404  endviewB->GetCanvas()->Clear();
1405 
1406  // ----- BCAL ------
1407  TEllipse *bcal1 = new TEllipse(0.0, 0.0, BCAL_Rmax, BCAL_Rmax);
1408  TEllipse *bcal2 = new TEllipse(0.0, 0.0, BCAL_Rmin, BCAL_Rmin);
1409  bcal1->SetFillColor(0);
1410  bcal2->SetFillColor(0);
1411  graphics_endA.push_back(bcal1);
1412  graphics_endA.push_back(bcal2);
1413 
1414  double dlayer1 = 0.5*(BCAL_MIDRAD-BCAL_Rmin)/(double)BCAL_LAYS1;
1415  //double dlayer2 = (BCAL_Rmax-BCAL_MIDRAD)/(double)BCAL_LAYS2;
1416  double dmodule = (double)TMath::TwoPi()/(double)BCAL_MODS;
1417  double dsector1 = dmodule/(double)BCAL_SECS1;
1418  double dsector2 = dmodule/(double)BCAL_SECS2;
1419 
1420  // Create polygon for each readout segment for use in coloring hits
1421  if(GetCheckButton("bcal")){
1422  for(int imod=0; imod<BCAL_MODS; imod++){
1423  double mod_phi = (double)imod*dmodule -2.0*dsector1 + BCAL_PHI_SHIFT;
1424  double r_min=BCAL_Rmin;
1425  for(int ilay=0; ilay<BCAL_LAYS1; ilay++){
1426  r_min+=dlayer1*ilay;
1427  double r_max = r_min+(ilay+1)*dlayer1;
1428  for(int isec=0; isec<BCAL_SECS1; isec++){
1429  double phimin = mod_phi + (double)isec*dsector1;
1430  double phimax = phimin + dsector1;
1431 
1432  double x[4], y[4];
1433  x[0] = r_min*cos(phimin);
1434  y[0] = r_min*sin(phimin);
1435  x[1] = r_max*cos(phimin);
1436  y[1] = r_max*sin(phimin);
1437  x[2] = r_max*cos(phimax);
1438  y[2] = r_max*sin(phimax);
1439  x[3] = r_min*cos(phimax);
1440  y[3] = r_min*sin(phimax);
1441 
1442  TPolyLine *poly = new TPolyLine(4, x, y);
1443  poly->SetLineColor(12);
1444  poly->SetLineWidth(0);
1445  poly->SetFillColor(0);
1446  poly->SetFillStyle(0);
1447  int chan = (imod+1)*1000 + (ilay+1)*100 + (isec+1)*10;
1448  graphics_endA.push_back(poly);
1449  bcalblocks[chan] = poly; // record so we can set the color later
1450  }
1451 
1452  for(int isec=0; isec<BCAL_SECS2; isec++){
1453  double phimin = mod_phi + (double)isec*dsector2;
1454  double phimax = phimin + dsector2;
1455 
1456  double x[5], y[5];
1457  x[0] = BCAL_MIDRAD*cos(phimin);
1458  y[0] = BCAL_MIDRAD*sin(phimin);
1459  x[1] = BCAL_Rmax*cos(phimin);
1460  y[1] = BCAL_Rmax*sin(phimin);
1461  x[2] = BCAL_Rmax*cos(phimax);
1462  y[2] = BCAL_Rmax*sin(phimax);
1463  x[3] = BCAL_MIDRAD*cos(phimax);
1464  y[3] = BCAL_MIDRAD*sin(phimax);
1465  x[4] = x[0];
1466  y[4] = y[0];
1467  TPolyLine *poly = new TPolyLine(5, x, y);
1468  poly->SetLineColor(12);
1469  poly->SetLineWidth(1);
1470  poly->SetFillColor(0);
1471  poly->SetFillStyle(0);
1472  int chan = (int)((imod+1)*1000 + (ilay+1+BCAL_LAYS1)*100 + (isec+1)*10);
1473  graphics_endA.push_back(poly);
1474  bcalblocks[chan] = poly; // record so we can set the color later
1475  }
1476  }
1477  }
1478  }
1479  // Draw lines to identify boundaries of readout segments
1480  for(int imod=0; imod<BCAL_MODS; imod++){
1481  // Vertical(sector) boundaries
1482  double mod_phi = (double)imod*dmodule -2.0*dsector1 + BCAL_PHI_SHIFT;
1483  for(int isec=0; isec<BCAL_SECS1; isec++){
1484  double rmin = BCAL_Rmin;
1485  double rmax = BCAL_MIDRAD;
1486  double phi = mod_phi + (double)isec*dsector1;
1487 
1488  TLine *l = new TLine(rmin*cos(phi), rmin*sin(phi), rmax*cos(phi), rmax*sin(phi));
1489  l->SetLineColor(isec==0 ? kBlack:12);
1490  l->SetLineWidth((Width_t)(isec==0 ? 2.5:1.0));
1491  graphics_endA.push_back(l);
1492  }
1493  for(int isec=0; isec<BCAL_SECS2; isec++){
1494  double rmin = BCAL_MIDRAD;
1495  double rmax = BCAL_Rmax;
1496  double phi = mod_phi + (double)isec*dsector2;
1497 
1498  TLine *l = new TLine(rmin*cos(phi), rmin*sin(phi), rmax*cos(phi), rmax*sin(phi));
1499  l->SetLineColor(isec==0 ? kBlack:12);
1500  l->SetLineWidth((Width_t)(isec==0 ? 2.5:1.0));
1501  graphics_endA.push_back(l);
1502  }
1503 
1504  // Horizontal(layer) boundaries
1505  double r=BCAL_Rmin;
1506  for(int ilay=0; ilay<BCAL_LAYS1; ilay++){
1507  r+=dlayer1*ilay;
1508  TLine *l = new TLine(r*cos(mod_phi), r*sin(mod_phi), r*cos(mod_phi+dmodule), r*sin(mod_phi+dmodule));
1509  l->SetLineColor(ilay==0 ? kBlack:12);
1510  l->SetLineWidth((Width_t)(ilay==0 ? 1.0:1.0));
1511  graphics_endA.push_back(l);
1512  }
1513 
1514  TLine *l = new TLine(BCAL_MIDRAD*cos(mod_phi), BCAL_MIDRAD*sin(mod_phi), BCAL_MIDRAD*cos(mod_phi+dmodule), BCAL_MIDRAD*sin(mod_phi+dmodule));
1515  l->SetLineColor(12);
1516  l->SetLineWidth((Width_t)(1.0));
1517  graphics_endA.push_back(l);
1518  }
1519 
1520  // ----- CDC ------
1521  TEllipse *cdc1 = new TEllipse(0.0, 0.0, CDC_Rmax, CDC_Rmax);
1522  TEllipse *cdc2 = new TEllipse(0.0, 0.0, CDC_Rmin, CDC_Rmin);
1523  cdc1->SetFillColor(17);
1524  cdc1->SetLineColor(17);
1525  cdc2->SetFillColor(10);
1526  graphics_endA.push_back(cdc1);
1527  graphics_endA.push_back(cdc2);
1528 
1529  // ----- FDC ------
1530  TEllipse *fdc1 = new TEllipse(0.0, 0.0, FDC_Rmax, FDC_Rmax);
1531  TEllipse *fdc2 = new TEllipse(0.0, 0.0, FDC_Rmin, FDC_Rmin);
1532  fdc1->SetFillColor(21);
1533  fdc1->SetLineColor(21);
1534  fdc2->SetFillColor(10);
1535  fdc2->SetLineColor(10);
1536  graphics_endA.push_back(fdc1);
1537  graphics_endA.push_back(fdc2);
1538 
1539 
1540  /*
1541  // ------ Start counter ------
1542  double r_start=7.7;
1543  for (unsigned int i=0;i<30;i++){
1544  double phi_0=0.209*i;
1545  double phi_1=0.209*(i+1);
1546  TLine *l = new TLine(r_start*cos(phi_0), r_start*sin(phi_0),
1547  r_start*cos(phi_1), r_start*sin(phi_1));
1548  l->SetLineColor(10);
1549  l->SetLineWidth(2.);
1550  graphics_endA.push_back(l);
1551  }
1552  */
1553 
1554  // ----- Start Counter -----
1555  // All units are in cm. These dimensions represent the geometry exactly.
1556  Double_t inner_radius = 7.7493; // Inner radius of the Start Counter
1557  Double_t outer_radius = 8.0493; // Outer radius of the Start Counter
1558  Double_t bottom_width = 1.6289; // Width of the bottom edge of scintillator
1559  Double_t top_width = 1.692; // Width of the top edge of scintillator
1560  Double_t dtr = 1.745329252e-02; // Conversion factor from degrees to radians
1561 
1562  // 5 x and 5 y coordinates for each of the 30 paddles
1563  Double_t x_coords[31][5];
1564  Double_t y_coords[31][5];
1565 
1566  // Initialize the x-coordinates of channel 0 (phi = [0, 12 deg] in hall coordinates)
1567  x_coords[0][0] = -outer_radius;
1568  x_coords[0][1] = -(outer_radius - top_width*sin(6.0*dtr));
1569  x_coords[0][2] = -(inner_radius - bottom_width*sin(6.0*dtr));
1570  x_coords[0][3] = -inner_radius;
1571  x_coords[0][4] = -outer_radius;
1572  // Initialize the x-coordinates of channel 0 (phi = [0, 12 deg] in hall coordinates)
1573  y_coords[0][0] = 0.0;
1574  y_coords[0][1] = top_width*cos(6.0*dtr);
1575  y_coords[0][2] = bottom_width*cos(6.0*dtr);
1576  y_coords[0][3] = 0.0;
1577  y_coords[0][4] = 0.0;
1578 
1579  // Create an array of TPolyLine objects
1580  TPolyLine *ch_pline[30];
1581 
1582  // Define array of points which define the individual scintillators
1583  for (int i = 1; i < 31; i++)
1584  {
1585  // Contruct the x-coordinates of the 30 scintillator paddles
1586  x_coords[i][0] = x_coords[i-1][1];
1587  x_coords[i][1] = x_coords[i-1][1] + top_width*sin((6.0 + 12.0*i)*dtr);
1588  x_coords[i][2] = x_coords[i-1][2] + bottom_width*sin((6.0 + 12.0*i)*dtr);
1589  x_coords[i][3] = x_coords[i-1][2];
1590  x_coords[i][4] = x_coords[i-1][1];
1591  // Construct the y-coordinates of the 30 scintillator paddles
1592  y_coords[i][0] = y_coords[i-1][1];
1593  y_coords[i][1] = y_coords[i-1][1] + top_width*cos((6.0 + 12.0*i)*dtr);
1594  y_coords[i][2] = y_coords[i-1][2] + bottom_width*cos((6.0 + 12.0*i)*dtr);
1595  y_coords[i][3] = y_coords[i-1][2];
1596  y_coords[i][4] = y_coords[i-1][1];
1597 
1598  // Construct the TPolyLine objects that defines the paddles
1599  Double_t x[5] = {x_coords[i-1][0], x_coords[i-1][1], x_coords[i-1][2], x_coords[i-1][3], x_coords[i-1][4]};
1600  Double_t y[5] = {y_coords[i-1][0], y_coords[i-1][1], y_coords[i-1][2], y_coords[i-1][3], y_coords[i-1][4]};
1601  ch_pline[i-1] = new TPolyLine(5, x, y);
1602  ch_pline[i-1]->SetFillColor(18);
1603  ch_pline[i-1]->SetLineColor(1);
1604  ch_pline[i-1]->SetLineWidth(2);
1605  graphics_endA.push_back(ch_pline[i-1]);
1606  }
1607 
1608  // ----- TARGET ------
1609  TEllipse *target = new TEllipse(0.0, 0.0, 0.5, 0.5);
1610  target->SetFillColor(13);
1611  graphics_endA.push_back(target);
1612 
1613  // ------ scale ------
1614  DrawScale(endviewA->GetCanvas(), graphics_endA);
1615  }
1616 
1617  //============== End B
1618  {
1619  endviewB->GetCanvas()->cd(0);
1620  endviewB->GetCanvas()->Clear();
1621 
1622  // ----- FCAL ------
1623  // Get list of blocks. Loop over all getting x,y coordinates of corners for all active ones.
1624 
1625  // Set up 4 2-D vectors that point from the center of a block to its
1626  // corners. This makes it easier to represent each corner as a vector
1627  // in lab coordinate which we can extract r, phi from.
1628  double blocksize = fcalgeom->blockSize();
1629  DVector2 shift[4];
1630  shift[0].Set(-blocksize/2, -blocksize/2); // these are ordered such that they
1631  shift[1].Set(-blocksize/2, +blocksize/2); // go in a clockwise manner. This
1632  shift[2].Set(+blocksize/2, +blocksize/2); // ensures the r/phi cooridinates also
1633  shift[3].Set(+blocksize/2, -blocksize/2); // define a single enclosed space
1634  fcalblocks.clear();
1635 
1636  if(GetCheckButton("fcal")){
1637  for(int chan=0; chan<DFCALGeometry::kMaxChannels; chan++){
1638  int row = fcalgeom->row(chan);
1639  int col = fcalgeom->column(chan);
1640  if(!fcalgeom->isBlockActive(row, col))continue;
1641  double x[5], y[5];
1642  for(int i=0; i<4; i++){
1643  DVector2 pos = shift[i] + fcalgeom->positionOnFace(chan);
1644  x[i] = pos.X();
1645  y[i] = pos.Y();
1646  }
1647  x[4] = x[0];
1648  y[4] = y[0];
1649 
1650  TPolyLine *poly = new TPolyLine(5, x, y);
1651  poly->SetFillColor(0);
1652  poly->SetLineColor(kBlack);
1653  graphics_endB.push_back(poly);
1654 
1655  fcalblocks[chan] = poly; // record so we can set the color later
1656  }
1657  }
1658 
1659  // ----- CCAL ------
1660  // Get list of blocks. Loop over all getting x,y coordinates of corners for all active ones.
1661 
1662  // Set up 4 2-D vectors that point from the center of a block to its
1663  // corners. This makes it easier to represent each corner as a vector
1664  // in lab coordinate which we can extract r, phi from.
1665  blocksize = 2.0;
1666  shift[0].Set(-blocksize/2, -blocksize/2); // these are ordered such that they
1667  shift[1].Set(-blocksize/2, +blocksize/2); // go in a clockwise manner. This
1668  shift[2].Set(+blocksize/2, +blocksize/2); // ensures the r/phi coordinates also
1669  shift[3].Set(+blocksize/2, -blocksize/2); // define a single enclosed space
1670  ccalblocks.clear();
1671 
1672  if(GetCheckButton("ccal")){
1673  for(int irow=0; irow<12; irow++){
1674  for(int icol=0; icol<12; icol++){
1675  if( (irow==5 || irow==6) && (icol==5 || icol==6) ) continue;
1676 
1677  double center_x = (-6.0 + (icol+0.5))*2.0;
1678  double center_y = (-6.0 + (irow+0.5))*2.0;
1679  DVector2 mypos(center_x,center_y);
1680 
1681  double x[5], y[5];
1682  for(int i=0; i<4; i++){
1683  DVector2 pos = shift[i] + mypos;
1684  x[i] = pos.X();
1685  y[i] = pos.Y();
1686  }
1687  x[4] = x[0];
1688  y[4] = y[0];
1689 
1690  TPolyLine *poly = new TPolyLine(5, x, y);
1691  poly->SetFillColor(0);
1692  poly->SetLineColor(kBlack);
1693  graphics_endB.push_back(poly);
1694 
1695  int channel = icol + 12*(irow);
1696  ccalblocks[channel] = poly; // record so we can set the color later
1697  }
1698  }
1699 
1700  // If also drawing FCAL, draw an extra outline of the FCAL beam hole
1701  if(GetCheckButton("fcal")){
1702  double x[5] = {-6.0, -6.0, 6.0, 6.0, -6.0};
1703  double y[5] = {-6.0, 6.0, 6.0,-6.0, -6.0};
1704  TPolyLine *poly = new TPolyLine(5, x, y);
1705  poly->SetFillColor(0);
1706  poly->SetLineColor(kBlack);
1707  poly->SetLineWidth(3);
1708  poly->SetLineStyle(2);
1709  graphics_endB.push_back(poly);
1710  }
1711  }
1712 
1713  // ------- TOF ---------//
1714  tofblocks.clear();
1715  if(GetCheckButton("tof")){
1716 
1717  TPolyLine *pmtPline[4][44] = {{ NULL }, { NULL }};
1718 
1719  // 38 PMTs for the standard modules in each side
1720  Double_t pmtX[4][44][5];
1721  Double_t pmtY[4][44][5];
1722 
1723  Double_t x[5];
1724  Double_t y[5];
1725 
1726  // origin: 0:DOWN; 1:NORTH; 2:UP; 3:SOUTH
1727  Double_t position_x[4] = {-126,-126,-126,126};
1728  Double_t position_y[4] = {-126,-126,126,-126};
1729 
1730  // PMTs from regular and half lenght modules with 6 cm x 14 cm
1731  Double_t step_x[4][5] = {{0,0,6,6,0},{0,-14,-14,0,0},{0,0,6,6,0},{0,14,14,0,0}};
1732  Double_t step_y[4][5] = {{0,-14,-14,0,0},{0,0,6,6,0},{0,14,14,0,0},{0,0,6,6,0}};
1733  Double_t step_xl[4][5] = {{0,0,3,3,0},{0,-20,-20,0,0},{0,0,3,3,0},{0,20,20,0,0}};
1734  Double_t step_yl[4][5] = {{0,-20,-20,0,0},{0,0,3,3,0},{0,20,20,0,0},{0,0,3,3,0}};
1735  Double_t step_X[4] = {6,0,6,0};
1736  Double_t step_Y[4] = {0,6,0,6};
1737  Double_t step_XL[4] = {3,0,3,0};
1738  Double_t step_YL[4] = {0,3,0,3};
1739 
1740 
1741  for (int sd=0; sd<4; sd++)
1742  {
1743  for (int i=0; i<44; i++)
1744  {
1745  for (int l=0; l<5; l++)
1746  {
1747  switch(l)
1748  {
1749  case 0:
1750  if (i == 19 || i == 20 || i == 23 || i == 24){
1751  pmtX[sd][i][l]=position_x[sd] + step_xl[sd][l];
1752  pmtY[sd][i][l]=position_y[sd] + step_yl[sd][l];
1753  }
1754  else{
1755  pmtX[sd][i][l]=position_x[sd] + step_x[sd][l];
1756  pmtY[sd][i][l]=position_y[sd] + step_y[sd][l];
1757  }
1758  break;
1759  case 1:
1760  if (i == 19 || i == 20 || i == 23 || i == 24){
1761  pmtX[sd][i][l]=position_x[sd] + step_xl[sd][l];
1762  pmtY[sd][i][l]=position_y[sd] + step_yl[sd][l];
1763  }
1764  else{
1765  pmtX[sd][i][l]=position_x[sd] + step_x[sd][l];
1766  pmtY[sd][i][l]=position_y[sd] + step_y[sd][l];
1767  }
1768  break;
1769  case 2:
1770  if (i == 19 || i == 20 || i == 23 || i == 24){
1771  pmtX[sd][i][l]=position_x[sd] + step_xl[sd][l];
1772  pmtY[sd][i][l]=position_y[sd] + step_yl[sd][l];
1773  }
1774  else{
1775  pmtX[sd][i][l]=position_x[sd] + step_x[sd][l];
1776  pmtY[sd][i][l]=position_y[sd] + step_y[sd][l];
1777  }
1778  break;
1779  case 3:
1780  if (i == 19 || i == 20 || i == 23 || i == 24){
1781  pmtX[sd][i][l]=position_x[sd] + step_xl[sd][l];
1782  pmtY[sd][i][l]=position_y[sd] + step_yl[sd][l];
1783  }
1784  else{
1785  pmtX[sd][i][l]=position_x[sd] + step_x[sd][l];
1786  pmtY[sd][i][l]=position_y[sd] + step_y[sd][l];
1787  }
1788  break;
1789  case 4:
1790  if (i == 19 || i == 20 || i == 23 || i == 24){
1791  pmtX[sd][i][l]=position_x[sd] + step_xl[sd][l];
1792  pmtY[sd][i][l]=position_y[sd] + step_yl[sd][l];
1793  }
1794  else{
1795  pmtX[sd][i][l]=position_x[sd] + step_x[sd][l];
1796  pmtY[sd][i][l]=position_y[sd] + step_y[sd][l];
1797  }
1798  break;
1799  }
1800  }
1801  if ( i == 19 || i == 20 || i == 23 || i == 24){
1802  position_x[sd] = position_x[sd] + step_XL[sd];
1803  position_y[sd] = position_y[sd] + step_YL[sd];
1804  }
1805  else{
1806  position_x[sd] = position_x[sd] + step_X[sd];
1807  position_y[sd] = position_y[sd] + step_Y[sd];
1808  }
1809  }
1810  }
1811 
1812  for (int sd=0; sd<4; sd++) // for the 4 sides
1813  {
1814  for (int j=0; j<44; j++) // PMT for the standard modules
1815  {
1816  for (int q=0; q<5; q++)
1817  {
1818  x[q] = pmtX[sd][j][q];
1819  y[q] = pmtY[sd][j][q];
1820  }
1821  pmtPline[sd][j] = new TPolyLine(5,x,y);
1822  }
1823  }
1824 
1825  int tof_count = 0;
1826  for (int sd=0; sd<4; sd++) // for the 4 sides
1827  {
1828  for (int j=0; j<44; j++)
1829  {
1830  pmtPline[sd][j]->SetFillColor(1);
1831  pmtPline[sd][j]->SetLineColor(41);
1832  pmtPline[sd][j]->SetLineWidth(2);
1833  tof_count++;
1834  graphics_endB.push_back(pmtPline[sd][j]);
1835  tofblocks[sd][tof_count] = pmtPline[sd][j];
1836  }
1837  tof_count = 0;
1838  }
1839 
1840  } // close the if tof-check button
1841 
1842  // ------ scale ------
1843  DrawScale(endviewB->GetCanvas(), graphics_endB);
1844  }
1845 
1846  //=============== Draw axes arrows
1847  // (this is done here since the sideB graphics are copied from sideA)
1848  DrawAxes(sideviewA->GetCanvas(), graphics_sideA, "Z", "X");
1849  DrawAxes(sideviewB->GetCanvas(), graphics_sideB, "Z", "Y");
1850  DrawAxes(endviewA->GetCanvas(), graphics_endA, "X", "Y");
1851  DrawAxes(endviewB->GetCanvas(), graphics_endB, "X", "Y");
1852 
1853 
1854  //=============== Draw view labels
1855  DrawLabel(sideviewA->GetCanvas(), graphics_sideA, "top view (looking down from above detector)");
1856  DrawLabel(sideviewA->GetCanvas(), graphics_sideB, "side view from beam right (south)");
1857  DrawLabel(endviewA->GetCanvas(), graphics_endA, "BCAL view from downstream looking upstream");
1858  DrawLabel(endviewB->GetCanvas(), graphics_endB, "FCAL view from downstream looking upstream");
1859 }
1860 
1861 //-------------------
1862 // DrawDetectorsRPhi
1863 //-------------------
1865 {
1866  //============== Side A R vs. z
1867  {
1868  sideviewA->GetCanvas()->cd(0);
1869  sideviewA->GetCanvas()->Clear();
1870 
1871  // ------ Target ------
1872  TBox *target = new TBox(TARGET_Zmid-TARGET_Zlen/2.0, 0.0, TARGET_Zmid+TARGET_Zlen/2.0, 0.5);
1873  target->SetFillColor(13);
1874  graphics_sideA.push_back(target);
1875 
1876  // ----- BCAL ------
1877  TBox *bcal1 = new TBox(BCAL_Zmin, BCAL_Rmin, BCAL_Zmin+BCAL_Zlen, BCAL_Rmax);
1878  bcal1->SetFillColor(28);
1879  graphics_sideA.push_back(bcal1);
1880 
1881  // ----- CDC ------
1882  TBox *cdc1 = new TBox(CDC_Zmin, CDC_Rmin, CDC_Zmin + CDC_Zlen, CDC_Rmax);
1883  cdc1->SetFillColor(17);
1884  graphics_sideA.push_back(cdc1);
1885 
1886  // ----- FDC ------
1887  for(int i=0; i<4; i++){
1888  // Get FDC package positions from FDC library
1889  float zu = fdcwires[i*6][0]->origin.z();
1890  float zd = fdcwires[i*6+5][0]->origin.z();
1891  TBox *fdc1 = new TBox(zu, FDC_Rmin, zd, FDC_Rmax);
1892  fdc1->SetFillColor(21);
1893  graphics_sideA.push_back(fdc1);
1894  }
1895 
1896  // ----- TOF ------
1897  TBox *tof1 = new TBox(TOF_Zmin, TOF_Rmin, TOF_Zmin+TOF_Zlen, TOF_Rmax);
1898  tof1->SetFillColor(11);
1899  graphics_sideA.push_back(tof1);
1900 
1901  // ----- FCAL ------
1902  TBox *fcal1 = new TBox(FCAL_Zmin, FCAL_Rmin, FCAL_Zmin+FCAL_Zlen, FCAL_Rmax);
1903  fcal1->SetFillColor(40);
1904  graphics_sideA.push_back(fcal1);
1905 
1906  // ------ scale ------
1907  DrawScale(endviewA->GetCanvas(), graphics_endA);
1908  }
1909 
1910  //============== Side B Phi vs. z
1911  {
1912  sideviewB->GetCanvas()->cd(0);
1913  sideviewB->GetCanvas()->Clear();
1914 
1915  // ------ Target ------
1916  TBox *target = new TBox(TARGET_Zmid-TARGET_Zlen/2.0, 0.0, TARGET_Zmid+TARGET_Zlen/2.0, 2.0*M_PI);
1917  target->SetFillColor(13);
1918  graphics_sideB.push_back(target);
1919 
1920  // ----- BCAL ------
1921  TBox *bcal1 = new TBox(BCAL_Zmin, 0.0, BCAL_Zmin+BCAL_Zlen, 2.0*M_PI);
1922  bcal1->SetFillColor(28);
1923  graphics_sideB.push_back(bcal1);
1924 
1925  // ----- CDC ------
1926  TBox *cdc1 = new TBox(CDC_Zmin, 0.0, CDC_Zmin + CDC_Zlen, 2.0*M_PI);
1927  cdc1->SetFillColor(17);
1928  graphics_sideB.push_back(cdc1);
1929 
1930  // ----- FDC ------
1931  for(int i=0; i<4; i++){
1932  // Get FDC package positions from FDC library
1933  float zu = fdcwires[i*6][0]->origin.z();
1934  float zd = fdcwires[i*6+5][0]->origin.z();
1935 
1936  TBox *fdc1 = new TBox(zu, 0.0, zd, 2.0*M_PI);
1937  fdc1->SetFillColor(21);
1938  graphics_sideB.push_back(fdc1);
1939  }
1940 
1941  // ----- TOF ------
1942  TBox *tof1 = new TBox(TOF_Zmin, 0.0, TOF_Zmin+TOF_Zlen, 2.0*M_PI);
1943  tof1->SetFillColor(11);
1944  graphics_sideB.push_back(tof1);
1945 
1946  // ----- FCAL ------
1947  TBox *fcal1 = new TBox(FCAL_Zmin, 0.0, FCAL_Zmin+FCAL_Zlen, 2.0*M_PI);
1948  fcal1->SetFillColor(40);
1949  graphics_sideB.push_back(fcal1);
1950 
1951  // ------ scale ------
1952  DrawScale(endviewA->GetCanvas(), graphics_endA);
1953  }
1954 
1955  //============== End A R vs. phi
1956  {
1957  endviewA->GetCanvas()->cd(0);
1958  endviewA->GetCanvas()->Clear();
1959 
1960  // ----- BCAL ------
1961  TBox *bcal1 = new TBox(0.0, BCAL_Rmin, 2.0*M_PI, BCAL_Rmax);
1962  bcal1->SetFillColor(28);
1963  graphics_endA.push_back(bcal1);
1964 
1965  // ----- CDC ------
1966  TBox *cdc1 = new TBox(0.0, CDC_Rmin, 2.0*M_PI, CDC_Rmax);
1967  cdc1->SetFillColor(17);
1968  graphics_endA.push_back(cdc1);
1969 
1970  // ----- FDC ------
1971  TBox *fdc1 = new TBox(0.0, FDC_Rmin, 2.0*M_PI, FDC_Rmax);
1972  fdc1->SetFillColor(21);
1973  graphics_endA.push_back(fdc1);
1974 
1975  // ----- TARGET ------
1976  TBox *target = new TBox(0.0, 0.0, 2.0*M_PI, 0.5);
1977  target->SetFillColor(13);
1978  graphics_endA.push_back(target);
1979 
1980  }
1981 
1982  //============== End B R vs. phi
1983  {
1984  endviewB->GetCanvas()->cd(0);
1985  endviewB->GetCanvas()->Clear();
1986 
1987  // ----- FCAL ------
1988  // Get list of blocks. Loop over all getting x,y coordinates of corners for all active ones.
1989 
1990  // Set up 4 2-D vectors that point from the center of a block to its
1991  // corners. This makes it easier to represent each corner as a vector
1992  // in lab corrdinate whch we can extract r, phi from.
1993  double blocksize = fcalgeom->blockSize();
1994  DVector2 shift[4];
1995  shift[0].Set(-blocksize/2, -blocksize/2); // these are ordered such that they
1996  shift[1].Set(-blocksize/2, +blocksize/2); // go in a clockwise manner. This
1997  shift[2].Set(+blocksize/2, +blocksize/2); // ensures the r/phi cooridinates also
1998  shift[3].Set(+blocksize/2, -blocksize/2); // define a single enclosed space
1999  fcalblocks.clear();
2000  for(int chan=0; chan<DFCALGeometry::kMaxChannels; chan++){
2001  int row = fcalgeom->row(chan);
2002  int col = fcalgeom->column(chan);
2003  if(!fcalgeom->isBlockActive(row, col))continue;
2004  double r[4], phi[4];
2005  for(int i=0; i<4; i++){
2006  DVector2 pos = shift[i] + fcalgeom->positionOnFace(chan);
2007  r[i] = pos.Mod();
2008  phi[i] = pos.Phi_0_2pi(pos.Phi());
2009  }
2010 
2011  TPolyLine *poly = new TPolyLine(4, phi, r);
2012  poly->SetFillColor(18);
2013  poly->SetLineColor(kBlack);
2014  graphics_endB.push_back(poly);
2015 
2016  fcalblocks[chan] = poly; // record so we can set the color later
2017  }
2018  }
2019 
2020  //=============== Draw axes arrows
2021  DrawAxes(sideviewA->GetCanvas(), graphics_sideA, "Z", "R");
2022  DrawAxes(sideviewB->GetCanvas(), graphics_sideB, "Z", "#phi");
2023  DrawAxes(endviewA->GetCanvas(), graphics_endA, "#phi", "R");
2024  DrawAxes(endviewB->GetCanvas(), graphics_endB, "#phi", "R");
2025 }
2026 
2027 //-------------------
2028 // DrawAxes
2029 //-------------------
2030 void hdv_mainframe::DrawAxes(TCanvas *c, vector<TObject*> &graphics, const char *xlab, const char *ylab)
2031 {
2032  /// Create arrows indicating x and y axes with labels on the specified canvas
2033  /// and add them to the specified container of graphics objects to be draw later.
2034  double x1 = c->GetX1();
2035  double x2 = c->GetX2();
2036  double y1 = c->GetY1();
2037  double y2 = c->GetY2();
2038  double deltax = x2-x1;
2039  deltax *= c->GetYsizeReal()/c->GetXsizeReal();
2040  double deltay = y2-y1;
2041  double xlo = x1+0.04*deltax;
2042  double xhi = xlo + 0.075*deltax;
2043  double ylo = y1+0.04*deltay;
2044  double yhi = ylo + 0.075*deltay;
2045  TArrow *yarrow = new TArrow(xlo, ylo, xlo, yhi, 0.02, ">");
2046  yarrow->SetLineWidth((Width_t)1.5);
2047  graphics.push_back(yarrow);
2048 
2049  TLatex *ylabel = new TLatex(xlo, yhi+0.005*deltay, ylab);
2050  ylabel->SetTextAlign(21);
2051  graphics.push_back(ylabel);
2052 
2053  TArrow *xarrow = new TArrow(xlo, ylo, xhi, ylo, 0.02, ">");
2054  xarrow->SetLineWidth((Width_t)1.5);
2055  graphics.push_back(xarrow);
2056 
2057  TLatex *xlabel = new TLatex(xhi+0.005*deltax, ylo, xlab);
2058  xlabel->SetTextAlign(12);
2059  graphics.push_back(xlabel);
2060 }
2061 
2062 //-------------------
2063 // DrawScale
2064 //-------------------
2065 void hdv_mainframe::DrawScale(TCanvas *c, vector<TObject*> &graphics)
2066 {
2067  /// Create a scale label on the specified canvas and add it
2068  /// to the specified container of graphics objects to be draw later.
2069  double x1 = c->GetX1();
2070  double x2 = c->GetX2();
2071  double y1 = c->GetY1();
2072  double y2 = c->GetY2();
2073  double deltax = x2-x1;
2074  double deltay = y2-y1;
2075  double p = floor(log(0.1*deltax)/log(10.0));
2076  double m = floor(0.1*deltax/pow(10.0, p) + 0.5);
2077  double xlo = x1+0.72*deltax;
2078  double xhi = xlo + m*pow(10.0, p);
2079  double y = y1+0.04*deltay;
2080  TArrow *arrow = new TArrow(xlo, y, xhi, y, 0.02, "|-|");
2081  arrow->SetLineWidth((Width_t)1.0);
2082  graphics.push_back(arrow);
2083 
2084  const char *units="<out of range>";
2085  switch((int)p){
2086  case -5:
2087  units = "#mum";
2088  break;
2089  case -4:
2090  units = "#mum";
2091  break;
2092  case -3:
2093  m*=10.0;
2094  units = "#mum";
2095  break;
2096  case -2:
2097  m*=100.0;
2098  units="#mum";
2099  break;
2100  case -1:
2101  units="mm";
2102  break;
2103  case 0:
2104  units = "cm";
2105  break;
2106  case 1:
2107  m*=10.0;
2108  units = "cm";
2109  break;
2110  case 2:
2111  units = "m";
2112  break;
2113  case 3:
2114  m*=10.0;
2115  units = "m";
2116  break;
2117  case 4:
2118  m*=100.0;
2119  units = "m";
2120  break;
2121  case 5:
2122  units = "km";
2123  break;
2124  case 6:
2125  m*=10.0;
2126  units = "km";
2127  break;
2128  }
2129  char str[256];
2130  sprintf(str,"%d %s", (int)m, units);
2131  TLatex *label = new TLatex(xhi+0.01*deltax, y, str);
2132  label->SetTextAlign(12);
2133  graphics.push_back(label);
2134 }
2135 
2136 //-------------------
2137 // DrawLabel
2138 //-------------------
2139 void hdv_mainframe::DrawLabel(TCanvas *c, vector<TObject*> &graphics, const char *txt)
2140 {
2141  /// Create label on top of the specified canvas
2142  /// and add it to the specified container of graphics
2143  /// objects to be drawn later.
2144  double x1 = c->GetX1();
2145  double x2 = c->GetX2();
2146  double y1 = c->GetY1();
2147  double y2 = c->GetY2();
2148  double deltax = x2-x1;
2149  double deltay = y2-y1;
2150  deltax *= c->GetYsizeReal()/c->GetXsizeReal();
2151  double x = x1 + 0.005*deltax;
2152  double y = y2 - 0.003*deltay;
2153 
2154  TLatex *label = new TLatex(x, y, txt);
2155  label->SetTextAlign(13);
2156  label->SetTextSize(0.045);
2157  graphics.push_back(label);
2158 }
2159 
2160 
2161 //-------------------
2162 // SetEvent
2163 //-------------------
2164 void hdv_mainframe::SetEvent(ULong64_t id)
2165 {
2166  if(!event)return;
2167 
2168  stringstream ss;
2169  ss << id;
2170  event->SetTitle(ss.str().c_str());
2171  event->Draw();
2172 }
2173 
2174 //-------------------
2175 // SetRun
2176 //-------------------
2178 {
2179  if(!event)return;
2180 
2181  stringstream ss;
2182  ss << id;
2183  run->SetTitle(ss.str().c_str());
2184  run->Draw();
2185 }
2186 
2187 //-------------------
2188 // SetTrig
2189 //-------------------
2190 void hdv_mainframe::SetTrig(char *trigstring)
2191 {
2192  if(!event)return;
2193 
2194  trig->SetTitle(trigstring);
2195  trig->Draw();
2196 }
2197 
2198 
2199 //-------------------
2200 // SetSource
2201 //-------------------
2202 void hdv_mainframe::SetSource(string source)
2203 {
2204  this->source->SetTitle(source.c_str());
2205  this->source->Draw();
2206 }
2207 
2208 //-------------------
2209 // SetCandidateFactories
2210 //-------------------
2211 void hdv_mainframe::SetCandidateFactories(vector<string> &facnames)
2212 {
2213  /// Filter out the factories that provide "DTrackCandidate" objects
2214  /// and add their tags to the tracksfactory combobox.
2215  // Erase all current entries in the combobox and add back in
2216  // "<default>".
2217  candidatesfactory->RemoveAll();
2218  candidatesfactory->AddEntry("<default>", 0);
2219  candidatesfactory->GetTextEntry()->SetText("<default>");
2220  candidatesfactory->Select(0, kFALSE);
2221 
2222  for(unsigned int i=0; i< facnames.size(); i++){
2223  string name = "DTrackCandidate:";
2224  string::size_type pos = facnames[i].find(name);
2225  if(pos==string::npos)continue;
2226  string tag = facnames[i];
2227  tag.erase(0, name.size());
2228  candidatesfactory->AddEntry(tag.c_str(), i);
2229  if(tag==default_candidate){
2230  candidatesfactory->Select(i, kTRUE);
2231  candidatesfactory->GetTextEntry()->SetText(tag.c_str());
2232  }
2233  }
2234 }
2235 
2236 //-------------------
2237 // SetWireBasedTrackFactories
2238 //-------------------
2239 void hdv_mainframe::SetWireBasedTrackFactories(vector<string> &facnames)
2240 {
2241  /// Filter out the factories that provide "DTrackWireBased" objects
2242  /// and add their tags to the tracksfactory combobox.
2243 
2244  // Erase all current entries in the combobox and add back in
2245  // "<default>".
2246  wiretracksfactory->RemoveAll();
2247  wiretracksfactory->AddEntry("<default>", 0);
2248  wiretracksfactory->GetTextEntry()->SetText("<default>");
2249  wiretracksfactory->Select(0, kFALSE);
2250 
2251  for(unsigned int i=0; i< facnames.size(); i++){
2252  string name = "DTrackWireBased:";
2253  string::size_type pos = facnames[i].find(name);
2254  if(pos==string::npos)continue;
2255  string tag = facnames[i];
2256  tag.erase(0, name.size());
2257  wiretracksfactory->AddEntry(tag.c_str(), i+1);
2258  if(tag==default_track){
2259  wiretracksfactory->Select(i, kTRUE);
2260  wiretracksfactory->GetTextEntry()->SetText(tag.c_str());
2261  }
2262  }
2263 }
2264 
2265 //-------------------
2266 // SetTimeBasedTrackFactories
2267 //-------------------
2268 void hdv_mainframe::SetTimeBasedTrackFactories(vector<string> &facnames)
2269 {
2270  /// Filter out the factories that provide "DTrackTimeBased" objects
2271  /// and add their tags to the timetracksfactory combobox.
2272 
2273  // Erase all current entries in the combobox and add back in
2274  // "<default>".
2275  timetracksfactory->RemoveAll();
2276  timetracksfactory->AddEntry("<default>", 0);
2277  timetracksfactory->GetTextEntry()->SetText("<default>");
2278  timetracksfactory->Select(0, kFALSE);
2279 
2280  for(unsigned int i=0; i< facnames.size(); i++){
2281  string name = "DTrackTimeBased:";
2282  string::size_type pos = facnames[i].find(name);
2283  if(pos==string::npos)continue;
2284  string tag = facnames[i];
2285  tag.erase(0, name.size());
2286  timetracksfactory->AddEntry(tag.c_str(), i+1);
2287  if(tag==default_track){
2288  timetracksfactory->Select(i, kTRUE);
2289  timetracksfactory->GetTextEntry()->SetText(tag.c_str());
2290  }
2291  }
2292 }
2293 
2294 //-------------------
2295 // SetChargedTrackFactories
2296 //-------------------
2297 void hdv_mainframe::SetChargedTrackFactories(vector<string> &facnames)
2298 {
2299  /// Filter out the factories that provide "DChargedTrack" objects
2300  /// and add their tags to the chargedtracksfactory combobox.
2301 
2302  // Erase all current entries in the combobox and add back in
2303  // "<default>".
2304  chargedtracksfactory->RemoveAll();
2305  chargedtracksfactory->AddEntry("<default>", 0);
2306  chargedtracksfactory->GetTextEntry()->SetText("<default>");
2307  chargedtracksfactory->Select(0, kFALSE);
2308 
2309  for(unsigned int i=0; i< facnames.size(); i++){
2310  string name = "DChargedTrack:";
2311  string::size_type pos = facnames[i].find(name);
2312  if(pos==string::npos)continue;
2313  string tag = facnames[i];
2314  tag.erase(0, name.size());
2315  chargedtracksfactory->AddEntry(tag.c_str(), i+1);
2316  if(tag==default_track){
2317  chargedtracksfactory->Select(i, kTRUE);
2318  chargedtracksfactory->GetTextEntry()->SetText(tag.c_str());
2319  }
2320  }
2321 }
2322 
2323 
2324 
2325 //-------------------
2326 // SetReconstructedFactories
2327 //-------------------
2328 void hdv_mainframe::SetReconstructedFactories(vector<string> &facnames)
2329 {
2330  /// Filter out the factories that provide "DTrack" objects
2331  /// and add them to the reconfactory combobox.
2332 
2333  // Erase all current entries in the combobox and add back in
2334  // "<default>".
2335  int id =0;
2336  reconfactory->RemoveAll();
2337  reconfactory->AddEntry("DTrackTimeBased:", id++);
2338  reconfactory->Select(0, kFALSE);
2339  reconfactory->GetTextEntry()->SetText("DTrackTimeBased:");
2340 
2341  // Add DTrackTimeBased factories
2342  for(unsigned int i=0; i< facnames.size(); i++){
2343  string name = "DTrackTimeBased:";
2344  string::size_type pos = facnames[i].find(name);
2345  if(pos==string::npos)continue;
2346  string tag = facnames[i].substr(name.size(), facnames[i].size()-name.size());
2347  reconfactory->AddEntry(facnames[i].c_str(), id++);
2348  if(facnames[i]==default_reconstructed){
2349  reconfactory->Select(id-1, kTRUE);
2350  reconfactory->GetTextEntry()->SetText(facnames[i].c_str());
2351  }
2352  }
2353 
2354  // Add DTrackWireBased factories
2355  reconfactory->AddEntry("DTrackWireBased:", id++);
2356  for(unsigned int i=0; i< facnames.size(); i++){
2357  string name = "DTrackWireBased:";
2358  string::size_type pos = facnames[i].find(name);
2359  if(pos==string::npos)continue;
2360  string tag = facnames[i].substr(name.size(), facnames[i].size()-name.size());
2361  reconfactory->AddEntry(facnames[i].c_str(), id++);
2362  if(facnames[i]==default_reconstructed){
2363  reconfactory->Select(id-1, kTRUE);
2364  reconfactory->GetTextEntry()->SetText(facnames[i].c_str());
2365  }
2366  }
2367 
2368  // Add DTrackCandidate factories
2369  reconfactory->AddEntry("DTrackCandidate:", id++);
2370  for(unsigned int i=0; i< facnames.size(); i++){
2371  string name = "DTrackCandidate:";
2372  string::size_type pos = facnames[i].find(name);
2373  if(pos==string::npos)continue;
2374  string tag = facnames[i].substr(name.size(), facnames[i].size()-name.size());
2375  reconfactory->AddEntry(facnames[i].c_str(), id++);
2376  if(facnames[i]==default_reconstructed){
2377  reconfactory->Select(id-1, kTRUE);
2378  reconfactory->GetTextEntry()->SetText(facnames[i].c_str());
2379  }
2380  }
2381 
2382 
2383  // Add DNeutralTrack factories
2384  reconfactory->AddEntry("DNeutralParticle:", id++);
2385  for(unsigned int i=0; i< facnames.size(); i++){
2386  string name = "DNeutralParticle:";
2387  string::size_type pos = facnames[i].find(name);
2388  if(pos==string::npos)continue;
2389  string tag = facnames[i].substr(name.size(), facnames[i].size()-name.size());
2390  reconfactory->AddEntry(facnames[i].c_str(), id++);
2391  if(facnames[i]==default_reconstructed){
2392  reconfactory->Select(id-1, kTRUE);
2393  reconfactory->GetTextEntry()->SetText(facnames[i].c_str());
2394  }
2395  }
2396 
2397  // Add DChargedTrack factories
2398  reconfactory->AddEntry("DChargedTrack:", id++);
2399  for(unsigned int i=0; i< facnames.size(); i++){
2400  string name = "DChargedTrack:";
2401  string::size_type pos = facnames[i].find(name);
2402  if(pos==string::npos)continue;
2403  string tag = facnames[i].substr(name.size(), facnames[i].size()-name.size());
2404  reconfactory->AddEntry(facnames[i].c_str(), id++);
2405  if(facnames[i]==default_reconstructed){
2406  reconfactory->Select(id-1, kTRUE);
2407  reconfactory->GetTextEntry()->SetText(facnames[i].c_str());
2408  }
2409  }
2410 
2411 
2412 }
2413 
2414 //-------------------
2415 // GetCheckButton
2416 //-------------------
2418 {
2419  map<string, TGCheckButton*>::iterator iter = checkbuttons.find(who);
2420  if(iter==checkbuttons.end())return false;
2421  return iter->second->GetState()==kButtonDown;
2422 }
2423 //-------------------
2424 // AddCheckButtons
2425 //-------------------
2426 void hdv_mainframe::AddCheckButtons(map<string, TGCheckButton*> &checkbuttons)
2427 {
2428  this->checkbuttons.insert(checkbuttons.begin(), checkbuttons.end());
2429 }
2430 
2431 //-------------------
2432 // GetFactoryTag
2433 //-------------------
2434 const char* hdv_mainframe::GetFactoryTag(string who)
2435 {
2436  const char *tag = "";
2437 
2438  if(who=="DTrackWireBased"){
2439  tag = wiretracksfactory->GetTextEntry()->GetTitle();
2440  //tag = wiretracksfactory->GetSelectedEntry()->GetTitle();
2441  }
2442  if(who=="DTrackCandidate"){
2443  tag = candidatesfactory->GetTextEntry()->GetTitle();
2444  //tag = candidatesfactory->GetSelectedEntry()->GetTitle();
2445  }
2446  if(who=="DTrackTimeBased"){
2447  tag = timetracksfactory->GetTextEntry()->GetTitle();
2448  //tag = timetracksfactory->GetSelectedEntry()->GetTitle();
2449  }
2450  if (who=="DChargedTrack"){
2451  tag=chargedtracksfactory->GetTextEntry()->GetTitle();
2452  }
2453  if(string(tag) == "<default>")tag = "";
2454 
2455  return tag;
2456 }
2457 
2458 //-------------------
2459 // GetReconFactory
2460 //-------------------
2461 void hdv_mainframe::GetReconFactory(string &name, string &tag)
2462 {
2463  if(!reconfactory) return;
2464  if(!reconfactory->GetSelectedEntry()) return;
2465  if(!reconfactory->GetSelectedEntry()->GetTitle()) return;
2466  string nametag(reconfactory->GetSelectedEntry()->GetTitle());
2467  string::size_type pos = nametag.find(":");
2468  name = nametag.substr(0, pos);
2469  tag = nametag.substr(pos+1, nametag.size()-(pos+1));
2470 }
2471 
2472 //-------------------
2473 // GetFCALPolyLine
2474 //-------------------
2475 TPolyLine* hdv_mainframe::GetFCALPolyLine(int channel)
2476 {
2477  map<int, TPolyLine*>::iterator iter = fcalblocks.find(channel);
2478  if(iter==fcalblocks.end())return NULL;
2479  return iter->second;
2480 }
2481 
2482 //-------------------
2483 // GetFCALPolyLine
2484 //-------------------
2485 TPolyLine* hdv_mainframe::GetFCALPolyLine(float x, float y)
2486 {
2487  if(!fcalgeom)return NULL;
2488  int row = fcalgeom->row(y);
2489  int column = fcalgeom->column(x);
2490  return GetFCALPolyLine(fcalgeom->channel(row, column));
2491 }
2492 
2493 //-------------------
2494 // GetCCALPolyLine
2495 //-------------------
2496 TPolyLine* hdv_mainframe::GetCCALPolyLine(int row, int col)
2497 {
2498  int channel = col + 12*(row);
2499  map<int, TPolyLine*>::iterator iter = ccalblocks.find(channel);
2500  if(iter==ccalblocks.end())return NULL;
2501  return iter->second;
2502 }
2503 
2504 //-------------------
2505 // GetTOFPolyLine
2506 //-------------------
2507 
2508 TPolyLine* hdv_mainframe::GetTOFPolyLine(int translate_side, int tof_ch)
2509 {
2510  map <int, map<int, TPolyLine*> >::iterator iter;
2511  iter = tofblocks.find(translate_side);
2512  map <int, TPolyLine*>::iterator iter2 = iter->second.find(tof_ch);
2513  if(iter2==iter->second.end())return NULL;
2514  return iter2->second;
2515 }
2516 
2517 //-------------------
2518 // GetBCALPolyLine
2519 //-------------------
2520 TPolyLine* hdv_mainframe::GetBCALPolyLine(int module, int layer, int sector)
2521 {
2522  int chan = module*1000 + layer*100 + sector*10;
2523  map<int, TPolyLine*>::iterator iter = bcalblocks.find(chan);
2524  if(iter==bcalblocks.end()){
2525  _DBG_<<"ERROR: No BCAL readout segment display poly for module="<<module<<" layer="<<layer<<" sector="<<sector<<endl;
2526  return NULL;
2527  }
2528  return iter->second;
2529 }
2530 
2531 //-------------------
2532 // AddGraphicsSideA
2533 //-------------------
2534 void hdv_mainframe::AddGraphicsSideA(vector<TObject*> &v)
2535 {
2536  for(unsigned int i=0; i<v.size(); i++)graphics_sideA.push_back(v[i]);
2537 }
2538 
2539 //-------------------
2540 // AddGraphicsSideB
2541 //-------------------
2542 void hdv_mainframe::AddGraphicsSideB(vector<TObject*> &v)
2543 {
2544  for(unsigned int i=0; i<v.size(); i++)graphics_sideB.push_back(v[i]);
2545 }
2546 
2547 //-------------------
2548 // AddGraphicsEndA
2549 //-------------------
2550 void hdv_mainframe::AddGraphicsEndA(vector<TObject*> &v)
2551 {
2552  for(unsigned int i=0; i<v.size(); i++)graphics_endA.push_back(v[i]);
2553 }
2554 
2555 //-------------------
2556 // AddGraphicsEndB
2557 //-------------------
2558 void hdv_mainframe::AddGraphicsEndB(vector<TObject*> &v)
2559 {
2560  for(unsigned int i=0; i<v.size(); i++)graphics_endB.push_back(v[i]);
2561 }
void DoPanXpos(void)
TRootEmbeddedCanvas * sideviewA
static float FCAL_Zmin
void SetReconstructedFactories(vector< string > &facnames)
DApplication * dapp
void DoEndViewBEvent(TVirtualPad *pad, TObject *obj, Int_t event)
static float BCAL_SECS2
static float FCAL_Rmin
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)
void UpdateBcalDisp(void)
double rmax
hdv_fulllistframe * fulllistmf
void DoPanZneg(void)
void DoUpdateTrackLabels(void)
TGComboBox * chargedtracksfactory
static float TOF_Rmin
void SetTrig(char *trigstring)
char str[256]
void DoOpenFCALInspector(void)
Int_t layer
static float BCAL_LAYS1
TVector2 DVector2
Definition: DVector2.h:9
void DoSetDelay(Int_t)
bool GetCheckButton(string who)
map< string, TGCheckButton * > checkbuttons
static float TOF_Zmin
TPad * pad
Definition: psc_mon.C:73
vector< TObject * > graphics_tof_hits
Int_t GetNTrTB(void)
Double_t x[NCHANNELS]
Definition: st_tw_resols.C:39
void DoClearBCALInspectorPointer(void)
char string[256]
static DTOFGeometry * tofgeom
void DrawDetectorsXY(void)
void DoOpenFullListWindow(void)
sprintf(text,"Post KinFit Cut")
void AddGraphicsSideA(vector< TObject * > &v)
#define c
TGTextButton * prev
TPolyLine * GetCCALPolyLine(int row, int col)
vector< TObject * > graphics_xz
#define y
void DoTimer(void)
static vector< vector< DFDCWire * > > fdcwires
void DoReset(void)
void DoSetCoordinates(Int_t)
static float TARGET_Zmid
void SetEvent(ULong64_t id)
void FillPoly(T *sA, T *sB, T *eA, vector< TVector3 > &v)
static float FCAL_Zlen
JEventLoop * eventloop
Definition: hdview2.cc:16
map< int, TPolyLine * > bcalblocks
map< int, TPolyLine * > fcalblocks
void DoQuit(void)
vector< TObject * > graphics_endA
vector< DGraphicSet > graphics
void DoOpenBCALInspector(void)
bool SKIP_EPICS_EVENTS
Definition: hdview2.cc:12
void SetTimeBasedTrackFactories(vector< string > &facnames)
static float CCAL_Zmin
void UpdateTrackLabels(void)
void DoNext(void)
void FillGraphics(void)
string default_track
void DoClearTOFInspectorPointer(void)
void SetRange(double xlo, double ylo, double xhi, double yhi)
void DoClearFCALInspectorPointer(void)
double rmin
void DoCont(void)
DVector2 positionOnFace(int row, int column) const
static float BCAL_Zlen
hdv_debugerframe * debugermf
void DrawObjects(vector< TObject * > &graphics_endA)
map< string, vector< TGLabel * > > reconlabs
static float TOF_Zlen
JApplication * japp
void AddGraphicsEndA(vector< TObject * > &v)
double zoom_factor
TGTextButton * next
static float CDC_Rmax
string default_candidate
void AddGraphicsEndB(vector< TObject * > &v)
map< int, map< int, TPolyLine * > > tofblocks
MyProcessor * gMYPROC
static float BCAL_MODS
TRootEmbeddedCanvas * endviewB
static float CCAL_Rmin
void DoPanYpos(void)
static float CCAL_Zlen
TEllipse * e
static float CDC_Zmin
map< int, TPolyLine * > ccalblocks
hdv_endviewBframe * endviewBmf
void DoPanYneg(void)
void DoOpenDebugerWindow(void)
TGLabel * source
TPolyLine * GetBCALPolyLine(int mod, int layer, int sector)
string default_reconstructed
void DoOpenTrackInspector(void)
void DrawObjects(vector< TObject * > &graphics_endB)
static double blockSize()
Definition: DFCALGeometry.h:48
TPolyLine * GetFCALPolyLine(int channel)
void DoPrev(void)
TGComboBox * reconfactory
static evioFileChannel * chan
static float BCAL_PHI_SHIFT
void DoOpenTOFInspector(void)
static float BCAL_Rmax
DGeometry * GetDGeometry(unsigned int run_number)
void DoClearOptionsWindowPointer(void)
TGLabel * trig
Int_t GetNTrCand(void)
void SetRange(double xlo, double ylo, double xhi, double yhi)
#define _DBG_
Definition: HDEVIO.h:12
vector< TObject * > graphics_sideA
void SetChargedTrackFactories(vector< string > &facnames)
static float FDC_Rmin
TTimer * timer
int32_t RUNNUMBER
Definition: hdview2.cc:19
trk_mainframe * trkmf
vector< TObject * > graphics_endB
void SetRange(void)
DFCALGeometry fcalgeom
void DoZoomIn(void)
void GetReconFactory(string &name, string &tag)
void DoZoomOut(void)
vector< TObject * > graphics_yz
void DoClearTrackInspectorPointer(void)
map< string, vector< TGLabel * > > thrownlabs
void SetRun(Int_t id)
int column(int channel) const
Definition: DFCALGeometry.h:65
TGComboBox * delay
void ReadPreferences(void)
void DoPanXneg(void)
static float CCAL_Rmax
TGLabel * event
void DoMyRedraw(void)
vector< TObject * > graphics_xyB
double sin(double)
bool GetBCALPhiShift(float &bcal_phi_shift) const
phi angle in degrees that first BCAL module is shifted from being centered at ph=0.0
Definition: DGeometry.cc:1683
int channel(int row, int column) const
static float BCAL_SECS1
TGComboBox * candidatesfactory
TGGroupFrame * reconinfo
static float TOF_Rmax
void DoStop(void)
hdv_optionsframe * optionsmf
static float FCAL_Rmax
void DrawDetectorsRPhi(void)
void DrawScale(TCanvas *c, vector< TObject * > &graphics)
void SavePreferences(void)
Int_t GetNTrWB(void)
int GO
Definition: hdview2.cc:10
vector< TObject * > graphics_sideB
bool GetFDCWires(vector< vector< DFDCWire * > > &fdcwires) const
Definition: DGeometry.cc:1078
hdv_mainframe(const TGWindow *p, UInt_t w, UInt_t h)
static float CDC_Rmin
static float BCAL_MIDRAD
int row(int channel) const
Definition: DFCALGeometry.h:64
void DoUpdateBcalDisp(void)
TCanvas * bcaldispmf
TGLabel * run
bool GetTargetLength(double &target_length) const
z-location of center of target
Definition: DGeometry.cc:1972
void AddGraphicsSideB(vector< TObject * > &v)
coordsys_t coordinatetype
bool isBlockActive(int row, int column) const
void DoEndViewAEvent(TVirtualPad *pad, TObject *obj, Int_t event)
static float BCAL_Rmin
static float TARGET_Zlen
static float BCAL_Zmin
hdv_endviewAframe * endviewAmf
static float FDC_Rmax
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)
vector< TObject * > graphics_xyA
TGComboBox * timetracksfactory
TGGroupFrame * throwninfo
locHist_NumHighLevel Draw("COLZ")
void SetCandidateFactories(vector< string > &facnames)
bool GetTargetZ(double &z_target) const
z-location of center of target
Definition: DGeometry.cc:1933
const char * GetFactoryTag(string who)
TGComboBox * wiretracksfactory
TRootEmbeddedCanvas * endviewA
static float CDC_Zlen
TRootEmbeddedCanvas * sideviewB
void DoBcalDispFrame(void)