// @(#)root/test:$Name: $:$Id: MainEvent.cxx,v 1.31 2005/12/02 18:50:07 pcanal Exp $ // Author: Rene Brun 19/01/97 //////////////////////////////////////////////////////////////////////// // // A simple example with a ROOT tree // ================================= // // This program creates : // - a ROOT file // - a tree // One possible argument : number of events // ---Running/Linking instructions---- // This program consists of the following files and procedures. // - Event.h event class description // - Event.C event class implementation // - MainEvent.C the main program to demo this class might be used (this file) // - EventCint.C the CINT dictionary for the event and Track classes // this file is automatically generated by rootcint (see Makefile), // when the class definition in Event.h is modified. // // ---Analyzing the event.root file with the interactive root // example of a simple session // Root > TFile f("Event.root") // Root > T.Draw("feTrue") //histogram true x // Root > T.Draw("feTrue:fIEvent","fIEvent<10") //histogram E true x vs event number for first 10 events // //////////////////////////////////////////////////////////////////////// #include #include "Riostream.h" #include "TROOT.h" #include "TFile.h" #include "TNetFile.h" #include "TRandom.h" #include "TTree.h" #include "TBranch.h" #include "TClonesArray.h" #include "TStopwatch.h" #include "Event.h" #include "simulate.cxx" #include "ana_simu.cxx" #include "reconstruct.cxx" //______________________________________________________________________________ int main(int argc, char **argv) { Int_t nevent = 400; // by default create 400 events if (argc > 1) nevent = atoi(argv[1]); Int_t branchStyle = 1; //new style by default Int_t split=1; TFile *hfile; TTree *tree; Event *event = 0; // Fill event, header and tracks with some random numbers // Create a timer object to benchmark this loop TStopwatch timer; timer.Start(); Long64_t nb = 0; Int_t ev; Int_t bufsize; Int_t printev = 100; //Authorize Trees up to 2 Terabytes (if the system can do it) TTree::SetMaxTreeSize(1000*Long64_t(2000000000)); // Create a new ROOT binary machine independent file. // Note that this file may contain any kind of ROOT objects, histograms, // pictures, graphics objects, detector geometries, tracks, events, etc.. // This file is now becoming the current directory. hfile = new TFile("Event.root","RECREATE","TTree stage info root file"); // Create a ROOT Tree and one superbranch tree = new TTree("T","Calo sim root tree"); tree->SetAutoSave(1000000000); // autosave when 1 Gbyte written bufsize = 64000; if (split) bufsize /= 4; event = new Event(); TTree::SetBranchStyle(branchStyle); TBranch *branch = tree->Branch("event", &event, bufsize,split); branch->SetAutoDelete(kFALSE); if(split >= 0 && branchStyle) tree->BranchRef(); gRandom->SetSeed(); for (ev = 0; ev < nevent; ev++) { if (ev%printev == 0) { printf("event:%d \n",ev); } // initialize event event->build(ev); // simulation simulate(event); ana_simu(event); // reconstruction reconstruct(event); nb += tree->Fill(); //fill the tree } // ev loop hfile = tree->GetCurrentFile(); //just in case we switched to a new file hfile->Write(); tree->Print(); //printf("file compression factor = %f\n",hfile.GetCompressionFactor()); hfile->Close(); return 0; }