Run a function in ROOT GUI

Please provide the following information:


ROOT Version (5.34):
Platform, compiler (window 7):


Dear Rooters,

I have built a program with root gui. But I have the following problem.

I have functions:

MyMainFrame::DoDraw()
MyMainFrame::DoDraw2()
MyMainFrame::DoFit()

When I call DoDraw() from DoDraw2(), it works. But when I tried to call DoDraw and DoDraw2() in DoFit, it does not work.

Fitting button (DoFit), it first calls DoDraw and DoDraw2, which draw histogram on top canvas and second canvas, respectively.

Could you please help me.

Thank you very much,
peakprogram.C (16.4 KB)

I am not the GUI expert and @bellenot can surely help you better than me. I see you are on windows and therefore using ROOT 5. But I tried anyway to run your program using ROOT 6 on Mac and I get the following errors. Some seems to be real C++ mistakes:

root [0] 
Processing peakprogram.C...
In file included from input_line_10:1:
/Users/couet/Downloads/peakprogram.C:118:24: error: cannot initialize a parameter of type 'EButtonState' with an rvalue of type
      'int'
   bt_tscfit->SetState(1);
                       ^
/Users/couet/git/roottrunk-bin/include/TGButton.h:315:41: note: passing argument to parameter 'state' here
   virtual void   SetState(EButtonState state, Bool_t emit = kFALSE);
                                        ^
In file included from input_line_10:1:
/Users/couet/Downloads/peakprogram.C:225:9: error: use of undeclared identifier 'loadspe'
        hspe = loadspe(bt_spe_name->GetText());
               ^
/Users/couet/Downloads/peakprogram.C:226:16: error: assigning to 'TH1F *' from incompatible type 'TObject *'
        hspe1 = hspe->Clone();
                ~~~~~~^~~~~~~
/Users/couet/Downloads/peakprogram.C:257:15: error: assigning to 'TH1F *' from incompatible type 'TObject *'
        hfit = hspe->Clone();
               ~~~~~~^~~~~~~
/Users/couet/Downloads/peakprogram.C:327:19: error: out-of-line definition of 'DoFit' does not match any declaration in
      'MyMainFrame'
void MyMainFrame::DoFit()
                  ^~~~~
/Users/couet/Downloads/peakprogram.C:391:15: error: assigning to 'Double_t *' (aka 'double *') from incompatible type
      'const Double_t *' (aka 'const double *')
        upar = ffit->GetParErrors();
               ~~~~~~^~~~~~~~~~~~~~
