#include #include "TFile.h" #include "TTree.h" #include "TRandom.h" #include "TROOT.h" extern void InitGui(); VoidFuncPtr_t initfuncs[] = {InitGui, 0}; TROOT root("Rint","The ROOT Interactive Interface", initfuncs); int main() { // -- Open a TFile TFile *f = new TFile("SimpleTree.root","recreate"); // -- for each event, you want up to 500 candidates (or whatever) Int_t n; // keeps track of how many per event Double_t E[500]; Float_t Px[500]; Float_t Py[500]; Float_t Pz[500]; // -- Instantiate a tree TTree* pMyTree = new TTree("SimpleTree","An example of a tree"); // -- Define branches (Note: that the second argument is a pointer) pMyTree->Branch("n",&n,"n/I"); // I is integer pMyTree->Branch("E",E,"E[n]/D"); // D is double pMyTree->Branch("Px",Px,"Px[n]/F"); // F is float pMyTree->Branch("Py",Py,"Py[n]/F"); pMyTree->Branch("Pz",Pz,"Pz[n]/F"); // -- Run over 100 'events' for (Int_t i=0; i<100; i++) { n = 500*gRandom->Rndm(); // each event has a random number of candidates for (Int_t j=0; jGaus(10., 2.); Px[j] = gRandom->Gaus(5, 1.); Py[j] = gRandom->Gaus(5., 1.); Pz[j] = gRandom->Gaus(7., 0.6); } // -- Fill the tree pMyTree->Fill(); } // -- Show what we got pMyTree->Print(); // -- Dump it to a file pMyTree->Write(); // -- And clean up f->Close(); delete f; }