Main Page | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Examples

tselector.doc


`TSelector' Analysis Mode


This mode is the suggested way to analyze large samples of AMS data in parallel, using the PROOF facility. It implies using two programs: a steering program and the analysis program. An example of steering program is run_MySelector1.C , which will initialize some ROOT stuff, define input and output files and process (compile+link+execute) the actual analysis program, MySelector1.C , containing the real stuff. Everything works together by doing "root run_MySelector1.C". If one wants to run in non-graphic mode and exiting root at the end of processing, use: "root -b -q run_MySelector1.C".

Another example, including additional AMS utilities, is illustrated by the files run_MySelector2.C and MySelector2.C . Again, you can run it with: "root run.Myselector2.C".

The advantages of this approach are:

The TSelector class is used by the method "TTree::Process" in order to loop over TTree events and to make selections. TSelector contains the following methods:
Init: Attach a new TTree during the loop.
Begin: Called everytime a loop on the tree(s) starts. A convenient place to create your histograms.
Notify: This function is called at the first entry of a new tree in a chain.
ProcessCut: Called at the beginning of each entry to return a flag true if the entry must be analyzed.
ProcessFill: Called in the entry loop for all entries accepted by ProcessCut
Terminate: Called at the end of a loop on a Tree. A convenient place to draw/fit your histograms.

The relevant features of the AMS implementation are:

{
  gROOT->Reset();

  TString include_dir = gSystem->ExpandPathName("../lib/AMSRoot");
  gInterpreter->AddIncludePath(include_dir);
  gSystem->Exec("cd ../lib; make shared");
  gSystem->Load("../lib/libAMSRoot.so");

  AMSChain* chain = new AMSChain;
  chain->Add("../files/test.root");
  //chain->Add("http://pcamsf0.cern.ch/f2dah1/MC/AMS02/2004A/protons/el.pl1.10200/738197524.0000001.root");
  //chain->Add("rfio:/castor/cern.ch/ams/MC/AMS02/2004A/protons/el.pl1.10200/738197524.0000001.root");

// Alternatives
  chain->Process("MySelector1.C+");    // compile whenever the C file is modified
  //chain->Process("MySelector1.C");   // interpreted, no compilation at all
  //chain->Process("MySelector1.C++"); // always force compilation
}
#include <root.h>
#include "TStyle.h"
#include "TFile.h"
#include "TH1.h"

class MySelector1 : public AMSEventR {
public :
  MySelector1(){};
  ~MySelector1(){};

#ifdef __CINT__
#include <process_cint.h>
#endif

  void    UBegin();
  Bool_t  UProcessCut();
  void    UProcessFill();
  void    UTerminate();

  TFile* h_file;
  TH1F* h_rig;

  AMSEventList* plist;

};

void MySelector1::UBegin(){
  h_file = new TFile("amstest.root","RECREATE");

  plist = new AMSEventList;

  h_rig = new TH1F ("h_rig", "Momentum (GeV)", 50, -10., 10.);
      
}

Bool_t MySelector1::UProcessCut(){ 
  return true;
}

void MySelector1::UProcessFill() {
  for (int i=0; i<nParticle(); i++) {
      ParticleR* part = pParticle(i);
      h_rig->Fill(part->Momentum);
      if (nVertex()>0) {
            plist->Add(this); // Add to list of selected events
            Fill(); // write it into output ROOT file
      }
  }
}

void MySelector1::UTerminate() {
  gStyle->SetOptStat(1111111);
  h_rig->Draw();
  h_file->Write();

  plist->Write("select.list");

  printf("We have processed %d events\n", (int)Tree()->GetEntries());
  printf("Histograms saved in '%s'\n", h_file->GetName());
}


Generated on Fri Oct 10 10:39:23 2008 for AMSRoot by  doxygen 1.3.9.1