00001 // $Id: Example_read_dst_write_table_ntup.C,v 1.6 2006/08/15 21:42:56 jeromel Exp $ 00002 // $Log: Example_read_dst_write_table_ntup.C,v $ 00003 // Revision 1.6 2006/08/15 21:42:56 jeromel 00004 // Fix rhic -> rhic.bnl.gov 00005 // 00006 // Revision 1.5 2000/05/09 20:15:43 kathy 00007 // transfer obsolete macros to /macros/obsolete; update other macros so that they use standard default inputs plus only few events by default so they'll be easy to run in autoQA macro testing 00008 // 00009 // Revision 1.4 2000/04/18 20:37:25 kathy 00010 // St_DataSet,St_DataSetIter,St_Table classes are nowchanged to TDataSet,TDataSetIter,TTable 00011 // 00012 // Revision 1.3 2000/04/13 21:46:21 kathy 00013 // remove loading of libtpc_Tables since l3Track table is now dst_track type from global 00014 // 00015 // Revision 1.2 2000/04/12 16:13:40 kathy 00016 // have changed so that macro loads only table libraries needed instead of all table libraries 00017 // 00018 // Revision 1.1 2000/01/21 18:20:45 kathy 00019 // now have macro that writes a table-based ntuple and another that reads the ntuple back in and draws from it 00020 // 00021 // 00022 //======================================================================= 00023 // owner: Kathy Turner 00024 // what it does: 00025 // - Reads an .dst.root produced from bfc 00026 // - finds a table (dst/globtrk) 00027 // - fills an ntuple with this table. 00028 // - Draws some plots from the ntuple. 00029 // - Writes out ntuple at end. 00030 //======================================================================= 00031 00032 00033 void Example_read_dst_write_table_ntup( 00034 Int_t nevents=2, 00035 const Char_t *MainFile= 00036 "/afs/rhic.bnl.gov/star/data/samples/gstar.dst.root", 00037 const Char_t *NtupFile="globtrk_ntup.root") 00038 { 00039 00040 cout << " nevents to process = " << nevents << endl; 00041 cout << " Input file = " << MainFile << endl; 00042 cout << " Output ntup file = " << NtupFile << endl; 00043 00044 gSystem->Load("St_base"); 00045 gSystem->Load("StChain"); 00046 00047 gSystem->Load("libglobal_Tables"); 00048 gSystem->Load("libgen_Tables"); 00049 gSystem->Load("libsim_Tables"); 00050 00051 gSystem->Load("StIOMaker"); 00052 gSystem->Load("StarClassLibrary"); 00053 gSystem->Load("StUtilities"); 00054 gSystem->Load("StAnalysisUtilities"); 00055 00056 // Setup top part of chain 00057 chain = new StChain("bfc"); 00058 chain->SetDebug(); 00059 00060 // setup chain with IOMaker - can read in .dst.root, .dst.xdf files 00061 StIOMaker *IOMk = new StIOMaker("IO","r",MainFile,"bfcTree"); 00062 IOMk->SetDebug(); 00063 IOMk->SetIOMode("r"); 00064 IOMk->SetBranch("*",0,"0"); //deactivate all branches 00065 // IOMk->SetBranch("tpc_tracks",0,"r"); //activate tpc_tracks Branch 00066 // IOMk->SetBranch("geantBranch",0,"r"); //activate geant Branch 00067 IOMk->SetBranch("dstBranch",0,"r"); //activate dst Branch 00068 00069 00070 // construct output ntuple file 00071 TFile *ntupfile = 0; 00072 00073 // construct ntuple 00074 St_TableNtuple *myNtuple=0; 00075 00076 // --- now execute chain member functions 00077 chain->Init(); 00078 00079 00080 // loop over events 00081 for (int iev=0;iev<nevents; iev++) 00082 { 00083 chain->Clear(); 00084 int iret = chain->Make(); 00085 if (iret) break; 00086 00087 cout << " !!!!! Now read event # " << iev << endl; 00088 00089 TDataSet *ds=chain->GetDataSet("dst/globtrk"); 00090 TDataSetIter dsiter(ds); 00091 St_dst_track *glob = (St_dst_track *) dsiter.Find("globtrk"); 00092 00093 // cout << " globtrk table pointer = " << glob << endl; 00094 00095 // if pointer is zero, go back to top and read in next event 00096 // last event is really end-run record, so it doesn't have the 00097 // data on it. After this record is passed, the while loop ends 00098 00099 if (!glob) continue; 00100 00101 // Create ntuple & file in first event! 00102 // Ntuple gets named "globtrk" here! 00103 // Must have variable list setup already in order to define an ntuple 00104 // We don't have this done until after we get to the table in the 00105 // first event - so am defining the ntuple below. 00106 // See Manuel's StMCAnalysisMaker class to see how to setup and fill 00107 // a general (not necessarily table) ntuple! 00108 // I *think* that this ntuple gets written to the last TFile opened! 00109 // 00110 00111 if (iev==0){ 00112 cout << " CREATE NTUPLE! " << endl; 00113 ntupfile = new TFile(NtupFile,"RECREATE","My Ntuple"); 00114 myNtuple = new St_TableNtuple((St_Table&)*glob); 00115 } 00116 00117 00118 // fill ntuple 00119 myNtuple->Fill((TTable&)*glob); 00120 } 00121 00122 cout << " ==> finished loop, now write ntuple to output file" << endl; 00123 // write ntuple in memory to the Tfile: 00124 myNtuple->Write(); 00125 00126 // draw some things from ntuple which is in memory 00127 gStyle->SetOptStat(111111); 00128 myNtuple->Draw("n_point"); 00129 myNtuple->Draw("r0:z0","n_point<50 && n_fit_point<40"); 00130 myNtuple->Draw("x_first0:x_first1","n_point<50 && n_fit_point<40"); 00131 00132 cout << " ==> close output file" << endl; 00133 // close ntuple in TFile 00134 ntupfile->Close(); 00135 00136 } 00137 00138 00139 00140
1.5.9