Which library? :-)

Hola Rooterinos

I am compiling some code which loops over several rootfile inputs to create an array of canvases.

The code works OK, however I have two minor niggles.

  • Firstly, I would like to increase the label size.
    gStyle->SetLabelSize(0.06, “XY”); gives a seg fault, anything with gStyle does - which library do I need to include?

  • Secondly, I would like to clean up the 2D spectra by removing low stat regions.
    h[j]->SetMinimum(1000); or h[j]->GetZaxis()->SetRangeUser(1000,10000); both fail.

I compile via
g++ root-config --cflags -Wl,–no-as-needed -g -O2 paparazzi2.cpp -o paparazzi2 root-config --libs

I attach one of the canvas elements as an example and also my code.

Ta muchly

Ben

(I also get “Error in TTreeFormula::TTreeFormula: Index 70 for dimension #1 in cal[70] is too high (max is 31)”, but as errors go it is quite agreeable :slight_smile:

paparazzi2.cpp (2.28 KB)paparazzi2.cppDE_DE_Energy_120_run_274.png


You don’t need any special library for gStyle (i.e. “root-config --libs” is sufficient).

Fix (try “-W -Wall”):
paparazzi2.cpp:37: warning: unused variable ‘h’
paparazzi2.cpp:39: warning: ‘ii’ may be used uninitialized in this function

Replace:
"cal[%i]:cal[%i]>>h%i"
with something like (note: “>>” requires a NAME of a histogram):
“cal[%i]:cal[%i]>>h_%i(240,0,120,240,0,120)”

Fix topdown[j+1], which for j = 31 will try to access topdown[32], which does NOT exists.

Thankyou Coyote, a swift and helpful reply!

Indeed, now the axis labels can be adjusted.

However, without using an array of histograms, how might I set the minimum?
“h[j]->GetZaxis()->SetRangeUser(1000,reallybignumber);”

I know topdown[32] doesn’t exist - it draws something crazy. But then I write over that corner of the canvas, so in the end I think it’s ok (bad practice :slight_smile:

Try to create all histograms in a loop first (i.e. h[i] = new TH…), then use their names in TTree::Project and then you can change their ranges.

It’s a serious bug when you try to access array elements beyond array’s size.