tutCAFMacro.C
Go to the documentation of this file.
1 {
2 
3  // Load the CAF libraries using some fancy cintex magic
4  // This macro is meant to be run using a bare ROOT prompt
5  // If you use the cafe command line utility, you can skip this step
6  gSystem->Load("libCintex.so");
7  Cintex::Enable();
8  gSystem->Load("$SRT_PUBLIC_CONTEXT/lib/Linux2.6-GCC-debug/libStandardRecord_dict.so");
9 
10  // Open the file object
11  TFile* file = new TFile("/nova/data/mc/S13-06-18/genie/nd/nd_r0000001_s01_S13-06-18_v1_genie_1000_fhc_20121129_181943.sim.caf.root", "READ");
12 
13  // Get the tree from the file
14  TTree* tree = file->Get("recTree");
15  // Use the tree to draw a histogram, just for kicks, make a canvas for this histogram too.
16  TCanvas* can1 = new TCanvas("nameOfCanvas", "Tree::Draw()");
17  tree->Draw("slc.nhit");
18 
19  // Create a StandardRecord object and associate it with the tree.
21  tree->SetBranchAddress("rec", &rec);
22 
23  // Create a histogram for my awesome variable
24  TH1F* myAwesomeHist = new TH1F("myHist", ";Awesome Variable; Number of Slices", 100, 0, 100);
25 
26  // Loop over the entries in the tree (slices)
27  for(int i = 0; i< tree->GetEntries(); ++i)
28  {
29  // Get an entry from the tree, this copies it's information to the rec pointer
30  tree->GetEntry(i);
31  // Get a variable from the tree, this is mostly unnecessary, could just refer to rec->slc.nhit everywhere
32  int nhit = rec->slc.nhit;
33  // Do my awesome analysis
34  float myAwesomeVar = nhit * 5.3;
35 
36  // Add my variable to the histogram
37  myAwesomeHist->Fill(myAwesomeVar);
38  }
39 
40  TCanvas* can2 = new TCanvas("name", "Awesome Analysis");
41  myAwesomeHist->Draw();
42 
43 
44 }
TFile * file
Definition: tutCAFMacro.C:11
nhit
Definition: demo1.py:25
caf::StandardRecord * rec
Definition: tutCAFMacro.C:20
TH1F * myAwesomeHist
Definition: tutCAFMacro.C:24
unsigned int nhit
number of hits
Definition: SRSlice.h:22
TCanvas * can1
Definition: tutCAFMacro.C:16
The StandardRecord is the primary top-level object in the Common Analysis File trees.
TTree * tree
Definition: tutCAFMacro.C:14
SRSlice slc
Slice branch: nhit, extents, time, etc.
TCanvas * can2
Definition: tutCAFMacro.C:40