KaliVeda
Toolkit for HIC analysis
Loading...
Searching...
No Matches
KVIDGridManagerGUI.cpp
1#include "KVIDGridManagerGUI.h"
2#include "Riostream.h"
3#include "KVIDGridManager.h"
4#include "KVIDGrid.h"
5#include "TGFileDialog.h"
6#include "TPad.h"
7#include <TGMsgBox.h>
8#include <TTimer.h>
9#include <TClass.h>
10#include <TROOT.h>
11#include <TGLayout.h>
12#include <TCanvas.h>
13#include <KVTestIDGridDialog.h>
14#include "KVConfig.h"
15#include <KVIDGUITelescopeChooserDialog.h>
16#include <KVDropDownDialog.h>
17#include <KVIdentificationResult.h>
18#include <KVReconstructedNucleus.h>
19#include "TEnv.h"
20#include "KVInputDialog.h"
21#include "KVIDCutLine.h"
22#include "KVIDCutContour.h"
23#include "KVVirtualIDFitter.h"
24#include "TTree.h"
25
26using namespace std;
27
29
30
31
32
33KVIDGridManagerGUI::KVIDGridManagerGUI(): TGMainFrame(gClient->GetRoot(), 500, 300)
34{
35 fFirstGrid = 0;
36 fLastGrid = -1;
37 fSelectedGrid = 0;
38 fLastSelectedGrid = 0;
39
40 fIDGridEditor = new KVIDGridEditor;
41
42 //to have access to online KaliVeda documentation via context menus
43 //and dialog box "Online Help" buttons
44 gEnv->SetValue("Browser.StartUrl", Form("http://indra.in2p3.fr/KaliVedaDoc/%s/", KVBase::GetKVVersion()));
45
46 //any change of ID grid manager causes UpdateListOfGrids to be called
47 gIDGridManager->Connect("Modified()", "KVIDGridManagerGUI", this,
48 "UpdateListOfGrids()");
49
50 //create new manager GUI
51
52 /**************** GRIDS popup menu *****************/
53 fMenuFile = new TGPopupMenu(gClient->GetRoot());
54 /* cascading "Save grids" menu... */
55 TGPopupMenu* sgm = new TGPopupMenu(gClient->GetRoot());
56 sgm->AddEntry("Selected", M_GRIDS_SAVE_SEL);
57 sgm->AddEntry("Tab", M_GRIDS_SAVE_TAB);
58 sgm->AddEntry("All", M_GRIDS_SAVE_ALL);
59 fMenuFile->AddPopup("Save...", sgm);
60
61 fMenuFile->AddSeparator();
62 /* cascading "Delete grids" menu... */
63 sgm = new TGPopupMenu(gClient->GetRoot());
64 sgm->AddEntry("Selected", M_GRIDS_DEL_SEL);
65 sgm->AddEntry("Tab", M_GRIDS_DEL_TAB);
66 sgm->AddEntry("All", M_GRIDS_DEL_ALL);
67 fMenuFile->AddPopup("Delete...", sgm);
68 fMenuFile->AddSeparator();
69 fMenuFile->AddEntry("&Quit", M_QUIT);
70
71 fMenuFile->Connect("Activated(Int_t)", "KVIDGridManagerGUI", this,
72 "HandleGridsMenu(Int_t)");
73 /**************** HELP popup menu *****************/
74// fMenuHelp = new TGPopupMenu(gClient->GetRoot());
75// fMenuHelp->AddEntry("About...", M_HELP_ABOUT);
76 /******************MENUBAR*********************/
77
78 fMenuEdit = new TGPopupMenu(gClient->GetRoot());
79 sgm = new TGPopupMenu(gClient->GetRoot());
80 sgm->AddEntry("Runlist", M_GRIDS_SET_RUNLIST);
81 sgm->AddEntry("X Variable", M_GRIDS_SET_VARX);
82 sgm->AddEntry("Y Variable", M_GRIDS_SET_VARY);
83 //sgm->AddEntry("Mass Formula", M_GRIDS_SET_MASSFORM);
84 sgm->AddEntry("Z ID Only", M_GRIDS_SET_ZID);
85 fMenuEdit->AddPopup("Set...", sgm);
86 fMenuEdit->AddEntry("Clear", M_GRIDS_CLEAR);
87 fMenuEdit->Connect("Activated(Int_t)", "KVIDGridManagerGUI", this,
88 "HandleGridsMenu(Int_t)");
89
90 fMenuBarItemLayout =
91 new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
92// fMenuBarHelpLayout = new TGLayoutHints(kLHintsTop | kLHintsRight);
93 fMenuBar = new TGMenuBar(this, 1, 1, kHorizontalFrame);
94 fMenuBar->AddPopup("&File", fMenuFile, fMenuBarItemLayout);
95 fMenuBar->AddPopup("&Edit", fMenuEdit, fMenuBarItemLayout);
96// fMenuBar->AddPopup("&Help", fMenuHelp, fMenuBarHelpLayout);
97
98 //add to main window
99 AddFrame(fMenuBar,
101 0, 1, 1));
102// adding a horizontal line as a separator
104 AddFrame(lh, new TGLayoutHints(kLHintsTop | kLHintsExpandX));
105
107// toolbar icon files
108 const char* xpms[] = {
109 "ofolder_t.xpm", // open
110 "filesaveas.xpm", // save
111 "profile_t.xpm",
112 "bld_copy.xpm",
113 "sm_delete.xpm",
114 "ed_find.png",
115 "draw_t.xpm",//
116 "root_t.xpm",//
117 "refresh1.xpm",
118 0
119 };
120// toolbar tool tip text
121 const char* tips[] = {
122 "Open file containing grids",
123 "Save all grids in current file",
124 "New grid",
125 "Copy grid",
126 "Delete selected grid(s)",
127 "Set ID telescopes for grid",
128 "Start editor",//"Quit"
129 "Open root file",
130 "Refresh display",
131 0
132 };
133 int spacing[] = {
134 5,
135 0,
136 20,
137 0,
138 0,
139 0,
140 20,
141 0,
142 20,
143 0
144 };
145 TGButton** buttons[] = {
146 &fTBOpen,
147 &fTBSave,
148 &fTBNewG,
149 &fTBCopyG,
150 &fTBDelG,
151 &fTBSetIDG,
152 &fTBStartEditor,
153 &fTBOpenRoot,
154 &fTBRefresh,
155 0
156 };
157 const char* method[] = {
158 "OpenFile()",
159 "SaveCurrent()",
160 "NewGrid()",
161 "CopyGrid()",
162 "DeleteSelectedGrids()",
163 "SetIDTelescopes()",
164 "StartEditor()", //"Quit()"
165 "OpenRootFile()",
166 "UpdateListOfGrids()",
167 0
168 };
169 fNbButtons = 0;
170// structure containing toolbar button information
171 ToolBarData_t t[50];
172// creation of a toolbar object as a child of main frame
173 fToolBar = new TGToolBar(this, 520, 80);
174 int i = 0;
175 while (xpms[i]) {
176 t[i].fPixmap = xpms[i];
177 t[i].fTipText = tips[i];
178 t[i].fStayDown = kFALSE;
179 t[i].fId = i + 1;
180 t[i].fButton = NULL;
181 *buttons[i] = fToolBar->AddButton(this, &t[i], spacing[i]);
182 (*buttons[i])->Connect("Clicked()", "KVIDGridManagerGUI", this, method[i]);
183 fTBbuttons[i] = *buttons[i];
184 fNbButtons++;
185 i++;
186 }
187 // 'new id line' & 'new cut' button stays down until line is drawn
188// fTBNewIDL->AllowStayDown(kTRUE);
189// fTBNewCut->AllowStayDown(kTRUE);
190
191// adding the tool bar to the main frame
192 AddFrame(fToolBar, new TGLayoutHints(kLHintsTop | kLHintsExpandX));
194
195// adding a horizontal line as a separator
196 lh = new TGHorizontal3DLine(this);
197 AddFrame(lh, new TGLayoutHints(kLHintsTop | kLHintsExpandX));
198
200 fStatusBar = new TGStatusBar(this);
201 AddFrame(fStatusBar, new TGLayoutHints(kLHintsTop | kLHintsExpandX));
203
204 fHframe = new TGHorizontalFrame(this, 10, 10);
205
206 // Tabs for lists of grids. Each tab holds list of grids for a given
207 // type of ID telescope.
208 fGridListTabs = new TGTab(fHframe, 550, 400);
209 fGridListTabs->Connect("Selected(Int_t)", "KVIDGridManagerGUI", this, "TabSelect(Int_t)");
210 fIDGridList = 0;
211 //initialise tabs with lists of grids
212 CreateAndFillTabs();
213
214 fHframe->AddFrame(fGridListTabs,
216
217 TGVerticalFrame* line_frame = new TGVerticalFrame(fHframe, 350, 400);
218
219 TGLabel* lab1 = new TGLabel(line_frame, "CURRENT GRID IDENTIFIERS");
220 line_frame->AddFrame(lab1, new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 2, 2, 10, 2));
221
222 // list view for lines in current grid
223 fIDLineList = new KVListView(KVIDentifier::Class(), line_frame, 350, 400);
224 fIDLineList->SetDataColumns(5);
225 fIDLineList->SetDataColumn(0, "Name", "", kTextLeft);
226 fIDLineList->SetDataColumn(1, "Z", "", kTextCenterX);
227 fIDLineList->SetDataColumn(2, "A", "", kTextCenterX);
228 fIDLineList->SetDataColumn(3, "OnlyZId", "OnlyZId", kTextCenterX);
229 fIDLineList->SetDataColumn(4, "MassFormula", "", kTextCenterX);
230 fIDLineList->GetDataColumn(3)->SetIsBoolean();
231 fIDLineList->ActivateSortButtons();
232 fIDLineList->AllowBrowse(kFALSE);
233 //fIDLineList->Connect("SelectionChanged()", "KVIDGridManagerGUI", this,
234 // "SelectionChanged()");
235 line_frame->AddFrame(fIDLineList, new TGLayoutHints(kLHintsTop | kLHintsExpandY | kLHintsExpandX, 2, 2, 2, 10));
236
237 lab1 = new TGLabel(line_frame, "Cuts");
238 line_frame->AddFrame(lab1, new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 2, 2, 2, 2));
239
240 fCUTList = new KVListView(KVIDentifier::Class(), line_frame, 350, 150);
241 fCUTList->SetDataColumns(3);
242 fCUTList->SetDataColumn(0, "Name", "", kTextLeft);
243 fCUTList->SetDataColumn(1, "# Points", "GetN", kTextCenterX);
244 fCUTList->SetDataColumn(2, "Class", "ClassName", kTextCenterX);
245// fCUTLineList->SetDataColumn(2, "Direction", "GetAcceptedDirection", kTextCenterX);
246 fCUTList->ActivateSortButtons();
247 fCUTList->AllowBrowse(kFALSE);
248 //fIDLineList->Connect("SelectionChanged()", "KVIDGridManagerGUI", this,
249 // "SelectionChanged()");
250 line_frame->AddFrame(fCUTList, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 2, 2, 2));
251
252 lab1 = new TGLabel(line_frame, "Infos");
253 line_frame->AddFrame(lab1, new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 2, 2, 2, 2));
254
255 fCUTInfoList = new KVListView(KVIDentifier::Class(), line_frame, 350, 150);
256 fCUTInfoList->SetDataColumns(3);
257 fCUTInfoList->SetDataColumn(0, "Name", "", kTextLeft);
258 fCUTInfoList->SetDataColumn(1, "# Points", "GetN", kTextCenterX);
259 fCUTInfoList->SetDataColumn(2, "Class", "ClassName", kTextCenterX);
260// fCUTContourList->SetDataColumn(2, "Exclusive", "IsExclusive", kTextCenterX);
261// fCUTContourList->GetDataColumn(2)->SetIsBoolean();
262 fCUTInfoList->ActivateSortButtons();
263 fCUTInfoList->AllowBrowse(kFALSE);
264 //fIDLineList->Connect("SelectionChanged()", "KVIDGridManagerGUI", this,
265 // "SelectionChanged()");
266 line_frame->AddFrame(fCUTInfoList, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 2, 2, 10));
267
268 fHframe->AddFrame(line_frame, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandY, 20, 20, 20, 20));
269
270 AddFrame(fHframe,
272 0));
273
274 SetWindowName("ID Grid Manager");
275
276 //layout & draw window
278 Resize(GetDefaultSize());
279 MapWindow();
280 SetWMSize(1200, 600);
281
282 // first tab is visible, but TabSelect(0) is not called automatically
283 TabSelect(0);
284
285}
286
287
288
291
293{
294 //close window
295 UnmapWindow();
296 gIDGridManager->Disconnect("Modified()", this, "UpdateListOfGrids()");
297}
298
299
300
303
305{
306 //close viewer
307 DeleteWindow();
308}
309
310
311
313
315{
318 if (fSelectedGrid) {
319 // avant d'editer la grille, on en fait une copie pour
320 // pouvoir revenir en arriere
323 }
324}
325
326
327
330
332{
333 //Info("StartEditor(TObject*)", "obj=%p", o);
334 StartEditor();
335}
336
337
338
340
342{
343 static TString dir("$HISTOROOT");
344 TString currentdir(gSystem->ExpandPathName("."));
345
346 if (gSystem->ExpandPathName(dir)) dir = ".";
347
348 const char* filetypes[] = {"Root files", "*.root", "All files", "*", 0, 0};
349 TGFileInfo fi;
350 fi.fFileTypes = filetypes;
351 fi.fIniDir = StrDup(dir);
352 new TGFileDialog(fClient->GetDefaultRoot(), this, kFDOpen, &fi);
353 if (fi.fFilename) {
354 if (!(TFile::Open(fi.fFilename))) {
355 new TGMsgBox(gClient->GetDefaultRoot(), gClient->GetDefaultRoot(), "ID Grid Editor", Form("Could not open file %s", fi.fFilename), 0, kMBOk);
356 }
357 }
358 dir = fi.fIniDir;
359 gSystem->cd(currentdir.Data());
360}
361
362
363
366
368{
369 //Receive signals emitted by items selected in Grids menu
370 switch (id) {
371
372 case M_QUIT:
373
374 Quit();
375 break;
376
377 case M_GRIDS_NEW:
378
379 cout << "Add new grid" << endl;
380 NewGrid();
381 break;
382 case M_GRIDS_READ:
383 OpenFile();
384 break;
385
386 case M_GRIDS_SAVE_SEL:
387 // save current selection of grids in file
389 break;
390
391 case M_GRIDS_SAVE_TAB:
392 // save all grids in current tab in file
394 break;
395
396 case M_GRIDS_SAVE_ALL:
397
398 //save all grids in file - ask user to confirm or change filename/path
399 SaveGridsAs();
400 break;
401
402 case M_GRIDS_DEL_SEL:
404 break;
405
406 case M_GRIDS_DEL_TAB:
407 //warning message and confirmation
408 {
409 Int_t ret_val;
410 new TGMsgBox(fClient->GetDefaultRoot(), this, "ID Grid Manager",
411 "This will delete all grids in the current tab. Are you sure ?",
412 kMBIconExclamation, kMBOk | kMBCancel, &ret_val);
413 if (ret_val & kMBOk) {
415 }
416 }
417 break;
418 case M_GRIDS_DEL_ALL:
419
420 //warning message and confirmation
421 {
422 Int_t ret_val;
423 new TGMsgBox(fClient->GetDefaultRoot(), this, "ID Grid Manager",
424 "This will delete all grids. Are you sure ?",
425 kMBIconExclamation, kMBOk | kMBCancel, &ret_val);
426 if (ret_val & kMBOk) {
427 gIDGridManager->Clear();
428 //UpdateListOfGrids();
430 //with an empty file !!
431 fFileName = "";
432 }
433 }
434 break;
435
437 // set runlist for all selected grids
438 {
439 if (!fSelectedGrid) break; // must have selected at least one grid
440 TString runs = fSelectedGrid->GetRunList(); // fill dialog box with current runlist of selected grid
441 Bool_t ok_pressed = kFALSE;
442 new KVInputDialog(this, "Enter list of runs for grid(s):", &runs, &ok_pressed,
443 "Example: 1-10, 13, 22-657");
444 if (!ok_pressed) break; // user pressed 'cancel' or otherwise closed the dialog
445 TIter next(fSelectedEntries.get());
446 KVIDGraph* entry;
447 while ((entry = (KVIDGraph*) next())) {
448 entry->SetRunList(runs.Data());
449 }
450 }
451 break;
452 case M_GRIDS_SET_VARX:
453 // set varx for all selected grids
454 {
455 if (!fSelectedGrid) break; // must have selected at least one grid
456 TString runs = fSelectedGrid->GetVarX(); // fill dialog box with current runlist of selected grid
457 Bool_t ok_pressed = kFALSE;
458 new KVInputDialog(this, "Enter X variable for grid(s):", &runs, &ok_pressed,
459 "");
460 if (!ok_pressed) break; // user pressed 'cancel' or otherwise closed the dialog
461 TIter next(fSelectedEntries.get());
462 KVIDGraph* entry;
463 while ((entry = (KVIDGraph*) next())) {
464 entry->SetVarX(runs.Data());
465 }
466 }
467 break;
468 case M_GRIDS_SET_VARY:
469 // set varx for all selected grids
470 {
471 if (!fSelectedGrid) break; // must have selected at least one grid
472 TString runs = fSelectedGrid->GetVarY(); // fill dialog box with current runlist of selected grid
473 Bool_t ok_pressed = kFALSE;
474 new KVInputDialog(this, "Enter Y variable for grid(s):", &runs, &ok_pressed,
475 "");
476 if (!ok_pressed) break; // user pressed 'cancel' or otherwise closed the dialog
477 TIter next(fSelectedEntries.get());
478 KVIDGraph* entry;
479 while ((entry = (KVIDGraph*) next())) {
480 entry->SetVarY(runs.Data());
481 }
482 }
483 break;
484 case M_GRIDS_SET_ZID:
485 // set varx for all selected grids
486 {
487 if (!fSelectedGrid) break; // must have selected at least one grid
488 Bool_t runs = !fSelectedGrid->HasMassIDCapability(); // fill dialog box with current runlist of selected grid
489 TIter next(fSelectedEntries.get());
490 KVIDGraph* entry;
491 while ((entry = (KVIDGraph*) next())) {
492 entry->SetOnlyZId(!runs);
493 }
494 }
495 break;
496 case M_GRIDS_CLEAR:
497 // set varx for all selected grids
498 {
499 if (!fSelectedGrid) break; // must have selected at least one grid
500 TIter next(fSelectedEntries.get());
501 KVIDGraph* entry;
502 while ((entry = (KVIDGraph*) next())) {
503 entry->Clear();
504 }
505 }
506 break;
507
508 default:
509
510 break;
511 }
512}
513
514
515
518
520{
521 //warning message and confirmation
522 Int_t ret_val;
523 new TGMsgBox(fClient->GetDefaultRoot(), this, "ID Grid Manager",
524 "This will delete the selected grids. Are you sure ?",
525 kMBIconExclamation, kMBOk | kMBCancel, &ret_val);
526 if (ret_val & kMBOk) {
527 DeleteGrids();
528 }
529}
530
531
532
534
536{
537 static TString dir(".");
538 const char* filetypes[] = {
539 "ID Grid files", "*.dat",
540 "All files", "*",
541 0, 0
542 };
543 TGFileInfo fi;
544 fi.fFileTypes = filetypes;
545 fi.fIniDir = StrDup(dir);
546 //printf("fIniDir = %s\n", fi.fIniDir);
547 new TGFileDialog(fClient->GetDefaultRoot(), this, kFDOpen, &fi);
548 if (fi.fFilename) {
549 int ngri = gIDGridManager->GetGrids()->GetEntries();
550 bool ok = gMultiDetArray ? gMultiDetArray->ReadGridsFromAsciiFile(fi.fFilename)
551 : gIDGridManager->ReadAsciiFile(fi.fFilename);
552 if (ok) {
554 //read file ok no problem.
555 int ngriread = gIDGridManager->GetGrids()->GetEntries() - ngri;
556 SetStatus(Form("Read %d grids from file %s", ngriread, fi.fFilename));
557 //set filename for Save
559 }
560 else {
561 new TGMsgBox(fClient->GetDefaultRoot(), this, "ID Grid Manager",
562 Form("Could not read file %s", fi.fFilename),
563 0, kMBOk);
564 }
565 }
566 dir = fi.fIniDir;
567}
568
569
570
576
578{
579 //remove all existing entries, then fill list from gIDGridManager
580 //we update the current pad, in case the displayed grid no longer exists
581 //grid buttons are disabled, as any selected grid is deselected
582 // cout << "DEBUG: KVIDGridManagerGUI::UpdateListOfGrids(): starting..." << endl;
583 UpdateTabs();
584 // cout << "DEBUG: KVIDGridManagerGUI::UpdateListOfGrids(): tabs has been updated !" << endl;
585 //update all canvases
586// TSeqCollection* Clist = gROOT->GetListOfCanvases();
587// if (Clist && Clist->GetEntries()) {
588// Clist->R__FOR_EACH(TCanvas, Modified)();
589// Clist->R__FOR_EACH(TCanvas, Update)();
590// }
591 // cout << "DEBUG: KVIDGridManagerGUI::UpdateListOfGrids(): canvas has been updated !" << endl;
592}
593
594
595
603
605{
606 //called any time the selection of grids changes
607 //each time, we update:
608 //fSelectedEntries : the list of all selected entries
609 //GetNSelected() : the number of selected entries
610 //fSelectedGrid : the last selected grid (=the only grid selected if GeTNSelected==1)
611
612 //get number of selected items
615 if (!GetNSelected())fSelectedGrid = 0x0;
617 //(de)activate toolbar buttons
619 if (!GetNSelected()) SetStatus();
620 else if (GetNSelected() == 1) SetStatus(Form("Selected grid %s (%s)", fSelectedGrid->GetName(), fSelectedGrid->ClassName()));
621 else SetStatus(Form("Selected %d grids, last selected grid %s (%s)", GetNSelected(), fSelectedGrid->GetName(), fSelectedGrid->ClassName()));
622}
623
624
625
628
630{
631 //returns current number of selected items in grid list
632 return (fSelectedEntries ? fSelectedEntries->GetSize() : 0);
633}
634
635
636
639
641{
642 //delete the current selected grid, or all currently selected grids if there are more than one
643
644 if (!GetNSelected()) return;
645
647 KVIDGraph* entry;
648 while ((entry = (KVIDGraph*) next())) {
649 // cout << "DEBUG: KVIDGridManagerGUI::DeleteGrids(): deleting grid '" << entry->GetName() << "' !" << endl;
650 if (fLastSelectedGrid == entry) fLastSelectedGrid = 0;
651 gIDGridManager->DeleteGrid(entry, kFALSE); //no update
652 // cout << "DEBUG: KVIDGridManagerGUI::DeleteGrids(): grid has been deleted !" << endl;
653 }
654
655 // cout << "DEBUG: KVIDGridManagerGUI::DeleteGrids(): list of selected grids has been deleted !" << endl;
656 fSelectedEntries.reset(nullptr);
657 fSelectedGrid = 0;
659 // cout << "DEBUG: KVIDGridManagerGUI::DeleteGrids(): list of grids has been updated !" << endl;
660}
661
662
663
666
668{
669 //delete the all grids in currently selected tab
670
672 KVIDGraph* entry;
673 while ((entry = (KVIDGraph*) next())) {
674 gIDGridManager->DeleteGrid(entry, kFALSE); //no update
675 }
676 fSelectedEntries.reset(nullptr);
677 fSelectedGrid = 0;
679}
680
681
682
685
687{
688 // Set ID telescopes for selected grid
689 Bool_t cancel;
690 TList telescopes;
691 telescopes.AddAll(fSelectedGrid->GetIDTelescopes());
692 new KVIDGUITelescopeChooserDialog(gMultiDetArray, &telescopes, &cancel,
693 fClient->GetDefaultRoot(), this, kTRUE);
694 if (cancel || !telescopes.GetEntries()) return;
696 fSelectedGrid->AddIDTelescopes(&telescopes);
697}
698
699
700
703
705{
706 //deletes all lines in currently selected grid(s)
707
708 if (GetNSelected() == 1)
710 else if (GetNSelected() > 1) {
711 //multiselection
712 TIter next(fSelectedEntries.get());
713 KVIDGraph* grid;
714 while ((grid = (KVIDGraph*) next())) {
715 grid->Clear();
716 }
717 }
718 //update all canvases
719 TSeqCollection* Clist = gROOT->GetListOfCanvases();
720 if (Clist->GetSize() > 0) {
721 Clist->R__FOR_EACH(TCanvas, Modified)();
722 Clist->R__FOR_EACH(TCanvas, Update)();
723 }
724}
725
726
727
729
731{
732 if (!fSelectedGrid) return;
733 gIDGridManager->Disconnect("Modified()", this, "UpdateListOfGrids()");
735 fSelectedGrid->Copy(*new_gr);
737 new_gr->SetRunList("");
738 gIDGridManager->GetGrids()->Sort();
739 UpdateTabs();
740 gIDGridManager->Connect("Modified()", "KVIDGridManagerGUI", this, "UpdateListOfGrids()");
741 fIDGridList->Sort(0);
742 fIDGridList->Sort(0);
743 return;
744}
745
746
747
754
756{
757 // Create a new identification grid.
758 // First we ask the user to select the identification telescope(s)
759 // for which this grid will be used.
760 // For a given type of ID telescope, several types of grid may be
761 // applicable. If so, we ask the user to choose one.
762
763 Info("NewGrid", "There are %d grids in the manager", gIDGridManager->GetGrids()->GetSize());
764 TString default_class = "KVIDZAGrid";
765 TList* telescopes = new TList;
766 if (gMultiDetArray) {
767 Bool_t cancel;
768 new KVIDGUITelescopeChooserDialog(gMultiDetArray, telescopes, &cancel,
769 fClient->GetDefaultRoot(), this);
770 if (cancel || !telescopes->At(0)) {
771 Info("NewGrid", "No ID telescopes chosen. Grid creation cancelled.");
772 return;
773 }
774 // get default ID grid class of first ID telescope
775 default_class = ((KVIDTelescope*)telescopes->At(0))->GetDefaultIDGridClass();
776 }
777 // get list of possible choices of grid class = list of all plugin classes
778 // defined for KVIDGraph
779 TString choice = KVBase::GetListOfPlugins("KVIDGraph");
780 // open dialog to choose ID grid class
781 Bool_t ok_pressed = kFALSE;
782 TString id_grid_class;
783 new KVDropDownDialog(this, "Choose class for new grid:",
784 choice.Data(), default_class.Data(), &id_grid_class, &ok_pressed);
785 if (!ok_pressed) {
786 Info("NewGrid", "No ID grid class chosen. Grid creation cancelled.");
787 return;
788 }
789 gIDGridManager->Disconnect("Modified()", this, "UpdateListOfGrids()");
790 KVIDGraph* new_gr = KVIDGraph::MakeIDGraph(id_grid_class.Data());
791 if (telescopes->GetEntries()) new_gr->AddIDTelescopes(telescopes);
792 UpdateTabs();
793 gIDGridManager->Connect("Modified()", "KVIDGridManagerGUI", this, "UpdateListOfGrids()");
794 delete telescopes;
795}
796
797
798
804
806{
807 //merge 2 grids
808 //KVIDGraph *g1 = (KVIDGraph *) fSelectedEntries->At(1);
809 //KVIDGraph *g2 = (KVIDGraph *) fSelectedEntries->First();
810 //new KVMergeGridsDialog(g1, g2, fClient->GetDefaultRoot(), this, 10, 10);
811}
812
813
814
819
821{
822 // Opens dialog to choose filename in which to save grids.
823 // If selection=0 (default), all grids are saved
824 // If selection!=0 only grids in list are saved
825
826 static TString dir(".");
827 const char* filetypes[] = {
828 "ID Grid files", "*.dat",
829 "All files", "*",
830 0, 0
831 };
832 TGFileInfo fi;
833 fi.fFileTypes = filetypes;
834 fi.fIniDir = StrDup(dir);
835 if (fFileName != "") fi.fFilename = StrDup(fFileName);
836 new TGFileDialog(fClient->GetDefaultRoot(), this, kFDSave, &fi);
837 if (fi.fFilename) {
838 //if no ".xxx" ending given, we add ".dat"
839 TString filenam(fi.fFilename);
840 if (!filenam.Contains('.'))
841 filenam += ".dat";
842 Int_t n_saved = gIDGridManager->WriteAsciiFile(filenam.Data(), selection);
843 if (n_saved) {
844 //wrote file no problem
845 SetStatus(Form("Saved %d grids in file %s", n_saved, filenam.Data()));
846 //set file name for Save
847 fFileName = gSystem->BaseName(filenam);
848 }
849 else {
850 new TGMsgBox(fClient->GetDefaultRoot(), this, "ID Grid Manager",
851 Form("Could not write file %s", filenam.Data()), 0,
852 kMBOk);
853 }
854 }
855 dir = fi.fIniDir;
856}
857
858
859
863
865{
866 // create a tab for each type of ID telescope
867 // put a list box for ID grid names on each tab
868
869 KVString labels;
870 if (gIDGridManager->GetGrids()->GetSize()) gIDGridManager->GetListOfIDTelescopeLabels(labels);
871 if (labels == "") {
872 // no known idtelescopes referenced by grids (maybe we don't have a KVMultiDetArray?)
873 // make 1 tab "Grids" and put them all in
874 KVString lab = "Grids";
877 fIDGridList = new KVListView(KVIDGraph::Class(), cf, 600, 400);
879 fIDGridList->SetDataColumn(0, "Name", "", kTextLeft);
880 fIDGridList->SetDataColumn(2, "VarX", "", kTextLeft);
881 fIDGridList->SetDataColumn(1, "VarY", "", kTextLeft);
882 fIDGridList->SetDataColumn(3, "ID Telescopes", "GetNamesOfIDTelescopes", kTextLeft);
883 fIDGridList->SetDataColumn(4, "RunList", "", kTextLeft);
884 fIDGridList->SetDataColumn(5, "Identify Z and A?", "HasMassIDCapability", kTextCenterX);
886 fIDGridList->SetDataColumn(6, "# Ident.", "GetNumberOfIdentifiers", kTextRight);
887 fIDGridList->SetDataColumn(7, "# Cuts", "GetNumberOfCuts", kTextRight);
888 fIDGridList->SetDataColumn(8, "# Infos", "GetNumberOfInfos", kTextRight);
889 fIDGridList->SetDataColumn(9, "X scaling", "GetXScaleFactor", kTextRight);
890 fIDGridList->SetDataColumn(10, "Y scaling", "GetYScaleFactor", kTextRight);
892 fIDGridList->Connect("SelectionChanged()", "KVIDGridManagerGUI", this,
893 "SelectionChanged()");
894 fIDGridList->SetDoubleClickAction("KVIDGridManagerGUI", this, "StartEditor(TObject*)");
897 10, 10, 10));
898 KVList* grids = gIDGridManager->GetGrids();
899 fIDGridList->Display(grids);
900 return;
901 }
902 //loop over labels
903 labels.Begin(",");
904 while (! labels.End()) {
905 KVString lab = labels.Next();
908 fIDGridList = new KVListView(KVIDGraph::Class(), cf, 600, 400);
910 fIDGridList->SetDataColumn(0, "Name", "", kTextLeft);
911 fIDGridList->SetDataColumn(2, "VarX", "", kTextLeft);
912 fIDGridList->SetDataColumn(1, "VarY", "", kTextLeft);
913 fIDGridList->SetDataColumn(3, "ID Telescopes", "GetNamesOfIDTelescopes", kTextLeft);
914 fIDGridList->SetDataColumn(4, "RunList", "", kTextLeft);
915 fIDGridList->SetDataColumn(5, "Identify Z and A?", "HasMassIDCapability", kTextCenterX);
917 fIDGridList->SetDataColumn(6, "# Ident.", "GetNumberOfIdentifiers", kTextRight);
918 fIDGridList->SetDataColumn(7, "# Cuts", "GetNumberOfCuts", kTextRight);
919 fIDGridList->SetDataColumn(8, "X scaling", "GetXScaleFactor", kTextRight);
920 fIDGridList->SetDataColumn(9, "Y scaling", "GetYScaleFactor", kTextRight);
922 fIDGridList->Connect("SelectionChanged()", "KVIDGridManagerGUI", this,
923 "SelectionChanged()");
924 fIDGridList->SetDoubleClickAction("KVIDGridManagerGUI", this, "StartEditor(TObject*)");
927 10, 10, 10));
928 KVList* grids = gIDGridManager->GetGridsForIDTelescope(lab);
929 fIDGridList->Display(grids);
930 delete grids;
931 }
932
933}
934
935
936
939
941{
942 //called when a new tab is selected
943
945 if (!cf) return;//there are no tabs
946 TGFrameElement* el = (TGFrameElement*)cf->GetList()->At(0);
949}
950
951
952
957
959{
960 // create a tab for each type of ID telescope
961 // put a list box for ID grid names on each tab
962 // cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : starting..." << endl;
963
964 KVString labels("");
965 if (gIDGridManager->GetGrids()->GetSize()) gIDGridManager->GetListOfIDTelescopeLabels(labels);
966 else {
967 // there are no grids in the grid manager
969 KVString lab = "Grids";
972 fIDGridList = new KVListView(KVIDGraph::Class(), cf, 600, 400);
974 fIDGridList->SetDataColumn(0, "Name", "", kTextLeft);
975 fIDGridList->SetDataColumn(2, "VarX", "", kTextLeft);
976 fIDGridList->SetDataColumn(1, "VarY", "", kTextLeft);
977 fIDGridList->SetDataColumn(3, "ID Telescopes", "GetNamesOfIDTelescopes", kTextLeft);
978 fIDGridList->SetDataColumn(4, "RunList", "", kTextLeft);
979 fIDGridList->SetDataColumn(5, "Identify Z and A?", "HasMassIDCapability", kTextCenterX);
981 fIDGridList->SetDataColumn(6, "# Ident.", "GetNumberOfIdentifiers", kTextRight);
982 fIDGridList->SetDataColumn(7, "# Cuts", "GetNumberOfCuts", kTextRight);
983 fIDGridList->SetDataColumn(8, "X scaling", "GetXScaleFactor", kTextRight);
984 fIDGridList->SetDataColumn(9, "Y scaling", "GetYScaleFactor", kTextRight);
986 fIDGridList->Connect("SelectionChanged()", "KVIDGridManagerGUI", this,
987 "SelectionChanged()");
990 10, 10, 10));
993 Int_t ntabs = fGridListTabs->GetCurrent();
994 TabSelect(ntabs);
995 return;
996 }
997 if (labels == "") {
998 // no known idtelescopes referenced by grids (maybe we don't have a KVMultiDetArray?)
999 // update "Grids" tab
1001 if (!cf) {
1002 cout << "cf = 0x0 : label=Grids tab name=" <<
1003 fGridListTabs->GetTabTab("Grids")->GetText()->GetString() << endl;
1004 }
1005 else {
1006 TGFrameElement* el = (TGFrameElement*)cf->GetList()->At(0);
1008 KVList* grids = gIDGridManager->GetGrids();
1009 fIDGridList->Display(grids);
1010 }
1011 //make sure we are on the right tab
1012 Int_t ntabs = fGridListTabs->GetCurrent();
1013 TabSelect(ntabs);
1014 return;
1015 }
1016 //add any missing labels, update existing ones
1017 labels.Begin(",");
1018 while (! labels.End()) {
1019 KVString lab = labels.Next();
1020 // cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : updating tab '" << lab.Data() << "'..." << endl;
1021 if (!fGridListTabs->GetTabContainer(lab.Data())) { // new tab
1022 // cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : new tab '" << lab.Data() << "'..." << endl;
1025 fIDGridList = new KVListView(KVIDGraph::Class(), cf, 600, 400);
1027 fIDGridList->SetDataColumn(0, "Name", "", kTextLeft);
1028 fIDGridList->SetDataColumn(2, "VarX", "", kTextLeft);
1029 fIDGridList->SetDataColumn(1, "VarY", "", kTextLeft);
1030 fIDGridList->SetDataColumn(3, "ID Telescopes", "GetNamesOfIDTelescopes", kTextLeft);
1031 fIDGridList->SetDataColumn(4, "RunList", "", kTextLeft);
1032 fIDGridList->SetDataColumn(5, "Identify Z and A?", "HasMassIDCapability", kTextCenterX);
1034 fIDGridList->SetDataColumn(6, "# Ident.", "GetNumberOfIdentifiers", kTextRight);
1035 fIDGridList->SetDataColumn(7, "# Cuts", "GetNumberOfCuts", kTextRight);
1036 fIDGridList->SetDataColumn(8, "# Infos", "GetNumberOfInfos", kTextRight);
1037 fIDGridList->SetDataColumn(9, "X scaling", "GetXScaleFactor", kTextRight);
1038 fIDGridList->SetDataColumn(10, "Y scaling", "GetYScaleFactor", kTextRight);
1040 fIDGridList->Connect("SelectionChanged()", "KVIDGridManagerGUI", this,
1041 "SelectionChanged()");
1044 10, 10, 10));
1045 KVList* grids = gIDGridManager->GetGridsForIDTelescope(lab);
1046 fIDGridList->Display(grids);
1047 delete grids;
1051 }
1052 else { //existing tab
1053 //cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : existing tab '" << lab.Data() << "'..." << endl;
1055 if (!cf) {
1056 cout << "cf = 0x0 : label=" << lab.Data() << " tab name=" <<
1057 fGridListTabs->GetTabTab(lab.Data())->GetText()->GetString() << endl;
1058 }
1059 else {
1060 //cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : recup tab '" << cf->GetName() << "'..." << endl;
1061 TGFrameElement* el = (TGFrameElement*)cf->GetList()->At(0);
1062 //cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : recup element '" << el->GetName() << "'..." << endl;
1064 //cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : recup view list '" << fIDGridList->GetName() << "'..." << endl;
1065 KVList* grids = gIDGridManager->GetGridsForIDTelescope(lab);
1066 //cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : recup list de telescope'" << grids->GetName() << "'..." << endl;
1067 //grids->ls();
1068 fIDGridList->Display(grids);
1069 //cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : display list of grids in the viewerlist..." << endl;
1070
1071 if (grids) delete grids;
1072 // cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : deleting the list..." << endl;
1073 }
1074 }
1075 }
1076 //now check that none of the remaining tabs are empty & should be removed
1078 // cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : empty tabs removed !" << endl;
1079 //make sure we are on the right tab
1080 Int_t ntabs = fGridListTabs->GetCurrent();
1081 TabSelect(ntabs);
1082 // cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : current tab selected !" << endl;
1083}
1084
1085
1086
1089
1091{
1092 // Recursively remove any empty tabs
1093
1095 Bool_t recursive = kFALSE;
1096 for (Int_t itab = 0; itab < ntabs; itab++) {
1097
1098 //get name of tab
1099 KVString lab = fGridListTabs->GetTabTab(itab)->GetString();
1100 //get grids for this tab (if any)
1101 KVList* grids = gIDGridManager->GetGridsForIDTelescope(lab);
1102 Int_t ngrids = grids->GetEntries();
1103 delete grids;
1104 if (!ngrids) {
1105 //empty tab! remove it!
1106 //delete the KVListView
1108 TGFrameElement* el = (TGFrameElement*)cf->GetList()->At(0);
1109 KVListView* lv = (KVListView*)el->fFrame;
1110 delete lv;
1111 //remove tab
1113 recursive = kTRUE; // call recursively
1114 break;//stop loop - tab numbers have changed
1115 }
1116 }
1117 if (recursive) RemoveEmptyTabs();
1120}
1121
1122
1123
1127
1129{
1130 // called when a previously selected grid is modified
1131 // updates lists of lines
1132
1133 if (!fLastSelectedGrid) return;
1134
1136 // sort lines in order of increasing Z
1137 ids->Sort();
1138 fIDLineList->Display(ids);
1139// KVSeqCollection* cutlines = fSelectedGrid->GetCuts()->GetSubListWithClass("KVIDCutLine");
1141// fCUTLineList->Display(cutlines);
1142// delete cutlines;
1143// cutlines = fSelectedGrid->GetCuts()->GetSubListWithClass("KVIDCutContour");
1145// fCUTContourList->Display(cutlines);
1146// delete cutlines;
1147}
1148
1149
1150
1156
1158{
1159 // Called when a grid is selected in list of grids
1160 // We fill list of all lines in grid
1161 //If only one grid is selected, we display its lines in the line list
1162 //If more than one grid is selected, we clear the line list
1163
1164 if (GetNSelected() == 1 && fSelectedGrid) {
1166 // sort lines in order of increasing Z
1167 ids->Sort();
1168 fIDLineList->Display(ids);
1169// KVSeqCollection* cutlines = fSelectedGrid->GetCuts()->GetSubListWithClass("KVIDCutLine");
1171// delete cutlines;
1172// cutlines = fSelectedGrid->GetCuts()->GetSubListWithClass("KVIDCutContour");
1174// delete cutlines;
1175 if (fLastSelectedGrid) {
1176 fLastSelectedGrid->Disconnect("Modified()", this, "UpdateListOfLines()");
1177 }
1178 fSelectedGrid->Connect("Modified()", "KVIDGridManagerGUI", this, "UpdateListOfLines()");
1180 }
1181 else {
1185 if (fLastSelectedGrid) {
1186 fLastSelectedGrid->Disconnect("Modified()", this, "UpdateListOfLines()");
1188 }
1189 }
1190}
1191
1192
1193
1196
1198{
1199 // disable all buttons
1200 for (int i = 0; i < fNbButtons; i++) fTBbuttons[i]->SetEnabled(kFALSE);
1201 // enable 'open' & 'quit' & 'new grid"
1204// fTBStartEditor->SetEnabled();
1207 // enable 'save' if there are grids
1208 if (gIDGridManager->GetGrids()->GetEntries()) fTBSave->SetEnabled();
1209
1210 if (!GetNSelected()) return; // no grids selected
1211
1212 //enable delete selected grid(s)
1214
1215 if (GetNSelected() == 1) {
1216 // only one grid selected
1219 if (gMultiDetArray) fTBSetIDG->SetEnabled();
1220 }
1221}
1222
1223
1224
1236
1238{
1239 // GUI method to draw a new identifier and add it to graph.
1240 // A dialog box with drop-down list pops up for the user to choose the class of the
1241 // new identifier, unless only one choice is possible, in which case it is used automatically.
1242 // For each KVIDGraph-derived class, the list of possible identifier classes and the
1243 // default class are define in .kvrootrc by the variables:
1244 //
1245 // [class_name].IDClass: [id class 1]
1246 // +[class_name].IDClass: [id class 2]
1247 // + ...
1248 // [class_name].DefaultIDClass: [id class]
1249
1250 if (!fSelectedGrid || GetNSelected() != 1) return;
1251 TString resname;
1252 resname.Form("%s.IDClass", fSelectedGrid->ClassName());
1253 TString cut_choices = gEnv->GetValue(resname.Data(), "");
1254 resname.Form("%s.DefaultIDClass", fSelectedGrid->ClassName());
1255 TString cut_default = gEnv->GetValue(resname.Data(), "");
1256 TString cut_class;
1257 Bool_t okpressed;
1258 if (cut_choices.Contains(" ")) {
1259 new KVDropDownDialog(this,
1260 "Choose class of new identifier :",
1261 cut_choices.Data(),
1262 cut_default.Data(),
1263 &cut_class,
1264 &okpressed);
1265 if (!okpressed) return;
1266 }
1267 else
1268 cut_class = cut_choices;
1269 SetStatus(Form("Draw ID line (%s) in current pad", cut_class.Data()));
1270 fSelectedGrid->DrawAndAdd("ID", cut_class.Data());
1272 SetStatus();
1273}
1274
1275
1276
1288
1290{
1291 // GUI method to draw a new cut and add it to graph.
1292 // A dialog box with drop-down list pops up for the user to choose the class of the
1293 // new cut, unless only one choice is possible, in which case it is used automatically.
1294 // For each KVIDGraph-derived class, the list of possible cut classes and the
1295 // default class are define in .kvrootrc by the variables:
1296 //
1297 // [class_name].CutClass: [cut class 1]
1298 // +[class_name].CutClass: [cut class 2]
1299 // + ...
1300 // [class_name].DefaultCutClass: [cut class]
1301
1302 if (!fSelectedGrid || GetNSelected() != 1) return;
1303 TString resname;
1304 resname.Form("%s.CutClass", fSelectedGrid->ClassName());
1305 TString cut_choices = gEnv->GetValue(resname.Data(), "");
1306 resname.Form("%s.DefaultCutClass", fSelectedGrid->ClassName());
1307 TString cut_default = gEnv->GetValue(resname.Data(), "");
1308 TString cut_class;
1309 TString cut_types = cut_choices;
1310 cut_types.ReplaceAll("KVIDCut", "");
1311 Bool_t okpressed;
1312 if (cut_choices.Contains(" ")) {
1313 new KVDropDownDialog(this,
1314 "Choose class of new cut :",
1315 cut_types.Data(),
1316 cut_default.Data(),
1317 &cut_class,
1318 &okpressed);
1319 if (!okpressed) return;
1320 }
1321 else
1322 cut_class = cut_types;
1323 SetStatus(Form("Draw cut %s in current pad", cut_class.Data()));
1324 cut_class.Prepend("KVIDCut");
1325 fSelectedGrid->DrawAndAdd("CUT", cut_class.Data());
1327 SetStatus();
1328}
1329
1330
1331
1332
1336
1338{
1339 // test the identification with selected grid
1340 // we search in current pad for the data histogram
1341
1342 SetStatus("");
1343 if (GetNSelected() != 1) return;
1344 if (!fSelectedGrid) return;
1345 // look for data histogram in current pad
1346 TH2* histo = 0;
1347 if (gPad) {
1348 TIter next(gPad->GetListOfPrimitives());
1349 TObject* o;
1350 while ((o = next())) {
1351 if (o->InheritsFrom("TH2")) {
1352 histo = (TH2*)o;
1353 break;
1354 }
1355 }
1356 }
1357 if (!histo) {
1358 SetStatus("No TH2 found in current pad. Select pad containing 2D histo with data to identify.");
1359 return;
1360 }
1361 else {
1362 SetStatus(Form("Test identification of data in current pad %s.", histo->GetName()));
1363 }
1364 new KVTestIDGridDialog(fClient->GetDefaultRoot(), this, 10, 10, fSelectedGrid, histo);
1365 SetStatus("");
1366}
1367
1368
1369
1373
1375{
1376 // test the identification with selected grid
1377 // we search in current pad for the data histogram
1378 SetStatus("");
1379 if (GetNSelected() != 1) return;
1380 if (!fSelectedGrid) return;
1381 // look for data histogram in current pad
1382 TH2* histo = 0;
1383 if (gPad) {
1384 TIter next(gPad->GetListOfPrimitives());
1385 TObject* o;
1386 while ((o = next())) {
1387 if (o->InheritsFrom("TH2")) {
1388 histo = (TH2*)o;
1389 break;
1390 }
1391 }
1392 }
1393 if (!histo) {
1394 SetStatus("No TH2 found in current pad. Select pad containing 2D histo with data to identify.");
1395 return;
1396 }
1397 else {
1398 SetStatus(Form("Test identification of data in current pad %s.", histo->GetName()));
1399 }
1400 TFile* tmpfiles = TestIdentificationWithTree(fSelectedGrid, histo->GetName());
1401 if (!tmpfiles) {
1402 SetStatus("There was a problem with the test ???");
1403 return;
1404 }
1405 new TCanvas;
1406 TH2* id = (TH2*)tmpfiles->Get("idcode_map");
1407 id->SetStats(kFALSE);
1408 id->Draw("zcol");
1409 TTree* t = (TTree*)tmpfiles->Get("tree_idresults");
1410 t->StartViewer();
1411 SetStatus("");
1412}
1413
1414
1415
1416
1429
1430TFile* KVIDGridManagerGUI::TestIdentificationWithTree(KVIDGraph* gr, const Char_t* name_of_data_histo)
1431{
1432 //This method allows to test the identification capabilities of the grid using data in a TH2F.
1433 //We assume that 'data' contains an identification map, whose 'x' and 'y' coordinates correspond
1434 //to this grid. Then we loop over every bin of the histogram, perform the identification (if
1435 //IsIdentifiable() returns kTRUE) and fill the two histograms with the resulting identification
1436 //and its dependence on the 'residual energy' i.e. the 'x'-coordinate of the 'data' histogram,
1437 //each identification weighted by the contents of the original data bin.
1438 //
1439 //The 'identification" we represent is the result of the KVReconstructedNucleus::GetPID() method.
1440 //For particles identified in Z only, this is the "real Z".
1441 //For particles with A & Z identification, this is Z + 0.1*(A - 2*Z)
1442
1443 //Initialize the grid: calculate line widths etc.
1444 gr->Initialize();
1445
1446 TH2F* data = (TH2F*)gROOT->FindObject(name_of_data_histo);
1447 if (!data) {
1448 printf(" KVIDGraph::TestIdentificationWithTree l histo %s n existe pas\n", name_of_data_histo);
1449 return 0;
1450 }
1451
1452
1455
1456 // store current memory directory
1457 TDirectory* CWD = gDirectory;
1458
1459 TTree* tid = 0;
1460 if ((tid = (TTree*)gROOT->FindObject("tree_idresults"))) {
1461 printf(" KVIDGraph::TestIdentificationWithTree effacemenent de l arbre existant\n");
1462 delete tid;
1463 }
1464 // create temporary file for tree
1465 TString fn("IDtestTree.root");
1467 TFile* tmpfile = new TFile(fn.Data(), "recreate");
1468 TH2F* idmap = (TH2F*)data->Clone("idcode_map");
1469 idmap->Reset();
1470 tid = new TTree("tree_idresults", "pid");
1471 Float_t br_xxx, br_yyy, br_stat, br_pid;
1472 Int_t br_idcode, br_isid;
1473
1474 tid->Branch("X", &br_xxx, "br_xxx/F");
1475 tid->Branch("Y", &br_yyy, "br_yyy/F");
1476 tid->Branch("Stat", &br_stat, "br_stat/F");
1477
1478 tid->Branch("PID", &br_pid, "br_pid/F");
1479 tid->Branch("IDcode", &br_idcode, "br_idcode/I");
1480 tid->Branch("IsIdentified", &br_isid, "br_isid/I");
1481
1482 Int_t tot_events = (Int_t) data->GetSum();
1483 Int_t events_read = 0;
1484 Float_t percent = 0., cumul = 10.;
1485
1486 //loop over data in histo
1487 for (int i = 1; i <= data->GetNbinsX(); i++) {
1488 for (int j = 1; j <= data->GetNbinsY(); j++) {
1489
1490 Stat_t poids = data->GetBinContent(i, j);
1491 if (poids == 0)
1492 continue;
1493 br_stat = Float_t(poids);
1494
1495 Axis_t x0 = data->GetXaxis()->GetBinCenter(i);
1496 Axis_t y0 = data->GetYaxis()->GetBinCenter(j);
1497 Axis_t wx = data->GetXaxis()->GetBinWidth(i);
1498 Axis_t wy = data->GetYaxis()->GetBinWidth(j);
1499
1500 br_xxx = Float_t(x0);
1501 br_yyy = Float_t(y0);
1502 //If bin content ('poids') is <=20, we perform the identification 'poids' times, each time with
1503 //randomly-drawn x and y coordinates inside this bin
1504 //If 'poids'>20, we perform the identification 20 times and we fill the histograms with
1505 //a weight poids/20
1506 Double_t x, y;
1507 Int_t kmax = (Int_t) TMath::Min(20., poids);
1508 //Double_t weight = (kmax == 20 ? poids / 20. : 1.);
1509
1510 for (int k = 0; k < kmax; k++) {
1511
1512 x = gRandom->Uniform(x0 - .5 * wx, x0 + .5 * wx);
1513 y = gRandom->Uniform(y0 - .5 * wy, y0 + .5 * wy);
1514 if (gr->IsIdentifiable(x, y)) {
1515 br_isid = 1;
1516 gr->Identify(x, y, idr);
1517 nuc.SetIdentification(idr, nullptr);
1518 br_pid = nuc.GetPID();
1519 br_idcode = gr->GetQualityCode();
1520 idmap->SetBinContent(i, j, br_idcode);
1521 }
1522 else {
1523 br_isid = 0;
1524 br_pid = -1;
1525 br_idcode = -1;
1526 idmap->SetBinContent(i, j, br_idcode);
1527 }
1528 tid->Fill();
1529 }
1530 events_read += (Int_t) poids;
1531 percent = (1. * events_read / tot_events) * 100.;
1532 gr->Increment((Float_t) events_read); //sends signal to GUI progress bar
1533 if (percent >= cumul) {
1534 cout << (Int_t) percent << "\% processed" << endl;
1535 cumul += 10;
1536 }
1537 //gSystem->ProcessEvents();
1538 }
1539 }
1540
1541 delete idr;
1542 CWD->cd();
1543 return tmpfile;
1544}
1545
1546
1547
1549
1551{
1552 SetStatus("");
1553 if (GetNSelected() != 1) return;
1554 if (!fSelectedGrid) return;
1555 SetStatus(Form("Fitting grid %s", fSelectedGrid->GetName()));
1557 fitter->SetGrid(fSelectedGrid);
1558 fitter->SetPad(fSelectedGrid->GetPad());
1559 TMethod* m = fitter->IsA()->GetMethodAny("FitPanel");
1560 TContextMenu* cm = new TContextMenu("FitPanel", "Context menu for KVVirtualIDFitter::FitPanel");
1561 cm->Action(fitter, m);
1562 delete cm;
1563}
1564
1565
int Int_t
kVerticalFrame
kHorizontalFrame
bool Bool_t
char Char_t
float Float_t
double Axis_t
constexpr Bool_t kFALSE
double Double_t
double Stat_t
constexpr Bool_t kTRUE
const Bool_t kIterBackward
#define gDirectory
R__EXTERN TEnv * gEnv
#define gClient
kFDOpen
kFDSave
kLHintsExpandY
kLHintsLeft
kLHintsCenterX
kLHintsTop
kLHintsExpandX
kMBCancel
kMBOk
kMBIconExclamation
kTextCenterX
kTextLeft
kTextRight
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize MapSubwindows
Option_t Option_t TPoint TPoint percent
#define gROOT
R__EXTERN TRandom * gRandom
char * Form(const char *fmt,...)
char * StrDup(const char *str)
R__EXTERN TSystem * gSystem
#define gPad
static const Char_t * GetListOfPlugins(const Char_t *base)
Definition KVBase.cpp:1260
static void GetTempFileName(TString &base)
Definition KVBase.cpp:848
static const Char_t * GetKVVersion()
Returns KaliVeda version string.
Definition KVBase.cpp:874
Ask user to choose between several options in a drop-down list.
ID Grid Manager dialog for choice of ID telescope(s)
Base class for particle identification in a 2D map.
Definition KVIDGraph.h:32
void SetRunList(const char *runlist)
Definition KVIDGraph.h:156
virtual void SetVarX(const char *v)
Definition KVIDGraph.h:525
const TList * GetIDTelescopes() const
Definition KVIDGraph.h:245
void UpdateLastSavedVersion()
update last saved version. mkae copy of current state of graph.
virtual void Copy(TObject &) const
Copy this to 'obj'.
virtual Bool_t HasMassIDCapability() const
Definition KVIDGraph.h:169
TVirtualPad * GetPad() const
Definition KVIDGraph.h:133
const KVList * GetIdentifiers() const
Definition KVIDGraph.h:298
virtual void SetVarY(const char *v)
Definition KVIDGraph.h:529
virtual void DrawAndAdd(const Char_t *type="ID", const Char_t *classname="KVIDentifier")
const Char_t * GetName() const
const KVList * GetInfos() const
Definition KVIDGraph.h:318
void AddIDTelescopes(const TList *)
Associate this graph with all ID telescopes in list.
static KVIDGraph * MakeIDGraph(const Char_t *)
const KVList * GetCuts() const
Definition KVIDGraph.h:308
virtual void Clear(Option_t *opt="")
virtual void SetOnlyZId(Bool_t yes=kTRUE)
void ClearListOfTelescopes()
Definition KVIDGraph.h:112
const Char_t * GetRunList() const
Definition KVIDGraph.h:266
Identification grid editor GUI ,.
void SetGrid(KVIDGraph *gg, Bool_t histo=true)
void StartViewer()
Close();.
Graphical interface tool for managing, creating, testing and fitting identification grids.
void TabSelect(Int_t)
called when a new tab is selected
Int_t GetNSelected()
returns current number of selected items in grid list
void SaveGridsAs(const TCollection *=0)
KVListView * fCUTInfoList
list of lines in currently selected grid
void DeleteSelectedGrids()
warning message and confirmation
void HandleGridsMenu(Int_t id)
Receive signals emitted by items selected in Grids menu.
void DeleteAllGridsInTab()
delete the all grids in currently selected tab
void SetIDTelescopes()
Set ID telescopes for selected grid.
void ActivateToolbarButtons()
disable all buttons
KVIDGraph * fLastSelectedGrid
virtual ~KVIDGridManagerGUI()
close window
void DeleteGrids()
delete the current selected grid, or all currently selected grids if there are more than one
KVListView * fIDGridList
list of grids in current tab
TGTab * fGridListTabs
tabs with lists of grids
KVListView * fIDLineList
list of lines in currently selected grid
const Char_t * name_of_data_histo
TCollection * GetAllGridsInTab()
void CloseWindow()
close viewer
void ClearGrid()
deletes all lines in currently selected grid(s)
void SetStatus(const Char_t *text="")
TGButton * fTBbuttons[50]
void RemoveEmptyTabs()
Recursively remove any empty tabs.
KVIDGridEditor * fIDGridEditor
ID grid editor.
KVListView * fCUTList
list of lines in currently selected grid
std::unique_ptr< TList > fSelectedEntries
void GetListOfIDTelescopeLabels(KVString &)
KVList * GetGrids()
void DeleteGrid(KVIDGraph *, Bool_t update=kTRUE)
void Clear(Option_t *opt="")
Delete all grids and empty list, ready to start anew.
Int_t WriteAsciiFile(const Char_t *filename, const TCollection *selection=0)
Bool_t ReadAsciiFile(const Char_t *filename)
KVList * GetGridsForIDTelescope(const Char_t *label)
Base class for all detectors or associations of detectors in array which can identify charged particl...
Full result of one attempted particle identification.
General purpose dialog box asking for some input in the form of a string.
virtual void SetIsBoolean(Bool_t isit=kTRUE)
Enhanced version of ROOT TGListView widget.
Definition KVListView.h:146
virtual void ActivateSortButtons()
virtual void SetDataColumns(Int_t ncolumns)
virtual void Sort(Int_t column)
Definition KVListView.h:177
void SetDoubleClickAction(const char *receiver_class, void *receiver, const char *slot)
virtual void Display(const TCollection *l)
Definition KVListView.h:173
virtual void RemoveAll()
Definition KVListView.h:190
TObject * GetLastSelectedObject() const
Definition KVListView.h:231
TList * GetSelectedObjects() const
Definition KVListView.h:245
virtual void SetDataColumn(Int_t index, const Char_t *name, const Char_t *method="", Int_t mode=kTextCenterX)
virtual KVLVColumnData * GetDataColumn(Int_t index) const
Definition KVListView.h:168
Extended TList class which owns its objects by default.
Definition KVList.h:28
void Sort(Bool_t order=kSortAscending)
Definition KVList.h:35
Bool_t ReadGridsFromAsciiFile(const Char_t *) const
Nuclei reconstructed from data measured by a detector array .
void SetIdentification(KVIdentificationResult *, KVIDTelescope *)
virtual Float_t GetPID() const
virtual Int_t GetSize() const
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition KVString.h:73
void Begin(TString delim) const
Definition KVString.cpp:565
Bool_t End() const
Definition KVString.cpp:634
KVString Next(Bool_t strip_whitespace=kFALSE) const
Definition KVString.cpp:695
GUI for testing identification grids.
ABC for fitting ID grids with functionals.
static KVVirtualIDFitter * GetDefaultFitter()
void SetPad(TVirtualPad *p)
void SetGrid(KVIDGraph *g)
static TClass * Class()
TMethod * GetMethodAny(const char *method)
virtual void AddAll(const TCollection *col)
virtual Int_t GetEntries() const
virtual Int_t GetSize() const
const char * GetVarX() const
const char * GetVarY() const
T * Get(const char *namecycle)
virtual Bool_t cd()
virtual const char * GetValue(const char *name, const char *dflt) const
virtual void SetValue(const char *name, const char *value, EEnvLevel level=kEnvChange, const char *type=nullptr)
virtual void SetDown(Bool_t on=kTRUE, Bool_t emit=kFALSE)
virtual void SetEnabled(Bool_t e=kTRUE)
const TGWindow * GetDefaultRoot() const
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
virtual TList * GetList() const
void MapSubwindows() override
void Layout() override
void ChangeOptions(UInt_t options) override
char * fFilename
const char ** fFileTypes
char * fIniDir
TGFrame * fFrame
virtual void DeleteWindow()
void UnmapWindow() override
virtual void SelectionChanged()
TGClient * fClient
virtual void AddEntry(const char *s, Int_t id, void *ud=nullptr, const TGPicture *p=nullptr, TGMenuEntry *before=nullptr)
const char * GetString() const
const char * GetString() const
const TGString * GetText() const
virtual TGCompositeFrame * AddTab(const char *text)
TGCompositeFrame * GetCurrentContainer() const
TGTabElement * GetTabTab(const char *name) const
TGCompositeFrame * GetTabContainer(const char *name) const
Int_t GetNumberOfTabs() const
Int_t GetCurrent() const
virtual void RemoveTab(Int_t tabIndex=-1, Bool_t storeRemoved=kTRUE)
virtual Bool_t SetTab(const char *name, Bool_t emit=kTRUE)
void Reset(Option_t *option="") override
void SetBinContent(Int_t bin, Double_t content) override
TObject * At(Int_t idx) const override
const char * GetName() const override
TClass * IsA() const override
virtual const char * ClassName() const
virtual Bool_t InheritsFrom(const char *classname) const
virtual void Info(const char *method, const char *msgfmt,...) const
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
virtual Double_t Uniform(Double_t x1, Double_t x2)
const char * Data() const
TString & Prepend(char c, Ssiz_t rep=1)
void Form(const char *fmt,...)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
TString & ReplaceAll(const char *s1, const char *s2)
Bool_t cd(const char *path)
virtual const char * BaseName(const char *pathname)
virtual char * ExpandPathName(const char *path)
virtual Int_t Fill()
virtual Int_t Branch(const char *folder, Int_t bufsize=32000, Int_t splitlevel=99)
virtual void StartViewer()
Double_t y[n]
Double_t x[n]
TGraphErrors * gr
Double_t Min(Double_t a, Double_t b)
const char * fTipText
TGButton * fButton
Bool_t fStayDown
const char * fPixmap
TLine lv
TMarker m
ClassImp(TPyArg)