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);
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);
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);
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);
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);
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);
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 = 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 
630 
631 
634 
636 {
637  //delete the current selected grid, or all currently selected grids if there are more than one
638 
639  if (!GetNSelected()) return;
640 
641  TIter next(&fSelectedEntries, kIterBackward);
642  KVIDGraph* entry;
643  while ((entry = (KVIDGraph*) next())) {
644  // cout << "DEBUG: KVIDGridManagerGUI::DeleteGrids(): deleting grid '" << entry->GetName() << "' !" << endl;
645  if (fLastSelectedGrid == entry) fLastSelectedGrid = 0;
646  gIDGridManager->DeleteGrid(entry, kFALSE); //no update
647  // cout << "DEBUG: KVIDGridManagerGUI::DeleteGrids(): grid has been deleted !" << endl;
648  }
649 
650  // cout << "DEBUG: KVIDGridManagerGUI::DeleteGrids(): list of selected grids has been deleted !" << endl;
651  fSelectedEntries.Clear();
652  fSelectedGrid = 0;
653  UpdateListOfGrids();
654  // cout << "DEBUG: KVIDGridManagerGUI::DeleteGrids(): list of grids has been updated !" << endl;
655 }
656 
657 
658 
661 
663 {
664  //delete the all grids in currently selected tab
665 
666  TIter next(GetAllGridsInTab(), kIterBackward);
667  KVIDGraph* entry;
668  while ((entry = (KVIDGraph*) next())) {
669  gIDGridManager->DeleteGrid(entry, kFALSE); //no update
670  }
671  fSelectedEntries.Clear();
672  fSelectedGrid = 0;
673  UpdateListOfGrids();
674 }
675 
676 
677 
680 
682 {
683  // Set ID telescopes for selected grid
684  Bool_t cancel;
685  TList telescopes;
686  telescopes.AddAll(fSelectedGrid->GetIDTelescopes());
687  new KVIDGUITelescopeChooserDialog(gMultiDetArray, &telescopes, &cancel,
688  fClient->GetDefaultRoot(), this, kTRUE);
689  if (cancel || !telescopes.GetEntries()) return;
690  fSelectedGrid->ClearListOfTelescopes();
691  fSelectedGrid->AddIDTelescopes(&telescopes);
692 }
693 
694 
695 
698 
700 {
701  //deletes all lines in currently selected grid(s)
702 
703  if (GetNSelected() == 1)
704  fSelectedGrid->Clear();
705  else if (GetNSelected() > 1) {
706  //multiselection
707  TIter next(&fSelectedEntries);
708  KVIDGraph* grid;
709  while ((grid = (KVIDGraph*) next())) {
710  grid->Clear();
711  }
712  }
713  //update all canvases
714  TSeqCollection* Clist = gROOT->GetListOfCanvases();
715  if (Clist->GetSize() > 0) {
716  Clist->R__FOR_EACH(TCanvas, Modified)();
717  Clist->R__FOR_EACH(TCanvas, Update)();
718  }
719 }
720 
721 
722 
724 
726 {
727  if (!fSelectedGrid) return;
728  gIDGridManager->Disconnect("Modified()", this, "UpdateListOfGrids()");
729  KVIDGraph* new_gr = KVIDGraph::MakeIDGraph(fSelectedGrid->ClassName());
730  fSelectedGrid->Copy(*new_gr);
731  new_gr->AddIDTelescopes(fSelectedGrid->GetIDTelescopes());
732  new_gr->SetRunList("");
733  gIDGridManager->SortGrids();
734  UpdateTabs();
735  gIDGridManager->Connect("Modified()", "KVIDGridManagerGUI", this, "UpdateListOfGrids()");
736  fIDGridList->Sort(0);
737  fIDGridList->Sort(0);
738  return;
739 }
740 
741 
742 
749 
751 {
752  // Create a new identification grid.
753  // First we ask the user to select the identification telescope(s)
754  // for which this grid will be used.
755  // For a given type of ID telescope, several types of grid may be
756  // applicable. If so, we ask the user to choose one.
757 
758  Info("NewGrid", "There are %d grids in the manager", gIDGridManager->GetGrids()->GetSize());
759  TString default_class = "KVIDZAGrid";
760  TList* telescopes = new TList;
761  if (gMultiDetArray) {
762  Bool_t cancel;
763  new KVIDGUITelescopeChooserDialog(gMultiDetArray, telescopes, &cancel,
764  fClient->GetDefaultRoot(), this);
765  if (cancel || !telescopes->At(0)) {
766  Info("NewGrid", "No ID telescopes chosen. Grid creation cancelled.");
767  return;
768  }
769  // get default ID grid class of first ID telescope
770  default_class = ((KVIDTelescope*)telescopes->At(0))->GetDefaultIDGridClass();
771  }
772  // get list of possible choices of grid class = list of all plugin classes
773  // defined for KVIDGraph
774  TString choice = KVBase::GetListOfPlugins("KVIDGraph");
775  // open dialog to choose ID grid class
776  Bool_t ok_pressed = kFALSE;
777  TString id_grid_class;
778  new KVDropDownDialog(this, "Choose class for new grid:",
779  choice.Data(), default_class.Data(), &id_grid_class, &ok_pressed);
780  if (!ok_pressed) {
781  Info("NewGrid", "No ID grid class chosen. Grid creation cancelled.");
782  return;
783  }
784  gIDGridManager->Disconnect("Modified()", this, "UpdateListOfGrids()");
785  KVIDGraph* new_gr = KVIDGraph::MakeIDGraph(id_grid_class.Data());
786  if (telescopes->GetEntries()) new_gr->AddIDTelescopes(telescopes);
787  UpdateTabs();
788  gIDGridManager->Connect("Modified()", "KVIDGridManagerGUI", this, "UpdateListOfGrids()");
789  delete telescopes;
790 }
791 
792 
793 
799 
801 {
802  //merge 2 grids
803  //KVIDGraph *g1 = (KVIDGraph *) fSelectedEntries->At(1);
804  //KVIDGraph *g2 = (KVIDGraph *) fSelectedEntries->First();
805  //new KVMergeGridsDialog(g1, g2, fClient->GetDefaultRoot(), this, 10, 10);
806 }
807 
808 
809 
814 
816 {
817  // Opens dialog to choose filename in which to save grids.
818  // If selection=0 (default), all grids are saved
819  // If selection!=0 only grids in list are saved
820 
821  static TString dir(".");
822  const char* filetypes[] = {
823  "ID Grid files", "*.dat",
824  "All files", "*",
825  0, 0
826  };
827  TGFileInfo fi;
828  fi.fFileTypes = filetypes;
829  fi.fIniDir = StrDup(dir);
830  if (fFileName != "") fi.fFilename = StrDup(fFileName);
831  new TGFileDialog(fClient->GetDefaultRoot(), this, kFDSave, &fi);
832  if (fi.fFilename) {
833  //if no ".xxx" ending given, we add ".dat"
834  TString filenam(fi.fFilename);
835  if (!filenam.Contains('.'))
836  filenam += ".dat";
837  Int_t n_saved = gIDGridManager->WriteAsciiFile(filenam.Data(), selection);
838  if (n_saved) {
839  //wrote file no problem
840  SetStatus(Form("Saved %d grids in file %s", n_saved, filenam.Data()));
841  //set file name for Save
842  fFileName = gSystem->BaseName(filenam);
843  }
844  else {
845  new TGMsgBox(fClient->GetDefaultRoot(), this, "ID Grid Manager",
846  Form("Could not write file %s", filenam.Data()), 0,
847  kMBOk);
848  }
849  }
850  dir = fi.fIniDir;
851 }
852 
853 
854 
858 
860 {
861  // create a tab for each type of ID telescope
862  // put a list box for ID grid names on each tab
863 
864  KVString labels;
865  if (gIDGridManager->GetGrids()->GetSize()) gIDGridManager->GetListOfIDTelescopeLabels(labels);
866  if (labels == "") {
867  // no known idtelescopes referenced by grids (maybe we don't have a KVMultiDetArray?)
868  // make 1 tab "Grids" and put them all in
869  KVString lab = "Grids";
870  TGCompositeFrame* cf = fGridListTabs->AddTab(lab.Data());
872  fIDGridList = new KVListView(KVIDGraph::Class(), cf, 600, 400);
873  fIDGridList->SetDataColumns(11);
874  fIDGridList->SetDataColumn(0, "Name", "", kTextLeft);
875  fIDGridList->SetDataColumn(2, "VarX", "", kTextLeft);
876  fIDGridList->SetDataColumn(1, "VarY", "", kTextLeft);
877  fIDGridList->SetDataColumn(3, "ID Telescopes", "GetNamesOfIDTelescopes", kTextLeft);
878  fIDGridList->SetDataColumn(4, "RunList", "", kTextLeft);
879  fIDGridList->SetDataColumn(5, "Identify Z and A?", "HasMassIDCapability", kTextCenterX);
880  fIDGridList->GetDataColumn(5)->SetIsBoolean();
881  fIDGridList->SetDataColumn(6, "# Ident.", "GetNumberOfIdentifiers", kTextRight);
882  fIDGridList->SetDataColumn(7, "# Cuts", "GetNumberOfCuts", kTextRight);
883  fIDGridList->SetDataColumn(8, "# Infos", "GetNumberOfInfos", kTextRight);
884  fIDGridList->SetDataColumn(9, "X scaling", "GetXScaleFactor", kTextRight);
885  fIDGridList->SetDataColumn(10, "Y scaling", "GetYScaleFactor", kTextRight);
886  fIDGridList->ActivateSortButtons();
887  fIDGridList->Connect("SelectionChanged()", "KVIDGridManagerGUI", this,
888  "SelectionChanged()");
889  fIDGridList->SetDoubleClickAction("KVIDGridManagerGUI", this, "StartEditor(TObject*)");
890  cf->AddFrame(fIDGridList, new TGLayoutHints(kLHintsLeft | kLHintsTop |
892  10, 10, 10));
893  auto grids = gIDGridManager->GetGrids();
894  fIDGridList->Display(grids);
895  return;
896  }
897  //loop over labels
898  labels.Begin(",");
899  while (! labels.End()) {
900  KVString lab = labels.Next();
901  TGCompositeFrame* cf = fGridListTabs->AddTab(lab.Data());
903  fIDGridList = new KVListView(KVIDGraph::Class(), cf, 600, 400);
904  fIDGridList->SetDataColumns(10);
905  fIDGridList->SetDataColumn(0, "Name", "", kTextLeft);
906  fIDGridList->SetDataColumn(2, "VarX", "", kTextLeft);
907  fIDGridList->SetDataColumn(1, "VarY", "", kTextLeft);
908  fIDGridList->SetDataColumn(3, "ID Telescopes", "GetNamesOfIDTelescopes", kTextLeft);
909  fIDGridList->SetDataColumn(4, "RunList", "", kTextLeft);
910  fIDGridList->SetDataColumn(5, "Identify Z and A?", "HasMassIDCapability", kTextCenterX);
911  fIDGridList->GetDataColumn(5)->SetIsBoolean();
912  fIDGridList->SetDataColumn(6, "# Ident.", "GetNumberOfIdentifiers", kTextRight);
913  fIDGridList->SetDataColumn(7, "# Cuts", "GetNumberOfCuts", kTextRight);
914  fIDGridList->SetDataColumn(8, "X scaling", "GetXScaleFactor", kTextRight);
915  fIDGridList->SetDataColumn(9, "Y scaling", "GetYScaleFactor", kTextRight);
916  fIDGridList->ActivateSortButtons();
917  fIDGridList->Connect("SelectionChanged()", "KVIDGridManagerGUI", this,
918  "SelectionChanged()");
919  fIDGridList->SetDoubleClickAction("KVIDGridManagerGUI", this, "StartEditor(TObject*)");
920  cf->AddFrame(fIDGridList, new TGLayoutHints(kLHintsLeft | kLHintsTop |
922  10, 10, 10));
923  auto grids = gIDGridManager->GetGridsForIDTelescope(lab);
924  fIDGridList->Display(grids);
925  delete grids;
926  }
927 
928 }
929 
930 
931 
934 
936 {
937  //called when a new tab is selected
938 
939  TGCompositeFrame* cf = fGridListTabs->GetCurrentContainer();
940  if (!cf) return;//there are no tabs
941  TGFrameElement* el = (TGFrameElement*)cf->GetList()->At(0);
942  fIDGridList = (KVListView*)el->fFrame;
943  fIDGridList->SelectionChanged();
944 }
945 
946 
947 
952 
954 {
955  // create a tab for each type of ID telescope
956  // put a list box for ID grid names on each tab
957  // cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : starting..." << endl;
958 
959  KVString labels("");
960  if (gIDGridManager->GetGrids()->GetSize()) gIDGridManager->GetListOfIDTelescopeLabels(labels);
961  else {
962  // there are no grids in the grid manager
963  RemoveEmptyTabs();
964  KVString lab = "Grids";
965  TGCompositeFrame* cf = fGridListTabs->AddTab(lab.Data());
967  fIDGridList = new KVListView(KVIDGraph::Class(), cf, 600, 400);
968  fIDGridList->SetDataColumns(10);
969  fIDGridList->SetDataColumn(0, "Name", "", kTextLeft);
970  fIDGridList->SetDataColumn(2, "VarX", "", kTextLeft);
971  fIDGridList->SetDataColumn(1, "VarY", "", kTextLeft);
972  fIDGridList->SetDataColumn(3, "ID Telescopes", "GetNamesOfIDTelescopes", kTextLeft);
973  fIDGridList->SetDataColumn(4, "RunList", "", kTextLeft);
974  fIDGridList->SetDataColumn(5, "Identify Z and A?", "HasMassIDCapability", kTextCenterX);
975  fIDGridList->GetDataColumn(5)->SetIsBoolean();
976  fIDGridList->SetDataColumn(6, "# Ident.", "GetNumberOfIdentifiers", kTextRight);
977  fIDGridList->SetDataColumn(7, "# Cuts", "GetNumberOfCuts", kTextRight);
978  fIDGridList->SetDataColumn(8, "X scaling", "GetXScaleFactor", kTextRight);
979  fIDGridList->SetDataColumn(9, "Y scaling", "GetYScaleFactor", kTextRight);
980  fIDGridList->ActivateSortButtons();
981  fIDGridList->Connect("SelectionChanged()", "KVIDGridManagerGUI", this,
982  "SelectionChanged()");
983  cf->AddFrame(fIDGridList, new TGLayoutHints(kLHintsLeft | kLHintsTop |
985  10, 10, 10));
986  fGridListTabs->MapSubwindows();
987  fGridListTabs->Layout();
988  Int_t ntabs = fGridListTabs->GetCurrent();
989  TabSelect(ntabs);
990  return;
991  }
992  if (labels == "") {
993  // no known idtelescopes referenced by grids (maybe we don't have a KVMultiDetArray?)
994  // update "Grids" tab
995  TGCompositeFrame* cf = fGridListTabs->GetTabContainer("Grids");
996  if (!cf) {
997  cout << "cf = 0x0 : label=Grids tab name=" <<
998  fGridListTabs->GetTabTab("Grids")->GetText()->GetString() << endl;
999  }
1000  else {
1001  TGFrameElement* el = (TGFrameElement*)cf->GetList()->At(0);
1002  fIDGridList = (KVListView*)el->fFrame;
1003  auto grids = gIDGridManager->GetGrids();
1004  fIDGridList->Display(grids);
1005  }
1006  //make sure we are on the right tab
1007  Int_t ntabs = fGridListTabs->GetCurrent();
1008  TabSelect(ntabs);
1009  return;
1010  }
1011  //add any missing labels, update existing ones
1012  labels.Begin(",");
1013  while (! labels.End()) {
1014  KVString lab = labels.Next();
1015  // cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : updating tab '" << lab.Data() << "'..." << endl;
1016  if (!fGridListTabs->GetTabContainer(lab.Data())) { // new tab
1017  // cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : new tab '" << lab.Data() << "'..." << endl;
1018  TGCompositeFrame* cf = fGridListTabs->AddTab(lab.Data());
1020  fIDGridList = new KVListView(KVIDGraph::Class(), cf, 600, 400);
1021  fIDGridList->SetDataColumns(11);
1022  fIDGridList->SetDataColumn(0, "Name", "", kTextLeft);
1023  fIDGridList->SetDataColumn(2, "VarX", "", kTextLeft);
1024  fIDGridList->SetDataColumn(1, "VarY", "", kTextLeft);
1025  fIDGridList->SetDataColumn(3, "ID Telescopes", "GetNamesOfIDTelescopes", kTextLeft);
1026  fIDGridList->SetDataColumn(4, "RunList", "", kTextLeft);
1027  fIDGridList->SetDataColumn(5, "Identify Z and A?", "HasMassIDCapability", kTextCenterX);
1028  fIDGridList->GetDataColumn(5)->SetIsBoolean();
1029  fIDGridList->SetDataColumn(6, "# Ident.", "GetNumberOfIdentifiers", kTextRight);
1030  fIDGridList->SetDataColumn(7, "# Cuts", "GetNumberOfCuts", kTextRight);
1031  fIDGridList->SetDataColumn(8, "# Infos", "GetNumberOfInfos", kTextRight);
1032  fIDGridList->SetDataColumn(9, "X scaling", "GetXScaleFactor", kTextRight);
1033  fIDGridList->SetDataColumn(10, "Y scaling", "GetYScaleFactor", kTextRight);
1034  fIDGridList->ActivateSortButtons();
1035  fIDGridList->Connect("SelectionChanged()", "KVIDGridManagerGUI", this,
1036  "SelectionChanged()");
1037  cf->AddFrame(fIDGridList, new TGLayoutHints(kLHintsLeft | kLHintsTop |
1039  10, 10, 10));
1040  auto grids = gIDGridManager->GetGridsForIDTelescope(lab);
1041  fIDGridList->Display(grids);
1042  delete grids;
1043  fGridListTabs->MapSubwindows();
1044  fGridListTabs->Layout();
1045  fGridListTabs->SetTab(fGridListTabs->GetNumberOfTabs() - 1, kTRUE);
1046  }
1047  else { //existing tab
1048  //cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : existing tab '" << lab.Data() << "'..." << endl;
1049  TGCompositeFrame* cf = fGridListTabs->GetTabContainer(lab.Data());
1050  if (!cf) {
1051  cout << "cf = 0x0 : label=" << lab.Data() << " tab name=" <<
1052  fGridListTabs->GetTabTab(lab.Data())->GetText()->GetString() << endl;
1053  }
1054  else {
1055  //cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : recup tab '" << cf->GetName() << "'..." << endl;
1056  TGFrameElement* el = (TGFrameElement*)cf->GetList()->At(0);
1057  //cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : recup element '" << el->GetName() << "'..." << endl;
1058  fIDGridList = (KVListView*)el->fFrame;
1059  //cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : recup view list '" << fIDGridList->GetName() << "'..." << endl;
1060  auto grids = gIDGridManager->GetGridsForIDTelescope(lab);
1061  //cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : recup list de telescope'" << grids->GetName() << "'..." << endl;
1062  //grids->ls();
1063  fIDGridList->Display(grids);
1064  //cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : display list of grids in the viewerlist..." << endl;
1065 
1066  if (grids) delete grids;
1067  // cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : deleting the list..." << endl;
1068  }
1069  }
1070  }
1071  //now check that none of the remaining tabs are empty & should be removed
1072  RemoveEmptyTabs();
1073  // cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : empty tabs removed !" << endl;
1074  //make sure we are on the right tab
1075  Int_t ntabs = fGridListTabs->GetCurrent();
1076  TabSelect(ntabs);
1077  // cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : current tab selected !" << endl;
1078 }
1079 
1080 
1081 
1084 
1086 {
1087  // Recursively remove any empty tabs
1088 
1089  Int_t ntabs = fGridListTabs->GetNumberOfTabs();
1090  Bool_t recursive = kFALSE;
1091  for (Int_t itab = 0; itab < ntabs; itab++) {
1092 
1093  //get name of tab
1094  KVString lab = fGridListTabs->GetTabTab(itab)->GetString();
1095  //get grids for this tab (if any)
1096  auto grids = gIDGridManager->GetGridsForIDTelescope(lab);
1097  Int_t ngrids = grids->GetEntries();
1098  delete grids;
1099  if (!ngrids) {
1100  //empty tab! remove it!
1101  //delete the KVListView
1102  TGCompositeFrame* cf = fGridListTabs->GetTabContainer(itab);
1103  TGFrameElement* el = (TGFrameElement*)cf->GetList()->At(0);
1104  KVListView* lv = (KVListView*)el->fFrame;
1105  delete lv;
1106  //remove tab
1107  fGridListTabs->RemoveTab(itab, kFALSE);
1108  recursive = kTRUE; // call recursively
1109  break;//stop loop - tab numbers have changed
1110  }
1111  }
1112  if (recursive) RemoveEmptyTabs();
1113  fGridListTabs->MapSubwindows();
1114  fGridListTabs->Layout();
1115 }
1116 
1117 
1118 
1122 
1124 {
1125  // called when a previously selected grid is modified
1126  // updates lists of lines
1127 
1128  if (!fLastSelectedGrid) return;
1129 
1130  KVList* ids = fLastSelectedGrid->GetIdentifiers();
1131  // sort lines in order of increasing Z
1132  ids->Sort();
1133  fIDLineList->Display(ids);
1134 // KVSeqCollection* cutlines = fSelectedGrid->GetCuts()->GetSubListWithClass("KVIDCutLine");
1135  fCUTList->Display(fSelectedGrid->GetCuts());
1136 // fCUTLineList->Display(cutlines);
1137 // delete cutlines;
1138 // cutlines = fSelectedGrid->GetCuts()->GetSubListWithClass("KVIDCutContour");
1139  fCUTInfoList->Display(fSelectedGrid->GetInfos());
1140 // fCUTContourList->Display(cutlines);
1141 // delete cutlines;
1142 }
1143 
1144 
1145 
1151 
1153 {
1154  // Called when a grid is selected in list of grids
1155  // We fill list of all lines in grid
1156  //If only one grid is selected, we display its lines in the line list
1157  //If more than one grid is selected, we clear the line list
1158 
1159  if (GetNSelected() == 1 && fSelectedGrid) {
1160  KVList* ids = fSelectedGrid->GetIdentifiers();
1161  // sort lines in order of increasing Z
1162  ids->Sort();
1163  fIDLineList->Display(ids);
1164 // KVSeqCollection* cutlines = fSelectedGrid->GetCuts()->GetSubListWithClass("KVIDCutLine");
1165  fCUTList->Display(fSelectedGrid->GetCuts());
1166 // delete cutlines;
1167 // cutlines = fSelectedGrid->GetCuts()->GetSubListWithClass("KVIDCutContour");
1168  fCUTInfoList->Display(fSelectedGrid->GetInfos());
1169 // delete cutlines;
1170  if (fLastSelectedGrid) {
1171  fLastSelectedGrid->Disconnect("Modified()", this, "UpdateListOfLines()");
1172  }
1173  fSelectedGrid->Connect("Modified()", "KVIDGridManagerGUI", this, "UpdateListOfLines()");
1174  fLastSelectedGrid = fSelectedGrid;
1175  }
1176  else {
1177  fIDLineList->RemoveAll();
1178  fCUTList->RemoveAll();
1179  fCUTInfoList->RemoveAll();
1180  if (fLastSelectedGrid) {
1181  fLastSelectedGrid->Disconnect("Modified()", this, "UpdateListOfLines()");
1182  fLastSelectedGrid = 0;
1183  }
1184  }
1185 }
1186 
1187 
1188 
1191 
1193 {
1194  // disable all buttons
1195  for (int i = 0; i < fNbButtons; i++) fTBbuttons[i]->SetEnabled(kFALSE);
1196  // enable 'open' & 'quit' & 'new grid"
1197  fTBOpen->SetEnabled();
1198  fTBRefresh->SetEnabled();
1199 // fTBStartEditor->SetEnabled();
1200  fTBNewG->SetEnabled();
1201  fTBOpenRoot->SetEnabled();
1202  // enable 'save' if there are grids
1203  if (gIDGridManager->GetGrids()->GetEntries()) fTBSave->SetEnabled();
1204 
1205  if (!GetNSelected()) return; // no grids selected
1206 
1207  //enable delete selected grid(s)
1208  fTBDelG->SetEnabled();
1209 
1210  if (GetNSelected() == 1) {
1211  // only one grid selected
1212  fTBStartEditor->SetEnabled();
1213  fTBCopyG->SetEnabled();
1214  if (gMultiDetArray) fTBSetIDG->SetEnabled();
1215  }
1216 }
1217 
1218 
1219 
1231 
1233 {
1234  // GUI method to draw a new identifier and add it to graph.
1235  // A dialog box with drop-down list pops up for the user to choose the class of the
1236  // new identifier, unless only one choice is possible, in which case it is used automatically.
1237  // For each KVIDGraph-derived class, the list of possible identifier classes and the
1238  // default class are define in .kvrootrc by the variables:
1239  //
1240  // [class_name].IDClass: [id class 1]
1241  // +[class_name].IDClass: [id class 2]
1242  // + ...
1243  // [class_name].DefaultIDClass: [id class]
1244 
1245  if (!fSelectedGrid || GetNSelected() != 1) return;
1246  TString resname;
1247  resname.Form("%s.IDClass", fSelectedGrid->ClassName());
1248  TString cut_choices = gEnv->GetValue(resname.Data(), "");
1249  resname.Form("%s.DefaultIDClass", fSelectedGrid->ClassName());
1250  TString cut_default = gEnv->GetValue(resname.Data(), "");
1251  TString cut_class;
1252  Bool_t okpressed;
1253  if (cut_choices.Contains(" ")) {
1254  new KVDropDownDialog(this,
1255  "Choose class of new identifier :",
1256  cut_choices.Data(),
1257  cut_default.Data(),
1258  &cut_class,
1259  &okpressed);
1260  if (!okpressed) return;
1261  }
1262  else
1263  cut_class = cut_choices;
1264  SetStatus(Form("Draw ID line (%s) in current pad", cut_class.Data()));
1265  fSelectedGrid->DrawAndAdd("ID", cut_class.Data());
1266  fTBNewIDL->SetDown(kFALSE, kFALSE);
1267  SetStatus();
1268 }
1269 
1270 
1271 
1283 
1285 {
1286  // GUI method to draw a new cut and add it to graph.
1287  // A dialog box with drop-down list pops up for the user to choose the class of the
1288  // new cut, unless only one choice is possible, in which case it is used automatically.
1289  // For each KVIDGraph-derived class, the list of possible cut classes and the
1290  // default class are define in .kvrootrc by the variables:
1291  //
1292  // [class_name].CutClass: [cut class 1]
1293  // +[class_name].CutClass: [cut class 2]
1294  // + ...
1295  // [class_name].DefaultCutClass: [cut class]
1296 
1297  if (!fSelectedGrid || GetNSelected() != 1) return;
1298  TString resname;
1299  resname.Form("%s.CutClass", fSelectedGrid->ClassName());
1300  TString cut_choices = gEnv->GetValue(resname.Data(), "");
1301  resname.Form("%s.DefaultCutClass", fSelectedGrid->ClassName());
1302  TString cut_default = gEnv->GetValue(resname.Data(), "");
1303  TString cut_class;
1304  TString cut_types = cut_choices;
1305  cut_types.ReplaceAll("KVIDCut", "");
1306  Bool_t okpressed;
1307  if (cut_choices.Contains(" ")) {
1308  new KVDropDownDialog(this,
1309  "Choose class of new cut :",
1310  cut_types.Data(),
1311  cut_default.Data(),
1312  &cut_class,
1313  &okpressed);
1314  if (!okpressed) return;
1315  }
1316  else
1317  cut_class = cut_types;
1318  SetStatus(Form("Draw cut %s in current pad", cut_class.Data()));
1319  cut_class.Prepend("KVIDCut");
1320  fSelectedGrid->DrawAndAdd("CUT", cut_class.Data());
1321  fTBNewCut->SetDown(kFALSE, kFALSE);
1322  SetStatus();
1323 }
1324 
1325 
1326 
1327 
1331 
1333 {
1334  // test the identification with selected grid
1335  // we search in current pad for the data histogram
1336 
1337  SetStatus("");
1338  if (GetNSelected() != 1) return;
1339  if (!fSelectedGrid) return;
1340  // look for data histogram in current pad
1341  TH2* histo = 0;
1342  if (gPad) {
1343  TIter next(gPad->GetListOfPrimitives());
1344  TObject* o;
1345  while ((o = next())) {
1346  if (o->InheritsFrom("TH2")) {
1347  histo = (TH2*)o;
1348  break;
1349  }
1350  }
1351  }
1352  if (!histo) {
1353  SetStatus("No TH2 found in current pad. Select pad containing 2D histo with data to identify.");
1354  return;
1355  }
1356  else {
1357  SetStatus(Form("Test identification of data in current pad %s.", histo->GetName()));
1358  }
1359  new KVTestIDGridDialog(fClient->GetDefaultRoot(), this, 10, 10, fSelectedGrid, histo);
1360  SetStatus("");
1361 }
1362 
1363 
1364 
1368 
1370 {
1371  // test the identification with selected grid
1372  // we search in current pad for the data histogram
1373  SetStatus("");
1374  if (GetNSelected() != 1) return;
1375  if (!fSelectedGrid) return;
1376  // look for data histogram in current pad
1377  TH2* histo = 0;
1378  if (gPad) {
1379  TIter next(gPad->GetListOfPrimitives());
1380  TObject* o;
1381  while ((o = next())) {
1382  if (o->InheritsFrom("TH2")) {
1383  histo = (TH2*)o;
1384  break;
1385  }
1386  }
1387  }
1388  if (!histo) {
1389  SetStatus("No TH2 found in current pad. Select pad containing 2D histo with data to identify.");
1390  return;
1391  }
1392  else {
1393  SetStatus(Form("Test identification of data in current pad %s.", histo->GetName()));
1394  }
1395  TFile* tmpfiles = TestIdentificationWithTree(fSelectedGrid, histo->GetName());
1396  if (!tmpfiles) {
1397  SetStatus("There was a problem with the test ???");
1398  return;
1399  }
1400  new TCanvas;
1401  TH2* id = (TH2*)tmpfiles->Get("idcode_map");
1402  id->SetStats(kFALSE);
1403  id->Draw("zcol");
1404  TTree* t = (TTree*)tmpfiles->Get("tree_idresults");
1405  t->StartViewer();
1406  SetStatus("");
1407 }
1408 
1409 
1410 
1411 
1424 
1425 TFile* KVIDGridManagerGUI::TestIdentificationWithTree(KVIDGraph* gr, const Char_t* name_of_data_histo)
1426 {
1427  //This method allows to test the identification capabilities of the grid using data in a TH2F.
1428  //We assume that 'data' contains an identification map, whose 'x' and 'y' coordinates correspond
1429  //to this grid. Then we loop over every bin of the histogram, perform the identification (if
1430  //IsIdentifiable() returns kTRUE) and fill the two histograms with the resulting identification
1431  //and its dependence on the 'residual energy' i.e. the 'x'-coordinate of the 'data' histogram,
1432  //each identification weighted by the contents of the original data bin.
1433  //
1434  //The 'identification" we represent is the result of the KVReconstructedNucleus::GetPID() method.
1435  //For particles identified in Z only, this is the "real Z".
1436  //For particles with A & Z identification, this is Z + 0.1*(A - 2*Z)
1437 
1438  //Initialize the grid: calculate line widths etc.
1439  gr->Initialize();
1440 
1441  TH2F* data = (TH2F*)gROOT->FindObject(name_of_data_histo);
1442  if (!data) {
1443  printf(" KVIDGraph::TestIdentificationWithTree l histo %s n existe pas\n", name_of_data_histo);
1444  return 0;
1445  }
1446 
1447 
1450 
1451  // store current memory directory
1452  TDirectory* CWD = gDirectory;
1453 
1454  TTree* tid = 0;
1455  if ((tid = (TTree*)gROOT->FindObject("tree_idresults"))) {
1456  printf(" KVIDGraph::TestIdentificationWithTree effacemenent de l arbre existant\n");
1457  delete tid;
1458  }
1459  // create temporary file for tree
1460  TString fn("IDtestTree.root");
1462  TFile* tmpfile = new TFile(fn.Data(), "recreate");
1463  TH2F* idmap = (TH2F*)data->Clone("idcode_map");
1464  idmap->Reset();
1465  tid = new TTree("tree_idresults", "pid");
1466  Float_t br_xxx, br_yyy, br_stat, br_pid;
1467  Int_t br_idcode, br_isid;
1468 
1469  tid->Branch("X", &br_xxx, "br_xxx/F");
1470  tid->Branch("Y", &br_yyy, "br_yyy/F");
1471  tid->Branch("Stat", &br_stat, "br_stat/F");
1472 
1473  tid->Branch("PID", &br_pid, "br_pid/F");
1474  tid->Branch("IDcode", &br_idcode, "br_idcode/I");
1475  tid->Branch("IsIdentified", &br_isid, "br_isid/I");
1476 
1477  Int_t tot_events = (Int_t) data->GetSum();
1478  Int_t events_read = 0;
1479  Float_t percent = 0., cumul = 10.;
1480 
1481  //loop over data in histo
1482  for (int i = 1; i <= data->GetNbinsX(); i++) {
1483  for (int j = 1; j <= data->GetNbinsY(); j++) {
1484 
1485  Stat_t poids = data->GetBinContent(i, j);
1486  if (poids == 0)
1487  continue;
1488  br_stat = Float_t(poids);
1489 
1490  Axis_t x0 = data->GetXaxis()->GetBinCenter(i);
1491  Axis_t y0 = data->GetYaxis()->GetBinCenter(j);
1492  Axis_t wx = data->GetXaxis()->GetBinWidth(i);
1493  Axis_t wy = data->GetYaxis()->GetBinWidth(j);
1494 
1495  br_xxx = Float_t(x0);
1496  br_yyy = Float_t(y0);
1497  //If bin content ('poids') is <=20, we perform the identification 'poids' times, each time with
1498  //randomly-drawn x and y coordinates inside this bin
1499  //If 'poids'>20, we perform the identification 20 times and we fill the histograms with
1500  //a weight poids/20
1501  Double_t x, y;
1502  Int_t kmax = (Int_t) TMath::Min(20., poids);
1503  //Double_t weight = (kmax == 20 ? poids / 20. : 1.);
1504 
1505  for (int k = 0; k < kmax; k++) {
1506 
1507  x = gRandom->Uniform(x0 - .5 * wx, x0 + .5 * wx);
1508  y = gRandom->Uniform(y0 - .5 * wy, y0 + .5 * wy);
1509  if (gr->IsIdentifiable(x, y)) {
1510  br_isid = 1;
1511  gr->Identify(x, y, idr);
1512  nuc.SetIdentification(idr, nullptr);
1513  br_pid = nuc.GetPID();
1514  br_idcode = gr->GetQualityCode();
1515  idmap->SetBinContent(i, j, br_idcode);
1516  }
1517  else {
1518  br_isid = 0;
1519  br_pid = -1;
1520  br_idcode = -1;
1521  idmap->SetBinContent(i, j, br_idcode);
1522  }
1523  tid->Fill();
1524  }
1525  events_read += (Int_t) poids;
1526  percent = (1. * events_read / tot_events) * 100.;
1527  gr->Increment((Float_t) events_read); //sends signal to GUI progress bar
1528  if (percent >= cumul) {
1529  cout << (Int_t) percent << "\% processed" << endl;
1530  cumul += 10;
1531  }
1532  //gSystem->ProcessEvents();
1533  }
1534  }
1535 
1536  delete idr;
1537  CWD->cd();
1538  return tmpfile;
1539 }
1540 
1541 
1542 
1544 
1546 {
1547  SetStatus("");
1548  if (GetNSelected() != 1) return;
1549  if (!fSelectedGrid) return;
1550  SetStatus(Form("Fitting grid %s", fSelectedGrid->GetName()));
1552  fitter->SetGrid(fSelectedGrid);
1553  fitter->SetPad(fSelectedGrid->GetPad());
1554  TMethod* m = fitter->IsA()->GetMethodAny("FitPanel");
1555  TContextMenu* cm = new TContextMenu("FitPanel", "Context menu for KVVirtualIDFitter::FitPanel");
1556  cm->Action(fitter, m);
1557  delete cm;
1558 }
1559 
1560 
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:1244
static void GetTempFileName(TString &base)
Definition: KVBase.cpp:843
static const Char_t * GetKVVersion()
Returns KaliVeda version string.
Definition: KVBase.cpp:869
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:182
void Clear(Option_t *opt="") override
Definition: KVIDGraph.cpp:203
void SetVarY(const char *v) override
Definition: KVIDGraph.h:556
void SetVarX(const char *v) override
Definition: KVIDGraph.h:552
void AddIDTelescopes(const TList *)
Associate this graph with all ID telescopes in list.
Definition: KVIDGraph.cpp:1528
static KVIDGraph * MakeIDGraph(const Char_t *)
Definition: KVIDGraph.cpp:1568
virtual void SetOnlyZId(Bool_t yes=kTRUE)
Definition: KVIDGraph.cpp:1508
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
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 &)
void DeleteGrid(KVIDGraph *, Bool_t update=kTRUE)
Int_t WriteAsciiFile(const Char_t *filename, const TCollection *selection=0)
KVSeqCollection * GetGridsForIDTelescope(const Char_t *label)
KVSeqCollection * GetGrids()
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:85
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:22
void Sort(Bool_t order=kSortAscending)
Definition: KVList.h:40
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)