jets.C

Go to the documentation of this file.
00001 // script illustrating the use of a Tree using the JetEvent class.
00002 // The JetEvent class has several collections (TClonesArray)
00003 // and other collections (TRefArray) referencing objects
00004 // in the TClonesArrays.
00005 // The JetEvent class is in $ROOTSYS/tutorials/JetEvent.h,cxx
00006 // to execute the script, do
00007 // .x jets.C
00008 //
00009 //Author: Rene Brun
00010       
00011 void write(Int_t nev=100) {
00012    //write nev Jet events
00013    TFile f("JetEvent.root","recreate");
00014    TTree *T = new TTree("T","Event example with Jets");
00015    JetEvent *event = new JetEvent;
00016    T->Branch("event","JetEvent",&event,8000,2);
00017    
00018    for (Int_t ev=0;ev<nev;ev++) {
00019       event->Build();
00020       T->Fill();
00021    }
00022    
00023    T->Print();
00024    T->Write();
00025 }
00026 
00027 void read() {
00028   //read the JetEvent file
00029   TFile f("JetEvent.root");
00030   TTree *T = (TTree*)f.Get("T");
00031   JetEvent *event = 0;
00032   T->SetBranchAddress("event", &event);
00033   Int_t nentries = (Int_t)T->GetEntries();
00034   
00035   for (Int_t ev=0;ev<nentries;ev++) {
00036       T->GetEntry(ev);
00037       if (ev) continue; //dump first event only
00038       cout << " Event: "<< ev
00039            << "  Jets: " << event->GetNjet()
00040            << "  Tracks: " << event->GetNtrack()
00041            << "  Hits A: " << event->GetNhitA()
00042            << "  Hits B: " << event->GetNhitB() << endl;
00043   }
00044 }
00045 
00046 void pileup(Int_t nev=200) {
00047   //make nev pilepup events, each build with LOOPMAX events selected
00048   //randomly among the nentries
00049   TFile f("JetEvent.root");
00050   TTree *T = (TTree*)f.Get("T");
00051   Int_t nentries = (Int_t)T->GetEntries();
00052   
00053   const Int_t LOOPMAX=10;
00054   JetEvent *events[LOOPMAX];
00055   Int_t loop;
00056   for (loop=0;loop<LOOPMAX;loop++) events[loop] = 0;
00057   for (Int_t ev=0;ev<nev;ev++) {
00058       if (ev%10 == 0) printf("building pileup: %d\n",ev);
00059       for (loop=0;loop<LOOPMAX;loop++) {
00060          Int_t rev = gRandom->Uniform(LOOPMAX);
00061          T->SetBranchAddress("event", &events[loop]);
00062          T->GetEntry(rev);
00063       }
00064   }
00065 }
00066 
00067 void jets(Int_t nev=100, Int_t npileup=200) {
00068    gSystem->Load("libPhysics");
00069    gROOT->ProcessLine(".L $ROOTSYS/tutorials/tree/JetEvent.cxx+");
00070    write(nev);
00071    read();
00072    pileup(npileup);
00073 }

Generated on Tue Jul 5 15:45:11 2011 for ROOT_528-00b_version by  doxygen 1.5.1