Error plotting on log scale

Hello everyone,

I attached a picture of my plot. It shows the problem, that for entries below 1 with associated errors below 1, the errors are drawn very weird on a log-scale. Can anyone explain this and maybe help me fix it? Is this simply, because for values lower than 1, e.g log(0.99), this value is negative and therefore cannot be represented in log?


Can you post a script reproducing this problem ?

for (int entries = 0; entries < uniqueTimes.size(); entries++){
        nonzero_empty_peak_store_ar[entries] = averagedCounts[entries];
        nonzero_empty_peak_store_error_ar[entries] = errorOfAveragedCounts[entries];
        storingtimings_ar[entries] = uniqueTimes[entries];
    }


    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // FITTING STORAGE CURVE
    times->cd(1);
    gPad->SetGrid();
    gPad->SetLogy();

    // create the TGraphErrors and draw it
    int length_ar = sizeof(nonzero_empty_peak_store_ar)/sizeof(nonzero_empty_peak_store_ar[0]);
    TGraphErrors *storing_times = new TGraphErrors(length_ar, storingtimings_ar, nonzero_empty_peak_store_ar, 0, nonzero_empty_peak_store_error_ar);
    storing_times->GetXaxis()->SetTitle("Storing time [s]");
    storing_times->GetYaxis()->SetTitle("Counts in emptying peak");
    storing_times->GetXaxis()->SetRangeUser(0,extractedNumbers_array[last_number][3]);
    storing_times->SetMarkerColor(4);
    storing_times->SetMarkerStyle(1);
   storing_times->Draw("AP");
}

Essentially, the problem is that the array nonzero_empty_peak_store contains events which are below 1, see above.

It should be fine. can you provide the TGraphErrors producing this plot ?

What do you mean exactly? The definition of the TGraphErrors producing the shown plot is already attached before as storing_times

The TGraphErrors is defined with:

    TGraphErrors *storing_times = new TGraphErrors(length_ar, storingtimings_ar, nonzero_empty_peak_store_ar, 0, nonzero_empty_peak_store_error_ar);

But the script does not provide the vectors used to build it… the values …

void wfelix() {
   for (int entries = 0; entries < uniqueTimes.size(); entries++){
      nonzero_empty_peak_store_ar[entries] = averagedCounts[entries];
      nonzero_empty_peak_store_error_ar[entries] = errorOfAveragedCounts[entries];
      storingtimings_ar[entries] = uniqueTimes[entries];
   }

   times->cd(1);
   gPad->SetGrid();
   gPad->SetLogy();

   // create the TGraphErrors and draw it
   int length_ar = sizeof(nonzero_empty_peak_store_ar)/sizeof(nonzero_empty_peak_store_ar[0]);
   TGraphErrors *storing_times = new TGraphErrors(length_ar, storingtimings_ar, nonzero_empty_peak_store_ar, 0, nonzero_empty_peak_store_error_ar);
   storing_times->GetXaxis()->SetTitle("Storing time [s]");
   storing_times->GetYaxis()->SetTitle("Counts in emptying peak");
   storing_times->GetXaxis()->SetRangeUser(0,extractedNumbers_array[last_number][3]);
   storing_times->SetMarkerColor(4);
   storing_times->SetMarkerStyle(1);
   storing_times->Draw("AP");
}

Gives:

