GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4ConditionEditor.cpp
Go to the documentation of this file.
1 // $Id: TGo4ConditionEditor.cpp 1730 2015-08-28 07:29:30Z adamczew $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum für Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 
15 #include "TGo4ConditionEditor.h"
16 
17 #include <QMessageBox>
18 #include <QMenu>
19 #include <QtCore/QSignalMapper>
20 #include <QToolTip>
21 
22 #include "TH1.h"
23 #include "TMath.h"
24 #include "TCutG.h"
25 #include "TClass.h"
26 #include "TPad.h"
27 #include "TArrayD.h"
28 #include "TGo4Log.h"
29 #include "TGo4Condition.h"
30 #include "TGo4Slot.h"
31 #include "TGo4WinCond.h"
32 #include "TGo4PolyCond.h"
33 #include "TGo4ShapedCond.h"
34 #include "TGo4CondArray.h"
35 #include "TGo4ViewPanel.h"
36 #include "TGo4BrowserProxy.h"
37 #include "TGo4AnalysisProxy.h"
38 
39 
40 TGo4ConditionEditor::TGo4ConditionEditor(QWidget *parent, const char* name) :
41  QGo4Widget(parent, name)
42 {
43  setupUi(this);
44 
45 #if QT_VERSION >= QT_VERSION_CHECK(4,6,0)
46  LCDCounts->setDigitCount(10);
47  LCDTrueCounts->setDigitCount(10);
48 #else
49  LCDCounts->setNumDigits(10);
50  LCDTrueCounts->setNumDigits(10);
51 #endif
52 
53  setWindowTitle("Condition editor");
54  ResetWidget();
55  fiSelectedIndex = -1;
56  parentWidget()->adjustSize();
57  fbDrawOnNextRefresh = false;
58  fbEllipseAutoRefresh = false;
59  fiLastChangeValue = -1;
60  CutTable->setContextMenuPolicy(Qt::CustomContextMenu);
61  fbNewWindow=true;
62 }
63 
64 
65 bool TGo4ConditionEditor::IsAcceptDrag(const char* itemname, TClass* cl, int kind)
66 {
67  if (cl==0) return false;
68  bool res = cl->InheritsFrom(TGo4Condition::Class());
69 // res = res || cl->InheritsFrom(TH1::Class());
70  return res;
71 }
72 
73 void TGo4ConditionEditor::DropItem(const char* itemname, TClass* cl, int kind)
74 {
75  if (cl==0) return;
76 
77  if (cl->InheritsFrom(TGo4Condition::Class()))
78  WorkWithCondition(itemname);
79 
80 // uncomment this to enable histogram drop on condition editor
81 
82 // else
83 // if (cl->InheritsFrom(TH1::Class()) && (fiSelectedIndex==-1)) {
84 // RemoveLink("Histogram");
85 // AddLink(itemname, "Histogram");
86 // GetLinked("Histogram", 1);
87 //
88 // TGo4Condition* cond = dynamic_cast<TGo4Condition*>(GetLinked("Condition", 0));
89 // if (cond!=0) {
90 // cond->SetHistogram(itemname);
91 // cond->SetHistogramLink(kTRUE);
92 // }
93 // CondTabs->setCurrentIndex(1);
94 // PleaseUpdateSlot();
95 // RefreshWidget();
96 // }
97 
98 }
99 
100 void TGo4ConditionEditor::linkedObjectUpdated(const char* linkname, TObject* obj)
101 {
102  if (strcmp(linkname,"Condition")==0) {
103  TGo4Condition* cond = dynamic_cast<TGo4Condition*> (obj);
104  if (cond!=0) cond->SetChanged(kFALSE);
105  }
106 
107  RefreshWidget(false);
108 }
109 
111 {
112  if (strcmp(linkname,"Condition")==0)
113  ShootCloseWidget(true);
114 }
115 
116 void TGo4ConditionEditor::WorkWithCondition(const char* itemname)
117 {
118  const char* conditemname = GetLinkedName("Condition");
119 
120  TGo4Condition* con = dynamic_cast<TGo4Condition*> (GetLinked("Condition",0));
121  if ((con!=0) && (con->IsChanged()!=0) && (strcmp(conditemname,itemname)!=0)) {
122 
123  int res = QMessageBox::warning(this, "Condition editor",
124  QString("Current condition %1 is modified!\n"
125  "New condition %2 is selected.").arg(conditemname).arg(itemname),
126  QString("Continue with current"),
127  QString("Start with new"), QString::null, 0);
128 // (BrowserItemRemote(conditemname) ? QString("Update in analysis and start new") : QString::null), 0);
129  if (res==0) return;
130 // if (res==2) UpdateItemInAnalysis(conditemname);
131  }
132 
133  if ((conditemname==0) || (strcmp(conditemname,itemname)!=0)) {
134  ResetWidget();
135  CondNameLbl->setText(itemname);
136  AddLink(itemname, "Condition");
137  }
138 
139  QString iconname = ":/icons/right.png";
140  QString tooltip = "Refresh condition from analysis";
141  if (!BrowserItemRemote(itemname)) {
142  iconname = ":/icons/refresh.png";
143  tooltip = "Refresh condition from source";
144  }
145  RefreshButton->setIcon( QIcon(iconname) );
146  RefreshButton->setToolTip(tooltip);
147 
148  TGo4ViewPanel* panel = WhereItemDrawn(itemname);
149 
150  if (panel==0) {
151  GetLinked("Condition", 2);
152  fbDrawOnNextRefresh = true;
153  fiSelectedIndex = -1;
154  } else {
155  TPad* pad = panel->FindPadWithItem(itemname);
157  panel->setFocus();
158  }
159 
160  RefreshWidget(false);
161  setFocus();
162 
163 }
164 
166 {
168  CondNameLbl->setText("");
169  CondClassLbl->setText("");
170 
171  PleaseUpdateLabel->setVisible(false);
172 
173  ArrayAllButton->setVisible(false);
174  ArrayElements->setVisible(false);
175 
176  HistogramChk->setVisible(false);
177  HistogramChk->setChecked(false);
178  HistogramChk->setText("null");
179  HistogramChk->setEnabled(false);
180 
181  CondVisibleChk->setVisible(false);
182  DrawInfoLbl->setText("");
183  CondTabs->setEnabled(false);
184 
185  LCDCounts->display(0);
186  LCDTrueCounts->display(0);
187 
188  Win1_low->setDisabled(true);
189  Win1_up->setDisabled(true);
190  Win2_low->setDisabled(true);
191  Win2_up->setDisabled(true);
192 
193  ResultCombo->setEnabled(false);
194  InvertCombo->setEnabled(false);
195 
196  //CondTabs->setTabEnabled(1, false);
197  //CondTabs->setTabEnabled(2, false);
198 }
199 
201 {
202  TGo4Condition* cond = dynamic_cast<TGo4Condition*>(GetLinked("Condition", 0));
203  if (cond==0) return;
204  const char* conditemname = GetLinkedName("Condition");
205  TGo4ViewPanel* panel = WhereItemDrawn(conditemname);
206  TPad* pad = panel==0 ? 0 : panel->FindPadWithItem(conditemname);
207 
208  TGo4BrowserProxy* br = Browser();
209  TGo4ServerProxy* serv = br ? br->DefineServerObject(conditemname) : 0;
210  UpdateCon->setEnabled((serv==0) || serv->CanSubmitObjects());
211 
212  PleaseUpdateLabel->setVisible(cond->IsChanged()!=0);
213  fiLastChangeValue = cond->IsChanged();
214 
215  QString hitemname;
216  TH1* histo = 0;
217  if ((panel!=0) && (pad!=0)) {
218  histo = panel->GetPadHistogram(pad);
219  hitemname = panel->GetDrawObjectLinkName(pad, histo);
220  if (checkindex) {
221  QString selname = panel->GetSelectedMarkerName(pad);
222  int selindex = panel->GetSelectedMarkerIndex(pad);
223  if (selname==cond->GetName())
224  fiSelectedIndex = selindex;
225  }
226  }
227  if (histo==0) histo = dynamic_cast<TH1*>(GetLinked("Histogram", 0));
228 
229  fbTypingMode = false;
230 
231  TGo4CondArray* arr = dynamic_cast<TGo4CondArray*> (cond);
232 
233  ArrayAllButton->setVisible(arr!=0);
234  ArrayElements->setVisible(arr!=0);
235  if (arr==0) {
236  fiSelectedIndex = -1;
237  } else {
238  ArrayElements->setMaximum(arr->GetNumber()-1);
239  if (fiSelectedIndex>=arr->GetNumber()-1)
240  fiSelectedIndex=arr->GetNumber()-1;
241  ArrayElements->setValue(fiSelectedIndex);
242 
243  cond = SelectedCondition();
244  }
245 
246  ModifyButton->setVisible((panel!=0) && ((arr==0) || (fiSelectedIndex>=0)));
247 
248  TGo4WinCond* wcond = dynamic_cast<TGo4WinCond*> (cond);
249  TGo4PolyCond* pcond = dynamic_cast<TGo4PolyCond*> (cond);
250  TGo4ShapedCond* econd = dynamic_cast<TGo4ShapedCond*> (cond);
251 
252  if (wcond != 0)
253  {
254  if (wcond->GetDimension() == 2)
255  CondClassLbl->setText("Win 2-D ");
256  else
257  CondClassLbl->setText("Win 1-D ");
258  }
259  else if (econd != 0)
260  {
261  if(econd->IsEllipse())
262  CondClassLbl->setText("Ellipse ");
263  else if (econd->IsCircle())
264  CondClassLbl->setText("Circle ");
265  else if (econd->IsBox())
266  CondClassLbl->setText("Box ");
267  else
268  CondClassLbl->setText("Free shape ");
269  }
270  else if (pcond != 0)
271  CondClassLbl->setText("Polygon ");
272 
273  else
274  CondClassLbl->setText("");
275 
276  QString infolbl;
277 
278  const char* hname = cond->GetLinkedHistogram();
279  if ((hname==0) || (*hname==0)) {
280  HistogramChk->setChecked(false);
281  HistogramChk->setText("null");
282  HistogramChk->setEnabled(false);
283 // DisplayB->setEnabled(false);
284  } else {
285  HistogramChk->setChecked(cond->IsHistogramLink());
286  HistogramChk->setText(hname);
287  HistogramChk->setEnabled(true);
288  infolbl = "Hist: ";
289  if (hitemname.length()>0)
290  infolbl += hitemname;
291  else
292  infolbl += hname;
293 // DisplayB->setEnabled(true);
294  }
295 
296  CondVisibleChk->setVisible(true);
297  CondVisibleChk->setChecked(cond->IsVisible());
298 
299  if (panel!=0) {
300  if (infolbl.length()>0) infolbl+=" ";
301  infolbl += "Drawn: ";
302  infolbl += panel->objectName();
303  if ((pad!=0) && (pad!=(TPad*)panel->GetCanvas())) {
304  infolbl += ", ";
305  infolbl += pad->GetName();
306  }
307  }
308  DrawInfoLbl->setText(infolbl);
309 
310  CondTabs->setEnabled(true);
311 
312  ResultCombo->setEnabled(true);
313  InvertCombo->setEnabled(true);
314 
315  if(cond->IsEnabled())
316  ResultCombo->setCurrentIndex(0);
317  else
318  if (cond->FixedResult())
319  ResultCombo->setCurrentIndex(1);
320  else
321  ResultCombo->setCurrentIndex(2);
322 
323  if(cond->IsTrue()) InvertCombo->setCurrentIndex(0);
324  else InvertCombo->setCurrentIndex(1);
325 
326  LCDCounts->display(cond->Counts());
327  LCDTrueCounts->display(cond->TrueCounts());
328 
329  double ratio = 0;
330  if (cond->Counts()>0)
331  ratio = 1.*cond->TrueCounts() / cond->Counts();
332  QString sratio;
333  if ((ratio>=0.) && (ratio<=100.))
334  sratio.sprintf("%4.2f%s",ratio*100.,"%");
335  else
336  sratio = "?.?? %";
337  PercentLabel->setText(sratio);
338 
339  CondLimits->setChecked(cond->IsLimitsDraw());
340  CondLabel->setChecked(cond->IsLabelDraw());
341 
342  Win1_low->setText(QString::number(cond->GetXLow()));
343  Win1_up->setText(QString::number(cond->GetXUp()));
344 
345  if (cond->GetDimension()==2) {
346  Win2_low->setText(QString::number(cond->GetYLow()));
347  Win2_up->setText(QString::number(cond->GetYUp()));
348  } else {
349  Win2_low->setText("");
350  Win2_up->setText("");
351  }
352 
353  if (wcond!=0) {
354  Win1_low->setEnabled(true);
355  Win1_up->setEnabled(true);
356  Win2_low->setEnabled(wcond->GetDimension()==2);
357  Win2_up->setEnabled(wcond->GetDimension()==2);
358  } else {
359  Win1_low->setDisabled(true);
360  Win1_up->setDisabled(true);
361  Win2_low->setDisabled(true);
362  Win2_up->setDisabled(true);
363  }
364 
365  ShowEllipseWidget(econd!=0); // hide all elements on shape tab to reduce minimum window size
366  int oldindex = CondTabs->currentIndex();
367  CondTabs->setCurrentIndex(2); // JAM: need this trick to retrieve actual tab limits with hidden icons?
368  CondTabs->setCurrentIndex(oldindex);
369 
370  if ((pcond==0) && ((CondTabs->currentIndex()==1) || (CondTabs->currentIndex()==2)))
371  CondTabs->setCurrentIndex(0); // switch to wincond defaults when changing from polycond type
372 
373  if ((econd==0) && (pcond!=0) && (CondTabs->currentIndex()==2))
374  CondTabs->setCurrentIndex(1); // switch to polycond defaults when changing from shape type
375 
376 
377  CondTabs->setTabEnabled(1, (pcond!=0));
378  CondTabs->setTabEnabled(2, (econd!=0));
379 
380 
381  if (pcond != 0)
382  {
383  FillCutWidget(pcond->GetCut(kFALSE));
384  if (econd != 0)
385  {
386  FillEllipseWidget(econd);
387  if (fbNewWindow) CondTabs->setCurrentIndex(2);
388  }
389  else
390  {
391  if (fbNewWindow) CondTabs->setCurrentIndex(1);
392  }
393  }
394  else
395  {
396  if (fbNewWindow) CondTabs->setCurrentIndex(0);
397  }
398 
399  IntBox->setChecked(cond->IsIntDraw());
400  MaxCBox->setChecked(cond->IsCMaxDraw());
401  MaxXBox->setChecked(cond->IsXMaxDraw());
402  MaxYBox->setChecked(cond->IsYMaxDraw());
403 
404  XMeanBox->setChecked(cond->IsXMeanDraw());
405  YMeanBox->setChecked(cond->IsYMeanDraw());
406  XRMSBox->setChecked(cond->IsXRMSDraw());
407  YRMSBox->setChecked(cond->IsYRMSDraw());
408 
409  IntBox->setText(QString("Integr: ") + QString::number(cond->GetIntegral(histo,"")));
410  MaxXBox->setText(QString("MaxX: ") + QString::number(cond->GetXMax(histo)));
411  MaxYBox->setText(QString("MaxY: ") + QString::number(cond->GetYMax(histo)));
412  MaxCBox->setText(QString("Max: ") + QString::number(cond->GetCMax(histo)));
413 
414  XMeanBox->setText(QString("XMean: ") + QString::number(cond->GetMean(histo, 1)));
415  XRMSBox->setText(QString("XRMS: ") + QString::number(cond->GetRMS(histo, 1)));
416  YMeanBox->setText(QString("YMean: ") + QString::number(cond->GetMean(histo, 2)));
417  YRMSBox->setText(QString("YRMS: ") + QString::number(cond->GetRMS(histo, 2)));
418 
419  fbTypingMode = true;
420 
421  if (fbDrawOnNextRefresh) {
422  fbDrawOnNextRefresh = false;
423  TString hitemname;
424  if ((panel==0) && HistogramChk->isChecked() &&
425  Browser()->DefineRelatedObject(conditemname, hname, hitemname))
426  DrawCondition(false);
427  }
428  fbNewWindow=false;
429 }
430 
432 {
433  TGo4Condition* cond = dynamic_cast<TGo4Condition*>(GetLinked("Condition", 0));
434  if (cond==0) return 0;
435 
436  TGo4CondArray* arr = dynamic_cast<TGo4CondArray*> (cond);
437 
438  if ((arr==0) || (fiSelectedIndex==-1))
439  {
440  if(arr) arr->SetMultiEdit(kTRUE);
441  return cond;
442  }
443  if (fiSelectedIndex<arr->GetNumber())
444  {
445  arr->SetMultiEdit(kFALSE);
447  return arr->At(fiSelectedIndex);
448  }
449  return cond;
450 }
451 
453 {
454  TGo4Condition* cond = dynamic_cast<TGo4Condition*> (GetLinked("Condition",0));
455  SetChangeFlag(true);
456  PleaseUpdateLabel->setVisible(true);
457 }
458 
460 {
461  if (!fbTypingMode) return;
462  if (fiSelectedIndex==t) return;
463 
464  fiSelectedIndex = t;
465  RefreshWidget(false);
466  RedrawCondition();
467 }
468 
470 {
471  ArrayElements->setValue(-1);
472 }
473 
475 {
477  if (!fbTypingMode || (cond==0)) return;
478  switch (mode) {
479  case 0: cond->Enable(); break;
480  case 1: cond->Disable(kTRUE); break;
481  case 2: cond->Disable(kFALSE ); break;
482  default: cond->Enable(); break;
483  }
485 }
486 
488 {
490  if (!fbTypingMode || (cond==0)) return;
491  cond->Invert(mode==1);
493 }
494 
496 {
497  const char* conditemname = GetLinkedName("Condition");
498  TGo4Condition* con = dynamic_cast<TGo4Condition*> (GetLinked("Condition",0));
499 
500  if ((con==0) || (conditemname==0)) return;
501 
502  TString objname;
503  TGo4ServerProxy* an = Browser()->DefineAnalysisObject(conditemname, objname);
504  if (an!=0) {
505  an->ClearAnalysisObject(objname.Data());
506  GetLinked("Condition", 2);
507  } else {
508  con->ResetCounts();
510  RefreshWidget(false);
511  }
512 }
513 
515 {
516  UpdateLimits();
517 }
518 
520 {
521  if (UpdateLimits())
522  RedrawCondition();
523 }
524 
526 {
528  if (!fbTypingMode || (cond==0)) return false;
529 
530  bool okx1, okx2, res = false;
531  Double_t x1 = Win1_low->text().toDouble(&okx1);
532  Double_t x2 = Win1_up->text().toDouble(&okx2);
533 
534  if (cond->GetDimension()==2) {
535  bool oky1, oky2;
536  Double_t y1 = Win2_low->text().toDouble(&oky1);
537  Double_t y2 = Win2_up->text().toDouble(&oky2);
538  if (okx1 && okx2 && oky1 && oky2) {
539  cond->SetValues(x1, x2, y1, y2);
540  res = true;
541  }
542  } else
543  if (okx1 && okx2) {
544  cond->SetValues(x1, x2);
545  res = true;
546  }
547  if (res) PleaseUpdateSlot();
548  return res;
549 }
550 
552 {
554  if (!fbTypingMode || (cond==0)) return;
555  switch(id) {
556  case 0: cond->SetLabelDraw(on); break;
557  case 1: cond->SetLimitsDraw(on); break;
558  case 2: cond->SetIntDraw(on); break;
559  case 3: cond->SetXMeanDraw(on); break;
560  case 4: cond->SetXRMSDraw(on); break;
561  case 5: cond->SetYRMSDraw(on); break;
562  case 6: cond->SetYMeanDraw(on); break;
563  case 7: cond->SetXMaxDraw(on); break;
564  case 8: cond->SetYMaxDraw(on); break;
565  case 9: cond->SetCMaxDraw(on); break;
566  case 10: cond->SetVisible(on); break;
567  default: return;
568  }
570  RedrawCondition();
571 }
572 
573 
575 {
577 }
578 
579 
581 {
583 }
584 
586 {
588 }
589 
591 {
593 }
594 
596 {
598 }
599 
601 {
603 }
604 
606 {
608 }
609 
611 {
613 }
614 
616 {
618 }
619 
621 {
623 }
624 
626 {
627  ChangeConditionProperty(10, on);
628 }
629 
630 
632 {
633  TGo4Condition* cond = dynamic_cast<TGo4Condition*>(GetLinked("Condition", 0));
634  if (cond==0) return;
635  if (fiLastChangeValue==cond->IsChanged()) return;
636 
637  RefreshWidget(true);
638 }
639 
641 {
642 }
643 
645 {
646  GetLinked("Condition", 2);
647  RefreshWidget(false);
648 }
649 
651 {
652  DrawCondition(true);
653 }
654 
656 {
657  TGo4Condition* cond = dynamic_cast<TGo4Condition*> (GetLinked("Condition",0));
658  if (cond!=0) cond->SetChanged(changed);
659 }
660 
662 {
663  if (PrepareForAnalysis()) {
664  const char* conditem = GetLinkedName("Condition");
665  if (UpdateItemInAnalysis(conditem) && BrowserItemRemote(conditem))
666  RefreshClicked();
667  else {
668  SetChangeFlag(false);
669  RefreshWidget(false);
670  }
671  }
672 }
673 
675 {
676  if (PrepareForAnalysis())
677  if (SaveItemToFile(GetLinkedName("Condition"), "Conditions")) {
678  SetChangeFlag(false);
679  RefreshWidget(false);
680  }
681 }
682 
684 {
685  TGo4Condition* cond = dynamic_cast<TGo4Condition*>(GetLinked("Condition", 0));
686  if (cond==0) return;
687 
688  const char* conditemname = GetLinkedName("Condition");
689  if (conditemname==0) return;
690 
691  TGo4ViewPanel* panel = 0;
692 
693  if (useactive) panel = LastActivePanel();
694  if (panel!=0) {
695  DrawItem(conditemname, panel, 0, false, 0);
696  RedrawCondition();
697  RefreshWidget(false);
698  panel->setFocus();
699  setFocus();
700  return;
701  }
702 
703  panel = WhereItemDrawn(conditemname);
704  TPad* pad = panel==0 ? 0 : panel->FindPadWithItem(conditemname);
705 
706  if (panel!=0) {
707  if (pad!=0)
708  RedrawCondition();
709  else {
710  DrawItem(conditemname, panel, panel->GetActivePad(), false, 0);
711  panel->SetSelectedMarker(pad, cond->GetName(), fiSelectedIndex);
712  panel->MarkPadModified(pad);
713  panel->ShootRepaintTimer(pad);
714  }
715  panel->setFocus();
716  setFocus();
717  return;
718  }
719 
720  const char* hname = 0;
721  if (cond->IsHistogramLink())
722  hname = cond->GetLinkedHistogram();
723  TString hitemname;
724 
725  TGo4BrowserProxy* br = Browser();
726 
727  if (hname!=0)
728  if (br->DefineRelatedObject(conditemname, hname, hitemname)) {
729  panel = DrawItem(hitemname.Data(), 0);
730  RemoveLink("Histogram");
731  AddLink(hitemname.Data(), "Histogram");
732  DrawItem(conditemname, panel, 0, false, 0);
733  RefreshWidget(false);
734  RedrawCondition();
735  panel->setFocus();
736  setFocus();
737  }
738 }
739 
741 {
742  const char* conditemname = GetLinkedName("Condition");
743  if (conditemname==0) return;
744 
745  TGo4Condition* cond = dynamic_cast<TGo4Condition*>(GetLinked("Condition", 0));
746  if (cond==0) return;
747 
748  TGo4ViewPanel* panel = WhereItemDrawn(conditemname);
749  if (panel==0) return;
750 
751  TPad* pad = panel->FindPadWithItem(conditemname);
752  if (pad==0) return;
753 
754  panel->SetSelectedMarker(pad, cond->GetName(), fiSelectedIndex);
755  panel->MarkPadModified(pad);
756  panel->ShootRepaintTimer(pad);
757 }
758 
760 {
761  TGo4Condition* cond = dynamic_cast<TGo4Condition*>(GetLinked("Condition", 0));
762  if (cond!=0)
763  {
764  cond->PrintCondition(kFALSE); // JAM want additional output of specific infos, no poly coords
765  cond->Print("go4log-limits-stats");
766  }
767  }
768 
770 {
771  TGo4Condition* cond = dynamic_cast<TGo4Condition*>(GetLinked("Condition", 0));
772  if (cond==0) return false;
773 
774  SetChangeFlag(false);
775 
776  const char* hname = cond->GetLinkedHistogram();
777  if ((hname!=0) && (strlen(hname)!=0)) {
778  TString foldername, objname;
779  TGo4Slot::ProduceFolderAndName(hname, foldername, objname);
780  cond->SetHistogram(objname.Data());
781  }
782  return true;
783 }
784 
786 {
787  TGo4Condition* cond = dynamic_cast<TGo4Condition*>(GetLinked("Condition", 0));
788  if (cond==0) return;
789 
790  const char* conditemname = GetLinkedName("Condition");
791  TGo4ViewPanel* panel = WhereItemDrawn(conditemname);
792  TPad* pad = panel==0 ? 0 : panel->FindPadWithItem(conditemname);
793 
794  if ((panel==0) || (pad==0)) return;
795 
796  panel->SetActivePad(pad);
797 
798  panel->setFocus();
799 
800  panel->SetSelectedMarker(pad, cond->GetName(), fiSelectedIndex);
801 
802  panel->StartConditionEditing(pad);
803 }
804 
806 {
807  bool old = fbTypingMode;
808  fbTypingMode = false;
809 
810  if (cut==0) {
811  CutTable->setRowCount(0);
812  NPointsSpin->setValue(0);
813  } else {
814  CutTable->setRowCount(cut->GetN());
815  NPointsSpin->setValue(cut->GetN());
816  for (int n=0;n<cut->GetN();n++) {
817  Double_t x,y;
818  cut->GetPoint(n, x,y);
819  CutTable->setItem(n, 0, new QTableWidgetItem(QString::number(x)));
820  CutTable->setItem(n, 1, new QTableWidgetItem(QString::number(y)));
821  CutTable->setVerticalHeaderItem(n, new QTableWidgetItem(QString::number(n)));
822  }
823  }
824 
825  fbTypingMode = old;
826 }
827 
829 {
830  if(elli==0) return;
831  bool old = fbTypingMode;
832  fbTypingMode = false;
833  double a1=0,a2=0,x=0,y=0;
834  int theta=0;
835 
836  elli->GetRadius(a1,a2);
837  elli-> GetCenter(x,y);
838  theta= (int) elli->GetTheta();
839 
840  EllipseCxSpinbox->setValue(x);
841  EllipseCySpinbox->setValue(y);
842  EllipseA1Spinbox->setValue(a1);
843  EllipseA2Spinbox->setValue(a2);
844  EllipseTiltDial->setValue(theta);
845  EllipseTiltEdit->setText(QString::number(theta));
846 
847  CircleBox->setChecked(elli->IsCircle());
848  EllipseBox->setChecked(elli->IsEllipse());
849  BoxshapeBox->setChecked(elli->IsBox());
850  FreeshapeBox->setChecked(elli->IsFreeShape());
851  EllipseNptsSpin->setValue(elli->GetResolution());
852  fbTypingMode = old;
853 }
854 
856 {
857 
858 
859  EllipseCxSpinbox->setVisible(show);
860  EllipseCySpinbox->setVisible(show);
861  EllipseA1Spinbox->setVisible(show);
862  EllipseA2Spinbox->setVisible(show);
863  EllipseTiltDial->setVisible(show);
864  EllipseTiltEdit->setVisible(show);
865 
866  ShapegroupBox->setVisible(show);
867  CircleBox->setVisible(show);
868  EllipseBox->setVisible(show);
869  BoxshapeBox->setVisible(show);
870  FreeshapeBox->setVisible(show);
871  EllipseNptsSpin->setVisible(show);
872 
873  AutoRefreshBox->setVisible(show);
874  EllipseCenterLabel->setVisible(show);
875  EllipseTitlLabel->setVisible(show);
876  EllipseRadiusLabel->setVisible(show);
877  EllipseNptsLabel->setVisible(show);
878  EllipsCxLabel->setVisible(show);
879  EllipsCyLabel->setVisible(show);
880  EllipsA1Label->setVisible(show);
881  EllipsA2Label->setVisible(show);
882 
883  verticalLayout_2->setEnabled(show);
884  verticalLayout_5->setEnabled(show);
885  horizontalLayout_4->setEnabled(show);
886 
887 }
888 
889 
891 {
892  if (!fbTypingMode) return;
893 
894  TGo4PolyCond* pcond = dynamic_cast<TGo4PolyCond*> (SelectedCondition());
895  if (pcond==0) return;
896 
897  TCutG* cut = pcond->GetCut(kFALSE);
898 
899  if (cut==0) {
900  cut = new TCutG("conditioncut", npoint);
901  Double_t x=0., y=0.;
902  for (int n=0;n<npoint-1; n++)
903  cut->SetPoint(n, n*10, n*10);
904  cut->GetPoint(0, x, y);
905  cut->SetPoint(npoint-1, x, y);
906  pcond->SetValues(cut);
907  } else {
908  if (npoint==0) {
909  pcond->SetValues(0);
910  cut = 0;
911  } else {
912  int old = cut->GetN();
913  Double_t x=0., y=0.;
914  if (old>1) cut->GetPoint(old-2, x, y);
915  cut->Set(npoint);
916  for(int n= (old-1>=0 ? old-1 : 0); n<npoint-1; n++)
917  cut->SetPoint(n, x, y+(n-old+2)*10);
918  cut->GetPoint(0, x, y);
919  cut->SetPoint(npoint-1, x, y);
920  }
921  }
922 
924 
925  FillCutWidget(cut);
926 
927  RedrawCondition();
928 }
929 
931 {
932  if (!fbTypingMode) return;
933 
934  TGo4PolyCond* pcond = dynamic_cast<TGo4PolyCond*> (SelectedCondition());
935  TCutG* cut = pcond==0 ? 0 : pcond->GetCut(kFALSE);
936  if (cut==0) return;
937 
938  bool ok;
939  double zn = CutTable->item(nrow, ncol)->text().toDouble(&ok);
940 
941  if (!ok) return;
942  if (ncol==0) cut->GetX()[nrow] = zn;
943  else cut->GetY()[nrow] = zn;
944  if ((nrow==0) || (nrow==cut->GetN()-1)) {
945  int nrow1 = (nrow==0) ? cut->GetN()-1 : 0;
946  fbTypingMode = false;
947  CutTable->setItem(nrow1, ncol, new QTableWidgetItem(CutTable->item(nrow, ncol)->text()));
948  if (ncol==0) cut->GetX()[nrow1] = zn;
949  else cut->GetY()[nrow1] = zn;
950  fbTypingMode = true;
951  }
952 
954 
955  RedrawCondition();
956 }
957 
958 
960 {
961  if (!fbTypingMode) return;
962 
963  QTableWidgetItem* item = CutTable->itemAt (pos);
964 
965  TGo4PolyCond* pcond = dynamic_cast<TGo4PolyCond*> (SelectedCondition());
966  TCutG* cut = pcond==0 ? 0 : pcond->GetCut(kFALSE);
967  if ((cut==0) || (item==0)) return;
968 
969  int nrow = CutTable->row(item);
970 
971  QMenu menu(this);
972  QSignalMapper map(this);
973  AddIdAction(&menu, &map, "Insert point", nrow);
974  // only internal points should be allowed to deleted
975  AddIdAction(&menu, &map, "Delete point", nrow+1000000, (nrow>0) && (nrow<cut->GetN()-1));
976  connect(&map, SIGNAL(mapped(int)), this, SLOT(ContextMenuSlot(int)));
977  menu.exec(CutTable->mapToGlobal(pos));
978 }
979 
981 {
982  TGo4PolyCond* pcond = dynamic_cast<TGo4PolyCond*> (SelectedCondition());
983  TCutG* cut = pcond==0 ? 0 : pcond->GetCut(kFALSE);
984  if (cut==0) return;
985 
986  if (id>=1000000) { // delete point
987  id-=1000000;
988  cut->RemovePoint(id);
989  } else { // insert point
990  Int_t npoints = cut->GetN();
991  if (id>=npoints) return;
992  cut->Set(npoints+1);
993 
994  Double_t x,y;
995 
996  for(int n=npoints;n>id;n--) {
997  cut->GetPoint(n-1, x, y);
998  cut->SetPoint(n, x, y);
999  }
1000 
1001  if (id>0) {
1002  Double_t x1, y1;
1003  cut->GetPoint(id-1, x1, y1);
1004  cut->SetPoint(id, (x1+x)/2., (y+y1)/2.);
1005  }
1006  }
1007 
1008  FillCutWidget(cut);
1009 
1010  PleaseUpdateSlot();
1011 
1012  RedrawCondition();
1013 }
1014 
1015 
1016 
1018 {
1019  if (!fbTypingMode) return;
1020  //std::cout <<"EllipseTheta_valueChanged to "<< deg << std::endl;
1021  EllipseTiltEdit->setText(QString::number(deg));
1023  {
1024  TGo4ShapedCond* econd = dynamic_cast<TGo4ShapedCond*> (SelectedCondition());
1025  if(econd) econd->SetTheta((double) deg);
1026  PleaseUpdateSlot();
1027  RedrawCondition();
1028  }
1029 
1030 }
1031 
1032 
1034 {
1035  if (!fbTypingMode) return;
1036  //std::cout <<"EllipseCx_valueChanged to "<< x << std::endl;
1038  {
1039  TGo4ShapedCond* econd = dynamic_cast<TGo4ShapedCond*> (SelectedCondition());
1040  if(econd) {
1041  double y=EllipseCySpinbox->value();
1042  econd->SetCenter(x, y);
1043  PleaseUpdateSlot();
1044  RedrawCondition();
1045  }
1046  }
1047 }
1049 {
1050  if (!fbTypingMode) return;
1051  //std::cout <<"EllipseCy_valueChanged to "<< y << std::endl;
1053  {
1054  TGo4ShapedCond* econd = dynamic_cast<TGo4ShapedCond*> (SelectedCondition());
1055  if(econd) {
1056  double x=EllipseCxSpinbox->value();
1057  econd->SetCenter(x,y);
1058  }
1059  PleaseUpdateSlot();
1060  RedrawCondition();
1061  }
1062 }
1063 
1064 
1066 {
1067  if (!fbTypingMode) return;
1068  //std::cout <<"EllipseA1_valueChanged to "<< r1 << std::endl;
1070 }
1071 
1073 {
1074  if (!fbTypingMode) return;
1075  //std::cout <<"EllipseA2_valueChanged to "<< r2 << std::endl;
1077 }
1078 
1079 
1081 {
1082  if (!fbTypingMode) return;
1083  //std::cout <<"EllipseRefreshBox_toggled "<< on<< std::endl;
1086 
1087 
1088 }
1089 
1090 
1092 {
1093  if (!fbTypingMode) return;
1094  //std::cout <<"EllipseCircleBox_toggled "<< on<< std::endl;
1096 
1097 
1098 }
1099 
1100 
1102 {
1103  if (!fbTypingMode) return;
1104  //std::cout <<"EllipseTheta_returnPressed() "<< std::endl;
1105  bool ok = false;
1106  Int_t theta = EllipseTiltEdit->text().toInt(&ok);
1107  if(theta<0) theta=0;
1108  theta = theta % 360;
1109  if(ok)
1110  {
1111  EllipseTiltDial->setValue(theta);
1112  }
1114 
1115 }
1116 
1118 {
1119  if (!fbTypingMode) return;
1120  //std::cout <<"EllipseNPoints_valueChanged "<< std::endl;
1122 }
1123 
1124 
1126 {
1127 
1128  TGo4ShapedCond* econd = dynamic_cast<TGo4ShapedCond*> (SelectedCondition());
1129  if(econd==0){
1130  std::cout <<"UpdateEllipse did not find ellipse condition!!!"<< std::endl;
1131  return;
1132  }
1133 
1134 
1135 
1136  if (FreeshapeBox->isChecked())
1137  {
1138  econd->SetFreeShape();
1139  }
1140  else
1141  {
1142  double cx = EllipseCxSpinbox->value();
1143  double cy = EllipseCySpinbox->value();
1144  double a1 = EllipseA1Spinbox->value();
1145  double a2 = EllipseA2Spinbox->value();
1146  double th = EllipseTiltDial->value();
1147  if(econd->IsFreeShape())
1148  {
1149  // transition from free shape to other form: use polygon geometry to init pars:
1150  cx= (econd->GetXUp() + econd->GetXLow())/2; // mean of coordinates is center
1151  cy= (econd->GetYUp() + econd->GetYLow())/2;
1152  //a1=(econd->GetXUp() - econd->GetXLow())/2; // half diameter is radius
1153  //a2=(econd->GetYUp() - econd->GetYLow())/2;
1154  // better: use minimum and maximum radial distance
1155  TCutG* cut=econd->GetCut(false);
1156  Int_t n = cut->GetN();
1157  Double_t* xarr=cut->GetX();
1158  Double_t* yarr=cut->GetY();
1159  TArrayD rarr(n);
1160  for (int i=0; i<n; ++i)
1161  {
1162  rarr[i]= TMath::Sqrt(TMath::Power((xarr[i]-cx),2) + TMath::Power((yarr[i]-cy),2));
1163  }
1164  Int_t nrmax=TMath::LocMax(n,rarr.GetArray());
1165  Int_t nrmin=TMath::LocMin(n,rarr.GetArray());
1166  a1=rarr[nrmax];
1167  a2=rarr[nrmin];
1168  // now evaluate angle:
1169  th=0;
1170  if(a1){
1171  th= TMath::ACos((econd->GetXUp() - cx)/a1) * 180/TMath::Pi();
1172  }
1173  }
1174 
1175 
1176  if (CircleBox->isChecked())
1177  econd->SetCircle(cx, cy, a1, EllipseNptsSpin->value());
1178  else if (EllipseBox->isChecked())
1179  econd->SetEllipse(cx, cy, a1, a2, th, EllipseNptsSpin->value());
1180  else if (BoxshapeBox->isChecked())
1181  {
1182  if (econd->IsFreeShape())
1183  {
1184  // transition to box will use different defaults for extensions, otherwise we always get increasing box
1185  a1 = (econd->GetXUp() - econd->GetXLow()) / 2; // half diameter is radius
1186  a2 = (econd->GetYUp() - econd->GetYLow()) / 2;
1187  th = 0; // todo: correctly conserve tilt angle when switching to/fro between free and box
1188  }
1189 
1190  econd->SetBox(cx, cy, a1, a2, th);
1191  }
1192  } // no freeshape selected
1193  PleaseUpdateSlot();
1194  RedrawCondition();
1195  FillEllipseWidget(econd);
1196 }
virtual void ShootRepaintTimer()
virtual void ResetWidget()
Definition: QGo4Widget.cpp:51
void SetTheta(Double_t angle)
Bool_t IsHistogramLink()
virtual Bool_t IsYRMSDraw()
virtual void SetYMeanDraw(bool on)
virtual void SetChanged(Bool_t on)
virtual void LimitsReturnPressed()
void GetRadius(Double_t &a1, Double_t &a2)
virtual Bool_t IsLabelDraw()
void SetEllipse(Double_t cx, Double_t cy, Double_t a1, Double_t a2, Double_t theta=0, Int_t npoints=0)
virtual void enterEvent(QEvent *)
virtual Double_t GetXUp()
virtual Double_t GetXMax(TH1 *histo)
virtual Double_t GetMean(TH1 *histo, Int_t axis=1)
bool UpdateItemInAnalysis(const char *itemname, TObject *obj=0)
Definition: QGo4Widget.cpp:383
virtual const char * GetDrawObjectLinkName(TPad *pad, TObject *obj)
virtual void SetLimitsDraw(Bool_t on)
virtual void SelectedCond(int t)
virtual void RefreshWidget(bool checkindex)
virtual void SetActivePad(TPad *pad)
virtual void PrintConditionLog()
virtual Double_t GetCMax(TH1 *histo)
void ShootCloseWidget(bool closeparent=false)
Definition: QGo4Widget.cpp:69
virtual QString GetSelectedMarkerName(TPad *pad)
virtual void StartConditionEditing(TPad *pad)
virtual Int_t IsChanged()
Bool_t IsCircle()
virtual void SetXMeanDraw(bool on)
virtual void leaveEvent(QEvent *)
virtual void SetYRMSDraw(Bool_t on)
virtual void SetChangeFlag(bool changed)
TObject * GetLinked(const char *linkname, int updatelevel)
Definition: QGo4Widget.cpp:176
Int_t GetDimension()
virtual void EllipseTheta_valueChanged(int deg)
virtual Bool_t IsXMeanDraw()
virtual void PrintCondition(Bool_t full=kTRUE)
virtual bool PrepareForAnalysis()
virtual Bool_t IsLimitsDraw()
virtual void EllipseNPoints_valueChanged(int npoint)
TGo4ServerProxy * DefineServerObject(const char *itemname, TString *objname=0, Bool_t onlyanalysis=kTRUE)
Bool_t IsEnabled() const
Definition: TGo4Condition.h:94
virtual Bool_t IsYMeanDraw()
virtual Double_t GetYUp()
virtual void EllipseA1_valueChanged(double r1)
virtual void SetVisible(Bool_t on)
Int_t GetResolution()
virtual void SetValues()
QAction * AddIdAction(QMenu *menu, QSignalMapper *map, const QString &text, int id, int enabled, int checked)
Definition: QGo4Widget.cpp:419
virtual TGo4Condition * SelectedCondition()
virtual void SetYRMSDraw(bool on)
virtual void SetXMaxDraw(Bool_t on)
void SetCenter(Double_t x, Double_t y)
virtual void SetYMaxDraw(bool on)
const char * GetLinkedName(const char *linkname)
Definition: QGo4Widget.cpp:157
virtual void ChangeConditionProperty(int id, bool on)
virtual void SetIntDraw(bool on)
virtual void ShowEllipseWidget(bool show)
virtual void linkedObjectRemoved(const char *linkname)
virtual Bool_t IsIntDraw()
TGo4BrowserProxy * Browser()
Definition: QGo4Widget.cpp:223
virtual void ResetCounts()
virtual Bool_t IsXRMSDraw()
virtual void ClearAnalysisObject(const char *fullpath)
Bool_t FixedResult() const
virtual void LimitsChanged(const QString &)
virtual void EllipseCircleBox_toggled(bool on)
virtual void SetYMaxDraw(Bool_t on)
virtual bool IsAcceptDrag(const char *itemname, TClass *cl, int kind)
virtual void SetValues(Double_t *x, Double_t *y, Int_t len)
virtual void SetInvertMode(int mode)
TCutG * GetCut(Bool_t changeowner)
virtual void Enable()
virtual void RedrawCondition()
virtual void ModifyButton_clicked()
virtual Double_t GetYUp()
bool BrowserItemRemote(const char *itemname)
Definition: QGo4Widget.cpp:216
virtual Bool_t IsXMaxDraw()
Bool_t IsEllipse()
virtual void SetSelectedMarker(TPad *pad, const QString &selname, int selindex)
virtual Bool_t IsVisible()
virtual void ContextMenuSlot(int)
void RemoveLink(const char *linkname, bool blockreset=true)
Definition: QGo4Widget.cpp:192
virtual void SetIntDraw(Bool_t on)
virtual void MarkPadModified(TPad *pad)
virtual void EllipseCy_valueChanged(double y)
TGo4ViewPanel * DrawItem(const QString &itemname, TGo4ViewPanel *panel=0, TPad *pad=0, bool activate=true, int updatelevel=-1)
Definition: QGo4Widget.cpp:311
virtual void Print(Option_t *opt="") const
Bool_t IsFreeShape()
virtual void DrawCondition(bool useactive)
void SetCircle(Double_t cx, Double_t cy, Double_t r, Int_t npoints=0)
virtual void SetCMaxDraw(bool on)
virtual void SetYMeanDraw(Bool_t on)
virtual TPad * FindPadWithItem(const char *itemname)
void SetHistogram(const char *name)
Bool_t IsTrue() const
virtual void SetXRMSDraw(bool on)
virtual void Disable(Bool_t result)
virtual Bool_t CanSubmitObjects()
Bool_t DefineRelatedObject(const char *itemname, const char *objectname, TString &objectitem, Int_t mask=3)
TGo4ConditionEditor(QWidget *parent=0, const char *name=0)
virtual void FillCutWidget(TCutG *cut)
virtual int GetSelectedMarkerIndex(TPad *pad)
void SetMultiEdit(Bool_t on)
virtual void CutTable_valueChanged(int ncol, int nrow)
virtual Double_t GetXLow()
TGo4ViewPanel * LastActivePanel()
Definition: QGo4Widget.cpp:344
virtual void SetXMeanDraw(Bool_t on)
virtual void EllipseRefreshBox_toggled(bool on)
static void ProduceFolderAndName(const char *fullname, TString &foldername, TString &objectname)
Definition: TGo4Slot.cxx:668
virtual void EllipseTheta_returnPressed()
virtual void EllipseA2_valueChanged(double r2)
virtual TH1 * GetPadHistogram(TPad *pad)
TGo4ViewPanel * WhereItemDrawn(const char *itemname)
Definition: QGo4Widget.cpp:322
virtual void FillEllipseWidget(TGo4ShapedCond *elli)
virtual void EllipseCx_valueChanged(double x)
virtual Double_t GetYMax(TH1 *histo)
virtual void SetLabelDraw(Bool_t on)
Double_t GetTheta()
virtual void SetDrawLimits(bool on)
virtual void SetLabel(bool on)
virtual void PleaseUpdateSlot()
TGo4ServerProxy * DefineAnalysisObject(const char *itemname, TString &analysisname)
bool SaveItemToFile(const char *itemname, const char *subfolder=0)
Definition: QGo4Widget.cpp:374
virtual void SetXMaxDraw(bool on)
virtual void NPointsSpin_valueChanged(int npoint)
void AddLink(const char *itemname, const char *linkname)
Definition: QGo4Widget.cpp:121
TGo4Condition * At(Int_t i)
virtual Double_t GetXUp()
virtual Double_t GetRMS(TH1 *histo, Int_t axis=1)
virtual void SetResultMode(int mode)
virtual void SetCurrentIndex(Int_t ix)
void SetBox(Double_t cx, Double_t cy, Double_t a1, Double_t a2, Double_t theta=0)
const char * GetLinkedHistogram()
virtual void SetCondVisible(bool on)
virtual Int_t TrueCounts()
virtual void linkedObjectUpdated(const char *linkname, TObject *obj)
virtual Bool_t IsCMaxDraw()
virtual void SetXRMSDraw(Bool_t on)
virtual Int_t Counts()
virtual TPad * GetActivePad()
virtual Double_t GetXLow()
virtual void CutTable_contextMenuRequested(const QPoint &)
virtual void DropItem(const char *itemname, TClass *cl, int kind)
virtual TCanvas * GetCanvas()
Int_t GetNumber() const
virtual Bool_t IsYMaxDraw()
virtual void WorkWithCondition(const char *itemname)
virtual Double_t GetIntegral(TH1 *histo, Option_t *opt="")
virtual void Invert(Bool_t on)
virtual void SetCMaxDraw(Bool_t on)
virtual Double_t GetYLow()
virtual Double_t GetYLow()