14 from .run_command
import run_command
15 from .hist_tab
import HistTab
16 from .tcut_tab
import TCutTab
17 from .variable_tab
import VariableTab
18 from .util
import update_tcanvases
19 from .AnsiColorText
import AnsiColorText
20 from .status_widget
import ThreadStatusFrame
35 with open(filename)
as f:
37 settings = ast.literal_eval(text)
39 if 'tcuts' in settings:
40 self.
tcut_tab._load_tcut_patterns(settings[
'tcuts'])
41 if 'compiled_histograms' in settings:
42 self.
hist_tab._load_compiled_histograms(settings[
'compiled_histograms'][
'name'])
43 if 'variables' in settings:
44 self.
variable_tab._load_variable_patterns(settings[
'variables'])
48 filename = tkFileDialog.asksaveasfilename(filetypes=((
"GUI File",
"*.hist"),))
53 if not filename.endswith(
'.hist'):
57 output[
'histograms'] = self.
hist_tab._hist_patterns()
58 output[
'tcuts'] = self.
tcut_tab._tcut_patterns()
59 output[
'variables'] = self.
variable_tab._variable_patterns()
61 if self.
hist_tab._compiled_histogram_filename():
62 output[
'compiled_histograms'] = {
'name':self.
hist_tab._compiled_histogram_filename()}
64 with open(filename,
'w')
as f:
65 pprint.pprint(output, f)
69 filename = tkFileDialog.asksaveasfilename(filetypes=((
"ROOT File",
"*.root"),))
74 if not filename.endswith(
'.root'):
78 output = ROOT.TFile(filename,
'RECREATE')
79 if include_histograms:
87 self.
icons[
'h1_t'] = tk.PhotoImage(
88 file = os.path.join(os.path.dirname(__file__),
'../icons',
'h1_t.gif'))
89 self.
icons[
'h2_t'] = tk.PhotoImage(
90 file = os.path.join(os.path.dirname(__file__),
'../icons',
'h2_t.gif'))
91 self.
icons[
'folder_t'] = tk.PhotoImage(
92 file = os.path.join(os.path.dirname(__file__),
'../icons',
'folder_t.gif'))
93 self.
icons[
'tfile'] = tk.PhotoImage(
94 file = os.path.join(os.path.dirname(__file__),
'../icons',
'rootdb_t.gif'))
95 self.
icons[
'tcutg'] = tk.PhotoImage(
96 file = os.path.join(os.path.dirname(__file__),
'../icons',
'bld_cut.gif'))
97 self.
icons[
'ttree'] = tk.PhotoImage(
98 file = os.path.join(os.path.dirname(__file__),
'../icons',
'ttree_t.gif'))
99 img = tk.PhotoImage(file=os.path.join(os.path.dirname(__file__),
'../icons',
'hdb_s.gif'))
100 self.
window.tk.call(
'wm',
'iconphoto',self.
window._w,img)
103 style = ROOT.TStyle(
"GRSIStyle",
"")
104 style.SetOptStat(1001111)
106 style.SetTitleColor(ROOT.kBlue)
107 style.SetStatTextColor(ROOT.kBlue)
108 style.SetFuncColor(ROOT.kRed)
109 style.SetTitleBorderSize(0)
110 style.SetOptFit(1111)
111 style.SetPadBorderSize(1)
112 style.SetPadBorderMode(1)
113 ROOT.gROOT.SetStyle(
"GRSIStyle")
114 ROOT.gROOT.ForceStyle()
118 ws = self.
window.winfo_screenwidth()
119 hs = self.
window.winfo_screenheight()
121 self.
window.geometry(
'450x850+%d+%d' % (ws-475,25))
122 self.
window.wm_title(
"hist-o-matic")
125 frame = tk.Frame(self.
window)
126 button = tk.Button(frame,
127 text=
'Load Data File',fg=
"black",bg=
"goldenrod",
129 button.pack(side=tk.LEFT)
131 button = tk.Button(frame,
132 text=
'Load Root File',fg=
"black",bg=
"goldenrod",
134 button.pack(side=tk.LEFT)
136 button = tk.Button(frame,
137 text=
'Load Window File',fg=
"black",bg=
"goldenrod",
139 button.pack(side=tk.LEFT)
141 frame.pack(fill=tk.X,expand=
False)
143 frame = tk.Frame(self.
window)
145 button = tk.Button(frame,
146 text=
'Refresh',fg=
"black",bg=
"goldenrod",
148 button.pack(side=tk.LEFT)
150 button = tk.Button(frame,
151 text=
'Reset',fg=
"black",bg=
"goldenrod",
153 button.pack(side=tk.LEFT)
155 button = tk.Button(frame,
156 text=
'Reset All',fg=
"black",bg=
"goldenrod",
158 button.pack(side=tk.LEFT)
160 button = tk.Button(frame,
161 text=
'Resort Data',fg=
"black",bg=
"goldenrod",
163 button.pack(side=tk.LEFT)
165 frame.pack(fill=tk.X,expand=
False)
167 notebook = ttk.Notebook(self.
window)
169 hist_page = ttk.Frame(notebook)
171 notebook.add(hist_page, text=
'Histograms')
173 tcut_page = ttk.Frame(notebook)
175 notebook.add(tcut_page, text=
'Gates')
177 variable_page = ttk.Frame(notebook)
179 notebook.add(variable_page, text=
'Variables')
181 notebook.pack(fill=tk.BOTH,expand=
True)
190 frame = tk.Frame(parent, height=60)
191 frame.propagate(
False)
194 frame.pack(fill=tk.X, expand=
False)
232 ROOT.gStyle.SetOptStat(stat)
235 menubar = tk.Menu(self.
window)
248 filemenu = tk.Menu(menubar,tearoff=0)
249 filemenu.add_command(label=
"New Canvas",command=self.
open_canvas)
250 filemenu.add_separator()
251 filemenu.add_checkbutton(label=
"Size 800 x 600",onvalue=
"800x600",
253 filemenu.add_checkbutton(label=
"Size 1200 x 600",onvalue=
"1200x600",
255 filemenu.add_checkbutton(label=
"Size 1900 x 450",onvalue=
"1900x450",
257 filemenu.add_checkbutton(label=
"Size 1900 x 900",onvalue=
"1900x900",
259 filemenu.add_separator()
261 filemenu.add_separator()
262 filemenu.add_command(label=
"Open GUI",command=self.
hello)
263 filemenu.add_command(label=
"Save GUI",command=self.
_save_gui_file)
264 filemenu.add_command(label=
"Dump ROOT Config",
266 filemenu.add_command(label=
"Dump ROOT Histograms",command=self.
_dump_root_file)
267 filemenu.add_separator()
268 filemenu.add_command(label=
"Exit",command=self.
Terminate)
269 menubar.add_cascade(label=
"File",menu=filemenu)
273 self.
dummy.Start(-1,
True)
280 if isinstance(obj, ROOT.TKey):
281 cls = ROOT.TClass(obj.GetClassName())
285 if cls.InheritsFrom(ROOT.TH2.Class()):
286 return self.
icons[
'h2_t']
287 elif cls.InheritsFrom(ROOT.TH1.Class()):
288 return self.
icons[
'h1_t']
289 elif cls.InheritsFrom(ROOT.TFile.Class()):
290 return self.
icons[
'tfile']
291 elif cls.InheritsFrom(ROOT.TDirectory.Class()):
292 return self.
icons[
'folder_t']
293 elif cls.InheritsFrom(ROOT.TList.Class()):
294 return self.
icons[
'folder_t']
295 elif cls.InheritsFrom(ROOT.TTree.Class()):
296 return self.
icons[
'ttree']
305 size = size.split(
"x")
306 array =(size[0],size[1])
312 refreshmenu = tk.Menu(menubar,tearoff=0)
313 refreshmenu.add_checkbutton(label=
"Off",onvalue=-1,
316 refreshmenu.add_separator()
317 refreshmenu.add_checkbutton(label=
"1 second",onvalue=1,
319 refreshmenu.add_checkbutton(label=
"2 seconds",onvalue=2,
321 refreshmenu.add_checkbutton(label=
"5 seconds",onvalue=5,
323 refreshmenu.add_checkbutton(label=
"10 seconds",onvalue=10,
325 refreshmenu.add_checkbutton(label=
"30 seconds",onvalue=30,
327 menubar.add_cascade(label=
"Refresh",menu=refreshmenu)
343 zonesmenu = tk.Menu(menubar,tearoff=0)
344 zonesmenu.add_checkbutton(label=
"1 x 1",onvalue=
'1x1',
346 zonesmenu.add_checkbutton(label=
"1 x 2",onvalue=
'1x2',
348 zonesmenu.add_checkbutton(label=
"1 x 3",onvalue=
'1x3',
350 zonesmenu.add_checkbutton(label=
"2 x 1",onvalue=
'2x1',
352 zonesmenu.add_checkbutton(label=
"2 x 2",onvalue=
'2x2',
354 zonesmenu.add_checkbutton(label=
"2 x 3",onvalue=
'2x3',
356 zonesmenu.add_checkbutton(label=
"2 x 5",onvalue=
'2x5',
358 zonesmenu.add_checkbutton(label=
"3 x 1",onvalue=
'3x1',
360 zonesmenu.add_checkbutton(label=
"3 x 2",onvalue=
'3x2',
362 zonesmenu.add_checkbutton(label=
"3 x 3",onvalue=
'3x3',
364 zonesmenu.add_checkbutton(label=
"4 x 4",onvalue=
'4x4',
366 zonesmenu.add_checkbutton(label=
"5 x 2",onvalue=
'5x2',
368 zonesmenu.add_checkbutton(label=
"8 x 3",onvalue=
'8x3',
370 zonesmenu.add_checkbutton(label=
"8 x 4",onvalue=
'8x4',
372 zonesmenu.add_checkbutton(label=
"9 x 4",onvalue=
'9x4',
374 zonesmenu.add_checkbutton(label=
"12 x 12",onvalue=
'12x12',
376 zonesmenu.add_checkbutton(label=
"13 x 13",onvalue=
'13x13',
378 menubar.add_cascade(label=
"Zones",menu=zonesmenu)
383 zones = map(int,zones_str.split(
"x"))
385 except (IndexError,ValueError):
386 print 'Cannot set zones to "{}"'.format(zones_str)
403 optstatmenu = tk.Menu(menubar,tearoff=0)
404 optstatmenu.add_checkbutton(label=
"Name",onvalue=1,variable=self.
optstat_name)
405 optstatmenu.add_checkbutton(label=
"Entries",onvalue=1,variable=self.
optstat_entries)
406 optstatmenu.add_checkbutton(label=
"Mean",onvalue=1,variable=self.
optstat_mean)
407 optstatmenu.add_checkbutton(label=
"Mean Error",onvalue=1,variable=self.
optstat_mean_err)
408 optstatmenu.add_checkbutton(label=
"RMS",onvalue=1,variable=self.
optstat_rms)
409 optstatmenu.add_checkbutton(label=
"RMS Error",onvalue=1,variable=self.
optstat_rms_err)
410 optstatmenu.add_checkbutton(label=
"Underflows",onvalue=1,variable=self.
optstat_underflow)
411 optstatmenu.add_checkbutton(label=
"Overflows",onvalue=1,variable=self.
optstat_overflow)
412 optstatmenu.add_checkbutton(label=
"Integral",onvalue=1,variable=self.
optstat_integral)
413 optstatmenu.add_checkbutton(label=
"Skew",onvalue=1,variable=self.
optstat_skew)
414 optstatmenu.add_checkbutton(label=
"Skew Error",onvalue=1,variable=self.
optstat_skew_err)
415 optstatmenu.add_checkbutton(label=
"Kurtosis",onvalue=1,variable=self.
optstat_kurt)
416 optstatmenu.add_checkbutton(label=
"Kurtosis Error",onvalue=1,variable=self.
optstat_kurt_err)
417 menubar.add_cascade(label=
"OptStats",menu=optstatmenu)
422 plotmenu = tk.Menu(menubar,tearoff=0)
423 plotmenu.add_checkbutton(label=
"New Canvas",onvalue=
'NewCanvas',
425 plotmenu.add_checkbutton(label=
"Next Pad",onvalue=
'NextPad',
427 plotmenu.add_checkbutton(label=
"Current Pad (replace)",onvalue=
'Replace',
429 plotmenu.add_checkbutton(label=
"Current Pad (overlay)",onvalue=
'Overlay',
431 menubar.add_cascade(label=
"Plot",menu=plotmenu)
434 helpmenu = tk.Menu(menubar,tearoff=0)
435 menubar.add_cascade(label=
"Send Help",menu=helpmenu)
442 for obj
in ROOT.gPad.GetListOfPrimitives():
443 if isinstance(obj, ROOT.TH1):
456 canvas_exists = bool(filter(
None,self.
canvases))
458 if(
not canvas_exists
or not ROOT.gPad):
463 ROOT.gPad.GetCanvas().cd(0)
464 if (ROOT.gPad.GetListOfPrimitives().GetSize()==0):
465 ROOT.gPad.GetCanvas().Clear();
486 currentnumber = ROOT.gPad.GetNumber()
487 if (self.
plotlocation.get() ==
'NextPad' and currentnumber>0):
488 ROOT.gPad.GetCanvas().cd(currentnumber+1)
489 if ROOT.gPad.GetNumber() == currentnumber:
490 ROOT.gPad.GetCanvas().cd(1)
495 if hist.GetDimension() > 1:
498 hist.SetLineColor(color)
499 hist.Draw(
' '.join(opt))
503 self.
hist_tab.AddActiveDirectory(tdir)
517 filename = tkFileDialog.askopenfilename(filetypes=((
"NSCL Evt",
"*.evt"),
518 (
"GEB File",
"*.dat"),
519 (
"GZip File",
"*.gz")))
524 ROOT.TGRSIint.instance().LoadRawFile(filename)
529 filename = tkFileDialog.askopenfilename(filetypes=((
"ROOT File",
"*.root"),))
534 filename = os.path.abspath(filename)
535 tfile = ROOT.TGRSIint.instance().OpenRootFile(filename)
537 self.
files[filename] = tfile
542 print 'MainWindow.LoadRootFile: Could not open {}'.format(filename)
546 filename = tkFileDialog.askopenfilename(filetypes=((
"Window File",
"*.win"),))
550 filename = os.path.abspath(filename)
551 can = ROOT.TPresetCanvas()
552 can.ReadWinFile(filename)
564 library_name = os.path.join(os.path.dirname(__file__),
565 '..',
'libraries',library_name)
566 ROOT.gSystem.Load(library_name)
572 canvases = ROOT.gROOT.GetListOfCanvases()
573 for canvas
in canvases:
576 def open_canvas(self,title="",columns=-1,rows=-1,topx=0,topy=0,width=0,height=0):
578 title =
"canvas" + str(len(self.
canvases))
580 if columns==-1
or rows==-1:
584 if width*height == 0:
586 array = map(int,array)
587 canvas = ROOT.GCanvas(title,title,0,0,array[0],array[1],
True)
589 canvas = ROOT.GCanvas(title,title,topx,topy,width,height,
True)
592 if columns*rows == 1:
596 canvas.Divide(columns,rows)
597 canvas.cd(columns*rows)
def LoadGuiFile(self, filename)
def open_canvas(self, title="", columns=-1, rows=-1, topx=0, topy=0, width=0, height=0)
def LoadWindowFile(self, filename=None)
def _draw_single(self, hist, color=1, nselected=1)
def _update_status_bar(self)
def _MakeFileMenu(self, menubar)
def _dump_root_file(self, filename=None, include_histograms=True)
def _save_gui_file(self, filename=None)
def ResetAllHistograms(self)
def _MakeZoneMenu(self, menubar)
def get_canvas_size(self, size="")
def _MakePlotMenu(self, menubar)
def RefreshHistograms(self)
def _MakeRefreshMenu(self, menubar)
def AddDirectory(self, tdir)
def _setup_status_bar(self, parent)
def _PeriodicRefresh(self)
def LoadRootFile(self, filename=None)
def _MakeOptStatMenu(self, menubar)
def update_tcanvases(objects=None)
def LoadDataFile(self, filename=None)
if(hist) hist -> Fill(fragment->GetCharge())
def ResetHistograms(self, hist=None)
def load_library(self, library_name, grut_lib=True)
def close_all_canvases(self)
def _load_default_style(self)
def _MakeHelpMenu(self, menubar)