Problem with segmaentation violation (TGraph)

Good morning,
I wrote a root macro that fit a data set (attached file). However when I try to run it, ROOT give me this error: “*** Break *** segmentation violation”

Fit.C (2.9 KB)
Prova.txt (683 Bytes)

I tried to use “SetPameter” for TGraph but it gives me this error “cannot initialize a parameter of type ‘Double_t’ (aka ‘double’) with an lvalue of type 'double []” what am I doing wrong?

Do not call your macro Fit, as root already has a Fit function and this confuses it. If you call it myFit, for instance, the macro works (the fit fails on your data, by the way, but at least it runs).
Similarly, it’s better to avoid using variable names so similar to reserved words, like “Cout”, “Int”, etc. which, although strictly speaking are ok, are error magnets (as your use of “Fit” exemplifies).

Your problems have nothing to do with your function’ nor variables’ names.
Please always try to precompile your macro using ACLiC:

root [0] .L Fit.C++

Then fix all reported bugs and warnings:

// ...
#include<sstream>
// ...
  double y_min = 0, sum = 0;
  int i = 0;
  // ...
  ifstream myfile (input_name.c_str()); // for ROOT 5 compatibility
1 Like

I don’t understand these mistakes.

Wikipedia -> Uninitialized variable

I have the same problem"Break…" with a large file (9.8 Mbyte) why?

Try (it should tell you where it died):

root [0] .x Fit.C++g

Thanks! It works! But what has changed? Why the extra g?

ROOT User’s Guide -> The C++ Interpreter Cling -> ACLiC: Compiling Scripts Into Libraries

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