/Users/couet/Downloads/peakprogram.C:394:48: warning: format specifies type 'int' but the argument has type 'Double_t' (aka 'double')
      [-Wformat]
        printf("Fitting Range:  %i *********** %i \n",bt_left2->GetNumber(),bt_r...
                                ~~                    ^~~~~~~~~~~~~~~~~~~~~
                                %f
/Users/couet/Downloads/peakprogram.C:394:70: warning: format specifies type 'int' but the argument has type 'Double_t' (aka 'double')
      [-Wformat]
  ...%i *********** %i \n",bt_left2->GetNumber(),bt_right2->GetNumber());
                    ~~                           ^~~~~~~~~~~~~~~~~~~~~~
                    %f
/Users/couet/Downloads/peakprogram.C:417:22: error: cannot initialize a parameter of type 'EButtonState' with an rvalue of type
      'int'
        bt_tscfit->SetState(0);
                            ^
/Users/couet/git/roottrunk-bin/include/TGButton.h:315:41: note: passing argument to parameter 'state' here
   virtual void   SetState(EButtonState state, Bool_t emit = kFALSE);
                                        ^
In file included from input_line_10:1:
/Users/couet/Downloads/peakprogram.C:418:37: error: cannot initialize a parameter of type 'EButtonState' with an rvalue of type
      'int'
        if (s1=="tsc") bt_tscfit->SetState(1);
                                           ^
/Users/couet/git/roottrunk-bin/include/TGButton.h:315:41: note: passing argument to parameter 'state' here
   virtual void   SetState(EButtonState state, Bool_t emit = kFALSE);
                                        ^
root [1] 

Thank Couet,

I run this program on Root 5 without any errors or warning. The errors that you get may come from the different between Root versions. Sometime ROOT updates the type of function’s arguments, then it create errors.

For example, I use Search in TSpectrum with double_t as argument, it works well on ROOT 6, but not in ROOT 5, because we need to use float_t in ROOT 5.

Yes I know. ROOT 5 less strict than ROOT 6 regarding C++. I would suggest you run your macro (with ROOT 5) using AClic. Adding a “+” after the “C” when you run the macro:

root > .x peakprogram.C+

You will then benefit from a true C++ compiler and see possible C++ errors in your code.

Thank Couet,

Ops, a lot of errors when I try to run with AClic.

root [0] .x peakprogram.C+
Info in <TWinNTSystem::ACLiC>: creating shared library D:\Dropbox\BUREAU\00 - n2g\Peak_Area\peakprog
ram_C.dll
2839646_cint.cxx
Error: Symbol TGTextEntry is not defined in current scope  D:\Dropbox\BUREAU\00 - n2g\Peak_Area\peak
program.C(29)
Error: Symbol bt_spe_name is not defined in current scope  D:\Dropbox\BUREAU\00 - n2g\Peak_Area\peak
program.C(29)
Error: Symbol TGNumberEntry is not defined in current scope  D:\Dropbox\BUREAU\00 - n2g\Peak_Area\pe
akprogram.C(31)
Error: Symbol bt_left is not defined in current scope  D:\Dropbox\BUREAU\00 - n2g\Peak_Area\peakprog
ram.C(31)
Error: Symbol TGNumberEntry is not defined in current scope  D:\Dropbox\BUREAU\00 - n2g\Peak_Area\pe
akprogram.C(32)
Error: Symbol bt_right is not defined in current scope  D:\Dropbox\BUREAU\00 - n2g\Peak_Area\peakpro
gram.C(32)
Error: Symbol TGNumberEntry is not defined in current scope  D:\Dropbox\BUREAU\00 - n2g\Peak_Area\pe
akprogram.C(33)
Error: Symbol bt_left2 is not defined in current scope  D:\Dropbox\BUREAU\00 - n2g\Peak_Area\peakpro
gram.C(33)
Error: Symbol TGNumberEntry is not defined in current scope  D:\Dropbox\BUREAU\00 - n2g\Peak_Area\pe
akprogram.C(34)
Error: Symbol bt_right2 is not defined in current scope  D:\Dropbox\BUREAU\00 - n2g\Peak_Area\peakpr
ogram.C(34)
Error: Symbol TGTextEntry is not defined in current scope  D:\Dropbox\BUREAU\00 - n2g\Peak_Area\peak
program.C(39)
Error: Symbol bt_peak_pos is not defined in current scope  D:\Dropbox\BUREAU\00 - n2g\Peak_Area\peak
program.C(39)
Error: Symbol TGTextEntry is not defined in current scope  D:\Dropbox\BUREAU\00 - n2g\Peak_Area\peak
program.C(40)
Error: Symbol bt_sig_par is not defined in current scope  D:\Dropbox\BUREAU\00 - n2g\Peak_Area\peakp
rogram.C(40)
Error: Symbol TGNumberEntry is not defined in current scope  D:\Dropbox\BUREAU\00 - n2g\Peak_Area\pe
akprogram.C(41)
Error: Symbol bt_Esum is not defined in current scope  D:\Dropbox\BUREAU\00 - n2g\Peak_Area\peakprog
ram.C(41)
Error: Symbol TGNumberEntry is not defined in current scope  D:\Dropbox\BUREAU\00 - n2g\Peak_Area\pe
akprogram.C(42)
Error: Symbol bt_bkg_deg is not defined in current scope  D:\Dropbox\BUREAU\00 - n2g\Peak_Area\peakp
rogram.C(42)
Error: Symbol TGNumberEntry is not defined in current scope  D:\Dropbox\BUREAU\00 - n2g\Peak_Area\pe
akprogram.C(43)
Error: Symbol bt_ini_sig is not defined in current scope  D:\Dropbox\BUREAU\00 - n2g\Peak_Area\peakp
rogram.C(43)
Error: Symbol TGTextEntry is not defined in current scope  D:\Dropbox\BUREAU\00 - n2g\Peak_Area\peak
program.C(44)
Error: Symbol bt_roi_name is not defined in current scope  D:\Dropbox\BUREAU\00 - n2g\Peak_Area\peak
program.C(44)
Error: Symbol TGLabel is not defined in current scope  D:\Dropbox\BUREAU\00 - n2g\Peak_Area\peakprog
ram.C(48)
Error: Symbol coordinate is not defined in current scope  D:\Dropbox\BUREAU\00 - n2g\Peak_Area\peakp
rogram.C(48)
Warning: Error occurred during reading source files
Warning: Error occurred during dictionary source generation
!!!Removing D:\Dropbox\BUREAU\00 - n2g\Peak_Area\peakprogram_C_ACLiC_dict.cxx D:\Dropbox\BUREAU\00 -
 n2g\Peak_Area\peakprogram_C_ACLiC_dict.h !!!
Error: C:\root_v5.34.32\bin\rootcint: error loading headers...
Error in <ACLiC>: Dictionary generation failed!
Info in <ACLiC>: Invoking compiler to check macro's validity
Error: Function peakprogram() is not defined in current scope  (0)
*** Interpreter error recovered ***
root [1]

Yes , That’s what I meant … cleaning them can already clarify a bit the problem .

Some of the errors you get come from missing include files. Add them like for any C++ program.

Thank you,

I did this and a lot of others errors, including: Function peakprogram() is not defined in current scope. So programming with AClic is much different from interpret ROOT.

Yes, it is real C++ so with ROOT 5 it can be quite different as ROOT 5 was very tolerant with C++ rules.

With the attached source code, one still gets one error, but I think it’s not really a critical one:

Error in <MyMainFrame>: MyMainFrame inherits from TObject but does not have its own ClassDef

peakprogram.C (16.5 KB)

1 Like

I get a different one on Mac:

root [0] .x peakprogram.C
In file included from input_line_10:1:
/Users/couet/Downloads/peakprogram.C:412:15: error: assigning to 'Double_t *' (aka 'double *') from incompatible type 'const Double_t *' (aka 'const double *')
        upar = ffit->GetParErrors();
               ~~~~~~^~~~~~~~~~~~~~

Well, this is then another incompatibility between ROOT 5.x a 6.x.

BTW. I “fixed” obvious problems reported by the compiler only so, there may still be things which are not “kosher”. I “fixed” the “upar” problem now, too (see the modified source code in my previous post).

BTW. TSpectrum::Search uses a const TH1 *hin parameter so it should accept both float and double. For some examples how one can simultaneously deal with TSpectrum in ROOT 5 and TSpectrum in ROOT 6, see:

Dear friends,

With your help, I resolved my problem. But now I have 2 new problems.

  1. I tried to print my fit status to screen, however, when I input
     printf("Fitting Result: %20s \n", fitstate);   //Line 442. 

The program is crashed.

  1. I fit in many ranges, so I would like that after each fit, the program pause, so I can see the fit. In order to continue, I can press any key.

For this purpose, I use system(“pause”)

		if (bt_range_by_range->IsOn()) system("pause");    //Line 507. 

However, the program works unstable, that means sometime it stop and update the fitting canvas, but sometimes it stop but does not update the fitting canvas.

Here is my source code:

peakprogram.C (21.0 KB)

5868.c (84.9 KB)

test.txt (1.4 KB)

In order to test my program, you only need to put all the above files in a folder, change “test.txt” to “test.roi” (because I can not upload .roi file), compile, and press Auto_cal button. (right side)

Thank you,

     printf("Fitting Result: %20s \n", fitstate.c_str());   //Line 442. 

I tried to use the following script, and the program works better but somehow a little bit unstable. I don’t understand.
TCanvas *fCanvas = fEcanvas2->GetCanvas();
fCanvas->cd(); fCanvas->Modified(); fCanvas->Update(); gSystem->ProcessEvents();
cout<<“Press any key to continue”<<endl;
cin.get();

By the way, I would be very glad if there is a solution, in which I can zoom the histogram during the pause time. It seems that the fitting line is not well drawn. See fig1 (without zooming) and fig2 (zooming).


Try:

	TF1 *ffit = new TF1("ffit",fit_function,bt_left2->GetNumber(), bt_right2->GetNumber(),3+max_peak_num*3);
	ffit->SetNpx(TMath::Max(100, Int_t(0.5 + 3. * (bt_right2->GetNumber() - bt_left2->GetNumber()) / hfit->GetBinWidth(1))));

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.