Root exiting without any error

This is a duplicate of previously asked question in the forum. In my case though I don’t think its a memory issue(could be). I normally load a cpp file containing functions, call a particular function to make rapidity list and then call this block of code. After removing all the newbie errors, root just exits now without plotting the graph. Any help on the matter would be appreciated.

{  //Code for plotting d(rapidity)/d(N) vs rapidity;  rapidity is denoted by y
    TH1D *h1= new TH1D("h1","rapidity distribution",40,-5,5);
    double listdydn[40];              //array for containing dy/dn--------y axis
    double listycent[40];              //array for containing centers of each bin (rapidity)-----x axis
    for (double i :listphi){               //*Filling the Histogram;
        h1->Fill(i);                    //list phi is vector containing rapidity entries
    for (int j=0 ;j<40;j++){            //*Taking counts from each bin, subtracting adjacent bin heights and dividing by bin width
        int l= h1->GetBinContent(j);
        int u= h1->GetBinContent(j+1);
    TGraph *g2= new TGraph(40,listdydn,listycent);

This is the link to my GitHub repo containing the .cpp file which creates rapidity list from a dat file(ampt.dat)(this seems to be working fine).

_ROOT Version:6.26
_Platform: Windows
_Compiler: Clang

This can happen when running Cling and the macro has some error. In your code above, where is listphi defined ?


Try with:
listdydn[j] = ((u-l) ? (((5.-(-5.)/40.))/(u-l)) : 0.);

1 Like

Thankyou! It worked.

The listphi is defined in this.cpp file.

It seems to me that you actually want “((5.-(-5.))/40.)” instead of “((5.-(-5.)/40.))”.

I did fix that. Thanks!

And I think you could make your procedure more “robust” (in case you ever change the histogram’s binning or limits):
listdydn[j] = ((u - l) ? (h1->GetBinWidth(j) / (u - l)) : 0.);

1 Like