Fit an histogram from VC++

Dear rooters,

I am trying to fit a TH1F histogram with the Fit function. I do it from Microsoft Visual Studio c++, where I included all libraries and .dll of root. The program compiles and links, but I get the following error when executing: “Unhandled exception in file_name.exe(LIBHIST.DLL): 0xC0000005:Access Violation”.

I know that the histogram is created and filled, the problem appears when I try to fit it to the simple gaus function. Could you tell me the reason and help me to solve it?.

I am using Windows 2000.

Thank you very much in advance,

Berta Escat.

Please identify which version of ROOT.
In case you use a version older than 4.02, please try with this version
and follow the rules described at:
root.cern.ch/root/roottalk/RoottalkRules.html

Rene

Now I am using version 4.02 of root and I get the following error message when I try to fit a TH1 histogram (which is created an filled with no problems): " Unhandled exception in 0x1003dc4c in file_name.exe 0xC0000005: Access Violation when reading 0x00000000"

What can I do to solve the problem?,

thanks in advance,

Berta.

Please send the shortest possible running script reproducing the problem.
If the script requires a data file send the data file too.

Rene

Hello,
I send you the script and the data file. I am compiling with VC++ including the following libraries of root: libhist.lib, libcore.lib, libGraf.lib,
libGui.lib, libGpad.lib.

Thanks,

Berta.
Data.txt (700 KB)
HistTest.cpp (823 Bytes)
HistTest.cpp (823 Bytes)

Hi Berta,

I have no problem with your code on NT4 and XP VC++6 :

C:\home\bellenotb\temp\test>test
 FCN=59584.6 FROM MIGRAD    STATUS=CONVERGED     164 CALLS         165 TOTAL
                     EDM=5.47744e-007    STRATEGY= 1      ERROR MATRIX ACCURATE

  EXT PARAMETER                                   STEP         FIRST
  NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE
   1  Constant    2.64233e+001  1.34319e+000
   2  Mean        1.31536e+002  6.22425e-001
   3  Sigma       1.12697e+001  5.94032e-001
Fit results:26.4233 131.536 11.2697 %

C:\home\bellenotb\temp\test>

Could you send your makefile/project file ?

Cheers,
Bertrand.

Hello Bertrand,
I send you the project file HistTest.dsp and the workspace file HistTest.dsw.
I execute it on Windows 2000 VC++ 6.0 I and I get the following error
when it tries to fit the hisogram at line 27 of HistTest.cpp: “Unhandled exception in HistTest.exe (LIBHIST.DLL) 0xC0000005: Access Violation”.

Could you send me your project and your workspace file in order to try them in my system?.

Thank you very much for your help,

Berta.

Hello Bertrand,

I try to send you again de HistTest.dsp and HistTest.dsw, but it didn´t work because extensions dsp and dsw are not allowed to attach.
I changed the extensions of this files in order to be able to attach them, now they are called HistTest_project.txt (rename it as HistTest.dsp) and HistTest_workspace.txt (rename it as HistTest.dsw).
I hope I can send them now, cheers and thanks,

Berta.
HistTest_workspace.txt (539 Bytes)
HistTest_project.txt (4.14 KB)

Hi Berta,

Your dsp file has no source file specified !
Please take a look at the ones attached here.

Cheers,
Bertrand.
test_dsw.txt (531 Bytes)
test_dsp.txt (4.58 KB)

Hi Bertrand,
I have specified the sources in my dsp file, but I continue having the same error when executing.

I guess the problem is at libHist.dll and/or at libMatrix.dll, libCore.dll, libCint.dll. I have them form root 4.02. Which version of root are you using?. Do you use the dll that you got when you downloaded root or did you build them from the sources?. Could you please send me these four dll?,

than you,

Berta.

Berta,

I tried with latest version (CVS) and also with version downloaded from web : 4.02/00 and 4.02/00 debug. Each version works just fine…
If you have the debug version, you can try to open the debugger to see where it crashes.

Bertrand.

Hello Bertrand,
I have downloaded 4.02/00 debug version and followed the instructions from web, and the problem was solved, now I can fit the histogram!, thank you very much for your help!.

But… when I try to create a canvas I get the following message in the console: “Warning in ::SetProgname: Wrong Program path”. Then, the execution finishes without errors, but no canvas is created, do you know what can I do to solve this?. I have included Windows4Root.h before the TCanvas.h class.

Thanks again,

Berta.

Hi Berta,
what is %ROOTSYS%, %PATH% (is %ROOTSYS%/bin part of %PATH%?), and what is the name of the directory where your program is? Where is the version of root installed which you used when building your program - is this the same as %ROOTSYS%? Make sure none of the above directories contain spaces, i.e. ROOTSYS=“C:\Program Files\root” is no good.
Axel.

Hi Axel,
my %ROOTSYS% is “C:\root_v4.02.00.win32gdk.debug\root”,
%ROOTSYS%/bin IS part of %PATH%,
the name of the directory where my program is is “D:\Usuarios\Berta\Programas\ValidacionFisica”,
the version of root installed which I use when building my program is the same as %ROOTSYS%, and none of the directories contains spaces, so, I don´t understand why no canvas is shown when I execute the program…

Do you have any further tip?, thanks,

Berta.

Hi Berta,
you need to create a TApplication object if you want graphics output. The error message is a symptom for not having one.

In your int main(int argc, char** argv) (this is the “real” name of the main function - if you don’t have parameters for it then please add them), add the following before creating any graphics output:

Axel.

Hi Axel,
I wrote the sentence:
TApplication myApp(“myApp”, &argc, argv);
in the main program. Then, I don´t get any warning, but nevertheless no canvas is shown when I execute the program. So, the problem remains, do you know what else can I do?,
cheers,
Berta.

Hi Berta,
you probably exit your program before root manages to show the TCanvas. Use TApplication::Run.
Axel.

Hi Axel,
I wrote:

TApplication myApp(“myApp”, &argc, argv);
myApp.Run();

in the main program. Then, when I execute the program I get a ROOT session console where the execution doesn´t runs further. This of course doesn´t solve the problem, I would like that a canvas is shown directly, without opening any ROOT session, is it possible?,

thanks again,

Berta.

Hi Berta,
this should work:

int main(int argc, char** argv) { TApplication myApp("myApp",argc, argv); new TCanvas(); myApp.Run(); }
I just realized that there is no generic example in the users’ guide; TApplication only shows up in connection with the GUI topic. I’ll ask Ilka what she thinks about that.
Axel.

Hello Axel,
when I write the code:
int main(int argc, char** argv) {
TApplication myApp(“myApp”,&argc, argv);
new TCanvas();
myApp.Run();
}

I get the following error when compiling: " ‘TObject::operator new’: no overloaded function accepts 3 arguments".

Then, I tried to use the standard “new operator” with the code:
int main(int argc, char** argv) {
TApplication myApp(“myApp”,&argc, argv);
TCanvas *tc = ::new TCanvas();
myApp.Run();
}
With this, the program compliles and a canvas and a ROOT session are shown when executing. But, when I want to close the session via the canvas menu File->QuitROOT I get an “unhandled error”. Do you know why this happens?. Is possible to show the canvas without oppening any ROOT session console?.

Thanks,

Berta.