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", "https://kaliveda.in2p3.fr/class");
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, "Type", "", kTextCenterX);
244  fCUTList->SetDataColumn(2, "Selection", "GetSelectionType", kTextCenterX);
245  fCUTList->ActivateSortButtons();
246  fCUTList->AllowBrowse(kFALSE);
247  //fIDLineList->Connect("SelectionChanged()", "KVIDGridManagerGUI", this,
248  // "SelectionChanged()");
249  line_frame->AddFrame(fCUTList, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 2, 2, 2));
250 
251  lab1 = new TGLabel(line_frame, "Infos");
252  line_frame->AddFrame(lab1, new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 2, 2, 2, 2));
253 
254  fCUTInfoList = new KVListView(KVIDentifier::Class(), line_frame, 350, 150);
255  fCUTInfoList->SetDataColumns(3);
256  fCUTInfoList->SetDataColumn(0, "Name", "", kTextLeft);
257  fCUTInfoList->SetDataColumn(1, "# Points", "GetN", kTextCenterX);
258  fCUTInfoList->SetDataColumn(2, "Class", "ClassName", kTextCenterX);
259  fCUTInfoList->ActivateSortButtons();
260  fCUTInfoList->AllowBrowse(kFALSE);
261  line_frame->AddFrame(fCUTInfoList, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 2, 2, 2, 10));
262 
263  fHframe->AddFrame(line_frame, new TGLayoutHints(kLHintsLeft | kLHintsTop | kLHintsExpandY, 20, 20, 20, 20));
264 
265  AddFrame(fHframe,
267  0));
268 
269  SetWindowName("ID Grid Manager");
270 
271  //layout & draw window
272  MapSubwindows();
273  Resize(GetDefaultSize());
274  MapWindow();
275  SetWMSize(1200, 600);
276 
277  // first tab is visible, but TabSelect(0) is not called automatically
278  TabSelect(0);
279 
280 }
281 
282 
283 
286 
287 KVIDGridManagerGUI::~KVIDGridManagerGUI()
288 {
289  //close window
290  UnmapWindow();
291  gIDGridManager->Disconnect("Modified()", this, "UpdateListOfGrids()");
292 }
293 
294 
295 
298 
300 {
301  //close viewer
302  DeleteWindow();
303 }
304 
305 
306 
308 
310 {
311  if (!fIDGridEditor) fIDGridEditor = new KVIDGridEditor;
312  if (fIDGridEditor->IsClosed()) fIDGridEditor->StartViewer();
313  if (fSelectedGrid) {
314  // avant d'editer la grille, on en fait une copie pour
315  // pouvoir revenir en arriere
316  fSelectedGrid->UpdateLastSavedVersion();
317  fIDGridEditor->SetGrid(fSelectedGrid);
318  }
319 }
320 
321 
322 
325 
327 {
328  //Info("StartEditor(TObject*)", "obj=%p", o);
329  StartEditor();
330 }
331 
332 
333 
335 
337 {
338  static TString dir("$(HISTOROOT)");
339  TString currentdir(gSystem->ExpandPathName("."));
340 
341  if (dir == "$(HISTOROOT)" && gSystem->Getenv("HISTOROOT")) {
342  if (gSystem->ExpandPathName(dir)) dir = ".";
343  }
344  else
345  dir = ".";
346 
347  const char* filetypes[] = {"Root files", "*.root", "All files", "*", 0, 0};
348  TGFileInfo fi;
349  fi.fFileTypes = filetypes;
350  fi.fIniDir = StrDup(dir);
351  new TGFileDialog(fClient->GetDefaultRoot(), this, kFDOpen, &fi);
352  if (fi.fFilename) {
353  if (!(TFile::Open(fi.fFilename))) {
354  new TGMsgBox(gClient->GetDefaultRoot(), gClient->GetDefaultRoot(), "ID Grid Editor", Form("Could not open file %s", fi.fFilename), 0, kMBOk);
355  }
356  }
357  dir = fi.fIniDir;
358  gSystem->cd(currentdir.Data());
359 }
360 
361 
362 
365 
367 {
368  //Receive signals emitted by items selected in Grids menu
369  switch (id) {
370 
371  case M_QUIT:
372 
373  Quit();
374  break;
375 
376  case M_GRIDS_NEW:
377 
378  cout << "Add new grid" << endl;
379  NewGrid();
380  break;
381  case M_GRIDS_READ:
382  OpenFile();
383  break;
384 
385  case M_GRIDS_SAVE_SEL:
386  // save current selection of grids in file
387  SaveGridsAs(&fSelectedEntries);
388  break;
389 
390  case M_GRIDS_SAVE_TAB:
391  // save all grids in current tab in file
392  SaveGridsAs(GetAllGridsInTab());
393  break;
394 
395  case M_GRIDS_SAVE_ALL:
396 
397  //save all grids in file - ask user to confirm or change filename/path
398  SaveGridsAs();
399  break;
400 
401  case M_GRIDS_DEL_SEL:
402  DeleteSelectedGrids();
403  break;
404 
405  case M_GRIDS_DEL_TAB:
406  //warning message and confirmation
407  {
408  Int_t ret_val;
409  new TGMsgBox(fClient->GetDefaultRoot(), this, "ID Grid Manager",
410  "This will delete all grids in the current tab. Are you sure ?",
411  kMBIconExclamation, kMBOk | kMBCancel, &ret_val);
412  if (ret_val & kMBOk) {
413  DeleteAllGridsInTab();
414  }
415  }
416  break;
417  case M_GRIDS_DEL_ALL:
418 
419  //warning message and confirmation
420  {
421  Int_t ret_val;
422  new TGMsgBox(fClient->GetDefaultRoot(), this, "ID Grid Manager",
423  "This will delete all grids. Are you sure ?",
424  kMBIconExclamation, kMBOk | kMBCancel, &ret_val);
425  if (ret_val & kMBOk) {
426  gIDGridManager->Clear();
427  //UpdateListOfGrids();
429  //with an empty file !!
430  fFileName = "";
431  }
432  }
433  break;
434 
435  case M_GRIDS_SET_RUNLIST:
436  // set runlist for all selected grids
437  {
438  if (!fSelectedGrid) break; // must have selected at least one grid
439  TString runs = fSelectedGrid->GetRunList(); // fill dialog box with current runlist of selected grid
440  Bool_t ok_pressed = kFALSE;
441  new KVInputDialog(this, "Enter list of runs for grid(s):", &runs, &ok_pressed,
442  "Example: 1-10, 13, 22-657");
443  if (!ok_pressed) break; // user pressed 'cancel' or otherwise closed the dialog
444  TIter next(&fSelectedEntries);
445  KVIDGraph* entry;
446  while ((entry = (KVIDGraph*) next())) {
447  entry->SetRunList(runs.Data());
448  }
449  }
450  break;
451  case M_GRIDS_SET_VARX:
452  // set varx for all selected grids
453  {
454  if (!fSelectedGrid) break; // must have selected at least one grid
455  TString runs = fSelectedGrid->GetVarX(); // fill dialog box with current runlist of selected grid
456  Bool_t ok_pressed = kFALSE;
457  new KVInputDialog(this, "Enter X variable for grid(s):", &runs, &ok_pressed,
458  "");
459  if (!ok_pressed) break; // user pressed 'cancel' or otherwise closed the dialog
460  TIter next(&fSelectedEntries);
461  KVIDGraph* entry;
462  while ((entry = (KVIDGraph*) next())) {
463  entry->SetVarX(runs.Data());
464  }
465  }
466  break;
467  case M_GRIDS_SET_VARY:
468  // set varx for all selected grids
469  {
470  if (!fSelectedGrid) break; // must have selected at least one grid
471  TString runs = fSelectedGrid->GetVarY(); // fill dialog box with current runlist of selected grid
472  Bool_t ok_pressed = kFALSE;
473  new KVInputDialog(this, "Enter Y variable for grid(s):", &runs, &ok_pressed,
474  "");
475  if (!ok_pressed) break; // user pressed 'cancel' or otherwise closed the dialog
476  TIter next(&fSelectedEntries);
477  KVIDGraph* entry;
478  while ((entry = (KVIDGraph*) next())) {
479  entry->SetVarY(runs.Data());
480  }
481  }
482  break;
483  case M_GRIDS_SET_ZID:
484  // set varx for all selected grids
485  {
486  if (!fSelectedGrid) break; // must have selected at least one grid
487  Bool_t runs = !fSelectedGrid->HasMassIDCapability(); // fill dialog box with current runlist of selected grid
488  TIter next(&fSelectedEntries);
489  KVIDGraph* entry;
490  while ((entry = (KVIDGraph*) next())) {
491  entry->SetOnlyZId(!runs);
492  }
493  }
494  break;
495  case M_GRIDS_CLEAR:
496  // set varx for all selected grids
497  {
498  if (!fSelectedGrid) break; // must have selected at least one grid
499  TIter next(&fSelectedEntries);
500  KVIDGraph* entry;
501  while ((entry = (KVIDGraph*) next())) {
502  entry->Clear();
503  }
504  }
505  break;
506 
507  default:
508 
509  break;
510  }
511 }
512 
513 
514 
517 
519 {
520  //warning message and confirmation
521  Int_t ret_val;
522  new TGMsgBox(fClient->GetDefaultRoot(), this, "ID Grid Manager",
523  "This will delete the selected grids. Are you sure ?",
524  kMBIconExclamation, kMBOk | kMBCancel, &ret_val);
525  if (ret_val & kMBOk) {
526  DeleteGrids();
527  }
528 }
529 
530 
531 
533 
535 {
536  static TString dir(".");
537  const char* filetypes[] = {
538  "ID Grid files", "*.dat",
539  "All files", "*",
540  0, 0
541  };
542  TGFileInfo fi;
543  fi.fFileTypes = filetypes;
544  fi.fIniDir = StrDup(dir);
545  //printf("fIniDir = %s\n", fi.fIniDir);
546  new TGFileDialog(fClient->GetDefaultRoot(), this, kFDOpen, &fi);
547  if(fi.fMultipleSelection)
548  {
549  if(fi.fFileNamesList)
550  {
551  TIter nxt_file(fi.fFileNamesList);
552  int ngri = gIDGridManager->GetGrids()->GetEntries();
553  TObjString* fname;
554  bool ok = false;
555  TString filenames;
556  while((fname=(TObjString*)nxt_file()))
557  {
558  auto _ok = gMultiDetArray ? gMultiDetArray->ReadGridsFromAsciiFile(fname->GetString())
559  : gIDGridManager->ReadAsciiFile(fname->GetString());
560  if(_ok)
561  {
562  if(!filenames.IsNull())
563  filenames.Append(" ");
564  filenames.Append(fname->GetString());
565  }
566  ok |= _ok;
567  }
568  if (ok) {
569  UpdateListOfGrids();
570  int ngriread = gIDGridManager->GetGrids()->GetEntries() - ngri;
571  SetStatus(Form("Read %d grids from files %s", ngriread, filenames.Data()));
572  fFileName = gSystem->BaseName(filenames.Data());
573  }
574  else {
575  new TGMsgBox(fClient->GetDefaultRoot(), this, "ID Grid Manager",
576  Form("Could not read any of files %s", filenames.Data()),
577  0, kMBOk);
578  }
579  }
580  }
581  else if (fi.fFilename) {
582  int ngri = gIDGridManager->GetGrids()->GetEntries();
583  bool ok = gMultiDetArray ? gMultiDetArray->ReadGridsFromAsciiFile(fi.fFilename)
584  : gIDGridManager->ReadAsciiFile(fi.fFilename);
585  if (ok) {
586  UpdateListOfGrids();
587  //read file ok no problem.
588  int ngriread = gIDGridManager->GetGrids()->GetEntries() - ngri;
589  SetStatus(Form("Read %d grids from file %s", ngriread, fi.fFilename));
590  //set filename for Save
591  fFileName = gSystem->BaseName(fi.fFilename);
592  }
593  else {
594  new TGMsgBox(fClient->GetDefaultRoot(), this, "ID Grid Manager",
595  Form("Could not read file %s", fi.fFilename),
596  0, kMBOk);
597  }
598  }
599  dir = fi.fIniDir;
600 }
601 
602 
603 
609 
611 {
612  //remove all existing entries, then fill list from gIDGridManager
613  //we update the current pad, in case the displayed grid no longer exists
614  //grid buttons are disabled, as any selected grid is deselected
615  // cout << "DEBUG: KVIDGridManagerGUI::UpdateListOfGrids(): starting..." << endl;
616  UpdateTabs();
617  // cout << "DEBUG: KVIDGridManagerGUI::UpdateListOfGrids(): tabs has been updated !" << endl;
618  //update all canvases
619 // TSeqCollection* Clist = gROOT->GetListOfCanvases();
620 // if (Clist && Clist->GetEntries()) {
621 // Clist->R__FOR_EACH(TCanvas, Modified)();
622 // Clist->R__FOR_EACH(TCanvas, Update)();
623 // }
624  // cout << "DEBUG: KVIDGridManagerGUI::UpdateListOfGrids(): canvas has been updated !" << endl;
625 }
626 
627 
628 
636 
638 {
639  //called any time the selection of grids changes
640  //each time, we update:
641  //fSelectedEntries : the list of all selected entries
642  //GetNSelected() : the number of selected entries
643  //fSelectedGrid : the last selected grid (=the only grid selected if GeTNSelected==1)
644 
645  //get number of selected items
646  fSelectedEntries = fIDGridList->GetSelectedObjects();
647  fSelectedGrid = (KVIDGraph*)fIDGridList->GetLastSelectedObject();
648  if (!GetNSelected())fSelectedGrid = 0x0;
649  ShowListOfLines();
650  //(de)activate toolbar buttons
651  ActivateToolbarButtons();
652  if (!GetNSelected()) SetStatus();
653  else if (GetNSelected() == 1) SetStatus(Form("Selected grid %s (%s)", fSelectedGrid->GetName(), fSelectedGrid->ClassName()));
654  else SetStatus(Form("Selected %d grids, last selected grid %s (%s)", GetNSelected(), fSelectedGrid->GetName(), fSelectedGrid->ClassName()));
655 }
656 
657 
658 
659 
660 
666 
668 {
669  //delete the current selected grid, or all currently selected grids if there are more than one
670  //
671  //grids must be removed from the GUI before deleting, as objects given to KVListView::Display()
672  //must remain valid as long as they are displayed
673 
674  if (!GetNSelected()) return;
675 
676  fIDGridList->RemoveAll();
677 
678  TIter next(&fSelectedEntries, kIterBackward);
679  KVIDGraph* entry;
680  while ((entry = (KVIDGraph*) next()))
681  {
682  if (fLastSelectedGrid == entry) fLastSelectedGrid = 0;
683  gIDGridManager->DeleteGrid(entry, kFALSE); //no update
684  }
685  fSelectedEntries.Clear();
686  fSelectedGrid = 0;
687  UpdateListOfGrids();
688 }
689 
690 
691 
694 
696 {
697  //delete the all grids in currently selected tab
698 
699  TIter next(GetAllGridsInTab(), kIterBackward);
700  KVIDGraph* entry;
701  while ((entry = (KVIDGraph*) next())) {
702  gIDGridManager->DeleteGrid(entry, kFALSE); //no update
703  }
704  fSelectedEntries.Clear();
705  fSelectedGrid = 0;
706  UpdateListOfGrids();
707 }
708 
709 
710 
713 
715 {
716  // propose to set IDTelescopes parameter using grid names
717  Int_t ret_val;
718  new TGMsgBox(fClient->GetDefaultRoot(), this, "ID Grid Manager",
719  "Set IDTelescope for selected grid(s) using grid name ?",
720  kMBIconQuestion, kMBOk | kMBCancel, &ret_val);
721  if (ret_val & kMBOk)
722  {
723  for(auto tidg : fSelectedEntries)
724  {
725  auto idg = dynamic_cast<KVIDGraph*>(tidg);
727  Info("SetIDTelescopes", "Setting IDTelescope for %s...", idg->GetName());
728  if(gMultiDetArray)
729  idg->AddIDTelescope(gMultiDetArray->GetIDTelescope(idg->GetName()));
730  else
731  idg->AddIDTelescope(idg->GetName());
732  }
733  UpdateListOfGrids();
734  return;
735  }
736  TString idtels; bool ok_pressed=false;
737  new KVInputDialog(this, "Enter names of IDTelescopes to use for grid(s):",
738  &idtels, &ok_pressed, "Separate the names with commas!");
739  if(ok_pressed)
740  {
741  for(auto tidg : fSelectedEntries)
742  {
743  auto idg = dynamic_cast<KVIDGraph*>(tidg);
744  idg->SetIDTelescopes(idtels);
745  }
746  UpdateListOfGrids();
747  return;
748  }
749 
750 // TList telescopes;
751 // telescopes.AddAll(fSelectedGrid->GetListOfIDTelescopes());
752 // new KVIDGUITelescopeChooserDialog(gMultiDetArray, &telescopes, &cancel,
753 // fClient->GetDefaultRoot(), this, kTRUE);
754 // if (cancel || !telescopes.GetEntries()) return;
755 // fSelectedGrid->ClearListOfIDTelescopes();
756 // fSelectedGrid->AddIDTelescopes(&telescopes);
757 }
758 
759 
760 
763 
765 {
766  //deletes all lines in currently selected grid(s)
767 
768  if (GetNSelected() == 1)
769  fSelectedGrid->Clear();
770  else if (GetNSelected() > 1) {
771  //multiselection
772  TIter next(&fSelectedEntries);
773  KVIDGraph* grid;
774  while ((grid = (KVIDGraph*) next())) {
775  grid->Clear();
776  }
777  }
778  //update all canvases
779  TSeqCollection* Clist = gROOT->GetListOfCanvases();
780  if (Clist->GetSize() > 0) {
781  Clist->R__FOR_EACH(TCanvas, Modified)();
782  Clist->R__FOR_EACH(TCanvas, Update)();
783  }
784 }
785 
786 
787 
789 
791 {
792  if (!fSelectedGrid) return;
793  gIDGridManager->Disconnect("Modified()", this, "UpdateListOfGrids()");
794  KVIDGraph* new_gr = KVIDGraph::MakeIDGraph(fSelectedGrid->ClassName());
795  fSelectedGrid->Copy(*new_gr);
796  new_gr->AddIDTelescopes(fSelectedGrid->GetListOfIDTelescopes());
797  new_gr->SetRunList("");
798  gIDGridManager->SortGrids();
799  UpdateTabs();
800  gIDGridManager->Connect("Modified()", "KVIDGridManagerGUI", this, "UpdateListOfGrids()");
801  fIDGridList->Sort(0);
802  fIDGridList->Sort(0);
803  return;
804 }
805 
806 
807 
814 
816 {
817  // Create a new identification grid.
818  // First we ask the user to select the identification telescope(s)
819  // for which this grid will be used.
820  // For a given type of ID telescope, several types of grid may be
821  // applicable. If so, we ask the user to choose one.
822 
823  Info("NewGrid", "There are %d grids in the manager", gIDGridManager->GetGrids()->GetSize());
824  TString default_class = "KVIDZAGrid";
825  TList* telescopes = new TList;
826  if (gMultiDetArray) {
827  Bool_t cancel;
828  new KVIDGUITelescopeChooserDialog(gMultiDetArray, telescopes, &cancel,
829  fClient->GetDefaultRoot(), this);
830  if (cancel || !telescopes->At(0)) {
831  Info("NewGrid", "No ID telescopes chosen. Grid creation cancelled.");
832  return;
833  }
834  // get default ID grid class of first ID telescope
835  default_class = ((KVIDTelescope*)telescopes->At(0))->GetDefaultIDGridClass();
836  }
837  // get list of possible choices of grid class = list of all plugin classes
838  // defined for KVIDGraph
839  TString choice = KVBase::GetListOfPlugins("KVIDGraph");
840  // open dialog to choose ID grid class
841  Bool_t ok_pressed = kFALSE;
842  TString id_grid_class;
843  new KVDropDownDialog(this, "Choose class for new grid:",
844  choice.Data(), default_class.Data(), &id_grid_class, &ok_pressed);
845  if (!ok_pressed) {
846  Info("NewGrid", "No ID grid class chosen. Grid creation cancelled.");
847  return;
848  }
849  gIDGridManager->Disconnect("Modified()", this, "UpdateListOfGrids()");
850  KVIDGraph* new_gr = KVIDGraph::MakeIDGraph(id_grid_class.Data());
851  if (telescopes->GetEntries()) new_gr->AddIDTelescopes(telescopes);
852  UpdateTabs();
853  gIDGridManager->Connect("Modified()", "KVIDGridManagerGUI", this, "UpdateListOfGrids()");
854  delete telescopes;
855 }
856 
857 
858 
864 
866 {
867  //merge 2 grids
868  //KVIDGraph *g1 = (KVIDGraph *) fSelectedEntries->At(1);
869  //KVIDGraph *g2 = (KVIDGraph *) fSelectedEntries->First();
870  //new KVMergeGridsDialog(g1, g2, fClient->GetDefaultRoot(), this, 10, 10);
871 }
872 
873 
874 
879 
881 {
882  // Opens dialog to choose filename in which to save grids.
883  // If selection=0 (default), all grids are saved
884  // If selection!=0 only grids in list are saved
885 
886  static TString dir(".");
887  const char* filetypes[] = {
888  "ID Grid files", "*.dat",
889  "All files", "*",
890  0, 0
891  };
892  TGFileInfo fi;
893  fi.fFileTypes = filetypes;
894  fi.fIniDir = StrDup(dir);
895  if (fFileName != "") fi.fFilename = StrDup(fFileName);
896  new TGFileDialog(fClient->GetDefaultRoot(), this, kFDSave, &fi);
897  if (fi.fFilename) {
898  //if no ".xxx" ending given, we add ".dat"
899  TString filenam(fi.fFilename);
900  if (!filenam.Contains('.'))
901  filenam += ".dat";
902  Int_t n_saved = gIDGridManager->WriteAsciiFile(filenam.Data(), selection);
903  if (n_saved) {
904  //wrote file no problem
905  SetStatus(Form("Saved %d grids in file %s", n_saved, filenam.Data()));
906  //set file name for Save
907  fFileName = gSystem->BaseName(filenam);
908  UpdateListOfGrids();
909  }
910  else {
911  new TGMsgBox(fClient->GetDefaultRoot(), this, "ID Grid Manager",
912  Form("Could not write file %s", filenam.Data()), 0,
913  kMBOk);
914  }
915  }
916  dir = fi.fIniDir;
917 }
918 
919 
920 
924 
926 {
927  // create a tab for each type of ID telescope
928  // put a list box for ID grid names on each tab
929 
930  KVString labels;
931  if (gIDGridManager->GetGrids()->GetSize()) gIDGridManager->GetListOfIDTelescopeLabels(labels);
932  if (labels == "") {
933  // no known idtelescopes referenced by grids (maybe we don't have a KVMultiDetArray?)
934  // make 1 tab "Grids" and put them all in
935  auto grids = gIDGridManager->GetGrids();
936  create_and_fill_id_grid_list("Grids", grids);
937  return;
938  }
939  //loop over labels
940  labels.Begin(",");
941  while (! labels.End()) {
942  KVString lab = labels.Next();
943  std::unique_ptr<KVSeqCollection> grids{gIDGridManager->GetGridsForIDTelescope(lab)};
944  create_and_fill_id_grid_list(lab, grids.get());
945  }
946 
947 }
948 
949 
950 
953 
955 {
956  //called when a new tab is selected
957 
958  TGCompositeFrame* cf = fGridListTabs->GetCurrentContainer();
959  if (!cf) return;//there are no tabs
960  TGFrameElement* el = (TGFrameElement*)cf->GetList()->At(0);
961  fIDGridList = (KVListView*)el->fFrame;
962  fIDGridList->SelectionChanged();
963 }
964 
965 
966 
968 
969 void KVIDGridManagerGUI::create_and_fill_id_grid_list(const KVString& tab_label, KVSeqCollection* grid_list)
970 {
971  TGCompositeFrame* cf = fGridListTabs->AddTab(tab_label);
972  cf->ChangeOptions(kVerticalFrame);
973  fIDGridList = new KVListView(KVIDGraph::Class(), cf, 600, 400);
974  fIDGridList->SetDataColumns(11);
975  fIDGridList->SetDataColumn(0, "Name", "", kTextLeft);
976  fIDGridList->SetDataColumn(2, "VarX", "", kTextLeft);
977  fIDGridList->SetDataColumn(1, "VarY", "", kTextLeft);
978  fIDGridList->SetDataColumn(3, "ID Telescopes", "GetNamesOfIDTelescopes", kTextLeft);
979  fIDGridList->SetDataColumn(4, "RunList", "", kTextLeft);
980  fIDGridList->SetDataColumn(5, "Identify Z and A?", "HasMassIDCapability", kTextCenterX);
981  fIDGridList->GetDataColumn(5)->SetIsBoolean();
982  fIDGridList->SetDataColumn(6, "# Ident.", "GetNumberOfIdentifiers", kTextRight);
983  fIDGridList->SetDataColumn(7, "# Cuts", "GetNumberOfCuts", kTextRight);
984  fIDGridList->SetDataColumn(8, "# Infos", "GetNumberOfInfos", kTextRight);
985  fIDGridList->SetDataColumn(9, "Last modified", "GetTimestamp", kTextCenterX);
986  fIDGridList->SetDataColumn(10, "Saved", "GetFileWrite", kTextCenterX);
987  fIDGridList->ActivateSortButtons();
988  fIDGridList->Connect("SelectionChanged()", "KVIDGridManagerGUI", this,
989  "SelectionChanged()");
990  fIDGridList->SetDoubleClickAction("KVIDGridManagerGUI", this, "StartEditor(TObject*)");
991  cf->AddFrame(fIDGridList, new TGLayoutHints(kLHintsLeft | kLHintsTop |
992  kLHintsExpandX | kLHintsExpandY, 30,
993  10, 10, 10));
994  if(grid_list)
995  fIDGridList->Display(grid_list);
996 }
997 
998 
999 
1004 
1006 {
1007  // create a tab for each type of ID telescope
1008  // put a list box for ID grid names on each tab
1009  // cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : starting..." << endl;
1010 
1011  KVString labels("");
1012  if (gIDGridManager->GetGrids()->GetSize()) gIDGridManager->GetListOfIDTelescopeLabels(labels);
1013  else {
1014  // there are no grids in the grid manager
1015  RemoveEmptyTabs();
1016  create_and_fill_id_grid_list("Grids");
1017  fGridListTabs->MapSubwindows();
1018  fGridListTabs->Layout();
1019  Int_t ntabs = fGridListTabs->GetCurrent();
1020  TabSelect(ntabs);
1021  return;
1022  }
1023  if (labels == "") {
1024  // no known idtelescopes referenced by grids (maybe we don't have a KVMultiDetArray?)
1025  // update "Grids" tab
1026  TGCompositeFrame* cf = fGridListTabs->GetTabContainer("Grids");
1027  if (!cf) {
1028  cout << "cf = 0x0 : label=Grids tab name=" <<
1029  fGridListTabs->GetTabTab("Grids")->GetText()->GetString() << endl;
1030  }
1031  else {
1032  TGFrameElement* el = (TGFrameElement*)cf->GetList()->At(0);
1033  fIDGridList = (KVListView*)el->fFrame;
1034  auto grids = gIDGridManager->GetGrids();
1035  fIDGridList->Display(grids);
1036  }
1037  //make sure we are on the right tab
1038  Int_t ntabs = fGridListTabs->GetCurrent();
1039  TabSelect(ntabs);
1040  return;
1041  }
1042  //add any missing labels, update existing ones
1043  labels.Begin(",");
1044  while (! labels.End()) {
1045  KVString lab = labels.Next();
1046  if (!fGridListTabs->GetTabContainer(lab)) { // new tab
1047  std::unique_ptr<KVSeqCollection> grids{gIDGridManager->GetGridsForIDTelescope(lab)};
1048  create_and_fill_id_grid_list(lab,grids.get());
1049  fGridListTabs->MapSubwindows();
1050  fGridListTabs->Layout();
1051  fGridListTabs->SetTab(fGridListTabs->GetNumberOfTabs() - 1, kTRUE);
1052  }
1053  else { //existing tab
1054  //cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : existing tab '" << lab.Data() << "'..." << endl;
1055  TGCompositeFrame* cf = fGridListTabs->GetTabContainer(lab.Data());
1056  if (!cf) {
1057  cout << "cf = 0x0 : label=" << lab.Data() << " tab name=" <<
1058  fGridListTabs->GetTabTab(lab.Data())->GetText()->GetString() << endl;
1059  }
1060  else {
1061  //cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : recup tab '" << cf->GetName() << "'..." << endl;
1062  TGFrameElement* el = (TGFrameElement*)cf->GetList()->At(0);
1063  //cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : recup element '" << el->GetName() << "'..." << endl;
1064  fIDGridList = (KVListView*)el->fFrame;
1065  //cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : recup view list '" << fIDGridList->GetName() << "'..." << endl;
1066  auto grids = gIDGridManager->GetGridsForIDTelescope(lab);
1067  //cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : recup list de telescope'" << grids->GetName() << "'..." << endl;
1068  //grids->ls();
1069  fIDGridList->Display(grids);
1070  //cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : display list of grids in the viewerlist..." << endl;
1071 
1072  if (grids) delete grids;
1073  // cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : deleting the list..." << endl;
1074  }
1075  }
1076  }
1077  //now check that none of the remaining tabs are empty & should be removed
1078  RemoveEmptyTabs();
1079  // cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : empty tabs removed !" << endl;
1080  //make sure we are on the right tab
1081  Int_t ntabs = fGridListTabs->GetCurrent();
1082  TabSelect(ntabs);
1083  // cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : current tab selected !" << endl;
1084 }
1085 
1086 
1087 
1090 
1092 {
1093  // Recursively remove any empty tabs
1094 
1095  Int_t ntabs = fGridListTabs->GetNumberOfTabs();
1096  Bool_t recursive = kFALSE;
1097  for (Int_t itab = 0; itab < ntabs; itab++) {
1098 
1099  //get name of tab
1100  KVString lab = fGridListTabs->GetTabTab(itab)->GetString();
1101  //get grids for this tab (if any)
1102  auto grids = gIDGridManager->GetGridsForIDTelescope(lab);
1103  Int_t ngrids = grids->GetEntries();
1104  delete grids;
1105  if (!ngrids) {
1106  //empty tab! remove it!
1107  //delete the KVListView
1108  TGCompositeFrame* cf = fGridListTabs->GetTabContainer(itab);
1109  TGFrameElement* el = (TGFrameElement*)cf->GetList()->At(0);
1110  KVListView* lv = (KVListView*)el->fFrame;
1111  delete lv;
1112  //remove tab
1113  fGridListTabs->RemoveTab(itab, kFALSE);
1114  recursive = kTRUE; // call recursively
1115  break;//stop loop - tab numbers have changed
1116  }
1117  }
1118  if (recursive) RemoveEmptyTabs();
1119  fGridListTabs->MapSubwindows();
1120  fGridListTabs->Layout();
1121 }
1122 
1123 
1124 
1128 
1130 {
1131  // called when a previously selected grid is modified
1132  // updates lists of lines
1133 
1134  if (!fLastSelectedGrid) return;
1135 
1136  KVList* ids = fLastSelectedGrid->GetIdentifiers();
1137  // sort lines in order of increasing Z
1138  ids->Sort();
1139  fIDLineList->Display(ids);
1140 // KVSeqCollection* cutlines = fSelectedGrid->GetCuts()->GetSubListWithClass("KVIDCutLine");
1141  fCUTList->Display(fSelectedGrid->GetCuts());
1142 // fCUTLineList->Display(cutlines);
1143 // delete cutlines;
1144 // cutlines = fSelectedGrid->GetCuts()->GetSubListWithClass("KVIDCutContour");
1145  fCUTInfoList->Display(fSelectedGrid->GetInfos());
1146 // fCUTContourList->Display(cutlines);
1147 // delete cutlines;
1148 }
1149 
1150 
1151 
1158 
1160 {
1161  // Called when a grid is selected in list of grids
1162  //
1163  // We fill list of all lines in grid
1164  // * if only one grid is selected, we display its lines in the line list
1165  // * if more than one grid is selected, we clear the line list
1166 
1167  if (GetNSelected() == 1 && fSelectedGrid) {
1168  KVList* ids = fSelectedGrid->GetIdentifiers();
1169  // sort lines in order of increasing Z
1170  ids->Sort();
1171  fIDLineList->Display(ids);
1172  fCUTList->Display(fSelectedGrid->GetCuts());
1173  fCUTInfoList->Display(fSelectedGrid->GetInfos());
1174  if (fLastSelectedGrid) {
1175  fLastSelectedGrid->Disconnect("Modified()", this, "UpdateListOfLines()");
1176  }
1177  fSelectedGrid->Connect("Modified()", "KVIDGridManagerGUI", this, "UpdateListOfLines()");
1178  fLastSelectedGrid = fSelectedGrid;
1179  }
1180  else {
1181  fIDLineList->RemoveAll();
1182  fCUTList->RemoveAll();
1183  fCUTInfoList->RemoveAll();
1184  if (fLastSelectedGrid) {
1185  fLastSelectedGrid->Disconnect("Modified()", this, "UpdateListOfLines()");
1186  fLastSelectedGrid = 0;
1187  }
1188  }
1189 }
1190 
1191 
1192 
1195 
1197 {
1198  // disable all buttons
1199  for (int i = 0; i < fNbButtons; i++) fTBbuttons[i]->SetEnabled(kFALSE);
1200  // enable 'open' & 'quit' & 'new grid"
1201  fTBOpen->SetEnabled();
1202  fTBRefresh->SetEnabled();
1203 // fTBStartEditor->SetEnabled();
1204  fTBNewG->SetEnabled();
1205  fTBOpenRoot->SetEnabled();
1206  // enable 'save' if there are grids
1207  if (gIDGridManager->GetGrids()->GetEntries()) fTBSave->SetEnabled();
1208 
1209  if (!GetNSelected()) return; // no grids selected
1210 
1211  //enable delete selected grid(s)
1212  fTBDelG->SetEnabled();
1213  // enable set id telescopes
1214  fTBSetIDG->SetEnabled();
1215 
1216  if (GetNSelected() == 1) {
1217  // only one grid selected
1218  fTBStartEditor->SetEnabled();
1219  fTBCopyG->SetEnabled();
1220  }
1221 }
1222 
1223 
1224 
1236 
1238 {
1239  // GUI method to draw a new identifier and add it to graph.
1240  // A dialog box with drop-down list pops up for the user to choose the class of the
1241  // new identifier, unless only one choice is possible, in which case it is used automatically.
1242  // For each KVIDGraph-derived class, the list of possible identifier classes and the
1243  // default class are define in .kvrootrc by the variables:
1244  //
1245  // [class_name].IDClass: [id class 1]
1246  // +[class_name].IDClass: [id class 2]
1247  // + ...
1248  // [class_name].DefaultIDClass: [id class]
1249 
1250  if (!fSelectedGrid || GetNSelected() != 1) return;
1251  TString resname;
1252  resname.Form("%s.IDClass", fSelectedGrid->ClassName());
1253  TString cut_choices = gEnv->GetValue(resname.Data(), "");
1254  resname.Form("%s.DefaultIDClass", fSelectedGrid->ClassName());
1255  TString cut_default = gEnv->GetValue(resname.Data(), "");
1256  TString cut_class;
1257  Bool_t okpressed;
1258  if (cut_choices.Contains(" ")) {
1259  new KVDropDownDialog(this,
1260  "Choose class of new identifier :",
1261  cut_choices.Data(),
1262  cut_default.Data(),
1263  &cut_class,
1264  &okpressed);
1265  if (!okpressed) return;
1266  }
1267  else
1268  cut_class = cut_choices;
1269  SetStatus(Form("Draw ID line (%s) in current pad", cut_class.Data()));
1270  fSelectedGrid->DrawAndAdd("ID", cut_class.Data());
1271  fTBNewIDL->SetDown(kFALSE, kFALSE);
1272  SetStatus();
1273 }
1274 
1275 
1276 
1288 
1290 {
1291  // GUI method to draw a new cut and add it to graph.
1292  // A dialog box with drop-down list pops up for the user to choose the class of the
1293  // new cut, unless only one choice is possible, in which case it is used automatically.
1294  // For each KVIDGraph-derived class, the list of possible cut classes and the
1295  // default class are define in .kvrootrc by the variables:
1296  //
1297  // [class_name].CutClass: [cut class 1]
1298  // +[class_name].CutClass: [cut class 2]
1299  // + ...
1300  // [class_name].DefaultCutClass: [cut class]
1301 
1302  if (!fSelectedGrid || GetNSelected() != 1) return;
1303  TString resname;
1304  resname.Form("%s.CutClass", fSelectedGrid->ClassName());
1305  TString cut_choices = gEnv->GetValue(resname.Data(), "");
1306  resname.Form("%s.DefaultCutClass", fSelectedGrid->ClassName());
1307  TString cut_default = gEnv->GetValue(resname.Data(), "");
1308  TString cut_class;
1309  TString cut_types = cut_choices;
1310  cut_types.ReplaceAll("KVIDCut", "");
1311  Bool_t okpressed;
1312  if (cut_choices.Contains(" ")) {
1313  new KVDropDownDialog(this,
1314  "Choose class of new cut :",
1315  cut_types.Data(),
1316  cut_default.Data(),
1317  &cut_class,
1318  &okpressed);
1319  if (!okpressed) return;
1320  }
1321  else
1322  cut_class = cut_types;
1323  SetStatus(Form("Draw cut %s in current pad", cut_class.Data()));
1324  cut_class.Prepend("KVIDCut");
1325  fSelectedGrid->DrawAndAdd("CUT", cut_class.Data());
1326  fTBNewCut->SetDown(kFALSE, kFALSE);
1327  SetStatus();
1328 }
1329 
1330 
1331 
1332 
1336 
1338 {
1339  // test the identification with selected grid
1340  // we search in current pad for the data histogram
1341 
1342  SetStatus("");
1343  if (GetNSelected() != 1) return;
1344  if (!fSelectedGrid) return;
1345  // look for data histogram in current pad
1346  TH2* histo = 0;
1347  if (gPad) {
1348  TIter next(gPad->GetListOfPrimitives());
1349  TObject* o;
1350  while ((o = next())) {
1351  if (o->InheritsFrom("TH2")) {
1352  histo = (TH2*)o;
1353  break;
1354  }
1355  }
1356  }
1357  if (!histo) {
1358  SetStatus("No TH2 found in current pad. Select pad containing 2D histo with data to identify.");
1359  return;
1360  }
1361  else {
1362  SetStatus(Form("Test identification of data in current pad %s.", histo->GetName()));
1363  }
1364  new KVTestIDGridDialog(fClient->GetDefaultRoot(), this, 10, 10, fSelectedGrid, histo);
1365  SetStatus("");
1366 }
1367 
1368 
1369 
1373 
1375 {
1376  // test the identification with selected grid
1377  // we search in current pad for the data histogram
1378  SetStatus("");
1379  if (GetNSelected() != 1) return;
1380  if (!fSelectedGrid) return;
1381  // look for data histogram in current pad
1382  TH2* histo = 0;
1383  if (gPad) {
1384  TIter next(gPad->GetListOfPrimitives());
1385  TObject* o;
1386  while ((o = next())) {
1387  if (o->InheritsFrom("TH2")) {
1388  histo = (TH2*)o;
1389  break;
1390  }
1391  }
1392  }
1393  if (!histo) {
1394  SetStatus("No TH2 found in current pad. Select pad containing 2D histo with data to identify.");
1395  return;
1396  }
1397  else {
1398  SetStatus(Form("Test identification of data in current pad %s.", histo->GetName()));
1399  }
1400  TFile* tmpfiles = TestIdentificationWithTree(fSelectedGrid, histo->GetName());
1401  if (!tmpfiles) {
1402  SetStatus("There was a problem with the test ???");
1403  return;
1404  }
1405  new TCanvas;
1406  TH2* id = (TH2*)tmpfiles->Get("idcode_map");
1407  id->SetStats(kFALSE);
1408  id->Draw("zcol");
1409  TTree* t = (TTree*)tmpfiles->Get("tree_idresults");
1410  t->StartViewer();
1411  SetStatus("");
1412 }
1413 
1414 
1415 
1416 
1429 
1430 TFile* KVIDGridManagerGUI::TestIdentificationWithTree(KVIDGraph* gr, const Char_t* name_of_data_histo)
1431 {
1432  //This method allows to test the identification capabilities of the grid using data in a TH2F.
1433  //We assume that 'data' contains an identification map, whose 'x' and 'y' coordinates correspond
1434  //to this grid. Then we loop over every bin of the histogram, perform the identification (if
1435  //IsIdentifiable() returns kTRUE) and fill the two histograms with the resulting identification
1436  //and its dependence on the 'residual energy' i.e. the 'x'-coordinate of the 'data' histogram,
1437  //each identification weighted by the contents of the original data bin.
1438  //
1439  //The 'identification" we represent is the result of the KVReconstructedNucleus::GetPID() method.
1440  //For particles identified in Z only, this is the "real Z".
1441  //For particles with A & Z identification, this is Z + 0.1*(A - 2*Z)
1442 
1443  //Initialize the grid: calculate line widths etc.
1444  gr->Initialize();
1445 
1446  TH2F* data = (TH2F*)gROOT->FindObject(name_of_data_histo);
1447  if (!data) {
1448  printf(" KVIDGraph::TestIdentificationWithTree l histo %s n existe pas\n", name_of_data_histo);
1449  return 0;
1450  }
1451 
1452 
1455 
1456  // store current memory directory
1457  TDirectory* CWD = gDirectory;
1458 
1459  TTree* tid = 0;
1460  if ((tid = (TTree*)gROOT->FindObject("tree_idresults"))) {
1461  printf(" KVIDGraph::TestIdentificationWithTree effacemenent de l arbre existant\n");
1462  delete tid;
1463  }
1464  // create temporary file for tree
1465  TString fn("IDtestTree.root");
1467  TFile* tmpfile = new TFile(fn.Data(), "recreate");
1468  TH2F* idmap = (TH2F*)data->Clone("idcode_map");
1469  idmap->Reset();
1470  tid = new TTree("tree_idresults", "pid");
1471  Float_t br_xxx, br_yyy, br_stat, br_pid;
1472  Int_t br_idcode, br_isid;
1473 
1474  tid->Branch("X", &br_xxx, "br_xxx/F");
1475  tid->Branch("Y", &br_yyy, "br_yyy/F");
1476  tid->Branch("Stat", &br_stat, "br_stat/F");
1477 
1478  tid->Branch("PID", &br_pid, "br_pid/F");
1479  tid->Branch("IDcode", &br_idcode, "br_idcode/I");
1480  tid->Branch("IsIdentified", &br_isid, "br_isid/I");
1481 
1482  Int_t tot_events = (Int_t) data->GetSum();
1483  Int_t events_read = 0;
1484  Float_t percent = 0., cumul = 10.;
1485 
1486  //loop over data in histo
1487  for (int i = 1; i <= data->GetNbinsX(); i++) {
1488  for (int j = 1; j <= data->GetNbinsY(); j++) {
1489 
1490  Stat_t poids = data->GetBinContent(i, j);
1491  if (poids == 0)
1492  continue;
1493  br_stat = Float_t(poids);
1494 
1495  Axis_t x0 = data->GetXaxis()->GetBinCenter(i);
1496  Axis_t y0 = data->GetYaxis()->GetBinCenter(j);
1497  Axis_t wx = data->GetXaxis()->GetBinWidth(i);
1498  Axis_t wy = data->GetYaxis()->GetBinWidth(j);
1499 
1500  br_xxx = Float_t(x0);
1501  br_yyy = Float_t(y0);
1502  //If bin content ('poids') is <=20, we perform the identification 'poids' times, each time with
1503  //randomly-drawn x and y coordinates inside this bin
1504  //If 'poids'>20, we perform the identification 20 times and we fill the histograms with
1505  //a weight poids/20
1506  Double_t x, y;
1507  Int_t kmax = (Int_t) TMath::Min(20., poids);
1508  //Double_t weight = (kmax == 20 ? poids / 20. : 1.);
1509 
1510  for (int k = 0; k < kmax; k++) {
1511 
1512  x = gRandom->Uniform(x0 - .5 * wx, x0 + .5 * wx);
1513  y = gRandom->Uniform(y0 - .5 * wy, y0 + .5 * wy);
1514  if (gr->IsIdentifiable(x, y)) {
1515  br_isid = 1;
1516  gr->Identify(x, y, idr);
1517  nuc.SetIdentification(idr, nullptr);
1518  br_pid = nuc.GetPID();
1519  br_idcode = gr->GetQualityCode();
1520  idmap->SetBinContent(i, j, br_idcode);
1521  }
1522  else {
1523  br_isid = 0;
1524  br_pid = -1;
1525  br_idcode = -1;
1526  idmap->SetBinContent(i, j, br_idcode);
1527  }
1528  tid->Fill();
1529  }
1530  events_read += (Int_t) poids;
1531  percent = (1. * events_read / tot_events) * 100.;
1532  gr->Increment((Float_t) events_read); //sends signal to GUI progress bar
1533  if (percent >= cumul) {
1534  cout << (Int_t) percent << "\% processed" << endl;
1535  cumul += 10;
1536  }
1537  //gSystem->ProcessEvents();
1538  }
1539  }
1540 
1541  delete idr;
1542  CWD->cd();
1543  return tmpfile;
1544 }
1545 
1546 
1547 
1549 
1551 {
1552  SetStatus("");
1553  if (GetNSelected() != 1) return;
1554  if (!fSelectedGrid) return;
1555  SetStatus(Form("Fitting grid %s", fSelectedGrid->GetName()));
1557  fitter->SetGrid(fSelectedGrid);
1558  fitter->SetPad(fSelectedGrid->GetPad());
1559  TMethod* m = fitter->IsA()->GetMethodAny("FitPanel");
1560  TContextMenu* cm = new TContextMenu("FitPanel", "Context menu for KVVirtualIDFitter::FitPanel");
1561  cm->Action(fitter, m);
1562  delete cm;
1563 }
1564 
1565 
int Int_t
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
kMBIconQuestion
kTextCenterX
kTextLeft
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:1251
static void GetTempFileName(TString &base)
Definition: KVBase.cpp:850
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:31
void SetRunList(const char *runlist)
Definition: KVIDGraph.h:218
void Clear(Option_t *opt="") override
Definition: KVIDGraph.cpp:205
void SetVarY(const char *v) override
Definition: KVIDGraph.h:642
void ClearListOfIDTelescopes()
Definition: KVIDGraph.h:485
void SetVarX(const char *v) override
Definition: KVIDGraph.h:638
void AddIDTelescopes(const TList *)
Associate this graph with all ID telescopes in list.
Definition: KVIDGraph.cpp:1600
static KVIDGraph * MakeIDGraph(const Char_t *)
Definition: KVIDGraph.cpp:1620
void SetIDTelescopes(const TString &)
Set value of "IDTelescopes" parameter with comma-separated list of ID telescope names.
Definition: KVIDGraph.cpp:1676
virtual void SetOnlyZId(Bool_t yes=kTRUE)
Definition: KVIDGraph.cpp:1580
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()
propose to set IDTelescopes parameter using grid names
void ActivateToolbarButtons()
disable all buttons
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)
Bool_t ReadAsciiFile(const Char_t *filename)
const KVSeqCollection * GetGrids() const
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:147
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
KVIDTelescope * GetIDTelescope(const Char_t *name) const
Return pointer to DeltaE-E ID Telescope with "name".
Nuclei reconstructed from data measured by a detector array .
void SetIdentification(KVIdentificationResult *, KVIDTelescope *)
virtual Float_t GetPID() const
KaliVeda extensions to ROOT collection classes.
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 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
TList * fFileNamesList
char * fFilename
const char ** fFileTypes
char * fIniDir
Bool_t fMultipleSelection
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
const TString & GetString() const
virtual Bool_t InheritsFrom(const char *classname) const
virtual Double_t Uniform(Double_t x1, Double_t x2)
const char * Data() const
TString & Append(char c, Ssiz_t rep=1)
Bool_t IsNull() 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)