forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_ntuple_with_chain.C
32 lines (29 loc) · 1.19 KB
/
read_ntuple_with_chain.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Read several previously produced N-Tuples and print on screen its
// content.
//
// you can easily create some files with the following statement:
//
// for i in 0 1 2 3 4 5; \\
// do root -l -x -b -q \\
// "write_ntuple_to_file.cxx \\
// (\"conductivity_experiment_${i}.root\", 100)"; \\
// done
void read_ntuple_with_chain(){
// initiate a TChain with the name of the TTree to be processed
TChain in_chain("cond_data");
in_chain.Add("conductivity_experiment*.root"); // add files,
// wildcards work
// define variables and assign them to the corresponding branches
float pot, cur, temp, pres;
in_chain.SetBranchAddress("Potential", &pot);
in_chain.SetBranchAddress("Current", &cur);
in_chain.SetBranchAddress("Temperature", &temp);
in_chain.SetBranchAddress("Pressure", &pres);
cout << "Potential\tCurrent\tTemperature\tPressure\n";
for (size_t irow=0; irow<in_chain.GetEntries(); ++irow){
in_chain.GetEntry(irow); // loads all variables that have
// been connected to branches
cout << pot << "\t" << cur << "\t" << temp <<
"\t" << pres << endl;
}
}