ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
jets.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_tree
3 ///
4 /// Usage of a Tree using the JetEvent class.
5 ///
6 /// The JetEvent class has several collections (TClonesArray)
7 /// and other collections (TRefArray) referencing objects
8 /// in the TClonesArrays.
9 /// The JetEvent class is in $ROOTSYS/tutorials/tree/JetEvent.h,cxx
10 /// to execute the script, do
11 /// ~~~
12 /// .x jets.C
13 /// ~~~
14 ///
15 /// \macro_code
16 /// \author Rene Brun
17 
18 
19 #ifdef JETS_SECOND_RUN
20 
21 #include "TFile.h"
22 #include "TTree.h"
23 #include "TRandom.h"
24 #include "TROOT.h"
25 #include "TSystem.h"
26 #include "JetEvent.h"
27 #include "Riostream.h"
28 
29 
30 void write(Int_t nev=100) {
31  //write nev Jet events
32  TFile f("JetEvent.root","recreate");
33  TTree *T = new TTree("T","Event example with Jets");
34  JetEvent *event = new JetEvent;
35  T->Branch("event","JetEvent",&event,8000,2);
36 
37  for (Int_t ev=0;ev<nev;ev++) {
38  event->Build();
39  T->Fill();
40  }
41 
42  T->Print();
43  T->Write();
44 }
45 
46 void read() {
47  //read the JetEvent file
48  TFile f("JetEvent.root");
49  TTree *T = (TTree*)f.Get("T");
50  JetEvent *event = 0;
51  T->SetBranchAddress("event", &event);
52  Long64_t nentries = T->GetEntries();
53 
54  for (Long64_t ev=0;ev<nentries;ev++) {
55  T->GetEntry(ev);
56  if (ev) continue; //dump first event only
57  cout << " Event: "<< ev
58  << " Jets: " << event->GetNjet()
59  << " Tracks: " << event->GetNtrack()
60  << " Hits A: " << event->GetNhitA()
61  << " Hits B: " << event->GetNhitB() << endl;
62  }
63 }
64 
65 void pileup(Int_t nev=200) {
66  //make nev pilepup events, each build with LOOPMAX events selected
67  //randomly among the nentries
68  TFile f("JetEvent.root");
69  TTree *T = (TTree*)f.Get("T");
70  // Long64_t nentries = T->GetEntries();
71 
72  const Int_t LOOPMAX=10;
73  JetEvent *events[LOOPMAX];
74  Int_t loop;
75  for (loop=0;loop<LOOPMAX;loop++) events[loop] = 0;
76  for (Long64_t ev=0;ev<nev;ev++) {
77  if (ev%10 == 0) printf("building pileup: %lld\n",ev);
78  for (loop=0;loop<LOOPMAX;loop++) {
79  Int_t rev = gRandom->Uniform(LOOPMAX);
80  T->SetBranchAddress("event", &events[loop]);
81  T->GetEntry(rev);
82  }
83  }
84 }
85 
86 void jets(Int_t nev=100, Int_t npileup=200, Bool_t secondrun = true) {
87  // Embedding these loads inside the first run of the script is not yet
88  // supported in v6
89  // gSystem->Load("libPhysics");
90  // gROOT->ProcessLine(".L $ROOTSYS/tutorials/tree/JetEvent.cxx+");
91  write(nev);
92  read();
93  pileup(npileup);
94 }
95 
96 #else
97 
98 //void jets(Int_t nev=100, Int_t npileup=200, Bool_t secondrun);
99 void jets(Int_t nev=100, Int_t npileup=200) {
100  gSystem->Load("libPhysics");
101  TString tutdir = gROOT->GetTutorialsDir();
102  gROOT->ProcessLine(".L " + tutdir + "/tree/JetEvent.cxx+");
103  gROOT->ProcessLine("#define JETS_SECOND_RUN yes");
104  gROOT->ProcessLine("#include \"" __FILE__ "\"");
105  gROOT->ProcessLine("jets(100,200,true)");
106 }
107 
108 #endif
double read(const std::string &file_name)
reading
long long Long64_t
Definition: RtypesCore.h:69
double write(int n, const std::string &file_name, const std::string &vector_type, int compress=0)
writing
virtual Int_t Fill()
Fill all branches.
Definition: TTree.cxx:4306
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
#define gROOT
Definition: TROOT.h:344
virtual Int_t GetEntry(Long64_t entry=0, Int_t getall=0)
Read all branches of entry and return total number of bytes read.
Definition: TTree.cxx:5144
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Definition: TSystem.cxx:1766
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TFile * f
virtual void Print(Option_t *option="") const
Print a summary of the tree contents.
Definition: TTree.cxx:6495
virtual Int_t SetBranchAddress(const char *bname, void *add, TBranch **ptr=0)
Change branch address, dealing with clone trees properly.
Definition: TTree.cxx:7510
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
Definition: TTree.cxx:8780
R__EXTERN TSystem * gSystem
Definition: TSystem.h:545
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
int nentries
Definition: THbookFile.cxx:89
virtual Double_t Uniform(Double_t x1=1)
Returns a uniform deviate on the interval (0, x1).
Definition: TRandom.cxx:606
virtual Int_t Branch(TCollection *list, Int_t bufsize=32000, Int_t splitlevel=99, const char *name="")
Create one branch for each element in the collection.
Definition: TTree.cxx:1623
virtual Long64_t GetEntries() const
Definition: TTree.h:386
A TTree object has a header with a name and a title.
Definition: TTree.h:98