#define memorydepth 100 class MY_DATA{ public: Double_t peak; Double_t wvf[memorydepth]; Int_t selection; MY_DATA(); string tobranch = "peak/D:wvf[" + to_string(memorydepth) + "]/D:selection/I"; void setBranchName(Int_t n = memorydepth){ tobranch = "peak/D:wvf[" + to_string(n) + "]/D:selection/I"; } }; MY_DATA::MY_DATA(){ for(Int_t i = 0; isetBranchName(npts); TFile *fnew = new TFile("example_tree.root","RECREATE"); TTree *t1 = new TTree("t1","t1"); t1->Branch("data",data,data->tobranch.c_str()); for(Int_t i = 0; i < 5; i++){ // 5 entries only for(Int_t j = 0; j < npts; j++){ data->wvf[j] = 0.5 + i; } data->peak = i; data->selection = i; t1->Fill(); } fnew->WriteTObject(t1, "t1", "TObject::kOverwrite"); fnew->Close(); }