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.fFilename) {
548  int ngri = gIDGridManager->GetGrids()->GetEntries();
549  bool ok = gMultiDetArray ? gMultiDetArray->ReadGridsFromAsciiFile(fi.fFilename)
550  : gIDGridManager->ReadAsciiFile(fi.fFilename);
551  if (ok) {
552  UpdateListOfGrids();
553  //read file ok no problem.
554  int ngriread = gIDGridManager->GetGrids()->GetEntries() - ngri;
555  SetStatus(Form("Read %d grids from file %s", ngriread, fi.fFilename));
556  //set filename for Save
557  fFileName = gSystem->BaseName(fi.fFilename);
558  }
559  else {
560  new TGMsgBox(fClient->GetDefaultRoot(), this, "ID Grid Manager",
561  Form("Could not read file %s", fi.fFilename),
562  0, kMBOk);
563  }
564  }
565  dir = fi.fIniDir;
566 }
567 
568 
569 
575 
577 {
578  //remove all existing entries, then fill list from gIDGridManager
579  //we update the current pad, in case the displayed grid no longer exists
580  //grid buttons are disabled, as any selected grid is deselected
581  // cout << "DEBUG: KVIDGridManagerGUI::UpdateListOfGrids(): starting..." << endl;
582  UpdateTabs();
583  // cout << "DEBUG: KVIDGridManagerGUI::UpdateListOfGrids(): tabs has been updated !" << endl;
584  //update all canvases
585 // TSeqCollection* Clist = gROOT->GetListOfCanvases();
586 // if (Clist && Clist->GetEntries()) {
587 // Clist->R__FOR_EACH(TCanvas, Modified)();
588 // Clist->R__FOR_EACH(TCanvas, Update)();
589 // }
590  // cout << "DEBUG: KVIDGridManagerGUI::UpdateListOfGrids(): canvas has been updated !" << endl;
591 }
592 
593 
594 
602 
604 {
605  //called any time the selection of grids changes
606  //each time, we update:
607  //fSelectedEntries : the list of all selected entries
608  //GetNSelected() : the number of selected entries
609  //fSelectedGrid : the last selected grid (=the only grid selected if GeTNSelected==1)
610 
611  //get number of selected items
612  fSelectedEntries = fIDGridList->GetSelectedObjects();
613  fSelectedGrid = (KVIDGraph*)fIDGridList->GetLastSelectedObject();
614  if (!GetNSelected())fSelectedGrid = 0x0;
615  ShowListOfLines();
616  //(de)activate toolbar buttons
617  ActivateToolbarButtons();
618  if (!GetNSelected()) SetStatus();
619  else if (GetNSelected() == 1) SetStatus(Form("Selected grid %s (%s)", fSelectedGrid->GetName(), fSelectedGrid->ClassName()));
620  else SetStatus(Form("Selected %d grids, last selected grid %s (%s)", GetNSelected(), fSelectedGrid->GetName(), fSelectedGrid->ClassName()));
621 }
622 
623 
624 
625 
626 
632 
634 {
635  //delete the current selected grid, or all currently selected grids if there are more than one
636  //
637  //grids must be removed from the GUI before deleting, as objects given to KVListView::Display()
638  //must remain valid as long as they are displayed
639 
640  if (!GetNSelected()) return;
641 
642  fIDGridList->RemoveAll();
643 
644  TIter next(&fSelectedEntries, kIterBackward);
645  KVIDGraph* entry;
646  while ((entry = (KVIDGraph*) next()))
647  {
648  if (fLastSelectedGrid == entry) fLastSelectedGrid = 0;
649  gIDGridManager->DeleteGrid(entry, kFALSE); //no update
650  }
651  fSelectedEntries.Clear();
652  fSelectedGrid = 0;
653  UpdateListOfGrids();
654 }
655 
656 
657 
660 
662 {
663  //delete the all grids in currently selected tab
664 
665  TIter next(GetAllGridsInTab(), kIterBackward);
666  KVIDGraph* entry;
667  while ((entry = (KVIDGraph*) next())) {
668  gIDGridManager->DeleteGrid(entry, kFALSE); //no update
669  }
670  fSelectedEntries.Clear();
671  fSelectedGrid = 0;
672  UpdateListOfGrids();
673 }
674 
675 
676 
679 
681 {
682  // propose to set IDTelescopes parameter using grid names
683  Int_t ret_val;
684  new TGMsgBox(fClient->GetDefaultRoot(), this, "ID Grid Manager",
685  "Set IDTelescope for selected grid(s) using grid name ?",
686  kMBIconQuestion, kMBOk | kMBCancel, &ret_val);
687  if (ret_val & kMBOk)
688  {
689  for(auto tidg : fSelectedEntries)
690  {
691  auto idg = dynamic_cast<KVIDGraph*>(tidg);
693  Info("SetIDTelescopes", "Setting IDTelescope for %s...", idg->GetName());
694  if(gMultiDetArray)
695  idg->AddIDTelescope(gMultiDetArray->GetIDTelescope(idg->GetName()));
696  else
697  idg->AddIDTelescope(idg->GetName());
698  }
699  UpdateListOfGrids();
700  return;
701  }
702  TString idtels; bool ok_pressed=false;
703  new KVInputDialog(this, "Enter names of IDTelescopes to use for grid(s):",
704  &idtels, &ok_pressed, "Separate the names with commas!");
705  if(ok_pressed)
706  {
707  for(auto tidg : fSelectedEntries)
708  {
709  auto idg = dynamic_cast<KVIDGraph*>(tidg);
710  idg->SetIDTelescopes(idtels);
711  }
712  UpdateListOfGrids();
713  return;
714  }
715 
716 // TList telescopes;
717 // telescopes.AddAll(fSelectedGrid->GetListOfIDTelescopes());
718 // new KVIDGUITelescopeChooserDialog(gMultiDetArray, &telescopes, &cancel,
719 // fClient->GetDefaultRoot(), this, kTRUE);
720 // if (cancel || !telescopes.GetEntries()) return;
721 // fSelectedGrid->ClearListOfIDTelescopes();
722 // fSelectedGrid->AddIDTelescopes(&telescopes);
723 }
724 
725 
726 
729 
731 {
732  //deletes all lines in currently selected grid(s)
733 
734  if (GetNSelected() == 1)
735  fSelectedGrid->Clear();
736  else if (GetNSelected() > 1) {
737  //multiselection
738  TIter next(&fSelectedEntries);
739  KVIDGraph* grid;
740  while ((grid = (KVIDGraph*) next())) {
741  grid->Clear();
742  }
743  }
744  //update all canvases
745  TSeqCollection* Clist = gROOT->GetListOfCanvases();
746  if (Clist->GetSize() > 0) {
747  Clist->R__FOR_EACH(TCanvas, Modified)();
748  Clist->R__FOR_EACH(TCanvas, Update)();
749  }
750 }
751 
752 
753 
755 
757 {
758  if (!fSelectedGrid) return;
759  gIDGridManager->Disconnect("Modified()", this, "UpdateListOfGrids()");
760  KVIDGraph* new_gr = KVIDGraph::MakeIDGraph(fSelectedGrid->ClassName());
761  fSelectedGrid->Copy(*new_gr);
762  new_gr->AddIDTelescopes(fSelectedGrid->GetListOfIDTelescopes());
763  new_gr->SetRunList("");
764  gIDGridManager->SortGrids();
765  UpdateTabs();
766  gIDGridManager->Connect("Modified()", "KVIDGridManagerGUI", this, "UpdateListOfGrids()");
767  fIDGridList->Sort(0);
768  fIDGridList->Sort(0);
769  return;
770 }
771 
772 
773 
780 
782 {
783  // Create a new identification grid.
784  // First we ask the user to select the identification telescope(s)
785  // for which this grid will be used.
786  // For a given type of ID telescope, several types of grid may be
787  // applicable. If so, we ask the user to choose one.
788 
789  Info("NewGrid", "There are %d grids in the manager", gIDGridManager->GetGrids()->GetSize());
790  TString default_class = "KVIDZAGrid";
791  TList* telescopes = new TList;
792  if (gMultiDetArray) {
793  Bool_t cancel;
794  new KVIDGUITelescopeChooserDialog(gMultiDetArray, telescopes, &cancel,
795  fClient->GetDefaultRoot(), this);
796  if (cancel || !telescopes->At(0)) {
797  Info("NewGrid", "No ID telescopes chosen. Grid creation cancelled.");
798  return;
799  }
800  // get default ID grid class of first ID telescope
801  default_class = ((KVIDTelescope*)telescopes->At(0))->GetDefaultIDGridClass();
802  }
803  // get list of possible choices of grid class = list of all plugin classes
804  // defined for KVIDGraph
805  TString choice = KVBase::GetListOfPlugins("KVIDGraph");
806  // open dialog to choose ID grid class
807  Bool_t ok_pressed = kFALSE;
808  TString id_grid_class;
809  new KVDropDownDialog(this, "Choose class for new grid:",
810  choice.Data(), default_class.Data(), &id_grid_class, &ok_pressed);
811  if (!ok_pressed) {
812  Info("NewGrid", "No ID grid class chosen. Grid creation cancelled.");
813  return;
814  }
815  gIDGridManager->Disconnect("Modified()", this, "UpdateListOfGrids()");
816  KVIDGraph* new_gr = KVIDGraph::MakeIDGraph(id_grid_class.Data());
817  if (telescopes->GetEntries()) new_gr->AddIDTelescopes(telescopes);
818  UpdateTabs();
819  gIDGridManager->Connect("Modified()", "KVIDGridManagerGUI", this, "UpdateListOfGrids()");
820  delete telescopes;
821 }
822 
823 
824 
830 
832 {
833  //merge 2 grids
834  //KVIDGraph *g1 = (KVIDGraph *) fSelectedEntries->At(1);
835  //KVIDGraph *g2 = (KVIDGraph *) fSelectedEntries->First();
836  //new KVMergeGridsDialog(g1, g2, fClient->GetDefaultRoot(), this, 10, 10);
837 }
838 
839 
840 
845 
847 {
848  // Opens dialog to choose filename in which to save grids.
849  // If selection=0 (default), all grids are saved
850  // If selection!=0 only grids in list are saved
851 
852  static TString dir(".");
853  const char* filetypes[] = {
854  "ID Grid files", "*.dat",
855  "All files", "*",
856  0, 0
857  };
858  TGFileInfo fi;
859  fi.fFileTypes = filetypes;
860  fi.fIniDir = StrDup(dir);
861  if (fFileName != "") fi.fFilename = StrDup(fFileName);
862  new TGFileDialog(fClient->GetDefaultRoot(), this, kFDSave, &fi);
863  if (fi.fFilename) {
864  //if no ".xxx" ending given, we add ".dat"
865  TString filenam(fi.fFilename);
866  if (!filenam.Contains('.'))
867  filenam += ".dat";
868  Int_t n_saved = gIDGridManager->WriteAsciiFile(filenam.Data(), selection);
869  if (n_saved) {
870  //wrote file no problem
871  SetStatus(Form("Saved %d grids in file %s", n_saved, filenam.Data()));
872  //set file name for Save
873  fFileName = gSystem->BaseName(filenam);
874  UpdateListOfGrids();
875  }
876  else {
877  new TGMsgBox(fClient->GetDefaultRoot(), this, "ID Grid Manager",
878  Form("Could not write file %s", filenam.Data()), 0,
879  kMBOk);
880  }
881  }
882  dir = fi.fIniDir;
883 }
884 
885 
886 
890 
892 {
893  // create a tab for each type of ID telescope
894  // put a list box for ID grid names on each tab
895 
896  KVString labels;
897  if (gIDGridManager->GetGrids()->GetSize()) gIDGridManager->GetListOfIDTelescopeLabels(labels);
898  if (labels == "") {
899  // no known idtelescopes referenced by grids (maybe we don't have a KVMultiDetArray?)
900  // make 1 tab "Grids" and put them all in
901  auto grids = gIDGridManager->GetGrids();
902  create_and_fill_id_grid_list("Grids", grids);
903  return;
904  }
905  //loop over labels
906  labels.Begin(",");
907  while (! labels.End()) {
908  KVString lab = labels.Next();
909  std::unique_ptr<KVSeqCollection> grids{gIDGridManager->GetGridsForIDTelescope(lab)};
910  create_and_fill_id_grid_list(lab, grids.get());
911  }
912 
913 }
914 
915 
916 
919 
921 {
922  //called when a new tab is selected
923 
924  TGCompositeFrame* cf = fGridListTabs->GetCurrentContainer();
925  if (!cf) return;//there are no tabs
926  TGFrameElement* el = (TGFrameElement*)cf->GetList()->At(0);
927  fIDGridList = (KVListView*)el->fFrame;
928  fIDGridList->SelectionChanged();
929 }
930 
931 
932 
934 
936 {
937  TGCompositeFrame* cf = fGridListTabs->AddTab(tab_label);
939  fIDGridList = new KVListView(KVIDGraph::Class(), cf, 600, 400);
940  fIDGridList->SetDataColumns(11);
941  fIDGridList->SetDataColumn(0, "Name", "", kTextLeft);
942  fIDGridList->SetDataColumn(2, "VarX", "", kTextLeft);
943  fIDGridList->SetDataColumn(1, "VarY", "", kTextLeft);
944  fIDGridList->SetDataColumn(3, "ID Telescopes", "GetNamesOfIDTelescopes", kTextLeft);
945  fIDGridList->SetDataColumn(4, "RunList", "", kTextLeft);
946  fIDGridList->SetDataColumn(5, "Identify Z and A?", "HasMassIDCapability", kTextCenterX);
947  fIDGridList->GetDataColumn(5)->SetIsBoolean();
948  fIDGridList->SetDataColumn(6, "# Ident.", "GetNumberOfIdentifiers", kTextRight);
949  fIDGridList->SetDataColumn(7, "# Cuts", "GetNumberOfCuts", kTextRight);
950  fIDGridList->SetDataColumn(8, "# Infos", "GetNumberOfInfos", kTextRight);
951  fIDGridList->SetDataColumn(9, "Last modified", "GetTimestamp", kTextCenterX);
952  fIDGridList->SetDataColumn(10, "Saved", "GetFileWrite", kTextCenterX);
953  fIDGridList->ActivateSortButtons();
954  fIDGridList->Connect("SelectionChanged()", "KVIDGridManagerGUI", this,
955  "SelectionChanged()");
956  fIDGridList->SetDoubleClickAction("KVIDGridManagerGUI", this, "StartEditor(TObject*)");
957  cf->AddFrame(fIDGridList, new TGLayoutHints(kLHintsLeft | kLHintsTop |
959  10, 10, 10));
960  if(grid_list)
961  fIDGridList->Display(grid_list);
962 }
963 
964 
965 
970 
972 {
973  // create a tab for each type of ID telescope
974  // put a list box for ID grid names on each tab
975  // cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : starting..." << endl;
976 
977  KVString labels("");
978  if (gIDGridManager->GetGrids()->GetSize()) gIDGridManager->GetListOfIDTelescopeLabels(labels);
979  else {
980  // there are no grids in the grid manager
981  RemoveEmptyTabs();
982  create_and_fill_id_grid_list("Grids");
983  fGridListTabs->MapSubwindows();
984  fGridListTabs->Layout();
985  Int_t ntabs = fGridListTabs->GetCurrent();
986  TabSelect(ntabs);
987  return;
988  }
989  if (labels == "") {
990  // no known idtelescopes referenced by grids (maybe we don't have a KVMultiDetArray?)
991  // update "Grids" tab
992  TGCompositeFrame* cf = fGridListTabs->GetTabContainer("Grids");
993  if (!cf) {
994  cout << "cf = 0x0 : label=Grids tab name=" <<
995  fGridListTabs->GetTabTab("Grids")->GetText()->GetString() << endl;
996  }
997  else {
998  TGFrameElement* el = (TGFrameElement*)cf->GetList()->At(0);
999  fIDGridList = (KVListView*)el->fFrame;
1000  auto grids = gIDGridManager->GetGrids();
1001  fIDGridList->Display(grids);
1002  }
1003  //make sure we are on the right tab
1004  Int_t ntabs = fGridListTabs->GetCurrent();
1005  TabSelect(ntabs);
1006  return;
1007  }
1008  //add any missing labels, update existing ones
1009  labels.Begin(",");
1010  while (! labels.End()) {
1011  KVString lab = labels.Next();
1012  if (!fGridListTabs->GetTabContainer(lab)) { // new tab
1013  std::unique_ptr<KVSeqCollection> grids{gIDGridManager->GetGridsForIDTelescope(lab)};
1014  create_and_fill_id_grid_list(lab,grids.get());
1015  fGridListTabs->MapSubwindows();
1016  fGridListTabs->Layout();
1017  fGridListTabs->SetTab(fGridListTabs->GetNumberOfTabs() - 1, kTRUE);
1018  }
1019  else { //existing tab
1020  //cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : existing tab '" << lab.Data() << "'..." << endl;
1021  TGCompositeFrame* cf = fGridListTabs->GetTabContainer(lab.Data());
1022  if (!cf) {
1023  cout << "cf = 0x0 : label=" << lab.Data() << " tab name=" <<
1024  fGridListTabs->GetTabTab(lab.Data())->GetText()->GetString() << endl;
1025  }
1026  else {
1027  //cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : recup tab '" << cf->GetName() << "'..." << endl;
1028  TGFrameElement* el = (TGFrameElement*)cf->GetList()->At(0);
1029  //cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : recup element '" << el->GetName() << "'..." << endl;
1030  fIDGridList = (KVListView*)el->fFrame;
1031  //cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : recup view list '" << fIDGridList->GetName() << "'..." << endl;
1032  auto grids = gIDGridManager->GetGridsForIDTelescope(lab);
1033  //cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : recup list de telescope'" << grids->GetName() << "'..." << endl;
1034  //grids->ls();
1035  fIDGridList->Display(grids);
1036  //cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : display list of grids in the viewerlist..." << endl;
1037 
1038  if (grids) delete grids;
1039  // cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : deleting the list..." << endl;
1040  }
1041  }
1042  }
1043  //now check that none of the remaining tabs are empty & should be removed
1044  RemoveEmptyTabs();
1045  // cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : empty tabs removed !" << endl;
1046  //make sure we are on the right tab
1047  Int_t ntabs = fGridListTabs->GetCurrent();
1048  TabSelect(ntabs);
1049  // cout << "DEBUG: KVIDGridManagerGUI::UpdateTabs() : current tab selected !" << endl;
1050 }
1051 
1052 
1053 
1056 
1058 {
1059  // Recursively remove any empty tabs
1060 
1061  Int_t ntabs = fGridListTabs->GetNumberOfTabs();
1062  Bool_t recursive = kFALSE;
1063  for (Int_t itab = 0; itab < ntabs; itab++) {
1064 
1065  //get name of tab
1066  KVString lab = fGridListTabs->GetTabTab(itab)->GetString();
1067  //get grids for this tab (if any)
1068  auto grids = gIDGridManager->GetGridsForIDTelescope(lab);
1069  Int_t ngrids = grids->GetEntries();
1070  delete grids;
1071  if (!ngrids) {
1072  //empty tab! remove it!
1073  //delete the KVListView
1074  TGCompositeFrame* cf = fGridListTabs->GetTabContainer(itab);
1075  TGFrameElement* el = (TGFrameElement*)cf->GetList()->At(0);
1076  KVListView* lv = (KVListView*)el->fFrame;
1077  delete lv;
1078  //remove tab
1079  fGridListTabs->RemoveTab(itab, kFALSE);
1080  recursive = kTRUE; // call recursively
1081  break;//stop loop - tab numbers have changed
1082  }
1083  }
1084  if (recursive) RemoveEmptyTabs();
1085  fGridListTabs->MapSubwindows();
1086  fGridListTabs->Layout();
1087 }
1088 
1089 
1090 
1094 
1096 {
1097  // called when a previously selected grid is modified
1098  // updates lists of lines
1099 
1100  if (!fLastSelectedGrid) return;
1101 
1102  KVList* ids = fLastSelectedGrid->GetIdentifiers();
1103  // sort lines in order of increasing Z
1104  ids->Sort();
1105  fIDLineList->Display(ids);
1106 // KVSeqCollection* cutlines = fSelectedGrid->GetCuts()->GetSubListWithClass("KVIDCutLine");
1107  fCUTList->Display(fSelectedGrid->GetCuts());
1108 // fCUTLineList->Display(cutlines);
1109 // delete cutlines;
1110 // cutlines = fSelectedGrid->GetCuts()->GetSubListWithClass("KVIDCutContour");
1111  fCUTInfoList->Display(fSelectedGrid->GetInfos());
1112 // fCUTContourList->Display(cutlines);
1113 // delete cutlines;
1114 }
1115 
1116 
1117 
1124 
1126 {
1127  // Called when a grid is selected in list of grids
1128  //
1129  // We fill list of all lines in grid
1130  // * if only one grid is selected, we display its lines in the line list
1131  // * if more than one grid is selected, we clear the line list
1132 
1133  if (GetNSelected() == 1 && fSelectedGrid) {
1134  KVList* ids = fSelectedGrid->GetIdentifiers();
1135  // sort lines in order of increasing Z
1136  ids->Sort();
1137  fIDLineList->Display(ids);
1138  fCUTList->Display(fSelectedGrid->GetCuts());
1139  fCUTInfoList->Display(fSelectedGrid->GetInfos());
1140  if (fLastSelectedGrid) {
1141  fLastSelectedGrid->Disconnect("Modified()", this, "UpdateListOfLines()");
1142  }
1143  fSelectedGrid->Connect("Modified()", "KVIDGridManagerGUI", this, "UpdateListOfLines()");
1144  fLastSelectedGrid = fSelectedGrid;
1145  }
1146  else {
1147  fIDLineList->RemoveAll();
1148  fCUTList->RemoveAll();
1149  fCUTInfoList->RemoveAll();
1150  if (fLastSelectedGrid) {
1151  fLastSelectedGrid->Disconnect("Modified()", this, "UpdateListOfLines()");
1152  fLastSelectedGrid = 0;
1153  }
1154  }
1155 }
1156 
1157 
1158 
1161 
1163 {
1164  // disable all buttons
1165  for (int i = 0; i < fNbButtons; i++) fTBbuttons[i]->SetEnabled(kFALSE);
1166  // enable 'open' & 'quit' & 'new grid"
1167  fTBOpen->SetEnabled();
1168  fTBRefresh->SetEnabled();
1169 // fTBStartEditor->SetEnabled();
1170  fTBNewG->SetEnabled();
1171  fTBOpenRoot->SetEnabled();
1172  // enable 'save' if there are grids
1173  if (gIDGridManager->GetGrids()->GetEntries()) fTBSave->SetEnabled();
1174 
1175  if (!GetNSelected()) return; // no grids selected
1176 
1177  //enable delete selected grid(s)
1178  fTBDelG->SetEnabled();
1179  // enable set id telescopes
1180  fTBSetIDG->SetEnabled();
1181 
1182  if (GetNSelected() == 1) {
1183  // only one grid selected
1184  fTBStartEditor->SetEnabled();
1185  fTBCopyG->SetEnabled();
1186  }
1187 }
1188 
1189 
1190 
1202 
1204 {
1205  // GUI method to draw a new identifier and add it to graph.
1206  // A dialog box with drop-down list pops up for the user to choose the class of the
1207  // new identifier, unless only one choice is possible, in which case it is used automatically.
1208  // For each KVIDGraph-derived class, the list of possible identifier classes and the
1209  // default class are define in .kvrootrc by the variables:
1210  //
1211  // [class_name].IDClass: [id class 1]
1212  // +[class_name].IDClass: [id class 2]
1213  // + ...
1214  // [class_name].DefaultIDClass: [id class]
1215 
1216  if (!fSelectedGrid || GetNSelected() != 1) return;
1217  TString resname;
1218  resname.Form("%s.IDClass", fSelectedGrid->ClassName());
1219  TString cut_choices = gEnv->GetValue(resname.Data(), "");
1220  resname.Form("%s.DefaultIDClass", fSelectedGrid->ClassName());
1221  TString cut_default = gEnv->GetValue(resname.Data(), "");
1222  TString cut_class;
1223  Bool_t okpressed;
1224  if (cut_choices.Contains(" ")) {
1225  new KVDropDownDialog(this,
1226  "Choose class of new identifier :",
1227  cut_choices.Data(),
1228  cut_default.Data(),
1229  &cut_class,
1230  &okpressed);
1231  if (!okpressed) return;
1232  }
1233  else
1234  cut_class = cut_choices;
1235  SetStatus(Form("Draw ID line (%s) in current pad", cut_class.Data()));
1236  fSelectedGrid->DrawAndAdd("ID", cut_class.Data());
1237  fTBNewIDL->SetDown(kFALSE, kFALSE);
1238  SetStatus();
1239 }
1240 
1241 
1242 
1254 
1256 {
1257  // GUI method to draw a new cut and add it to graph.
1258  // A dialog box with drop-down list pops up for the user to choose the class of the
1259  // new cut, unless only one choice is possible, in which case it is used automatically.
1260  // For each KVIDGraph-derived class, the list of possible cut classes and the
1261  // default class are define in .kvrootrc by the variables:
1262  //
1263  // [class_name].CutClass: [cut class 1]
1264  // +[class_name].CutClass: [cut class 2]
1265  // + ...
1266  // [class_name].DefaultCutClass: [cut class]
1267 
1268  if (!fSelectedGrid || GetNSelected() != 1) return;
1269  TString resname;
1270  resname.Form("%s.CutClass", fSelectedGrid->ClassName());
1271  TString cut_choices = gEnv->GetValue(resname.Data(), "");
1272  resname.Form("%s.DefaultCutClass", fSelectedGrid->ClassName());
1273  TString cut_default = gEnv->GetValue(resname.Data(), "");
1274  TString cut_class;
1275  TString cut_types = cut_choices;
1276  cut_types.ReplaceAll("KVIDCut", "");
1277  Bool_t okpressed;
1278  if (cut_choices.Contains(" ")) {
1279  new KVDropDownDialog(this,
1280  "Choose class of new cut :",
1281  cut_types.Data(),
1282  cut_default.Data(),
1283  &cut_class,
1284  &okpressed);
1285  if (!okpressed) return;
1286  }
1287  else
1288  cut_class = cut_types;
1289  SetStatus(Form("Draw cut %s in current pad", cut_class.Data()));
1290  cut_class.Prepend("KVIDCut");
1291  fSelectedGrid->DrawAndAdd("CUT", cut_class.Data());
1292  fTBNewCut->SetDown(kFALSE, kFALSE);
1293  SetStatus();
1294 }
1295 
1296 
1297 
1298 
1302 
1304 {
1305  // test the identification with selected grid
1306  // we search in current pad for the data histogram
1307 
1308  SetStatus("");
1309  if (GetNSelected() != 1) return;
1310  if (!fSelectedGrid) return;
1311  // look for data histogram in current pad
1312  TH2* histo = 0;
1313  if (gPad) {
1314  TIter next(gPad->GetListOfPrimitives());
1315  TObject* o;
1316  while ((o = next())) {
1317  if (o->InheritsFrom("TH2")) {
1318  histo = (TH2*)o;
1319  break;
1320  }
1321  }
1322  }
1323  if (!histo) {
1324  SetStatus("No TH2 found in current pad. Select pad containing 2D histo with data to identify.");
1325  return;
1326  }
1327  else {
1328  SetStatus(Form("Test identification of data in current pad %s.", histo->GetName()));
1329  }
1330  new KVTestIDGridDialog(fClient->GetDefaultRoot(), this, 10, 10, fSelectedGrid, histo);
1331  SetStatus("");
1332 }
1333 
1334 
1335 
1339 
1341 {
1342  // test the identification with selected grid
1343  // we search in current pad for the data histogram
1344  SetStatus("");
1345  if (GetNSelected() != 1) return;
1346  if (!fSelectedGrid) return;
1347  // look for data histogram in current pad
1348  TH2* histo = 0;
1349  if (gPad) {
1350  TIter next(gPad->GetListOfPrimitives());
1351  TObject* o;
1352  while ((o = next())) {
1353  if (o->InheritsFrom("TH2")) {
1354  histo = (TH2*)o;
1355  break;
1356  }
1357  }
1358  }
1359  if (!histo) {
1360  SetStatus("No TH2 found in current pad. Select pad containing 2D histo with data to identify.");
1361  return;
1362  }
1363  else {
1364  SetStatus(Form("Test identification of data in current pad %s.", histo->GetName()));
1365  }
1366  TFile* tmpfiles = TestIdentificationWithTree(fSelectedGrid, histo->GetName());
1367  if (!tmpfiles) {
1368  SetStatus("There was a problem with the test ???");
1369  return;
1370  }
1371  new TCanvas;
1372  TH2* id = (TH2*)tmpfiles->Get("idcode_map");
1373  id->SetStats(kFALSE);
1374  id->Draw("zcol");
1375  TTree* t = (TTree*)tmpfiles->Get("tree_idresults");
1376  t->StartViewer();
1377  SetStatus("");
1378 }
1379 
1380 
1381 
1382 
1395 
1396 TFile* KVIDGridManagerGUI::TestIdentificationWithTree(KVIDGraph* gr, const Char_t* name_of_data_histo)
1397 {
1398  //This method allows to test the identification capabilities of the grid using data in a TH2F.
1399  //We assume that 'data' contains an identification map, whose 'x' and 'y' coordinates correspond
1400  //to this grid. Then we loop over every bin of the histogram, perform the identification (if
1401  //IsIdentifiable() returns kTRUE) and fill the two histograms with the resulting identification
1402  //and its dependence on the 'residual energy' i.e. the 'x'-coordinate of the 'data' histogram,
1403  //each identification weighted by the contents of the original data bin.
1404  //
1405  //The 'identification" we represent is the result of the KVReconstructedNucleus::GetPID() method.
1406  //For particles identified in Z only, this is the "real Z".
1407  //For particles with A & Z identification, this is Z + 0.1*(A - 2*Z)
1408 
1409  //Initialize the grid: calculate line widths etc.
1410  gr->Initialize();
1411 
1412  TH2F* data = (TH2F*)gROOT->FindObject(name_of_data_histo);
1413  if (!data) {
1414  printf(" KVIDGraph::TestIdentificationWithTree l histo %s n existe pas\n", name_of_data_histo);
1415  return 0;
1416  }
1417 
1418 
1421 
1422  // store current memory directory
1423  TDirectory* CWD = gDirectory;
1424 
1425  TTree* tid = 0;
1426  if ((tid = (TTree*)gROOT->FindObject("tree_idresults"))) {
1427  printf(" KVIDGraph::TestIdentificationWithTree effacemenent de l arbre existant\n");
1428  delete tid;
1429  }
1430  // create temporary file for tree
1431  TString fn("IDtestTree.root");
1433  TFile* tmpfile = new TFile(fn.Data(), "recreate");
1434  TH2F* idmap = (TH2F*)data->Clone("idcode_map");
1435  idmap->Reset();
1436  tid = new TTree("tree_idresults", "pid");
1437  Float_t br_xxx, br_yyy, br_stat, br_pid;
1438  Int_t br_idcode, br_isid;
1439 
1440  tid->Branch("X", &br_xxx, "br_xxx/F");
1441  tid->Branch("Y", &br_yyy, "br_yyy/F");
1442  tid->Branch("Stat", &br_stat, "br_stat/F");
1443 
1444  tid->Branch("PID", &br_pid, "br_pid/F");
1445  tid->Branch("IDcode", &br_idcode, "br_idcode/I");
1446  tid->Branch("IsIdentified", &br_isid, "br_isid/I");
1447 
1448  Int_t tot_events = (Int_t) data->GetSum();
1449  Int_t events_read = 0;
1450  Float_t percent = 0., cumul = 10.;
1451 
1452  //loop over data in histo
1453  for (int i = 1; i <= data->GetNbinsX(); i++) {
1454  for (int j = 1; j <= data->GetNbinsY(); j++) {
1455 
1456  Stat_t poids = data->GetBinContent(i, j);
1457  if (poids == 0)
1458  continue;
1459  br_stat = Float_t(poids);
1460 
1461  Axis_t x0 = data->GetXaxis()->GetBinCenter(i);
1462  Axis_t y0 = data->GetYaxis()->GetBinCenter(j);
1463  Axis_t wx = data->GetXaxis()->GetBinWidth(i);
1464  Axis_t wy = data->GetYaxis()->GetBinWidth(j);
1465 
1466  br_xxx = Float_t(x0);
1467  br_yyy = Float_t(y0);
1468  //If bin content ('poids') is <=20, we perform the identification 'poids' times, each time with
1469  //randomly-drawn x and y coordinates inside this bin
1470  //If 'poids'>20, we perform the identification 20 times and we fill the histograms with
1471  //a weight poids/20
1472  Double_t x, y;
1473  Int_t kmax = (Int_t) TMath::Min(20., poids);
1474  //Double_t weight = (kmax == 20 ? poids / 20. : 1.);
1475 
1476  for (int k = 0; k < kmax; k++) {
1477 
1478  x = gRandom->Uniform(x0 - .5 * wx, x0 + .5 * wx);
1479  y = gRandom->Uniform(y0 - .5 * wy, y0 + .5 * wy);
1480  if (gr->IsIdentifiable(x, y)) {
1481  br_isid = 1;
1482  gr->Identify(x, y, idr);
1483  nuc.SetIdentification(idr, nullptr);
1484  br_pid = nuc.GetPID();
1485  br_idcode = gr->GetQualityCode();
1486  idmap->SetBinContent(i, j, br_idcode);
1487  }
1488  else {
1489  br_isid = 0;
1490  br_pid = -1;
1491  br_idcode = -1;
1492  idmap->SetBinContent(i, j, br_idcode);
1493  }
1494  tid->Fill();
1495  }
1496  events_read += (Int_t) poids;
1497  percent = (1. * events_read / tot_events) * 100.;
1498  gr->Increment((Float_t) events_read); //sends signal to GUI progress bar
1499  if (percent >= cumul) {
1500  cout << (Int_t) percent << "\% processed" << endl;
1501  cumul += 10;
1502  }
1503  //gSystem->ProcessEvents();
1504  }
1505  }
1506 
1507  delete idr;
1508  CWD->cd();
1509  return tmpfile;
1510 }
1511 
1512 
1513 
1515 
1517 {
1518  SetStatus("");
1519  if (GetNSelected() != 1) return;
1520  if (!fSelectedGrid) return;
1521  SetStatus(Form("Fitting grid %s", fSelectedGrid->GetName()));
1523  fitter->SetGrid(fSelectedGrid);
1524  fitter->SetPad(fSelectedGrid->GetPad());
1525  TMethod* m = fitter->IsA()->GetMethodAny("FitPanel");
1526  TContextMenu* cm = new TContextMenu("FitPanel", "Context menu for KVVirtualIDFitter::FitPanel");
1527  cm->Action(fitter, m);
1528  delete cm;
1529 }
1530 
1531 
int Int_t
kVerticalFrame
kHorizontalFrame
bool Bool_t
char Char_t
float Float_t
double Axis_t
constexpr Bool_t kFALSE
double Double_t
double Stat_t
constexpr Bool_t kTRUE
const Bool_t kIterBackward
#define gDirectory
R__EXTERN TEnv * gEnv
#define gClient
kFDOpen
kFDSave
kLHintsExpandY
kLHintsLeft
kLHintsCenterX
kLHintsTop
kLHintsExpandX
kMBCancel
kMBOk
kMBIconExclamation
kMBIconQuestion
kTextCenterX
kTextLeft
kTextRight
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize UnmapWindow
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize MapSubwindows
Option_t Option_t TPoint TPoint percent
#define gROOT
R__EXTERN TRandom * gRandom
char * Form(const char *fmt,...)
char * StrDup(const char *str)
R__EXTERN TSystem * gSystem
#define gPad
static const Char_t * GetListOfPlugins(const Char_t *base)
Definition: KVBase.cpp: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:637
void ClearListOfIDTelescopes()
Definition: KVIDGraph.h:480
void SetVarX(const char *v) override
Definition: KVIDGraph.h:633
void AddIDTelescopes(const TList *)
Associate this graph with all ID telescopes in list.
Definition: KVIDGraph.cpp:1598
static KVIDGraph * MakeIDGraph(const Char_t *)
Definition: KVIDGraph.cpp:1618
void SetIDTelescopes(const TString &)
Set value of "IDTelescopes" parameter with comma-separated list of ID telescope names.
Definition: KVIDGraph.cpp:1674
virtual void SetOnlyZId(Bool_t yes=kTRUE)
Definition: KVIDGraph.cpp:1578
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 create_and_fill_id_grid_list(const KVString &tab_label, KVSeqCollection *grid_list=nullptr)
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)
KVSeqCollection * GetGrids()
Bool_t ReadAsciiFile(const Char_t *filename)
Base class for all detectors or associations of detectors in array which can identify charged particl...
Definition: KVIDTelescope.h:85
Full result of one attempted particle identification.
General purpose dialog box asking for some input in the form of a string.
Definition: KVInputDialog.h:24
Enhanced version of ROOT TGListView widget.
Definition: KVListView.h: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
char * fFilename
const char ** fFileTypes
char * fIniDir
TGFrame * fFrame
virtual void AddEntry(const char *s, Int_t id, void *ud=nullptr, const TGPicture *p=nullptr, TGMenuEntry *before=nullptr)
void Reset(Option_t *option="") override
void SetBinContent(Int_t bin, Double_t content) override
TObject * At(Int_t idx) const override
const char * GetName() const override
TClass * IsA() const override
virtual Bool_t InheritsFrom(const char *classname) const
virtual Double_t Uniform(Double_t x1, Double_t x2)
const char * Data() const
TString & Prepend(char c, Ssiz_t rep=1)
void Form(const char *fmt,...)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
TString & ReplaceAll(const char *s1, const char *s2)
Bool_t cd(const char *path)
virtual const char * Getenv(const char *env)
virtual const char * BaseName(const char *pathname)
virtual char * ExpandPathName(const char *path)
virtual Int_t Fill()
virtual Int_t Branch(const char *folder, Int_t bufsize=32000, Int_t splitlevel=99)
virtual void StartViewer()
Double_t y[n]
Double_t x[n]
TGraphErrors * gr
void Info(const char *location, const char *fmt,...)
TFile * OpenFile(const TString &fin)
Double_t Min(Double_t a, Double_t b)
const char * fTipText
TGButton * fButton
Bool_t fStayDown
const char * fPixmap
TLine lv
TMarker m
ClassImp(TPyArg)