Logo ROOT  
Reference Guide
jets.C File Reference

Detailed Description

Usage of a Tree using the JetEvent class.

The JetEvent class has several collections (TClonesArray) and other collections (TRefArray) referencing objects in the TClonesArrays. The JetEvent class is in $ROOTSYS/tutorials/tree/JetEvent.h,cxx to execute the script, do

.x jets.C
#ifdef JETS_SECOND_RUN
#include "TFile.h"
#include "TTree.h"
#include "TRandom.h"
#include "TROOT.h"
#include "TSystem.h"
#include "JetEvent.h"
#include "Riostream.h"
void write(Int_t nev=100) {
//write nev Jet events
TFile f("JetEvent.root","recreate");
TTree *T = new TTree("T","Event example with Jets");
JetEvent *event = new JetEvent;
T->Branch("event","JetEvent",&event,8000,2);
for (Int_t ev=0;ev<nev;ev++) {
event->Build();
T->Fill();
}
T->Print();
T->Write();
}
void read() {
//read the JetEvent file
TFile f("JetEvent.root");
TTree *T = (TTree*)f.Get("T");
JetEvent *event = 0;
T->SetBranchAddress("event", &event);
Long64_t nentries = T->GetEntries();
for (Long64_t ev=0;ev<nentries;ev++) {
T->GetEntry(ev);
if (ev) continue; //dump first event only
cout << " Event: "<< ev
<< " Jets: " << event->GetNjet()
<< " Tracks: " << event->GetNtrack()
<< " Hits A: " << event->GetNhitA()
<< " Hits B: " << event->GetNhitB() << endl;
}
}
void pileup(Int_t nev=200) {
//make nev pileup events, each build with LOOPMAX events selected
//randomly among the nentries
TFile f("JetEvent.root");
TTree *T = (TTree*)f.Get("T");
// Long64_t nentries = T->GetEntries();
const Int_t LOOPMAX=10;
JetEvent *events[LOOPMAX];
Int_t loop;
for (loop=0;loop<LOOPMAX;loop++) events[loop] = 0;
for (Long64_t ev=0;ev<nev;ev++) {
if (ev%10 == 0) printf("building pileup: %lld\n",ev);
for (loop=0;loop<LOOPMAX;loop++) {
Int_t rev = gRandom->Uniform(LOOPMAX);
T->SetBranchAddress("event", &events[loop]);
T->GetEntry(rev);
}
}
}
void jets(Int_t nev=100, Int_t npileup=200, Bool_t secondrun = true) {
// Embedding these loads inside the first run of the script is not yet
// supported in v6
// gROOT->ProcessLine(".L $ROOTSYS/tutorials/tree/JetEvent.cxx+");
write(nev);
read();
pileup(npileup);
}
#else
//void jets(Int_t nev=100, Int_t npileup=200, Bool_t secondrun);
void jets(Int_t nev=100, Int_t npileup=200) {
TString tutdir = gROOT->GetTutorialDir();
gROOT->ProcessLine(".L " + tutdir + "/tree/JetEvent.cxx+");
gROOT->ProcessLine("#define JETS_SECOND_RUN yes");
gROOT->ProcessLine("#include \"" __FILE__ "\"");
gROOT->ProcessLine("jets(100,200,true)");
}
#endif
Author
Rene Brun

Definition in file jets.C.

f
#define f(i)
Definition: RSha256.hxx:104
jets
void jets()
Definition: jets.C:38
Long64_t
long long Long64_t
Definition: RtypesCore.h:73
TTree
A TTree represents a columnar dataset.
Definition: TTree.h:79
TRandom.h
Int_t
int Int_t
Definition: RtypesCore.h:45
TRandom::Uniform
virtual Double_t Uniform(Double_t x1=1)
Returns a uniform deviate on the interval (0, x1).
Definition: TRandom.cxx:635
nentries
int nentries
Definition: THbookFile.cxx:91
TTree.h
TString
Basic string class.
Definition: TString.h:136
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TFile.h
TROOT.h
TSystem.h
gRandom
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
TFile
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:54
JetEvent
Definition: JetEvent.h:64
ROOT::Math::Chebyshev::T
double T(double x)
Definition: ChebyshevPol.h:34
JetEvent.h
Riostream.h
gROOT
#define gROOT
Definition: TROOT.h:406