00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "Riostream.h"
00018
00019
00020 class TGo4FitGuiArrow : public TArrow {
00021
00022 public:
00023
00024 enum { at_none, at_pos, at_width, at_range };
00025
00026 TGo4FitGuiArrow();
00027 TGo4FitGuiArrow(Float_t arrowsize, Option_t* option);
00028 TGo4FitGuiArrow(Double_t x1, Double_t y1, Double_t x2, Double_t y2, Float_t arrowsize, Option_t* option);
00029 virtual ~TGo4FitGuiArrow();
00030
00031 void SetForPosition(TGo4FitModel* model, TGo4FitGuiArrow* forwidth, Double_t iLineAmpl);
00032 void SetForWidth(TGo4FitModel* model, TGo4FitGuiArrow* forposition);
00033 void SetForRange(TGo4FitComponent* Comp, Int_t num, Double_t rangey, Double_t shiftx);
00034 void SetItem(QFitItem* item, TGo4FitPanel* panel);
00035
00036 QFitItem* GetItem() { return fxItem; }
00037
00038 Bool_t Locate();
00039
00040 Int_t GetType() { return fxType; }
00041 TGo4FitModel* GetModel() { return fxModel; }
00042 TGo4FitComponent* GetComp() { return fxComp; }
00043
00044 Bool_t IsAssignTo(TObject* obj);
00045
00046 void ClearOther() { fxOther = 0; }
00047 virtual void Delete(Option_t* option="");
00048
00049 virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py);
00050
00051 private:
00052 Int_t fxType;
00053 TGo4FitModel* fxModel;
00054 TGo4FitGuiArrow* fxOther;
00055 Double_t fdLineAmpl;
00056 TGo4FitComponent* fxComp;
00057 Int_t fiRangeNum;
00058 Double_t fdRangeY;
00059 Double_t fdShiftX;
00060 QFitItem* fxItem;
00061 TGo4FitPanel* fxPanel;
00062 };
00063
00064
00065
00066 TGo4FitGuiArrow::TGo4FitGuiArrow() :
00067 TArrow(), fxType(at_none), fxModel(0), fxOther(0), fdLineAmpl(0.), fxComp(0), fiRangeNum(0),
00068 fdRangeY(0.), fdShiftX(0.), fxItem(0), fxPanel(0)
00069 {
00070 }
00071
00072 TGo4FitGuiArrow::TGo4FitGuiArrow(Float_t arrowsize, Option_t* option) :
00073 TArrow(0.,0.,0.,0.,arrowsize,option), fxType(at_none), fxModel(0), fxOther(0), fdLineAmpl(0.), fxComp(0), fiRangeNum(0),
00074 fdRangeY(0.), fdShiftX(0.), fxItem(0), fxPanel(0)
00075 {
00076 }
00077
00078 TGo4FitGuiArrow::TGo4FitGuiArrow(Double_t x1, Double_t y1, Double_t x2, Double_t y2, Float_t arrowsize, Option_t* option) :
00079 TArrow(x1,y1,x2,y2,arrowsize,option), fxType(at_none), fxModel(0), fxOther(0), fdLineAmpl(0.), fxComp(0), fiRangeNum(0),
00080 fdRangeY(0.), fdShiftX(0.), fxItem(0), fxPanel(0)
00081 {
00082 }
00083
00084 TGo4FitGuiArrow::~TGo4FitGuiArrow()
00085 {
00086 }
00087
00088 void TGo4FitGuiArrow::SetForPosition(TGo4FitModel* model, TGo4FitGuiArrow* forwidth, Double_t iLineAmpl)
00089 {
00090 fxType = at_pos;
00091 fxModel = model;
00092 fxOther = forwidth;
00093 fdLineAmpl = iLineAmpl;
00094 }
00095
00096 void TGo4FitGuiArrow::SetForWidth(TGo4FitModel* model, TGo4FitGuiArrow* forposition)
00097 {
00098 fxType = at_width;
00099 fxModel = model;
00100 fxOther = forposition;
00101 }
00102
00103 void TGo4FitGuiArrow::SetForRange(TGo4FitComponent* Comp, Int_t num, Double_t rangey, Double_t shiftx) {
00104 fxType = at_range;
00105 fxComp = Comp;
00106 fiRangeNum = num;
00107 fdRangeY = rangey;
00108 fdShiftX = shiftx;
00109 }
00110
00111 void TGo4FitGuiArrow::SetItem(QFitItem* item, TGo4FitPanel* panel)
00112 {
00113 fxItem = item;
00114 fxPanel = panel;
00115 }
00116
00117 Bool_t TGo4FitGuiArrow::Locate()
00118 {
00119 Double_t x1 = GetX1(), x2 = GetX2();
00120 Double_t y1 = GetY1(), y2 = GetY2();
00121
00122 switch (fxType) {
00123 case at_pos:
00124 Double_t pos;
00125 if (fxModel->GetPosition(0,pos)) {
00126 SetX1(pos); SetX2(pos); SetY1(fdLineAmpl/2); SetY2(fdLineAmpl);
00127 }
00128 break;
00129 case at_width:
00130 Double_t width, ppp;
00131 if ((fxModel->GetWidth(0,width)) && (fxModel->GetPosition(0,ppp))) {
00132 SetX1(ppp-width); SetX2(ppp+width);
00133 SetY1(fxOther->GetY1());
00134 SetY2(fxOther->GetY1());
00135 }
00136 break;
00137 case at_range:
00138 Int_t typ, naxis;
00139 Double_t left, right;
00140 fxComp->GetRangeCondition(fiRangeNum, typ, naxis, left, right);
00141 switch (typ) {
00142 case 0: SetX1(left); SetX2(right); break;
00143 case 1: SetX1(left); SetX2(right); break;
00144 case 2: SetX1(left); SetX2(left+fdShiftX); break;
00145 case 3: SetX1(right-fdShiftX); SetX2(right); break;
00146 }
00147 SetY1(fdRangeY); SetY2(fdRangeY);
00148
00149 break;
00150 }
00151
00152 return (x1 != GetX1()) || (x2 != GetX2()) || (y1 != GetY1()) || (y2 != GetY2());
00153 }
00154
00155 Bool_t TGo4FitGuiArrow::IsAssignTo(TObject* obj)
00156 {
00157 return (obj!=0) && ((obj==fxModel) || (obj==fxComp));
00158 }
00159
00160 void TGo4FitGuiArrow::Delete(Option_t* option)
00161 {
00162 if ((fxType==at_pos) && (fxPanel!=0))
00163 fxPanel->DeleteModelWithPrimit(this);
00164 }
00165
00166 void TGo4FitGuiArrow::ExecuteEvent(Int_t event, Int_t px, Int_t py)
00167 {
00168 TArrow::ExecuteEvent(event,px,py);
00169 if (event!=kButton1Up) return;
00170
00171 switch (fxType) {
00172
00173 case at_pos: {
00174 fxModel->SetPosition(0, GetX2());
00175 fdLineAmpl = (GetY1()>GetY2()) ? GetY1() : GetY2();
00176 if (fxPanel) fxPanel->ArrowChanged(this);
00177 break; }
00178
00179 case at_width: {
00180 Double_t width = 0;
00181 fxModel->GetWidth(0,width);
00182 Double_t pos = fxOther->GetX2();
00183
00184 Double_t w0 = (GetX2()-GetX1())/2;
00185 Double_t w1 = pos-GetX1();
00186 Double_t w2 = GetX2()-pos;
00187
00188 if (TMath::Abs(w0-width)>1e-10) {
00189 Double_t w = width;
00190 if (TMath::Abs(w1-width)>1e-10) w=w1; else w=w2;
00191 if (w>0) {
00192 width=w;
00193 fxModel->SetWidth(0,width);
00194 if (fxPanel) fxPanel->ArrowChanged(this);
00195 }
00196 }
00197 break; }
00198
00199 case at_range: {
00200 Int_t typ, naxis;
00201 Double_t left, right;
00202 fxComp->GetRangeCondition(fiRangeNum,typ,naxis,left,right);
00203
00204 left = GetX1()<GetX2() ? GetX1() : GetX2();
00205 right = GetX1()>GetX2() ? GetX1() : GetX2();
00206
00207 fxComp->SetRangeCondition(fiRangeNum,typ,naxis,left,right);
00208
00209 if (fxPanel) fxPanel->ArrowChanged(this);
00210
00211 break; }
00212
00213 }
00214 }
00215
00216
00217
00218
00219 static const char* SelectedXPM[]={
00220 "12 12 5 1",
00221 "# c #000000",
00222 "a c #ffffff",
00223 "c c #808080",
00224 "b c #c0c0c0",
00225 ". c None",
00226 "############",
00227 "#aaaaaaaaaa#",
00228 "#aaaaaaa##a#",
00229 "#aaaaaaa##a#",
00230 "#aaaaaa##aa#",
00231 "#a##aaa##aa#",
00232 "#a##aa##aaa#",
00233 "#aa##a##aaa#",
00234 "#aa####aaaa#",
00235 "#aaa##aaaaa#",
00236 "#aaaaaaaaaa#",
00237 "############"};
00238
00239 static const char* UnselectedXPM[]={
00240 "12 12 5 1",
00241 "# c #000000",
00242 "a c #ffffff",
00243 "c c #808080",
00244 "b c #c0c0c0",
00245 ". c None",
00246 "############",
00247 "#aaaaaaaaaa#",
00248 "#aaaaaaaaaa#",
00249 "#aaaaaaaaaa#",
00250 "#aaaaaaaaaa#",
00251 "#aaaaaaaaaa#",
00252 "#aaaaaaaaaa#",
00253 "#aaaaaaaaaa#",
00254 "#aaaaaaaaaa#",
00255 "#aaaaaaaaaa#",
00256 "#aaaaaaaaaa#",
00257 "############"};
00258
00259 void TGo4FitPanel::init()
00260 {
00261
00262
00263
00264 fbFreezeMode = false;
00265 fiPanelMode = FitGui::pm_Wizard;
00266 fbParsWidgetShown = false;
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278 fbNeedConfirmation = go4sett->getBool("/FitPanel/NeedConfirmation", false);
00279 fbShowPrimitives = go4sett->getBool("/FitPanel/ShowPrimitives", true);
00280 fbSaveWithReferences = go4sett->getBool("/FitPanel/SaveWithReferences", false);
00281 fbUseCurrentRange = go4sett->getBool("/FitPanel/UseCurrentRange", true);
00282 fbDrawModels = go4sett->getBool("/FitPanel/DrawModels", true);
00283 fbDrawComponents = go4sett->getBool("/FitPanel/DrawComponents", false);
00284 fbUseSamePanelForDraw = go4sett->getBool("/FitPanel/UseSamePanelForDraw",true);
00285 fbDrawBackground = go4sett->getBool("/FitPanel/DrawBackground", false);
00286 fbDrawInfoOnPad = go4sett->getBool("/FitPanel/DrawInfoOnPad", false);
00287 fbRecalculateGaussWidth = go4sett->getBool("/FitPanel/RecalculateGaussWidth", true);
00288 fiIntegralMode = go4sett->getInt("/FitPanel/IntegralMode", 0);
00289 fiBuffersUsage = go4sett->getInt("/FitPanel/BuffersUsage", 1);
00290
00291
00292 fxWizDataName = "";
00293 fxWizModelName = "";
00294 fbWizShowAllModels = true;
00295 fiWizPageIndex = 0;
00296 fbUseAmplEstim = false;
00297 fiNumMigradIter = 0;
00298
00299 fxCurrentItem = 0;
00300
00301 fxActivePanel = 0;
00302 fxActivePad = 0;
00303
00304 fxDrawNewPanel = 0;
00305 fbDrawPanelCreation = false;
00306
00307 TGo4WorkSpace* ws = TGo4WorkSpace::Instance();
00308 connect(ws, SIGNAL(panelSignal(TGo4ViewPanel*, TPad*, int)),
00309 this, SLOT(panelSlot(TGo4ViewPanel*, TPad*, int)));
00310
00311 MenuBar = new QMenuBar( this, "menubar" );
00312 MenuBar->setFrameShape(QFrame::NoFrame);
00313
00314 FitterMenu = new QPopupMenu( this );
00315 MenuBar->insertItem( "&Fitter",FitterMenu);
00316 connect(FitterMenu, SIGNAL(aboutToShow()), this, SLOT(AboutToShowFitterMenu()) );
00317
00318 ViewMenu = new QPopupMenu( this );
00319 MenuBar->insertItem( "&Tools",ViewMenu);
00320 connect(ViewMenu, SIGNAL(aboutToShow()), this, SLOT(AboutToShowViewMenu()) );
00321
00322 SettMenu = new QPopupMenu( this );
00323 MenuBar->insertItem( "&Settings", SettMenu);
00324 connect(SettMenu, SIGNAL(aboutToShow()), this, SLOT(AboutToShowSettMenu()) );
00325
00326 SettMenu->insertItem("&Confirmation", this, SLOT(ChangeSettings(int)), 0, 1);
00327 SettMenu->insertItem("&Show primitives", this, SLOT(ChangeSettings(int)), 0, 2);
00328 SettMenu->insertItem("&Freeze mode", this, SLOT(ChangeSettings(int)), 0, 3);
00329 SettMenu->insertItem("&Save with objects", this, SLOT(ChangeSettings(int)), 0, 4);
00330
00331 SettMenu->insertSeparator();
00332
00333 SettMenu->insertItem("&Use current range", this, SLOT(ChangeSettings(int)), 0, 10);
00334 SettMenu->insertItem("&Draw model", this, SLOT(ChangeSettings(int)), 0, 11);
00335 SettMenu->insertItem("Draw &background", this, SLOT(ChangeSettings(int)), 0, 14);
00336 SettMenu->insertItem("Dra&w components", this, SLOT(ChangeSettings(int)), 0, 12);
00337 SettMenu->insertItem("Draw on same &pad", this, SLOT(ChangeSettings(int)), 0, 13);
00338 SettMenu->insertItem("Draw &info on pad", this, SLOT(ChangeSettings(int)), 0, 15);
00339
00340 SettMenu->insertSeparator();
00341
00342 SettMenu->insertItem("&No &integral", this, SLOT(ChangeSettings(int)), 0, 17);
00343 SettMenu->insertItem("&Counts", this, SLOT(ChangeSettings(int)), 0, 18);
00344 SettMenu->insertItem("&Integral", this, SLOT(ChangeSettings(int)), 0, 19);
00345 SettMenu->insertItem("&Gauss integral", this, SLOT(ChangeSettings(int)), 0, 20);
00346
00347 SettMenu->insertItem("Recalculate gauss &widths", this, SLOT(ChangeSettings(int)), 0, 16);
00348
00349 SettMenu->insertSeparator();
00350
00351 SettMenu->insertItem("&Do not use buffers", this, SLOT(ChangeSettings(int)), 0, 21);
00352 SettMenu->insertItem("&Only for data", this, SLOT(ChangeSettings(int)), 0, 22);
00353 SettMenu->insertItem("&For data and models", this, SLOT(ChangeSettings(int)), 0, 23);
00354 SettMenu->insertItem("&Individual settings", this, SLOT(ChangeSettings(int)), 0, 24);
00355
00356 ItemMenu = 0;
00357
00358 fxWizPars = new TObjArray();
00359 fxWizSlots = new TObjArray();
00360 fxParsTableList = new TObjArray();
00361
00362 fiPaintMode = 0;
00363
00364 TGo4FitPanelLayout->setMargin(3);
00365 TGo4FitPanelLayout->setSpacing(1);
00366
00367 UpdateActivePage();
00368 }
00369
00370 void TGo4FitPanel::destroy()
00371 {
00372
00373 fxCurrentItem = 0;
00374 FitList->clear();
00375
00376 delete fxParsTableList;
00377 delete fxWizSlots;
00378 delete fxWizPars;
00379
00380 RemovePrimitives();
00381 RemoveDrawObjects();
00382 CloseDrawPanel();
00383
00384 ClearObjectReferenceInSlots();
00385 }
00386
00387
00388
00389
00390 bool TGo4FitPanel::IsAcceptDrag( const char* itemname, TClass * cl, int kind )
00391 {
00392 if (cl==0) return false;
00393
00394 return (cl->InheritsFrom(TGo4Fitter::Class())) ||
00395 (cl->InheritsFrom(TH1::Class())) ||
00396 (cl->InheritsFrom(TGraph::Class()));
00397 }
00398
00399 void TGo4FitPanel::DropOnPanel( QDropEvent* event, const char * itemname, TClass * cl, int kind)
00400 {
00401 if (cl==0) return;
00402
00403 if (cl->InheritsFrom(TGo4Fitter::Class())) {
00404 WorkWithFitter(itemname, 0, 0);
00405 return;
00406 }
00407
00408 if (event==0) return;
00409
00410 QWidget* w = childAt(event->pos(), TRUE);
00411
00412 if (w == Wiz_DataSlotsTable->viewport()) {
00413 QPoint pnt = Wiz_DataSlotsTable->viewport()->mapFrom(this, event->pos());
00414 pnt = Wiz_DataSlotsTable->viewportToContents(pnt);
00415 int nrow = Wiz_DataSlotsTable->rowAt(pnt.y());
00416
00417 if ((nrow<0) || (nrow>fxWizSlots->GetLast())) return;
00418
00419 TGo4FitSlot* slot = dynamic_cast<TGo4FitSlot*> (fxWizSlots->At(nrow));
00420
00421 if (slot==0) return;
00422 if (!slot->IsSuitableClass(cl)) return;
00423
00424 CreateFitSlotLink(slot, itemname);
00425
00426 UpdateActivePage();
00427 } else
00428
00429 if(w == (QWidget*)FitList->viewport()) {
00430 QPoint pnt = FitList->viewport()->mapFrom(this, event->pos());
00431 QFitItem* item = dynamic_cast<QFitItem*> (FitList->itemAt(pnt));
00432 if ((item==0) || (item->ObjectType()!=FitGui::ot_slot)) return;
00433
00434 TGo4FitSlot* slot = dynamic_cast<TGo4FitSlot*>(item->Object());
00435 if (slot==0) return;
00436 if (!slot->IsSuitableClass(cl)) return;
00437
00438 CreateFitSlotLink(slot, itemname);
00439
00440 UpdateActivePage();
00441 }
00442 }
00443
00444 void TGo4FitPanel::linkedObjectUpdated( const char * linkname, TObject * obj )
00445 {
00446 UpdateObjectReferenceInSlots();
00447
00448 UpdateActivePage();
00449 }
00450
00451 void TGo4FitPanel::RemoveFitterLink()
00452 {
00453 RemoveLink("Fitter");
00454 }
00455
00456 void TGo4FitPanel::linkedObjectRemoved( const char * linkname )
00457 {
00458 if (strcmp(linkname,"Fitter")==0) {
00459 RemoveAllLinks();
00460 fxActivePanel = 0;
00461 fxActivePad = 0;
00462 } else {
00463 UpdateObjectReferenceInSlots();
00464 }
00465
00466 UpdateActivePage();
00467 }
00468
00469 void TGo4FitPanel::linkedRemoved(TGo4Slot* slot, TObject* obj)
00470 {
00471 }
00472
00473
00474 void TGo4FitPanel::WorkWithFitter(const char* itemname, TGo4ViewPanel* panel, TPad* pad)
00475 {
00476 RemovePrimitives();
00477 RemoveDrawObjects();
00478 CloseDrawPanel();
00479 ClearObjectReferenceInSlots();
00480
00481 fxActivePanel = panel;
00482 fxActivePad = pad;
00483
00484 RemoveFitterLink();
00485 AddLink(itemname, "Fitter");
00486
00487 TObject* obj = GetLinked("Fitter",2);
00488
00489 UpdateObjectReferenceInSlots();
00490
00491 UpdateActivePage();
00492 }
00493
00494 void TGo4FitPanel::WorkWithFitterInSlot(TGo4Slot* slot)
00495 {
00496 RemovePrimitives();
00497 RemoveDrawObjects();
00498 CloseDrawPanel();
00499 ClearObjectReferenceInSlots();
00500
00501 fxActivePanel = 0;
00502 fxActivePad = 0;
00503
00504 RemoveFitterLink();
00505 AddLink(slot, "Fitter");
00506
00507 TObject* obj = GetLinked("Fitter",0);
00508
00509 UpdateObjectReferenceInSlots();
00510
00511 UpdateActivePage();
00512 }
00513
00514
00515
00516 void TGo4FitPanel::panelSlot(TGo4ViewPanel* panel, TPad* pad, int signalid)
00517 {
00518 switch (signalid) {
00519 case panel_Activated: {
00520 if ((panel==0) || (pad==0)) return;
00521
00522 if (fbDrawPanelCreation) return;
00523 if ((panel==fxDrawNewPanel) || fbDrawPanelCreation) return;
00524
00525 bool update = fbFreezeMode;
00526
00527 if (!update && (GetFitter()!=0) && (GetFitter()->GetNumData()>1))
00528 update = true;
00529
00530 if (WorkingWithPanel() &&
00531 (panel==ActivePanel()) &&
00532 (pad==ActivePad()) ) update = true;
00533
00534 if (update) {
00535 UpdateObjectReferenceInSlots();
00536 if (fiPanelMode==FitGui::pm_Expert) UpdateItemsOfType(FitGui::ot_slot, 0);
00537 if (fiPanelMode==FitGui::pm_Wizard) UpdateWizStackWidget();
00538 return;
00539 }
00540
00541 RemovePrimitives();
00542 RemoveDrawObjects();
00543 CloseDrawPanel();
00544 ClearObjectReferenceInSlots();
00545
00546 RemoveFitterLink();
00547
00548 fxActivePanel = panel;
00549 fxActivePad = pad;
00550
00551 if ((panel!=0) && (pad!=0)) {
00552 TGo4Slot* slot = panel->GetDrawObjectSlot(pad, "::Fitter");
00553 AddLink(slot, "Fitter");
00554 }
00555
00556 UpdateObjectReferenceInSlots();
00557
00558 UpdateActivePage();
00559
00560 break;
00561 }
00562
00563 case panel_Modified: {
00564 if (!WorkingWithPanel() || (panel!=ActivePanel())) return;
00565 RemovePrimitives();
00566 CloseDrawPanel();
00567 UpdateObjectReferenceInSlots();
00568 if (fiPanelMode==FitGui::pm_Wizard) UpdateWizStackWidget();
00569 if (fiPanelMode==FitGui::pm_Expert) UpdateItemsOfType(FitGui::ot_slot, 0);
00570 break;
00571 }
00572
00573 case panel_Deleted: {
00574 if (panel==0) return;
00575 if (panel==fxDrawNewPanel) { fxDrawNewPanel = 0; return; }
00576 if (WorkingWithPanel() && (panel==ActivePanel())) {
00577 ClearObjectReferenceInSlots();
00578 RemoveFitterLink();
00579 fxActivePanel = 0;
00580 fxActivePad = 0;
00581 }
00582
00583 UpdateActivePage();
00584 break;
00585 }
00586 }
00587 }
00588
00589
00590
00591
00592 bool TGo4FitPanel::WorkingWithPanel()
00593 {
00594 return (fxActivePanel!=0) && (fxActivePad!=0);
00595 }
00596
00597 bool TGo4FitPanel::WorkingWithOnlyPad()
00598 {
00599 return WorkingWithPanel() ? !ActivePanel()->IsPadHasSubPads(ActivePad()) : false;
00600 }
00601
00602 TGo4ViewPanel* TGo4FitPanel::ActivePanel()
00603 {
00604 return fxActivePanel;
00605 }
00606
00607 TPad* TGo4FitPanel::ActivePad()
00608 {
00609 return fxActivePad;
00610 }
00611
00612 TGo4Fitter* TGo4FitPanel::GetFitter()
00613 {
00614 return dynamic_cast<TGo4Fitter*>(GetLinked("Fitter",0));
00615 }
00616
00617 void TGo4FitPanel::SetFitter(TGo4Fitter* fitter)
00618 {
00619 ClearObjectReferenceInSlots();
00620 RemoveFitterLink();
00621 if (!WorkingWithPanel()) {
00622 if (fitter!=0) {
00623 QString itemname = SaveObjectInMemory("FitPanel", fitter);
00624 AddLink(itemname, "Fitter");
00625 }
00626 } else {
00627 ActivePanel()->DeleteDrawObject(ActivePad(),"::Fitter");
00628 TGo4Slot* slot = ActivePanel()->AddDrawObject(
00629 ActivePad(),
00630 TGo4ViewPanel::kind_Fitter,
00631 "::Fitter",
00632 fitter, true, 0);
00633 if (slot!=0)
00634 AddLink(slot, "Fitter");
00635 }
00636 UpdateObjectReferenceInSlots();
00637 fbParsWidgetShown = false;
00638 }
00639
00640 TGo4Fitter* TGo4FitPanel::CloneFitter()
00641 {
00642 TGo4Fitter* fitter = GetFitter();
00643 if (fitter==0) return 0;
00644
00645 fitter->SetSaveFlagForObjects(fbSaveWithReferences);
00646
00647 return dynamic_cast<TGo4Fitter*> (fitter->Clone());
00648 }
00649
00650 void TGo4FitPanel::Fitter_New()
00651 {
00652 if (WorkingWithPanel()) {
00653 ClearObjectReferenceInSlots();
00654 fxActivePanel = 0;
00655 fxActivePad = 0;
00656 }
00657
00658 TGo4Fitter* fitter = new TGo4Fitter("Fitter","Fitter object");
00659 SetFitter(fitter);
00660
00661 UpdateActivePage();
00662 }
00663
00664
00665 void TGo4FitPanel::Fitter_NewForActivePad(bool overwrite)
00666 {
00667 TGo4ViewPanel* panel = LastActivePanel();
00668 if ((panel==0) || (panel==fxDrawNewPanel)) return;
00669 TPad* pad = panel->GetActivePad();
00670
00671 ClearObjectReferenceInSlots();
00672
00673 RemoveFitterLink();
00674
00675 fxActivePanel = panel;
00676 fxActivePad = pad;
00677
00678 if ((panel!=0) && (pad!=0)) {
00679 TGo4Slot* fitterslot = panel->GetDrawObjectSlot(pad, "::Fitter");
00680
00681 if (!overwrite && (fitterslot!=0))
00682 AddLink(fitterslot, "Fitter");
00683 }
00684
00685 if (overwrite || (GetFitter()==0))
00686 SetFitter(CreateFitterFor(panel, pad, "Fitter"));
00687
00688 UpdateObjectReferenceInSlots();
00689 UpdateActivePage();
00690 }
00691
00692 void TGo4FitPanel::Fitter_Delete()
00693 {
00694 if(fbNeedConfirmation)
00695 if ( QMessageBox::information(0,
00696 QString("Delete fitter"),
00697 QString("Are you sure?"),
00698 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
00699
00700 RemovePrimitives();
00701 RemoveDrawObjects();
00702 CloseDrawPanel();
00703
00704 ClearObjectReferenceInSlots();
00705
00706 SetFitter(0);
00707
00708 if (WorkingWithPanel()) {
00709 fxActivePanel = 0;
00710 fxActivePad = 0;
00711 }
00712
00713 UpdateActivePage();
00714 }
00715
00716 void TGo4FitPanel::Fitter_UseWorkspace()
00717 {
00718 RemovePrimitives();
00719 CloseDrawPanel();
00720 ClearObjectReferenceInSlots();
00721
00722 fxActivePanel = 0;
00723 fxActivePad = 0;
00724
00725 UpdateObjectReferenceInSlots();
00726 UpdateActivePage();
00727 }
00728
00729
00730 void TGo4FitPanel::Fitter_UpdateReferences()
00731 {
00732 UpdateObjectReferenceInSlots();
00733 UpdateActivePage();
00734 }
00735
00736 void TGo4FitPanel::Fitter_SaveToBrowser()
00737 {
00738 TGo4LockGuard lock;
00739
00740 TGo4Fitter* clone = CloneFitter();
00741
00742 if (clone!=0) SaveObjectInMemory("", clone);
00743 }
00744
00745 void TGo4FitPanel::Fitter_PrintParameters()
00746 {
00747 QTable* tab = ParsTable;
00748 if (tab==0) return;
00749
00750 TGo4Log::Info("Printout of fitter parameters table");
00751
00752 QString str("Name");
00753 for(int ncol=0;ncol<tab->numCols();ncol++) {
00754 str+="\t";
00755 str+=tab->horizontalHeader()->label(ncol);
00756 }
00757 TGo4Log::Info(str.latin1());
00758
00759 for(int nrow=0;nrow<tab->numRows();nrow++) {
00760 str = tab->verticalHeader()->label(nrow);
00761 for(int ncol=0;ncol<tab->numCols();ncol++) {
00762 str+="\t";
00763 str+=tab->text(nrow, ncol);
00764 }
00765 TGo4Log::Info(str.latin1());
00766 }
00767 }
00768
00769 void TGo4FitPanel::Fitter_RollbackParameters()
00770 {
00771 TGo4Fitter* fitter = GetFitter();
00772 fitter->RememberPars();
00773
00774 UpdateStatusBar(0);
00775 UpdateActivePage();
00776 }
00777
00778 void TGo4FitPanel::Button_WorkWithPanel()
00779 {
00780 TGo4LockGuard lock;
00781
00782 TGo4Fitter* fitter = GetFitter();
00783 if (fitter!=0) {
00784 TGo4WorkSpace* space = TGo4WorkSpace::Instance();
00785 if (space==0) return;
00786 TGo4ViewPanel* panel = LastActivePanel();
00787 if ((panel==0) || (panel==fxDrawNewPanel)) return;
00788 if ( (panel!=ActivePanel()) || (panel->GetActivePad()!=ActivePad())) {
00789 TGo4Fitter* clone = (TGo4Fitter*) fitter->Clone();
00790 fxActivePanel = panel;
00791 fxActivePad = panel->GetActivePad();
00792 SetFitter(clone);
00793 UpdateObjectReferenceInSlots();
00794 UpdateActivePage();
00795 }
00796 } else
00797 Fitter_NewForActivePad(false);
00798 }
00799
00800 void TGo4FitPanel::Button_SimpleFit(int nmodel)
00801 {
00802 if (!WorkingWithOnlyPad()) return;
00803
00804 TGo4Fitter* fitter = GetFitter();
00805 if (fitter==0) return;
00806
00807 if (fitter->GetNumData()!=1) { cout << " Incorrect data" << endl; return; }
00808
00809 if (!UpdateObjectReferenceInSlots()) return;
00810
00811 TGo4FitData* data = fitter->GetData(0);
00812 if (data==0) return;
00813
00814 data->ClearRanges();
00815 data->SetRange(0, ActivePad()->GetUxmin(), ActivePad()->GetUxmax());
00816
00817 fitter->SetMemoryUsage(1);
00818
00819 int NumDim = data->DefineDimensions();
00820
00821 TGo4FitModel* model = 0;
00822
00823 switch (nmodel) {
00824 case 0:
00825 fitter->AddPolynoms(data->GetName(), "Pol", Smp_PolOrderSpin->value(), NumDim);
00826 break;
00827
00828 case 1:
00829 model = CreateModel(20, 0, fitter, data);
00830 break;
00831
00832 case 2:
00833 model = CreateModel(24, 0, fitter, data);
00834 break;
00835
00836 case 3:
00837 model = CreateModel(25, 0, fitter, data);
00838 break;
00839 }
00840
00841 if (model && ((nmodel==1) || (nmodel==2))) LocateModel(model, data, FALSE);
00842
00843 fbUseAmplEstim = true;
00844 fiNumMigradIter = 500;
00845
00846 Button_PerformFit();
00847 }
00848
00849 void TGo4FitPanel::Button_SimpleClear()
00850 {
00851 TGo4Fitter* fitter = GetFitter();
00852 if (fitter==0) return;
00853
00854 fitter->DeleteAllModels();
00855
00856 RemovePrimitives();
00857 RemoveDrawObjects();
00858 }
00859
00860 void TGo4FitPanel::Button_PeakFinder()
00861 {
00862 TGo4Fitter* fitter = GetFitter();
00863 if (fitter==0) return;
00864
00865 TGo4FitPeakFinder* finder = GetPeakFinder(true);
00866 if (finder==0) return;
00867
00868 TGo4FitData* data = 0;
00869 if (fiPanelMode==FitGui::pm_Wizard) data = Wiz_SelectedData();
00870 else data = fitter->GetData(0);
00871 if (data==0) return;
00872
00873 RemovePrimitives();
00874 RemoveDrawObjects();
00875
00876 if (fbUseCurrentRange)
00877 Wiz_TakeCurrentRange();
00878
00879 finder->SetDataName(data->GetName());
00880
00881 finder->SetClearModels(kTRUE);
00882
00883 fitter->SetMemoryUsage(fiBuffersUsage);
00884
00885 UpdateStatusBar("Start peak finder ... ");
00886
00887 fitter->DoAction(finder);
00888
00889 fbUseAmplEstim = true;
00890 fiNumMigradIter = 300;
00891
00892 UpdateStatusBar(0);
00893
00894 fiPaintMode = 1;
00895 UpdateActivePage();
00896 }
00897
00898 void TGo4FitPanel::Button_PerformFit()
00899 {
00900 TGo4Fitter* fitter = GetFitter();
00901 if (fitter==0) return;
00902
00903 if (fiPanelMode!=FitGui::pm_Expert) {
00904
00905 if (fbUseAmplEstim || (fiNumMigradIter>0)) {
00906 TGo4FitPeakFinder* finder = GetPeakFinder(false);
00907 Int_t n=0;
00908 while (n<fitter->GetNumActions()) {
00909 TGo4FitterAction* action = fitter->GetAction(n);
00910 if (action==finder) n++;
00911 else fitter->DeleteAction(action);
00912 }
00913
00914 if (fbUseAmplEstim) fitter->AddAmplEstimation();
00915 if (fiNumMigradIter > 0) {
00916 TGo4FitMinuit* minuit = new TGo4FitMinuit("Minuit");
00917 QString cmd("MIGRAD ");
00918 cmd+=QString::number(fiNumMigradIter);
00919 cmd+=" 1";
00920 minuit->AddCommand(cmd.latin1());
00921 fitter->AddAction(minuit);
00922 }
00923 }
00924
00925 if (fitter->GetNumActions() == 0)
00926 fitter->AddStandardActions();
00927 }
00928
00929 if (fbUseCurrentRange)
00930 Wiz_TakeCurrentRange();
00931
00932 fitter->SetMemoryUsage(fiBuffersUsage);
00933
00934 fitter->MemorizePars();
00935
00936 UpdateStatusBar("Start fitting ... ");
00937
00938 fitter->DoActions();
00939
00940 Button_FitterDraw(0);
00941
00942 if (fiPanelMode==FitGui::pm_Simple) {
00943 RemovePrimitives();
00944 if (!fbShowPrimitives) return;
00945 TGo4FitData* data = fitter->GetData(0);
00946 PaintModelsFor(fitter, data, 0, TRUE);
00947 UpdateStatusBar(0);
00948 } else
00949 UpdateActivePage();
00950 }
00951
00952 void TGo4FitPanel::Button_FitterDraw(TGo4FitData* selecteddata)
00953 {
00954 TGo4Fitter* fitter = GetFitter();
00955 if ((fitter==0) ||
00956 (!fbDrawModels && !fbDrawComponents && !fbDrawBackground)) {
00957 RemoveDrawObjects();
00958 return;
00959 }
00960
00961 bool UseSamePads = fbUseSamePanelForDraw;
00962 if (UseSamePads)
00963 for(Int_t n=0;n<fitter->GetNumData();n++) {
00964 TGo4FitData* data = fitter->GetData(n);
00965 if (selecteddata && (data!=selecteddata)) continue;
00966
00967 if (data->IsAnyDataTransform())
00968 UseSamePads = FALSE;
00969
00970 if (FindPadWhereData(data)==0)
00971 UseSamePads = FALSE;
00972 }
00973
00974 int NeedPads = 1;
00975 if(!UseSamePads) {
00976 if (fxDrawNewPanel==0) {
00977 fbDrawPanelCreation = kTRUE;
00978 fxDrawNewPanel = CreateViewPanel();
00979 fbDrawPanelCreation = kFALSE;
00980 if (fxDrawNewPanel==0) return;
00981 } else fxDrawNewPanel->ClearCanvas();
00982
00983 if (selecteddata==0) NeedPads = fitter->GetNumData();
00984 else NeedPads = 1;
00985
00986 if (NeedPads>1) {
00987 int DivX = (int)TMath::Sqrt(NeedPads*1.);
00988 int DivY = DivX;
00989 while (DivX*DivY<NeedPads) DivY++;
00990 fxDrawNewPanel->Divide(DivX, DivY);
00991 }
00992 }
00993
00994 for(Int_t n=0;n<fitter->GetNumData();n++) {
00995 TGo4FitData* data = fitter->GetData(n);
00996
00997 if (selecteddata && (data!=selecteddata)) continue;
00998
00999 const char* drawopt = 0;
01000 if (data->GetDataType()==TGo4FitData::dtGraph)
01001 drawopt = "L";
01002
01003 TGo4ViewPanel* panel = 0;
01004 TPad* pad = 0;
01005
01006 if (UseSamePads) {
01007 panel = ActivePanel();
01008 pad = FindPadWhereData(data);
01009 } else {
01010 panel = fxDrawNewPanel;
01011 pad = fxDrawNewPanel->GetSubPad(0, n, true);
01012 }
01013 if ((panel==0) || (pad==0)) continue;
01014
01015 panel->DeleteDrawObjects(pad, TGo4ViewPanel::kind_FitModels);
01016
01017
01018
01019 if (UseSamePads) panel->SetAutoScale(false, pad);
01020
01021
01022
01023
01024 panel->ShootRepaintTimer();
01025
01026 if (!UseSamePads) {
01027 TObject* obj = fitter->CreateDrawObject("Data", data->GetName(), kFALSE);
01028 panel->AddDrawObject(pad, TGo4ViewPanel::kind_FitModels, "::Data", obj, true, drawopt);
01029 }
01030
01031 if (!fbDrawInfoOnPad)
01032 panel->DeleteDrawObjects(pad, TGo4ViewPanel::kind_FitInfo);
01033 else {
01034 Double_t x2 = 0.98;
01035 Double_t y2 = 0.5;
01036 Double_t x1 = x2 - gStyle->GetStatW();
01037 Double_t y1 = y2 - gStyle->GetStatH();
01038 TPaveStats* stats = dynamic_cast<TPaveStats*> (pad->GetPrimitive("stats"));
01039 if (stats) {
01040 x1 = stats->GetX1NDC();
01041 x2 = stats->GetX2NDC();
01042 y2 = stats->GetY1NDC() - 0.05;
01043 y1 = y2 - (stats->GetY2NDC() - stats->GetY1NDC());
01044 if (y1<0.02) y1 = 0.02;
01045 }
01046
01047 TPaveStats* info = dynamic_cast<TPaveStats*>
01048 (panel->GetDrawObject(pad, "::FitterPars"));
01049
01050 bool infocreated = false;
01051
01052 if (info!=0) info->Clear("*"); else {
01053 infocreated = true;
01054 info = new TPaveStats(x1,y1,x2,y2,"brNDC");
01055 info->SetFillColor(gStyle->GetStatColor());
01056 info->SetFillStyle(gStyle->GetStatStyle());
01057 info->SetBorderSize(gStyle->GetStatBorderSize());
01058 info->SetTextFont(gStyle->GetStatFont());
01059 if (gStyle->GetStatFont()%10 > 2)
01060 info->SetTextSize(gStyle->GetStatFontSize());
01061 info->SetFitFormat(gStyle->GetFitFormat());
01062 info->SetStatFormat(gStyle->GetStatFormat());
01063 info->SetTextColor(gStyle->GetStatTextColor());
01064 info->SetTextAlign(12);
01065 info->SetName("fitinfo");
01066 }
01067
01068 info->AddText(data->GetName());
01069 info->AddLine(0,0,0,0);
01070
01071 char t[500], tt[500];
01072
01073 if (LineParsChk->isChecked())
01074 info->AddText("Line | Ampl | Pos & Width");
01075
01076 for(Int_t m=0;m<fitter->GetNumModel();m++) {
01077 TGo4FitModel* model = fitter->GetModel(m);
01078 if (!model->IsAssignTo(data->GetName())) continue;
01079
01080 if (LineParsChk->isChecked()) {
01081 Double_t ampl, pos, width;
01082
01083 ampl = model->GetAmplValue();
01084 if (!model->GetPosition(0,pos)) pos = 0.;
01085 if (!model->GetWidth(0,width)) width = 0.;
01086
01087 snprintf(tt,500,"%7s | %s%s | %s%s %s%s",
01088 model->GetName(),
01089 "%",gStyle->GetStatFormat(),
01090 "%",gStyle->GetStatFormat(),
01091 "%",gStyle->GetStatFormat());
01092
01093 snprintf(t,500,tt,ampl,pos,width);
01094 info->AddText(t);
01095 } else {
01096 int maxparlen = 7;
01097 for(Int_t np=0;np<model->NumPars();np++) {
01098 int len = strlen(model->GetParFullName(np));
01099 if (len>maxparlen) maxparlen = len;
01100 }
01101 snprintf(tt,500,"%s%ds = %s%s","%",maxparlen,"%",gStyle->GetStatFormat());
01102
01103 for(Int_t np=0;np<model->NumPars();np++) {
01104 snprintf(t,500,tt,model->GetParFullName(np), model->GetPar(np)->GetValue());
01105 info->AddText(t);
01106 }
01107 }
01108 }
01109
01110 if (infocreated)
01111 panel->AddDrawObject(pad, TGo4ViewPanel::kind_FitInfo, "::FitterPars", info, true, 0);
01112 }
01113
01114 if (fbDrawModels) {
01115 TObject* model = fitter->CreateDrawObject("Model", data->GetName(), kTRUE);
01116 panel->AddDrawObject(pad, TGo4ViewPanel::kind_FitModels, "::DataModel", model, true, drawopt);
01117 }
01118
01119 if (fbDrawBackground) {
01120 TObject* model = fitter->CreateDrawObject("Background", data->GetName(), kTRUE, "Background");
01121 panel->AddDrawObject(pad, TGo4ViewPanel::kind_FitModels, "::Background", model, true, drawopt);
01122 }
01123
01124 if (fbDrawComponents)
01125 for(Int_t m=0;m<fitter->GetNumModel();m++) {
01126 TGo4FitModel* model = fitter->GetModel(m);
01127 if (!model->IsAssignTo(data->GetName())) continue;
01128 if (model->GetGroupIndex()==0) continue;
01129 TObject* comp = fitter->CreateDrawObject(model->GetName(), data->GetName(), kTRUE, model->GetName());
01130 if (comp==0) continue;
01131
01132 panel->AddDrawObject(pad, TGo4ViewPanel::kind_FitModels, "::FitComponent", comp, true, drawopt);
01133 }
01134 }
01135 }
01136
01137
01138 void TGo4FitPanel::Cmd_CreateFitter()
01139 {
01140 TGo4Fitter* fitter = new TGo4Fitter("Fitter","Fitter object");
01141 SetFitter(fitter);
01142
01143 UpdateActivePage();
01144 }
01145
01146 void TGo4FitPanel::Cmd_CreateAppropriateFitter()
01147 {
01148 TGo4Fitter* fitter = CreateFitterFor(ActivePanel(), ActivePad(), "Fitter");
01149 if (fitter) {
01150 SetFitter(fitter);
01151 UpdateActivePage();
01152 }
01153 }
01154
01155 void TGo4FitPanel::Cmd_DeleteFitter()
01156 {
01157 if(fbNeedConfirmation)
01158 if ( QMessageBox::information(0,
01159 QString("Clear fitter"),
01160 QString("Are you sure?"),
01161 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
01162
01163 RemovePrimitives();
01164
01165 SetFitter(0);
01166
01167 UpdateActivePage();
01168 }
01169
01170 void TGo4FitPanel::Cmd_ClearFitter()
01171 {
01172 TGo4Fitter* fitter = GetFitter();
01173 if (fitter==0) return;
01174
01175 if(fbNeedConfirmation)
01176 if ( QMessageBox::information(0,
01177 QString("Clear fitter"),
01178 QString("Are you sure?"),
01179 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
01180
01181 fitter->Clear();
01182
01183 UpdateActivePage();
01184 }
01185
01186 void TGo4FitPanel::Cmd_SaveFitter(bool ask)
01187 {
01188 TGo4Fitter* fitter = GetFitter();
01189 if (fitter==0) return;
01190
01191 QString fname(fitter->GetName());
01192 fname+=".root";
01193
01194 if(ask) {
01195 fname = QFileDialog::getSaveFileName(fname,
01196 QString("Root file (*.root)"),
01197 0,
01198 QString("save fitter dialog"),
01199 QString("Set file name to save fitter"));
01200 if (fname==QString::null) return;
01201 }
01202
01203 fitter->SetSaveFlagForObjects(fbSaveWithReferences);
01204
01205 TFile f(fname,"recreate");
01206 fitter->Write();
01207 }
01208
01209 void TGo4FitPanel::Cmd_ItemPrint(QFitItem* item)
01210 {
01211 TObject* obj = item->Object();
01212 if (obj==0) return;
01213
01214 QString str("*");
01215 bool ok = TRUE;
01216 if (obj->InheritsFrom(TGo4Fitter::Class()))
01217 str = QInputDialog::getText(QString("Go4 Fit Panel"),
01218 QString("Enter parameters for Print() command"),
01219 QLineEdit::Normal, str, &ok, 0);
01220 if (!ok) return;
01221
01222 RemoveItemWidget();
01223 QFitPrintWidget* widget = new QFitPrintWidget(0, QString("Print ")+obj->GetName());
01224
01225 ListStack->addWidget(widget, FitGui::ListStackId);
01226
01227 widget->SetDrawOption(str);
01228 widget->SetItem(this, item);
01229 ListStack->raiseWidget(widget);
01230 }
01231
01232 void TGo4FitPanel::Cmd_DrawData(QFitItem * item)
01233 {
01234 TGo4FitData* data = dynamic_cast<TGo4FitData*> (item->Object());
01235 if (data) Button_FitterDraw(data);
01236 }
01237
01238 void TGo4FitPanel::Cmd_DeleteData(QFitItem * item)
01239 {
01240 TGo4FitData* data = dynamic_cast<TGo4FitData*> (item->Object());
01241 TGo4Fitter* fitter = GetFitter();
01242
01243 if ((data==0) || (fitter==0)) return;
01244
01245 if(fbNeedConfirmation)
01246 if ( QMessageBox::information(0,
01247 QString("Delete data"),
01248 QString("Are you sure to delete ") + data->GetName(),
01249 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
01250
01251 fitter->RemoveData(data->GetName(),kTRUE);
01252
01253 UpdateObjectReferenceInSlots();
01254
01255 UpdateItemsOfType(FitGui::ot_allslots, 0);
01256
01257 UpdateItem(item->Parent(), TRUE);
01258
01259 UpdateStatusBar(0);
01260 }
01261
01262 void TGo4FitPanel::Cmd_DeleteAllData(QFitItem * item)
01263 {
01264 TGo4Fitter* fitter = GetFitter();
01265 if (fitter==0) return;
01266
01267 if(fbNeedConfirmation)
01268 if ( QMessageBox::information(0,
01269 QString("Delete all data"),
01270 QString("Are you sure to delete all data objects"),
01271 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
01272
01273 fitter->DeleteAllData();
01274
01275 UpdateObjectReferenceInSlots();
01276
01277 UpdateItemsOfType(FitGui::ot_allslots, 0);
01278
01279 UpdateItem(item, TRUE);
01280
01281 UpdateStatusBar(0);
01282 }
01283
01284 void TGo4FitPanel::Cmd_DeleteAssosiatedModels(QFitItem * item)
01285 {
01286 if ((item==0) || (item->Parent()==0)) return;
01287 TGo4FitData* data = dynamic_cast<TGo4FitData*> (item->Object());
01288 TGo4Fitter* fitter = GetFitter();
01289
01290 if ((data==0) || (fitter==0)) return;
01291
01292 if(fbNeedConfirmation)
01293 if ( QMessageBox::information(0,
01294 QString("Delete models"),
01295 QString("Are you sure to delete models, assosiated to ") + data->GetName(),
01296 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
01297
01298 fitter->DeleteModelsAssosiatedTo(data->GetName());
01299
01300 QFitItem* mlist = FindItem(0, FitGui::ot_modellist, 0);
01301 if (mlist) UpdateItem(mlist, TRUE);
01302
01303 UpdateItemsOfType(FitGui::ot_allslots, 0);
01304
01305 ShowItem(item, false);
01306
01307 UpdateStatusBar(0);
01308 }
01309
01310 void TGo4FitPanel::Cmd_DeleteModel(QFitItem * item)
01311 {
01312 TGo4FitModel* model = dynamic_cast<TGo4FitModel*> (item->Object());
01313
01314 Cmd_RemoveModel(model);
01315 }
01316
01317 void TGo4FitPanel::Cmd_RemoveModel(TGo4FitModel* model)
01318 {
01319 TGo4Fitter* fitter = GetFitter();
01320 if ((model==0) || (fitter==0)) return;
01321
01322 if(fbNeedConfirmation)
01323 if ( QMessageBox::information(0,
01324 QString("Delete model"),
01325 QString("Are you sure to delete ") + model->GetName(),
01326 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
01327
01328 fitter->RemoveModel(model->GetName(), kTRUE);
01329
01330 UpdateObjectReferenceInSlots();
01331
01332 UpdateActivePage();
01333 }
01334
01335 void TGo4FitPanel::Cmd_DeleteModels(QFitItem * item)
01336 {
01337 TGo4Fitter* fitter = GetFitter();
01338 if (fitter==0) return;
01339
01340 if(fbNeedConfirmation)
01341 if ( QMessageBox::information(0,
01342 QString("Delete all models"),
01343 QString("Are you sure to delete all models objects"),
01344 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
01345
01346 fitter->DeleteAllModels();
01347
01348 UpdateObjectReferenceInSlots();
01349
01350 UpdateItem(item, TRUE);
01351 UpdateItemsOfType(FitGui::ot_allslots, 0);
01352 UpdateStatusBar(0);
01353 }
01354
01355 void TGo4FitPanel::Cmd_CloneModel(QFitItem * item)
01356 {
01357 TGo4FitModel* model = dynamic_cast<TGo4FitModel*> (item->Object());
01358
01359 TGo4Fitter* fitter = GetFitter();
01360 if ((fitter==0) || (model==0)) return;
01361
01362 fitter->CloneModel(model->GetName());
01363
01364 UpdateObjectReferenceInSlots();
01365
01366 UpdateActivePage();
01367 }
01368
01369 void TGo4FitPanel::Cmd_AddNewData(QFitItem * item, int id)
01370 {
01371 if (item->ObjectType()!=FitGui::ot_datalist) item = item->Parent();
01372 if (item->ObjectType()!=FitGui::ot_datalist) return;
01373
01374 TGo4Fitter* fitter = GetFitter();
01375 if (fitter==0) return;
01376
01377 TGo4FitData* data = CreateData(id, 0);
01378 if (data==0) return;
01379
01380 fitter->AddData(data);
01381
01382 UpdateObjectReferenceInSlots();
01383
01384 UpdateItem(item, TRUE);
01385
01386 UpdateItemsOfType(FitGui::ot_allslots, 0);
01387
01388 QFitItem* curr = FindItem(data, FitGui::ot_data, item);
01389 if (curr!=0)
01390 FitList->setSelected(curr, TRUE);
01391 UpdateStatusBar(0);
01392 }
01393
01394 void TGo4FitPanel::Cmd_AddNewModel(QFitItem * item, int id)
01395 {
01396 if (item->ObjectType()!=FitGui::ot_modellist) item = item->Parent();
01397 if (item->ObjectType()!=FitGui::ot_modellist) return;
01398
01399 TGo4Fitter* fitter = GetFitter();
01400 if (fitter==0) return;
01401
01402 TGo4FitModel* model = CreateModel(id, 0, fitter, 0);
01403 LocateModel(model, 0, true);
01404
01405 UpdateObjectReferenceInSlots();
01406
01407 UpdateItem(item, TRUE);
01408
01409 UpdateItemsOfType(FitGui::ot_allslots, 0);
01410
01411 QFitItem* curr = FindItem(model, FitGui::ot_model, item);
01412 if (curr!=0)
01413 FitList->setSelected(curr, TRUE);
01414 UpdateStatusBar(0);
01415 }
01416
01417 void TGo4FitPanel::Cmd_ClearAssigment(QFitItem* item)
01418 {
01419 if (item==0) return;
01420 TGo4FitModel* model = dynamic_cast<TGo4FitModel*> (item->Parent()->Object());
01421 if (model==0) return;
01422
01423 model->ClearAssignmentTo(item->text(0).latin1());
01424
01425 UpdateItemsOfType(FitGui::ot_parslist, item->Parent()->Parent());
01426
01427 UpdateItem(item->Parent(), TRUE);
01428 }
01429
01430 void TGo4FitPanel::Cmd_ClearAssigments(QFitItem* item)
01431 {
01432 TGo4FitModel* model = dynamic_cast<TGo4FitModel*> (item->Object());
01433 if (model==0) return;
01434
01435 model->ClearAssignments();
01436
01437 UpdateItemsOfType(FitGui::ot_parslist, item->Parent());
01438
01439 UpdateItem(item, TRUE);
01440 }
01441
01442 void TGo4FitPanel::Cmd_AssignModelToAllData(QFitItem* item)
01443 {
01444 TGo4FitModel* model = dynamic_cast<TGo4FitModel*> (item->Object());
01445 TGo4Fitter* fitter = GetFitter();
01446 if ((model==0) || (fitter==0)) return;
01447
01448 fitter->AssignModelTo(model->GetName(), 0);
01449
01450 UpdateItemsOfType(FitGui::ot_parslist, item->Parent());
01451
01452 UpdateItem(item, TRUE);
01453 }
01454
01455 void TGo4FitPanel::Cmd_AssignModelToData(QFitItem* item, int id)
01456 {
01457 TGo4FitModel* model = dynamic_cast<TGo4FitModel*> (item->Object());
01458 TGo4Fitter* fitter = GetFitter();
01459 if ((model==0) || (fitter==0)) return;
01460
01461 fitter->AssignModelTo(model->GetName(), fitter->GetDataName(id));
01462
01463 UpdateItemsOfType(FitGui::ot_parslist, item->Parent());
01464
01465 UpdateItem(item, TRUE);
01466 }
01467
01468 void TGo4FitPanel::Cmd_RemoveRangeCondition(QFitItem* item)
01469 {
01470 if (item==0) return;
01471
01472 Int_t typ = item->ObjectType();
01473
01474 if ((typ!=FitGui::ot_range) && (typ!=FitGui::ot_rangecut)) return;
01475
01476 int num = item->Tag();
01477
01478 if (num<0) return;
01479
01480 if(fbNeedConfirmation)
01481 if ( QMessageBox::information(0,
01482 QString("Remove condition"),
01483 QString("Are you sure to delete condition ") + item->text(0),
01484 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
01485
01486 QFitItem* parent = item->Parent();
01487 TGo4FitComponent* comp = dynamic_cast<TGo4FitComponent*> (parent->Object());
01488
01489 if (typ==FitGui::ot_range) comp->RemoveRangeCondition(num);
01490 else comp->RemoveRangeCut(num);
01491
01492 UpdateItem(parent, TRUE);
01493 }
01494
01495 void TGo4FitPanel::Cmd_RemoveRangeConditions(QFitItem* item)
01496 {
01497 if ((item==0) || (item->ObjectType()!=FitGui::ot_rangelist)) return;
01498
01499 if(fbNeedConfirmation)
01500 if ( QMessageBox::information(0,
01501 QString("Delete conditions"),
01502 QString("Are you sure to delete all conditions"),
01503 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
01504
01505 TGo4FitComponent* comp = dynamic_cast<TGo4FitComponent*> (item->Object());
01506 comp->ClearRanges();
01507
01508 UpdateItem(item, TRUE);
01509 }
01510
01511 void TGo4FitPanel::Cmd_AddRangeCondition(QFitItem* item, int id)
01512 {
01513 if ((item==0) || (item->ObjectType()!=FitGui::ot_rangelist)) return;
01514
01515 TGo4FitData* data = 0;
01516
01517 if (item->Object()->InheritsFrom(TGo4FitData::Class()))
01518 data = dynamic_cast<TGo4FitData*> (item->Object());
01519 else {
01520 TGo4FitModel* model = dynamic_cast<TGo4FitModel*> (item->Object());
01521 TGo4Fitter* fitter = GetFitter();
01522 if ((model!=0) && (fitter!=0))
01523 for (Int_t n=0;n<model->NumAssigments();n++) {
01524 data = fitter->FindData(model->AssignmentName(n));
01525 if (data!=0) break;
01526 }
01527
01528 }
01529 Double_t minx = 0., maxx = 100., miny = 0., maxy = 100;
01530
01531 TPad* pad = FindPadWhereData(data);
01532 if (pad) {
01533 minx = pad->GetUxmin(); maxx = pad->GetUxmax();
01534 miny = pad->GetUymin(); maxy = pad->GetUymax();
01535 } else
01536 if (data!=0) {
01537 data->DefineScaleMinMax(0,minx,maxx);
01538 data->DefineScaleMinMax(1,miny,maxy);
01539 Double_t ddx = 0.1*(maxx-minx);
01540 minx += ddx;
01541 maxx -= ddx;
01542 Double_t ddy = 0.1*(maxy-miny);
01543 miny += ddy;
01544 maxy -= ddy;
01545 }
01546
01547 TGo4FitComponent* comp = dynamic_cast<TGo4FitComponent*> (item->Object());
01548
01549 if (id==0) comp->SetRange(0, minx, maxx); else
01550 if (id==1) comp->ExcludeRange(0, minx, maxx); else
01551 if (id==2) comp->SetRangeMin(0, minx); else
01552 if (id==3) comp->SetRangeMax(0, maxx); else
01553 if (id==4) {
01554 TString name("Cut");
01555 name+=comp->GetNumRangeCut();
01556 TCutG* cut = new TCutG(name, 5);
01557 cut->SetTitle("range cut of X and Y axis");
01558 cut->SetPoint(0, minx, miny);
01559 cut->SetPoint(1, maxx, miny);
01560 cut->SetPoint(2, maxx, maxy);
01561 cut->SetPoint(3, minx, maxy);
01562 cut->SetPoint(4, minx, miny);
01563 comp->AddRangeCut(cut);
01564 }
01565
01566 UpdateItem(item, TRUE);
01567 }
01568
01569 void TGo4FitPanel::Cmd_DeleteAction(QFitItem* item)
01570 {
01571 if (item==0) return;
01572 TGo4FitterAction* action = dynamic_cast<TGo4FitterAction*> (item->Object());
01573 TGo4Fitter* fitter = GetFitter();
01574
01575 if(action && fitter) {
01576 if(fbNeedConfirmation)
01577 if ( QMessageBox::information(0,
01578 QString("Delete action"),
01579 QString("Are you sure to delete ") + item->text(0),
01580 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
01581
01582 fitter->DeleteAction(action);
01583 UpdateItem(item->Parent(), TRUE);
01584 }
01585 }
01586
01587 void TGo4FitPanel::Cmd_MoveAction(QFitItem* item, int dir)
01588 {
01589 if ((item==0) || (item->Parent()==0)) return;
01590
01591 TGo4FitterAction* action = dynamic_cast<TGo4FitterAction*> (item->Object());
01592 TGo4Fitter* fitter = GetFitter();
01593
01594 if(action && fitter) {
01595 fitter->ReplaceAction(action, dir);
01596 QFitItem* parent = item->Parent();
01597 UpdateItem(parent, TRUE);
01598 item = FindItem(action, -1, 0);
01599 if (item!=0)
01600 FitList->setSelected(item, TRUE);
01601 }
01602 }
01603
01604 void TGo4FitPanel::Cmd_ExecuteAction(QFitItem* item)
01605 {
01606 TGo4Fitter* fitter = GetFitter();
01607 if ((item==0) || (fitter==0)) return;
01608
01609 TGo4FitterAction* action = dynamic_cast<TGo4FitterAction*> (item->Object());
01610 if (action==0) return;
01611
01612 fitter->DoAction(action);
01613
01614 if (action->CanChangeFitter()) UpdateActivePage(); else {
01615 UpdateItem(item, TRUE);
01616 UpdateItemsOfType(FitGui::ot_par, 0);
01617 }
01618 }
01619
01620 void TGo4FitPanel::Cmd_ExecuteActions(QFitItem* item, bool expert)
01621 {
01622 TGo4Fitter* fitter = GetFitter();
01623
01624 if ((item==0) || (fitter==0)) return;
01625
01626 fitter->MemorizePars();
01627
01628 fitter->DoActions(expert);
01629
01630 if (expert) UpdateActivePage(); else {
01631 UpdateItem(item, TRUE);
01632 UpdateItemsOfType(FitGui::ot_par, 0);
01633 }
01634 }
01635
01636 void TGo4FitPanel::Cmd_DeleteOutputActions(QFitItem* item)
01637 {
01638 TGo4Fitter* fitter = GetFitter();
01639 if ((item==0) || (item->ObjectType()!=FitGui::ot_actlist) || (fitter==0)) return;
01640
01641 if(fbNeedConfirmation)
01642 if ( QMessageBox::information(0,
01643 QString("Delete output actions"),
01644 QString("Are you sure to delete all output actions") + item->text(0),
01645 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
01646
01647 fitter->DeleteOutputActions();
01648 UpdateItem(item, TRUE);
01649 }
01650
01651 void TGo4FitPanel::Cmd_DeleteActions(QFitItem* item)
01652 {
01653 TGo4Fitter* fitter = GetFitter();
01654 if ((item==0) || (item->ObjectType()!=FitGui::ot_actlist) || (fitter==0)) return;
01655
01656 if(fbNeedConfirmation)
01657 if ( QMessageBox::information(0,
01658 QString("Delete all actions"),
01659 QString("Are you sure to delete all actions"),
01660 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
01661
01662 fitter->DeleteActions();
01663 UpdateItem(item, TRUE);
01664 }
01665
01666 void TGo4FitPanel::Cmd_AddNewAction(QFitItem* item, int id)
01667 {
01668 TGo4Fitter* fitter = GetFitter();
01669 if ((item==0) || (item->ObjectType()!=FitGui::ot_actlist) || (fitter==0)) return;
01670
01671 switch(id) {
01672 case 0: fitter->AddAction(new TGo4FitterConfig("Config","Fitter configuration")); break;
01673 case 1: fitter->AddAmplEstimation(); break;
01674 case 2: fitter->AddSimpleMinuit(); break;
01675 case 3: fitter->AddOutputAction("Print","*"); break;
01676 case 4: fitter->AddAction(new TGo4FitPeakFinder("Finder")); break;
01677 }
01678 UpdateItem(item, TRUE);
01679 }
01680
01681 void TGo4FitPanel::Cmd_DeleteDependency(QFitItem* item)
01682 {
01683 if ((item==0) || (item->ObjectType()!=FitGui::ot_depend)) return;
01684
01685 TGo4FitDependency* depen = dynamic_cast<TGo4FitDependency*> (item->Object());
01686 TObjArray* lst = dynamic_cast<TObjArray*> (item->Parent()->Object());
01687
01688 if((depen==0) || (lst==0)) return;
01689
01690 if(fbNeedConfirmation)
01691 if ( QMessageBox::information(0,
01692 QString("Delete dependency item"),
01693 QString("Are you sure to delete ") + item->text(0),
01694 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
01695
01696 lst->Remove(depen);
01697 lst->Compress();
01698 delete depen;
01699
01700 UpdateItem(item->Parent(), TRUE);
01701 }
01702
01703 void TGo4FitPanel::Cmd_DeleteDependencies(QFitItem* item)
01704 {
01705 if (item==0) return;
01706 TObjArray* lst = dynamic_cast<TObjArray*> (item->Object());
01707 if(lst==0) return;
01708
01709 if(fbNeedConfirmation)
01710 if ( QMessageBox::information(0,
01711 QString("Delete all"),
01712 QString("Are you sure to delete all items from ") + item->text(0),
01713 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
01714
01715 lst->Clear();
01716
01717 UpdateItem(item, TRUE);
01718 }
01719
01720 void TGo4FitPanel::Cmd_AddDependency(QFitItem* item)
01721 {
01722 if (item==0) return;
01723
01724 TObjArray* lst = dynamic_cast<TObjArray*> (item->Object());
01725 if(lst==0) return;
01726
01727 if(item->ObjectType()==FitGui::ot_reslist)
01728 lst->Add(new TGo4FitDependency(0,0.0));
01729 else
01730 lst->Add(new TGo4FitDependency("Par1",1.0));
01731
01732 UpdateItem(item, TRUE);
01733 }
01734
01735 void TGo4FitPanel::Cmd_MemorizePars(QFitItem* item)
01736 {
01737 if (item==0) return;
01738
01739 TGo4FitParsList* pars = dynamic_cast<TGo4FitParsList*> (item->Object());
01740 if (pars==0) return;
01741
01742 pars->MemorizePars();
01743 }
01744
01745 void TGo4FitPanel::Cmd_RememberPars(QFitItem* item)
01746 {
01747 if (item==0) return;
01748
01749 TGo4FitParsList* pars = dynamic_cast<TGo4FitParsList*> (item->Object());
01750 if (pars==0) return;
01751
01752 pars->RememberPars();
01753
01754 UpdateItemsOfType(FitGui::ot_par, item);
01755
01756 ShowItem(item, false);
01757 }
01758
01759 void TGo4FitPanel::Cmd_DeletePars(QFitItem* item)
01760 {
01761 if (item==0) return;
01762 TGo4FitParsList* pars = dynamic_cast<TGo4FitParsList*> (item->Object());
01763 if (pars==0) return;
01764
01765 if(fbNeedConfirmation)
01766 if ( QMessageBox::information(0,
01767 QString("Delete all"),
01768 QString("Are you sure to delete all items"),
01769 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
01770
01771 pars->ClearPars();
01772
01773 UpdateItem(item, TRUE);
01774 }
01775
01776 void TGo4FitPanel::Cmd_MemorizePar(QFitItem* item)
01777 {
01778 if (item==0) return;
01779 TGo4FitParameter* par = dynamic_cast<TGo4FitParameter*> (item->Object());
01780 if (par==0) return;
01781
01782 par->MemorizeValue();
01783 }
01784
01785 void TGo4FitPanel::Cmd_RememberPar(QFitItem* item)
01786 {
01787 if (item==0) return;
01788 TGo4FitParameter* par = dynamic_cast<TGo4FitParameter*> (item->Object());
01789 if (par==0) return;
01790
01791 par->RememberValue();
01792
01793 SetItemText(item, TRUE);
01794
01795 ShowItem(item, false);
01796 }
01797
01798 void TGo4FitPanel::Cmd_AddNewPar(QFitItem* item)
01799 {
01800 if (item==0) return;
01801
01802 TGo4FitParsList* pars = dynamic_cast<TGo4FitParsList*> (item->Object());
01803 if (pars==0) return;
01804
01805 TString name;
01806 int num = 0;
01807 do {
01808 name = "Par";
01809 name += num;
01810 num++;
01811 } while (pars->FindPar(name));
01812 pars->CreatePar(name.Data(),"additional parameter",0.);
01813
01814 UpdateItem(item, TRUE);
01815 }
01816
01817 void TGo4FitPanel::Cmd_DeletePar(QFitItem* item)
01818 {
01819 if (item==0) return;
01820
01821 TGo4FitParameter* par = dynamic_cast<TGo4FitParameter*> (item->Object());
01822 TGo4FitParsList* pars = dynamic_cast<TGo4FitParsList*> (item->Parent()->Object());
01823 if ((pars==0) || (par==0)) return;
01824
01825 if(fbNeedConfirmation)
01826 if ( QMessageBox::information(0,
01827 QString("Delete item"),
01828 QString("Are you sure to delete ") + par->GetName(),
01829 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
01830
01831 pars->RemovePar(par);
01832
01833 UpdateItem(item->Parent(), TRUE);
01834 }
01835
01836 void TGo4FitPanel::Cmd_DeleteMinuitResult(QFitItem* item)
01837 {
01838 if (item==0) return;
01839
01840 TGo4FitMinuitResult* res = dynamic_cast<TGo4FitMinuitResult*> (item->Object());
01841 TGo4FitMinuit* minuit = dynamic_cast<TGo4FitMinuit*> (item->Parent()->Object());
01842 if ((res==0) || (minuit==0)) return;
01843
01844 if(fbNeedConfirmation)
01845 if ( QMessageBox::information(0,
01846 QString("Delete result"),
01847 QString("Are you sure to delete ") + res->GetName(),
01848 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
01849
01850 minuit->RemoveResult(res);
01851 delete res;
01852
01853 UpdateItem(item->Parent(), TRUE);
01854 }
01855
01856 void TGo4FitPanel::Cmd_UpdateAllSlots(QFitItem* item)
01857 {
01858 if (item==0) return;
01859
01860 UpdateObjectReferenceInSlots();
01861
01862 QListViewItem* child = item->firstChild();
01863 while (child) {
01864 UpdateItem(dynamic_cast<QFitItem*>(child), TRUE);
01865 child = child->nextSibling();
01866 }
01867 }
01868
01869
01870
01871
01872
01873 void TGo4FitPanel::FitList_contextMenuRequested( QListViewItem * item, const QPoint & pnt, int )
01874 {
01875 QFitItem* fititem = dynamic_cast<QFitItem*> (item);
01876 if (fititem==0) return;
01877
01878 QPopupMenu menu(0,"ListPopup");
01879
01880 if (FillPopupForItem(fititem,&menu)) {
01881 int id = menu.exec(pnt);
01882 ExecPopupForItem(fititem, id );
01883 }
01884 }
01885
01886
01887 void TGo4FitPanel::FitList_currentChanged( QListViewItem * item)
01888 {
01889 QFitItem* fititem = dynamic_cast<QFitItem*> (item);
01890 if (fititem==0) return;
01891
01892 ShowItem(fititem, false);
01893 fxCurrentItem = fititem;
01894
01895 UpdateItemMenu();
01896 }
01897
01898 void TGo4FitPanel::AboutToShowViewMenu()
01899 {
01900 ViewMenu->clear();
01901
01902 ViewMenu->insertItem("&Simple", this, SLOT(ChangeViewType(int)), 0, FitGui::pm_Simple);
01903 ViewMenu->insertItem("&Wizard", this, SLOT(ChangeViewType(int)), 0, FitGui::pm_Wizard);
01904 ViewMenu->insertItem("&Expert", this, SLOT(ChangeViewType(int)), 0, FitGui::pm_Expert);
01905
01906 ViewMenu->setItemChecked(fiPanelMode, TRUE);
01907 }
01908
01909
01910 void TGo4FitPanel::ChangeViewType(int id)
01911 {
01912 if (id!=FitGui::pm_None)
01913 fiPanelMode = id;
01914
01915 fbParsWidgetShown = false;
01916 UpdateActivePage();
01917 }
01918
01919 void TGo4FitPanel::ShowPanelPage( int id )
01920 {
01921 QWidget* w = PageEmpty;
01922 switch(id) {
01923 case 1: w = PageSimple; break;
01924 case 2: w = PageWizard; break;
01925 case 3: w = PageExtended; break;
01926 case 100: w = PageParameters; break;
01927 }
01928 if (w!=WidgetStack->visibleWidget())
01929 WidgetStack->raiseWidget(w);
01930 }
01931
01932 void TGo4FitPanel::UpdateStatusBar(const char* info)
01933 {
01934 QString status;
01935 TGo4Fitter* fitter = GetFitter();
01936
01937 if (info!=0) status=info; else {
01938 if (WorkingWithPanel()) {
01939 status = QString("Active: ") + ActivePad()->GetName();
01940 if (!WorkingWithOnlyPad())
01941 status += ". Muiltifit";
01942
01943 } else status = "Workspace";
01944 if (fitter==0) status+=". No fitter";
01945 else status = status + ". Fitter: "+fitter->GetName();
01946 }
01947 MainStatusLbl->setText(status);
01948 MainStatusLbl->update();
01949 MainStatusLbl->repaint();
01950
01951 MainAttachBtn->setEnabled(TRUE);
01952
01953 QToolTip::remove(MainParsBtn);
01954 if (fbParsWidgetShown) {
01955 MainParsBtn->setText("Back");
01956 QToolTip::add(MainParsBtn, "Back to last selected page");
01957 } else {
01958 MainParsBtn->setText("Pars");
01959 QToolTip::add(MainParsBtn, "Show list of fitter parameters");
01960 }
01961
01962 if (fitter==0) {
01963 MainFitBtn->setEnabled(FALSE);
01964 MainDrawBtn->setEnabled(FALSE);
01965 MainFindBtn->setEnabled(FALSE);
01966 MainParsBtn->setEnabled(FALSE);
01967 } else {
01968 MainFitBtn->setEnabled((fitter->GetNumData()>0) &&
01969 ((fitter->GetNumModel()>0) || (fiPanelMode==FitGui::pm_Simple)));
01970 MainDrawBtn->setEnabled(fitter->GetNumData()>0);
01971 MainFindBtn->setEnabled((fitter->GetNumData()>0) && (fiPanelMode==FitGui::pm_Wizard)
01972 && GetPeakFinder(false));
01973 MainParsBtn->setEnabled(TRUE);
01974 }
01975 }
01976
01977 void TGo4FitPanel::UpdateItemMenu()
01978 {
01979 bool showitem = fiPanelMode==FitGui::pm_Expert;
01980
01981 QString itemtext;
01982
01983 if (showitem) {
01984 QFitItem* item = dynamic_cast<QFitItem*> (FitList->currentItem());
01985 if ((item==0) || (item->ObjectType()==FitGui::ot_fitter)) showitem = FALSE; else
01986 itemtext = item->text(0);
01987 }
01988
01989 if (showitem) {
01990 if (ItemMenu==0) {
01991 ItemMenu = new QPopupMenu(this);
01992 MenuBar->insertItem( itemtext, ItemMenu, 111);
01993 connect(ItemMenu, SIGNAL(aboutToShow()), this, SLOT(AboutToShowItemMenu()) );
01994 } else MenuBar->changeItem(111, itemtext);
01995 } else
01996 if (ItemMenu!=0) {
01997 MenuBar->removeItem(111);
01998 delete ItemMenu;
01999 ItemMenu = 0;
02000 }
02001 }
02002
02003 void TGo4FitPanel::AboutToShowSettMenu()
02004 {
02005 SettMenu->setItemChecked(1, fbNeedConfirmation);
02006 SettMenu->setItemChecked(2, fbShowPrimitives);
02007 SettMenu->setItemChecked(3, fbFreezeMode);
02008 SettMenu->setItemChecked(4, fbSaveWithReferences);
02009 SettMenu->setItemVisible(4, (fiPanelMode==FitGui::pm_Expert) || (fiPanelMode==FitGui::pm_Wizard));
02010
02011 SettMenu->setItemChecked(10,fbUseCurrentRange);
02012 SettMenu->setItemChecked(11,fbDrawModels);
02013 SettMenu->setItemChecked(12,fbDrawComponents);
02014 SettMenu->setItemChecked(13,fbUseSamePanelForDraw);
02015 SettMenu->setItemChecked(14,fbDrawBackground);
02016 SettMenu->setItemChecked(15,fbDrawInfoOnPad);
02017 SettMenu->setItemChecked(16,fbRecalculateGaussWidth);
02018
02019 SettMenu->setItemChecked(17,fiIntegralMode==0);
02020 SettMenu->setItemChecked(18,fiIntegralMode==1);
02021 SettMenu->setItemChecked(19,fiIntegralMode==2);
02022 SettMenu->setItemChecked(20,fiIntegralMode==3);
02023
02024 SettMenu->setItemChecked(21,fiBuffersUsage==0);
02025 SettMenu->setItemChecked(22,fiBuffersUsage==1);
02026 SettMenu->setItemChecked(23,fiBuffersUsage==2);
02027 SettMenu->setItemChecked(24,fiBuffersUsage==3);
02028 }
02029
02030 void TGo4FitPanel::ChangeSettings(int id)
02031 {
02032 switch(id) {
02033 case 1: fbNeedConfirmation = !fbNeedConfirmation; break;
02034 case 2: fbShowPrimitives = !fbShowPrimitives; break;
02035 case 3: fbFreezeMode = !fbFreezeMode; break;
02036 case 4: fbSaveWithReferences = !fbSaveWithReferences; break;
02037 case 10: fbUseCurrentRange = !fbUseCurrentRange; break;
02038 case 11: fbDrawModels = !fbDrawModels; break;
02039 case 12: fbDrawComponents = !fbDrawComponents; break;
02040 case 13: fbUseSamePanelForDraw = !fbUseSamePanelForDraw; break;
02041 case 14: fbDrawBackground = !fbDrawBackground; break;
02042 case 15: fbDrawInfoOnPad = !fbDrawInfoOnPad; break;
02043 case 16: fbRecalculateGaussWidth = !fbRecalculateGaussWidth; UpdateActivePage(); break;
02044 case 17: fiIntegralMode = 0; UpdateActivePage(); break;
02045 case 18: fiIntegralMode = 1; UpdateActivePage(); break;
02046 case 19: fiIntegralMode = 2; UpdateActivePage(); break;
02047 case 20: fiIntegralMode = 3; UpdateActivePage(); break;
02048 case 21: fiBuffersUsage = 0; break;
02049 case 22: fiBuffersUsage = 1; break;
02050 case 23: fiBuffersUsage = 2; break;
02051 case 24: fiBuffersUsage = 3; break;
02052 }
02053
02054 go4sett->setBool("/FitPanel/NeedConfirmation",fbNeedConfirmation);
02055 go4sett->setBool("/FitPanel/ShowPrimitives",fbShowPrimitives);
02056 go4sett->setBool("/FitPanel/SaveWithReferences",fbSaveWithReferences);
02057 go4sett->setBool("/FitPanel/UseCurrentRange",fbUseCurrentRange);
02058 go4sett->setBool("/FitPanel/DrawModels",fbDrawModels);
02059 go4sett->setBool("/FitPanel/DrawComponents",fbDrawComponents);
02060 go4sett->setBool("/FitPanel/UseSamePanelForDraw",fbUseSamePanelForDraw);
02061 go4sett->setBool("/FitPanel/DrawBackground",fbDrawBackground);
02062 go4sett->setBool("/FitPanel/DrawInfoOnPad",fbDrawInfoOnPad);
02063 go4sett->setBool("/FitPanel/RecalculateGaussWidth",fbRecalculateGaussWidth);
02064 go4sett->setInt("/FitPanel/IntegralMode",fiIntegralMode);
02065 go4sett->setInt("/FitPanel/BuffersUsage",fiBuffersUsage);
02066 }
02067
02068 void TGo4FitPanel::AboutToShowFitterMenu()
02069 {
02070 FitterMenu->clear();
02071
02072 TGo4Fitter* fitter = GetFitter();
02073 TGo4WorkSpace* space = TGo4WorkSpace::Instance();
02074 TGo4ViewPanel* panel = LastActivePanel();
02075
02076 bool samepad = (panel==0) ? FALSE : WorkingWithPanel() &&
02077 (panel==ActivePanel()) && (panel->GetActivePad()==ActivePad());
02078
02079 QString padname;
02080 if (panel!=0) padname = QString("panel \"") + panel->caption() + "\"";
02081
02082 if (fiPanelMode==FitGui::pm_Expert)
02083 FitterMenu->insertItem("&Create for workspace", this, SLOT(FitterMenuItemSelected(int)), 0, 1);
02084 FitterMenu->insertItem("Create &for "+padname, this, SLOT(FitterMenuItemSelected(int)), 0, 2);
02085 FitterMenu->insertItem("&Delete", this, SLOT(FitterMenuItemSelected(int)), 0, 3);
02086 FitterMenu->insertSeparator();
02087
02088 FitterMenu->insertItem("Save to &browser", this, SLOT(FitterMenuItemSelected(int)), 0, 21);
02089 if (fiPanelMode==FitGui::pm_Expert)
02090 FitterMenu->insertItem("&Workspace", this, SLOT(FitterMenuItemSelected(int)), 0, 23);
02091 FitterMenu->insertItem("&Update references", this, SLOT(FitterMenuItemSelected(int)), 0, 24);
02092 FitterMenu->insertItem("&Print parameters", this, SLOT(FitterMenuItemSelected(int)), 0, 25);
02093 FitterMenu->insertItem("&Rollback parameters", this, SLOT(FitterMenuItemSelected(int)), 0, 26);
02094
02095 FitterMenu->insertSeparator();
02096
02097 FitterMenu->insertItem("&Close", this, SLOT(FitterMenuItemSelected(int)), 0, 99);
02098
02099 FitterMenu->setItemEnabled(1, TRUE);
02100 FitterMenu->setItemEnabled(2, (panel!=0));
02101 FitterMenu->setItemEnabled(3, (fitter!=0));
02102
02103 FitterMenu->setItemEnabled(11, (fitter!=0) && (panel!=0) && !samepad);
02104 FitterMenu->setItemEnabled(12, (fitter!=0) && (panel!=0) && !samepad);
02105 FitterMenu->setItemEnabled(13, (fitter!=0) && WorkingWithPanel());
02106 FitterMenu->setItemEnabled(14, (fitter!=0) && WorkingWithPanel());
02107
02108 FitterMenu->setItemEnabled(21, (fitter!=0));
02109 FitterMenu->setItemEnabled(22, (fitter!=0));
02110 FitterMenu->setItemEnabled(23, WorkingWithPanel());
02111 FitterMenu->setItemEnabled(24, (fitter!=0));
02112 FitterMenu->setItemEnabled(25, (fitter!=0) && fbParsWidgetShown);
02113 FitterMenu->setItemEnabled(26, (fitter!=0) && fitter->CanRollbackPars());
02114
02115 FitterMenu->setItemEnabled(99, TRUE);
02116 }
02117
02118 void TGo4FitPanel::FitterMenuItemSelected(int id)
02119 {
02120 switch (id) {
02121 case 1: Fitter_New(); break;
02122 case 2: Fitter_NewForActivePad(true); break;
02123 case 3: Fitter_Delete(); break;
02124 case 21: Fitter_SaveToBrowser(); break;
02125 case 23: Fitter_UseWorkspace(); break;
02126 case 24: Fitter_UpdateReferences(); break;
02127 case 25: Fitter_PrintParameters(); break;
02128 case 26: Fitter_RollbackParameters(); break;
02129 case 99: close(); break;
02130 }
02131 }
02132
02133 void TGo4FitPanel::AboutToShowItemMenu()
02134 {
02135 if (ItemMenu==0) return;
02136 QFitItem* item = dynamic_cast<QFitItem*> (FitList->currentItem());
02137 if (item==0) return;
02138 ItemMenu->clear();
02139 if (!FillPopupForItem(item,ItemMenu)) return;
02140 for(uint n=0;n<ItemMenu->count();n++) {
02141 int id = ItemMenu->idAt(n);
02142 ItemMenu->connectItem(id, this, SLOT(ItemMenuItemSelected(int)));
02143 }
02144 }
02145
02146 void TGo4FitPanel::ItemMenuItemSelected(int id)
02147 {
02148 QFitItem* item = dynamic_cast<QFitItem*> (FitList->currentItem());
02149 if (item==0) return;
02150 ExecPopupForItem(item, id );
02151 }
02152
02153 void TGo4FitPanel::focusInEvent( QFocusEvent* event)
02154 {
02155 UpdateStatusBar(0);
02156 QWidget::focusInEvent(event);
02157 }
02158
02159 void TGo4FitPanel::windowActivationChange( bool OldActive)
02160 {
02161 UpdateStatusBar(0);
02162 QWidget::windowActivationChange(OldActive);
02163 }
02164
02165 void TGo4FitPanel::UpdatePFAmplLbl()
02166 {
02167 TGo4FitPeakFinder* finder = GetPeakFinder(true);
02168 if (finder!=0)
02169 PF_AmplLbl->setText(QString("Threshold: ")+QString::number(finder->Get0MaxAmplFactor()*100)+"%");
02170 else
02171 PF_AmplLbl->setText("Threshold:");
02172 PF_AmplLbl->adjustSize();
02173 }
02174
02175 void TGo4FitPanel::UpdatePFRelNoiseLbl()
02176 {
02177 TGo4FitPeakFinder* finder = GetPeakFinder(true);
02178
02179 if (finder!=0)
02180 PF_RelNoiseLbl->setText(QString("Noise factor: ")+QString::number(finder->Get2NoiseFactor()));
02181 else
02182 PF_RelNoiseLbl->setText("Noise factor: ");
02183 PF_RelNoiseLbl->adjustSize();
02184 }
02185
02186 void TGo4FitPanel::PF_MinWidthEdt_textChanged( const QString & str )
02187 {
02188 if (fbFillingWidget) return;
02189 bool ok;
02190 double zn = str.toDouble(&ok);
02191 if (ok) {
02192 TGo4FitPeakFinder* finder = GetPeakFinder(true);
02193 if (finder!=0) finder->Set0MinWidth(zn);
02194 }
02195 }
02196
02197
02198 void TGo4FitPanel::PF_MaxWidthEdt_textChanged( const QString & str )
02199 {
02200 if (fbFillingWidget) return;
02201 bool ok;
02202 double zn = str.toDouble(&ok);
02203 if (ok) {
02204 TGo4FitPeakFinder* finder = GetPeakFinder(true);
02205 if (finder) finder->Set0MaxWidth(zn);
02206 }
02207 }
02208
02209
02210 void TGo4FitPanel::PF_WidthEdit_textChanged( const QString & str)
02211 {
02212 if (fbFillingWidget) return;
02213 bool ok;
02214 double zn = str.toDouble(&ok);
02215 if (ok) {
02216 TGo4FitPeakFinder* finder = GetPeakFinder(true);
02217 if (finder) finder->Set1LineWidth(zn);
02218 }
02219 }
02220
02221 void TGo4FitPanel::PF_AmplSlider_valueChanged( int zn )
02222 {
02223 if (!fbFillingWidget) {
02224 TGo4FitPeakFinder* finder = GetPeakFinder(true);
02225 if (finder) finder->Set0MaxAmplFactor(1.-zn/100.);
02226 UpdatePFAmplLbl();
02227 }
02228 }
02229
02230 void TGo4FitPanel::PF_AmplSlider_sliderReleased()
02231 {
02232 if (!fbFillingWidget)
02233 Button_PeakFinder();
02234 }
02235
02236 void TGo4FitPanel::PF_RelNoiseSlider_valueChanged( int zn )
02237 {
02238 if (!fbFillingWidget) {
02239 TGo4FitPeakFinder* finder = GetPeakFinder(true);
02240 if (finder) finder->Set2NoiseFactor((101-zn)/10.);
02241 UpdatePFRelNoiseLbl();
02242 }
02243 }
02244
02245 void TGo4FitPanel::PF_RelNoiseSlider_sliderReleased()
02246 {
02247 if (!fbFillingWidget)
02248 Button_PeakFinder();
02249 }
02250
02251 void TGo4FitPanel::PF_MinNoiseEdit_textChanged( const QString & str)
02252 {
02253 if (fbFillingWidget) return;
02254 bool ok;
02255 double zn = str.toDouble(&ok);
02256 if (ok) {
02257 TGo4FitPeakFinder* finder = GetPeakFinder(true);
02258 if (finder!=0) finder->Set2NoiseMinimum(zn);
02259 }
02260 }
02261
02262
02263 void TGo4FitPanel::PF_SumUpSpin_valueChanged( int num)
02264 {
02265 if (!fbFillingWidget) {
02266 TGo4FitPeakFinder* finder = GetPeakFinder(true);
02267 if (finder!=0) {
02268 finder->Set2ChannelSum(num);
02269 Button_PeakFinder();
02270 }
02271 }
02272 }
02273
02274
02275 void TGo4FitPanel::UpdateWizDataList()
02276 {
02277 TGo4Fitter* fitter = GetFitter();
02278
02279 fbFillingWidget = true;
02280
02281 bool updatestack = FALSE, updatepaint = FALSE;
02282
02283 Wiz_DataList->clear();
02284 if (fitter==0) fxWizDataName = "";
02285 else {
02286 if ((Wiz_SelectedData()==0) && (fitter->GetNumData()>0)) {
02287 fxWizDataName = fitter->GetDataName(0);
02288 if (fiWizPageIndex<1) updatestack = TRUE;
02289 if (fiPaintMode==0) updatepaint = TRUE;
02290 }
02291
02292 int selindx = -1;
02293 for(Int_t n=0;n<fitter->GetNumData();n++) {
02294 TGo4FitData* data = fitter->GetData(n);
02295 Wiz_DataList->insertItem(data->GetName());
02296 if (strcmp(data->GetName(), fxWizDataName.latin1())==0) selindx = n;
02297 }
02298 Wiz_DataList->setSelected(selindx, TRUE);
02299 if (selindx<0) fxWizDataName = "";
02300 else Wiz_DataList->setSelected(selindx, TRUE);
02301 }
02302 UpdateWizDataBtns();
02303 fbFillingWidget = false;
02304
02305 if (updatestack) {
02306 fiWizPageIndex = 2;
02307 UpdateWizStackWidget();
02308 }
02309 if (updatepaint)
02310 UpdateWizPaint(1);
02311
02312 }
02313
02314 void TGo4FitPanel::UpdateWizDataBtns()
02315 {
02316 TGo4Fitter* fitter = GetFitter();
02317 TGo4FitData* data = Wiz_SelectedData();
02318
02319 Wiz_PFSetupBtn->setEnabled(data!=0);
02320
02321 if (!WorkingWithPanel()) {
02322 Wiz_RebuildDataBtn->setShown(FALSE);
02323 Wiz_AddDataBtn->setShown(TRUE);
02324 Wiz_DelDataBtn->setShown(TRUE);
02325 Wiz_AddDataBtn->setEnabled(fitter!=0);
02326 Wiz_DelDataBtn->setEnabled(data!=0);
02327 } else {
02328 Wiz_RebuildDataBtn->setShown(TRUE);
02329 Wiz_RebuildDataBtn->setEnabled(fitter!=0);
02330 Wiz_AddDataBtn->setShown(FALSE);
02331 Wiz_DelDataBtn->setShown(FALSE);
02332 }
02333 }
02334
02335 void TGo4FitPanel::UpdateWizModelsList(bool changestack)
02336 {
02337 fbFillingWidget = true;
02338
02339 Wiz_ModelList->clear();
02340
02341 TGo4Fitter* fitter = GetFitter();
02342
02343 Wiz_ShowAllMod->setChecked(fbWizShowAllModels);
02344 int selindx = -1;
02345 if(fitter!=0) {
02346 TGo4FitData* data = Wiz_SelectedData();
02347 int indx = 0;
02348 for(Int_t n=0;n<fitter->GetNumModel();n++) {
02349 TGo4FitModel* model = fitter->GetModel(n);
02350 if (data && !fbWizShowAllModels)
02351 if (!model->IsAssignTo(data->GetName())) continue;
02352
02353 bool assign = FALSE;
02354 if (data && model->IsAssignTo(data->GetName())) assign = TRUE;
02355 if (assign) Wiz_ModelList->insertItem(QPixmap(SelectedXPM), model->GetName());
02356 else Wiz_ModelList->insertItem(QPixmap(UnselectedXPM), model->GetName());
02357
02358 if (strcmp(model->GetName(), fxWizModelName.latin1())==0) selindx = indx;
02359 indx++;
02360 }
02361
02362 Wiz_ModelList->setSelected(selindx, TRUE);
02363 if (selindx>=0)
02364 Wiz_ModelList->setCurrentItem(selindx);
02365
02366 if (selindx<0) fxWizModelName = "";
02367 else Wiz_ModelList->ensureCurrentVisible();
02368
02369 } else fxWizModelName = "";
02370
02371 if (changestack)
02372 if (selindx>=0) fiWizPageIndex = 1; else
02373 if (fiWizPageIndex==1) fiWizPageIndex = 0;
02374
02375 UpdateWizModelsBtns();
02376
02377 fbFillingWidget = false;
02378
02379 if(changestack)
02380 UpdateWizStackWidget();
02381 }
02382
02383 void TGo4FitPanel::UpdateWizModelsBtns()
02384 {
02385 TGo4Fitter* fitter = GetFitter();
02386 TGo4FitModel* model = Wiz_SelectedModel();
02387
02388 Wiz_ShowAllMod->setShown(!WorkingWithOnlyPad());
02389
02390 if (fitter) {
02391 Wiz_AddModelBtn->setEnabled(TRUE);
02392 Wiz_DelModelBtn->setEnabled(model!=0);
02393 Wiz_CloneModelBtn->setEnabled(model!=0);
02394 Wiz_ShowAllMod->setEnabled(TRUE);
02395 } else {
02396 Wiz_AddModelBtn->setEnabled(FALSE);
02397 Wiz_DelModelBtn->setEnabled(FALSE);
02398 Wiz_CloneModelBtn->setEnabled(FALSE);
02399 Wiz_ShowAllMod->setEnabled(FALSE);
02400 }
02401 }
02402
02403 void TGo4FitPanel::UpdateWizStackWidget()
02404 {
02405 fbFillingWidget = true;
02406 TGo4Fitter* fitter = GetFitter();
02407
02408 int indx = -1;
02409 if (fitter==0) fiWizPageIndex = -1;
02410 else indx = fiWizPageIndex;
02411
02412 QWidget* target = 0;
02413
02414 switch (indx) {
02415 case -1:
02416 target = Wiz_EmptyPage;
02417 break;
02418 case 0: {
02419 target = Wiz_FitterPage;
02420
02421 int typ = fitter->GetFitFunctionType();
02422 if (typ==TGo4Fitter::ff_user) typ = TGo4Fitter::ff_least_squares;
02423 Wiz_FitFuncCmb->setCurrentItem(typ);
02424
02425 Wiz_UseAmplEstimChk->setChecked(fbUseAmplEstim);
02426 Wiz_MigradIterSpin->setValue(fiNumMigradIter);
02427
02428 break;
02429 }
02430
02431 case 1: {
02432 TGo4FitModel* model = Wiz_SelectedModel();
02433 if (model==0) break;
02434
02435 target = Wiz_ModelPage;
02436
02437 QString modelinfo;
02438 Wiz_GetModelInfo(model, &modelinfo);
02439 Wiz_ModelInfoLbl->setText(modelinfo);
02440
02441 Wiz_BackgroundChk->setChecked(model->GetGroupIndex()==0);
02442
02443 Wiz_ModelBufChk->setChecked(model->GetUseBuffers());
02444 Wiz_ModelBufChk->setEnabled(fiBuffersUsage==3);
02445
02446 FillParsTable(Wiz_ParTable, fitter, model, FALSE, fxWizPars);
02447
02448 break;
02449 }
02450
02451 case 2: {
02452 TGo4FitData* data = Wiz_SelectedData();
02453 if (data==0) break;
02454
02455 target = Wiz_DataPage;
02456
02457 QString datainfo("Data: ");
02458 datainfo += data->GetName();
02459 datainfo += " of class: ";
02460 datainfo += data->ClassName();
02461 if (fiIntegralMode==1) {
02462 datainfo += "\nCounts=";
02463 double v = fitter->CalculatesIntegral(data->GetName(),0,kTRUE);
02464 datainfo += QString::number(v);
02465 }
02466 if (fiIntegralMode==2) {
02467 datainfo += "\nIntegral=";
02468 double v = fitter->CalculatesIntegral(data->GetName(),0,kFALSE);
02469 datainfo += QString::number(v);
02470 }
02471 Wiz_DataInfoLbl->setText(datainfo);
02472
02473 QString models("Models:");
02474 for(int n=0;n<fitter->GetNumModel();n++) {
02475 TGo4FitModel* model = fitter->GetModel(n);
02476 if (model->IsAssignTo(data->GetName())) {
02477 if (models.length()>45) {
02478 models += " ...";
02479 break;
02480 }
02481 models += " ";
02482 models += model->GetName();
02483 }
02484 }
02485 Wiz_DataModelsLbl->setText(models);
02486
02487 Wiz_DataBufChk->setChecked(
02488 (fiBuffersUsage==1) || (fiBuffersUsage==2) ||
02489 ((fiBuffersUsage==3) && data->GetUseBuffers()));
02490 Wiz_DataBufChk->setEnabled(fiBuffersUsage==3);
02491
02492 fxWizSlots->Clear();
02493 data->FillSlotList(fxWizSlots);
02494
02495 Wiz_DataSlotsTable->setNumRows(fxWizSlots->GetLast()+1);
02496
02497 for(int n=0;n<=fxWizSlots->GetLast();n++) {
02498 TGo4FitSlot* slot = dynamic_cast<TGo4FitSlot*> (fxWizSlots->At(n));
02499 if (slot==0) continue;
02500
02501 Wiz_DataSlotsTable->verticalHeader()->setLabel(n, slot->GetName());
02502 TObject* obj = slot->GetObject();
02503
02504 if (obj==0) {
02505 Wiz_DataSlotsTable->setText(n, 0, " --- ");
02506 Wiz_DataSlotsTable->setText(n, 1, slot->GetClass()->GetName());
02507 Wiz_DataSlotsTable->setText(n, 2, "false");
02508 } else {
02509 Wiz_DataSlotsTable->setText(n, 0, obj->GetName());
02510 Wiz_DataSlotsTable->setText(n, 1, obj->ClassName());
02511 if (slot->GetOwned()) Wiz_DataSlotsTable->setText(n, 2, "true");
02512 else Wiz_DataSlotsTable->setText(n, 2, "false");
02513 }
02514
02515 Wiz_DataSlotsTable->setText(n, 3, Wiz_GetSlotSourceInfo(slot));
02516 }
02517
02518 for(int n=0;n<=3;n++)
02519 Wiz_DataSlotsTable->adjustColumn(n);
02520
02521 Wiz_DataUseRangeBtn->setEnabled(FindPadWhereData(data)!=0);
02522 if (data!=0)
02523 Wiz_DataClearRangesBtn->setEnabled(data->IsAnyRangeLimits());
02524 Wiz_DrawDataBtn->setEnabled(data!=0);
02525
02526 break;
02527 }
02528 case 3: {
02529 target = Wiz_PFPage;
02530
02531 TGo4FitPeakFinder* finder = GetPeakFinder(true);
02532 if (finder==0) break;
02533
02534 UpdateStatusBar(0);
02535
02536 FindersTab->setCurrentPage(finder->GetPeakFinderType());
02537
02538 Wiz_PFUsePolynChk->setChecked(finder->GetUsePolynom());
02539 Wiz_PFPolynSpin->setEnabled(finder->GetUsePolynom());
02540 Wiz_PFPolynSpin->setValue(finder->GetPolynomOrder());
02541
02542 PF_MinWidthEdt->setText(QString::number(finder->Get0MinWidth()));
02543 PF_MaxWidthEdt->setText(QString::number(finder->Get0MaxWidth()));
02544 PF_AmplSlider->setValue(int(100*(1.-finder->Get0MaxAmplFactor())));
02545 UpdatePFAmplLbl();
02546
02547 PF_WidthEdit->setText(QString::number(finder->Get1LineWidth()));
02548
02549 int zn = int(10*finder->Get2NoiseFactor());
02550 PF_RelNoiseSlider->setValue(101 - zn);
02551 UpdatePFRelNoiseLbl();
02552 PF_MinNoiseEdit->setText(QString::number(finder->Get2NoiseMinimum()));
02553 PF_SumUpSpin->setValue(finder->Get2ChannelSum());
02554
02555 break;
02556 }
02557 }
02558
02559 if (target) Wiz_Stack->raiseWidget(target);
02560 else Wiz_Stack->raiseWidget(Wiz_EmptyPage);
02561
02562 fbFillingWidget = false;
02563 }
02564
02565 void TGo4FitPanel::UpdateWizPaint(int mode)
02566 {
02567 RemovePrimitives();
02568
02569 if (!fbShowPrimitives) return;
02570
02571 if (mode>=0) fiPaintMode = mode;
02572
02573 TGo4Fitter* fitter = GetFitter();
02574 TGo4FitModel* model = Wiz_SelectedModel();
02575 TGo4FitData* data = Wiz_SelectedData();
02576
02577 if ((fitter!=0) && (data!=0) && (fiPaintMode==1)) {
02578 TPad* pad = FindPadWhereData(data);
02579
02580 if (PaintModelsFor(fitter, data, 0, false))
02581 for(Int_t n=0;n<data->GetNumRangeCondition();n++)
02582 PaintRange(data, n, pad, 0);
02583 }
02584
02585 if ((fitter!=0) && (model!=0) && (fiPaintMode==2)) {
02586 for(Int_t n=0;n<model->NumAssigments();n++) {
02587 data = fitter->FindData(model->AssignmentName(n));
02588 if ((data!=0) && !data->IsAnyDataTransform()) {
02589 TPad* pad = FindPadWhereData(data);
02590 PaintModel(model, pad, 0);
02591 }
02592 }
02593 }
02594 }
02595
02596 void TGo4FitPanel::Wiz_DataListSelect(int indx)
02597 {
02598 if (fbFillingWidget) return;
02599 QString name = Wiz_DataList->text(indx);
02600
02601 if ( (name==fxWizDataName) &&
02602 (fiWizPageIndex == 2) ) return;
02603 fxWizDataName = name;
02604 fiWizPageIndex = 2;
02605 UpdateWizDataBtns();
02606 UpdateWizModelsList(FALSE);
02607 UpdateWizStackWidget();
02608 UpdateWizPaint(1);
02609 }
02610
02611 void TGo4FitPanel::Wiz_DataList_highlighted( int indx)
02612 {
02613 Wiz_DataListSelect(indx);
02614 }
02615
02616 void TGo4FitPanel::Wiz_ModelListSelect(int indx, bool ontext)
02617 {
02618 if (fbFillingWidget) return;
02619
02620 QString name = Wiz_ModelList->text(indx);
02621
02622 bool needupdate = ( (name != fxWizModelName.latin1()) ||
02623 (fiWizPageIndex != 1) );
02624
02625 fxWizModelName = name;
02626 fiWizPageIndex = 1;
02627
02628 if (!ontext) {
02629
02630 TGo4Fitter* fitter = GetFitter();
02631 TGo4FitModel* model = Wiz_SelectedModel();
02632 TGo4FitData* data = Wiz_SelectedData();
02633 if ((fitter!=0) && (data!=0) && (model!=0)) {
02634 bool wasassigned = model->IsAssignTo(data->GetName());
02635 if (wasassigned) fitter->ClearModelAssignmentTo(model->GetName(), data->GetName());
02636 else fitter->AssignModelTo(model->GetName(), data->GetName());
02637
02638 fbFillingWidget = true;
02639 if (!wasassigned) Wiz_ModelList->changeItem(QPixmap(SelectedXPM), model->GetName(), indx);
02640 else Wiz_ModelList->changeItem(QPixmap(UnselectedXPM), model->GetName(), indx);
02641 Wiz_ModelList->setSelected(indx, TRUE);
02642 fbFillingWidget = false;
02643 needupdate = TRUE;
02644 }
02645 }
02646
02647 if (needupdate) {
02648 UpdateWizModelsBtns();
02649 UpdateWizStackWidget();
02650 UpdateWizPaint(2);
02651 }
02652 }
02653
02654 void TGo4FitPanel::Wiz_ModelList_highlighted(int indx)
02655 {
02656 Wiz_ModelListSelect(indx, TRUE);
02657 }
02658
02659
02660 void TGo4FitPanel::Wiz_AddDataBtn_clicked()
02661 {
02662 if (fbFillingWidget) return;
02663 QPopupMenu menu(0,"WizPopup");
02664
02665 Wiz_PrepareDataTypeList(&menu);
02666 int id = menu.exec(Wiz_AddDataBtn->mapToGlobal(QPoint(5,5)));
02667 TGo4FitData* data = Wiz_CreateNewData(id);
02668 if (data) {
02669 fxWizDataName = data->GetName();
02670 fiWizPageIndex = 2;
02671 UpdateWizDataList();
02672 UpdateWizModelsList(FALSE);
02673 UpdateWizStackWidget();
02674 UpdateWizPaint(1);
02675 UpdateStatusBar(0);
02676 }
02677 }
02678
02679
02680 void TGo4FitPanel::Wiz_DelDataBtn_clicked()
02681 {
02682 if (fbFillingWidget) return;
02683
02684 if (Wiz_RemoveData()) {
02685 UpdateWizDataList();
02686 UpdateWizModelsList(FALSE);
02687 fiWizPageIndex = 0;
02688 UpdateWizStackWidget();
02689 UpdateWizPaint(0);
02690 UpdateStatusBar(0);
02691 }
02692 }
02693
02694 void TGo4FitPanel::Wiz_AddModelBtn_clicked()
02695 {
02696 if (fbFillingWidget) return;
02697 QPopupMenu menu(0,"WizPopup");
02698
02699 Wiz_PrepareModelTypeList(&menu);
02700 int id = menu.exec(Wiz_AddModelBtn->mapToGlobal(QPoint(5,5)));
02701 TGo4FitModel* model = Wiz_CreateNewModel(id);
02702 if (model) fxWizModelName = model->GetName();
02703 UpdateWizModelsList(TRUE);
02704 if(Wiz_SelectedModel()!=0) UpdateWizPaint(2);
02705 UpdateStatusBar(0);
02706 }
02707
02708 void TGo4FitPanel::Wiz_DelModelBtn_clicked()
02709 {
02710 if (fbFillingWidget) return;
02711
02712 TGo4Fitter* fitter = GetFitter();
02713 if (fitter==0) return;
02714
02715 if(fbNeedConfirmation)
02716 if ( QMessageBox::information(0,"Delete models",
02717 QString("Are you sure to delete selected models"),
02718 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
02719
02720 for(uint n=0; n<Wiz_ModelList->count();n++) {
02721 if (!Wiz_ModelList->isSelected(n)) continue;
02722 QString name = Wiz_ModelList->text(n);
02723 fitter->RemoveModel(name, kTRUE);
02724 }
02725
02726 fxWizModelName = "";
02727 UpdateWizModelsList(TRUE);
02728 UpdateWizPaint(0);
02729 UpdateStatusBar(0);
02730 }
02731
02732 void TGo4FitPanel::Wiz_CloneModelBtn_clicked()
02733 {
02734 if (fbFillingWidget) return;
02735
02736 TGo4Fitter* fitter = GetFitter();
02737 if (fitter==0) return;
02738
02739 for(uint n=0; n<Wiz_ModelList->count();n++) {
02740 if (!Wiz_ModelList->isSelected(n)) continue;
02741 QString name = Wiz_ModelList->text(n);
02742 fitter->CloneModel(name);
02743 }
02744
02745 fxWizModelName = "";
02746 UpdateWizModelsList(TRUE);
02747 UpdateWizPaint(0);
02748 UpdateStatusBar(0);
02749 }
02750
02751 void TGo4FitPanel::Wiz_ShowAllMod_toggled(bool zn)
02752 {
02753 if (fbFillingWidget) return;
02754 fbWizShowAllModels = zn;
02755 UpdateWizModelsList(TRUE);
02756 UpdateWizPaint(2);
02757 }
02758
02759
02760 void TGo4FitPanel::Wiz_FitFuncCmb_activated( int typ)
02761 {
02762 if (!fbFillingWidget && GetFitter())
02763 GetFitter()->SetFitFunctionType(typ);
02764 }
02765
02766
02767 void TGo4FitPanel::Wiz_FitNameEdt_textChanged( const QString & name)
02768 {
02769 TGo4Fitter* fitter = GetFitter();
02770 if(fbFillingWidget || (fitter==0) || (name.length()==0)) return;
02771 fitter->SetName(name);
02772
02773 fiWizPageIndex = 0;
02774 UpdateWizStackWidget();
02775 UpdateWizPaint(0);
02776
02777 UpdateStatusBar(0);
02778 }
02779
02780
02781 void TGo4FitPanel::Wiz_ParTable_valueChanged( int nrow, int ncol)
02782 {
02783 ParsTableChanged(Wiz_ParTable, nrow, ncol, FALSE, fxWizPars, TRUE);
02784 }
02785
02786
02787 void TGo4FitPanel::Wiz_DataList_doubleClicked( QListBoxItem * )
02788 {
02789 TGo4Fitter* fitter = GetFitter();
02790 TGo4FitData* data = Wiz_SelectedData();
02791 if ((data==0) || (fitter==0)) return;
02792 bool ok;
02793 QString newname = QInputDialog::getText("Change data name", "Input new name", QLineEdit::Normal, data->GetName(), &ok, this);
02794 if (ok && (newname.length()>0) && (newname!=data->GetName())) {
02795 if (fitter->FindData(newname)) {
02796 QMessageBox::information(this, "Fit panel", "Unable to rename data.\n Name " +
02797 newname + " already exists","return");
02798 return;
02799 }
02800 fitter->ChangeDataNameInAssignments(data->GetName(), newname);
02801 data->SetName(newname);
02802 fxWizDataName = newname;
02803 UpdateWizDataList();
02804 UpdateWizPaint(1);
02805 }
02806 }
02807
02808
02809 void TGo4FitPanel::Wiz_ModelList_doubleClicked( QListBoxItem * )
02810 {
02811 TGo4Fitter* fitter = GetFitter();
02812 TGo4FitModel* model = Wiz_SelectedModel();
02813 if ((model==0) || (fitter==0)) return;
02814 bool ok;
02815 QString newname = QInputDialog::getText("Change model name", "Input new name", QLineEdit::Normal, model->GetName(), &ok, this);
02816 if (ok && (newname.length()>0) && (newname!=model->GetName())) {
02817 if (fitter->FindModel(newname)) {
02818 QMessageBox::information(this, "Fit panel", QString("Unable to rename model.\n Name ")+
02819 newname + " already exists\n", "Return");
02820 return;
02821 }
02822 model->SetName(newname);
02823 fxWizModelName = newname;
02824 UpdateWizModelsList(TRUE);
02825 UpdateWizPaint(2);
02826 }
02827 }
02828
02829 void TGo4FitPanel::Wiz_RebuildDataBtn_clicked()
02830 {
02831 Wiz_RebuildDataList();
02832 }
02833
02834 void TGo4FitPanel::Wiz_DataBufChk_toggled( bool zn)
02835 {
02836 if (fbFillingWidget) return;
02837 TGo4FitData* data = Wiz_SelectedData();
02838 if (data) data->SetUseBuffers(zn);
02839 }
02840
02841
02842 void TGo4FitPanel::Wiz_UseAmplEstimChk_toggled( bool chk)
02843 {
02844 if (!fbFillingWidget)
02845 fbUseAmplEstim = chk;
02846 }
02847
02848
02849 void TGo4FitPanel::Wiz_MigradIterSpin_valueChanged( int num)
02850 {
02851 if (!fbFillingWidget)
02852 fiNumMigradIter = num;
02853 }
02854
02855
02856 void TGo4FitPanel::Wiz_DataSlotsTable_contextMenuRequested( int nrow, int ncol, const QPoint& pnt )
02857 {
02858 if (fbFillingWidget || (fxWizSlots==0)) return;
02859
02860 if ((nrow<0) || (ncol<0) || (nrow>fxWizSlots->GetLast())) return;
02861
02862 TGo4FitSlot* slot = dynamic_cast<TGo4FitSlot*> (fxWizSlots->At(nrow));
02863 if (slot==0) return;
02864
02865 QPopupMenu menu(0,"SlotPopup");
02866
02867 if (FillPopupForSlot(slot,&menu)) {
02868 int id = menu.exec(pnt);
02869 ExecutePopupForSlot(0, slot, id );
02870 }
02871 }
02872
02873 void TGo4FitPanel::Wiz_DataUseRangeBtn_clicked()
02874 {
02875 if (!fbFillingWidget)
02876 Wiz_UseSelectedRange();
02877 }
02878
02879
02880 void TGo4FitPanel::Wiz_DataClearRangesBtn_clicked()
02881 {
02882 if (fbFillingWidget) return;
02883 TGo4FitData* data = Wiz_SelectedData();
02884 if (data!=0) {
02885 data->ClearRanges();
02886 UpdateActivePage();
02887 }
02888 }
02889
02890 void TGo4FitPanel::Wiz_DrawDataBtn_clicked()
02891 {
02892 if (fbFillingWidget) return;
02893 if (Wiz_SelectedData()!=0)
02894 Button_FitterDraw(Wiz_SelectedData());
02895 }
02896
02897 void TGo4FitPanel::MainAttachBtn_clicked()
02898 {
02899 UpdateStatusBar(0);
02900
02901 Button_WorkWithPanel();
02902 }
02903
02904 void TGo4FitPanel::MainFitBtn_clicked()
02905 {
02906 QApplication::setOverrideCursor(Qt::WaitCursor);
02907
02908 Button_PerformFit();
02909
02910 QApplication::restoreOverrideCursor();
02911 }
02912
02913 void TGo4FitPanel::MainDrawBtn_clicked()
02914 {
02915 Button_FitterDraw(0);
02916 }
02917
02918 void TGo4FitPanel::MainFindBtn_clicked()
02919 {
02920 if (GetFitter()!=0)
02921 Button_PeakFinder();
02922 }
02923
02924 void TGo4FitPanel::Wiz_DataList_clicked( QListBoxItem * )
02925 {
02926 Wiz_DataListSelect(Wiz_DataList->currentItem());
02927 }
02928
02929 void TGo4FitPanel::Wiz_DataList_pressed( QListBoxItem * )
02930 {
02931 Wiz_DataListSelect(Wiz_DataList->currentItem());
02932 }
02933
02934 void TGo4FitPanel::Wiz_DataList_selected( int indx)
02935 {
02936 Wiz_DataListSelect(indx);
02937 }
02938
02939 void TGo4FitPanel::Wiz_ModelList_selected( int indx)
02940 {
02941 Wiz_ModelListSelect(indx, TRUE);
02942 }
02943
02944 void TGo4FitPanel::MainParsBtn_clicked()
02945 {
02946 fbParsWidgetShown = !fbParsWidgetShown;
02947
02948 UpdateActivePage();
02949 }
02950
02951 void TGo4FitPanel::FillParsWidget()
02952 {
02953 TGo4Fitter* fitter = GetFitter();
02954 if (fitter==0) return;
02955 fbFillingWidget = true;
02956
02957 Double_t FF = fitter->GetResultFF();
02958 Int_t NDF = fitter->GetResultNDF();
02959 if ((FF==0) && (NDF==0)) Par_FitterResLbl->hide();
02960 else {
02961 Par_FitterResLbl->setText("Result: Fit func = " + QString::number(FF) +
02962 " NDF = " + QString::number(NDF));
02963 Par_FitterResLbl->show();
02964 }
02965
02966 FillParsTable(ParsTable, fitter, 0, LineParsChk->isChecked(), fxParsTableList);
02967 fbFillingWidget = false;
02968 }
02969
02970 void TGo4FitPanel::LineParsChk_toggled(bool)
02971 {
02972 if (fbFillingWidget) return;
02973
02974 TGo4Fitter* fitter = GetFitter();
02975 if (fitter==0) return;
02976 fbFillingWidget = true;
02977 FillParsTable(ParsTable, fitter, 0, LineParsChk->isChecked(), fxParsTableList);
02978 WidgetStack->raiseWidget(PageParameters);
02979 fbFillingWidget = false;
02980 }
02981
02982
02983 void TGo4FitPanel::ParsTable_valueChanged( int nrow, int ncol)
02984 {
02985 if (!fbFillingWidget)
02986 ParsTableChanged(ParsTable, nrow, ncol, LineParsChk->isChecked(), fxParsTableList, FALSE);
02987 }
02988
02989
02990 void TGo4FitPanel::FillParsTable(QTable* table, TGo4Fitter* fitter, TGo4FitModel* model, bool LinesView, TObjArray* TableList) {
02991 if ((table==0) || (fitter==0) || (TableList==0)) return;
02992
02993 if (model && LinesView) return;
02994 TableList->Clear();
02995
02996 for (int n=0;n<table->numRows();n++) table->clearCell(n, 0);
02997
02998 for (int nr=0;nr<table->numRows();nr++)
02999 for (int nc=0;nc<table->numCols();nc++)
03000 if (table->item(nr,nc))
03001 table->item(nr,nc)->setEnabled(TRUE);
03002
03003 if (LinesView) {
03004 int MaxAxis = 0;
03005 for (Int_t n=0; n<fitter->GetNumModel();n++) {
03006 TGo4FitModel* m = fitter->GetModel(n);
03007 if (m==0) continue;
03008 Double_t zn;
03009 for (int naxis=0;naxis<10;naxis++)
03010 if (m->GetPosition(naxis,zn) || m->GetWidth(naxis,zn)) MaxAxis = naxis;
03011 }
03012
03013 int nfcol = (fiIntegralMode>0) ? 2 : 1;
03014 table->setNumCols(nfcol+(MaxAxis+1)*2);
03015 table->horizontalHeader()->setLabel(0,"Amplitude");
03016 if (fiIntegralMode==1)
03017 table->horizontalHeader()->setLabel(1,"Counts");
03018 else if (fiIntegralMode==2)
03019 table->horizontalHeader()->setLabel(1,"Integral");
03020 else if (fiIntegralMode==3)
03021 table->horizontalHeader()->setLabel(1,"Gauss Int");
03022
03023 for (int naxis=0;naxis<=MaxAxis;naxis++) {
03024 QString capt = QString("Position ") + QString::number(naxis);
03025 table->horizontalHeader()->setLabel(nfcol + naxis*2, capt);
03026 if (fbRecalculateGaussWidth)
03027 capt = QString("FWHM ");
03028 else
03029 capt = QString("Sigma ");
03030 capt += QString::number(naxis);
03031 table->horizontalHeader()->setLabel(nfcol+1 + naxis*2, capt);
03032 }
03033
03034 table->setNumRows(fitter->GetNumModel());
03035
03036 for (Int_t n=0; n<fitter->GetNumModel();n++) {
03037 TGo4FitModel* m = fitter->GetModel(n);
03038 TableList->Add(m);
03039
03040 bool recalculatew = (m->InheritsFrom(TGo4FitModelGauss1::Class()) ||
03041 m->InheritsFrom(TGo4FitModelGauss2::Class()) ||
03042 m->InheritsFrom(TGo4FitModelGaussN::Class())) &&
03043 fbRecalculateGaussWidth;
03044 double widthk = recalculatew ? 2.3548 : 1.0;
03045
03046 table->verticalHeader()->setLabel(n, m->GetName());
03047 table->setText(n, 0, QString::number(m->GetAmplValue()));
03048 table->item(n,0)->setEnabled(m->GetAmplPar());
03049
03050 if (fiIntegralMode>0) {
03051 Double_t v = 0.;
03052 TGo4FitData* data = Wiz_SelectedData();
03053 switch (fiIntegralMode) {
03054 case 1:
03055 if (data!=0)
03056 v = fitter->CalculatesIntegral(data->GetName(), m->GetName(), kTRUE);
03057 else
03058 v = fitter->CalculatesModelIntegral(m->GetName(), kTRUE);
03059 break;
03060 case 2:
03061 if (data!=0)
03062 v = fitter->CalculatesIntegral(data->GetName(), m->GetName(), kFALSE);
03063 else
03064 v = fitter->CalculatesModelIntegral(m->GetName(), kFALSE);
03065 break;
03066 case 3: v = m->Integral(); break;
03067 default: v = 0;
03068 }
03069 if ((v<=0.) && (fiIntegralMode==3))
03070 table->setText(n, 1, "---");
03071 else
03072 table->setText(n, 1, QString::number(v));
03073 table->item(n,1)->setEnabled(FALSE);
03074 }
03075
03076 for (int naxis=0;naxis<=MaxAxis;naxis++) {
03077
03078 Double_t pos, width;
03079
03080 if (m->GetPosition(naxis,pos)) {
03081 table->setText(n, nfcol+naxis*2, QString::number(pos));
03082 table->item(n, nfcol+naxis*2)->setEnabled(TRUE);
03083 } else {
03084 table->setText(n, nfcol+naxis*2, "---");
03085 table->item(n, nfcol+naxis*2)->setEnabled(FALSE);
03086 }
03087
03088 if (m->GetWidth(naxis,width)) {
03089 table->setText(n, nfcol+1+naxis*2, QString::number(width*widthk));
03090 table->item(n, nfcol+1+naxis*2)->setEnabled(TRUE);
03091 } else {
03092 table->setText(n, nfcol+1+naxis*2, "---");
03093 table->item(n, nfcol+1+naxis*2)->setEnabled(FALSE);
03094 }
03095 }
03096 }
03097
03098 } else {
03099
03100 TGo4FitParsList* pars = (model==0) ? dynamic_cast<TGo4FitParsList*> (fitter) :
03101 dynamic_cast<TGo4FitParsList*> (model);
03102 if (pars==0) return;
03103
03104 for(Int_t n=0; n<pars->NumPars();n++)
03105 TableList->Add(pars->GetPar(n));
03106
03107 table->setNumCols(6);
03108 table->horizontalHeader()->setLabel(0,"Fixed");
03109 table->horizontalHeader()->setLabel(1,"Value");
03110 table->horizontalHeader()->setLabel(2,"Error");
03111 table->horizontalHeader()->setLabel(3,"Epsilon");
03112 table->horizontalHeader()->setLabel(4,"Min");
03113 table->horizontalHeader()->setLabel(5,"Max");
03114
03115 table->setNumRows(TableList->GetLast()+1);
03116
03117 for(Int_t n=0;n<=TableList->GetLast();n++) {
03118 TGo4FitParameter* par = dynamic_cast<TGo4FitParameter*> (TableList->At(n));
03119 if (par==0) continue;
03120
03121 if (model) table->verticalHeader()->setLabel(n, par->GetName());
03122 else table->verticalHeader()->setLabel(n, par->GetFullName());
03123
03124 QCheckTableItem* checkitem = new QCheckTableItem(table, "fix");
03125 checkitem->setChecked(par->GetFixed());
03126 table->setItem(n, 0, checkitem);
03127
03128 table->setText(n, 1, QString::number(par->GetValue()));
03129 table->item(n,1)->setEnabled(!par->GetFixed());
03130
03131 table->setText(n, 2, QString::number(par->GetError()));
03132
03133 Double_t eps, min, max;
03134 if (par->GetEpsilon(eps)) table->setText(n, 3, QString::number(eps));
03135 else table->setText(n, 3, "");
03136
03137
03138 if (par->GetRange(min,max)) {
03139 table->setText(n, 4, QString::number(min));
03140 table->setText(n, 5, QString::number(max));
03141 } else {
03142 table->setText(n, 4, "");
03143 table->setText(n, 5, "");
03144 }
03145 }
03146 }
03147
03148 for(int n=0;n<table->numCols();n++)
03149 table->adjustColumn(n);
03150
03151 table->verticalHeader()->adjustHeaderSize();
03152 table->horizontalHeader()->adjustHeaderSize();
03153 }
03154
03155 void TGo4FitPanel::ParsTableChanged(QTable* table, int nrow, int ncol, bool LinesView, TObjArray* TableList, bool updatepaint) {
03156 if (fbFillingWidget || (table==0) || (TableList==0)) return;
03157
03158 if ((nrow<0) || (nrow>TableList->GetLast())) return;
03159
03160 if (LinesView) {
03161 TGo4FitModel* model = dynamic_cast<TGo4FitModel*> (TableList->At(nrow));
03162 if (model==0) return;
03163
03164 bool recalculatew = (model->InheritsFrom(TGo4FitModelGauss1::Class()) ||
03165 model->InheritsFrom(TGo4FitModelGauss2::Class()) ||
03166 model->InheritsFrom(TGo4FitModelGaussN::Class())) &&
03167 fbRecalculateGaussWidth;
03168 double widthk = recalculatew ? 2.3548 : 1.0;
03169
03170 bool ok = FALSE;
03171 double zn = table->text(nrow, ncol).toDouble(&ok);
03172 if (!ok) return;
03173
03174 if (ncol==0) model->SetAmplValue(zn); else {
03175 int nfcol = (fiIntegralMode>0) ? 2 : 1;
03176 int naxis = (ncol-nfcol) /2;
03177 if ((ncol-nfcol) % 2 == 0) model->SetPosition(naxis, zn);
03178 else model->SetWidth(naxis, zn/widthk);
03179 }
03180
03181 } else {
03182
03183 TGo4FitParameter* par = dynamic_cast<TGo4FitParameter*> (TableList->At(nrow));
03184 if (par==0) return;
03185
03186 switch (ncol) {
03187 case 0: {
03188 QCheckTableItem* checkitem = dynamic_cast<QCheckTableItem*> ( table->item(nrow,0));
03189 if (checkitem) par->SetFixed(checkitem->isChecked());
03190 table->item(nrow,1)->setEnabled(!par->GetFixed());
03191 break; }
03192 case 1: {
03193 if (par->GetFixed()) break;
03194 bool ok = FALSE;
03195 double zn = table->text(nrow,1).toDouble(&ok);
03196 if (ok) {
03197 par->SetValue(zn);
03198 if (updatepaint) UpdateWizPaint(2);
03199 }
03200 break; }
03201 case 2: {
03202 if (par->GetFixed()) break;
03203 bool ok = FALSE;
03204 double zn = table->text(nrow,2).toDouble(&ok);
03205 if (ok) par->SetError(zn);
03206 break; }
03207 case 3: {
03208 bool ok = FALSE;
03209 double zn = table->text(nrow,3).toDouble(&ok);
03210 if (ok) par->SetEpsilon(zn);
03211 break; }
03212 case 4:
03213 case 5: {
03214 cout << "Changing col " << ncol << endl;
03215
03216 bool ok = FALSE;
03217 bool range_changed = false;
03218 double zn = table->text(nrow, ncol).toDouble(&ok);
03219 if(ok) {
03220
03221 bool changemin = false;
03222 bool changemax = false;
03223
03224 Double_t min, max;
03225 if (!par->GetRange(min,max)) {
03226 double vvv = par->GetValue();
03227 if (ncol==4) {
03228 min = zn;
03229 if (min<vvv) max = 2*vvv - min;
03230 else max = min;
03231 changemax = true;
03232 } else {
03233 max = zn;
03234 if (max>vvv) min = 2*vvv - max;
03235 else min = max;
03236 changemin = true;
03237 }
03238 } else
03239 if (ncol==4) {
03240 min = zn;
03241 if (max<min) { max = min; changemax = true; }
03242 } else
03243 if (ncol==5) {
03244 max = zn;
03245 if (min>max) { min = max; changemin = true; }
03246 }
03247 par->SetRange(min,max);
03248 range_changed = true;
03249 fbFillingWidget = true;
03250 if (changemin)
03251 table->setText(nrow, 4, QString::number(min));
03252 if (changemax)
03253 table->setText(nrow, 5, QString::number(max));
03254 fbFillingWidget = false;
03255 } else {
03256 if ((table->text(nrow, ncol).length()==0) &&
03257 (table->text(nrow, 9-ncol).length()==0)) {
03258 par->ClearRange();
03259 range_changed = true;
03260 }
03261 }
03262
03263
03264 if (range_changed) {
03265 fbFillingWidget = true;
03266 QCheckTableItem* checkitem = dynamic_cast<QCheckTableItem*> ( table->item(nrow,0));
03267 if (checkitem) checkitem->setChecked(par->GetFixed());
03268 table->item(nrow,1)->setEnabled(!par->GetFixed());
03269 table->setText(nrow, 1, QString::number(par->GetValue()));
03270 fbFillingWidget = false;
03271 }
03272
03273 break; }
03274 }
03275 }
03276 }
03277
03278
03279 void TGo4FitPanel::Wiz_ModelBufChk_toggled( bool zn)
03280 {
03281 if (fbFillingWidget) return;
03282 TGo4FitModel* model = Wiz_SelectedModel();
03283 if (model) model->SetUseBuffers(zn);
03284 }
03285
03286
03287 void TGo4FitPanel::Wiz_PFSetupBtn_clicked()
03288 {
03289 if (fbFillingWidget) return;
03290
03291 if (Wiz_SelectedData()==0) return;
03292 fiWizPageIndex = 3;
03293 UpdateWizStackWidget();
03294 UpdateWizPaint(1);
03295 }
03296
03297
03298 void TGo4FitPanel::Wiz_PFUsePolynChk_toggled( bool zn )
03299 {
03300 if (fbFillingWidget) return;
03301
03302 TGo4FitPeakFinder* finder = GetPeakFinder(true);
03303 if (finder!=0) finder->SetUsePolynom(zn);
03304
03305 Wiz_PFPolynSpin->setEnabled(zn);
03306 }
03307
03308 void TGo4FitPanel::Wiz_PFPolynSpin_valueChanged( int zn )
03309 {
03310 if (fbFillingWidget) return;
03311
03312 TGo4FitPeakFinder* finder = GetPeakFinder(true);
03313 if (finder!=0) finder->SetPolynomOrder(zn);
03314 }
03315
03316
03317 void TGo4FitPanel::Smp_PolynomBtn_clicked()
03318 {
03319 Button_SimpleFit(0);
03320 }
03321
03322 void TGo4FitPanel::Smp_GaussianBtn_clicked()
03323 {
03324 Button_SimpleFit(1);
03325 }
03326
03327 void TGo4FitPanel::Smp_LorenzBtn_clicked()
03328 {
03329 Button_SimpleFit(2);
03330 }
03331
03332 void TGo4FitPanel::Smp_ExponentBtn_clicked()
03333 {
03334 Button_SimpleFit(3);
03335 }
03336
03337 void TGo4FitPanel::Smp_ClearBtn_clicked()
03338 {
03339 Button_SimpleClear();
03340 }
03341
03342 void TGo4FitPanel::Wiz_MinSetupBtn_clicked()
03343 {
03344 if (fbFillingWidget) return;
03345
03346 fiWizPageIndex = 0;
03347 UpdateWizStackWidget();
03348 UpdateWizPaint(0);
03349 }
03350
03351 void TGo4FitPanel::FindersTab_currentChanged( QWidget * )
03352 {
03353 if (fbFillingWidget) return;
03354
03355 TGo4FitPeakFinder* finder = GetPeakFinder(true);
03356 if (finder)
03357 finder->SetPeakFinderType(FindersTab->currentPageIndex());
03358 }
03359
03360 void TGo4FitPanel::Wiz_ModelList_clicked( QListBoxItem * item, const QPoint & pnt)
03361 {
03362 if (item==0) return;
03363
03364 QRect rect = Wiz_ModelList->itemRect(item);
03365 QPoint pnt2 = Wiz_ModelList->viewport()->mapFromGlobal(pnt);
03366
03367 Wiz_ModelListSelect(Wiz_ModelList->currentItem(), (pnt2.x() - rect.left()) >=15 );
03368 }
03369
03370 void TGo4FitPanel::Wiz_BackgroundChk_toggled( bool chk)
03371 {
03372 if (fbFillingWidget) return;
03373
03374 TGo4FitModel* model = Wiz_SelectedModel();
03375 if (model!=0)
03376 if (chk) model->SetBackgroundGroupIndex();
03377 else model->SetGroupIndex(-1);
03378 }
03379
03380 void TGo4FitPanel::PF_MinWidthEdt_returnPressed()
03381 {
03382 if (!fbFillingWidget)
03383 Button_PeakFinder();
03384 }
03385
03386 void TGo4FitPanel::PF_MaxWidthEdt_returnPressed()
03387 {
03388 if (!fbFillingWidget)
03389 Button_PeakFinder();
03390 }
03391
03392 void TGo4FitPanel::PF_WidthEdit_returnPressed()
03393 {
03394 if (!fbFillingWidget)
03395 Button_PeakFinder();
03396 }
03397
03398 void TGo4FitPanel::PF_MinNoiseEdit_returnPressed()
03399 {
03400 if (!fbFillingWidget)
03401 Button_PeakFinder();
03402 }
03403
03404 void TGo4FitPanel::ParsTable_contextMenuRequested(int nrow, int ncol, const QPoint &)
03405 {
03406 }
03407
03408 TGo4Fitter* TGo4FitPanel::CreateFitterFor(TGo4ViewPanel* panel, TPad* pad, const char* name)
03409 {
03410 if ((panel==0) || (pad==0)) return 0;
03411
03412 TGo4Fitter* fitter = new TGo4Fitter(name,"Fitter object");
03413
03414 CreateDataFor(panel, pad, fitter);
03415
03416 fitter->AddStandardActions();
03417
03418 fitter->SetMemoryUsage(3);
03419
03420 fitter->SetFitFunctionType(TGo4Fitter::ff_chi_square);
03421
03422 return fitter;
03423 }
03424
03425 void TGo4FitPanel::CreateDataFor(TGo4ViewPanel* panel, TPad* pad, TGo4Fitter* fitter)
03426 {
03427 if ((fitter==0) || (panel==0) || (pad==0)) return;
03428
03429 int npads = panel->GetNumberOfPads(pad);
03430
03431 for (Int_t n=0;n<npads;n++) {
03432 TPad* subpad = panel->GetSubPad(pad, n, false);
03433 if (panel->IsPadHasSubPads(subpad)) continue;
03434 TObject* obj = panel->GetPadMainObject(subpad);
03435 if (obj==0) continue;
03436
03437 TGo4FitData* data = 0;
03438
03439 if (obj->InheritsFrom(TH1::Class()))
03440 data = new TGo4FitDataHistogram(fitter->FindNextName("Data",0,kFALSE));
03441 else
03442 if (obj->InheritsFrom(TGraph::Class()))
03443 data = new TGo4FitDataGraph(fitter->FindNextName("Data",0,kFALSE));
03444
03445 if (data!=0)
03446 fitter->AddData(data);
03447 }
03448 }
03449
03450 void TGo4FitPanel::UpdateActivePage()
03451 {
03452 int select = fiPanelMode;
03453 if (GetFitter()==0) select = FitGui::pm_None;
03454
03455 if (fbParsWidgetShown && (select!=FitGui::pm_None)) select = 100;
03456
03457 switch (select) {
03458 case FitGui::pm_None: break;
03459 case FitGui::pm_Simple: UpdateSimplePage(); break;
03460 case FitGui::pm_Wizard: UpdateWizardPage(); break;
03461 case FitGui::pm_Expert: UpdateExtendedPage(); break;
03462 case 100: {
03463 FillParsWidget();
03464 if (fiPanelMode==FitGui::pm_Wizard) {
03465 RemovePrimitives();
03466 UpdateWizPaint(-1);
03467 }
03468 break;
03469 }
03470 }
03471
03472 ShowPanelPage(select);
03473 UpdateStatusBar(0);
03474 UpdateItemMenu();
03475 }
03476
03477 void TGo4FitPanel::UpdateSimplePage()
03478 {
03479 RemovePrimitives();
03480
03481 PaintFitter(GetFitter(), 0, TRUE);
03482
03483 UpdateStatusBar(0);
03484 }
03485
03486 void TGo4FitPanel::UpdateWizardPage()
03487 {
03488 RemovePrimitives();
03489
03490 TGo4Fitter* fitter = GetFitter();
03491 fbFillingWidget = true;
03492 if (fitter) Wiz_FitNameEdt->setText(QString(fitter->GetName()));
03493 else Wiz_FitNameEdt->setText(QString(""));
03494 fbFillingWidget = false;
03495
03496 UpdateWizDataList();
03497
03498 UpdateWizModelsList(FALSE);
03499
03500 UpdateWizStackWidget();
03501
03502 UpdateWizPaint(-1);
03503
03504 UpdateStatusBar(0);
03505 }
03506
03507 void TGo4FitPanel::UpdateExtendedPage()
03508 {
03509 RemoveItemWidget();
03510
03511 RemovePrimitives();
03512
03513 FitList->clear();
03514 FitList->setSorting(-1);
03515 TGo4Fitter* fitter = GetFitter();
03516 if (fitter==0) {
03517 new QFitItem(this, FitList, 0, FitGui::ot_empty, FitGui::wt_none, FitGui::mt_empty);
03518 } else {
03519 QFitItem* fitteritem = new QFitItem(this, FitList, fitter, FitGui::ot_fitter, FitGui::wt_fitter, FitGui::mt_fitter, FitGui::gt_fitter);
03520 fitteritem->setOpen(TRUE);
03521 FitList->setSelected(fitteritem, kTRUE);
03522 ShowItem(fitteritem, false);
03523 }
03524
03525 UpdateItemMenu();
03526
03527 UpdateStatusBar(0);
03528 }
03529
03530 void TGo4FitPanel::RemovePrimitives()
03531 {
03532 if (!WorkingWithPanel()) return;
03533
03534 TGo4Fitter* fitter = GetFitter();
03535 if (fitter==0) return;
03536
03537 for(Int_t n = 0; n<fitter->NumSlots();n++) {
03538 TPad* pad = FindPadForSlot(fitter->GetSlot(n));
03539 if (pad==0) continue;
03540 if (ActivePanel()->DeleteDrawObjects(pad, TGo4ViewPanel::kind_FitArrows))
03541 ActivePanel()->ShootRepaintTimer();
03542 }
03543 }
03544
03545
03546 bool TGo4FitPanel::FillPopupForItem(QFitItem* item, QPopupMenu* menu)
03547 {
03548 if((item==0) || (menu==0)) return false;
03549
03550 if(item->PopupMenuType() == FitGui::mt_empty) {
03551 menu->insertItem(QString("Create empty fitter"),8);
03552 if (WorkingWithPanel()) menu->insertItem(QString("Create appropriate fitter"),9);
03553 }
03554
03555 if(item->PopupMenuType() == FitGui::mt_fitter) {
03556 menu->insertItem(QString("Delete fitter"),1);
03557 menu->insertItem(QString("Clear fitter"),2);
03558 menu->insertItem(QString("Save fitter"),3);
03559 menu->insertItem(QString("Save fitter as ..."),4);
03560 menu->insertItem(QString("Print ..."),5);
03561 menu->insertItem(QString("Draw"),6);
03562 menu->insertItem(QString("Memorize parameters"), 706);
03563 menu->insertItem(QString("Remember parameters"), 707);
03564
03565 }
03566
03567 if(item->PopupMenuType() == FitGui::mt_data) {
03568 if (!WorkingWithPanel())
03569 menu->insertItem(QString("Remove ")+item->Object()->GetName(),101);
03570 menu->insertItem(QString("Remove assosiated models"),102);
03571 menu->insertItem(QString("Draw"),105);
03572 menu->insertItem(QString("Print"),5);
03573 }
03574
03575 if(item->PopupMenuType() == FitGui::mt_datalist)
03576 if (WorkingWithPanel()) {
03577 menu->insertItem(QString("Rebuild data list"),108);
03578 } else {
03579 menu->insertItem(QString("Delete all data"),107);
03580 FillDataTypesList(menu, 110);
03581 }
03582
03583 if(item->PopupMenuType() == FitGui::mt_model) {
03584 menu->insertItem(QString("Remove ")+item->Object()->GetName(), 201);
03585 menu->insertItem(QString("Clone"), 203);
03586 menu->insertItem(QString("Print"), 5);
03587 }
03588
03589 if(item->PopupMenuType() == FitGui::mt_modellist) {
03590 menu->insertItem(QString("Delete all models"),202);
03591 FillModelTypesList(menu, 210, TRUE);
03592 }
03593
03594 if(item->PopupMenuType() == FitGui::mt_asslist) {
03595 TGo4Fitter* fitter = GetFitter();
03596 TGo4FitModel* model = dynamic_cast<TGo4FitModel*> (item->Object());
03597 if (fitter && model) {
03598 menu->insertItem(QString("Clear all assignments"), 301);
03599 menu->insertItem(QString("Assign to all data"), 302);
03600 menu->insertSeparator();
03601 for(Int_t n=0; n<fitter->GetNumData();n++)
03602 if(!model->IsAssignTo(fitter->GetDataName(n)))
03603 menu->insertItem(QString("Assign to: ") + fitter->GetDataName(n), 310+n);
03604 }
03605 }
03606
03607 if(item->PopupMenuType() == FitGui::mt_ass)
03608 menu->insertItem(QString("Clear assignment to ") + item->text(0), 303);
03609
03610 if(item->PopupMenuType() == FitGui::mt_range)
03611 menu->insertItem(QString("Remove range condition"), 401);
03612
03613 if(item->PopupMenuType() == FitGui::mt_rangecut)
03614 menu->insertItem(QString("Remove range condition"), 401);
03615
03616 if(item->PopupMenuType() == FitGui::mt_rangelist) {
03617 TGo4FitComponent* comp = dynamic_cast<TGo4FitComponent*> (item->Object());
03618 if(comp) {
03619 if (comp->IsAnyRangeLimits()>0) {
03620 menu->insertItem(QString("Clear all ranges"), 402);
03621 menu->insertSeparator();
03622 }
03623 menu->insertItem(QString("Include new range"), 403);
03624 menu->insertItem(QString("Exclude new range"), 404);
03625 menu->insertItem(QString("Add left bound"), 405);
03626 menu->insertItem(QString("Add right bound"), 406);
03627 menu->insertSeparator();
03628 menu->insertItem(QString("Add range cut"), 407);
03629 }
03630 }
03631
03632 if(item->PopupMenuType() == FitGui::mt_action) {
03633 menu->insertItem(QString("Delete action"), 501);
03634 menu->insertItem(QString("Move action up"), 502);
03635 menu->insertItem(QString("Move action down"), 503);
03636 menu->insertItem(QString("Print"),5);
03637 menu->insertItem(QString("Execute"), 508);
03638 }
03639
03640 if(item->PopupMenuType() == FitGui::mt_actlist) {
03641 TGo4Fitter* fitter = dynamic_cast<TGo4Fitter*> (item->Object());
03642 if(fitter) {
03643 if (fitter->GetNumActions()>0) {
03644 menu->insertItem(QString("Execute norm actions"), 504);
03645 menu->insertItem(QString("Execute all actions"), 507);
03646 menu->insertItem(QString("Delete all actions"), 505);
03647 menu->insertItem(QString("Delete output actions"), 506);
03648 menu->insertSeparator();
03649 }
03650 menu->insertItem(QString("Add config"), 510);
03651 menu->insertItem(QString("Add peak finder"), 514);
03652 menu->insertItem(QString("Add amplitude estimation"), 511);
03653 menu->insertItem(QString("Add minuit"), 512);
03654 menu->insertItem(QString("Add output"), 513);
03655 }
03656 }
03657
03658 if(item->PopupMenuType() == FitGui::mt_depend)
03659 menu->insertItem(QString("Delete item"), 601);
03660
03661 if(item->PopupMenuType() == FitGui::mt_deplist) {
03662 menu->insertItem(QString("Delete all items"), 602);
03663 menu->insertItem(QString("Insert new item"), 603);
03664 }
03665
03666 if(item->PopupMenuType() == FitGui::mt_newpars) {
03667 menu->insertItem(QString("Delete all items"), 701);
03668 menu->insertItem(QString("Insert new item"), 702);
03669 }
03670
03671 if(item->PopupMenuType() == FitGui::mt_parcfg)
03672 menu->insertItem(QString("Delete item"), 703);
03673
03674 if(item->PopupMenuType() == FitGui::mt_par) {
03675 menu->insertItem(QString("Memorize value"), 704);
03676 menu->insertItem(QString("Remember value"), 705);
03677 }
03678
03679 if((item->PopupMenuType() == FitGui::mt_parslist)) {
03680 menu->insertItem(QString("Memorize parameters"), 706);
03681 menu->insertItem(QString("Remember parameters"), 707);
03682 }
03683
03684 if(item->PopupMenuType() == FitGui::mt_minuitres) {
03685 menu->insertItem(QString("Delete result entry"), 801);
03686 menu->insertItem(QString("Print"),5);
03687 }
03688
03689 if(item->PopupMenuType() == FitGui::mt_slot) {
03690 TGo4FitSlot* slot = dynamic_cast<TGo4FitSlot*> (item->Object());
03691 if (slot!=0) FillPopupForSlot(slot,menu);
03692 }
03693
03694 if(item->PopupMenuType() == FitGui::mt_allslots) {
03695 TGo4Fitter* fitter = dynamic_cast<TGo4Fitter*> (item->Object());
03696 if(fitter) {
03697 menu->insertItem(QString("Update slots from sources"), 904);
03698 }
03699 }
03700
03701 return (menu->count()>0);
03702 }
03703
03704 void TGo4FitPanel::ExecPopupForItem(QFitItem * item, int id)
03705 {
03706 switch(id) {
03707 case 1: Cmd_DeleteFitter(); break;
03708 case 2: Cmd_ClearFitter(); break;
03709 case 3: Cmd_SaveFitter(FALSE); break;
03710 case 4: Cmd_SaveFitter(TRUE); break;
03711 case 5: Cmd_ItemPrint(item); break;
03712 case 6: Button_FitterDraw(0); break;
03713 case 8: Cmd_CreateFitter(); break;
03714 case 9: Cmd_CreateAppropriateFitter(); break;
03715 case 101: Cmd_DeleteData(item); break;
03716 case 102: Cmd_DeleteAssosiatedModels(item); break;
03717 case 105: Cmd_DrawData(item); break;
03718 case 107: Cmd_DeleteAllData(item); break;
03719 case 108: Wiz_RebuildDataList(); break;
03720 case 201: Cmd_DeleteModel(item); break;
03721 case 202: Cmd_DeleteModels(item); break;
03722 case 203: Cmd_CloneModel(item); break;
03723 case 301: Cmd_ClearAssigments(item); break;
03724 case 302: Cmd_AssignModelToAllData(item); break;
03725 case 303: Cmd_ClearAssigment(item); break;
03726 case 401: Cmd_RemoveRangeCondition(item); break;
03727 case 402: Cmd_RemoveRangeConditions(item); break;
03728 case 403:
03729 case 404:
03730 case 405:
03731 case 406:
03732 case 407: Cmd_AddRangeCondition(item, id-403); break;
03733 case 501: Cmd_DeleteAction(item); break;
03734 case 502: Cmd_MoveAction(item, -1); break;
03735 case 503: Cmd_MoveAction(item, +1); break;
03736 case 504: Cmd_ExecuteActions(item, FALSE); break;
03737 case 505: Cmd_DeleteActions(item); break;
03738 case 506: Cmd_DeleteOutputActions(item); break;
03739 case 507: Cmd_ExecuteActions(item, TRUE); break;
03740 case 508: Cmd_ExecuteAction(item); break;
03741 case 601: Cmd_DeleteDependency(item); break;
03742 case 602: Cmd_DeleteDependencies(item); break;
03743 case 603: Cmd_AddDependency(item); break;
03744 case 701: Cmd_DeletePars(item); break;
03745 case 702: Cmd_AddNewPar(item); break;
03746 case 703: Cmd_DeletePar(item); break;
03747 case 704: Cmd_MemorizePar(item); break;
03748 case 705: Cmd_RememberPar(item); break;
03749 case 706: Cmd_MemorizePars(item); break;
03750 case 707: Cmd_RememberPars(item); break;
03751 case 801: Cmd_DeleteMinuitResult(item); break;
03752 case 904: Cmd_UpdateAllSlots(item); break;
03753
03754 default:
03755 if ((id>=110) && (id<200)) Cmd_AddNewData(item,id-110); else
03756 if ((id>=210) && (id<300)) Cmd_AddNewModel(item,id-210); else
03757 if ((id>=310) && (id<400)) Cmd_AssignModelToData(item,id-310); else
03758 if ((id>=510) && (id<600)) Cmd_AddNewAction(item,id-510); else
03759 if ((id>=1000) && (id<2000)) ExecutePopupForSlot(item, 0, id);
03760 }
03761 }
03762
03763 bool TGo4FitPanel::FillPopupForSlot(TGo4FitSlot* slot, QPopupMenu* menu)
03764 {
03765 if ((slot==0) || (menu==0)) return false;
03766
03767 if(!slot->GetOwned() && slot->IsObject())
03768 menu->insertItem(QString("Clone object in slot"), 1000);
03769
03770 if(slot->IsObject())
03771 menu->insertItem(QString("Clear object in slot"), 1001);
03772
03773 if (FindPadForSlot(slot)!=0)
03774 menu->insertItem(QString("Update from ") + Wiz_GetSlotSourceInfo(slot), 1002);
03775
03776 uint cnt=menu->count();
03777 if (cnt>0) menu->insertSeparator();
03778
03779 if (slot->GetConnectedSlot())
03780 menu->insertItem(QString("Brake connection to slot"), 1004);
03781 TGo4Fitter* fitter = GetFitter();
03782 if (fitter)
03783 for(Int_t n=0;n<fitter->NumSlots();n++) {
03784 TGo4FitSlot* sl = fitter->GetSlot(n);
03785 if (slot->CanConnectToSlot(sl) && (slot->GetConnectedSlot()!=sl))
03786 menu->insertItem(QString("Connect to ") + sl->GetFullName(), 1400 + n);
03787 }
03788
03789 if (cnt<menu->count()) menu->insertSeparator();
03790
03791 if (slot->GetClass() == TGo4FitData::Class()) FillDataTypesList(menu, 1100); else
03792 if (slot->GetClass() == TGo4FitModel::Class()) FillModelTypesList(menu, 1200, FALSE); else
03793 if (slot->GetClass() == TGo4FitAxisTrans::Class()) {
03794 menu->insertItem(QString(TGo4FitLinearTrans::Class()->GetName()), 1300);
03795 menu->insertItem(QString(TGo4FitMatrixTrans::Class()->GetName()), 1301);
03796 }
03797
03798 return (menu->count()>0);
03799 }
03800
03801 void TGo4FitPanel::ExecutePopupForSlot(QFitItem* item, TGo4FitSlot* slot, int id)
03802 {
03803 if (item!=0) slot = dynamic_cast<TGo4FitSlot*> (item->Object());
03804
03805 TGo4Fitter* fitter = GetFitter();
03806 if ((slot==0) || (fitter==0)) return;
03807
03808 switch (id) {
03809 case 1000: {
03810 TObject* newobj = slot->CloneObject();
03811 slot->SetObject(newobj, kTRUE);
03812 break;
03813 }
03814
03815 case 1001: {
03816
03817 if(fbNeedConfirmation)
03818 if ( QMessageBox::information(0,
03819 QString("Clear slot"),
03820 QString("Are you sure to clear object from slot ") + slot->GetName(),
03821 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
03822
03823 fitter->ClearSlot(slot, kFALSE);
03824
03825 if (item)
03826 for(Int_t i=0;i<fitter->NumSlots();i++) {
03827 QFitItem* sitem = FindItem(fitter->GetSlot(i), FitGui::ot_slot, 0);
03828 if (sitem) UpdateItem(sitem, TRUE);
03829 }
03830
03831 break; }
03832
03833 case 1002: {
03834 UpdateObjectReferenceInSlot(slot, false);
03835 break;
03836 }
03837
03838 case 1004: {
03839 slot->ClearConnectionToSlot();
03840 break;
03841 }
03842
03843 default: {
03844 TObject* obj = 0;
03845 if ((id>=1100) && (id<1200)) obj = CreateData(id-1100,"Data"); else
03846 if ((id>=1200) && (id<1300)) obj = CreateModel(id-1200, "Model", 0, 0); else
03847 if (id==1300) obj = new TGo4FitLinearTrans("Trans","Linear axis transformation"); else
03848 if (id==1301) obj = new TGo4FitMatrixTrans("Trans","Matrix axis transformation"); else
03849 if (id>=1400) {
03850 TGo4FitSlot* sl = fitter->GetSlot(id-1400);
03851 slot->ConnectToSlot(sl);
03852 break;
03853 }
03854 if (obj) slot->SetObject(obj, kTRUE);
03855 }
03856 }
03857
03858 if (item) {
03859 ShowItem(item, false);
03860 UpdateItem(item, TRUE);
03861 item->setOpen(TRUE);
03862 } else
03863 UpdateActivePage();
03864 }
03865
03866 void TGo4FitPanel::UpdateItem(QFitItem* item, bool trace)
03867 {
03868 if (item==0) return;
03869
03870 if (fxCurrentItem!=0)
03871 if (fxCurrentItem->FindInParents(item)) RemoveItemWidget();
03872
03873 while (item->firstChild())
03874 delete item->firstChild();
03875
03876 SetItemText(item, FALSE);
03877
03878 switch (item->ObjectType()) {
03879 case FitGui::ot_empty: break;
03880 case FitGui::ot_datalist: {
03881 TGo4Fitter* fitter = dynamic_cast<TGo4Fitter*> (item->Object());
03882 if(fitter)
03883 for(Int_t n=fitter->GetNumData()-1;n>=0;n--)
03884 new QFitItem(this, item, fitter->GetData(n), FitGui::ot_data, FitGui::wt_data, FitGui::mt_data, FitGui::gt_data, n);
03885 break; }
03886 case FitGui::ot_data: {
03887 TGo4FitData* data = dynamic_cast<TGo4FitData*> (item->Object());
03888 if (data==0) break;
03889
03890 FillSlotsList(item, data->GetSlotList(), data);
03891
03892 new QFitItem(this, item, data, FitGui::ot_parslist, FitGui::wt_none, FitGui::mt_parslist);
03893
03894 new QFitItem(this, item, data, FitGui::ot_rangelist, FitGui::wt_none, FitGui::mt_rangelist, FitGui::gt_ranges);
03895
03896 break; }
03897 case FitGui::ot_modellist: {
03898 TGo4Fitter* fitter = dynamic_cast<TGo4Fitter*> (item->Object());
03899 if(fitter)
03900 for(Int_t n=fitter->GetNumModel()-1;n>=0;n--)
03901 new QFitItem(this, item, fitter->GetModel(n), FitGui::ot_model, DefineModelWidgetType(fitter->GetModel(n)), FitGui::mt_model, FitGui::gt_model, n);
03902 break; }
03903 case FitGui::ot_model: {
03904 TGo4FitModel* model = dynamic_cast<TGo4FitModel*> (item->Object());
03905 if (model==0) break;
03906
03907 FillSlotsList(item, model->GetSlotList(), model);
03908
03909 new QFitItem(this, item, model, FitGui::ot_parslist, FitGui::wt_none, FitGui::mt_parslist);
03910
03911 new QFitItem(this, item, model, FitGui::ot_rangelist, FitGui::wt_none, FitGui::mt_rangelist, FitGui::gt_ranges);
03912
03913 new QFitItem(this, item, model, FitGui::ot_asslist, FitGui::wt_none, FitGui::mt_asslist, FitGui::gt_none);
03914
03915 break; }
03916 case FitGui::ot_parslist: FillParsList(item); break;
03917 case FitGui::ot_par: break;
03918 case FitGui::ot_parcfg: break;
03919 case FitGui::ot_asslist: {
03920 TGo4FitModel* model = dynamic_cast<TGo4FitModel*> (item->Object());
03921 if (model)
03922 for (Int_t n = model->NumAssigments()-1; n>=0; n--)
03923 new QFitItem(this, item, model, FitGui::ot_ass, FitGui::wt_none, FitGui::mt_ass, FitGui::gt_ass, n);
03924 break; }
03925 case FitGui::ot_ass: break;
03926 case FitGui::ot_rangelist: {
03927 TGo4FitComponent* comp = dynamic_cast<TGo4FitComponent*> (item->Object());
03928 if (comp) {
03929 for (Int_t n = comp->GetNumRangeCut()-1; n>=0; n--)
03930 new QFitItem(this, item, comp->GetRangeCut(n), FitGui::ot_rangecut, FitGui::wt_rangecut, FitGui::mt_rangecut, FitGui::gt_none, n);
03931 for (Int_t n = comp->GetNumRangeCondition()-1; n>=0; n--)
03932 new QFitItem(this, item, comp, FitGui::ot_range, FitGui::wt_range, FitGui::mt_range, FitGui::gt_range, n);
03933 }
03934 break; }
03935 case FitGui::ot_range: break;
03936 case FitGui::ot_rangecut: break;
03937 case FitGui::ot_actlist: {
03938 TGo4Fitter* fitter = dynamic_cast<TGo4Fitter*> (item->Object());
03939 if (fitter==0) break;
03940 for (Int_t n = fitter->GetNumActions()-1; n>=0; n--) {
03941 TGo4FitterAction* action = fitter->GetAction(n);
03942 int ot = FitGui::ot_action, wt = FitGui::wt_named;
03943 if (action->InheritsFrom(TGo4FitterConfig::Class())) ot = FitGui::ot_config; else
03944 if (action->InheritsFrom(TGo4FitAmplEstimation::Class())) { ot = FitGui::ot_amplest; wt = FitGui::wt_amplest; } else
03945 if (action->InheritsFrom(TGo4FitPeakFinder::Class())) { ot = FitGui::ot_peakfinder; wt = FitGui::wt_peakfinder; } else
03946 if (action->InheritsFrom(TGo4FitterOutput::Class())) { ot = FitGui::ot_output; wt = FitGui::wt_output; } else
03947 if (action->InheritsFrom(TGo4FitMinuit::Class())) { ot = FitGui::ot_minuit; wt = FitGui::wt_minuit; }
03948
03949 new QFitItem(this, item, action, ot, wt, FitGui::mt_action);
03950 }
03951 break;
03952 }
03953 case FitGui::ot_action: break;
03954 case FitGui::ot_amplest: break;
03955 case FitGui::ot_peakfinder: break;
03956 case FitGui::ot_output: break;
03957 case FitGui::ot_config: {
03958 TGo4FitterConfig* cfg = dynamic_cast<TGo4FitterConfig*> (item->Object());
03959 if (cfg==0) break;
03960 new QFitItem(this, item, &(cfg->GetResults()), FitGui::ot_reslist, FitGui::wt_none, FitGui::mt_deplist);
03961 new QFitItem(this, item, &(cfg->GetParsDepend()), FitGui::ot_pardeplist, FitGui::wt_none, FitGui::mt_deplist);
03962 new QFitItem(this, item, &(cfg->GetParsInit()), FitGui::ot_parinitlist, FitGui::wt_none, FitGui::mt_deplist);
03963 new QFitItem(this, item, &(cfg->GetParsCfg()), FitGui::ot_parscfg, FitGui::wt_none, FitGui::mt_newpars);
03964 new QFitItem(this, item, &(cfg->GetParsNew()), FitGui::ot_newpars, FitGui::wt_none, FitGui::mt_newpars);
03965 break; }
03966 case FitGui::ot_minuit: {
03967 TGo4FitMinuit* minuit = dynamic_cast<TGo4FitMinuit*> (item->Object());
03968 if (minuit==0) break;
03969 for (Int_t n=minuit->GetNumResults()-1;n>=0;n--)
03970 new QFitItem(this, item, minuit->GetResult(n), FitGui::ot_minuitres, FitGui::wt_minuitres, FitGui::mt_minuitres);
03971 break; }
03972 case FitGui::ot_parinitlist: FillDependencyList(item); break;
03973 case FitGui::ot_pardeplist: FillDependencyList(item); break;
03974 case FitGui::ot_reslist: FillDependencyList(item); break;
03975 case FitGui::ot_depend: break;
03976 case FitGui::ot_newpars: FillParsList(item); break;
03977 case FitGui::ot_parscfg: {
03978 TGo4FitParsList* pars = dynamic_cast<TGo4FitParsList*> (item->Object());
03979 if (pars==0) return;
03980 for (Int_t n = pars->NumPars()-1; n>=0;n--)
03981 new QFitItem(this, item, pars->GetPar(n), FitGui::ot_parcfg, FitGui::wt_parcfg, FitGui::mt_parcfg);
03982 break; }
03983 case FitGui::ot_minuitres: break;
03984 case FitGui::ot_slot: {
03985 TGo4FitSlot* slot = dynamic_cast<TGo4FitSlot*> (item->Object());
03986 if(slot==0) break;
03987
03988 TObject* obj = slot->GetObject();
03989 if (obj==0) break;
03990
03991 if (obj->InheritsFrom(TGo4FitData::Class()))
03992 new QFitItem(this, item, obj, FitGui::ot_data, FitGui::wt_data, FitGui::mt_none);
03993 else
03994
03995 if (obj->InheritsFrom(TGo4FitModel::Class()))
03996 new QFitItem(this, item, obj, FitGui::ot_model, DefineModelWidgetType(obj), FitGui::mt_none);
03997 else
03998
03999 if (obj->InheritsFrom(TGo4FitLinearTrans::Class()))
04000 new QFitItem(this, item, obj, FitGui::ot_lintrans, FitGui::wt_lintrans, FitGui::mt_none);
04001 else
04002
04003 if (obj->InheritsFrom(TGo4FitMatrixTrans::Class()))
04004 new QFitItem(this, item, obj, FitGui::ot_matrtrans, FitGui::wt_matrtrans, FitGui::mt_none);
04005 else
04006
04007 if (obj->InheritsFrom(TGo4FitAxisTrans::Class()))
04008 new QFitItem(this, item, obj, FitGui::ot_trans, FitGui::wt_named, FitGui::mt_none);
04009 else
04010
04011 new QFitItem(this, item, obj, FitGui::ot_none, FitGui::wt_none, FitGui::mt_none);
04012
04013 break; }
04014 case FitGui::ot_fitter: {
04015 TGo4Fitter* fitter = dynamic_cast<TGo4Fitter*> (item->Object());
04016 if (fitter==0) break;
04017
04018 new QFitItem(this, item, fitter, FitGui::ot_results, FitGui::wt_table);
04019 new QFitItem(this, item, fitter, FitGui::ot_actlist, FitGui::wt_none, FitGui::mt_actlist);
04020 new QFitItem(this, item, fitter, FitGui::ot_allslots, FitGui::wt_none, FitGui::mt_allslots);
04021 new QFitItem(this, item, fitter, FitGui::ot_modellist, FitGui::wt_none, FitGui::mt_modellist);
04022 new QFitItem(this, item, fitter, FitGui::ot_datalist, FitGui::wt_none, FitGui::mt_datalist);
04023 break; }
04024 case FitGui::ot_trans: FillParsList(item); break;
04025 case FitGui::ot_lintrans: FillParsList(item); break;
04026 case FitGui::ot_matrtrans: FillParsList(item); break;
04027 case FitGui::ot_results: break;
04028 case FitGui::ot_allslots: {
04029 TGo4Fitter* fitter = dynamic_cast<TGo4Fitter*> (item->Object());
04030 if (fitter)
04031 FillSlotsList(item, fitter->GetSlotList(), 0);
04032 break; }
04033 }
04034
04035 if (trace && (item->Object()!=0)) {
04036 QFitItem* topitem = GetFitterItem();
04037 if (topitem==0) return;
04038
04039 QListViewItemIterator iter(topitem);
04040 while (iter.current()!=0) {
04041 QFitItem* it = dynamic_cast<QFitItem*> (iter.current());
04042 if ((it!=0) && (it!=item) &&
04043 (item->ObjectType()==it->ObjectType()) &&
04044 (item->Object()==it->Object())) UpdateItem(it, FALSE);
04045 ++iter;
04046 }
04047 }
04048 }
04049
04050 void TGo4FitPanel::SetItemText(QFitItem* item, bool trace)
04051 {
04052 if (item==0) return;
04053 QString text;
04054 if (item->Object()) text = item->Object()->GetName();
04055 switch (item->ObjectType()) {
04056 case FitGui::ot_empty: text = "empty"; break;
04057 case FitGui::ot_datalist: text = "Data"; break;
04058 case FitGui::ot_data: break;
04059 case FitGui::ot_modellist: text = "Models"; break;
04060 case FitGui::ot_model: break;
04061 case FitGui::ot_parslist: text = "Parameters"; break;
04062 case FitGui::ot_par:
04063 case FitGui::ot_parcfg: {
04064 TGo4FitParameter* par = dynamic_cast<TGo4FitParameter*> (item->Object());
04065 if (par) text += " = " + QString::number(par->GetValue());
04066 break; }
04067 case FitGui::ot_asslist: text = "Assigments"; break;
04068 case FitGui::ot_ass: {
04069 TGo4FitModel* model = dynamic_cast<TGo4FitModel*> (item->Object());
04070 if (model) text = model->AssignmentName(item->Tag());
04071 break; }
04072 case FitGui::ot_rangelist: text = "Ranges"; break;
04073 case FitGui::ot_range: {
04074 TGo4FitComponent* comp = dynamic_cast<TGo4FitComponent*> (item->Object());
04075 if ((comp==0) || (item->Tag()<0) || (item->Tag()>=comp->GetNumRangeCondition())) break;
04076
04077 Int_t typ, naxis;
04078 Double_t left, right;
04079 comp->GetRangeCondition(item->Tag(), typ, naxis, left, right);
04080 text = QString::number(naxis) + ": ";
04081
04082 switch(typ) {
04083 case 0: text+="[" + QString::number(left) + "..." + QString::number(right) + "]"; break;
04084 case 1: text+="... " + QString::number(left) + "] [" + QString::number(right) + " ..."; break;
04085 case 2: text+="[" + QString::number(left) + " ..."; break;
04086 case 3: text+="... " + QString::number(right) + "]"; break;
04087 }
04088 break; }
04089 case FitGui::ot_rangecut: break;
04090 case FitGui::ot_actlist: text = "Actions"; break;
04091 case FitGui::ot_action: break;
04092 case FitGui::ot_amplest: break;
04093 case FitGui::ot_peakfinder: break;
04094 case FitGui::ot_output: break;
04095 case FitGui::ot_config: break;
04096 case FitGui::ot_minuit: break;
04097 case FitGui::ot_parinitlist: text = "Initialization"; break;
04098 case FitGui::ot_pardeplist: text = "Dependency"; break;
04099 case FitGui::ot_reslist: text = "Results"; break;
04100 case FitGui::ot_depend: {
04101 TGo4FitDependency* depen = dynamic_cast<TGo4FitDependency*> (item->Object());
04102 if (depen==0) break;
04103 if (depen->IsResultDepend()) text = "Res" + QString::number(item->Tag());
04104 else text = depen->GetParameter().Data();
04105 text += " = ";
04106 if (depen->IsInitValue()) text += QString::number(depen->GetInitValue());
04107 else text += depen->GetExpression().Data();
04108 break; }
04109 case FitGui::ot_newpars: text = "New pars"; break;
04110 case FitGui::ot_parscfg: text = "Pars setup"; break;
04111 case FitGui::ot_minuitres: break;
04112 case FitGui::ot_slot: break;
04113 case FitGui::ot_fitter: break;
04114 case FitGui::ot_trans: break;
04115 case FitGui::ot_lintrans: break;
04116 case FitGui::ot_matrtrans: break;
04117 case FitGui::ot_results: text = "Results"; break;
04118 case FitGui::ot_allslots: text = "Objects"; break;
04119 }
04120
04121 item->setText(0, text);
04122
04123 if (trace && (item->Object()!=0)) {
04124 QFitItem* topitem = GetFitterItem();
04125 if (topitem==0) return;
04126
04127 QListViewItemIterator iter(topitem);
04128 while (iter.current()!=0) {
04129 QFitItem* it = dynamic_cast<QFitItem*> (iter.current());
04130 if ((it!=0) && (it!=item) &&
04131 (item->ObjectType()==it->ObjectType()) &&
04132 (item->Object()==it->Object()) && (item->Tag()==it->Tag()))
04133 it->setText(0, text);
04134 ++iter;
04135 }
04136 }
04137 }
04138
04139 void TGo4FitPanel::UpdateItemsOfType(int typ, QFitItem* parent)
04140 {
04141 if (parent==0) parent = GetFitterItem();
04142
04143 QListViewItemIterator iter(parent);
04144 while (iter.current()!=0) {
04145 QFitItem* item = dynamic_cast<QFitItem*> (iter.current());
04146 if ((item!=0) && (item->ObjectType()==typ)) UpdateItem(item, FALSE);
04147 ++iter;
04148 }
04149 }
04150
04151 QFitItem* TGo4FitPanel::GetFitterItem()
04152 {
04153 QFitItem* item = dynamic_cast<QFitItem*> (FitList->firstChild());
04154 if (item && (item->ObjectType()==FitGui::ot_fitter)) return item;
04155 return 0;
04156 }
04157
04158 QFitItem* TGo4FitPanel::FindItem(TObject* obj, int ObjectType, QFitItem* parent)
04159 {
04160 if (parent==0) parent = GetFitterItem();
04161 QListViewItemIterator iter(parent);
04162 while (iter.current()!=0) {
04163 QFitItem* item = dynamic_cast<QFitItem*> (iter.current());
04164 if (item!=0)
04165 if ((obj==0) || (item->Object()==obj))
04166 if ((ObjectType==FitGui::ot_none) || (ObjectType==item->ObjectType())) return item;
04167 ++iter;
04168 }
04169 return 0;
04170 }
04171
04172 bool TGo4FitPanel::ShowItem(QFitItem* item, bool force)
04173 {
04174 if (force) RemoveItemWidget();
04175
04176 bool gr = FALSE;
04177
04178 RemovePrimitives();
04179 if (fbShowPrimitives)
04180 gr = ShowItemAsGraph(item, force);
04181
04182 bool txt = ShowItemAsText(item, force);
04183
04184 return (gr || txt);
04185 }
04186
04187 bool TGo4FitPanel::ShowItemAsText(QFitItem* item, bool force)
04188 {
04189
04190 QFitItem* widgetitem = item->DefineWidgetItem();
04191
04192 QFitWidget* oldwidget = dynamic_cast<QFitWidget*> (ListStack->widget(FitGui::ListStackId));
04193 if ((oldwidget!=0) && (oldwidget->GetItem()==widgetitem)) {
04194 oldwidget->FillWidget();
04195 return TRUE;
04196 }
04197
04198 RemoveItemWidget();
04199
04200 QFitWidget* widget = 0;
04201
04202 if (widgetitem==0) return TRUE;
04203
04204 QWidget* owner = 0;
04205
04206 switch(widgetitem->WidgetType()) {
04207 case FitGui::wt_par: widget = new QFitParWidget(owner,"Parameter"); break;
04208 case FitGui::wt_range : widget = new QFitRangeWidget(owner,"Range"); break;
04209 case FitGui::wt_rangecut : widget = new QFitRangeCutWidget(owner,"Range cut"); break;
04210 case FitGui::wt_data : widget = new QFitDataWidget(owner,"Data object"); break;
04211 case FitGui::wt_model : widget = new QFitModelWidget(owner,"Model"); break;
04212 case FitGui::wt_polynom : widget = new QFitModelPolynomWidget(owner,"Polynom"); break;
04213 case FitGui::wt_gauss1: widget = new QFitModelGauss1Widget(owner,"Gauss1"); break;
04214 case FitGui::wt_gauss2: widget = new QFitModelGauss2Widget(owner,"Gauss2"); break;
04215 case FitGui::wt_gaussn: widget = new QFitModelGaussNWidget(owner,"GaussN"); break;
04216 case FitGui::wt_formula: widget = new QFitModelFormulaWidget(owner,"Formula"); break;
04217 case FitGui::wt_function: widget = new QFitModelFunctionWidget(owner,"Function"); break;
04218 case FitGui::wt_amplest: widget = new QFitAmplEstimWidget(owner,"Amplitude estimation"); break;
04219 case FitGui::wt_peakfinder: widget = new QFitPeakFinderWidget(owner,"Peak finder"); break;
04220 case FitGui::wt_output: widget = new QFitOutputActionWidget(owner,"Fitter output"); break;
04221 case FitGui::wt_minuit: widget = new QFitMinuitWidget(owner,"Minuit"); break;
04222 case FitGui::wt_minuitres: widget = new QFitMinuitResWidget(owner,"Minuit result"); break;
04223 case FitGui::wt_depend: widget = new QFitDependencyWidget(owner,"Dependency"); break;
04224 case FitGui::wt_parcfg: widget = new QFitParCfgWidget(owner,"Parameter configuration"); break;
04225 case FitGui::wt_slot: widget = new QFitSlotWidget(owner,"Slot for external object"); break;
04226 case FitGui::wt_fitter: widget = new QFitterWidget(owner,"Fitter"); break;
04227 case FitGui::wt_named: widget = new QFitNamedWidget(owner,"Named object"); break;
04228 case FitGui::wt_table: widget = new QFitTableWidget(owner,"Table"); break;
04229 case FitGui::wt_lintrans: widget = new QFitLinearTransWidget(owner,"Simple transform"); break;
04230 case FitGui::wt_matrtrans: widget = new QFitMatrixTransWidget(owner,"Matrix transform"); break;
04231 }
04232
04233 if (widget!=0) {
04234 widget->SetItem(this, widgetitem);
04235 ListStack->addWidget(widget, FitGui::ListStackId);
04236 ListStack->raiseWidget(widget);
04237 }
04238
04239 return TRUE;
04240 }
04241
04242 bool TGo4FitPanel::ShowItemAsGraph(QFitItem* item, bool force)
04243 {
04244 if (item==0) return FALSE;
04245
04246 QFitItem* gritem = item->DefineGraphItem();
04247
04248 if (gritem==0) return false;
04249
04250 TGo4Fitter* fitter = GetFitter();
04251 if (fitter==0) return false;
04252
04253 if (gritem->GraphType()==FitGui::gt_fitter) {
04254 PaintFitter(fitter, gritem, false);
04255 return true;
04256 }
04257
04258 if (gritem->GraphType()==FitGui::gt_data) {
04259 TGo4FitData* data = dynamic_cast<TGo4FitData*> (gritem->Object());
04260
04261 if (data!=0)
04262 PaintModelsFor(fitter, data, gritem->Parent()->Parent(), false);
04263
04264 return (data!=0);
04265 }
04266
04267 if (gritem->GraphType()==FitGui::gt_model) {
04268 TGo4FitModel* model = dynamic_cast<TGo4FitModel*> (gritem->Object());
04269 if (model==0) return FALSE;
04270 bool draw = FALSE;
04271 for(Int_t n=0;n<model->NumAssigments();n++) {
04272 TGo4FitData* data = fitter->FindData(model->AssignmentName(n));
04273 if (PaintModel(model, FindPadWhereData(data), gritem)) draw = true;
04274 }
04275 return draw;
04276 }
04277
04278 if (gritem->GraphType()==FitGui::gt_ass) {
04279 TGo4FitModel* model = dynamic_cast<TGo4FitModel*> (gritem->Parent()->Parent()->Object());
04280 if (model) {
04281 TGo4FitData* data = fitter->FindData(gritem->text(0).latin1());
04282 if (PaintModel(model, FindPadWhereData(data), gritem->Parent()->Parent()))
04283 return true;
04284 }
04285 }
04286
04287 if (gritem->GraphType()==FitGui::gt_range) {
04288 TGo4FitComponent* comp = dynamic_cast<TGo4FitComponent*> (gritem->Parent()->Object());
04289 if (comp==0) return false;
04290 int nrange = gritem->Tag();
04291 if (PaintRange(comp, nrange, FindPadWhereComp(comp), gritem)) return true;
04292 }
04293
04294 if (gritem->GraphType()==FitGui::gt_ranges) {
04295 TGo4FitComponent* comp = dynamic_cast<TGo4FitComponent*> (gritem->Object());
04296 if (comp==0) return false;
04297
04298 TPad* pad = FindPadWhereComp(comp);
04299 if (pad!=0) {
04300 QListViewItem* child = gritem->firstChild();
04301 for(int nrange=0;nrange<comp->GetNumRangeCondition();nrange++) {
04302 if (child==0) return false;
04303 PaintRange(comp, nrange, pad, (QFitItem*)child);
04304 child = child->nextSibling();
04305 }
04306 return true;
04307 }
04308 }
04309
04310 return false;
04311 }
04312
04313 void TGo4FitPanel::RemoveItemWidget()
04314 {
04315 fxCurrentItem = 0;
04316 QWidget* w = ListStack->widget(FitGui::ListStackId);
04317 if (w) {
04318 ListStack->removeWidget(w);
04319 delete w;
04320 }
04321 }
04322
04323 void TGo4FitPanel::FitItemDeleted(QFitItem* item)
04324 {
04325 if ((item!=0) && (fxCurrentItem==item))
04326 RemoveItemWidget();
04327 }
04328
04329 void TGo4FitPanel::FillParsList(QFitItem* item)
04330 {
04331 if (item==0) return;
04332 TGo4FitParsList* pars = dynamic_cast<TGo4FitParsList*> (item->Object());
04333 if (pars==0) return;
04334 for (Int_t n = pars->NumPars()-1; n>=0;n--)
04335 new QFitItem(this, item, pars->GetPar(n), FitGui::ot_par, FitGui::wt_par, FitGui::mt_par);
04336 }
04337
04338 void TGo4FitPanel::FillSlotsList(QFitItem* parent, const TObjArray* lst, TObject* owner)
04339 {
04340 if ((parent==0) || (lst==0)) return;
04341 for(Int_t n = lst->GetLast();n>=0;n--) {
04342 TGo4FitSlot* slot = dynamic_cast<TGo4FitSlot*> (lst->At(n));
04343 if (slot && ((slot->GetOwner()==owner) || (owner==0)))
04344 new QFitItem(this, parent, slot, FitGui::ot_slot, FitGui::wt_slot, FitGui::mt_slot);
04345 }
04346 }
04347
04348 void TGo4FitPanel::FillDependencyList(QFitItem* parent)
04349 {
04350 if (parent==0) return;
04351
04352 TObjArray* lst = dynamic_cast<TObjArray*> (parent->Object());
04353 if (lst)
04354 for(Int_t n=lst->GetLast();n>=0;n--)
04355 new QFitItem(this, parent, lst->At(n), FitGui::ot_depend, FitGui::wt_depend, FitGui::mt_depend, FitGui::gt_none, n);
04356 }
04357
04358 void TGo4FitPanel::FillModelTypesList(QPopupMenu* menu, int id, bool extend)
04359 {
04360 if (menu->count()>0) menu->insertSeparator();
04361 if (extend) {
04362 menu->insertItem(QString("Add gaussian"), id+20);
04363 menu->insertItem(QString("Add lorenzian"), id+24);
04364 menu->insertItem(QString("Add exponent"), id+25);
04365 menu->insertItem(QString("Add 1-order polynom"), id+21);
04366 menu->insertItem(QString("Add 3-order polynom"), id+22);
04367 menu->insertItem(QString("Add 7-order polynom"), id+23);
04368 menu->insertSeparator();
04369 }
04370
04371 menu->insertItem(QString("Make ") + TGo4FitModelPolynom::Class()->GetName(), id+0);
04372 menu->insertItem(QString("Make ") + TGo4FitModelGauss1::Class()->GetName(), id+1);
04373 menu->insertItem(QString("Make ") + TGo4FitModelGauss2::Class()->GetName(), id+2);
04374 menu->insertItem(QString("Make ") + TGo4FitModelGaussN::Class()->GetName(), id+3);
04375 menu->insertItem(QString("Make ") + TGo4FitModelFormula::Class()->GetName(), id+4);
04376 menu->insertItem(QString("Make ") + TGo4FitModelFunction::Class()->GetName(),id+5);
04377 menu->insertItem(QString("Make ") + TGo4FitModelFromData::Class()->GetName(),id+6);
04378 }
04379
04380 void TGo4FitPanel::FillDataTypesList(QPopupMenu* menu, int id)
04381 {
04382 if (menu->count()>0) menu->insertSeparator();
04383 menu->insertItem(QString("Make ") + TGo4FitDataHistogram::Class()->GetName(), id+0);
04384 menu->insertItem(QString("Make ") + TGo4FitDataGraph::Class()->GetName(), id+1);
04385 menu->insertItem(QString("Make ") + TGo4FitDataProfile::Class()->GetName(), id+2);
04386 menu->insertItem(QString("Make ") + TGo4FitDataRidge::Class()->GetName(), id+3);
04387 }
04388
04389 void TGo4FitPanel::PaintFitter(TGo4Fitter* fitter, QFitItem* item, bool update)
04390 {
04391 if (fitter)
04392 for(Int_t nd=0;nd<fitter->GetNumData();nd++)
04393 PaintModelsFor(fitter, fitter->GetData(nd), item, update);
04394 }
04395
04396 bool TGo4FitPanel::PaintModel(TGo4FitModel* model, TPad* pad, QFitItem* item)
04397 {
04398 if ((model==0) || (pad==0) || !fbShowPrimitives) return false;
04399
04400 TH1* histo = ActivePanel()->GetPadHistogram(pad);
04401 if ((histo==0) || (histo->GetDimension()!=1)) return false;
04402
04403 Double_t pos, width, ampl;
04404
04405 if (model->GetPosition(0,pos)) {
04406
04407 Int_t nbin = histo->GetXaxis()->FindBin(pos);
04408 ampl = histo->GetBinContent(nbin);
04409
04410 Double_t limit = pad->GetUymin()*.7 + pad->GetUymax()*.3;
04411 if (ampl<limit) ampl = limit;
04412
04413 TGo4FitGuiArrow* arr = new TGo4FitGuiArrow(0.01,">");
04414 arr->SetLineColor(2);
04415 arr->SetLineWidth(1);
04416 arr->SetItem(item, this);
04417
04418 TGo4FitGuiArrow* warr = 0;
04419 if (model->GetWidth(0,width)) {
04420 warr = new TGo4FitGuiArrow(0.01,"<|>");
04421 warr->SetLineColor(2);
04422 warr->SetLineWidth(1);
04423 warr->SetForWidth(model, arr);
04424 warr->SetItem(item, this);
04425 }
04426
04427 arr->SetForPosition(model, warr, ampl);
04428 arr->Locate();
04429
04430 ActivePanel()->AddDrawObject(pad, TGo4ViewPanel::kind_FitArrows, "::Model_VArrow", arr, true, 0);
04431
04432 if (warr) {
04433 warr->Locate();
04434 ActivePanel()->AddDrawObject(pad, TGo4ViewPanel::kind_FitArrows, "::Model_HArrow", warr, true, 0);
04435 }
04436
04437 ActivePanel()->ShootRepaintTimer();
04438 }
04439
04440 return true;
04441 }
04442
04443 bool TGo4FitPanel::PaintModelsFor(TGo4Fitter* fitter, TGo4FitData* data, QFitItem* item, bool update)
04444 {
04445 if ((fitter==0) || (data==0)) return false;
04446
04447 if (data->IsAnyDataTransform()) return false;
04448
04449 for (Int_t nm=0;nm<fitter->GetNumModel();nm++) {
04450 TGo4FitModel* model = fitter->GetModel(nm);
04451 if (model->IsAssignTo(data->GetName()))
04452 PaintModel(model, FindPadWhereData(data), item);
04453 }
04454
04455 return true;
04456 }
04457
04458 bool TGo4FitPanel::PaintRange(TGo4FitComponent* comp, int nrange, TPad* pad, QFitItem* item)
04459 {
04460 if ((comp==0) || (pad==0) || !fbShowPrimitives) return false;
04461
04462 TH1* histo = ActivePanel()->GetPadHistogram(pad);
04463
04464 if ((histo==0) || (histo->GetDimension()!=1)) return false;
04465
04466 double range = 0.1 * (histo->GetXaxis()->GetXmax() - histo->GetXaxis()->GetXmin());
04467
04468 double ampl = (0.07 + nrange*0.02) * (histo->GetMaximum() - histo->GetMinimum()) + histo->GetMinimum();
04469
04470 double size = 0.015;
04471
04472 Int_t typ, naxis;
04473 Double_t left, right;
04474
04475 comp->GetRangeCondition(nrange, typ, naxis, left, right);
04476
04477 if (naxis!=0) return false;
04478
04479 TGo4FitGuiArrow* arr = 0;
04480
04481 switch (typ) {
04482 case 0: arr = new TGo4FitGuiArrow(size,"<|>"); break;
04483 case 1: arr = new TGo4FitGuiArrow(size,"-><-"); break;
04484 case 2: arr = new TGo4FitGuiArrow(size,"<"); break;
04485 case 3: arr = new TGo4FitGuiArrow(size,">"); break;
04486 }
04487
04488 if (arr!=0) {
04489 arr->SetLineColor(3);
04490 arr->SetLineWidth(3);
04491 arr->SetForRange(comp,nrange,ampl,range);
04492 arr->SetItem(item, this);
04493 arr->Locate();
04494
04495 ActivePanel()->AddDrawObject(pad, TGo4ViewPanel::kind_FitArrows, "::Range_Arrow", arr, true, 0);
04496
04497 ActivePanel()->ShootRepaintTimer();
04498 }
04499 return arr!=0;
04500 }
04501
04502 TGo4FitPeakFinder* TGo4FitPanel::GetPeakFinder(bool autocreate)
04503 {
04504 TGo4Fitter* fitter = GetFitter();
04505 if (fitter==0) return 0;
04506 for (Int_t n=0;n<fitter->GetNumActions();n++) {
04507 TGo4FitPeakFinder* finder = dynamic_cast<TGo4FitPeakFinder*> (fitter->GetAction(n));
04508 if (finder!=0) return finder;
04509 }
04510
04511 if (autocreate) {
04512 TGo4FitPeakFinder* finder = new TGo4FitPeakFinder("Finder", 0, kTRUE, 1);
04513 finder->SetPeakFinderType(2);
04514 fitter->AddActionAt(finder, 0);
04515 return finder;
04516 }
04517
04518 return 0;
04519 }
04520
04521 TGo4FitData* TGo4FitPanel::Wiz_SelectedData()
04522 {
04523 TGo4Fitter* fitter = GetFitter();
04524 return (fitter==0) ? 0 : fitter->FindData(fxWizDataName.latin1());
04525 }
04526
04527 TGo4FitModel* TGo4FitPanel::Wiz_SelectedModel()
04528 {
04529 TGo4Fitter* fitter = GetFitter();
04530 return (fitter==0) ? 0 : fitter->FindModel(fxWizModelName.latin1());
04531 }
04532
04533 void TGo4FitPanel::Wiz_PrepareModelTypeList(QPopupMenu* menu)
04534 {
04535 if (menu) FillModelTypesList(menu,0, TRUE);
04536 }
04537
04538 TGo4FitModel* TGo4FitPanel::Wiz_CreateNewModel(int id)
04539 {
04540 TGo4Fitter* fitter = GetFitter();
04541 if (fitter==0) return 0;
04542
04543 TGo4FitData* data = Wiz_SelectedData();
04544 TGo4FitModel* model = CreateModel(id, 0, fitter, data);
04545
04546 LocateModel(model, data, true);
04547
04548 return model;
04549 }
04550
04551 void TGo4FitPanel::Wiz_PrepareDataTypeList(QPopupMenu* menu)
04552 {
04553 if (menu) FillDataTypesList(menu,0);
04554 }
04555
04556 TGo4FitData* TGo4FitPanel::Wiz_CreateNewData(int id)
04557 {
04558 TGo4Fitter* fitter = GetFitter();
04559 if (fitter==0) return 0;
04560
04561 TGo4FitData* data = CreateData(id, 0);
04562 if (data==0) return 0;
04563
04564 fitter->AddData(data);
04565
04566 UpdateObjectReferenceInSlots();
04567
04568 return data;
04569 }
04570
04571 void TGo4FitPanel::Wiz_RebuildDataList()
04572 {
04573 TGo4Fitter* fitter = GetFitter();
04574 if (fitter==0) return;
04575 if ((fitter->GetNumData()>0) && fbNeedConfirmation)
04576 if ( QMessageBox::information(0,
04577 QString("Remake data list"),
04578 QString("Remove all current data?"),
04579 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return;
04580
04581 fitter->DeleteAllData();
04582 CreateDataFor(ActivePanel(), ActivePad(), fitter);
04583
04584 UpdateObjectReferenceInSlots();
04585 UpdateActivePage();
04586 }
04587
04588 bool TGo4FitPanel::Wiz_RemoveData()
04589 {
04590 TGo4Fitter* fitter = GetFitter();
04591 TGo4FitData* data = Wiz_SelectedData();
04592 if ((data==0) || (fitter==0)) return FALSE;
04593
04594 if(fbNeedConfirmation)
04595 if ( QMessageBox::information(0,
04596 QString("Delete data"),
04597 QString("Are you sure to delete ") + data->GetName(),
04598 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No ) return FALSE;
04599
04600 fitter->RemoveData(data->GetName(), kTRUE);
04601
04602 fxWizDataName = "";
04603
04604 UpdateObjectReferenceInSlots();
04605
04606 return TRUE;
04607 }
04608
04609 void TGo4FitPanel::Wiz_UseSelectedRange()
04610 {
04611 if (!WorkingWithPanel()) return;
04612
04613 TGo4FitData* data = Wiz_SelectedData();
04614 TPad* pad = FindPadWhereData(data);
04615 if ((pad==0) || (data==0)) return;
04616
04617 double xmin, xmax;
04618 if (ActivePanel()->GetVisibleRange(pad, 0, xmin, xmax))
04619 data->SetRange(0, xmin, xmax);
04620
04621 UpdateActivePage();
04622 }
04623
04624 void TGo4FitPanel::Wiz_TakeCurrentRange()
04625 {
04626 TGo4Fitter* fitter = GetFitter();
04627 if ((fitter==0) || (ActivePanel()==0)) return;
04628
04629 for (int n=0;n<fitter->GetNumData();n++) {
04630 TGo4FitData* data = fitter->GetData(n);
04631 TPad* pad = FindPadWhereData(data);
04632
04633 if ((pad!=0) && (data!=0)) {
04634 data->ClearRanges();
04635 double xmin, xmax;
04636 if (ActivePanel()->GetVisibleRange(pad, 0, xmin, xmax))
04637 data->SetRange(0, xmin, xmax);
04638 }
04639 }
04640 }
04641
04642 void TGo4FitPanel::Wiz_GetModelInfo(TGo4FitModel* model, QString* info)
04643 {
04644 if ((model==0) || (info==0)) return;
04645 *info = "Model: ";
04646 *info += model->GetName();
04647 *info += " of class: ";
04648 *info += model->ClassName();
04649
04650 if (model->InheritsFrom(TGo4FitModelFormula::Class())) {
04651 TGo4FitModelFormula* formula = dynamic_cast<TGo4FitModelFormula*> (model);
04652 if (formula) {
04653 *info += "\nFormula: ";
04654 *info += formula->GetExpression();
04655 }
04656 }
04657
04658 if (model->InheritsFrom(TGo4FitModelFunction::Class())) {
04659 TGo4FitModelFunction* func = dynamic_cast<TGo4FitModelFunction*> (model);
04660 if (func) {
04661 *info += "\nFunction: ";
04662 *info += func->GetFunctionName();
04663 *info += " from: ";
04664 *info += func->GetLibraryName();
04665 }
04666 }
04667 if (fiIntegralMode>0) {
04668 int mode = fiIntegralMode;
04669
04670 if ((mode==1) || (mode==2)) {
04671 TGo4Fitter* fitter = GetFitter();
04672 TGo4FitData* data = Wiz_SelectedData();
04673 if (data)
04674 if (!model->IsAssignTo(data->GetName())) data = 0;
04675 if ((data!=0) && (fitter!=0)) {
04676 if (mode==1) *info += "\nCounts="; else *info += "\nIntegral=";
04677 double v = fitter->CalculatesIntegral(data->GetName(),model->GetName(),(mode==1));
04678 *info += QString::number(v);
04679 }
04680 }
04681
04682 if (mode==3) {
04683 double v = model->Integral();
04684 if (v>0) {
04685 *info += "\nGauss integral=";
04686 *info += QString::number(v);
04687 }
04688 }
04689 }
04690 }
04691
04692
04693 QString TGo4FitPanel::Wiz_GetSlotSourceInfo(TGo4FitSlot* slot)
04694 {
04695 QString res = "";
04696 if (slot==0) return res;
04697
04698 if (slot->GetObject()==0) {
04699 res = "none";
04700 } else
04701 if (slot->GetOwned()) {
04702 res = "internal object";
04703 } else
04704 if (WorkingWithPanel()) {
04705 TPad* pad = FindPadForSlot(slot);
04706 if (pad==0)
04707 res = "reference without pad";
04708 else {
04709 res = "Panel: ";
04710 res+= ActivePanel()->name();
04711 if (ActivePanel()->GetCanvas() != pad) {
04712 res += " pad: ";
04713 res += pad->GetName();
04714 }
04715 }
04716 } else {
04717 int slotindex = GetPadIndexForSlot(slot);
04718 QString linkname;
04719 linkname.sprintf("FitSlotLink_%d", slotindex);
04720 const char* itemname = GetLinkedName(linkname);
04721
04722 if (itemname!=0) res = itemname;
04723 else res = "reference to external object";
04724 }
04725
04726 return res;
04727 }
04728
04729 void TGo4FitPanel::ArrowChanged(TGo4FitGuiArrow* arr)
04730 {
04731 TGo4Fitter* fitter = GetFitter();
04732
04733 if ((arr==0) || (fitter==0)) return;
04734
04735 bool ismodified = false;
04736 for(Int_t n=0;n<fitter->NumSlots();n++) {
04737 TPad* pad = FindPadForSlot(fitter->GetSlot(n));
04738 if (pad==0) continue;
04739
04740 TObjArray lst;
04741 ActivePanel()->CollectSpecialObjects(pad, &lst, TGo4ViewPanel::kind_FitArrows);
04742
04743 bool res = false;
04744 for (Int_t k=0;k<=lst.GetLast();k++) {
04745 TGo4FitGuiArrow* a = dynamic_cast<TGo4FitGuiArrow*> (lst[k]);
04746 if (a==0) continue;
04747 if (a->Locate()) res = true;
04748 }
04749 if (res) {
04750 ActivePanel()->MarkPadModified(pad);
04751 ismodified = true;
04752 }
04753 }
04754 if (ismodified)
04755 ActivePanel()->ShootRepaintTimer(ActivePad());
04756
04757 if (fiPanelMode==FitGui::pm_Expert) {
04758 if ((arr->GetType()==TGo4FitGuiArrow::at_pos) ||
04759 (arr->GetType()==TGo4FitGuiArrow::at_width)) UpdateItemsOfType(FitGui::ot_par, arr->GetItem());
04760
04761 if (arr->GetType()==TGo4FitGuiArrow::at_range)
04762 SetItemText(arr->GetItem(), TRUE);
04763
04764 QFitWidget* current = dynamic_cast<QFitWidget*> (ListStack->widget(FitGui::ListStackId));
04765 if(current) current->FillWidget();
04766 }
04767
04768 if (fiPanelMode==FitGui::pm_Wizard)
04769 if (fbParsWidgetShown)
04770 FillParsWidget();
04771 else
04772 UpdateWizStackWidget();
04773 }
04774
04775 void TGo4FitPanel::DeleteModelWithPrimit(TGo4FitGuiArrow* arr)
04776 {
04777 if (arr==0) return;
04778 TGo4FitModel* model = arr->GetModel();
04779 if (model==0) return;
04780
04781 if (fiPanelMode==FitGui::pm_Expert) {
04782 QFitItem* item = FindItem(model, FitGui::ot_model, 0);
04783 if (item) Cmd_DeleteModel(item);
04784 } else
04785 Cmd_RemoveModel(model);
04786 }
04787
04788 int TGo4FitPanel::GetPadIndexForSlot(TGo4FitSlot* slot)
04789 {
04790 TGo4Fitter* fitter = GetFitter();
04791 if ((slot==0) || (fitter==0)) return -1;
04792
04793 int indx = -1;
04794 for (int n=0;n<fitter->NumSlots();n++) {
04795 TGo4FitSlot* subslot = fitter->GetSlot(n);
04796 bool needpad = !subslot->GetOwned() &&
04797 (subslot->GetClass()->InheritsFrom(TH1::Class()) ||
04798 subslot->GetClass()->InheritsFrom(TGraph::Class()));
04799 if (needpad) indx++;
04800 if (slot==subslot)
04801 return needpad ? indx : -1;
04802 }
04803 return -1;
04804 }
04805
04806 TPad* TGo4FitPanel::FindPadForSlot(TGo4FitSlot* slot)
04807 {
04808 if (!WorkingWithPanel()) return 0;
04809 int indx = GetPadIndexForSlot(slot);
04810 return (indx<0) ? 0 : ActivePanel()->GetSubPad(ActivePad(), indx, true);
04811 }
04812
04813 TPad* TGo4FitPanel::FindPadWhereData(TGo4FitData* data)
04814 {
04815 TGo4Fitter* fitter = GetFitter();
04816 if (fitter==0) return 0;
04817 for(Int_t n = 0; n<fitter->NumSlots();n++) {
04818 TGo4FitSlot* slot = fitter->GetSlot(n);
04819 if (slot->GetOwner()!=data) continue;
04820 TPad* pad = FindPadForSlot(slot);
04821 if (pad!=0) return pad;
04822 }
04823 return 0;
04824 }
04825
04826 TPad* TGo4FitPanel::FindPadWhereModel(TGo4FitModel* model)
04827 {
04828 TGo4Fitter* fitter = GetFitter();
04829 if ((fitter==0) || (model==0)) return 0;
04830
04831 for(Int_t n=0;n<model->NumAssigments();n++) {
04832 TGo4FitData* data = fitter->FindData(model->AssignmentName(n));
04833 TPad* pad = FindPadWhereData(data);
04834 if (pad!=0) return pad;
04835 }
04836 return 0;
04837 }
04838
04839 TPad* TGo4FitPanel::FindPadWhereComp(TGo4FitComponent* comp)
04840 {
04841 if (comp==0) return 0;
04842 if (comp->InheritsFrom(TGo4FitData::Class()))
04843 return FindPadWhereData(dynamic_cast<TGo4FitData*> (comp));
04844 else
04845 return FindPadWhereModel(dynamic_cast<TGo4FitModel*> (comp));
04846 }
04847
04848 TGo4FitData* TGo4FitPanel::CreateData(int id, const char* name)
04849 {
04850 TString dataname;
04851
04852 if (name==0) {
04853 TGo4Fitter* fitter = GetFitter();
04854 if (fitter==0) return 0;
04855 dataname = fitter->FindNextName("Data", 0, kFALSE);
04856 } else dataname = name;
04857
04858 switch(id) {
04859 case 0: return new TGo4FitDataHistogram(dataname);
04860 case 1: return new TGo4FitDataGraph(dataname);
04861 case 2: return new TGo4FitDataProfile(dataname);
04862 case 3: return new TGo4FitDataRidge(dataname);
04863 }
04864 return 0;
04865 }
04866
04867 TGo4FitModel* TGo4FitPanel::CreateModel(int id, const char* namebase, TGo4Fitter* fitter, TGo4FitData* data)
04868 {
04869 TString NameBase;
04870
04871 if (fitter)
04872 if ((data==0) && (fitter->GetNumData()>0)) data = fitter->GetData(0);
04873 Int_t NumDim = 0;
04874 if (data) NumDim = data->DefineDimensions();
04875 if (NumDim<=0) NumDim = 1;
04876
04877 Int_t order = 0;
04878 switch(id) {
04879 case 20:
04880 switch (NumDim) {
04881 case 1: id = 1; break;
04882 case 2: id = 2; break;
04883 default: id = 3; break;
04884 }
04885 break;
04886 case 21: order = 1; id = 7; break;
04887 case 22: order = 3; id = 7; break;
04888 case 23: order = 7; id = 7; break;
04889 }
04890
04891 if (namebase) NameBase = namebase; else
04892 switch(id) {
04893 case 0: NameBase = "Pol"; break;
04894 case 1:
04895 case 2:
04896 case 3: NameBase = "Gauss"; break;
04897 case 4: NameBase = "Form"; break;
04898 case 5: NameBase = "Func"; break;
04899 case 6: NameBase = "FromData"; break;
04900 case 7: NameBase = "Pol"; break;
04901 case 24: NameBase = "Lor"; break;
04902 case 25: NameBase = "Exp"; break;
04903 default: NameBase = "Model";
04904 }
04905
04906 TString ModelName;
04907
04908 if (fitter && (id!=7)) ModelName = fitter->FindNextName(NameBase.Data(), 0);
04909 else ModelName = NameBase;
04910
04911 TGo4FitModel* model = 0;
04912
04913 switch(id) {
04914 case 0: model = new TGo4FitModelPolynom(ModelName); break;
04915 case 1: model = new TGo4FitModelGauss1(ModelName); break;
04916 case 2: model = new TGo4FitModelGauss2(ModelName); break;
04917 case 3: model = new TGo4FitModelGaussN(ModelName, NumDim<3 ? 3 : NumDim); break;
04918 case 4: model = new TGo4FitModelFormula(ModelName); break;
04919 case 5: model = new TGo4FitModelFunction(ModelName); break;
04920 case 6: model = new TGo4FitModelFromData(ModelName); break;
04921 case 7: fitter->AddPolynoms(data ? data->GetName() : 0, NameBase.Data(), order, NumDim); break;
04922 case 24: {
04923 TGo4FitModelFormula* formula = new TGo4FitModelFormula(ModelName,"1./(1.+sq((x-Pos)/Width))",2,kTRUE);
04924 formula->SetParsNames("Ampl","Pos","Width");
04925 formula->SetPosParIndex(0, 0);
04926 formula->SetWidthParIndex(0, 1);
04927 model = formula;
04928 break;
04929 }
04930 case 25: {
04931 model = new TGo4FitModelFormula(ModelName,"exp(Koef*x)",1,kTRUE);
04932 model->SetParsNames("Ampl","Koef");
04933 break;
04934 }
04935 }
04936
04937 if (fitter && model) {
04938 if (data) model->AssignToData(data->GetName());
04939 fitter->AddModel(model);
04940 }
04941
04942 return model;
04943 }
04944
04945 void TGo4FitPanel::LocateModel(TGo4FitModel* model, TGo4FitData* data, bool usepad)
04946 {
04947 TGo4Fitter* fitter = GetFitter();
04948
04949 if ((fitter==0) || (model==0)) return;
04950
04951 if (data==0)
04952 for(int n=0;n<=model->NumAssigments();n++) {
04953 data = fitter->FindData(model->AssignmentName(n));
04954 if (!usepad || FindPadWhereData(data)) break;
04955 }
04956 if (data==0) return;
04957
04958 if (!usepad && data->DefineDimensions()!=1) usepad = TRUE;
04959
04960 if (usepad) {
04961 TPad* pad = FindPadWhereData(data);
04962 if (pad) {
04963 model->SetPosition(0, (pad->GetUxmin() + pad->GetUxmax())/2.);
04964 model->SetWidth(0, TMath::Abs(pad->GetUxmax() - pad->GetUxmin())*.05);
04965 model->SetPosition(1, (pad->GetUymin() + pad->GetUymax())/2.);
04966 model->SetWidth(1, TMath::Abs(pad->GetUymax() - pad->GetUymin())*.05);
04967 }
04968 } else {
04969 Double_t mid, width;
04970 if (fitter->CalculatesMomentums(data->GetName(), kTRUE, kTRUE, mid, width)) {
04971 model->SetPosition(0, mid);
04972 model->SetWidth(0, width);
04973 }
04974 }
04975 }
04976
04977 int TGo4FitPanel::DefineModelWidgetType(TObject* obj)
04978 {
04979 if (obj==0) return FitGui::wt_none;
04980 if (obj->InheritsFrom(TGo4FitModelPolynom::Class())) return FitGui::wt_polynom;
04981 if (obj->InheritsFrom(TGo4FitModelGauss1::Class())) return FitGui::wt_gauss1;
04982 if (obj->InheritsFrom(TGo4FitModelGauss2::Class())) return FitGui::wt_gauss2;
04983 if (obj->InheritsFrom(TGo4FitModelGaussN::Class())) return FitGui::wt_gaussn;
04984 if (obj->InheritsFrom(TGo4FitModelFormula::Class())) return FitGui::wt_formula;
04985 if (obj->InheritsFrom(TGo4FitModelFunction::Class())) return FitGui::wt_function;
04986 if (obj->InheritsFrom(TGo4FitModel::Class())) return FitGui::wt_model;
04987 return FitGui::wt_none;
04988 }
04989
04990 void TGo4FitPanel::CreateFitSlotLink(TGo4FitSlot* slot, const char * itemname)
04991 {
04992 cout << "****** CreateFitSlotLink " << slot->GetName() << " " << itemname << endl;
04993
04994 if ((slot==0) || (itemname==0)) return;
04995
04996 int slotindex = GetPadIndexForSlot(slot);
04997
04998 cout << "Slot index = " << slotindex << endl;
04999
05000 if (slotindex<0) return;
05001
05002 QString linkname;
05003 linkname.sprintf("FitSlotLink_%d", slotindex);
05004
05005 RemoveLink(linkname);
05006
05007 AddLink(itemname, linkname);
05008
05009 GetLinked(linkname, 1);
05010
05011 UpdateObjectReferenceInSlot(slot, false);
05012
05013
05014 }
05015
05016
05017 bool TGo4FitPanel::UpdateObjectReferenceInSlot(TGo4FitSlot* slot, bool createlink)
05018 {
05019 if (slot==0) return true;
05020
05021 if (slot->GetOwned()) return true;
05022
05023 bool res = true;
05024
05025 TObject* obj = 0;
05026
05027 if (WorkingWithPanel()) {
05028
05029 TPad* pad = FindPadForSlot(slot);
05030
05031 TGo4Slot* objslot = ActivePanel()->GetPadMainObjectSlot(pad);
05032 obj = objslot==0 ? 0 : objslot->GetAssignedObject();
05033
05034 if ((obj!=0) && createlink) {
05035 TString linkname = "data_";
05036 linkname+=slot->GetName();
05037 AddLink(objslot, linkname);
05038 }
05039 } else {
05040 int slotindex = GetPadIndexForSlot(slot);
05041 QString linkname;
05042 linkname.sprintf("FitSlotLink_%d", slotindex);
05043 obj = GetLinked(linkname, 0);
05044 }
05045
05046 if (obj==0) res = false;
05047 if ((obj==0) || !slot->IsSuitable(obj))
05048 slot->SetObject(0, kFALSE);
05049 else
05050 slot->SetObject(obj, kFALSE);
05051
05052 return res;
05053 }
05054
05055
05056 bool TGo4FitPanel::UpdateObjectReferenceInSlots()
05057 {
05058 TGo4Fitter* fitter = GetFitter();
05059 if (fitter==0) return false;
05060
05061 bool res = true;
05062
05063
05064
05065
05066 if (WorkingWithPanel())
05067 RemoveLinksMasked("data_");
05068
05069
05070 for(Int_t n = 0; n<fitter->NumSlots();n++) {
05071 TGo4FitSlot* slot = fitter->GetSlot(n);
05072 res = res && UpdateObjectReferenceInSlot(slot, true);
05073 }
05074
05075
05076
05077 return res;
05078 }
05079
05080 void TGo4FitPanel::ClearObjectReferenceInSlots()
05081 {
05082 if (!WorkingWithPanel()) return;
05083
05084 TGo4Fitter* fitter = GetFitter();
05085 if (fitter==0) return;
05086
05087 for(Int_t n = 0; n<fitter->NumSlots();n++) {
05088 TGo4FitSlot* slot = fitter->GetSlot(n);
05089 if (!slot->GetOwned())
05090 slot->SetObject(0, kFALSE);
05091 }
05092 }
05093
05094 void TGo4FitPanel::RemoveDrawObjects()
05095 {
05096 if (!WorkingWithPanel()) return;
05097
05098 TGo4Fitter* fitter = GetFitter();
05099 if (fitter==0) return;
05100
05101 bool res = false;
05102
05103 for(Int_t n = 0; n<fitter->NumSlots();n++) {
05104 TPad* pad = FindPadForSlot(fitter->GetSlot(n));
05105 if (pad==0) continue;
05106 if (ActivePanel()->DeleteDrawObjects(pad, TGo4ViewPanel::kind_FitModels)) res = true;
05107 if (ActivePanel()->DeleteDrawObjects(pad, TGo4ViewPanel::kind_FitInfo)) res = true;
05108 }
05109 if (res) ActivePanel()->ShootRepaintTimer();
05110 }
05111
05112 void TGo4FitPanel::CloseDrawPanel()
05113 {
05114 if (fxDrawNewPanel!=0) {
05115 fxDrawNewPanel->close();
05116 fxDrawNewPanel = 0;
05117 }
05118 }
05119
05120 void TGo4FitPanel::FillNamedWidget(QFitNamedWidget* w)
05121 {
05122 if (w==0) return;
05123 TObject* obj = w->GetObject();
05124 if (obj==0) return;
05125
05126 w->ClassNameLbl->setText(QString("Class name: ") + obj->ClassName());
05127 w->ClassNameLbl->adjustSize();
05128 w->NameEdt->setText(obj->GetName());
05129 w->TitleEdt->setText(obj->GetTitle());
05130 TNamed* n = dynamic_cast<TNamed*> (obj);
05131 w->NameEdt->setReadOnly(n==0);
05132 w->TitleEdt->setReadOnly(n==0);
05133
05134 TGo4FitNamed* go4n = dynamic_cast<TGo4FitNamed*> (obj);
05135 if((go4n!=0) && go4n->GetOwner())
05136 w->FullNameLbl->setText(QString("Full name: ")+go4n->GetFullName());
05137 else
05138 w->FullNameLbl->setText("");
05139 w->FullNameLbl->adjustSize();
05140
05141 QFitModelWidget* mw = dynamic_cast<QFitModelWidget*> (w);
05142 TGo4FitModel* model = dynamic_cast<TGo4FitModel*> (obj);
05143 if ((mw!=0) && (model!=0)) {
05144 mw->AmplChk->setChecked(model->GetAmplPar()!=0);
05145 mw->AmplChk->setEnabled(model->CanAmplTouch());
05146 mw->BuffersChk->setChecked(model->GetUseBuffers());
05147 mw->GroupSpin->setValue(model->GetGroupIndex());
05148 }
05149 }
05150
05151 void TGo4FitPanel::ChangeObjectName(QFitNamedWidget* w, const char* newname)
05152 {
05153 if (w==0) return;
05154 QFitItem* item = w->GetItem();
05155 if ((item==0) || (strlen(newname)==0)) return;
05156 TNamed* obj = dynamic_cast<TNamed*> (item->Object());
05157 if (obj==0) return;
05158
05159 if (item->ObjectType()==FitGui::ot_slot) return;
05160
05161 if (item->ObjectType()==FitGui::ot_par)
05162 if (item->Parent()!=0)
05163 if (item->Parent()->ObjectType()==FitGui::ot_parslist) {
05164 TGo4FitParsList* pars = dynamic_cast<TGo4FitParsList*> (item->Parent()->Object());
05165 if (pars->FindPar(newname)) return;
05166 }
05167
05168 if (item->ObjectType()==FitGui::ot_data)
05169 if (item->Parent()!=0)
05170 if (item->Parent()->ObjectType()==FitGui::ot_datalist) {
05171 TGo4Fitter* fitter = GetFitter();
05172 if ((fitter==0) || (fitter->FindData(newname))) return;
05173 fitter->ChangeDataNameInAssignments(obj->GetName(), newname);
05174 UpdateItemsOfType(FitGui::ot_ass, 0);
05175 }
05176
05177 if (item->ObjectType()==FitGui::ot_model)
05178 if (item->Parent()!=0)
05179 if (item->Parent()->ObjectType()==FitGui::ot_modellist) {
05180 TGo4Fitter* fitter = GetFitter();
05181 if ((fitter==0) || (fitter->FindModel(newname))) return;
05182 }
05183
05184 obj->SetName(newname);
05185
05186 w->SetWidgetItemText(true);
05187
05188 TGo4FitNamed* go4n = dynamic_cast<TGo4FitNamed*> (obj);
05189 if((go4n!=0) && go4n->GetOwner())
05190 w->FullNameLbl->setText(QString("Full name: ")+go4n->GetFullName());
05191 else
05192 w->FullNameLbl->setText("");
05193 w->FullNameLbl->adjustSize();
05194 }
05195
05196 void TGo4FitPanel::ChangeObjectTitle(QFitNamedWidget* w, const char* newtitle)
05197 {
05198 if (w==0) return;
05199 TNamed* n = dynamic_cast<TNamed*> (w->GetObject());
05200 if (n!=0) n->SetTitle(newtitle);
05201 }
05202
05203 void TGo4FitPanel::ChangeModelPar(QFitModelWidget* w, int npar, int value)
05204 {
05205 if (w==0) return;
05206 TGo4FitModel* model = dynamic_cast<TGo4FitModel*> (w->GetObject());
05207 if (model==0) return;
05208 switch (npar) {
05209 case 0: {
05210 if (model->CanAmplTouch()) {
05211 bool res = FALSE;
05212 if (value!=0) res = model->MakeAmpl();
05213 else res = model->RemoveAmpl();
05214 if (res)
05215 w->UpdateItemsOfType(FitGui::ot_parslist, false);
05216 }
05217 break;
05218 }
05219
05220 case 1: {
05221 model->SetUseBuffers(value!=0);
05222 break;
05223 }
05224
05225 case 2:{
05226 model->SetGroupIndex(value);
05227 break;
05228 }
05229 }
05230 }
05231
05232