Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TFitParametersDialog.cxx
Go to the documentation of this file.
1// @(#)root/fitpanel:$Id$
2// Author: Ilka Antcheva, Lorenzo Moneta 03/10/06
3
4/*************************************************************************
5 * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12//////////////////////////////////////////////////////////////////////////
13// //
14// TFitParametersDialog //
15// //
16// Create a dialog for fit function parameter settings. //
17// //
18//////////////////////////////////////////////////////////////////////////
19
21#include "TF1.h"
22#include "TGButton.h"
23#include "TGLabel.h"
24#include "TGLayout.h"
25#include "TGTextEntry.h"
26#include "TGMsgBox.h"
27#include "TGNumberEntry.h"
28#include "TGTripleSlider.h"
29#include "TVirtualPad.h"
30#include "TMath.h"
31
32#include <limits>
33
34
37 kFIX = 10,
38 kBND = 20,
39 kVAL = 30,
40 kMIN = 40,
41 kMAX = 50,
42 kSLD = 60,
43 kSTP = 70,
44 kERR = 80,
45 kUPDATE = 8888,
50};
51
53
54////////////////////////////////////////////////////////////////////////////////
55
57 const TGWindow *main,
58 TF1 *func,
59 TVirtualPad *pad,
60 Int_t *ret_code) :
62 fFunc (func),
63 fFpad (pad),
64 fHasChanges (kFALSE),
65 fImmediateDraw (kTRUE),
66 fRetCode (ret_code)
67
68{
69 // Create a dialog for fit function parameters' settings.
70
72
74 fNP = fFunc->GetNpar();
75 fPmin = new Double_t[fNP];
76 fPmax = new Double_t[fNP];
77 fPval = new Double_t[fNP];
78 fPerr = new Double_t[fNP];
79 fPstp = new Double_t[fNP];
80
81 for (Int_t i = 0; i < fNP; i++) {
82 fFunc->GetParLimits(i, fPmin[i], fPmax[i]);
83 fPval[i] = fFunc->GetParameter(i);
84 fPerr[i] = fFunc->GetParError(i);
85 if (fPerr[i] > 1E-16)
87 else {
88 if (TMath::Abs(fPval[i]) > 1.)
89 // if error is zero use as step approx 10% of current value
91 else
92 fPstp[i] = 0.1;
93 }
94 }
95 fParNam = new TGTextEntry*[fNP];
102 fParStp = new TGNumberEntry*[fNP];
104
105 memset(fParNam, 0, sizeof(TGTextEntry*)*fNP);
106 memset(fParFix, 0, sizeof(TGCheckButton*)*fNP);
107 memset(fParBnd, 0, sizeof(TGCheckButton*)*fNP);
108 memset(fParVal, 0, sizeof(TGNumberEntry*)*fNP);
109 memset(fParMin, 0, sizeof(TGNumberEntryField*)*fNP);
110 memset(fParMax, 0, sizeof(TGNumberEntryField*)*fNP);
111 memset(fParSld, 0, sizeof(TGTripleHSlider*)*fNP);
112 memset(fParStp, 0, sizeof(TGNumberEntry*)*fNP);
113 memset(fParErr, 0, sizeof(TGNumberEntryField*)*fNP);
114
116 AddFrame(f1, new TGLayoutHints(kLHintsTop, 1, 1, 1, 1));
117
118 // column 'Name'
120 fContNam->AddFrame(new TGLabel(fContNam,"Name"),
121 new TGLayoutHints(kLHintsTop, 5, 0, 0, 0));
122 for (Int_t i = 0; i < fNP; i++ ) {
123 fParNam[i] = new TGTextEntry(fContNam, new TGTextBuffer(80), kNAME+i);
124 fParNam[i]->SetText(Form("%s", fFunc->GetParName(i)));
127 new TGLayoutHints(kLHintsExpandX, 2, 2, 7, 5));
128 }
129 f1->AddFrame(fContNam, new TGLayoutHints(kLHintsLeft, 1, 1, 2, 2));
130
131 // column 'Fix'
133 fContFix->AddFrame(new TGLabel(fContFix,"Fix"),
134 new TGLayoutHints(kLHintsTop, 2, 0, 0, 0));
135 for (Int_t i = 0; i < fNP; i++ ) {
136 fParFix[i] = new TGCheckButton(fContFix, "", kFIX*fNP+i);
137 fParFix[i]->SetToolTipText(Form("Set %s to fixed", fFunc->GetParName(i)));
139 5, 5, 10, 7));
140 if ((fPmin[i] == fPmax[i]) && (fPmin[i] || fPmax[i]))
142 else
144 fParFix[i]->Connect("Toggled(Bool_t)", "TFitParametersDialog", this, "DoParFix(Bool_t)");
145 }
146 f1->AddFrame(fContFix, new TGLayoutHints(kLHintsLeft, 1, 1, 2, 2));
147
148 // column 'Bound'
150 fContBnd->AddFrame(new TGLabel(fContBnd,"Bound"),
151 new TGLayoutHints(kLHintsTop, 2, 0, 0, 0));
152 for (Int_t i = 0; i < fNP; i++ ) {
153 fParBnd[i] = new TGCheckButton(fContBnd, "", kBND*fNP+i);
154 fParBnd[i]->SetToolTipText(Form("Set bound to %s", fFunc->GetParName(i)));
156 15, 5, 10, 7));
157 fParBnd[i]->Connect("Toggled(Bool_t)", "TFitParametersDialog", this, "DoParBound(Bool_t)");
158 if ( ((fPmin[i] != fPmax[i]) && (fPmin[i] || fPmax[i])) || (fParMin[i] < fParMax[i]) )
160 else
162 }
163 f1->AddFrame(fContBnd, new TGLayoutHints(kLHintsLeft, 1, 1, 2, 2));
164
165 // column 'Value'
167 fContVal->AddFrame(new TGLabel(fContVal,"Value"),
168 new TGLayoutHints(kLHintsTop, 5, 0, 0, 0));
169 for (Int_t i = 0; i < fNP; i++ ) {
170 fParVal[i] = new TGNumberEntry(fContVal, 1.2E-12, 15, kVAL*fNP+i,
172 fParVal[i]->SetNumber(fPval[i]);
175 (fParVal[i]->GetNumberEntry())->SetToolTipText(Form("%s", fFunc->GetParName(i)));
176 (fParVal[i]->GetNumberEntry())->Connect("ReturnPressed()", "TFitParametersDialog",
177 this, "DoParValue()");
178 fParVal[i]->Connect("ValueSet(Long_t)", "TFitParametersDialog", this, "DoParValue()");
179 (fParVal[i]->GetNumberEntry())->Connect("TabPressed()", "TFitParametersDialog", this, "HandleTab()");
180 (fParVal[i]->GetNumberEntry())->Connect("ShiftTabPressed()", "TFitParametersDialog", this, "HandleShiftTab()");
181 fTextEntries.Add(fParVal[i]->GetNumberEntry());
182 }
183 f1->AddFrame(fContVal, new TGLayoutHints(kLHintsLeft, 1, 1, 2, 2));
184
185 // column 'Min'
187 fContMin->AddFrame(new TGLabel(fContMin,"Min"),
188 new TGLayoutHints(kLHintsTop, 5, 0, 0, 0));
189 for (Int_t i = 0; i < fNP; i++ ) {
190 fParMin[i] = new TGNumberEntryField(fContMin, kMIN*fNP+i, 0.0,
193 ((TGTextEntry*)fParMin[i])->SetToolTipText(Form("Lower limit of %s",
194 fFunc->GetParName(i)));
196 fParMin[i]->SetNumber(fPmin[i]);
197 fParMin[i]->Connect("ReturnPressed()", "TFitParametersDialog", this,
198 "DoParMinLimit()");
199 fParMin[i]->Connect("TabPressed()", "TFitParametersDialog", this, "HandleTab()");
200 fParMin[i]->Connect("ShiftTabPressed()", "TFitParametersDialog", this, "HandleShiftTab()");
202 }
203 f1->AddFrame(fContMin, new TGLayoutHints(kLHintsLeft, 1, 1, 2, 2));
204
205 // column 'Set Range'
207 fContSld->AddFrame(new TGLabel(fContSld,"Set Range"),
208 new TGLayoutHints(kLHintsTop, 5, 0, 0, 0));
209 for (Int_t i = 0; i < fNP; i++ ) {
215 }
216 f1->AddFrame(fContSld, new TGLayoutHints(kLHintsLeft, 1, 1, 2, 2));
217
218 // column 'Max'
220 fContMax->AddFrame(new TGLabel(fContMax,"Max"),
221 new TGLayoutHints(kLHintsTop, 5, 0, 0, 0));
222 for (Int_t i = 0; i < fNP; i++ ) {
223 fParMax[i] = new TGNumberEntryField(fContMax, kMAX*fNP+i, 0.0,
226 ((TGTextEntry*)fParMax[i])->SetToolTipText(Form("Upper limit of %s",
227 fFunc->GetParName(i)));
229 fParMax[i]->SetNumber(fPmax[i]);
230 fParMax[i]->Connect("ReturnPressed()", "TFitParametersDialog", this, "DoParMaxLimit()");
231 fParMax[i]->Connect("TabPressed()", "TFitParametersDialog", this, "HandleTab()");
232 fParMax[i]->Connect("ShiftTabPressed()", "TFitParametersDialog", this, "HandleShiftTab()");
234 }
235 f1->AddFrame(fContMax, new TGLayoutHints(kLHintsLeft, 1, 1, 2, 2));
236
237 // column 'Step'
239 fContStp->AddFrame(new TGLabel(fContStp,"Step"),
240 new TGLayoutHints(kLHintsTop, 5, 0, 0, 0));
241 for (Int_t i = 0; i < fNP; i++ ) {
242 fParStp[i] = new TGNumberEntry(fContStp, 1.2E-12, 15, kSTP*fNP+i,
244 fParStp[i]->SetNumber(fPstp[i]);
247 (fParStp[i]->GetNumberEntry())->SetToolTipText(Form("%s", fFunc->GetParName(i)));
248 (fParStp[i]->GetNumberEntry())->Connect("ReturnPressed()", "TFitParametersDialog",
249 this, "DoParStep()");
250 fParStp[i]->Connect("ValueSet(Long_t)", "TFitParametersDialog", this, "DoParStep()");
251 (fParStp[i]->GetNumberEntry())->Connect("TabPressed()", "TFitParametersDialog", this, "HandleTab()");
252 (fParStp[i]->GetNumberEntry())->Connect("ShiftTabPressed()", "TFitParametersDialog", this, "HandleShiftTab()");
253 fTextEntries.Add(fParStp[i]->GetNumberEntry());
254 }
255 f1->AddFrame(fContStp, new TGLayoutHints(kLHintsLeft, 1, 1, 2, 2));
256
257 // column 'Error'
259 fContErr->AddFrame(new TGLabel(fContErr,"Errors"),
260 new TGLayoutHints(kLHintsTop, 5, 0, 0, 0));
261 for (Int_t i = 0; i < fNP; i++ ) {
262 fParErr[i] = new TGNumberEntryField(fContErr, kERR*fNP+i, 0.0,
265 ((TGTextEntry*)fParErr[i])->SetToolTipText(Form("Error of %s",
266 fFunc->GetParName(i)));
269 if (fPerr[i])
270 fParErr[i]->SetNumber(fPerr[i]);
271 else
272 ((TGTextEntry *)fParErr[i])->SetText("-");
273 }
274 f1->AddFrame(fContErr, new TGLayoutHints(kLHintsLeft, 1, 1, 2, 2));
275
276 TGCompositeFrame *f2 = new TGCompositeFrame(this, 270, 20, kHorizontalFrame);
278
279 fUpdate = new TGCheckButton(f2, "&Immediate preview", kUPDATE);
280 fUpdate->SetToolTipText("Immediate function redrawing");
283 fUpdate->Connect("Toggled(Bool_t)", "TFitParametersDialog", this, "HandleButtons(Bool_t)");
284
286 f2->AddFrame(f3, new TGLayoutHints(kLHintsRight));
287
288 fReset = new TGTextButton(f3, "&Reset", kRESET);
290 fReset->SetToolTipText("Reset the parameter settings");
292 fReset->Connect("Clicked()", "TFitParametersDialog", this, "DoReset()");
293
294 fApply = new TGTextButton(f3, "&Apply", kAPPLY);
297 fApply->Connect("Clicked()", "TFitParametersDialog", this, "DoApply()");
298 fApply->SetToolTipText("Apply parameter settings and redraw the function");
299
300 fOK = new TGTextButton(f3, "&OK", kOK);
302 fOK->SetToolTipText("Apply parameter settings, redraw function and close this dialog");
303 fOK->Connect("Clicked()", "TFitParametersDialog", this, "DoOK()");
304
305 fCancel = new TGTextButton(f3, "&Cancel", kCANCEL);
307 fCancel->SetToolTipText("Close this dialog with no parameter changes");
308 fCancel->Connect("Clicked()", "TFitParametersDialog", this, "DoCancel()");
309 *fRetCode = kFPDNoChange; // default setting
310
313 MapWindow();
315 SetWindowName(Form("Set Parameters of %s", fFunc->GetTitle()));
316
317 for (Int_t i = 0; i < fNP; i++ ) {
318 if (fParFix[i]->GetState() == kButtonDown) {
322 fParSld[i]->UnmapWindow();
323 } else {
324 if (fPmin[i]*fPmax[i] == 0 && fPmin[i] >= fPmax[i]) { //init
325 // round again the values on the percent level
327 Double_t roundVal = int(fPval[i]/ u) * u;
328 // set min at +/- 100 step size
329 fParMin[i]->SetNumber( roundVal - 100* fPstp[i]);
330 fParMax[i]->SetNumber( roundVal + 100* fPstp[i]);
331 // if (!fPval[i]) {
332 // fParMin[i]->SetNumber(-10);
333 // fParMax[i]->SetNumber(10);
334 // } else {
335 // fParMin[i]->SetNumber(-3*TMath::Abs(fPval[i]));
336 // fParMax[i]->SetNumber(3*TMath::Abs(fPval[i]));
337 // }
338 }
339 fParSld[i]->SetRange(fParMin[i]->GetNumber(), fParMax[i]->GetNumber());
340 fParSld[i]->SetPosition(fParMin[i]->GetNumber(), fParMax[i]->GetNumber());
341 fParSld[i]->SetPointerPosition(fParVal[i]->GetNumber());
342 fParSld[i]->Connect("PointerPositionChanged()", "TFitParametersDialog",
343 this, "DoSlider()");
344 fParSld[i]->Connect("PositionChanged()", "TFitParametersDialog",
345 this, "DoSlider()");
346 }
347 }
348
349 gClient->WaitFor(this);
350}
351
352////////////////////////////////////////////////////////////////////////////////
353/// Destructor.
354
356{
359 Cleanup();
360 delete [] fPval;
361 delete [] fPmin;
362 delete [] fPmax;
363 delete [] fPerr;
364 delete [] fPstp;
365
366 delete [] fParNam;
367 delete [] fParFix;
368 delete [] fParBnd;
369 delete [] fParVal;
370 delete [] fParMin;
371 delete [] fParMax;
372 delete [] fParSld;
373 delete [] fParStp;
374 delete [] fParErr;
375}
376
377////////////////////////////////////////////////////////////////////////////////
378/// Close parameters' dialog.
379
381{
382 if (fHasChanges) {
383 Int_t ret;
384 const char *txt;
385 txt = "Do you want to apply last parameters' setting?";
387 "Parameters Have Been Changed", txt, kMBIconExclamation,
388 kMBYes | kMBNo | kMBCancel, &ret);
389 if (ret == kMBYes) {
392 }
393 else if (ret == kMBNo)
394 DoReset();
395 else return;
396 }
397
399 DeleteWindow();
400}
401
402////////////////////////////////////////////////////////////////////////////////
403/// Slot related to the Cancel button.
404
406{
407 if (fHasChanges)
408 DoReset();
409 // for (Int_t i = 0; i < fNP; i++ ) {
410 // if (fParBnd[i]->GetState() == kButtonDown)
411 // *fRetCode = kFPDBounded;
412 // }
413 CloseWindow();
414}
415
416////////////////////////////////////////////////////////////////////////////////
417/// Slot related to the Bound check button.
418
420{
421 TGButton *bt = (TGButton *) gTQSender;
422 Int_t id = bt->WidgetId();
424
425 for (Int_t i = 0; i < fNP; i++ ) {
426 if (id == kBND*fNP+i) {
427 if (on) {
428 if (fParMin[i]->GetNumber() >= fParMax[i]->GetNumber()) {
429 Int_t ret;
430 const char *txt;
431 txt = "'Min' value cannot be bigger or equal to 'Max' - set the limits first!";
433 "Parameter Limits", txt, kMBIconExclamation,kMBOk,&ret);
434
436 return;
437 }
438 if ((fParVal[i]->GetNumber() < fParMin[i]->GetNumber()) ||
439 (fParVal[i]->GetNumber() > fParMax[i]->GetNumber())) {
440 Double_t v = (fParMax[i]->GetNumber()+fParMin[i]->GetNumber())/2.;
441 fParVal[i]->SetNumber(v);
442 fFunc->SetParameter(i, v);
444 }
446 fParMin[i]->GetNumber(),
447 fParMax[i]->GetNumber());
449 fFunc->SetParLimits(i, fParMin[i]->GetNumber(),
450 fParMax[i]->GetNumber());
451 } else {
454 fFunc->GetParLimits(i, fPmin[i], fPmax[i]);
455 fPval[i] = fFunc->GetParameter(i);
456 if (fPmin[i]*fPmax[i] == 0 && fPmin[i] >= fPmax[i]) { //init
457 if (!fPval[i]) {
458 fParMin[i]->SetNumber(-10);
459 fParMax[i]->SetNumber(10);
460 } else {
461 fParMin[i]->SetNumber(-10*TMath::Abs(fPval[i]));
462 fParMax[i]->SetNumber(10*TMath::Abs(fPval[i]));
463 }
464 }
465 fParSld[i]->SetRange(fParMin[i]->GetNumber(), fParMax[i]->GetNumber());
466 fParSld[i]->SetPosition(fParMin[i]->GetNumber(), fParMax[i]->GetNumber());
468 }
469 }
470 }
471 if (fUpdate->GetState() == kButtonDown)
472 DrawFunction();
473 else if ((fApply->GetState() == kButtonDisabled) && fHasChanges)
475}
476
477////////////////////////////////////////////////////////////////////////////////
478/// Slot related to parameter step setting.
479
481{
482}
483
484////////////////////////////////////////////////////////////////////////////////
485/// Slot related to the Fix check button.
486
488{
490
491 TGButton *bt = (TGButton *) gTQSender;
492 Int_t id = bt->WidgetId();
494
495 for (Int_t i = 0; i < fNP; i++ ) {
496 if (id == kFIX*fNP+i) {
497 if (on) {
498 // no bound available
499 fParBnd[i]->Disconnect("Toggled(Bool_t)");
501 fParBnd[i]->SetToolTipText(Form("DISABLED - %s is fixed", fFunc->GetParName(i)));
502 if (fParVal[i]->GetNumber() != 0) {
503 fParMin[i]->SetNumber(fParVal[i]->GetNumber());
505 fParMax[i]->SetNumber(fParVal[i]->GetNumber());
507 } else {
508 fParMin[i]->SetNumber(1.);
510 fParMax[i]->SetNumber(1.);
512 }
515 fParSld[i]->Disconnect("PointerPositionChanged()");
516 fParSld[i]->Disconnect("PositionChanged()");
517 fParSld[i]->UnmapWindow();
518 fFunc->FixParameter(i, fParVal[i]->GetNumber());
519 } else if (!fParMin[i]->IsEnabled()) {
520 if (fPmin[i] != fPmax[i]) {
521 if (fPmin[i])
522 fParMin[i]->SetNumber(fPmin[i]);
523 else if (fPerr[i])
524 fParMin[i]->SetNumber(fPval[i]-3*fPerr[i]);
525 else if (fPval[i])
526 fParMin[i]->SetNumber(fPval[i]-0.1*fPval[i]);
527 else
528 fParMin[i]->SetNumber(1.0);
529 if (fPmax[i])
530 fParMax[i]->SetNumber(fPmax[i]);
531 else if (fPerr[i])
532 fParMax[i]->SetNumber(fPval[i]+3*fPerr[i]);
533 else if (fPval[i])
534 fParMax[i]->SetNumber(fPval[i]+0.1*fPval[i]);
535 else
536 fParMax[i]->SetNumber(1.0);
537 } else if (fPval[i]) {
538 fParMin[i]->SetNumber(fPval[i]-0.1*fPval[i]);
539 fParMax[i]->SetNumber(fPval[i]+0.1*fPval[i]);
540 } else {
541 fParMin[i]->SetNumber(1.0);
542 fParMax[i]->SetNumber(1.0);
543 }
544 if (fParMax[i]->GetNumber() < fParMin[i]->GetNumber()){
545 Double_t temp;
546 temp = fParMax[i]->GetNumber();
547 fParMax[i]->SetNumber(fParMin[i]->GetNumber());
548 fParMin[i]->SetNumber(temp);
549 }
551 fParBnd[i]->Connect("Toggled(Bool_t)", "TFitParametersDialog",
552 this, "DoParBound(Bool_t)");
556 fParSld[i]->MapWindow();
559 fParSld[i]->SetRange(fParMin[i]->GetNumber(), fParMax[i]->GetNumber());
560 fParSld[i]->SetPosition(fParMin[i]->GetNumber(), fParMax[i]->GetNumber());
562 fParSld[i]->Connect("PointerPositionChanged()", "TFitParametersDialog",
563 this, "DoSlider()");
564 fParSld[i]->Connect("PositionChanged()", "TFitParametersDialog",
565 this, "DoSlider()");
566 fFunc->SetParLimits(i, fParMin[i]->GetNumber(), fParMax[i]->GetNumber());
567 }
568 }
569 }
570 if (fUpdate->GetState() == kButtonDown)
571 DrawFunction();
572 else if ((fApply->GetState() == kButtonDisabled) && fHasChanges)
574}
575
576////////////////////////////////////////////////////////////////////////////////
577/// Set the parameter values inside the function
578
580{
582 for (Int_t i = 0; i < fNP; i++ ) {
583 // first make sure the current value is up to date
585 if (fParFix[i]->GetState() == kButtonDown) {
586 fFunc->SetParameter(i, fParVal[i]->GetNumber());
587 fFunc->FixParameter(i, fParVal[i]->GetNumber());
589 } else {
590 if (fParBnd[i]->GetState() == kButtonDown) {
591 fFunc->SetParameter(i, fParVal[i]->GetNumber());
592 fFunc->SetParLimits(i, fParMin[i]->GetNumber(), fParMax[i]->GetNumber());
594 } else {
596 }
597 }
598 }
599}
600
601////////////////////////////////////////////////////////////////////////////////
602/// Slot related to the OK button.
603
605{
606 if (fHasChanges)
607 DrawFunction();
608
610
611 // we want here to confirm the parameters settings so
612 // it is like having changed them
614
615
616 CloseWindow();
617}
618
619////////////////////////////////////////////////////////////////////////////////
620/// Slot related to the Preview button.
621
623{
624 DrawFunction();
628}
629
630////////////////////////////////////////////////////////////////////////////////
631/// Slot related to the Reset button.
632
634{
636 Int_t k = fNP;
637 for (Int_t i = 0; i < fNP; i++) {
638 if (fParVal[i]->GetNumber() == fPval[i])
639 k--;
640 else
641 break;
642 }
643
644 if (!k) {
645 if (fReset->GetState() == kButtonUp)
648 return;
649 }
650 for (Int_t i = 0; i < fNP; i++) {
651 fFunc->SetParameter(i, fPval[i]);
652 fFunc->SetParLimits(i, fPmin[i], fPmax[i]);
653 fFunc->SetParError(i, fPerr[i]);
654
655 if (fPmin[i])
656 fParMin[i]->SetNumber(fPmin[i]);
657 else if (fPerr[i])
658 fParMin[i]->SetNumber(fPval[i]-3*fPerr[i]);
659 else if (fPval[i])
660 fParMin[i]->SetNumber(-3*TMath::Abs(fPval[i]));
661 else
662 fParMin[i]->SetNumber(1.0);
663
664 if (fPmax[i])
665 fParMax[i]->SetNumber(fPmax[i]);
666 else if (fPerr[i])
667 fParMax[i]->SetNumber(fPval[i]+3*fPerr[i]);
668 else if (fPval[i])
670 else
671 fParMax[i]->SetNumber(1.0);
672 if (fParMax[i]->GetNumber() < fParMin[i]->GetNumber()){
673 Double_t temp;
674 temp = fParMax[i]->GetNumber();
675 fParMax[i]->SetNumber(fParMin[i]->GetNumber());
676 fParMin[i]->SetNumber(temp);
677 }
678 if (fParMin[i]->GetNumber() == fParMax[i]->GetNumber()) {
683 fParSld[i]->Disconnect("PointerPositionChanged()");
684 fParSld[i]->Disconnect("PositionChanged()");
685 fParSld[i]->UnmapWindow();
686 fParBnd[i]->Disconnect("Toggled(Bool_t)");
688 fFunc->FixParameter(i, fParVal[i]->GetNumber());
690 } else {
692 if (!fParMax[i]->IsEnabled()) {
697 fParSld[i]->SetRange(fParMin[i]->GetNumber(), fParMax[i]->GetNumber());
698 fParSld[i]->SetPosition(fParMin[i]->GetNumber(), fParMax[i]->GetNumber());
700 fParSld[i]->MapWindow();
701 fParSld[i]->Connect("PointerPositionChanged()", "TFitParametersDialog",
702 this, "DoSlider()");
703 fParSld[i]->Connect("PositionChanged()", "TFitParametersDialog",
704 this, "DoSlider()");
706 fParBnd[i]->Connect("Toggled(Bool_t)", "TFitParametersDialog",
707 this, "DoParBound(Bool_t)");
708 }
709 }
710 fParVal[i]->SetNumber(fPval[i]);
711
712 fParSld[i]->SetRange(fParMin[i]->GetNumber(), fParMax[i]->GetNumber());
713 fParSld[i]->SetPosition(fParMin[i]->GetNumber(), fParMax[i]->GetNumber());
715 }
716
717 if (fUpdate->GetState() == kButtonDown)
718 DrawFunction();
719 else if ((fApply->GetState() == kButtonDisabled) && fHasChanges)
724}
725
726////////////////////////////////////////////////////////////////////////////////
727/// Slot related to the parameters' value settings.
728
730{
732 Int_t id = sl->WidgetId();
733
735 for (Int_t i = 0; i < fNP; i++ ) {
736 if (id == kSLD*fNP+i) {
737 fFunc->SetParameter(i,fParSld[i]->GetPointerPosition());
738 fFunc->SetParLimits(i,fParSld[i]->GetMinPosition(),
739 fParSld[i]->GetMaxPosition());
740 fParMin[i]->SetNumber(fParSld[i]->GetMinPosition());
741 fParMax[i]->SetNumber(fParSld[i]->GetMaxPosition());
742 fParVal[i]->SetNumber(fParSld[i]->GetPointerPosition());
743 }
744 }
745 if (fUpdate->GetState() == kButtonDown)
746 DrawFunction();
747 else if ((fApply->GetState() == kButtonDisabled) && fHasChanges)
751}
752
753////////////////////////////////////////////////////////////////////////////////
754/// Slot related to the parameter value settings.
755
757{
759 Int_t id = ne->WidgetId();
760
761 for (Int_t i = 0; i < fNP; i++ ) {
762 if (id == kVAL*fNP+i) {
763 if (fParVal[i]->GetNumber() < fParMin[i]->GetNumber()) {
764 Double_t extraIncrement = (fParMax[i]->GetNumber() - fParMin[i]->GetNumber()) / 4;
765 fParMin[i]->SetNumber(fParVal[i]->GetNumber() - extraIncrement );
767 fParSld[i]->SetRange(fParMin[i]->GetNumber(),
768 fParMax[i]->GetNumber());
769 fParSld[i]->SetPosition(fParMin[i]->GetNumber(),
770 fParMax[i]->GetNumber());
771 }
772 if (fParVal[i]->GetNumber() > fParMax[i]->GetNumber()) {
773 Double_t extraIncrement = (fParMax[i]->GetNumber() - fParMin[i]->GetNumber()) / 4;
774 fParMax[i]->SetNumber(fParVal[i]->GetNumber() + extraIncrement );
776 fParSld[i]->SetRange(fParMin[i]->GetNumber(),
777 fParMax[i]->GetNumber());
778 fParSld[i]->SetPosition(fParMin[i]->GetNumber(),
779 fParMax[i]->GetNumber());
780 }
781 fParSld[i]->SetPointerPosition(fParVal[i]->GetNumber());
783 fFunc->SetParameter(i,fParSld[i]->GetPointerPosition());
784 if (fParBnd[i]->GetState() == kButtonDown)
786 fParSld[i]->GetMaxPosition());
787 else
789 }
790 }
792 if (fUpdate->GetState() == kButtonDown)
793 DrawFunction();
794 else if ((fApply->GetState() == kButtonDisabled) && fHasChanges)
798}
799
800////////////////////////////////////////////////////////////////////////////////
801/// Slot related to the minumum parameter limit settings.
802
804{
806 Int_t id = ne->WidgetId();
807
808 for (Int_t i = 0; i < fNP; i++ ) {
809 if (id == kMIN*fNP+i) {
810 if ((fParMin[i]->GetNumber() >= fParMax[i]->GetNumber()) &&
811 (fParBnd[i]->GetState() == kButtonDown)) {
812 Int_t ret;
813 const char *txt;
814 txt = "'Min' cannot be bigger then 'Max' if this parameter is bounded.";
816 "Parameter Limits", txt, kMBIconExclamation, kMBOk, &ret);
817 fParMin[i]->SetNumber(fParVal[i]->GetNumber()-fParStp[i]->GetNumber());
818 return;
819 }
820 if (fParBnd[i]->GetState() == kButtonDown) {
821 Double_t val = (fParMax[i]->GetNumber()+fParMin[i]->GetNumber())/2.;
822 fParVal[i]->SetNumber(val);
823 fParVal[i]->SetLimitValues(fParMin[i]->GetNumber(),
824 fParMax[i]->GetNumber());
825 }
826 fParSld[i]->SetRange(fParMin[i]->GetNumber(),
827 fParMax[i]->GetNumber());
828 fParSld[i]->SetPosition(fParMin[i]->GetNumber(),
829 fParMax[i]->GetNumber());
830 fParSld[i]->SetPointerPosition(fParVal[i]->GetNumber());
832 }
833 }
835 if (fUpdate->GetState() == kButtonDown)
836 DrawFunction();
837 else if ((fApply->GetState() == kButtonDisabled) && fHasChanges)
841}
842
843////////////////////////////////////////////////////////////////////////////////
844/// Slot related to the maximum parameter limit settings.
845
847{
849 Int_t id = ne->WidgetId();
850
851 for (Int_t i = 0; i < fNP; i++ ) {
852 if (id == kMAX*fNP+i) {
853 if ((fParMin[i]->GetNumber() >= fParMax[i]->GetNumber()) &&
854 (fParBnd[i]->GetState() == kButtonDown)) {
855 Int_t ret;
856 const char *txt;
857 txt = "'Min' cannot be bigger then 'Max' if this parameter is bounded.";
859 "Parameter Limits", txt, kMBIconExclamation, kMBOk, &ret);
860 fParMax[i]->SetNumber(fParVal[i]->GetNumber()+fParStp[i]->GetNumber());
861 return;
862 }
863 if (fParBnd[i]->GetState() == kButtonDown) {
864 Double_t val = (fParMax[i]->GetNumber()+(fParMin[i]->GetNumber()))/2.;
865 fParVal[i]->SetNumber(val);
866 fParVal[i]->SetLimitValues(fParMin[i]->GetNumber(),
867 fParMax[i]->GetNumber());
868 }
869 fParSld[i]->SetRange(fParMin[i]->GetNumber(),
870 fParMax[i]->GetNumber());
871 fParSld[i]->SetPosition(fParMin[i]->GetNumber(),
872 fParMax[i]->GetNumber());
873 fParSld[i]->SetPointerPosition(fParVal[i]->GetNumber());
875 }
876 }
878 if (fUpdate->GetState() == kButtonDown)
879 DrawFunction();
880 else if ((fApply->GetState() == kButtonDisabled) && fHasChanges)
884}
885
886////////////////////////////////////////////////////////////////////////////////
887/// Redraw function graphics.
888
890{
891 if ( !fFpad ) return;
892 TVirtualPad *save = 0;
893 save = gPad;
894 gPad = fFpad;
895 gPad->cd();
896
897 Style_t st = fFunc->GetLineStyle();
899
900 TString opt = fFunc->GetDrawOption();
901 opt.ToUpper();
902 if (!opt.Contains("SAME"))
903 opt += "SAME";
904 //fFunc->SetRange(fRXmin, fRXmax);
905 fFunc->Draw(opt);
906 gPad->Modified();
907 gPad->Update();
909
910 fFunc->SetLineStyle(st);
911 if (save) gPad = save;
913}
914
915////////////////////////////////////////////////////////////////////////////////
916/// Handle the button dependent states in this dialog.
917
919{
920 if (update && fHasChanges)
921 DrawFunction();
922 else if ((fApply->GetState() == kButtonDisabled) && fHasChanges) {
924 }
925}
926
927////////////////////////////////////////////////////////////////////////////////
928/// Disconnect signals from slot methods.
929
931{
932 for (Int_t i = 0; i < fNP; i++ ) {
933 fParFix[i]->Disconnect("Toggled(Bool_t)");
934 fParBnd[i]->Disconnect("Toggled(Bool_t)");
935 fParVal[i]->Disconnect("ValueSet(Long_t)");
936 fParMin[i]->Disconnect("ReturnPressed()");
937 fParMax[i]->Disconnect("ReturnPressed()");
938 fParSld[i]->Disconnect("PointerPositionChanged()");
939 fParSld[i]->Disconnect("PositionChanged()");
940 fParStp[i]->Disconnect("ValueSet(Long_t)");
941 fParVal[i]->Disconnect("TabPressed(Long_t)");
942 fParVal[i]->Disconnect("ShiftTabPressed(Long_t)");
943 fParMin[i]->Disconnect("TabPressed(Long_t)");
944 fParMin[i]->Disconnect("ShiftTabPressed(Long_t)");
945 fParMax[i]->Disconnect("TabPressed(Long_t)");
946 fParMax[i]->Disconnect("ShiftTabPressed(Long_t)");
947 fParStp[i]->Disconnect("TabPressed(Long_t)");
948 fParStp[i]->Disconnect("ShiftTabPressed(Long_t)");
949 }
950 fUpdate->Disconnect("Toggled(Bool_t)");
951 fReset->Disconnect("Clicked()");
952 fApply->Disconnect("Clicked()");
953 fOK->Disconnect("Clicked()");
954 fCancel->Disconnect("Clicked()");
955}
956
957////////////////////////////////////////////////////////////////////////////////
958/// Handle Shift+Tab key event (set focus to the previous number entry field)
959
961{
963 next = (TGNumberEntryField *)fTextEntries.Before((TObject *)sender);
964 if (next == 0)
966 if (next) {
967 next->SetFocus();
968 next->Home();
969 }
970}
971
972////////////////////////////////////////////////////////////////////////////////
973/// Handle Tab key event (set focus to the next number entry field)
974
976{
978 next = (TGNumberEntryField *)fTextEntries.After((TObject *)sender);
979 if (next == 0)
981 if (next) {
982 next->SetFocus();
983 next->Home();
984 }
985}
986
987
988
@ kVerticalFrame
Definition GuiTypes.h:381
@ kFixedWidth
Definition GuiTypes.h:387
@ kHorizontalFrame
Definition GuiTypes.h:382
static void update(gsl_integration_workspace *workspace, double a1, double b1, double area1, double error1, double a2, double b2, double area2, double error2)
const Bool_t kFALSE
Definition RtypesCore.h:92
double Double_t
Definition RtypesCore.h:59
short Style_t
Definition RtypesCore.h:80
const Bool_t kTRUE
Definition RtypesCore.h:91
#define ClassImp(name)
Definition Rtypes.h:364
@ kFPDNoChange
@ kFPDBounded
@ kButtonDown
Definition TGButton.h:54
@ kButtonDisabled
Definition TGButton.h:56
@ kButtonUp
Definition TGButton.h:53
#define gClient
Definition TGClient.h:166
@ kDoubleScaleBoth
@ kDeepCleanup
Definition TGFrame.h:50
@ kLHintsRight
Definition TGLayout.h:33
@ kLHintsLeft
Definition TGLayout.h:31
@ kLHintsCenterY
Definition TGLayout.h:35
@ kLHintsTop
Definition TGLayout.h:34
@ kLHintsExpandX
Definition TGLayout.h:37
@ kMBNo
Definition TGMsgBox.h:39
@ kMBYes
Definition TGMsgBox.h:38
@ kMBCancel
Definition TGMsgBox.h:44
@ kMBOk
Definition TGMsgBox.h:40
@ kMBIconExclamation
Definition TGMsgBox.h:31
R__EXTERN void * gTQSender
Definition TQObject.h:46
char * Form(const char *fmt,...)
#define gPad
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition TAttLine.h:42
virtual Style_t GetLineStyle() const
Return the line style.
Definition TAttLine.h:34
1-Dim function class
Definition TF1.h:213
virtual void ReleaseParameter(Int_t ipar)
Release parameter number ipar If used in a fit, the parameter can vary freely.
Definition TF1.cxx:3137
virtual void SetParError(Int_t ipar, Double_t error)
Set error for parameter number ipar.
Definition TF1.cxx:3486
virtual void GetParLimits(Int_t ipar, Double_t &parmin, Double_t &parmax) const
Return limits for parameter ipar.
Definition TF1.cxx:1930
virtual Double_t GetParError(Int_t ipar) const
Return value of parameter number ipar.
Definition TF1.cxx:1920
virtual void SetRange(Double_t xmin, Double_t xmax)
Initialize the upper and lower bounds to draw the function.
Definition TF1.cxx:3532
virtual Int_t GetNpar() const
Definition TF1.h:481
virtual void GetRange(Double_t *xmin, Double_t *xmax) const
Return range of a generic N-D function.
Definition TF1.cxx:2269
virtual const char * GetParName(Int_t ipar) const
Definition TF1.h:529
virtual void SetParLimits(Int_t ipar, Double_t parmin, Double_t parmax)
Set limits for parameter ipar.
Definition TF1.cxx:3511
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
Definition TF1.cxx:1322
virtual void SetParameter(Int_t param, Double_t value)
Definition TF1.h:634
virtual void FixParameter(Int_t ipar, Double_t value)
Fix the value of a parameter The specified value will be used in a fit operation.
Definition TF1.cxx:1547
virtual Double_t GetParameter(Int_t ipar) const
Definition TF1.h:512
TGCompositeFrame * fContMin
virtual void DoReset()
Slot related to the Reset button.
TFitParametersDialog(const TGWindow *p, const TGWindow *main, TF1 *func, TVirtualPad *pad, Int_t *ret_code=0)
virtual void DoSlider()
Slot related to the parameters' value settings.
TGCompositeFrame * fContVal
virtual void CloseWindow()
Close parameters' dialog.
virtual void HandleTab()
Handle Tab key event (set focus to the next number entry field)
virtual void HandleShiftTab()
Handle Shift+Tab key event (set focus to the previous number entry field)
TGNumberEntryField ** fParErr
virtual ~TFitParametersDialog()
Destructor.
TGCompositeFrame * fContStp
void DisconnectSlots()
Disconnect signals from slot methods.
TGCompositeFrame * fContNam
void SetParameters()
Set the parameter values inside the function.
virtual void DoParStep()
Slot related to parameter step setting.
TGTripleHSlider ** fParSld
TGCompositeFrame * fContErr
TGCompositeFrame * fContBnd
virtual void DoApply()
Slot related to the Preview button.
TGNumberEntryField ** fParMax
virtual void DoCancel()
Slot related to the Cancel button.
virtual void DoParValue()
Slot related to the parameter value settings.
virtual void DoParFix(Bool_t on)
Slot related to the Fix check button.
virtual void HandleButtons(Bool_t update)
Handle the button dependent states in this dialog.
TGNumberEntryField ** fParMin
virtual void DoOK()
Slot related to the OK button.
virtual void DoParBound(Bool_t on)
Slot related to the Bound check button.
TGCompositeFrame * fContFix
virtual void DoParMinLimit()
Slot related to the minumum parameter limit settings.
virtual void DrawFunction()
Redraw function graphics.
TGCompositeFrame * fContMax
virtual void DoParMaxLimit()
Slot related to the maximum parameter limit settings.
TGCompositeFrame * fContSld
virtual void SetToolTipText(const char *text, Long_t delayms=400)
Set tool tip text associated with this button.
Definition TGButton.cxx:398
virtual EButtonState GetState() const
Definition TGButton.h:112
virtual void SetEnabled(Bool_t e=kTRUE)
Set enabled or disabled state of button.
Definition TGButton.cxx:412
virtual void SetState(EButtonState state, Bool_t emit=kFALSE)
Set button state.
Definition TGButton.cxx:188
virtual void SetState(EButtonState state, Bool_t emit=kFALSE)
Set check button state.
const TGWindow * GetRoot() const
Returns current root (i.e.
Definition TGClient.cxx:223
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition TGClient.cxx:371
Int_t GetState(TGFrame *f) const
Get state of sub frame.
Definition TGFrame.cxx:1203
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1102
virtual void Cleanup()
Cleanup and delete all objects contained in this composite frame.
Definition TGFrame.cxx:952
virtual void SetCleanup(Int_t mode=kLocalCleanup)
Turn on automatic cleanup of child frames in dtor.
Definition TGFrame.cxx:1057
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
Definition TGFrame.h:352
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition TGFrame.cxx:1149
virtual Float_t GetMaxPosition() const
virtual Float_t GetMinPosition() const
virtual void SetRange(Float_t min, Float_t max)
virtual void SetPosition(Float_t min, Float_t max)
static Pixel_t GetDefaultFrameBackground()
Get default frame background.
Definition TGFrame.cxx:668
virtual void DeleteWindow()
Delete window.
Definition TGFrame.cxx:261
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition TGFrame.cxx:590
virtual void MapWindow()
map window
Definition TGFrame.h:228
virtual void UnmapWindow()
unmap window
Definition TGFrame.h:230
void SetWindowName(const char *name=0)
Set window name. This is typically done via the window manager.
Definition TGFrame.cxx:1749
virtual Double_t GetNumber() const
Get the numeric value (floating point representation).
virtual void ReturnPressed()
Return was pressed.
virtual void SetNumber(Double_t val)
Set the numeric value (floating point representation).
virtual void SetNumber(Double_t val)
TGNumberEntryField * GetNumberEntry() const
virtual void SetLimits(ELimit limits=TGNumberFormat::kNELNoLimits, Double_t min=0, Double_t max=1)
virtual void SetState(Bool_t enable=kTRUE)
Set the active state.
void SetLimitValues(Double_t min=0, Double_t max=1)
virtual void SetFormat(EStyle style, EAttribute attr=TGNumberFormat::kNEAAnyNumber)
TGClient * fClient
Definition TGObject.h:37
virtual void SetFocus()
Set focus to this text entry.
void SetEnabled(Bool_t flag=kTRUE)
virtual void SetText(const char *text, Bool_t emit=kTRUE)
Sets text entry to text, clears the selection and moves the cursor to the end of the line.
void Home(Bool_t mark=kFALSE)
Moves the text cursor to the left end of the line.
virtual void CenterOnParent(Bool_t croot=kTRUE, EPlacement pos=kCenter)
Position transient frame centered relative to the parent frame.
Definition TGFrame.cxx:1916
virtual void SetPointerPosition(Double_t pos)
Set pointer position in scaled (real) value.
virtual void SetConstrained(Bool_t on=kTRUE)
Set pointer position constrained in the slider range.
Int_t WidgetId() const
Definition TGWidget.h:78
virtual const TGWindow * GetMainFrame() const
Returns top level main frame.
Definition TGWindow.cxx:151
virtual void Add(TObject *obj)
Definition TList.h:87
virtual TObject * After(const TObject *obj) const
Returns the object after object obj.
Definition TList.cxx:330
virtual TObject * Last() const
Return the last object in the list. Returns 0 when list is empty.
Definition TList.cxx:693
virtual TObject * Before(const TObject *obj) const
Returns the object before object obj.
Definition TList.cxx:371
virtual TObject * First() const
Return the first object in the list. Returns 0 when list is empty.
Definition TList.cxx:659
virtual void Clear(Option_t *option="")
Remove all objects from the list.
Definition TList.cxx:402
virtual const char * GetTitle() const
Returns title of object.
Definition TNamed.h:48
Mother of all ROOT objects.
Definition TObject.h:37
virtual Option_t * GetDrawOption() const
Get option used by the graphics system to draw this object.
Definition TObject.cxx:343
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot.
Definition TQObject.cxx:866
Bool_t Disconnect(const char *signal=0, void *receiver=0, const char *slot=0)
Disconnects signal of this object from slot of receiver.
Basic string class.
Definition TString.h:136
void ToUpper()
Change string to upper case.
Definition TString.cxx:1158
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:624
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51
virtual TVirtualPad * cd(Int_t subpadnumber=0)=0
int main()
TF1 * f1
Definition legend1.C:11
Double_t Floor(Double_t x)
Definition TMath.h:703
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Definition TMath.h:735
Double_t Log10(Double_t x)
Definition TMath.h:764
Short_t Abs(Short_t d)
Definition TMathBase.h:120