root [0] .x wfelix.C
In file included from input_line_12:1:
/Users/couet/roottest/wfelix.C:2:36: error: use of undeclared identifier 'uniqueTimes'
   for (int entries = 0; entries < uniqueTimes.size(); entries++){
                                   ^
/Users/couet/roottest/wfelix.C:3:7: error: use of undeclared identifier 'nonzero_empty_peak_store_ar'
      nonzero_empty_peak_store_ar[entries] = averagedCounts[entries];
      ^
/Users/couet/roottest/wfelix.C:3:46: error: use of undeclared identifier 'averagedCounts'
      nonzero_empty_peak_store_ar[entries] = averagedCounts[entries];
                                             ^
/Users/couet/roottest/wfelix.C:4:7: error: use of undeclared identifier 'nonzero_empty_peak_store_error_ar'
      nonzero_empty_peak_store_error_ar[entries] = errorOfAveragedCounts[entries];
      ^
/Users/couet/roottest/wfelix.C:4:52: error: use of undeclared identifier 'errorOfAveragedCounts'
      nonzero_empty_peak_store_error_ar[entries] = errorOfAveragedCounts[entries];
                                                   ^
/Users/couet/roottest/wfelix.C:5:7: error: use of undeclared identifier 'storingtimings_ar'
      storingtimings_ar[entries] = uniqueTimes[entries];
      ^
/Users/couet/roottest/wfelix.C:5:36: error: use of undeclared identifier 'uniqueTimes'
      storingtimings_ar[entries] = uniqueTimes[entries];
                                   ^
/Users/couet/roottest/wfelix.C:8:9: error: member reference base type 'clock_t (struct tms *)' (aka 'unsigned long (tms *)') is not a structure or union
   times->cd(1);
   ~~~~~^ ~~
/Users/couet/roottest/wfelix.C:13:27: error: use of undeclared identifier 'nonzero_empty_peak_store_ar'
   int length_ar = sizeof(nonzero_empty_peak_store_ar)/sizeof(nonzero_empty_peak_store_ar[0]);
                          ^
/Users/couet/roottest/wfelix.C:13:63: error: use of undeclared identifier 'nonzero_empty_peak_store_ar'
   int length_ar = sizeof(nonzero_empty_peak_store_ar)/sizeof(nonzero_empty_peak_store_ar[0]);
                                                              ^
/Users/couet/roottest/wfelix.C:14:62: error: use of undeclared identifier 'storingtimings_ar'
   TGraphErrors *storing_times = new TGraphErrors(length_ar, storingtimings_ar, nonzero_empty_peak_store_ar, 0, nonzero_empty_peak_store_error_ar);
                                                             ^
/Users/couet/roottest/wfelix.C:14:81: error: use of undeclared identifier 'nonzero_empty_peak_store_ar'
   TGraphErrors *storing_times = new TGraphErrors(length_ar, storingtimings_ar, nonzero_empty_peak_store_ar, 0, nonzero_empty_peak_store_error_ar);
                                                                                ^
/Users/couet/roottest/wfelix.C:14:113: error: use of undeclared identifier 'nonzero_empty_peak_store_error_ar'
   TGraphErrors *storing_times = new TGraphErrors(length_ar, storingtimings_ar, nonzero_empty_peak_store_ar, 0, nonzero_empty_peak_store_error_ar);
                                                                                                                ^
/Users/couet/roottest/wfelix.C:17:46: error: use of undeclared identifier 'extractedNumbers_array'
   storing_times->GetXaxis()->SetRangeUser(0,extractedNumbers_array[last_number][3]);
                                             ^
/Users/couet/roottest/wfelix.C:17:69: error: use of undeclared identifier 'last_number'
   storing_times->GetXaxis()->SetRangeUser(0,extractedNumbers_array[last_number][3]);
                                                                    ^
root [1] 

Oh, I see: Here are the values:
storingtimings_ar = [1, 26, 51, 76, 101, 126, 151, 176, 201, 226, 251, 276, 301, 326, 351, 376, 401, 426, 451, 476, 501, 526, 551, 576, 601, 626, 651, 676, 701, 726, 751, 776, 801, 826, 851, 876, 901, 926, 951, 976, 1001, 1026, 1051, 1076, 1101, 1126, 1151, 1176, 1201, 1301, 1401, 1601, 1701, 1801]

nonzero_empty_peak_store_ar = [5431.25, 2172.69, 1367.94, 924.546, 780.802, 651.444, 569.655, 501.568, 445.997, 404.471, 352.558, 302.706, 332.281, 249.424, 258.842, 215.506, 181.439, 200.572, 160.481, 153, 160.407, 136.933, 128.813, 107.899, 89.6262, 76.543, 90.1961, 90.4481, 65.6103, 48.6211, 71.4096, 70.6644, 54.6096, 31.582, 51.6741, 36.5128, 37.693, 37.6006, 28.9041, 24.8275, 31.7555, 27.8355, 27.797, 16.962, 13.8218, 15.8872, 18.9159, 12.9927, 12.4403, 11.8494, 5.91972, 3.97934, 0.990924, 0.995243]

error_nonzero_empty_peak_store_ar = [73.697, 46.6121, 36.9857, 30.4063, 27.9428, 25.5234, 23.8675, 22.3957, 21.1186, 20.1115, 18.7765, 17.3985, 18.2286, 15.7932, 16.0886, 14.6801, 13.4699, 14.1624, 12.6681, 12.3693, 12.6652, 11.7018, 11.3496, 10.3874, 9.46711, 8.74889, 9.49716, 9.51042, 8.10002, 6.97289, 8.45042, 8.40621, 7.38983, 5.61979, 7.18847, 6.04258, 6.13946, 6.13193, 5.37625, 4.98272, 5.6352, 5.27594, 5.27229, 4.1185, 3.71776, 3.98587, 4.34924, 3.60454, 2.49402, 3.4423, 2.43305, 1.99483, 0.995452, 0.997619]

This should be enough to simply reproduce the plot, right?

It would be help full if you make the script yourself and test it before posting it. We will gain time.

Sure thing.
I just wanted to see if there is anything particular about values below 1 in log scale plots…

Lets make the script and it will be easier to to discuss it with a running example…

This one works:

// ROOT TEST //

// load needed libraries
#include
#include
#include
#include
#include
#include <TFile.h>
#include
#include <TTree.h>

using namespace std;

void test()
{
Double_t storingtimings_ar[60] = {1, 26, 51, 76, 101, 126, 151, 176, 201, 226, 251, 276, 301, 326, 351, 376, 401, 426, 451, 476, 501, 526, 551, 576, 601, 626, 651, 676, 701, 726, 751, 776, 801, 826, 851, 876, 901, 926, 951, 976, 1001, 1026, 1051, 1076, 1101, 1126, 1151, 1176, 1201, 1301, 1401, 1601, 1701, 1801};
Double_t nonzero_empty_peak_store_ar[60] = {5431.25, 2172.69, 1367.94, 924.546, 780.802, 651.444, 569.655, 501.568, 445.997, 404.471, 352.558, 302.706, 332.281, 249.424, 258.842, 215.506, 181.439, 200.572, 160.481, 153, 160.407, 136.933, 128.813, 107.899, 89.6262, 76.543, 90.1961, 90.4481, 65.6103, 48.6211, 71.4096, 70.6644, 54.6096, 31.582, 51.6741, 36.5128, 37.693, 37.6006, 28.9041, 24.8275, 31.7555, 27.8355, 27.797, 16.962, 13.8218, 15.8872, 18.9159, 12.9927, 12.4403, 11.8494, 5.91972, 3.97934, 0.990924, 0.995243};
Double_t error_nonzero_empty_peak_store_ar[60] = {73.697, 46.6121, 36.9857, 30.4063, 27.9428, 25.5234, 23.8675, 22.3957, 21.1186, 20.1115, 18.7765, 17.3985, 18.2286, 15.7932, 16.0886, 14.6801, 13.4699, 14.1624, 12.6681, 12.3693, 12.6652, 11.7018, 11.3496, 10.3874, 9.46711, 8.74889, 9.49716, 9.51042, 8.10002, 6.97289, 8.45042, 8.40621, 7.38983, 5.61979, 7.18847, 6.04258, 6.13946, 6.13193, 5.37625, 4.98272, 5.6352, 5.27594, 5.27229, 4.1185, 3.71776, 3.98587, 4.34924, 3.60454, 2.49402, 3.4423, 2.43305, 1.99483, 0.995452, 0.997619};

auto c = new TCanvas("c", "TEST", 1500, 900);
c->Divide(1,1);
c->cd(1); 
gPad->SetLogy();

Double_t length_ar = sizeof(nonzero_empty_peak_store_ar)/sizeof(nonzero_empty_peak_store_ar[0]);
TGraphErrors *storing_times = new TGraphErrors(length_ar, storingtimings_ar, nonzero_empty_peak_store_ar, 0, error_nonzero_empty_peak_store_ar);
storing_times->GetXaxis()->SetTitle("Storing time [s]");
storing_times->GetYaxis()->SetTitle("Counts in emptying peak");
storing_times->SetMarkerColor(4);
storing_times->SetMarkerStyle(1);
storing_times->Draw("AP");

}

Somehow, it doesn’t print the include <iostream brackets correctly.

I get this:

Exactly, I get the same. When you set the y-range from 0 to 10, you see the problem.

Which command are you using the set the Y range ?

I just used the interactive graph plot thing and chose SetRangeUser.
What’s even more weird: if I change the last two values to values above 1 (so both the value and its error), I STILL get the weird line in the log plot…

This is for the same values, except the values which were before 0.99 something I changed with values above 1:

This is what I have now:

void wfelix() {
   const int n = 54;
   double x[n] =  {  1,   26,   51,   76,  101,  126,  151,  176,  201,  226,
                   251,  276,  301,  326,  351,  376,  401,  426,  451,  476,
                   501,  526,  551,  576,  601,  626,  651,  676,  701,  726,
                   751,  776,  801,  826,  851,  876,  901,  926,  951,  976,
                  1001, 1026, 1051, 1076, 1101, 1126, 1151, 1176, 1201, 1301,
                  1401, 1601, 1701, 1801};

   double y[n] =  {5431.25, 2172.69,  1367.94,  924.546, 780.802, 651.444, 569.655, 501.568, 445.997, 404.471,
                   352.558, 302.706,  332.281,  249.424, 258.842, 215.506, 181.439, 200.572, 160.481,     153,
                   160.407, 136.933,  128.813,  107.899, 89.6262,  76.543, 90.1961, 90.4481, 65.6103, 48.6211,
                   71.4096, 70.6644,  54.6096,   31.582, 51.6741, 36.5128,  37.693, 37.6006, 28.9041, 24.8275,
                   31.7555, 27.8355,   27.797,   16.962, 13.8218, 15.8872, 18.9159, 12.9927, 12.4403, 11.8494,
                   5.91972, 3.97934, 0.990924, 0.995243};

   double e[n] =  {73.697 , 46.6121,  36.9857,  30.4063, 27.9428, 25.5234, 23.8675, 22.3957, 21.1186, 20.1115,
                   18.7765, 17.3985,  18.2286,  15.7932, 16.0886, 14.6801, 13.4699, 14.1624, 12.6681, 12.3693,
                   12.6652, 11.7018,  11.3496,  10.3874, 9.46711, 8.74889, 9.49716, 9.51042, 8.10002, 6.97289,
                   8.45042, 8.40621,  7.38983,  5.61979, 7.18847, 6.04258, 6.13946, 6.13193, 5.37625, 4.98272,
                    5.6352, 5.27594,  5.27229,   4.1185, 3.71776, 3.98587, 4.34924, 3.60454, 2.49402,  3.4423,
                   2.43305, 1.99483, 0.995452, 0.997619};

   auto c = new TCanvas();
   c->SetLogy();
   c->SetGridy(1);

   double le;
   for (int i = 0; i<n; i++) {
      le = y[i]-e[i];
      if ( le <0) {
         printf("Point number %d has an invalid low level error value %g in log scale\n",i,le);
         e[i] = e[i]+1.01*le;
      }
   }

   auto g = new TGraphErrors(n, x, y, 0, e);
   g->Draw("AP");
   g->GetYaxis()->SetRangeUser(0.00001,1500.);
   g->SetMarkerStyle(20);
}
  • I simplified the variable name to make easier to read (for myself)
  • I put the right domesion for the vector (there is 54 etries not 60)
  • I made loop to check te validity of the low error (negative value are invalid)
  • if a negative valu is found I make it positive.
  • I set the Y axis range in the macro.

When I execute the macro I get:

root [1] .x wfelix.C
Point number 52 has an invalid low level error value -0.004528 in log scale
Point number 53 has an invalid low level error value -0.002376 in log scale

And the plot is:

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