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