Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tree2csv.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file tree2csv.C
1 #include "tau_commons.h"
2 
9 int tree2csv( TString filelist, TString csv_out = TString("output_raw.txt") )
10 {
11  /* Create a TChain from trees in multiple input files */
12  TChain chain("candidates");
13 
14  /* open stream from input file list */
15  ifstream in;
16  in.open( filelist );
17 
18  /* add files from input list to TChain */
19  TString fname;
20  while (1) {
21  in >> fname;
22  if (!in.good()) break;
23  cout << "Adding input file " << fname << endl;
24  chain.Add(fname);
25  }
26 
27  /* close stream from input file list */
28  in.close();
29 
30  /* particle selection */
32 
33  /* select columns to keep */
34  TString cols_keep("*");
35 
36  /* Set up TTreePlayer to print output to ascii file */
37  ((TTreePlayer*)(chain.GetPlayer()))->SetScanRedirect(true);
38  ((TTreePlayer*)(chain.GetPlayer()))->SetScanFileName( csv_out );
39  chain.SetScanField(0);
40 
41  /* Call the Scan command that writes the tree content.
42  *
43  * Options:
44  *
45  * colsize=X --> set column size (length of character). This should correspond to the longest branch name.
46  */
47  chain.Scan( cols_keep , select_jetcandidates , "colsize=30");
48 
49  return 0;
50 }