00001 // $Id: bfcread_hist_extract.C,v 3.3 2008/05/23 17:54:55 genevb Exp $ 00002 // $Log: bfcread_hist_extract.C,v $ 00003 // Revision 3.3 2008/05/23 17:54:55 genevb 00004 // Allow subset histogram list when copying/extracting 00005 // 00006 // Revision 3.2 2006/08/15 21:42:38 jeromel 00007 // Fix rhic -> rhic.bnl.gov 00008 // 00009 // Revision 3.1 2004/07/01 18:33:50 genevb 00010 // Macro to extract hists from BFC output hist.root files 00011 // 00012 // 00013 //====================================================================== 00014 // owner: Gene Van Buren 00015 // what it does: see below 00016 //======================================================================= 00017 // bfcread_hist_extract.C 00018 // 00019 // what it does: reads the *.hist.root file produced from a chain 00020 // (such as bfc) and 00021 // then extracts list of histograms from given input Maker 00022 // to an output file 00023 // 00024 // inputs: MainFile - *.hist.root file from bfc output 00025 // MakerHistDir - directory name of Maker that you want histograms 00026 // from (this will be first input when you did constructor) 00027 // -- see standard Maker names note below! 00028 // TopDirTree - top level directory tree in your input hist file 00029 // (this is 3rd argument of constructor for StTreeMaker that 00030 // you probably used to write the *.hist.root file) 00031 // NOTE: if you ran bfc, then the TopDirTree = bfcTree !! 00032 // OutFile - file where histograms will be written. Default is 00033 // same as MainFile with last part of MakerHistDir in the name. 00034 // PrintList - name of subset histogram list that you want extracted 00035 // - these are defined in StHistUtil, method SetDefaultPrintList 00036 // - default = 0, extracts all histograms in directory MakerHistDir 00037 // 00038 // standard Maker names in bfc 00039 // (but if you run your own Maker here, then use whatever name you give it) 00040 // are listed at 00041 // http://www.star.bnl.gov/STAR/html/comp_l/train/tut/bfc_maker_names.html 00042 // 00043 // 00044 // Documentation on StHistUtil class is at: 00045 // http://duvall.star.bnl.gov/STARAFS/comp/pkg/dev/StRoot/StAnalysisUtilities/doc/ 00046 // 00047 // Note: most of this code is copied from bfcread_hist_list.C 00048 //====================================================================== 00049 00050 00051 class StChain; 00052 StChain *chain; 00053 00054 class StIOMaker; 00055 StIOMaker *IOMk=0; 00056 00057 //------------------------------------------------------------------------ 00058 00059 void bfcread_hist_extract( 00060 const Char_t *MainFile= 00061 "/afs/rhic.bnl.gov/star/data/samples/gstar.hist.root", 00062 const Char_t *MakerHistDir="EventQA", 00063 const Char_t *TopDirTree="bfcTree", 00064 Char_t *OutFile=0, 00065 const Char_t *PrintList="") 00066 { 00067 00068 cout << "bfcread_hist_extract.C, input hist file = " 00069 << MainFile << endl; 00070 cout << "bfcread_hist_extract.C, directory name for hist = " 00071 << MakerHistDir << endl; 00072 cout << "bfcread_hist_extract.C, top level directory in hist file = " 00073 << TopDirTree << endl; 00074 00075 // 00076 gSystem->Load("St_base"); 00077 gSystem->Load("StChain"); 00078 gSystem->Load("StIOMaker"); 00079 gSystem->Load("StarClassLibrary"); 00080 gSystem->Load("StUtilities"); 00081 gSystem->Load("StAnalysisUtilities"); 00082 gSystem->Load("libglobal_Tables"); 00083 00084 // setup chain with IOMaker - can read in .dst.root, .dst.xdf files 00085 StIOMaker *IOMk = new StIOMaker("IO","r",MainFile,TopDirTree); 00086 IOMk->SetDebug(); 00087 IOMk->SetIOMode("r"); 00088 IOMk->SetBranch("*",0,"0"); //deactivate all branches 00089 IOMk->SetBranch("histBranch",0,"r"); //activate dst Branch 00090 00091 00092 // constructor for other maker (not used in chain) 00093 StHistUtil *HU = new StHistUtil; 00094 00095 // now must set pointer to StMaker so HistUtil can find histograms 00096 // with StHistUtil methods 00097 // -- input any maker pointer but must cast as type StMaker 00098 HU->SetPntrToMaker((StMaker *)IOMk); 00099 00100 // ONLY use StIOMaker in chain 00101 // --- now execute chain member functions - 1 event (histograms) only 00102 IOMk->Init(); 00103 IOMk->Clear(); 00104 IOMk->Make(); 00105 00106 // method to print out list of histograms 00107 // - can do this anytime after they're booked 00108 // - default is to print out QA hist branch 00109 Int_t NoHist=0; 00110 //NoHist = HU->ListHists(MakerHistDir); 00111 TList* dList = HU->FindHists(MakerHistDir); 00112 if (PrintList) HU->SetDefaultPrintList(MakerHistDir,PrintList); 00113 NoHist = HU->CopyHists(dList); 00114 TH1** nh = HU->getNewHist(); 00115 00116 TString name = MainFile; 00117 if (!OutFile) { 00118 name.Remove(0,name.Last('/')+1); 00119 TString name2 = MakerHistDir; 00120 name2.Remove(0,name2.Last('/')+1); 00121 name.Insert(name.First('.'),"_"); 00122 name.Insert(name.First('.'),name2); 00123 OutFile = name.Data(); 00124 } 00125 cout << "Output hist file: " << OutFile << endl; 00126 TFile* ofile = new TFile(OutFile,"RECREATE"); 00127 for (int i=0; i<NoHist; i++) { 00128 printf("Extracting: %d. %s : %s\n", 00129 i+1,nh[i]->GetName(),nh[i]->GetTitle()); 00130 nh[i]->Write(); 00131 } 00132 ofile->Close(); 00133 00134 } 00135 00136 00137 00138 00139 00140 00141
1.5.9