All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SBNOsc/macro/example_macro.cc
Go to the documentation of this file.
1 #include "TFile.h"
2 #include "TH1F.h"
3 #include "TTreeReader.h"
4 #include "TTreeReaderValue.h"
5 
6 void read_numu_file() {
7  // open the input file
8  TFile f("/sbnd/data/users/gputnam/NuMu/outputs/sbnd_passthru_v1/SBND_numu_all.root");
9 
10  // histogram which will store neutrino energies
11  TH1F *hist = new TH1F("", "", 50, 0, 5);
12 
13  // maximum number of events to read from file
14  int max_event = -1;
15 
16  // setup a "TTreeReader" to read from the "sbnana" Tree
17  // Each entry in the branch is a single "Event" in SBND
18  TTreeReader myReader("sbnana", &f);
19 
20  // Access to energy of each neutrino in the event.
21  // In SBND, there are sometimes multiple neutrinos interacting
22  // in the detector in each event, so we need to keep track of an
23  // array of energies. However, most of the time this array will
24  // just have one entry.
25  TTreeReaderArray<double> neutrino_energies(myReader, "truth.neutrino.energy");
26 
27  int event_ind = 0;
28  // Loop over the sbnana Tree
29  while (myReader.Next()) {
30  // break if we are done
31  if (max_event >= 0 && event_ind == max_event) break;
32 
33  // fill each neutrino enrgy in each interaction
34  for (double e: neutrino_energies) {
35  hist->Fill(e);
36  }
37 
38  event_ind += 1;
39  }
40  hist->Draw();
41 
42 }
void read_numu_file()
do i e