Logo ROOT   6.07/09
Reference Guide
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 ///
17 /// \author Rene Brun
18 
19 
20 #ifdef JETS_SECOND_RUN
21 
22 #include "TFile.h"
23 #include "TTree.h"
24 #include "TRandom.h"
25 #include "TROOT.h"
26 #include "TSystem.h"
27 #include "JetEvent.h"
28 #include "Riostream.h"
29 
30 
31 void write(Int_t nev=100) {
32  //write nev Jet events
33  TFile f("JetEvent.root","recreate");
34  TTree *T = new TTree("T","Event example with Jets");
35  JetEvent *event = new JetEvent;
36  T->Branch("event","JetEvent",&event,8000,2);
37 
38  for (Int_t ev=0;ev<nev;ev++) {
39  event->Build();
40  T->Fill();
41  }
42 
43  T->Print();
44  T->Write();
45 }
46 
47 void read() {
48  //read the JetEvent file
49  TFile f("JetEvent.root");
50  TTree *T = (TTree*)f.Get("T");
51  JetEvent *event = 0;
52  T->SetBranchAddress("event", &event);
54 
55  for (Long64_t ev=0;ev<nentries;ev++) {
56  T->GetEntry(ev);
57  if (ev) continue; //dump first event only
58  cout << " Event: "<< ev
59  << " Jets: " << event->GetNjet()
60  << " Tracks: " << event->GetNtrack()
61  << " Hits A: " << event->GetNhitA()
62  << " Hits B: " << event->GetNhitB() << endl;
63  }
64 }
65 
66 void pileup(Int_t nev=200) {
67  //make nev pileup events, each build with LOOPMAX events selected
68  //randomly among the nentries
69  TFile f("JetEvent.root");
70  TTree *T = (TTree*)f.Get("T");
71  // Long64_t nentries = T->GetEntries();
72 
73  const Int_t LOOPMAX=10;
74  JetEvent *events[LOOPMAX];
75  Int_t loop;
76  for (loop=0;loop<LOOPMAX;loop++) events[loop] = 0;
77  for (Long64_t ev=0;ev<nev;ev++) {
78  if (ev%10 == 0) printf("building pileup: %lld\n",ev);
79  for (loop=0;loop<LOOPMAX;loop++) {
80  Int_t rev = gRandom->Uniform(LOOPMAX);
81  T->SetBranchAddress("event", &events[loop]);
82  T->GetEntry(rev);
83  }
84  }
85 }
86 
87 void jets(Int_t nev=100, Int_t npileup=200, Bool_t secondrun = true) {
88  // Embedding these loads inside the first run of the script is not yet
89  // supported in v6
90  // gSystem->Load("libPhysics");
91  // gROOT->ProcessLine(".L $ROOTSYS/tutorials/tree/JetEvent.cxx+");
92  write(nev);
93  read();
94  pileup(npileup);
95 }
96 
97 #else
98 
99 //void jets(Int_t nev=100, Int_t npileup=200, Bool_t secondrun);
100 void jets(Int_t nev=100, Int_t npileup=200) {
101  gSystem->Load("libPhysics");
102  TString tutdir = gROOT->GetTutorialsDir();
103  gROOT->ProcessLine(".L " + tutdir + "/tree/JetEvent.cxx+");
104  gROOT->ProcessLine("#define JETS_SECOND_RUN yes");
105  gROOT->ProcessLine("#include \"" __FILE__ "\"");
106  gROOT->ProcessLine("jets(100,200,true)");
107 }
108 
109 #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
double T(double x)
Definition: ChebyshevPol.h:34
virtual Int_t Fill()
Fill all branches.
Definition: TTree.cxx:4374
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:50
#define gROOT
Definition: TROOT.h:364
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:5210
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Definition: TSystem.cxx:1818
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual void Print(Option_t *option="") const
Print a summary of the tree contents.
Definition: TTree.cxx:6689
virtual Int_t SetBranchAddress(const char *bname, void *add, TBranch **ptr=0)
Change branch address, dealing with clone trees properly.
Definition: TTree.cxx:7719
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:9001
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
R__EXTERN TRandom * gRandom
Definition: TRandom.h:66
double f(double x)
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:1651
virtual Long64_t GetEntries() const
Definition: TTree.h:392
A TTree object has a header with a name and a title.
Definition: TTree.h:98