Problem with saving the array of vector as tree

Dear Experts,

I have a problem storing arrays of vectors with values in a tree.
In order to do that, I define an array of vectors with a float variable as:

vector <float> a1 [12];
after filling the array of vectors, I write the elements of the array of vectors into a tree as a two-dimensional array as:

Float_t b1[11][11];


However, in the generated Root file, the variable (b1) is stored as unusual and wrong numbers.
On the other hand, writing variables in an array of vectors work fine.

Any comments would be appreciated.
Thanks in advance.

I write the elements of the array of vectors into a tree as a two-dimensional array as:

What is the actual code use to do that? (Note you could also consider using a std::vector<std::vector<float>> and store that directlry).

Thanks for the suggestion.

However, I need to use the array of vectors to keep the correct position of each element in the array in the output file.

Here is a similar example code of what I try to do:

#define test_class_cxx
#include “test_class.h”
#include <TH2.h>
#include <TStyle.h>
#include <TCanvas.h>

using namespace std;

Double_t b1[12][12];
vector a1[12];

void test_class::Loop()
TFile *out_file = new TFile(“temp.root”, “recreate”);
TTree *t1 = new TTree(“Mytree”,“Mytree”);

Long64_t nentries = fChain->GetEntriesFast();
Long64_t nbytes = 0, nb = 0;

for (Long64_t jentry=0; jentry<nentries;jentry++) {

  Long64_t ientry = LoadTree(jentry);
  if (ientry < 0) break;
  nb = fChain->GetEntry(jentry);   nbytes += nb;

for(int i=0;i<12;i++) {

for (int i=0;i<12;i++) {
for (int j=0;j<12;j++){



for(int i=0; i<12 ; i++) {

for(int j=0; j<12; j++) {



for(int i=0; i<12 ; i++) {
for(int j=0; j<12; j++) {






I should point out that the array of vectors for float and double variables behave similarly.

Although the input variable (Particle_jer) range is in only 2 bins [-1000,-999],[0,1], the range of X-axe in the output b1 branch is extended to 10^36.

Could you let me know how to solve the problem?

I think you meant:

Double_t b1[12][12];
t1->Branch("b1", b1, "b1[12][12]/D");

Also since you filling the statically size array, how does the vector help? (cant’ you just use the array?)

Thanks for the correction and suggestion.
In my main code, beside mentioned variable (Paricle_jer), I need to store an array of TLorentz vectors for each event. To store the matched elements in both vectors, I use an array of vectors.

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