KaliVeda
Toolkit for HIC analysis
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 
26 using namespace std;
27 
29 
30 
31 
33 KVIDGridManagerGUI::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
103  TGHorizontal3DLine* lh = new TGHorizontal3DLine(this);
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
277  MapSubwindows();
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 
292 KVIDGridManagerGUI::~KVIDGridManagerGUI()
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 {
316  if (!fIDGridEditor) fIDGridEditor = new KVIDGridEditor;
317  if (fIDGridEditor->IsClosed()) fIDGridEditor->StartViewer();
318  if (fSelectedGrid) {
319  // avant d'editer la grille, on en fait une copie pour
320  // pouvoir revenir en arriere
321  fSelectedGrid->UpdateLastSavedVersion();
322  fIDGridEditor->SetGrid(fSelectedGrid);
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 (dir == "$(HISTOROOT)" && gSystem->Getenv("HISTOROOT")) {
347  if (gSystem->ExpandPathName(dir)) dir = ".";
348  }
349  else
350  dir = ".";
351 
352  const char* filetypes[] = {"Root files", "*.root", "All files", "*", 0, 0};
353  TGFileInfo fi;
354  fi.fFileTypes = filetypes;
355  fi.fIniDir = StrDup(dir);
356  new TGFileDialog(fClient->GetDefaultRoot(), this, kFDOpen, &fi);
357  if (fi.fFilename) {
358  if (!(TFile::Open(fi.fFilename))) {
359  new TGMsgBox(gClient->GetDefaultRoot(), gClient->GetDefaultRoot(), "ID Grid Editor", Form("Could not open file %s", fi.fFilename), 0, kMBOk);
360  }
361  }
362  dir = fi.fIniDir;
363  gSystem->cd(currentdir.Data());
364 }
365 
366 
367 
370 
372 {
373  //Receive signals emitted by items selected in Grids menu
374  switch (id) {
375 
376  case M_QUIT:
377 
378  Quit();
379  break;
380 
381  case M_GRIDS_NEW:
382 
383  cout << "Add new grid" << endl;
384  NewGrid();
385  break;
386  case M_GRIDS_READ:
387  OpenFile();
388  break;
389 
390  case M_GRIDS_SAVE_SEL:
391  // save current selection of grids in file
392  SaveGridsAs(fSelectedEntries.get());
393  break;
394 
395  case M_GRIDS_SAVE_TAB:
396  // save all grids in current tab in file
397  SaveGridsAs(GetAllGridsInTab());
398  break;
399 
400  case M_GRIDS_SAVE_ALL:
401 
402  //save all grids in file - ask user to confirm or change filename/path
403  SaveGridsAs();
404  break;
405 
406  case M_GRIDS_DEL_SEL:
407  DeleteSelectedGrids();
408  break;
409 
410  case M_GRIDS_DEL_TAB:
411  //warning message and confirmation
412  {
413  Int_t ret_val;
414  new TGMsgBox(fClient->GetDefaultRoot(), this, "ID Grid Manager",
415  "This will delete all grids in the current tab. Are you sure ?",
416  kMBIconExclamation, kMBOk | kMBCancel, &ret_val);
417  if (ret_val & kMBOk) {
418  DeleteAllGridsInTab();
419  }
420  }
421  break;
422  case M_GRIDS_DEL_ALL:
423 
424  //warning message and confirmation
425  {
426  Int_t ret_val;
427  new TGMsgBox(fClient->GetDefaultRoot(), this, "ID Grid Manager",
428  "This will delete all grids. Are you sure ?",
429  kMBIconExclamation, kMBOk | kMBCancel, &ret_val);
430  if (ret_val & kMBOk) {
431  gIDGridManager->Clear();
432  //UpdateListOfGrids();
434  //with an empty file !!
435  fFileName = "";
436  }
437  }
438  break;
439 
440  case M_GRIDS_SET_RUNLIST:
441  // set runlist for all selected grids
442  {
443  if (!fSelectedGrid) break; // must have selected at least one grid
444  TString runs = fSelectedGrid->GetRunList(); // fill dialog box with current runlist of selected grid
445  Bool_t ok_pressed = kFALSE;
446  new KVInputDialog(this, "Enter list of runs for grid(s):", &runs, &ok_pressed,
447  "Example: 1-10, 13, 22-657");
448  if (!ok_pressed) break; // user pressed 'cancel' or otherwise closed the dialog
449  TIter next(fSelectedEntries.get());
450  KVIDGraph* entry;
451  while ((entry = (KVIDGraph*) next())) {
452  entry->SetRunList(runs.Data());
453  }
454  }
455  break;
456  case M_GRIDS_SET_VARX:
457  // set varx for all selected grids
458  {
459  if (!fSelectedGrid) break; // must have selected at least one grid
460  TString runs = fSelectedGrid->GetVarX(); // fill dialog box with current runlist of selected grid
461  Bool_t ok_pressed = kFALSE;
462  new KVInputDialog(this, "Enter X variable for grid(s):", &runs, &ok_pressed,
463  "");
464  if (!ok_pressed) break; // user pressed 'cancel' or otherwise closed the dialog
465  TIter next(fSelectedEntries.get());
466  KVIDGraph* entry;
467  while ((entry = (KVIDGraph*) next())) {
468  entry->SetVarX(runs.Data());
469  }
470  }
471  break;
472  case M_GRIDS_SET_VARY:
473  // set varx for all selected grids
474  {
475  if (!fSelectedGrid) break; // must have selected at least one grid
476  TString runs = fSelectedGrid->GetVarY(); // fill dialog box with current runlist of selected grid
477  Bool_t ok_pressed = kFALSE;
478  new KVInputDialog(this, "Enter Y variable for grid(s):", &runs, &ok_pressed,
479  "");
480  if (!ok_pressed) break; // user pressed 'cancel' or otherwise closed the dialog
481  TIter next(fSelectedEntries.get());
482  KVIDGraph* entry;
483  while ((entry = (KVIDGraph*) next())) {
484  entry->SetVarY(runs.Data());
485  }
486  }
487  break;
488  case M_GRIDS_SET_ZID:
489  // set varx for all selected grids
490  {
491  if (!fSelectedGrid) break; // must have selected at least one grid
492  Bool_t runs = !fSelectedGrid->HasMassIDCapability(); // fill dialog box with current runlist of selected grid
493  TIter next(fSelectedEntries.get());
494  KVIDGraph* entry;
495  while ((entry = (KVIDGraph*) next())) {
496  entry->SetOnlyZId(!runs);
497  }
498  }
499  break;
500  case M_GRIDS_CLEAR:
501  // set varx for all selected grids
502  {
503  if (!fSelectedGrid) break; // must have selected at least one grid
504  TIter next(fSelectedEntries.get());
505  KVIDGraph* entry;
506  while ((entry = (KVIDGraph*) next())) {
507  entry->Clear();
508  }
509  }
510  break;
511 
512  default:
513 
514  break;
515  }
516 }
517 
518 
519 
522 
524 {
525  //warning message and confirmation
526  Int_t ret_val;
527  new TGMsgBox(fClient->GetDefaultRoot(), this, "ID Grid Manager",
528  "This will delete the selected grids. Are you sure ?",
529  kMBIconExclamation, kMBOk | kMBCancel, &ret_val);
530  if (ret_val & kMBOk) {
531  DeleteGrids();
532  }
533 }
534 
535 
536 
538 
540 {
541  static TString dir(".");
542  const char* filetypes[] = {
543  "ID Grid files", "*.dat",
544  "All files", "*",
545  0, 0
546  };
547  TGFileInfo fi;
548  fi.fFileTypes = filetypes;
549  fi.fIniDir = StrDup(dir);
550  //printf("fIniDir = %s\n", fi.fIniDir);
551  new TGFileDialog(fClient->GetDefaultRoot(), this, kFDOpen, &fi);
552  if (fi.fFilename) {
553  int ngri = gIDGridManager->GetGrids()->GetEntries();
554  bool ok = gMultiDetArray ? gMultiDetArray->ReadGridsFromAsciiFile(fi.fFilename)
555  : gIDGridManager->ReadAsciiFile(fi.fFilename);
556  if (ok) {
557  UpdateListOfGrids();
558  //read file ok no problem.
559  int ngriread = gIDGridManager->GetGrids()->GetEntries() - ngri;
560  SetStatus(Form("Read %d grids from file %s", ngriread, fi.fFilename));
561  //set filename for Save
562  fFileName = gSystem->BaseName(fi.fFilename);
563  }
564  else {
565  new TGMsgBox(fClient->GetDefaultRoot(), this, "ID Grid Manager",
566  Form("Could not read file %s", fi.fFilename),
567  0, kMBOk);
568  }
569  }
570  dir = fi.fIniDir;
571 }
572 
573 
574 
580 
582 {
583  //remove all existing entries, then fill list from gIDGridManager
584  //we update the current pad, in case the displayed grid no longer exists
585  //grid buttons are disabled, as any selected grid is deselected
586  // cout << "DEBUG: KVIDGridManagerGUI::UpdateListOfGrids(): starting..." << endl;
587  UpdateTabs();
588  // cout << "DEBUG: KVIDGridManagerGUI::UpdateListOfGrids(): tabs has been updated !" << endl;
589  //update all canvases
590 // TSeqCollection* Clist = gROOT->GetListOfCanvases();
591 // if (Clist && Clist->GetEntries()) {
592 // Clist->R__FOR_EACH(TCanvas, Modified)();
593 // Clist->R__FOR_EACH(TCanvas, Update)();
594 // }
595  // cout << "DEBUG: KVIDGridManagerGUI::UpdateListOfGrids(): canvas has been updated !" << endl;
596 }
597 
598 
599 
607 
609 {
610  //called any time the selection of grids changes
611  //each time, we update:
612  //fSelectedEntries : the list of all selected entries
613  //GetNSelected() : the number of selected entries
614  //fSelectedGrid : the last selected grid (=the only grid selected if GeTNSelected==1)
615 
616  //get number of selected items
617  fSelectedEntries.reset(fIDGridList->GetSelectedObjects());
618  fSelectedGrid = (KVIDGraph*)fIDGridList->GetLastSelectedObject();
619  if (!GetNSelected())fSelectedGrid = 0x0;
620  ShowListOfLines();
621  //(de)activate toolbar buttons
622  ActivateToolbarButtons();
623  if (!GetNSelected()) SetStatus();
624  else if (GetNSelected() == 1) SetStatus(Form("Selected grid %s (%s)", fSelectedGrid->GetName(), fSelectedGrid->ClassName()));
625  else SetStatus(Form("Selected %d grids, last selected grid %s (%s)", GetNSelected(), fSelectedGrid->GetName(), fSelectedGrid->ClassName()));
626 }
627 
628 
629 
632 
634 {
635  //returns current number of selected items in grid list
636  return (fSelectedEntries ? fSelectedEntries->GetSize() : 0);
637 }
638 
639 
640 
643 
645 {
646  //delete the current selected grid, or all currently selected grids if there are more than one
647 
648  if (!GetNSelected()) return;
649 
650  TIter next(fSelectedEntries.get(), kIterBackward);
651  KVIDGraph* entry;
652  while ((entry = (KVIDGraph*) next())) {
653  // cout << "DEBUG: KVIDGridManagerGUI::DeleteGrids(): deleting grid '" << entry->GetName() << "' !" << endl;
654  if (fLastSelectedGrid == entry) fLastSelectedGrid = 0;
655  gIDGridManager->DeleteGrid(entry, kFALSE); //no update
656  // cout << "DEBUG: KVIDGridManagerGUI::DeleteGrids(): grid has been deleted !" << endl;
657  }
658 
659  // cout << "DEBUG: KVIDGridManagerGUI::DeleteGrids(): list of selected grids has been deleted !" << endl;
660  fSelectedEntries.reset(nullptr);
661  fSelectedGrid = 0;
662  UpdateListOfGrids();
663  // cout << "DEBUG: KVIDGridManagerGUI::DeleteGrids(): list of grids has been updated !" << endl;
664 }
665 
666 
667 
670 
672 {
673  //delete the all grids in currently selected tab
674 
675  TIter next(GetAllGridsInTab(), kIterBackward);
676  KVIDGraph* entry;
677  while ((entry = (KVIDGraph*) next())) {
678  gIDGridManager->DeleteGrid(entry, kFALSE); //no update
679  }
680  fSelectedEntries.reset(nullptr);
681  fSelectedGrid = 0;
682  UpdateListOfGrids();
683 }
684 
685 
686 
689 
691 {
692  // Set ID telescopes for selected grid
693  Bool_t cancel;
694  TList telescopes;
695  telescopes.AddAll(fSelectedGrid->GetIDTelescopes());
696  new KVIDGUITelescopeChooserDialog(gMultiDetArray, &telescopes, &cancel,
697  fClient->GetDefaultRoot(), this, kTRUE);
698  if (cancel || !telescopes.GetEntries()) return;
699  fSelectedGrid->ClearListOfTelescopes();
700  fSelectedGrid->AddIDTelescopes(&telescopes);
701 }
702 
703 
704 
707 
709 {
710  //deletes all lines in currently selected grid(s)
711 
712  if (GetNSelected() == 1)
713  fSelectedGrid->Clear();
714  else if (GetNSelected() > 1) {
715  //multiselection
716  TIter next(fSelectedEntries.get());
717  KVIDGraph* grid;
718  while ((grid = (KVIDGraph*) next())) {
719  grid->Clear();
720  }
721  }
722  //update all canvases
723  TSeqCollection* Clist = gROOT->GetListOfCanvases();
724  if (Clist->GetSize() > 0) {
725  Clist->R__FOR_EACH(TCanvas, Modified)();
726  Clist->R__FOR_EACH(TCanvas, Update)();
727  }
728 }
729 
730 
731 
733 
735 {
736  if (!fSelectedGrid) return;
737  gIDGridManager->Disconnect("Modified()", this, "UpdateListOfGrids()");
738  KVIDGraph* new_gr = KVIDGraph::MakeIDGraph(fSelectedGrid->ClassName());
739  fSelectedGrid->Copy(*new_gr);
740  new_gr->AddIDTelescopes(fSelectedGrid->GetIDTelescopes());
741  new_gr->SetRunList("");
742  gIDGridManager->GetGrids()->Sort();
743  UpdateTabs();
744  gIDGridManager->Connect("Modified()", "KVIDGridManagerGUI", this, "UpdateListOfGrids()");
745  fIDGridList->Sort(0);
746  fIDGridList->Sort(0);
747  return;
748 }
749 
750 
751 
758 
760 {
761  // Create a new identification grid.
762  // First we ask the user to select the identification telescope(s)
763  // for which this grid will be used.
764  // For a given type of ID telescope, several types of grid may be
765  // applicable. If so, we ask the user to choose one.
766 
767  Info("NewGrid", "There are %d grids in the manager", gIDGridManager->GetGrids()->GetSize());
768  TString default_class = "KVIDZAGrid";
769  TList* telescopes = new TList;
770  if (gMultiDetArray) {
771  Bool_t cancel;
772  new KVIDGUITelescopeChooserDialog(gMultiDetArray, telescopes, &cancel,
773  fClient->GetDefaultRoot(), this);
774  if (cancel || !telescopes->At(0)) {
775  Info("NewGrid", "No ID telescopes chosen. Grid creation cancelled.");
776  return;
777  }
778  // get default ID grid class of first ID telescope
779  default_class = ((KVIDTelescope*)telescopes->At(0))->GetDefaultIDGridClass();
780  }
781  // get list of possible choices of grid class = list of all plugin classes
782  // defined for KVIDGraph
783  TString choice = KVBase::GetListOfPlugins("KVIDGraph");
784  // open dialog to choose ID grid class
785  Bool_t ok_pressed = kFALSE;
786  TString id_grid_class;
787  new KVDropDownDialog(this, "Choose class for new grid:",
788  choice.Data(), default_class.Data(), &id_grid_class, &ok_pressed);
789  if (!ok_pressed) {
790  Info("NewGrid", "No ID grid class chosen. Grid creation cancelled.");
791  return;
792  }
793  gIDGridManager->Disconnect("Modified()", this, "UpdateListOfGrids()");
794  KVIDGraph* new_gr = KVIDGraph::MakeIDGraph(id_grid_class.Data());
795  if (telescopes->GetEntries()) new_gr->AddIDTelescopes(telescopes);
796  UpdateTabs();
797  gIDGridManager->Connect("Modified()", "KVIDGridManagerGUI", this, "UpdateListOfGrids()");
798  delete telescopes;
799 }
800 
801 
802 
808 
810 {
811  //merge 2 grids
812  //KVIDGraph *g1 = (KVIDGraph *) fSelectedEntries->At(1);
813  //KVIDGraph *g2 = (KVIDGraph *) fSelectedEntries->First();
814  //new KVMergeGridsDialog(g1, g2, fClient->GetDefaultRoot(), this, 10, 10);
815 }
816 
817 
818 
823 
825 {
826  // Opens dialog to choose filename in which to save grids.
827  // If selection=0 (default), all grids are saved
828  // If selection!=0 only grids in list are saved
829 
830  static TString dir(".");
831  const char* filetypes[] = {
832  "ID Grid files", "*.dat",
833  "All files", "*",
834  0, 0
835  };
836  TGFileInfo fi;
837  fi.fFileTypes = filetypes;
838  fi.fIniDir = StrDup(dir);
839  if (fFileName != "") fi.fFilename = StrDup(fFileName);
840  new TGFileDialog(fClient->GetDefaultRoot(), this, kFDSave, &fi);
841  if (fi.fFilename) {
842  //if no ".xxx" ending given, we add ".dat"
843  TString filenam(fi.fFilename);
844  if (!filenam.Contains('.'))
845  filenam += ".dat";
846  Int_t n_saved = gIDGridManager->WriteAsciiFile(filenam.Data(), selection);
847  if (n_saved) {
848  //wrote file no problem
849  SetStatus(Form("Saved %d grids in file %s", n_saved, filenam.Data()));
850  //set file name for Save
851  fFileName = gSystem->BaseName(filenam);
852  }
853  else {
854  new TGMsgBox(fClient->GetDefaultRoot(), this, "ID Grid Manager",
855  Form("Could not write file %s", filenam.Data()), 0,
856  kMBOk);
857  }
858  }
859  dir = fi.fIniDir;
860 }
861 
862 
863 
867 
869 {
870  // create a tab for each type of ID telescope
871  // put a list box for ID grid names on each tab
872 
873  KVString labels;
874  if (gIDGridManager->GetGrids()->GetSize()) gIDGridManager->GetListOfIDTelescopeLabels(labels);
875  if (labels == "") {
876  // no known idtelescopes referenced by grids (maybe we don't have a KVMultiDetArray?)
877  // make 1 tab "Grids" and put them all in
878  KVString lab = "Grids";
879  TGCompositeFrame* cf = fGridListTabs->AddTab(lab.Data());
881  fIDGridList = new KVListView(KVIDGraph::Class(), cf, 600, 400);
882  fIDGridList->SetDataColumns(11);
883  fIDGridList->SetDataColumn(0, "Name", "", kTextLeft);
884  fIDGridList->SetDataColumn(2, "VarX", "", kTextLeft);
885  fIDGridList->SetDataColumn(1, "VarY", "", kTextLeft);
886  fIDGridList->SetDataColumn(3, "ID Telescopes", "GetNamesOfIDTelescopes", kTextLeft);
887  fIDGridList->SetDataColumn(4, "RunList", "", kTextLeft);
888  fIDGridList->SetDataColumn(5, "Identify Z and A?", "HasMassIDCapability", kTextCenterX);
889  fIDGridList->GetDataColumn(5)->SetIsBoolean();
890  fIDGridList->SetDataColumn(6, "# Ident.", "GetNumberOfIdentifiers", kTextRight);
891  fIDGridList->SetDataColumn(7, "# Cuts", "GetNumberOfCuts", kTextRight);
892  fIDGridList->SetDataColumn(8, "# Infos", "GetNumberOfInfos", kTextRight);
893  fIDGridList->SetDataColumn(9, "X scaling", "GetXScaleFactor", kTextRight);
894  fIDGridList->SetDataColumn(10, "Y scaling", "GetYScaleFactor", kTextRight);
895  fIDGridList->ActivateSortButtons();
896  fIDGridList->Connect("SelectionChanged()", "KVIDGridManagerGUI", this,
897  "SelectionChanged()");
898  fIDGridList->SetDoubleClickAction("KVIDGridManagerGUI", this, "StartEditor(TObject*)");
899  cf->AddFrame(fIDGridList, new TGLayoutHints(kLHintsLeft | kLHintsTop |
901  10, 10, 10));
902  KVList* grids = gIDGridManager->GetGrids();
903  fIDGridList->Display(grids);
904  return;
905  }
906  //loop over labels
907  labels.Begin(",");
908  while (! labels.End()) {
909  KVString lab = labels.Next();
910  TGCompositeFrame* cf = fGridListTabs->AddTab(lab.Data());
912  fIDGridList = new KVListView(KVIDGraph::Class(), cf, 600, 400);
913  fIDGridList->SetDataColumns(10);
914  fIDGridList->SetDataColumn(0, "Name", "", kTextLeft);
915  fIDGridList->SetDataColumn(2, "VarX", "", kTextLeft);
916  fIDGridList->SetDataColumn(1, "VarY", "", kTextLeft);
917  fIDGridList->SetDataColumn(3, "ID Telescopes", "GetNamesOfIDTelescopes", kTextLeft);
918  fIDGridList->SetDataColumn(4, "RunList", "", kTextLeft);
919  fIDGridList->SetDataColumn(5, "Identify Z and A?", "HasMassIDCapability", kTextCenterX);
920  fIDGridList->GetDataColumn(5)->SetIsBoolean();
921  fIDGridList->SetDataColumn(6, "# Ident.", "GetNumberOfIdentifiers", kTextRight);
922  fIDGridList->SetDataColumn(7, "# Cuts", "GetNumberOfCuts", kTextRight);
923  fIDGridList->SetDataColumn(8, "X scaling", "GetXScaleFactor", kTextRight);
924  fIDGridList->SetDataColumn(9, "Y scaling", "GetYScaleFactor", kTextRight);
925  fIDGridList->ActivateSortButtons();
926  fIDGridList->Connect("SelectionChanged()", "KVIDGridManagerGUI", this,
927  "SelectionChanged()");
928  fIDGridList->SetDoubleClickAction("KVIDGridManagerGUI", this, "StartEditor(TObject*)");
929  cf->AddFrame(fIDGridList, new TGLayoutHints(kLHintsLeft | kLHintsTop |
931  10, 10, 10));
932  KVList* grids = gIDGridManager->GetGridsForIDTelescope(lab);
933  fIDGridList->Display(grids);
934  delete grids;
935  }
936 
937 }
938 
939 
940 
943 
945 {
946  //called when a new tab is selected
947 
948  TGCompositeFrame* cf = fGridListTabs->GetCurrentContainer();
949  if (!cf) return;//there are no tabs
950  TGFrameElement* el = (TGFrameElement*)cf->GetList()->At(0);
951  fIDGridList = (KVListView*)el->fFrame;
952  fIDGridList->SelectionChanged();
953 }
954 
955 
956 
961 
963 {
964  // create a tab for each type of ID telescope
965  // put a list box for ID grid names on each tab
966  // cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : starting..." << endl;
967 
968  KVString labels("");
969  if (gIDGridManager->GetGrids()->GetSize()) gIDGridManager->GetListOfIDTelescopeLabels(labels);
970  else {
971  // there are no grids in the grid manager
972  RemoveEmptyTabs();
973  KVString lab = "Grids";
974  TGCompositeFrame* cf = fGridListTabs->AddTab(lab.Data());
976  fIDGridList = new KVListView(KVIDGraph::Class(), cf, 600, 400);
977  fIDGridList->SetDataColumns(10);
978  fIDGridList->SetDataColumn(0, "Name", "", kTextLeft);
979  fIDGridList->SetDataColumn(2, "VarX", "", kTextLeft);
980  fIDGridList->SetDataColumn(1, "VarY", "", kTextLeft);
981  fIDGridList->SetDataColumn(3, "ID Telescopes", "GetNamesOfIDTelescopes", kTextLeft);
982  fIDGridList->SetDataColumn(4, "RunList", "", kTextLeft);
983  fIDGridList->SetDataColumn(5, "Identify Z and A?", "HasMassIDCapability", kTextCenterX);
984  fIDGridList->GetDataColumn(5)->SetIsBoolean();
985  fIDGridList->SetDataColumn(6, "# Ident.", "GetNumberOfIdentifiers", kTextRight);
986  fIDGridList->SetDataColumn(7, "# Cuts", "GetNumberOfCuts", kTextRight);
987  fIDGridList->SetDataColumn(8, "X scaling", "GetXScaleFactor", kTextRight);
988  fIDGridList->SetDataColumn(9, "Y scaling", "GetYScaleFactor", kTextRight);
989  fIDGridList->ActivateSortButtons();
990  fIDGridList->Connect("SelectionChanged()", "KVIDGridManagerGUI", this,
991  "SelectionChanged()");
992  cf->AddFrame(fIDGridList, new TGLayoutHints(kLHintsLeft | kLHintsTop |
994  10, 10, 10));
995  fGridListTabs->MapSubwindows();
996  fGridListTabs->Layout();
997  Int_t ntabs = fGridListTabs->GetCurrent();
998  TabSelect(ntabs);
999  return;
1000  }
1001  if (labels == "") {
1002  // no known idtelescopes referenced by grids (maybe we don't have a KVMultiDetArray?)
1003  // update "Grids" tab
1004  TGCompositeFrame* cf = fGridListTabs->GetTabContainer("Grids");
1005  if (!cf) {
1006  cout << "cf = 0x0 : label=Grids tab name=" <<
1007  fGridListTabs->GetTabTab("Grids")->GetText()->GetString() << endl;
1008  }
1009  else {
1010  TGFrameElement* el = (TGFrameElement*)cf->GetList()->At(0);
1011  fIDGridList = (KVListView*)el->fFrame;
1012  KVList* grids = gIDGridManager->GetGrids();
1013  fIDGridList->Display(grids);
1014  }
1015  //make sure we are on the right tab
1016  Int_t ntabs = fGridListTabs->GetCurrent();
1017  TabSelect(ntabs);
1018  return;
1019  }
1020  //add any missing labels, update existing ones
1021  labels.Begin(",");
1022  while (! labels.End()) {
1023  KVString lab = labels.Next();
1024  // cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : updating tab '" << lab.Data() << "'..." << endl;
1025  if (!fGridListTabs->GetTabContainer(lab.Data())) { // new tab
1026  // cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : new tab '" << lab.Data() << "'..." << endl;
1027  TGCompositeFrame* cf = fGridListTabs->AddTab(lab.Data());
1029  fIDGridList = new KVListView(KVIDGraph::Class(), cf, 600, 400);
1030  fIDGridList->SetDataColumns(11);
1031  fIDGridList->SetDataColumn(0, "Name", "", kTextLeft);
1032  fIDGridList->SetDataColumn(2, "VarX", "", kTextLeft);
1033  fIDGridList->SetDataColumn(1, "VarY", "", kTextLeft);
1034  fIDGridList->SetDataColumn(3, "ID Telescopes", "GetNamesOfIDTelescopes", kTextLeft);
1035  fIDGridList->SetDataColumn(4, "RunList", "", kTextLeft);
1036  fIDGridList->SetDataColumn(5, "Identify Z and A?", "HasMassIDCapability", kTextCenterX);
1037  fIDGridList->GetDataColumn(5)->SetIsBoolean();
1038  fIDGridList->SetDataColumn(6, "# Ident.", "GetNumberOfIdentifiers", kTextRight);
1039  fIDGridList->SetDataColumn(7, "# Cuts", "GetNumberOfCuts", kTextRight);
1040  fIDGridList->SetDataColumn(8, "# Infos", "GetNumberOfInfos", kTextRight);
1041  fIDGridList->SetDataColumn(9, "X scaling", "GetXScaleFactor", kTextRight);
1042  fIDGridList->SetDataColumn(10, "Y scaling", "GetYScaleFactor", kTextRight);
1043  fIDGridList->ActivateSortButtons();
1044  fIDGridList->Connect("SelectionChanged()", "KVIDGridManagerGUI", this,
1045  "SelectionChanged()");
1046  cf->AddFrame(fIDGridList, new TGLayoutHints(kLHintsLeft | kLHintsTop |
1048  10, 10, 10));
1049  KVList* grids = gIDGridManager->GetGridsForIDTelescope(lab);
1050  fIDGridList->Display(grids);
1051  delete grids;
1052  fGridListTabs->MapSubwindows();
1053  fGridListTabs->Layout();
1054  fGridListTabs->SetTab(fGridListTabs->GetNumberOfTabs() - 1, kTRUE);
1055  }
1056  else { //existing tab
1057  //cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : existing tab '" << lab.Data() << "'..." << endl;
1058  TGCompositeFrame* cf = fGridListTabs->GetTabContainer(lab.Data());
1059  if (!cf) {
1060  cout << "cf = 0x0 : label=" << lab.Data() << " tab name=" <<
1061  fGridListTabs->GetTabTab(lab.Data())->GetText()->GetString() << endl;
1062  }
1063  else {
1064  //cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : recup tab '" << cf->GetName() << "'..." << endl;
1065  TGFrameElement* el = (TGFrameElement*)cf->GetList()->At(0);
1066  //cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : recup element '" << el->GetName() << "'..." << endl;
1067  fIDGridList = (KVListView*)el->fFrame;
1068  //cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : recup view list '" << fIDGridList->GetName() << "'..." << endl;
1069  KVList* grids = gIDGridManager->GetGridsForIDTelescope(lab);
1070  //cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : recup list de telescope'" << grids->GetName() << "'..." << endl;
1071  //grids->ls();
1072  fIDGridList->Display(grids);
1073  //cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : display list of grids in the viewerlist..." << endl;
1074 
1075  if (grids) delete grids;
1076  // cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : deleting the list..." << endl;
1077  }
1078  }
1079  }
1080  //now check that none of the remaining tabs are empty & should be removed
1081  RemoveEmptyTabs();
1082  // cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : empty tabs removed !" << endl;
1083  //make sure we are on the right tab
1084  Int_t ntabs = fGridListTabs->GetCurrent();
1085  TabSelect(ntabs);
1086  // cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : current tab selected !" << endl;
1087 }
1088 
1089 
1090 
1093 
1095 {
1096  // Recursively remove any empty tabs
1097 
1098  Int_t ntabs = fGridListTabs->GetNumberOfTabs();
1099  Bool_t recursive = kFALSE;
1100  for (Int_t itab = 0; itab < ntabs; itab++) {
1101 
1102  //get name of tab
1103  KVString lab = fGridListTabs->GetTabTab(itab)->GetString();
1104  //get grids for this tab (if any)
1105  KVList* grids = gIDGridManager->GetGridsForIDTelescope(lab);
1106  Int_t ngrids = grids->GetEntries();
1107  delete grids;
1108  if (!ngrids) {
1109  //empty tab! remove it!
1110  //delete the KVListView
1111  TGCompositeFrame* cf = fGridListTabs->GetTabContainer(itab);
1112  TGFrameElement* el = (TGFrameElement*)cf->GetList()->At(0);
1113  KVListView* lv = (KVListView*)el->fFrame;
1114  delete lv;
1115  //remove tab
1116  fGridListTabs->RemoveTab(itab, kFALSE);
1117  recursive = kTRUE; // call recursively
1118  break;//stop loop - tab numbers have changed
1119  }
1120  }
1121  if (recursive) RemoveEmptyTabs();
1122  fGridListTabs->MapSubwindows();
1123  fGridListTabs->Layout();
1124 }
1125 
1126 
1127 
1131 
1133 {
1134  // called when a previously selected grid is modified
1135  // updates lists of lines
1136 
1137  if (!fLastSelectedGrid) return;
1138 
1139  KVList* ids = fLastSelectedGrid->GetIdentifiers();
1140  // sort lines in order of increasing Z
1141  ids->Sort();
1142  fIDLineList->Display(ids);
1143 // KVSeqCollection* cutlines = fSelectedGrid->GetCuts()->GetSubListWithClass("KVIDCutLine");
1144  fCUTList->Display(fSelectedGrid->GetCuts());
1145 // fCUTLineList->Display(cutlines);
1146 // delete cutlines;
1147 // cutlines = fSelectedGrid->GetCuts()->GetSubListWithClass("KVIDCutContour");
1148  fCUTInfoList->Display(fSelectedGrid->GetInfos());
1149 // fCUTContourList->Display(cutlines);
1150 // delete cutlines;
1151 }
1152 
1153 
1154 
1160 
1162 {
1163  // Called when a grid is selected in list of grids
1164  // We fill list of all lines in grid
1165  //If only one grid is selected, we display its lines in the line list
1166  //If more than one grid is selected, we clear the line list
1167 
1168  if (GetNSelected() == 1 && fSelectedGrid) {
1169  KVList* ids = fSelectedGrid->GetIdentifiers();
1170  // sort lines in order of increasing Z
1171  ids->Sort();
1172  fIDLineList->Display(ids);
1173 // KVSeqCollection* cutlines = fSelectedGrid->GetCuts()->GetSubListWithClass("KVIDCutLine");
1174  fCUTList->Display(fSelectedGrid->GetCuts());
1175 // delete cutlines;
1176 // cutlines = fSelectedGrid->GetCuts()->GetSubListWithClass("KVIDCutContour");
1177  fCUTInfoList->Display(fSelectedGrid->GetInfos());
1178 // delete cutlines;
1179  if (fLastSelectedGrid) {
1180  fLastSelectedGrid->Disconnect("Modified()", this, "UpdateListOfLines()");
1181  }
1182  fSelectedGrid->Connect("Modified()", "KVIDGridManagerGUI", this, "UpdateListOfLines()");
1183  fLastSelectedGrid = fSelectedGrid;
1184  }
1185  else {
1186  fIDLineList->RemoveAll();
1187  fCUTList->RemoveAll();
1188  fCUTInfoList->RemoveAll();
1189  if (fLastSelectedGrid) {
1190  fLastSelectedGrid->Disconnect("Modified()", this, "UpdateListOfLines()");
1191  fLastSelectedGrid = 0;
1192  }
1193  }
1194 }
1195 
1196 
1197 
1200 
1202 {
1203  // disable all buttons
1204  for (int i = 0; i < fNbButtons; i++) fTBbuttons[i]->SetEnabled(kFALSE);
1205  // enable 'open' & 'quit' & 'new grid"
1206  fTBOpen->SetEnabled();
1207  fTBRefresh->SetEnabled();
1208 // fTBStartEditor->SetEnabled();
1209  fTBNewG->SetEnabled();
1210  fTBOpenRoot->SetEnabled();
1211  // enable 'save' if there are grids
1212  if (gIDGridManager->GetGrids()->GetEntries()) fTBSave->SetEnabled();
1213 
1214  if (!GetNSelected()) return; // no grids selected
1215 
1216  //enable delete selected grid(s)
1217  fTBDelG->SetEnabled();
1218 
1219  if (GetNSelected() == 1) {
1220  // only one grid selected
1221  fTBStartEditor->SetEnabled();
1222  fTBCopyG->SetEnabled();
1223  if (gMultiDetArray) fTBSetIDG->SetEnabled();
1224  }
1225 }
1226 
1227 
1228 
1240 
1242 {
1243  // GUI method to draw a new identifier and add it to graph.
1244  // A dialog box with drop-down list pops up for the user to choose the class of the
1245  // new identifier, unless only one choice is possible, in which case it is used automatically.
1246  // For each KVIDGraph-derived class, the list of possible identifier classes and the
1247  // default class are define in .kvrootrc by the variables:
1248  //
1249  // [class_name].IDClass: [id class 1]
1250  // +[class_name].IDClass: [id class 2]
1251  // + ...
1252  // [class_name].DefaultIDClass: [id class]
1253 
1254  if (!fSelectedGrid || GetNSelected() != 1) return;
1255  TString resname;
1256  resname.Form("%s.IDClass", fSelectedGrid->ClassName());
1257  TString cut_choices = gEnv->GetValue(resname.Data(), "");
1258  resname.Form("%s.DefaultIDClass", fSelectedGrid->ClassName());
1259  TString cut_default = gEnv->GetValue(resname.Data(), "");
1260  TString cut_class;
1261  Bool_t okpressed;
1262  if (cut_choices.Contains(" ")) {
1263  new KVDropDownDialog(this,
1264  "Choose class of new identifier :",
1265  cut_choices.Data(),
1266  cut_default.Data(),
1267  &cut_class,
1268  &okpressed);
1269  if (!okpressed) return;
1270  }
1271  else
1272  cut_class = cut_choices;
1273  SetStatus(Form("Draw ID line (%s) in current pad", cut_class.Data()));
1274  fSelectedGrid->DrawAndAdd("ID", cut_class.Data());
1275  fTBNewIDL->SetDown(kFALSE, kFALSE);
1276  SetStatus();
1277 }
1278 
1279 
1280 
1292 
1294 {
1295  // GUI method to draw a new cut and add it to graph.
1296  // A dialog box with drop-down list pops up for the user to choose the class of the
1297  // new cut, unless only one choice is possible, in which case it is used automatically.
1298  // For each KVIDGraph-derived class, the list of possible cut classes and the
1299  // default class are define in .kvrootrc by the variables:
1300  //
1301  // [class_name].CutClass: [cut class 1]
1302  // +[class_name].CutClass: [cut class 2]
1303  // + ...
1304  // [class_name].DefaultCutClass: [cut class]
1305 
1306  if (!fSelectedGrid || GetNSelected() != 1) return;
1307  TString resname;
1308  resname.Form("%s.CutClass", fSelectedGrid->ClassName());
1309  TString cut_choices = gEnv->GetValue(resname.Data(), "");
1310  resname.Form("%s.DefaultCutClass", fSelectedGrid->ClassName());
1311  TString cut_default = gEnv->GetValue(resname.Data(), "");
1312  TString cut_class;
1313  TString cut_types = cut_choices;
1314  cut_types.ReplaceAll("KVIDCut", "");
1315  Bool_t okpressed;
1316  if (cut_choices.Contains(" ")) {
1317  new KVDropDownDialog(this,
1318  "Choose class of new cut :",
1319  cut_types.Data(),
1320  cut_default.Data(),
1321  &cut_class,
1322  &okpressed);
1323  if (!okpressed) return;
1324  }
1325  else
1326  cut_class = cut_types;
1327  SetStatus(Form("Draw cut %s in current pad", cut_class.Data()));
1328  cut_class.Prepend("KVIDCut");
1329  fSelectedGrid->DrawAndAdd("CUT", cut_class.Data());
1330  fTBNewCut->SetDown(kFALSE, kFALSE);
1331  SetStatus();
1332 }
1333 
1334 
1335 
1336 
1340 
1342 {
1343  // test the identification with selected grid
1344  // we search in current pad for the data histogram
1345 
1346  SetStatus("");
1347  if (GetNSelected() != 1) return;
1348  if (!fSelectedGrid) return;
1349  // look for data histogram in current pad
1350  TH2* histo = 0;
1351  if (gPad) {
1352  TIter next(gPad->GetListOfPrimitives());
1353  TObject* o;
1354  while ((o = next())) {
1355  if (o->InheritsFrom("TH2")) {
1356  histo = (TH2*)o;
1357  break;
1358  }
1359  }
1360  }
1361  if (!histo) {
1362  SetStatus("No TH2 found in current pad. Select pad containing 2D histo with data to identify.");
1363  return;
1364  }
1365  else {
1366  SetStatus(Form("Test identification of data in current pad %s.", histo->GetName()));
1367  }
1368  new KVTestIDGridDialog(fClient->GetDefaultRoot(), this, 10, 10, fSelectedGrid, histo);
1369  SetStatus("");
1370 }
1371 
1372 
1373 
1377 
1379 {
1380  // test the identification with selected grid
1381  // we search in current pad for the data histogram
1382  SetStatus("");
1383  if (GetNSelected() != 1) return;
1384  if (!fSelectedGrid) return;
1385  // look for data histogram in current pad
1386  TH2* histo = 0;
1387  if (gPad) {
1388  TIter next(gPad->GetListOfPrimitives());
1389  TObject* o;
1390  while ((o = next())) {
1391  if (o->InheritsFrom("TH2")) {
1392  histo = (TH2*)o;
1393  break;
1394  }
1395  }
1396  }
1397  if (!histo) {
1398  SetStatus("No TH2 found in current pad. Select pad containing 2D histo with data to identify.");
1399  return;
1400  }
1401  else {
1402  SetStatus(Form("Test identification of data in current pad %s.", histo->GetName()));
1403  }
1404  TFile* tmpfiles = TestIdentificationWithTree(fSelectedGrid, histo->GetName());
1405  if (!tmpfiles) {
1406  SetStatus("There was a problem with the test ???");
1407  return;
1408  }
1409  new TCanvas;
1410  TH2* id = (TH2*)tmpfiles->Get("idcode_map");
1411  id->SetStats(kFALSE);
1412  id->Draw("zcol");
1413  TTree* t = (TTree*)tmpfiles->Get("tree_idresults");
1414  t->StartViewer();
1415  SetStatus("");
1416 }
1417 
1418 
1419 
1420 
1433 
1434 TFile* KVIDGridManagerGUI::TestIdentificationWithTree(KVIDGraph* gr, const Char_t* name_of_data_histo)
1435 {
1436  //This method allows to test the identification capabilities of the grid using data in a TH2F.
1437  //We assume that 'data' contains an identification map, whose 'x' and 'y' coordinates correspond
1438  //to this grid. Then we loop over every bin of the histogram, perform the identification (if
1439  //IsIdentifiable() returns kTRUE) and fill the two histograms with the resulting identification
1440  //and its dependence on the 'residual energy' i.e. the 'x'-coordinate of the 'data' histogram,
1441  //each identification weighted by the contents of the original data bin.
1442  //
1443  //The 'identification" we represent is the result of the KVReconstructedNucleus::GetPID() method.
1444  //For particles identified in Z only, this is the "real Z".
1445  //For particles with A & Z identification, this is Z + 0.1*(A - 2*Z)
1446 
1447  //Initialize the grid: calculate line widths etc.
1448  gr->Initialize();
1449 
1450  TH2F* data = (TH2F*)gROOT->FindObject(name_of_data_histo);
1451  if (!data) {
1452  printf(" KVIDGraph::TestIdentificationWithTree l histo %s n existe pas\n", name_of_data_histo);
1453  return 0;
1454  }
1455 
1456 
1459 
1460  // store current memory directory
1461  TDirectory* CWD = gDirectory;
1462 
1463  TTree* tid = 0;
1464  if ((tid = (TTree*)gROOT->FindObject("tree_idresults"))) {
1465  printf(" KVIDGraph::TestIdentificationWithTree effacemenent de l arbre existant\n");
1466  delete tid;
1467  }
1468  // create temporary file for tree
1469  TString fn("IDtestTree.root");
1471  TFile* tmpfile = new TFile(fn.Data(), "recreate");
1472  TH2F* idmap = (TH2F*)data->Clone("idcode_map");
1473  idmap->Reset();
1474  tid = new TTree("tree_idresults", "pid");
1475  Float_t br_xxx, br_yyy, br_stat, br_pid;
1476  Int_t br_idcode, br_isid;
1477 
1478  tid->Branch("X", &br_xxx, "br_xxx/F");
1479  tid->Branch("Y", &br_yyy, "br_yyy/F");
1480  tid->Branch("Stat", &br_stat, "br_stat/F");
1481 
1482  tid->Branch("PID", &br_pid, "br_pid/F");
1483  tid->Branch("IDcode", &br_idcode, "br_idcode/I");
1484  tid->Branch("IsIdentified", &br_isid, "br_isid/I");
1485 
1486  Int_t tot_events = (Int_t) data->GetSum();
1487  Int_t events_read = 0;
1488  Float_t percent = 0., cumul = 10.;
1489 
1490  //loop over data in histo
1491  for (int i = 1; i <= data->GetNbinsX(); i++) {
1492  for (int j = 1; j <= data->GetNbinsY(); j++) {
1493 
1494  Stat_t poids = data->GetBinContent(i, j);
1495  if (poids == 0)
1496  continue;
1497  br_stat = Float_t(poids);
1498 
1499  Axis_t x0 = data->GetXaxis()->GetBinCenter(i);
1500  Axis_t y0 = data->GetYaxis()->GetBinCenter(j);
1501  Axis_t wx = data->GetXaxis()->GetBinWidth(i);
1502  Axis_t wy = data->GetYaxis()->GetBinWidth(j);
1503 
1504  br_xxx = Float_t(x0);
1505  br_yyy = Float_t(y0);
1506  //If bin content ('poids') is <=20, we perform the identification 'poids' times, each time with
1507  //randomly-drawn x and y coordinates inside this bin
1508  //If 'poids'>20, we perform the identification 20 times and we fill the histograms with
1509  //a weight poids/20
1510  Double_t x, y;
1511  Int_t kmax = (Int_t) TMath::Min(20., poids);
1512  //Double_t weight = (kmax == 20 ? poids / 20. : 1.);
1513 
1514  for (int k = 0; k < kmax; k++) {
1515 
1516  x = gRandom->Uniform(x0 - .5 * wx, x0 + .5 * wx);
1517  y = gRandom->Uniform(y0 - .5 * wy, y0 + .5 * wy);
1518  if (gr->IsIdentifiable(x, y)) {
1519  br_isid = 1;
1520  gr->Identify(x, y, idr);
1521  nuc.SetIdentification(idr, nullptr);
1522  br_pid = nuc.GetPID();
1523  br_idcode = gr->GetQualityCode();
1524  idmap->SetBinContent(i, j, br_idcode);
1525  }
1526  else {
1527  br_isid = 0;
1528  br_pid = -1;
1529  br_idcode = -1;
1530  idmap->SetBinContent(i, j, br_idcode);
1531  }
1532  tid->Fill();
1533  }
1534  events_read += (Int_t) poids;
1535  percent = (1. * events_read / tot_events) * 100.;
1536  gr->Increment((Float_t) events_read); //sends signal to GUI progress bar
1537  if (percent >= cumul) {
1538  cout << (Int_t) percent << "\% processed" << endl;
1539  cumul += 10;
1540  }
1541  //gSystem->ProcessEvents();
1542  }
1543  }
1544 
1545  delete idr;
1546  CWD->cd();
1547  return tmpfile;
1548 }
1549 
1550 
1551 
1553 
1555 {
1556  SetStatus("");
1557  if (GetNSelected() != 1) return;
1558  if (!fSelectedGrid) return;
1559  SetStatus(Form("Fitting grid %s", fSelectedGrid->GetName()));
1561  fitter->SetGrid(fSelectedGrid);
1562  fitter->SetPad(fSelectedGrid->GetPad());
1563  TMethod* m = fitter->IsA()->GetMethodAny("FitPanel");
1564  TContextMenu* cm = new TContextMenu("FitPanel", "Context menu for KVVirtualIDFitter::FitPanel");
1565  cm->Action(fitter, m);
1566  delete cm;
1567 }
1568 
1569 
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 UnmapWindow
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:1228
static void GetTempFileName(TString &base)
Definition: KVBase.cpp:827
static const Char_t * GetKVVersion()
Returns KaliVeda version string.
Definition: KVBase.cpp:853
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
void Clear(Option_t *opt="") override
Definition: KVIDGraph.cpp:203
void SetVarY(const char *v) override
Definition: KVIDGraph.h:529
void SetVarX(const char *v) override
Definition: KVIDGraph.h:525
void AddIDTelescopes(const TList *)
Associate this graph with all ID telescopes in list.
Definition: KVIDGraph.cpp:1516
static KVIDGraph * MakeIDGraph(const Char_t *)
Definition: KVIDGraph.cpp:1556
virtual void SetOnlyZId(Bool_t yes=kTRUE)
Definition: KVIDGraph.cpp:1496
Identification grid editor GUI ,.
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)
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
void DeleteGrids()
delete the current selected grid, or all currently selected grids if there are more than one
void ClearGrid()
deletes all lines in currently selected grid(s)
void CloseWindow() override
close viewer
void RemoveEmptyTabs()
Recursively remove any empty tabs.
void Clear(Option_t *opt="") override
Delete all grids and empty list, ready to start anew.
void GetListOfIDTelescopeLabels(KVString &)
KVList * GetGrids()
void DeleteGrid(KVIDGraph *, Bool_t update=kTRUE)
Int_t WriteAsciiFile(const Char_t *filename, const TCollection *selection=0)
KVList * GetGridsForIDTelescope(const Char_t *label)
Bool_t ReadAsciiFile(const Char_t *filename)
Base class for all detectors or associations of detectors in array which can identify charged particl...
Definition: KVIDTelescope.h:84
Full result of one attempted particle identification.
General purpose dialog box asking for some input in the form of a string.
Definition: KVInputDialog.h:24
Enhanced version of ROOT TGListView widget.
Definition: KVListView.h:146
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
Int_t GetSize() const override
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)
TMethod * GetMethodAny(const char *method)
virtual void AddAll(const TCollection *col)
virtual Int_t GetEntries() const
virtual Int_t GetSize() const
static TClass * Class()
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)
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
virtual TList * GetList() const
void ChangeOptions(UInt_t options) override
char * fFilename
const char ** fFileTypes
char * fIniDir
TGFrame * fFrame
virtual void AddEntry(const char *s, Int_t id, void *ud=nullptr, const TGPicture *p=nullptr, TGMenuEntry *before=nullptr)
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 Bool_t InheritsFrom(const char *classname) const
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 * Getenv(const char *env)
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
void Info(const char *location, const char *fmt,...)
TFile * OpenFile(const TString &fin)
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)