I don’t think I implemented THnSparse::Add() yet 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.
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.
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…
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,
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?
none of your two (three, counting documentation 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…
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)
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.
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:
yes, see $ROOTSYS/tutorials/tree/drawsparse.C.
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.