Trouble with 2D array branch

Hi,

I am trying store invariant mass combinations by using a 2D array as a branch

myTree->Branch("singlemuid_massCBOS", &Mysinglemuid_massCBOS, "singlemuid_massCBOS[mu_muid_n][mu_muid_n]/F");
.
.
.
for (int i=0; i<mu_muid_n;++i){
       for (int j=i+1; j<mu_muid_n; ++j){
          /*TLorentzVector v1 = lv(Mymu_muid_pt[i],Mymu_muid_eta[i],Mymu_muid_phi[i]);
          TLorentzVector v2 = lv(Mymu_muid_pt[j],Mymu_muid_eta[j],Mymu_muid_phi[j]);
          TLorentzVector vSum = v1 + v2;
          Mymuid_massCB[index] = vSum.M()/1000.;*/


          if ((Mymu_muid_charge[i]*Mymu_muid_charge[j]) < 0){
          TLorentzVector v1OS = lv(Mymu_muid_pt[i],Mymu_muid_eta[i],Mymu_muid_phi[i]);
          TLorentzVector v2OS = lv(Mymu_muid_pt[j],Mymu_muid_eta[j],Mymu_muid_phi[j]);
          TLorentzVector vSumOS = v1OS + v2OS;

          //2D array that stores combinations of OS invMass 
          Mysinglemuid_massCBOS[i][j] = vSumOS.M()/1000.;
          }
.
.
.
   myTree->Fill() ;       

If I std::cout these values, they look fine. However, when I write them to a branch and try to draw, the histogram shows only values of 0. The same information written to a 1D array works fine. Does anyone know why 2D array branches won’t fill properly?

Hi,

The leaflist branch creation technique (the one you used) only support one variable array dimension. Instead you will either need to store a 1D array (and address it as a 2D array) or use a std:vector<std::vector > (for which you will need to provide a dictionary).

Cheers,
Philippe.

Thanks for your reply. This seems to work. But now I am trying to read this information into a small tree. After setting the branch address, I assume I can read the information with the syntax

std::vector< std::vector<float> > *muon_vec  ;
muon_vec->at(j)[k] ;

correct?

-Thomas

I seem to be having trouble properly accessing the 2D vector elements I previously wrote to a tree. I tried using the method

,where my event loop is over the exact same variables as I did to fill the original vector,
but if I cout << myMuon_eta << endl;, the output is garbage and doesn’t agree with the original eta distribution that I am trying to read in.

[quote]
std::vector< std::vector > *muon_vec ;
muon_vec->at(j)[k] ;
correct?[/quote]No, you must initialize the pointer. So something like: std::vector< std::vector<float> > *muon_vec = 0; tree->SetBranchAddress(branch_name,&muon_vec); for () { ... call GetEntry ... muon_vec->at(j)[k] ; }Cheers,
Philippe.