Text entry in displaying histograms

Hi,

I am an undergraduate student creating a gui for a project. I have a function that will display a histogram when the user enters the name of that histogram into a text entry field in a dialogue box and a button is pressed. I have a draw function in which there is a line of code:

fFrame->Draw(chain name)

I then enter the chain name into the text entry in the dialogue and press an Ok button. How do I have it such that when I press this button my histogram is displayed?
I have tried a few things and have had no luck.

Thanks,

Lisaq

Hi Lisa,

I will prepare and provide an example in the beginning of the next week.

Cheers, Ilka

Thank you for your help. It is much appreciated.

Lisa

Does anyone have an example of code in which they do a similar thing to what I described in my previous message?

I would be most grateful for you help,

Lisa

Dear Lisa,

I did not forget the example you need… some urgent tasks posponed my work on it. Thank you for your understanding.

Cheers, Ilka

No problem. Thank you for your help, Ilka.

Hi Lisa,

There is an example in the attached file with an main window application and a dialog window via which you can enter one of the both histogram names: hpx, hpxpy. After you hit Enter key, the entered histogram name is shown and you can draw the histogram in the main application window by clicking on the Draw&Close button. Please create and copy the file hsimple.root from $ROOTSYS/tutorials into the directory where you are going to execute this macro. To simplify the code I did not include the code for checking if this file exists; if the histogram names are entered correct ly (i.e. hpx, hpxpy), etc.

Thank you for your patience.

Best regards, Ilka
dialogExample2.C (6.79 KB)

Hi Ilka,

Thank you for the macro. I have tried to run it by creating a directory with the macro and the hsimple.C in. When I enter ROOT I type in .x dialogExample2.C and I get the error:

root [0] .x dialogExample2.C
Error: class,struct,union or type MyMainFrame not defined FILE:dialogExample2.C LINE:72
*** Interpreter error recovered ***

I can not see what the problem is. Any ideas?

Lisa

Hi Lisa,

I cannot reproduce this case. I have created a new directory, I have copied the macro hsimple.C and the example and everything runs. Please see the attached files.

Cheers, Ilka
exam.txt (1.2 KB)

Hi Ilka,

I am still unable to run the macro. When I type in .x hsimple.C the window appears and when I close it I get the attached errors.

Lisa
rooterrors.C (2.71 KB)

Hi Lisa,

Could be related with settings of your environment. You can copy the example macro in the $ROOTSYS/tutorials or you can run hsimple.C there and copy the hsimple.root file in the directory of the macro example.

Cheers, Ilka

When I run hsimple.C in the ROOTSYS/tutorials I get the same errors. Could it be the version of ROOT that I am using?

Hi Lisa,

If you could take the latest ROOT version.

Cheers, Ilka

Hi,

I have got the macro to work and have copied what I see as the revelant code into my class, but when I press the Draw&Close button I get the attached list of errors.
Any ideas as to why?

I have also attached the code for my dialog box.

Thanks,

Lisa
MyDialog.C (3.19 KB)
MyDialog.h (1.17 KB)
dialogErrors.C (2.09 KB)

Hi Lisa,

From the code you have sent it is not clear:

  • Does the MainFrame is your main frame application window?
  • where do you create the MyDialog object?

Please see TGMainFrame and TGTransient Frame classes in the ROOT reference Doc and in the User’s Guide chapter “Writting a GUI”. A pointer to the main frame window should be passed in the dialog constructor. The method TGTransientFrame::GetMain() can be used if you need to use the main frame pointer somewhere.

Best regards, Ilka

Hi Ilka,

I have solved my problem, I hadn’t initialised my canvas. However, now, when I type in the name of the histogram chain (data or Monte Carlo) and press the Ok button I get the error:

The Ok button is pressed
Error: Symbol data is not defined in current scope FILE:(tmpfile) LINE:1
Error: Failed to evaluate data->Draw()Possible candidates are…
filename line:size busy function type and name
*** Interpreter error recovered ***

Both myself and my supervisor can’t figure out why, can you help?

I have attached my MainFrame class and executable, useMainFrame.

Thanks,

Lisa
useMainFrame.C (848 Bytes)
MainFrame.C (2.82 KB)
MainFrame.h (1.22 KB)

Hi Lisa,

The example I provided uses the Draw() method that does not seem to be available for the object ‘data’ you want to draw on the canvas. Please read the “Drawing Objects” at: ftp://root.cern.ch/root/doc/Users_Guide_4_08.pdf.
If you list the file contents of “hsimple.root” you will see

root [0] TFile f("hsimple.root")
root [1] f.ls()
TFile**         hsimple.root    Demo ROOT file with histograms
 TFile*         hsimple.root    Demo ROOT file with histograms
  KEY: TH1F     hpx;1   This is the px distribution
  KEY: TH2F     hpxpy;1 py vs px
  KEY: TProfile hprof;1 Profile of pz versus px
  KEY: TNtuple  ntuple;1        Demo ntuple

The Draw() method is available for both: hpx and hpxpy as you can check in the ROOT Reference Guide.

Cheers, Ilka

Hi,

I have been trying to get my histograms displayed using the example that you gave me but I’ve not had much success. No matter what I do I still get an error saying that the symbol is not defined in current scope. Can you help me?

Unlike the example, I do not have previously created histograms.
I have an executable in which I open my analysis root file and read back the analysis. I then have a function in which I read back a chain, get the histograms from that chain, fill the arrays of histograms and add them to a plotter. When I enter the chain name into the text entry and close hte dialog box I want it to work through this sequence and display the histogram.

Thanks,

Lisa

In your context what is data?
Having the interpreter execute:data->Draw()might be relying on the fact that the ‘proper’ ROOT file is the current directory. In particular that there is an object named ‘data’ stored in the current directory.
If ‘data’ is indeed supposed to come from a file, you might need do cd to it before executing “data->Draw”.

Cheers,
Philippe.

Hi,

Data is the name of the chain that contains the files of eveny data recorded by the detector. I’m not sure if your suggestion is possible because I have a gui in which I bring up a dialog box and enter the name of the chain that I want to display.

Lisa