Example of analysis code with Chains

{
///////////////////////////////////////////////////////////////////////////////
//   This macro illustrates how to loop on events in a chain of files 
//   containing a TTree object
//   The skeleton of this file has been automatically generated 
//     (Wed Jul 23 14:09:39 1997 by ROOT version 1.01/07)
//   from TTree h3333/ATLFAST
//   found on file: atlfast_whbb_lowlum_r04.root
//
//   The analysis module and the data sets have been kindly provided
//   by the ATLAS Atlfast team.
//
//   The complete source of this macro, associated macros and files
//   can be found at  AtlFast massbb 
////////////////////////////////////////////////////////////////////////////////


//Reset ROOT
   gROOT->Reset();

//We intend to use this macro for benchmarking ROOT
   gBenchmark->Start("massbb");

//Load some utility functions and the event analysis code
   gROOT->LoadMacro("ElaUtil.C");
   gROOT->LoadMacro("ElaAnal.C");

// histos initialization. Create file and result histograms
   TFile histofile("atlf_massbb.root","RECREATE","WH-->bb mass distribution");
   TH1F Mbb_cru("Mbb_cru","m_bb_cru (GeV)",50,0,150);
   TH1F Ptj_cru("Ptj_cru","p_T^jet_cru (GeV)",50,0,100);
   TH1F Mbb("Mbb","m_bb (GeV)",50,0,150);
   TH1F Ptj("Ptj","p_T^jet (GeV)",50,0,100);

// Connecting calibration file
   TFile calibfile("atlf_calibration.root");
// Get histogram Kfac from file. We directly create a pointer
// because we intend to use this histogram when the current directory
// is not calibfile itself
   TH1F *Kfac = (TH1F*)calibfile.Get("Kfac");

// Create a chain of files. The parameter to the TChain constructor
// is the name of the Tree to be processed in each file of the chain.
   TChain chain("h3333");
   chain.Add("atlfast_whbb_lowlum_r04.root");
   chain.Add("atlfast_whbb_lowlum_r04.root");  // <== add a new file

//Declaration of leaves types
   UInt_t          Jrun;
   UInt_t          Jevnt;
   UInt_t          Jflag;
   UInt_t          Isub;
   UInt_t          Nel;
   UInt_t          Nmu;
   UInt_t          Nmux;
   UInt_t          Nph;
   UInt_t          Jetb;
   UInt_t          Jetc;
   UInt_t          Jetl;
   Float_t         Pmiss[2];
   UInt_t          Nlep;
   UInt_t          Kflep[12];
   Float_t         Pxlep[12];
   Float_t         Pylep[12];
   Float_t         Pzlep[12];
   Float_t         Eelep[12];
   UInt_t          Npho;
   UInt_t          Kfpho[12];
   Float_t         Pxpho[12];
   Float_t         Pypho[12];
   Float_t         Pzpho[12];
   Float_t         Eepho[12];
   UInt_t          Njeta;
   UInt_t          Kfjet[20];
   Float_t         Pxjet[20];
   Float_t         Pyjet[20];
   Float_t         Pzjet[20];
   Float_t         Eejet[20];
   UInt_t          Nonmux;
   UInt_t          Kfmux[12];
   Float_t         Pxmux[12];
   Float_t         Pymux[12];
   Float_t         Pzmux[12];
   Float_t         Eemux[12];
   UInt_t          Npart;
   UInt_t          Kfpar[40];
   Float_t         Pxpar[40];
   Float_t         Pypar[40];
   Float_t         Pzpar[40];
   Float_t         Eepar[40];
   Float_t         Tgall;
   Float_t         Tgem1;
   Float_t         Tgph1;
   Float_t         Tgem2;
   Float_t         Tgmu1;
   Float_t         Tgmu2;
   Float_t         Tgemu;
   Float_t         Tgjt1;
   Float_t         Tgjt3;
   Float_t         Tgjt4;
   UInt_t          Ntra;
   UInt_t          Kftra[100];
   Float_t         Pxtra[100];
   Float_t         Pytra[100];
   Float_t         Pztra[100];
   Float_t         Eetra[100];

//Set branch addresses
   chain.SetBranchAddress("Jrun",&Jrun);
   chain.SetBranchAddress("Jevnt",&Jevnt);
   chain.SetBranchAddress("Jflag",&Jflag);
   chain.SetBranchAddress("Isub",&Isub);
   chain.SetBranchAddress("Nel",&Nel);
   chain.SetBranchAddress("Nmu",&Nmu);
   chain.SetBranchAddress("Nmux",&Nmux);
   chain.SetBranchAddress("Nph",&Nph);
   chain.SetBranchAddress("Jetb",&Jetb);
   chain.SetBranchAddress("Jetc",&Jetc);
   chain.SetBranchAddress("Jetl",&Jetl);
   chain.SetBranchAddress("Pmiss",Pmiss);
   chain.SetBranchAddress("Nlep",&Nlep);
   chain.SetBranchAddress("Kflep",Kflep);
   chain.SetBranchAddress("Pxlep",Pxlep);
   chain.SetBranchAddress("Pylep",Pylep);
   chain.SetBranchAddress("Pzlep",Pzlep);
   chain.SetBranchAddress("Eelep",Eelep);
   chain.SetBranchAddress("Npho",&Npho);
   chain.SetBranchAddress("Kfpho",Kfpho);
   chain.SetBranchAddress("Pxpho",Pxpho);
   chain.SetBranchAddress("Pypho",Pypho);
   chain.SetBranchAddress("Pzpho",Pzpho);
   chain.SetBranchAddress("Eepho",Eepho);
   chain.SetBranchAddress("Njeta",&Njeta);
   chain.SetBranchAddress("Kfjet",Kfjet);
   chain.SetBranchAddress("Pxjet",Pxjet);
   chain.SetBranchAddress("Pyjet",Pyjet);
   chain.SetBranchAddress("Pzjet",Pzjet);
   chain.SetBranchAddress("Eejet",Eejet);
   chain.SetBranchAddress("Nonmux",&Nonmux);
   chain.SetBranchAddress("Kfmux",Kfmux);
   chain.SetBranchAddress("Pxmux",Pxmux);
   chain.SetBranchAddress("Pymux",Pymux);
   chain.SetBranchAddress("Pzmux",Pzmux);
   chain.SetBranchAddress("Eemux",Eemux);
   chain.SetBranchAddress("Npart",&Npart);
   chain.SetBranchAddress("Kfpar",Kfpar);
   chain.SetBranchAddress("Pxpar",Pxpar);
   chain.SetBranchAddress("Pypar",Pypar);
   chain.SetBranchAddress("Pzpar",Pzpar);
   chain.SetBranchAddress("Eepar",Eepar);
   chain.SetBranchAddress("Tgall",&Tgall);
   chain.SetBranchAddress("Tgem1",&Tgem1);
   chain.SetBranchAddress("Tgph1",&Tgph1);
   chain.SetBranchAddress("Tgem2",&Tgem2);
   chain.SetBranchAddress("Tgmu1",&Tgmu1);
   chain.SetBranchAddress("Tgmu2",&Tgmu2);
   chain.SetBranchAddress("Tgemu",&Tgemu);
   chain.SetBranchAddress("Tgjt1",&Tgjt1);
   chain.SetBranchAddress("Tgjt3",&Tgjt3);
   chain.SetBranchAddress("Tgjt4",&Tgjt4);
   chain.SetBranchAddress("Ntra",&Ntra);
   chain.SetBranchAddress("Kftra",Kftra);
   chain.SetBranchAddress("Pxtra",Pxtra);
   chain.SetBranchAddress("Pytra",Pytra);
   chain.SetBranchAddress("Pztra",Pztra);
   chain.SetBranchAddress("Eetra",Eetra);

//     This is the loop skeleton
//       To read only selected branches, Insert statements like:
// chain.SetBranchStatus("*",0);  // disable all branches
// chain.SetBranchStatus("branchname",1);  // activate branchname

//  Invoke analysis code
   ElaAnal();

//..... save histograms

   histofile.Write();
   histofile.Close();

   gBenchmark->Show("massbb");
   Float_t hp735     = 27;  //this macro gives 27 RootMarks on an HP735
   Float_t massbb_rt = gBenchmark->GetRealTime("massbb");
   Float_t massbb_ct = gBenchmark->GetCpuTime("massbb");
   Float_t rtmark    = hp735*(439/massbb_rt);
   Float_t cpmark    = hp735*(434/massbb_ct);
   printf("massbb    = %7.2f RealMARKS,  = %7.2f CpuMARKS\n",rtmark,cpmark);
   Float_t rtmarks   = 0.5*(rtmark+cpmark); // take average of realtime and cputime
   printf("\n");
   printf("****************************************************\n");
   printf("* Your machine is estimated at %7.2f ROOTMARKS   *\n",rtmarks);
   printf("****************************************************\n");
}


ROOT page - Class index - Top of the page

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.