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