Can i use Add in THnSparse?

hello,

I want to add two 6D histos in THnSparseD(root51703). I found the link
root.cern.ch/phpBB2/viewtopic.ph … ight=scale

So, I tried to use “Add” in THnSparse. For example,

hs1->THnSparseD::Add(hs2).

But after that, “hs1” did not change.

I want to know whether “Add” is the correct way to add two histos in THnSparse. And, if yes, what did i do wrong? If not, how should i do?

Thank you in advance.

Cheers,
Y.Cong

Hi,

I don’t think I implemented THnSparse::Add() yet :slight_smile: It’s surprising that you managed to call that non-existing function. But please send a patch if you are willing to implement it! It should use the algorithm applied in Projection(), too, i.e. only loop over filled bins.

Cheers, Axel.

Do you mean that there is no function to add two histos now? When do you plan to implement it? I am a new ROOT user, and I am no sure if I could do that.

Hi,

THnSparse is a brand new class; it’s available mainly for testing and to complete the implementation. I’ll let you know when it’s implemented. Of course you can add 1 to 3 dimensional histograms; 4 and more dimensional histograms should really stay a rare use case…

Cheers, Axel.

Thank you for your replies. I know it is just for testing now , so that I asked you the question. There is no good manual or HOWTO. I have other problems about THnSparse,

  1. After filling the histo (THnSparse case), if I want add number “5” to all the filled bins, what is the easy way you will choose?

2.could I use “Scale” in THnSparse? Or, is there other methods to normalize the histo?

3.could you help me to check this
root.cern.ch/phpBB2/viewtopic.php?t=5675

Hi,

none of your two (three, counting documentation :slight_smile: THnSparse requests is implemented so far. There is a tutorials/hist/sparsehist.C which shows how to use it, but that’s all. For your constant offset: we should probably offer a general all-bin offset such that the bins only store the difference to that offset. To be done…

Cheers, Axel.

hi,

I got some a new problem.

When I started to use THnSparse, I got this error message.


root [0] Int_t bins[2]={10,10}
root [1] Double_t xmin[2]={0.,0.}
root [2] Double_t xmax[2]={10.,10.}
root [3] THnSparseD hs(“hs”,“hs”,2,bins,xmin,xmax)
Error: Function THnSparseDhs(“hs”,“hs”,2,bins,xmin,xmax) is not defined in current scope (tmpfile):1:
*** Interpreter error recovered ***

I have to type “THnSparse” before “THnSparseD hs(…)” in order to use it. What did I do wrong?

==============
root [0] Int_t bins[2]={10,10}
root [1] Double_t xmin[2]={0.,0.}
root [2] Double_t xmax[2]={10.,10.}
root [3] THnSparse
Error: Symbol THnSparse is not defined in current scope (tmpfile):1:
Error in TCint::AutoLoadCallback: failure loading dependent library libMatrix.so for class THnSparse
Error in TCint::AutoLoadCallback: failure loading library libHist.so for class THnSparse
*** Interpreter error recovered ***
root [4] THnSparseD hs(“hs”,“hs”,2,bins,xmin,xmax)
root [5] (now I could use it)

Hi,

it’s a combination of magic and deficiency. THnSparse and THnSparseD are in a library that ROOT loads on demand. When you type THnSparse ROOT loads that library for you. That’s the magic. THnSparseD is a typedef to THnSparseT<Double_t> - and autoloading for typedefs doesn’t work yet. That’s the deficiency part.

So you can either do gSystem->Load(“libHist”) before using THnSparseD, or you can trigger the loading of that library by creating a (dummy) pointer of type THnSparse*, as in “THnSparse* whatever”.

We’ll fix the deficiency of not being able to autoload based on typedefs in the coming year.

Cheers, Axel.

Hi,

I get two new questions,

  1. There are some classes about high dimensional plot,
    root.cern.ch/root/Version517.news.html

Is it possible to plot n-D histos by “Parallel Coordinates Plots”?

  1. In TH2, if I want to subtract all (filled) bin content by a number, is there any function I can use?

Thanks

Hi,

sorry - sometimes posts just fall through the cracks - phpbb is not very good at telling us about posts that need to be answered… Anyway, your questions:

  1. yes, see $ROOTSYS/tutorials/tree/drawsparse.C.
  2. no, not that I know. You will have to call AddBinContent(bin, -2) for all bins.

Btw, scaling, operators (Add, Divide,…) and rebinning are now implemented in THnSparse.

Cheers, Axel.