TRestAnalysisPlot colorbar options for hit maps

REST version : v2.3.4
REST commit : 30b4091f

Hello,

I am drawing hit maps, and I have few naive questions.

  • I need to use the same scale in order to easily compare the maps. How can I set it? The “range” options does not work.
  • Is there a way to change the color palette?
  • The colorbar units are keV, right?

The rml file is attached.
Thanks for the help!

hitmap.rml (2.5 KB)

Hi Barbara,

sorry for the delay,

I know there is an option at the <plot construction named norm.

See for example the implementation inside TRestAnalysisPlot.cxx,

plot.normalize = StringToDouble(GetParameter("norm", plotele, ""));

If you give the option norm="1" it will adjusts the contents of the histogram bins so that the integral is equal to 1.

I have seen this working with TH1D histograms, but never tested with TH2D. Probably there is no big difference, and it just should work. Please, let me know in any case.

There is not such option directly at TRestAnalysisPlot right now. Although it might not be hard to integrate. I will add it as an issue to github so that it is at least on the list of things todo.

But … an option is always to save your plot as .C or .root so that you can recover the histogram later on.

If, instead of save="plot.pdf" you write save="plot.C" you will save the generated plot as a macro that will generate the histogram. You can then modify the macro.

To change the palette it is something like

gStyle->SetPalette(kRainBow);

See TColor reference.

https://root.cern.ch/doc/master/classTColor.html

So, probably, something like

root
[0] gStyle->SetPalette(kRainBow);
[1] .L plot.C

should work, but if it does not, perhaps it is because gStyle->SetPalette(xxx) is being called from the plot.C macro itself.

Please, let us know how the problem solves finally.

No, when you create a TH2D Histogram with 2 variables, it will fill a histogram by units

I.e.

histo2D->Fill(hitsAna_xMean, hitsAna_yMean);

will increase the corresponding bin by 1.

There is another call where you are allowed to add a weight (that could be the corresponding energy in keV). But it is not the case for us. We do not have a weight option here :(.

Instead, you could create a <cut on hitsAna_energy in order to create a hitmap on a specific energy range.

Actually, I believe the option exists. I had a better look inside TRestAnalysisPlot.cxx, and the palette is set before generating the plots

st->SetPalette(fPaletteStyle);

The member fPaletteStyle is initialised somewhere else in the code

fPaletteStyle = StringToInteger(GetParameter("paletteStyle", canvasdef, "57"));

which corresponds in fact to an option from <canvas definition.

As, you see it takes by default 57, which is kBird. To set-up the rainbow style you could set the following at the canvas definition.

<canvas .... paletteStyle="55" />
1 Like

Hello Javier,

  • to change the color palette the solution <canvas … paletteStyle=“55” /> works! For everybody convenience, the color-palette numbers can be retrieved here:
    ROOT: TColor Class Reference

  • I still have some issues with the options norm=“1” to get the same scale for the hitmaps. I set this condition in
    plot name=“HitMap” title=“Hit map” xlabel=“x (mm)” ylabel=“y (mm)” option=“colz” legend=“off” logscale=“false” save="" value=“ON” norm=“1”
    I try to set different norm values. Actually, the scale of the colorbar changes, but the plot remain unchanged (see attached files).

Thanks for the help!

I guess it is just auto-ranging the color to match the range of the histogram. So in principle I would say that makes sense.

Having a look at the root-forum, there are similar questions on how to play with colorbar

Perhaps what you are looking for is:

h->GetZaxis()->SetRangeUser(0.9, 1.1);

Save the histogram as a .C macro and recover the histogram pointer *h, then you can play around with all the ROOT options.