Logo ROOT  
Reference Guide
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 "TGFrame.h"
24#include "TGLabel.h"
25#include "TGLayout.h"
26#include "TGTextEntry.h"
27#include "TGMsgBox.h"
28#include "TGNumberEntry.h"
29#include "TGTripleSlider.h"
30#include "TVirtualPad.h"
31#include "TMath.h"
32
33#include <limits>
34
35
38 kFIX = 10,
39 kBND = 20,
40 kVAL = 30,
41 kMIN = 40,
42 kMAX = 50,
43 kSLD = 60,
44 kSTP = 70,
45 kERR = 80,
46 kUPDATE = 8888,
51};
52
54
55////////////////////////////////////////////////////////////////////////////////
56
58 const TGWindow *main,
59 TF1 *func,
60 TVirtualPad *pad,
61 Int_t *ret_code) :
63 fFunc (func),
64 fFpad (pad),
65 fHasChanges (kFALSE),
66 fImmediateDraw (kTRUE),
67 fRetCode (ret_code)
68
69{
70 // Create a dialog for fit function parameters' settings.
71
73
75 fNP = fFunc->GetNpar();
76 fPmin = new Double_t[fNP];
77 fPmax = new Double_t[fNP];
78 fPval = new Double_t[fNP];
79 fPerr = new Double_t[fNP];
80 fPstp = new Double_t[fNP];
81
82 for (Int_t i = 0; i < fNP; i++) {
83 fFunc->GetParLimits(i, fPmin[i], fPmax[i]);
84 fPval[i] = fFunc->GetParameter(i);
85 fPerr[i] = fFunc->GetParError(i);
86 if (fPerr[i] > 1E-16)
88 else {
89 if (TMath::Abs(fPval[i]) > 1.)
90 // if error is zero use as step approx 10% of current value
92 else
93 fPstp[i] = 0.1;
94 }
95 }
96 fParNam = new TGTextEntry*[fNP];
103 fParStp = new TGNumberEntry*[fNP];
105
106 memset(fParNam, 0, sizeof(TGTextEntry*)*fNP);
107 memset(fParFix, 0, sizeof(TGCheckButton*)*fNP);
108 memset(fParBnd, 0, sizeof(TGCheckButton*)*fNP);
109 memset(fParVal, 0, sizeof(TGNumberEntry*)*fNP);
110 memset(fParMin, 0, sizeof(TGNumberEntryField*)*fNP);
111 memset(fParMax, 0, sizeof(TGNumberEntryField*)*fNP);
112 memset(fParSld, 0, sizeof(TGTripleHSlider*)*fNP);
113 memset(fParStp, 0, sizeof(TGNumberEntry*)*fNP);
114 memset(fParErr, 0, sizeof(TGNumberEntryField*)*fNP);
115
117 AddFrame(f1, new TGLayoutHints(kLHintsTop, 1, 1, 1, 1));
118
119 // column 'Name'
121 fContNam->AddFrame(new TGLabel(fContNam,"Name"),
122 new TGLayoutHints(kLHintsTop, 5, 0, 0, 0));
123 for (Int_t i = 0; i < fNP; i++ ) {
124 fParNam[i] = new TGTextEntry(fContNam, new TGTextBuffer(80), kNAME+i);
125 fParNam[i]->SetText(Form("%s", fFunc->GetParName(i)));
128 new TGLayoutHints(kLHintsExpandX, 2, 2, 7, 5));
129 }
130 f1->AddFrame(fContNam, new TGLayoutHints(kLHintsLeft, 1, 1, 2, 2));
131
132 // column 'Fix'
134 fContFix->AddFrame(new TGLabel(fContFix,"Fix"),
135 new TGLayoutHints(kLHintsTop, 2, 0, 0, 0));
136 for (Int_t i = 0; i < fNP; i++ ) {
137 fParFix[i] = new TGCheckButton(fContFix, "", kFIX*fNP+i);
138 fParFix[i]->SetToolTipText(Form("Set %s to fixed", fFunc->GetParName(i)));
140 5, 5, 10, 7));
141 if ((fPmin[i] == fPmax[i]) && (fPmin[i] || fPmax[i]))
143 else
145 fParFix[i]->Connect("Toggled(Bool_t)", "TFitParametersDialog", this, "DoParFix(Bool_t)");
146 }
147 f1->AddFrame(fContFix, new TGLayoutHints(kLHintsLeft, 1, 1, 2, 2));
148
149 // column 'Bound'
151 fContBnd->AddFrame(new TGLabel(fContBnd,"Bound"),
152 new TGLayoutHints(kLHintsTop, 2, 0, 0, 0));
153 for (Int_t i = 0; i < fNP; i++ ) {
154 fParBnd[i] = new TGCheckButton(fContBnd, "", kBND*fNP+i);
155 fParBnd[i]->SetToolTipText(Form("Set bound to %s", fFunc->GetParName(i)));
157 15, 5, 10, 7));
158 fParBnd[i]->Connect("Toggled(Bool_t)", "TFitParametersDialog", this, "DoParBound(Bool_t)");
159 if ( ((fPmin[i] != fPmax[i]) && (fPmin[i] || fPmax[i])) || (fParMin[i] < fParMax[i]) )
161 else
163 }
164 f1->AddFrame(fContBnd, new TGLayoutHints(kLHintsLeft, 1, 1, 2, 2));
165
166 // column 'Value'
168 fContVal->AddFrame(new TGLabel(fContVal,"Value"),
169 new TGLayoutHints(kLHintsTop, 5, 0, 0, 0));
170 for (Int_t i = 0; i < fNP; i++ ) {
171 fParVal[i] = new TGNumberEntry(fContVal, 1.2E-12, 15, kVAL*fNP+i,
173 fParVal[i]->SetNumber(fPval[i]);
176 (fParVal[i]->GetNumberEntry())->SetToolTipText(Form("%s", fFunc->GetParName(i)));
177 (fParVal[i]->GetNumberEntry())->Connect("ReturnPressed()", "TFitParametersDialog",
178 this, "DoParValue()");
179 fParVal[i]->Connect("ValueSet(Long_t)", "TFitParametersDialog", this, "DoParValue()");
180 (fParVal[i]->GetNumberEntry())->Connect("TabPressed()", "TFitParametersDialog", this, "HandleTab()");
181 (fParVal[i]->GetNumberEntry())->Connect("ShiftTabPressed()", "TFitParametersDialog", this, "HandleShiftTab()");
182 fTextEntries.Add(fParVal[i]->GetNumberEntry());
183 }
184 f1->AddFrame(fContVal, new TGLayoutHints(kLHintsLeft, 1, 1, 2, 2));
185
186 // column 'Min'
188 fContMin->AddFrame(new TGLabel(fContMin,"Min"),
189 new TGLayoutHints(kLHintsTop, 5, 0, 0, 0));
190 for (Int_t i = 0; i < fNP; i++ ) {
191 fParMin[i] = new TGNumberEntryField(fContMin, kMIN*fNP+i, 0.0,
194 ((TGTextEntry*)fParMin[i])->SetToolTipText(Form("Lower limit of %s",
195 fFunc->GetParName(i)));
197 fParMin[i]->SetNumber(fPmin[i]);
198 fParMin[i]->Connect("ReturnPressed()", "TFitParametersDialog", this,
199 "DoParMinLimit()");
200 fParMin[i]->Connect("TabPressed()", "TFitParametersDialog", this, "HandleTab()");
201 fParMin[i]->Connect("ShiftTabPressed()", "TFitParametersDialog", this, "HandleShiftTab()");
203 }
204 f1->AddFrame(fContMin, new TGLayoutHints(kLHintsLeft, 1, 1, 2, 2));
205
206 // column 'Set Range'
208 fContSld->AddFrame(new TGLabel(fContSld,"Set Range"),
209 new TGLayoutHints(kLHintsTop, 5, 0, 0, 0));
210 for (Int_t i = 0; i < fNP; i++ ) {
216 }
217 f1->AddFrame(fContSld, new TGLayoutHints(kLHintsLeft, 1, 1, 2, 2));
218
219 // column 'Max'
221 fContMax->AddFrame(new TGLabel(fContMax,"Max"),
222 new TGLayoutHints(kLHintsTop, 5, 0, 0, 0));
223 for (Int_t i = 0; i < fNP; i++ ) {
224 fParMax[i] = new TGNumberEntryField(fContMax, kMAX*fNP+i, 0.0,
227 ((TGTextEntry*)fParMax[i])->SetToolTipText(Form("Upper limit of %s",
228 fFunc->GetParName(i)));
230 fParMax[i]->SetNumber(fPmax[i]);
231 fParMax[i]->Connect("ReturnPressed()", "TFitParametersDialog", this, "DoParMaxLimit()");
232 fParMax[i]->Connect("TabPressed()", "TFitParametersDialog", this, "HandleTab()");
233 fParMax[i]->Connect("ShiftTabPressed()", "TFitParametersDialog", this, "HandleShiftTab()");
235 }
236 f1->AddFrame(fContMax, new TGLayoutHints(kLHintsLeft, 1, 1, 2, 2));
237
238 // column 'Step'
240 fContStp->AddFrame(new TGLabel(fContStp,"Step"),
241 new TGLayoutHints(kLHintsTop, 5, 0, 0, 0));
242 for (Int_t i = 0; i < fNP; i++ ) {
243 fParStp[i] = new TGNumberEntry(fContStp, 1.2E-12, 15, kSTP*fNP+i,
245 fParStp[i]->SetNumber(fPstp[i]);
248 (fParStp[i]->GetNumberEntry())->SetToolTipText(Form("%s", fFunc->GetParName(i)));
249 (fParStp[i]->GetNumberEntry())->Connect("ReturnPressed()", "TFitParametersDialog",
250 this, "DoParStep()");
251 fParStp[i]->Connect("ValueSet(Long_t)", "TFitParametersDialog", this, "DoParStep()");
252 (fParStp[i]->GetNumberEntry())->Connect("TabPressed()", "TFitParametersDialog", this, "HandleTab()");
253 (fParStp[i]->GetNumberEntry())->Connect("ShiftTabPressed()", "TFitParametersDialog", this, "HandleShiftTab()");
254 fTextEntries.Add(fParStp[i]->GetNumberEntry());
255 }
256 f1->AddFrame(fContStp, new TGLayoutHints(kLHintsLeft, 1, 1, 2, 2));
257
258 // column 'Error'
260 fContErr->AddFrame(new TGLabel(fContErr,"Errors"),
261 new TGLayoutHints(kLHintsTop, 5, 0, 0, 0));
262 for (Int_t i = 0; i < fNP; i++ ) {
263 fParErr[i] = new TGNumberEntryField(fContErr, kERR*fNP+i, 0.0,
266 ((TGTextEntry*)fParErr[i])->SetToolTipText(Form("Error of %s",
267 fFunc->GetParName(i)));
270 if (fPerr[i])
271 fParErr[i]->SetNumber(fPerr[i]);
272 else
273 ((TGTextEntry *)fParErr[i])->SetText("-");
274 }
275 f1->AddFrame(fContErr, new TGLayoutHints(kLHintsLeft, 1, 1, 2, 2));
276
277 TGCompositeFrame *f2 = new TGCompositeFrame(this, 270, 20, kHorizontalFrame);
279
280 fUpdate = new TGCheckButton(f2, "&Immediate preview", kUPDATE);
281 fUpdate->SetToolTipText("Immediate function redrawing");
284 fUpdate->Connect("Toggled(Bool_t)", "TFitParametersDialog", this, "HandleButtons(Bool_t)");
285
287 f2->AddFrame(f3, new TGLayoutHints(kLHintsRight));
288
289 fReset = new TGTextButton(f3, "&Reset", kRESET);
291 fReset->SetToolTipText("Reset the parameter settings");
293 fReset->Connect("Clicked()", "TFitParametersDialog", this, "DoReset()");
294
295 fApply = new TGTextButton(f3, "&Apply", kAPPLY);
298 fApply->Connect("Clicked()", "TFitParametersDialog", this, "DoApply()");
299 fApply->SetToolTipText("Apply parameter settings and redraw the function");
300
301 fOK = new TGTextButton(f3, "&OK", kOK);
303 fOK->SetToolTipText("Apply parameter settings, redraw function and close this dialog");
304 fOK->Connect("Clicked()", "TFitParametersDialog", this, "DoOK()");
305
306 fCancel = new TGTextButton(f3, "&Cancel", kCANCEL);
308 fCancel->SetToolTipText("Close this dialog with no parameter changes");
309 fCancel->Connect("Clicked()", "TFitParametersDialog", this, "DoCancel()");
310 *fRetCode = kFPDNoChange; // default setting
311
314 MapWindow();
316 SetWindowName(Form("Set Parameters of %s", fFunc->GetTitle()));
317
318 for (Int_t i = 0; i < fNP; i++ ) {
319 if (fParFix[i]->GetState() == kButtonDown) {
323 fParSld[i]->UnmapWindow();
324 } else {
325 if (fPmin[i]*fPmax[i] == 0 && fPmin[i] >= fPmax[i]) { //init
326 // round again the values on the percent level
328 Double_t roundVal = int(fPval[i]/ u) * u;
329 // set min at +/- 100 step size
330 fParMin[i]->SetNumber( roundVal - 100* fPstp[i]);
331 fParMax[i]->SetNumber( roundVal + 100* fPstp[i]);
332 // if (!fPval[i]) {
333 // fParMin[i]->SetNumber(-10);
334 // fParMax[i]->SetNumber(10);
335 // } else {
336 // fParMin[i]->SetNumber(-3*TMath::Abs(fPval[i]));
337 // fParMax[i]->SetNumber(3*TMath::Abs(fPval[i]));
338 // }
339 }
340 fParSld[i]->SetRange(fParMin[i]->GetNumber(), fParMax[i]->GetNumber());
341 fParSld[i]->SetPosition(fParMin[i]->GetNumber(), fParMax[i]->GetNumber());
342 fParSld[i]->SetPointerPosition(fParVal[i]->GetNumber());
343 fParSld[i]->Connect("PointerPositionChanged()", "TFitParametersDialog",
344 this, "DoSlider()");
345 fParSld[i]->Connect("PositionChanged()", "TFitParametersDialog",
346 this, "DoSlider()");
347 }
348 }
349
350 gClient->WaitFor(this);
351}
352
353////////////////////////////////////////////////////////////////////////////////
354/// Destructor.
355
357{
360 Cleanup();
361 delete [] fPval;
362 delete [] fPmin;
363 delete [] fPmax;
364 delete [] fPerr;
365 delete [] fPstp;
366
367 delete [] fParNam;
368 delete [] fParFix;
369 delete [] fParBnd;
370 delete [] fParVal;
371 delete [] fParMin;
372 delete [] fParMax;
373 delete [] fParSld;
374 delete [] fParStp;
375 delete [] fParErr;
376}
377
378////////////////////////////////////////////////////////////////////////////////
379/// Close parameters' dialog.
380
382{
383 if (fHasChanges) {
384 Int_t ret;
385 const char *txt;
386 txt = "Do you want to apply last parameters' setting?";
388 "Parameters Have Been Changed", txt, kMBIconExclamation,
389 kMBYes | kMBNo | kMBCancel, &ret);
390 if (ret == kMBYes) {
393 }
394 else if (ret == kMBNo)
395 DoReset();
396 else return;
397 }
398
400 DeleteWindow();
401}
402
403////////////////////////////////////////////////////////////////////////////////
404/// Slot related to the Cancel button.
405
407{
408 if (fHasChanges)
409 DoReset();
410 // for (Int_t i = 0; i < fNP; i++ ) {
411 // if (fParBnd[i]->GetState() == kButtonDown)
412 // *fRetCode = kFPDBounded;
413 // }
414 CloseWindow();
415}
416
417////////////////////////////////////////////////////////////////////////////////
418/// Slot related to the Bound check button.
419
421{
422 TGButton *bt = (TGButton *) gTQSender;
423 Int_t id = bt->WidgetId();
425
426 for (Int_t i = 0; i < fNP; i++ ) {
427 if (id == kBND*fNP+i) {
428 if (on) {
429 if (fParMin[i]->GetNumber() >= fParMax[i]->GetNumber()) {
430 Int_t ret;
431 const char *txt;
432 txt = "'Min' value cannot be bigger or equal to 'Max' - set the limits first!";
434 "Parameter Limits", txt, kMBIconExclamation,kMBOk,&ret);
435
437 return;
438 }
439 if ((fParVal[i]->GetNumber() < fParMin[i]->GetNumber()) ||
440 (fParVal[i]->GetNumber() > fParMax[i]->GetNumber())) {
441 Double_t v = (fParMax[i]->GetNumber()+fParMin[i]->GetNumber())/2.;
442 fParVal[i]->SetNumber(v);
443 fFunc->SetParameter(i, v);
445 }
447 fParMin[i]->GetNumber(),
448 fParMax[i]->GetNumber());
450 fFunc->SetParLimits(i, fParMin[i]->GetNumber(),
451 fParMax[i]->GetNumber());
452 } else {
455 fFunc->GetParLimits(i, fPmin[i], fPmax[i]);
456 fPval[i] = fFunc->GetParameter(i);
457 if (fPmin[i]*fPmax[i] == 0 && fPmin[i] >= fPmax[i]) { //init
458 if (!fPval[i]) {
459 fParMin[i]->SetNumber(-10);
460 fParMax[i]->SetNumber(10);
461 } else {
462 fParMin[i]->SetNumber(-10*TMath::Abs(fPval[i]));
463 fParMax[i]->SetNumber(10*TMath::Abs(fPval[i]));
464 }
465 }
466 fParSld[i]->SetRange(fParMin[i]->GetNumber(), fParMax[i]->GetNumber());
467 fParSld[i]->SetPosition(fParMin[i]->GetNumber(), fParMax[i]->GetNumber());
469 }
470 }
471 }
472 if (fUpdate->GetState() == kButtonDown)
473 DrawFunction();
474 else if ((fApply->GetState() == kButtonDisabled) && fHasChanges)
476}
477
478////////////////////////////////////////////////////////////////////////////////
479/// Slot related to parameter step setting.
480
482{
483}
484
485////////////////////////////////////////////////////////////////////////////////
486/// Slot related to the Fix check button.
487
489{
491
492 TGButton *bt = (TGButton *) gTQSender;
493 Int_t id = bt->WidgetId();
495
496 for (Int_t i = 0; i < fNP; i++ ) {
497 if (id == kFIX*fNP+i) {
498 if (on) {
499 // no bound available
500 fParBnd[i]->Disconnect("Toggled(Bool_t)");
502 fParBnd[i]->SetToolTipText(Form("DISABLED - %s is fixed", fFunc->GetParName(i)));
503 if (fParVal[i]->GetNumber() != 0) {
504 fParMin[i]->SetNumber(fParVal[i]->GetNumber());
506 fParMax[i]->SetNumber(fParVal[i]->GetNumber());
508 } else {
509 fParMin[i]->SetNumber(1.);
511 fParMax[i]->SetNumber(1.);
513 }
516 fParSld[i]->Disconnect("PointerPositionChanged()");
517 fParSld[i]->Disconnect("PositionChanged()");
518 fParSld[i]->UnmapWindow();
519 fFunc->FixParameter(i, fParVal[i]->GetNumber());
520 } else if (!fParMin[i]->IsEnabled()) {
521 if (fPmin[i] != fPmax[i]) {
522 if (fPmin[i])
523 fParMin[i]->SetNumber(fPmin[i]);
524 else if (fPerr[i])
525 fParMin[i]->SetNumber(fPval[i]-3*fPerr[i]);
526 else if (fPval[i])
527 fParMin[i]->SetNumber(fPval[i]-0.1*fPval[i]);
528 else
529 fParMin[i]->SetNumber(1.0);
530 if (fPmax[i])
531 fParMax[i]->SetNumber(fPmax[i]);
532 else if (fPerr[i])
533 fParMax[i]->SetNumber(fPval[i]+3*fPerr[i]);
534 else if (fPval[i])
535 fParMax[i]->SetNumber(fPval[i]+0.1*fPval[i]);
536 else
537 fParMax[i]->SetNumber(1.0);
538 } else if (fPval[i]) {
539 fParMin[i]->SetNumber(fPval[i]-0.1*fPval[i]);
540 fParMax[i]->SetNumber(fPval[i]+0.1*fPval[i]);
541 } else {
542 fParMin[i]->SetNumber(1.0);
543 fParMax[i]->SetNumber(1.0);
544 }
545 if (fParMax[i]->GetNumber() < fParMin[i]->GetNumber()){
546 Double_t temp;
547 temp = fParMax[i]->GetNumber();
548 fParMax[i]->SetNumber(fParMin[i]->GetNumber());
549 fParMin[i]->SetNumber(temp);
550 }
552 fParBnd[i]->Connect("Toggled(Bool_t)", "TFitParametersDialog",
553 this, "DoParBound(Bool_t)");
557 fParSld[i]->MapWindow();
560 fParSld[i]->SetRange(fParMin[i]->GetNumber(), fParMax[i]->GetNumber());
561 fParSld[i]->SetPosition(fParMin[i]->GetNumber(), fParMax[i]->GetNumber());
563 fParSld[i]->Connect("PointerPositionChanged()", "TFitParametersDialog",
564 this, "DoSlider()");
565 fParSld[i]->Connect("PositionChanged()", "TFitParametersDialog",
566 this, "DoSlider()");
567 fFunc->SetParLimits(i, fParMin[i]->GetNumber(), fParMax[i]->GetNumber());
568 }
569 }
570 }
571 if (fUpdate->GetState() == kButtonDown)
572 DrawFunction();
573 else if ((fApply->GetState() == kButtonDisabled) && fHasChanges)
575}
576
577////////////////////////////////////////////////////////////////////////////////
578/// Set the parameter values inside the function
579
581{
583 for (Int_t i = 0; i < fNP; i++ ) {
584 // first make sure the current value is up to date
586 if (fParFix[i]->GetState() == kButtonDown) {
587 fFunc->SetParameter(i, fParVal[i]->GetNumber());
588 fFunc->FixParameter(i, fParVal[i]->GetNumber());
590 } else {
591 if (fParBnd[i]->GetState() == kButtonDown) {
592 fFunc->SetParameter(i, fParVal[i]->GetNumber());
593 fFunc->SetParLimits(i, fParMin[i]->GetNumber(), fParMax[i]->GetNumber());
595 } else {
597 }
598 }
599 }
600}
601
602////////////////////////////////////////////////////////////////////////////////
603/// Slot related to the OK button.
604
606{
607 if (fHasChanges)
608 DrawFunction();
609
611
612 // we want here to confirm the parameters settings so
613 // it is like having changed them
615
616
617 CloseWindow();
618}
619
620////////////////////////////////////////////////////////////////////////////////
621/// Slot related to the Preview button.
622
624{
625 DrawFunction();
629}
630
631////////////////////////////////////////////////////////////////////////////////
632/// Slot related to the Reset button.
633
635{
637 Int_t k = fNP;
638 for (Int_t i = 0; i < fNP; i++) {
639 if (fParVal[i]->GetNumber() == fPval[i])
640 k--;
641 else
642 break;
643 }
644
645 if (!k) {
646 if (fReset->GetState() == kButtonUp)
649 return;
650 }
651 for (Int_t i = 0; i < fNP; i++) {
652 fFunc->SetParameter(i, fPval[i]);
653 fFunc->SetParLimits(i, fPmin[i], fPmax[i]);
654 fFunc->SetParError(i, fPerr[i]);
655
656 if (fPmin[i])
657 fParMin[i]->SetNumber(fPmin[i]);
658 else if (fPerr[i])
659 fParMin[i]->SetNumber(fPval[i]-3*fPerr[i]);
660 else if (fPval[i])
661 fParMin[i]->SetNumber(-3*TMath::Abs(fPval[i]));
662 else
663 fParMin[i]->SetNumber(1.0);
664
665 if (fPmax[i])
666 fParMax[i]->SetNumber(fPmax[i]);
667 else if (fPerr[i])
668 fParMax[i]->SetNumber(fPval[i]+3*fPerr[i]);
669 else if (fPval[i])
671 else
672 fParMax[i]->SetNumber(1.0);
673 if (fParMax[i]->GetNumber() < fParMin[i]->GetNumber()){
674 Double_t temp;
675 temp = fParMax[i]->GetNumber();
676 fParMax[i]->SetNumber(fParMin[i]->GetNumber());
677 fParMin[i]->SetNumber(temp);
678 }
679 if (fParMin[i]->GetNumber() == fParMax[i]->GetNumber()) {
684 fParSld[i]->Disconnect("PointerPositionChanged()");
685 fParSld[i]->Disconnect("PositionChanged()");
686 fParSld[i]->UnmapWindow();
687 fParBnd[i]->Disconnect("Toggled(Bool_t)");
689 fFunc->FixParameter(i, fParVal[i]->GetNumber());
691 } else {
693 if (!fParMax[i]->IsEnabled()) {
698 fParSld[i]->SetRange(fParMin[i]->GetNumber(), fParMax[i]->GetNumber());
699 fParSld[i]->SetPosition(fParMin[i]->GetNumber(), fParMax[i]->GetNumber());
701 fParSld[i]->MapWindow();
702 fParSld[i]->Connect("PointerPositionChanged()", "TFitParametersDialog",
703 this, "DoSlider()");
704 fParSld[i]->Connect("PositionChanged()", "TFitParametersDialog",
705 this, "DoSlider()");
707 fParBnd[i]->Connect("Toggled(Bool_t)", "TFitParametersDialog",
708 this, "DoParBound(Bool_t)");
709 }
710 }
711 fParVal[i]->SetNumber(fPval[i]);
712
713 fParSld[i]->SetRange(fParMin[i]->GetNumber(), fParMax[i]->GetNumber());
714 fParSld[i]->SetPosition(fParMin[i]->GetNumber(), fParMax[i]->GetNumber());
716 }
717
718 if (fUpdate->GetState() == kButtonDown)
719 DrawFunction();
720 else if ((fApply->GetState() == kButtonDisabled) && fHasChanges)
725}
726
727////////////////////////////////////////////////////////////////////////////////
728/// Slot related to the parameters' value settings.
729
731{
733 Int_t id = sl->WidgetId();
734
736 for (Int_t i = 0; i < fNP; i++ ) {
737 if (id == kSLD*fNP+i) {
738 fFunc->SetParameter(i,fParSld[i]->GetPointerPosition());
739 fFunc->SetParLimits(i,fParSld[i]->GetMinPosition(),
740 fParSld[i]->GetMaxPosition());
741 fParMin[i]->SetNumber(fParSld[i]->GetMinPosition());
742 fParMax[i]->SetNumber(fParSld[i]->GetMaxPosition());
743 fParVal[i]->SetNumber(fParSld[i]->GetPointerPosition());
744 }
745 }
746 if (fUpdate->GetState() == kButtonDown)
747 DrawFunction();
748 else if ((fApply->GetState() == kButtonDisabled) && fHasChanges)
752}
753
754////////////////////////////////////////////////////////////////////////////////
755/// Slot related to the parameter value settings.
756
758{
760 Int_t id = ne->WidgetId();
761
762 for (Int_t i = 0; i < fNP; i++ ) {
763 if (id == kVAL*fNP+i) {
764 if (fParVal[i]->GetNumber() < fParMin[i]->GetNumber()) {
765 Double_t extraIncrement = (fParMax[i]->GetNumber() - fParMin[i]->GetNumber()) / 4;
766 fParMin[i]->SetNumber(fParVal[i]->GetNumber() - extraIncrement );
768 fParSld[i]->SetRange(fParMin[i]->GetNumber(),
769 fParMax[i]->GetNumber());
770 fParSld[i]->SetPosition(fParMin[i]->GetNumber(),
771 fParMax[i]->GetNumber());
772 }
773 if (fParVal[i]->GetNumber() > fParMax[i]->GetNumber()) {
774 Double_t extraIncrement = (fParMax[i]->GetNumber() - fParMin[i]->GetNumber()) / 4;
775 fParMax[i]->SetNumber(fParVal[i]->GetNumber() + extraIncrement );
777 fParSld[i]->SetRange(fParMin[i]->GetNumber(),
778 fParMax[i]->GetNumber());
779 fParSld[i]->SetPosition(fParMin[i]->GetNumber(),
780 fParMax[i]->GetNumber());
781 }
782 fParSld[i]->SetPointerPosition(fParVal[i]->GetNumber());
784 fFunc->SetParameter(i,fParSld[i]->GetPointerPosition());
785 if (fParBnd[i]->GetState() == kButtonDown)
787 fParSld[i]->GetMaxPosition());
788 else
790 }
791 }
793 if (fUpdate->GetState() == kButtonDown)
794 DrawFunction();
795 else if ((fApply->GetState() == kButtonDisabled) && fHasChanges)
799}
800
801////////////////////////////////////////////////////////////////////////////////
802/// Slot related to the minumum parameter limit settings.
803
805{
807 Int_t id = ne->WidgetId();
808
809 for (Int_t i = 0; i < fNP; i++ ) {
810 if (id == kMIN*fNP+i) {
811 if ((fParMin[i]->GetNumber() >= fParMax[i]->GetNumber()) &&
812 (fParBnd[i]->GetState() == kButtonDown)) {
813 Int_t ret;
814 const char *txt;
815 txt = "'Min' cannot be bigger then 'Max' if this parameter is bounded.";
817 "Parameter Limits", txt, kMBIconExclamation, kMBOk, &ret);
818 fParMin[i]->SetNumber(fParVal[i]->GetNumber()-fParStp[i]->GetNumber());
819 return;
820 }
821 if (fParBnd[i]->GetState() == kButtonDown) {
822 Double_t val = (fParMax[i]->GetNumber()+fParMin[i]->GetNumber())/2.;
823 fParVal[i]->SetNumber(val);
824 fParVal[i]->SetLimitValues(fParMin[i]->GetNumber(),
825 fParMax[i]->GetNumber());
826 }
827 fParSld[i]->SetRange(fParMin[i]->GetNumber(),
828 fParMax[i]->GetNumber());
829 fParSld[i]->SetPosition(fParMin[i]->GetNumber(),
830 fParMax[i]->GetNumber());
831 fParSld[i]->SetPointerPosition(fParVal[i]->GetNumber());
833 }
834 }
836 if (fUpdate->GetState() == kButtonDown)
837 DrawFunction();
838 else if ((fApply->GetState() == kButtonDisabled) && fHasChanges)
842}
843
844////////////////////////////////////////////////////////////////////////////////
845/// Slot related to the maximum parameter limit settings.
846
848{
850 Int_t id = ne->WidgetId();
851
852 for (Int_t i = 0; i < fNP; i++ ) {
853 if (id == kMAX*fNP+i) {
854 if ((fParMin[i]->GetNumber() >= fParMax[i]->GetNumber()) &&
855 (fParBnd[i]->GetState() == kButtonDown)) {
856 Int_t ret;
857 const char *txt;
858 txt = "'Min' cannot be bigger then 'Max' if this parameter is bounded.";
860 "Parameter Limits", txt, kMBIconExclamation, kMBOk, &ret);
861 fParMax[i]->SetNumber(fParVal[i]->GetNumber()+fParStp[i]->GetNumber());
862 return;
863 }
864 if (fParBnd[i]->GetState() == kButtonDown) {
865 Double_t val = (fParMax[i]->GetNumber()+(fParMin[i]->GetNumber()))/2.;
866 fParVal[i]->SetNumber(val);
867 fParVal[i]->SetLimitValues(fParMin[i]->GetNumber(),
868 fParMax[i]->GetNumber());
869 }
870 fParSld[i]->SetRange(fParMin[i]->GetNumber(),
871 fParMax[i]->GetNumber());
872 fParSld[i]->SetPosition(fParMin[i]->GetNumber(),
873 fParMax[i]->GetNumber());
874 fParSld[i]->SetPointerPosition(fParVal[i]->GetNumber());
876 }
877 }
879 if (fUpdate->GetState() == kButtonDown)
880 DrawFunction();
881 else if ((fApply->GetState() == kButtonDisabled) && fHasChanges)
885}
886
887////////////////////////////////////////////////////////////////////////////////
888/// Redraw function graphics.
889
891{
892 if ( !fFpad ) return;
893 TVirtualPad *save = 0;
894 save = gPad;
895 gPad = fFpad;
896 gPad->cd();
897
898 Style_t st = fFunc->GetLineStyle();
900
901 TString opt = fFunc->GetDrawOption();
902 opt.ToUpper();
903 if (!opt.Contains("SAME"))
904 opt += "SAME";
905 //fFunc->SetRange(fRXmin, fRXmax);
906 fFunc->Draw(opt);
907 gPad->Modified();
908 gPad->Update();
910
911 fFunc->SetLineStyle(st);
912 if (save) gPad = save;
914}
915
916////////////////////////////////////////////////////////////////////////////////
917/// Handle the button dependent states in this dialog.
918
920{
921 if (update && fHasChanges)
922 DrawFunction();
923 else if ((fApply->GetState() == kButtonDisabled) && fHasChanges) {
925 }
926}
927
928////////////////////////////////////////////////////////////////////////////////
929/// Disconnect signals from slot methods.
930
932{
933 for (Int_t i = 0; i < fNP; i++ ) {
934 fParFix[i]->Disconnect("Toggled(Bool_t)");
935 fParBnd[i]->Disconnect("Toggled(Bool_t)");
936 fParVal[i]->Disconnect("ValueSet(Long_t)");
937 fParMin[i]->Disconnect("ReturnPressed()");
938 fParMax[i]->Disconnect("ReturnPressed()");
939 fParSld[i]->Disconnect("PointerPositionChanged()");
940 fParSld[i]->Disconnect("PositionChanged()");
941 fParStp[i]->Disconnect("ValueSet(Long_t)");
942 fParVal[i]->Disconnect("TabPressed(Long_t)");
943 fParVal[i]->Disconnect("ShiftTabPressed(Long_t)");
944 fParMin[i]->Disconnect("TabPressed(Long_t)");
945 fParMin[i]->Disconnect("ShiftTabPressed(Long_t)");
946 fParMax[i]->Disconnect("TabPressed(Long_t)");
947 fParMax[i]->Disconnect("ShiftTabPressed(Long_t)");
948 fParStp[i]->Disconnect("TabPressed(Long_t)");
949 fParStp[i]->Disconnect("ShiftTabPressed(Long_t)");
950 }
951 fUpdate->Disconnect("Toggled(Bool_t)");
952 fReset->Disconnect("Clicked()");
953 fApply->Disconnect("Clicked()");
954 fOK->Disconnect("Clicked()");
955 fCancel->Disconnect("Clicked()");
956}
957
958////////////////////////////////////////////////////////////////////////////////
959/// Handle Shift+Tab key event (set focus to the previous number entry field)
960
962{
964 next = (TGNumberEntryField *)fTextEntries.Before((TObject *)sender);
965 if (next == 0)
967 if (next) {
968 next->SetFocus();
969 next->Home();
970 }
971}
972
973////////////////////////////////////////////////////////////////////////////////
974/// Handle Tab key event (set focus to the next number entry field)
975
977{
979 next = (TGNumberEntryField *)fTextEntries.After((TObject *)sender);
980 if (next == 0)
982 if (next) {
983 next->SetFocus();
984 next->Home();
985 }
986}
987
988
989
static void update(gsl_integration_workspace *workspace, double a1, double b1, double area1, double error1, double a2, double b2, double area2, double error2)
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
double Double_t
Definition: RtypesCore.h:55
short Style_t
Definition: RtypesCore.h:76
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:365
EParametersDialogWid
@ kFPDChange
@ 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:51
@ kVerticalFrame
Definition: TGFrame.h:59
@ kFixedWidth
Definition: TGFrame.h:65
@ kHorizontalFrame
Definition: TGFrame.h:60
@ 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:43
@ kMBYes
Definition: TGMsgBox.h:42
@ kMBCancel
Definition: TGMsgBox.h:48
@ kMBOk
Definition: TGMsgBox.h:44
@ kMBIconExclamation
Definition: TGMsgBox.h:35
R__EXTERN void * gTQSender
Definition: TQObject.h:44
char * Form(const char *fmt,...)
#define gPad
Definition: TVirtualPad.h:286
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:211
virtual void ReleaseParameter(Int_t ipar)
Release parameter number ipar If used in a fit, the parameter can vary freely.
Definition: TF1.cxx:3123
virtual void SetParError(Int_t ipar, Double_t error)
Set error for parameter number ipar.
Definition: TF1.cxx:3472
virtual void GetParLimits(Int_t ipar, Double_t &parmin, Double_t &parmax) const
Return limits for parameter ipar.
Definition: TF1.cxx:1920
virtual Double_t GetParError(Int_t ipar) const
Return value of parameter number ipar.
Definition: TF1.cxx:1910
virtual void SetRange(Double_t xmin, Double_t xmax)
Initialize the upper and lower bounds to draw the function.
Definition: TF1.cxx:3518
virtual Int_t GetNpar() const
Definition: TF1.h:475
virtual void GetRange(Double_t *xmin, Double_t *xmax) const
Return range of a generic N-D function.
Definition: TF1.cxx:2263
virtual const char * GetParName(Int_t ipar) const
Definition: TF1.h:523
virtual void SetParLimits(Int_t ipar, Double_t parmin, Double_t parmax)
Set limits for parameter ipar.
Definition: TF1.cxx:3497
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
Definition: TF1.cxx:1317
virtual void SetParameter(Int_t param, Double_t value)
Definition: TF1.h:628
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:1542
virtual Double_t GetParameter(Int_t ipar) const
Definition: TF1.h:506
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.
TGNumberEntry ** fParStp
TGCompositeFrame * fContVal
virtual void CloseWindow()
Close parameters' dialog.
virtual void HandleTab()
Handle Tab key event (set focus to the next number entry field)
TGCheckButton ** fParFix
TGCheckButton ** fParBnd
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.
TGNumberEntry ** fParVal
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:395
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:409
virtual void SetState(EButtonState state, Bool_t emit=kFALSE)
Set button state.
Definition: TGButton.cxx:185
virtual void SetState(EButtonState state, Bool_t emit=kFALSE)
Set check button state.
Definition: TGButton.cxx:1200
const TGWindow * GetRoot() const
Returns current root (i.e.
Definition: TGClient.cxx:224
void NeedRedraw(TGWindow *w, Bool_t force=kFALSE)
Set redraw flags.
Definition: TGClient.cxx:372
TGCompositeFrame(const TGCompositeFrame &)
Int_t GetState(TGFrame *f) const
Get state of sub frame.
Definition: TGFrame.cxx:1200
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
virtual void Cleanup()
Cleanup and delete all objects contained in this composite frame.
Definition: TGFrame.cxx:949
virtual void SetCleanup(Int_t mode=kLocalCleanup)
Turn on automatic cleanup of child frames in dtor.
Definition: TGFrame.cxx:1054
virtual TGDimension GetDefaultSize() const
std::cout << fWidth << "x" << fHeight << std::endl;
Definition: TGFrame.h:375
virtual void MapSubwindows()
Map all sub windows that are part of the composite frame.
Definition: TGFrame.cxx:1146
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:665
virtual void DeleteWindow()
Delete window.
Definition: TGFrame.cxx:258
virtual void Resize(UInt_t w=0, UInt_t h=0)
Resize the frame.
Definition: TGFrame.cxx:587
virtual void MapWindow()
Definition: TGFrame.h:251
virtual void UnmapWindow()
Definition: TGFrame.h:253
void SetWindowName(const char *name=0)
Set window name. This is typically done via the window manager.
Definition: TGFrame.cxx:1746
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)
Definition: TGTextEntry.h:164
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:1913
virtual void SetPointerPosition(Float_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:80
virtual const TGWindow * GetMainFrame() const
Returns top level main frame.
Definition: TGWindow.cxx:133
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:327
virtual TObject * Last() const
Return the last object in the list. Returns 0 when list is empty.
Definition: TList.cxx:690
virtual TObject * Before(const TObject *obj) const
Returns the object before object obj.
Definition: TList.cxx:368
virtual TObject * First() const
Return the first object in the list. Returns 0 when list is empty.
Definition: TList.cxx:656
virtual void Clear(Option_t *option="")
Remove all objects from the list.
Definition: TList.cxx:399
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:341
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:867
Bool_t Disconnect(const char *signal=0, void *receiver=0, const char *slot=0)
Disconnects signal of this object from slot of receiver.
Definition: TQObject.cxx:1025
Basic string class.
Definition: TString.h:131
void ToUpper()
Change string to upper case.
Definition: TString.cxx:1138
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:619
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:50
int main(int argc, char **argv)
TF1 * f1
Definition: legend1.C:11
Double_t Floor(Double_t x)
Definition: TMath.h:693
constexpr Double_t E()
Base of natural log:
Definition: TMath.h:97
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Definition: TMath.h:725
Double_t Log10(Double_t x)
Definition: TMath.h:754
Short_t Abs(Short_t d)
Definition: TMathBase.h:120