#include "TH1.h" #include "TH2.h" #include "TH3.h" #include "THnSparse.h" #include "TCanvas.h" #include "TFile.h" #include #include using namespace std; int main() { Int_t bins[2] = {1, 5}; THnSparseD* fSparse = new THnSparseD("hs", "hs", 2, bins); Int_t i; for(i=0;i<2;i++){ Double_t arrBinEdges[2][6] = {{0,12},{0,2.4,3,4,8,10}}; //fSparse->GetAxis(i)->Set(bins[i], arrBinEdges[i]); fSparse->SetBinEdges(i, arrBinEdges[i]); } Double_t Data1[10][2] = {{2,5},{3,5},{4,5},{6,5},{2,5},{3,9},{1,6},{5,5}, {8,7},{2,9}}; Int_t j; for(j=0;j<10;j++){ fSparse->Fill(Data1[j]); } Int_t ndims; ndims = fSparse->GetNdimensions(); //cout << ndims<<"\n"; Int_t* x = new Int_t[ndims]; memset(x, 0, sizeof(Int_t) * ndims); for (Long64_t k = 0; k < fSparse->GetNbins(); ++k) { Double_t v = fSparse->GetBinContent(k, x); printf("sparse%d", ndims); for (Int_t d = 0; d < ndims; ++d){ printf("[%d]", x[d]); printf(" = %g\n", v); } } Double_t BinLowEdge; BinLowEdge = fSparse->GetAxis(1)->GetBinLowEdge(2); cout <Projection(1); twod_plot->Draw(); return 0; }