TH2D Fill problem

Hi, I just want to fill a TH2D graph with two for-loops and arrays, how to change my script? Thanks!

using namespace std;

void test()
{
        TH2D *h = new TH2D("h","",100,0,18,100,0,27);

        double x[9];
        double y[9][9],z[9][9];
        double k;

        for(int i=1;i<10;i++){
                k=i;
                x[i] = 2*k;
                double l;
                for(int j=1;j<10;j++){
                        l=j;
                        y[i][j] = 3*l;
                        z[i][j] = y[i][j]*x[i];
//                      cout<<z[i][j]<<endl;
                        h->Fill(y[i],z[i]);
                }
        }

        auto c1 = new TCanvas("c1","",800,600);
        c1->cd();
        h->Draw("cont");
}

Array elements are always numbered from 0, not from 1.

Still doesn’t work.

Attach your improved source.

Here are the error Alerts:
error: no matching member function for call to ‘Fill’
h->Fill(y[i],z[i]);
~^~
/builddir/build/BUILD/root-6.22.08/x86_64-redhat-linux-gnu/include/TH2.h:58:13: note: candidate function not viable: no known conversion from ‘double [9]’ to 'const char ’ for 1st argument
Int_t Fill(const char
, Double_t) { return Fill(0);} //MayNotUse
^
/builddir/build/BUILD/root-6.22.08/x86_64-redhat-linux-gnu/include/TH2.h:75:21: note: candidate function not viable: no known conversion from ‘double [9]’ to ‘Double_t’ (aka ‘double’) for 1st argument
virtual Int_t Fill(Double_t x, Double_t y);
^
/builddir/build/BUILD/root-6.22.08/x86_64-redhat-linux-gnu/include/TH2.h:57:13: note: candidate function not viable: requires 1 argument, but 2 were provided
Int_t Fill(Double_t); //MayNotUse
^
/builddir/build/BUILD/root-6.22.08/x86_64-redhat-linux-gnu/include/TH2.h:76:21: note: candidate function not viable: requires 3 arguments, but 2 were provided
virtual Int_t Fill(Double_t x, Double_t y, Double_t w);
^
/builddir/build/BUILD/root-6.22.08/x86_64-redhat-linux-gnu/include/TH2.h:77:21: note: candidate function not viable: requires 3 arguments, but 2 were provided
virtual Int_t Fill(Double_t x, const char *namey, Double_t w);
^
/builddir/build/BUILD/root-6.22.08/x86_64-redhat-linux-gnu/include/TH2.h:78:21: note: candidate function not viable: requires 3 arguments, but 2 were provided
virtual Int_t Fill(const char *namex, Double_t y, Double_t w);
^
/builddir/build/BUILD/root-6.22.08/x86_64-redhat-linux-gnu/include/TH2.h:79:21: note: candidate function not viable: requires 3 arguments, but 2 were provided
virtual Int_t Fill(const char *namex, const char *namey, Double_t w);
^

You need: h->Fill(y[...][...], z[...][...]);

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.