Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

MainEvent.cpp

Go to the documentation of this file.
00001 // @(#)root/test:$Name:  $:$Id: MainEvent.cpp,v 1.2 2005/04/18 14:52:56 berthon Exp $
00002 // Author: Rene Brun   19/01/97
00003 
00005 //
00006 //             A simple example with a ROOT tree
00007 //             =================================
00008 //
00009 //  This program creates :
00010 //    - a ROOT file
00011 //    - a tree
00012 //  Additional arguments can be passed to the program to control the flow
00013 //  of execution. (see comments describing the arguments in the code).
00014 //      Event  nevent comp split fill
00015 //  All arguments are optional. Default is:
00016 //      Event  400      1    1     1
00017 //
00018 //  In this example, the tree consists of one single "super branch"
00019 //  The statement ***tree->Branch("event", event, 64000,split);*** below
00020 //  will parse the structure described in Event.h and will make
00021 //  a new branch for each data member of the class if split is set to 1.
00022 //    - 9 branches corresponding to the basic types fType, fNtrack,fNseg,
00023 //           fNvertex,fFlag,fTemperature,fMeasures,fMatrix,fClosesDistance.
00024 //    - 3 branches corresponding to the members of the subobject EventHeader.
00025 //    - one branch for each data member of the class Track of TClonesArray.
00026 //    - one branch for the TRefArray of high Pt tracks
00027 //    - one branch for the TRefArray of muon tracks
00028 //    - one branch for the reference pointer to the last track
00029 //    - one branch for the object fH (histogram of class TH1F).
00030 //
00031 //  if split = 0 only one single branch is created and the complete event
00032 //  is serialized in one single buffer.
00033 //  if split = -2 the event is split using the old TBranchObject mechanism
00034 //  if split = -1 the event is streamed using the old TBranchObject mechanism
00035 //  if split > 0  the event is split using the new TBranchElement mechanism.
00036 //
00037 //  if comp = 0 no compression at all.
00038 //  if comp = 1 event is compressed.
00039 //  if comp = 2 same as 1. In addition branches with floats in the TClonesArray
00040 //                         are also compressed.
00041 //  The 4th argument fill can be set to 0 if one wants to time
00042 //     the percentage of time spent in creating the event structure and
00043 //     not write the event in the file.
00044 //  In this example, one loops over nevent events.
00045 //  The branch "event" is created at the first event.
00046 //  The branch address is set for all other events.
00047 //  For each event, the event header is filled and ntrack tracks
00048 //  are generated and added to the TClonesArray list.
00049 //  For each event the event histogram is saved as well as the list
00050 //  of all tracks.
00051 //
00052 //  The two TRefArray contain only references to the original tracks owned by
00053 //  the TClonesArray fTracks.
00054 //
00055 //  The number of events can be given as the first argument to the program.
00056 //  By default 400 events are generated.
00057 //  The compression option can be activated/deactivated via the second argument.
00058 //
00059 //   ---Running/Linking instructions----
00060 //  This program consists of the following files and procedures.
00061 //    - Event.h event class description
00062 //    - Event.C event class implementation
00063 //    - MainEvent.C the main program to demo this class might be used (this file)
00064 //    - EventCint.C  the CINT dictionary for the event and Track classes
00065 //        this file is automatically generated by rootcint (see Makefile),
00066 //        when the class definition in Event.h is modified.
00067 //
00068 //   ---Analyzing the Event.root file with the interactive root
00069 //        example of a simple session
00070 //   Root > TFile f("Event.root")
00071 //   Root > T.Draw("fNtrack")   //histogram the number of tracks per event
00072 //   Root > T.Draw("fPx")       //histogram fPx for all tracks in all events
00073 //   Root > T.Draw("fXfirst:fYfirst","fNtrack>600")
00074 //                              //scatter-plot for x versus y of first point of each track
00075 //   Root > T.Draw("fH.GetRMS()")  //histogram of the RMS of the event histogram
00076 //
00077 //   Look also in the same directory at the following macros:
00078 //     - eventa.C  an example how to read the tree
00079 //     - eventb.C  how to read events conditionally
00080 //
00082 
00083 #include <stdlib.h>
00084 
00085 #include "Riostream.h"
00086 #include "TROOT.h"
00087 #include "TFile.h"
00088 #include "TNetFile.h"
00089 #include "TRandom.h"
00090 #include "TTree.h"
00091 #include "TBranch.h"
00092 #include "TClonesArray.h"
00093 #include "TStopwatch.h"
00094 
00095 #include "XANADOO/domain/interface/XANAEsdEvent.h"
00096 
00097 
00098 //______________________________________________________________________________
00099 
00100 class MainEventClass {
00101 
00102  public:
00103  
00104    MainEventClass();
00105    ~MainEventClass() {}
00106    
00107    void process();
00108    void end(); 
00109    
00110    Int_t nb, nevent;
00111    TTree *tree;
00112    TFile *hfile; 
00113    XANAEsdEvent *event;
00114    TBranch *branch;
00115    
00116 };
00117 
00118 int main(int argc, char **argv)
00119 {
00120    MainEventClass main;
00121    main.process();
00122    main.end();
00123    return 0;
00124 }
00125 
00126 
00127 MainEventClass::MainEventClass() :
00128  tree(0), hfile(0), event(0), branch(0)
00129 {
00130    nevent = 400;     // by default create 400 events
00131    Int_t comp   = 1;       // by default file is compressed
00132    Int_t split  = 1;       // by default, split Event in sub branches
00133    Int_t write  = 1;       // by default the tree is filled
00134    Int_t hfill  = 0;       // by default histograms are not filled
00135    Int_t read   = 0;
00136    Int_t arg4   = 1;
00137    Int_t arg5   = 600;     //default number of tracks per event
00138    Int_t netf   = 0;
00139    
00140 //   Event *event = 0;
00141 
00142    // Fill event, header and tracks with some random numbers
00143    nb = 0;
00144    Int_t bufsize;
00145    Double_t told = 0;
00146    Double_t tnew = 0;
00147 
00148       // Create a new ROOT binary machine independent file.
00149       // Note that this file may contain any kind of ROOT objects, histograms,
00150       // pictures, graphics objects, detector geometries, tracks, events, etc..
00151       // This file is now becoming the current directory.
00152       hfile = new TFile("Event.root","RECREATE");
00153       hfile->SetCompressionLevel(comp);
00154 
00155      // Create histogram to show write_time in function of time
00156      Float_t curtime = -0.5;
00157 
00158      // Create a ROOT Tree and one superbranch
00159       tree = new TTree("T","An example of a ROOT tree");
00160       tree->SetAutoSave(1000000000);  // autosave when 1 Gbyte written
00161       bufsize = 256000;
00162       if (split)  bufsize /= 4;
00163 // try XANA event class
00164 //      event = new Event();
00165       event = new XANAEsdEvent;
00166 //      TTree::SetBranchStyle(branchStyle);
00167 // try XANA event class
00168 //      TBranch *branch = tree->Branch("event", "Event", &event, bufsize,split);
00169       branch = tree->Branch("event","XANAEsdEvent",&event,bufsize,split);
00170       branch->SetAutoDelete(kFALSE);
00171       Float_t ptmin = 1;
00172 
00173 }
00174 
00175 void MainEventClass::process() 
00176 {
00177       for (Int_t ev = 0; ev < nevent; ev++) {
00178 
00179 //         event->Build(ev, arg5, ptmin);
00180          branch->ResetAddress();
00181          branch->SetAddress(&event);
00182          event->setGeneral(1,1);
00183 
00184 //         nb += tree->Fill();  //fill the tree
00185         tree->Fill();  //fill the tree
00186 
00187 //         if (hm) hm->Hfill(event);      //fill histograms
00188       }
00189 }
00190 
00191 void MainEventClass::end() 
00192 {
00193    printf("\n%d events and %d bytes processed.\n",nevent,nb);
00194    hfile->Write();
00195    tree->Print();
00196    delete hfile;
00197 }

Generated on Tue May 10 10:01:24 2005 for XANADOO by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002