/* #include #include #include #include "TFile.h" #include "TTree.h" #include "TCanvas.h" #include "TBranch.h" #include "TRandom.h" #include "TSystem.h" using namespace std; */ void macro9(){ TFile *f = TFile::Open("myfile.root", "RECREATE"); if (!f) { return; } TTree *T = new TTree("T", "Tree with vector"); std::vector px; std::vector py; std::vector pz; T->Branch("px", &px); T->Branch("py", &py); //std::vector, T->Branch("pz", &pz); TRandom r; int np; for(int i=0; i< 1000; i++){ //clean the vectors for each element px.clear(); py.clear(); pz.clear(); float x,y; //fill vectors for each element np= (int)(r.Rndm()*10); for(int j=0; j< np; j++){ r.Rannor(x,y); px.push_back(x); py.push_back(y); pz.push_back(std::sqrt(x*x + y*y)); } T->Fill(); } f->Write(); f->Close(); }