/// \file /// \ingroup tutorial_tree /// \notebook -nodraw /// Simple Event class example /// /// execute as: .x tree0.C++ /// /// You have to copy it first to a directory where you have write access! /// Note that .x tree0.C cannot work with this example /// /// ### Effect of ClassDef() and ClassImp() macros /// /// After running this macro create an instance of Det and Event /// /// ~~~ /// Det d; /// Event e; /// ~~~ /// /// now you can see the effect of the ClassDef() and ClassImp() macros. /// (for the Det class these commands are commented!) /// For instance 'e' now knows who it is: /// /// ~~~ /// cout< #include #include #include #include //ClassImp(Det) //class Event { //TObject is not required by this example class Event : public TObject { public: Double_t e; //energy; // say there are two detectors (a and b) in the experiment Double_t t; //time; ClassDef(Event,1) }; ClassImp(Event) void tree0() { // create a TTree TFile *outfile = new TFile("testtree.root","RECREATE"); TTree *tree = new TTree("tree","treelibrated tree"); // create a branch with energy TClonesArray *events = new TClonesArray("Event"); tree->Branch("t.",&events); // fill some events with random numbers Int_t nevent=10000; for (Int_t iev=0;ievClear("C"); if (iev%1000==0) cout<<"Processing event "<Rannor(ea,eb); // the two energies follow a gaus distribution ((Event*) events->At(0))->e=ea; ((Event*) events->At(0))->t=gRandom->Rndm(); // random tree->Fill(); // fill the tree with the current event } tree->Write(); outfile->Close(); }