10#include <ecl/modules/eclDisplay/EclFrame.h>
13#include <ecl/mapper/ECLChannelMapper.h>
14#include <ecl/modules/eclDisplay/geometry.h>
15#include <ecl/modules/eclDisplay/MultilineWidget.h>
16#include <ecl/modules/eclDisplay/EclPainter.h>
17#include <ecl/modules/eclDisplay/EclPainter1D.h>
22#include <TGComboBox.h>
23#include <TGDoubleSlider.h>
24#include <TGFileDialog.h>
26#include <TGListTree.h>
28#include <TGNumberEntry.h>
29#include <TRootEmbeddedCanvas.h>
35using namespace ECLDisplayUtility;
40 "Encapsulated PostScript",
"*.eps",
45 "ROOT files",
"*.root",
66 for (
int i = 1; i <= data->getCrystalCount(); i++) {
67 int phi_id = data->getPhiId(i);
68 int theta_id = data->getThetaId(i);
70 if (phi_id == -1 || theta_id == -1)
71 data->excludeChannel(i);
78 gStyle->SetOptStat(0);
91 B2DEBUG(100,
"EclFrame:: initializing GUI.");
93 SetLayoutManager(
new TGVerticalLayout(
this));
94 TGCompositeFrame* frame_container =
new TGCompositeFrame(
this, w, h, kHorizontalFrame);
98 TGPopupMenu* menu_file =
new TGPopupMenu(gClient->GetRoot());
99 menu_file->AddEntry(
"&Open...", M_FILE_OPEN);
101 menu_file->AddEntry(
"&Save As...", M_FILE_SAVE);
102 menu_file->AddSeparator();
103 menu_file->AddEntry(
"&Exit", M_FILE_EXIT);
104 TGPopupMenu* menu_view =
new TGPopupMenu(gClient->GetRoot());
105 menu_view->AddEntry(
"&Show event counts in histograms",
M_VIEW_EVENTS);
106 menu_view->AddEntry(
"&Show energy in histograms",
M_VIEW_ENERGY);
107 menu_view->AddSeparator();
108 menu_view->AddEntry(
"&Show events from all ECL subsystems",
M_VIEW_DET_FULL);
110 menu_view->AddEntry(
"&Show events from ECL forward endcap",
M_VIEW_DET_FORW);
111 menu_view->AddEntry(
"&Show events from ECL backward endcap",
M_VIEW_DET_BACK);
113 TGMenuBar* menubar =
new TGMenuBar(
this, w, 30);
114 menubar->AddPopup(
"&File", menu_file,
new TGLayoutHints(kLHintsTop | kLHintsLeft));
115 menubar->AddPopup(
"&View", menu_view,
new TGLayoutHints(kLHintsTop | kLHintsLeft));
117 menu_file->Connect(
"Activated(Int_t)",
"Belle2::EclFrame",
118 this,
"handleMenu(Int_t)");
119 menu_view->Connect(
"Activated(Int_t)",
"Belle2::EclFrame",
120 this,
"handleMenu(Int_t)");
122 AddFrame(menubar,
new TGLayoutHints(kLHintsExpandX | kLHintsTop, 0, 0, 1, 1));
126 m_settings =
new TGVerticalFrame(frame_container, w / 6, h);
130 TGComboBox* diagram_type =
new TGComboBox(
m_settings, -1);
131 diagram_type->SetName(
"DiagramType");
134 for (
int i = 0; i < types_count; i++)
135 diagram_type->AddEntry(types_names[i], i);
137 diagram_type->SetHeight(16);
138 m_settings->AddFrame(diagram_type,
new TGLayoutHints(kLHintsExpandX));
139 diagram_type->Connect(
"Selected(Int_t)",
"Belle2::EclFrame",
this,
140 "changeType(Int_t)");
154 TGHorizontalFrame* frame2_1 =
new TGHorizontalFrame(
m_frame2);
155 TGLabel* ev_min_label =
new TGLabel(frame2_1,
"Min: ");
156 frame2_1->AddFrame(ev_min_label,
new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 2, 2, 2));
157 m_events_min =
new TGNumberEntry(frame2_1, 0, 6, -1, TGNumberFormat::kNESInteger);
158 frame2_1->AddFrame(
m_events_min,
new TGLayoutHints(kLHintsLeft, 2, 2, 2, 2));
159 TGLabel* ev_max_label =
new TGLabel(frame2_1,
"Max: ");
160 frame2_1->AddFrame(ev_max_label,
new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 2, 2, 2));
161 m_events_max =
new TGNumberEntry(frame2_1, 0, 6, -1, TGNumberFormat::kNESInteger);
162 frame2_1->AddFrame(
m_events_max,
new TGLayoutHints(kLHintsLeft, 2, 2, 2, 2));
168 TGHorizontalFrame* frame2_2 =
new TGHorizontalFrame(
m_frame2);
169 TGTextButton* prev =
new TGTextButton(frame2_2,
"&Prev");
170 prev->Connect(
"Clicked()",
"Belle2::EclFrame",
this,
"showPrevEvents()");
171 frame2_2->AddFrame(prev,
new TGLayoutHints(kLHintsLeft, 5, 5, 3, 4));
172 TGTextButton* next =
new TGTextButton(frame2_2,
"&Next");
173 next->Connect(
"Clicked()",
"Belle2::EclFrame",
this,
"showNextEvents()");
174 frame2_2->AddFrame(next,
new TGLayoutHints(kLHintsRight, 5, 5, 3, 4));
175 m_frame2->AddFrame(frame2_2,
new TGLayoutHints(kLHintsExpandX));
185 TGCanvas* list_canvas =
new TGCanvas(
m_frame3, 1, 100);
186 m_list_tree =
new TGListTree(list_canvas, kHorizontalFrame);
188 TGListTreeItem* root =
m_list_tree->AddItem(0,
"Detector");
190 for (
int i = 0; i < 52; i++) {
191 sprintf(temp,
"Collector %d", i);
192 TGListTreeItem* parent =
m_list_tree->AddItem(root, temp);
193 parent->SetUserData((
void*)((intptr_t)i));
194 for (
int j = 0; j < 12; j++) {
195 sprintf(temp,
"Shaper %d", i * 12 + j);
196 TGListTreeItem* item =
m_list_tree->AddItem(parent, temp);
197 item->SetUserData((
void*)((intptr_t)j));
201 m_list_tree->Connect(
"Clicked(TGListTreeItem*, Int_t)",
"Belle2::EclFrame",
this,
202 "changeRange(TGListTreeItem*, Int_t)");
204 m_frame3->AddFrame(list_canvas,
new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
205 m_settings->AddFrame(
m_frame3,
new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 2, 2, 2, 2));
213 TGTextButton* exclude =
new TGTextButton(
m_frame4,
"&Exclude");
214 exclude->Connect(
"Clicked()",
"Belle2::EclFrame",
this,
"excludeChannel()");
215 m_frame4->AddFrame(exclude,
new TGLayoutHints(kLHintsRight, 5, 5, 3, 4));
222 TGHorizontalFrame* frame5_1 =
new TGHorizontalFrame(
m_frame5);
223 frame5_1->SetLayoutManager(
new TGHorizontalLayout(frame5_1));
225 TGLabel* min_lab =
new TGLabel(frame5_1,
"MeV");
227 TGLabel* max_lab =
new TGLabel(frame5_1,
"MeV");
229 frame5_1->AddFrame(min_lab,
new TGLayoutHints(kLHintsLeft, 2, 2, 2, 2));
230 frame5_1->AddFrame(max_lab,
new TGLayoutHints(kLHintsRight, 2, 2, 2, 2));
243 m_draw->Connect(
"Clicked()",
"Belle2::EclFrame",
this,
"doDraw()");
244 m_settings->AddFrame(
m_draw,
new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
247 m_draw_all->Connect(
"Clicked()",
"Belle2::EclFrame",
this,
"doDrawAll()");
256 m_ecanvas =
new TRootEmbeddedCanvas(
"Ecanvas", frame_container, w / 2, h / 2);
257 m_ecanvas->GetCanvas()->SetRightMargin(0.125);
258 m_ecanvas->GetCanvas()->SetLeftMargin(0.1);
259 frame_container->AddFrame(
m_ecanvas,
new TGLayoutHints(
260 kLHintsExpandX | kLHintsExpandY, 10, 10, 10, 1));
263 Connect(
"TCanvas",
"ProcessedEvent(Int_t, Int_t, Int_t, TObject*)",
264 "Belle2::EclFrame",
this,
"updateInfo(Int_t, Int_t, Int_t, TObject*)");
268 AddFrame(frame_container,
new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,
271 B2DEBUG(100,
"EclFrame:: GUI initialized.");
273 frame_container->SetMinWidth(w / 2);
277 SetWindowName(
"ECL Data");
282 B2DEBUG(100,
"EclFrame:: Initializing data.");
284 B2DEBUG(100,
"EclFrame:: Data initialized.");
289 m_events_min->SetLimits(TGNumberFormat::kNELLimitMinMax,
291 m_events_max->SetLimits(TGNumberFormat::kNELLimitMinMax,
297 m_ev_slider->Connect(
"TGDoubleHSlider",
"PositionChanged()",
298 "Belle2::EclFrame",
this,
"updateEventRange()");
304 static TString dir(
".");
311 fi.fIniDir = StrDup(dir);
312 new TGFileDialog(gClient->GetRoot(),
this, kFDOpen, &fi);
314 if (gSystem->AccessPathName(fi.fFilename, kFileExists) == 0) {
315 B2DEBUG(50,
"ECLFrame:: Opening file " << fi.fFilename);
324 fi.fIniDir = StrDup(dir);
325 new TGFileDialog(gClient->GetRoot(),
this, kFDSave, &fi);
326 B2DEBUG(50,
"Save file: " << fi.fFilename
327 <<
"(dir: " << fi.fIniDir <<
")");
328 m_ecanvas->GetCanvas()->SaveAs(fi.fFilename);
331 static const char* filetypes_root[] = {
"Root",
"*.root", 0, 0};
332 fi.fFileTypes = filetypes_root;
333 fi.fIniDir = StrDup(dir);
334 new TGFileDialog(gClient->GetRoot(),
this, kFDSave, &fi);
335 B2DEBUG(50,
"Save file: " << fi.fFilename
336 <<
"(dir: " << fi.fIniDir <<
")");
337 file =
new TFile(fi.fFilename,
"RECREATE");
380 m_events_min->SetLimits(TGNumberFormat::kNELLimitMinMax,
382 m_events_max->SetLimits(TGNumberFormat::kNELLimitMinMax,
385 if (m_last_event < m_ecl_data->getLastEventId() &&
402 TCanvas* fCanvas =
m_ecanvas->GetCanvas();
413 Float_t ev_min, ev_max;
425 Float_t ev_min, ev_max, diff;
433 diff = ev_max - ev_min + 1;
446 Float_t ev_min, ev_max, diff;
454 diff = ev_max - ev_min + 1;
499 if (new_painter !=
nullptr) {
522 TGListTreeItem* parent = entry->GetParent();
527 TGListTreeItem* grandparent = parent->GetParent();
531 long crate = (long)entry->GetUserData();
537 long shaper = (long)entry->GetUserData();
538 long crate = (long)parent->GetUserData();
539 shaper = 12 * crate + shaper;
This class provides access to ECL channel map that is either a) Loaded from the database (see ecl/dbo...
This class contains data for ECLSimHit's and provides several relevant conversion functions for bette...
void setEventRange(int ev_min, int ev_max, bool do_update=true)
Sets event range to (ev_min, ev_max)
void setEnergyThreshold(int en_min, int en_max, bool do_update=true)
Sets energy range to (en_min, en_max).
void excludeChannel(int ch, bool do_update=false)
Excludes specific channel from the count of events and energy.
void loadRootFile(const char *path)
Load root file containing ECLCalDigit data from the specified path.
TTree * getTree()
Returns data contained in EclDisplay.
ECL::ECLChannelMapper * m_mapper
ECLChannelMapper, class for conversion from CellID to (crate, shaper, chn_id).
TGListTree * m_list_tree
Tree GUI of crates/shapers.
void initData()
Initialize data.
TGVerticalFrame * m_settings
Main frame for settings; its subframes contain settings for different categories.
void doDrawAll()
Draw all events on m_ecanvas.
TGNumberEntry * m_events_max
Max value for range of displayed events.
bool m_open
Default is true, m_open is set to false when EclFrame closes.
void updateInfo(int event, int px, int py, TObject *)
Update information on the cursor position in the histogram.
TRootEmbeddedCanvas * m_ecanvas
Embedded canvas.
int m_last_event
If m_auto_display is set, this is the evtn of last displayed event.
static const char * filetypes[]
Possible export filetypes for histograms.
EclPainterType m_painter_type
Current painter type.
TGNumberEntry * m_max_en_threshold
Max value for energy threshold.
void showNextEvents()
Show next range of events.
EclData::EclSubsystem m_subsys
Current subsystem displayed.
TGGroupFrame * m_frame5
Energy threshold subframe.
TGNumberEntry * m_min_en_threshold
Min value for energy threshold.
EclFrame(int painter_type, EclData *data, bool auto_display, ECL::ECLChannelMapper *mapper)
TGGroupFrame * m_frame3
Optional subframe, crate/shaper select.
void showPrevEvents()
Show previous range of events.
@ M_VIEW_DET_BACK
Use data from backward endcap only.
@ M_VIEW_ENERGY
Display histograms for energy.
@ M_VIEW_DET_BARR
Use data from barrel only.
@ M_VIEW_DET_FULL
Use data from all ECL subsystems.
@ M_VIEW_DET_FORW
Use data from forward endcap only.
@ M_FILE_EXPORT_TREE
Export EclDisplay data into simple TTree.
@ M_VIEW_EVENTS
Display histograms for events.
void handleMenu(int id)
Apply action from menu.
TGGroupFrame * m_frame4
Channel exclusion subframe.
bool m_auto_display
This flag controls whether to display newly loaded events automatically.
virtual ~EclFrame()
ECLFrame destructor.
void changeType(int type, bool redraw=true)
Change EclPainter type when selected in drop-down menu.
void initGUI(int w, int h)
Initialize GUI.
void changeRange(TGListTreeItem *entry, int btn)
Opens shapers of specific crate/channels of specific shaper.
TGDoubleHSlider * m_ev_slider
Slider to set the time range.
void doDraw()
Get view parameters from GUI and call updateCanvas().
TGNumberEntry * m_events_min
Min value for range of displayed events.
void loadNewData()
Update view of the data.
TGCheckButton * m_threshold_switch
Check button to turn energy threshold on/off.
void updateCanvas()
Redraw m_ecanvas.
TGTextButton * m_draw_all
Button that initiates drawing of the data for all events.
TGNumberEntry * m_channel_id
Number field for channel exclusion.
MultilineWidget * m_frame1
Information subframe.
EclData * m_ecl_data
EclData, class containing data to display.
void excludeChannel()
Exclude channel specified in the GUI.
TGGroupFrame * m_frame2
Event range subframe.
void updateEventRange()
Change event range and pass information to m_ecl_data.
TGTextButton * m_draw
Button that initiates drawing of the data for selected events.
EclPainter * m_ecl_painter
Current EclPainter.
Painter for EclData, 1D histograms.
static EclPainter * createPainter(EclPainterType type, EclData *data, ECL::ECLChannelMapper *mapper, EclData::EclSubsystem subsys=EclData::ALL)
Creates EclPainter of the specified type.
static const char ** getTypeTitles()
Returns array of titles for each EclPainter type.
static int getTypeTitlesCount()
Size of array from getTypeTitles()
Painter for EclData, parent class, created with EclPainterFactory.
virtual void getInformation(int px, int py, MultilineWidget *panel)
Sets the information to be displayed in the provided MultilineWidget.
virtual void Draw()=0
Redraw the canvas.
virtual EclPainter * handleClick(int px, int py)
Some EclPainters can shift to another view upon click.
void setDisplayedSubsystem(EclData::EclSubsystem sys)
Change between the displayed ECL subsystem (barrel, forward and backward endcaps).
virtual void setXRange(int x1, int x2)
Set XRange for histogram in EclPainter.
void SetMode(int i)
Changes between display of events (0) and energy (1).
EclPainterType
Enum for type of EclPainter to create.
@ PAINTER_CHANNEL
Event count/energy distribution per channel.
@ PAINTER_COLLECTOR
Event count/energy distribution per crate/ECLCollector.
@ PAINTER_SHAPER
Event count/energy distribution per shaperDSP.
Abstract base class for different kinds of events.