Get specific value form 2D-array

Hi,

I have several root files and want to get value from 2D-array to make a histogram.
But I only need [1~6]x[1~3], [1~6]x[1~3], [1~6]x[1~3] data of my 9x5 array.
First I chain all of them first, then do:
mychain->SetBranchAddress("dth",&dth); Long64_t nentries = mychain->GetEntries(); for(Int_t i=0;i<nentries;i++){mychain->GetEntry(i);.......
Then I can’t find out anyway to do it…Should I store it into Vector, or is there another faster and better way to do?

Thanks.

What is your favorite way of access the data (i.e. for example when you don’t need the filtering) [Asking so we can tweak that method rather introducing a new one].

Cheers,
Philippe.

Hi,

I used:

  mychain->SetBranchAddress("dth",&dth);
  vector<Double_t> xpos;
  vector<Double_t> ypos;
  vector<Double_t> zpos;
  
  for(Int_t i=0;i<nentries;i++){
    mychain->GetEntry(i);
    
    for(Int_t j=1,k=1,l=1;j<7,k<7,l<7;i++,j++,l++){
    xpos.push_back(dth[j][1]);
    ypos.push_back(dth[k][2]);
    zpos.push_back(dth[l][3]);
    }
  }

  TH1D *histo = new TH1D(xpos.data());

Then it turned out:

Warning: Illegal numerical expression 7,k eldth2.cpp:55:
Warning: Illegal numerical expression 7,k eldth2.cpp:55:
Warning: Illegal numerical expression 7,l eldth2.cpp:55:
Error: Array index out of range dth -> [46]  valid upto dth[8][4] eldth2.cpp:56:
*** Interpreter error recovered ***

Rather than

j<7,k<7,l<7;

you meant

j<7 && k<7 && l<7;

Cheers,
Philippe

It’s really dumb that I didn’t notice it…Thanks!
But after I correct it I got:

Error: Can't call vector<double,allocator<double> >::data() in current scope eldth2.cpp:60:
Possible candidates are...
(in vector<double,allocator<double> >)
*** Interpreter error recovered ***

This is odd and seems like a bug in CINT. I recommend that either compile the scrip with ACLiC or upgrade to using ROOT v6.10.

Cheers,
Philippe.

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