Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members | Related Pages

EventLoop Class Reference

#include <EventLoop.h>

Inheritance diagram for EventLoop:

Inheritance graph
[legend]
Collaboration diagram for EventLoop:

Collaboration graph
[legend]
List of all members.

Detailed Description

Base class for user event loops.

EventLoop is used as base class for user classes that perfotm analysis tasks in our framework. A class (say, class AnalysisLoop) derived from EventLoop will typically implement a constructor, where (self-filling) histograms are created (i.e., booked), and an output method that creates plots (written to a postscript file) and/or write the histograms to a RooT file.

For an ntuple, defined in the RooT-generated header file Ntuple.h (generated by TTree::MakeClass), a minimal main program will look like this:

 *#define Ntuple_cxx
 *#include "Ntuple.h"                            // The ntuple
 *#include "AnalysisLoop.h"                      // The AnalysisLoop
 *int main(int argc, char** argv) 
 *{
  Ntuple nt;                                   // open ntuple
  TApplication theApp("main", &argc, argv);    // for graphics
  AnalysisLoop theAnalysisLoop (&nt);          // book histos 
  // Loop over ntuple entries
  for (int i = 0; i < int(nt.fChain->GetEntriesFast()); ++i) {
    if (nt.LoadTree (i) < 0) break;
    nt.fChain->GetEntry(i);
    theAnalysisLoop.loop();                    // fill the histos
  }
  theAnalysisLoop.output("out.root","out.ps"); // store the histos
  return 0;
 *}
 *

A minimal AnalysisLoop could look like this (assuming we have a class PTMissFun that returns the missing pt for each ntuple row):

 *#include "jbltools/sfh/EventLoop.h"
 *#include "jbltools/sfh/Binning.h"
 *#include "jbltools/sfh/SFH1F.h"
 *#include "PTMissFun.h"
 *class AnalysisLoop: public EventLoop {
  public:
    // Constructor books histograms
    AnalysisLoop (Ntuple* ntuple) 
    {
      Binning ptmissbinning (50, 0., 100.);
      FloatFun& ptmiss = *new PTMissFun (ntuple);
      // self-filling histogram for missing pt
      h = new SFH1F ("ptmiss", "Missing pt", ptmissbinning, this, ptmiss);        
    
    }
    
    // Destructor does nothing
    virtual ~AnalysisLoop () 
    {}
    
    // output method writes histos to postscript and file
    virtual void output (const char* rootfile = "", 
                         const char* psfile = "") 
    {
      // create canvas 
      TCanvas *canvas = new TCanvas("canvas", "ptmiss", 600, 800);
      // Write plot to psfile
      TPostScript ps (psfile, 111);
      canvas->Clear();
      h->Draw ("E0");                 // Draws the histo
      canvas->Update();
      ps.Close(); 
      // Write histogram to file
      TFile file (rootfile, "RECREATE");
      h->Write();                     // Writes out the histo
      file.Write(); 
      file.Close();
    }
  protected:
    SFH1F *h;                         // The self-filling histogram
 *};
 *

Author: Jenny Böhme, Benno List

Date
2004/06/30 15:31:45
Author
blist

Definition at line 102 of file EventLoop.h.

Public Member Functions

virtual ~EventLoop ()
 Virtual destructor.

virtual void loop ()
 Fills the histograms and invalidates cached objects.

virtual void output (const char *rootfile="", const char *psfile="")
 Generates postscript and RooT output.


Protected Attributes

ROList cachedObjects
 A list of CachedO objects.


The documentation for this class was generated from the following files:
Generated on Thu Oct 26 12:54:32 2006 for SFH by doxygen 1.3.2