Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:12:53

0001 #include "tau_commons.h"
0002 
0003 /**
0004  * Save ROOT::TTree as CSV file
0005  *
0006  * Written by nils.feege@stonybrook.edu
0007  */
0008 
0009 int tree2csv( TString filelist, TString csv_out = TString("output_raw.txt") )
0010 {
0011   /* Create a TChain from trees in multiple input files */
0012   TChain chain("candidates");
0013 
0014   /* open stream from input file list */
0015   ifstream in;
0016   in.open( filelist );
0017 
0018   /* add files from input list to TChain */
0019   TString fname;
0020   while (1) {
0021     in >> fname;
0022     if (!in.good()) break;
0023     cout << "Adding input file " << fname << endl;
0024     chain.Add(fname);
0025   }
0026 
0027   /* close stream from input file list */
0028   in.close();
0029 
0030   /* particle selection */
0031   TCut select_jetcandidates( tau_commons::select_accept_jet && ( tau_commons::select_true_uds || tau_commons::select_true_tau ) );
0032 
0033   /* select columns to keep */
0034   TString cols_keep("*");
0035 
0036   /* Set up TTreePlayer to print output to ascii file */
0037   ((TTreePlayer*)(chain.GetPlayer()))->SetScanRedirect(true);
0038   ((TTreePlayer*)(chain.GetPlayer()))->SetScanFileName( csv_out );
0039   chain.SetScanField(0);
0040 
0041   /* Call the Scan command that writes the tree content.
0042    *
0043    * Options:
0044    *
0045    * colsize=X --> set column size (length of character). This should correspond to the longest branch name.
0046    */
0047   chain.Scan( cols_keep , select_jetcandidates , "colsize=30");
0048 
0049   return 0;
0050 }