StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
bfcread_hist_extract.C
1 // $Id: bfcread_hist_extract.C,v 3.3 2008/05/23 17:54:55 genevb Exp $
2 // $Log: bfcread_hist_extract.C,v $
3 // Revision 3.3 2008/05/23 17:54:55 genevb
4 // Allow subset histogram list when copying/extracting
5 //
6 // Revision 3.2 2006/08/15 21:42:38 jeromel
7 // Fix rhic -> rhic.bnl.gov
8 //
9 // Revision 3.1 2004/07/01 18:33:50 genevb
10 // Macro to extract hists from BFC output hist.root files
11 //
12 //
13 //======================================================================
14 // owner: Gene Van Buren
15 // what it does: see below
16 //=======================================================================
17 // bfcread_hist_extract.C
18 //
19 // what it does: reads the *.hist.root file produced from a chain
20 // (such as bfc) and
21 // then extracts list of histograms from given input Maker
22 // to an output file
23 //
24 // inputs: MainFile - *.hist.root file from bfc output
25 // MakerHistDir - directory name of Maker that you want histograms
26 // from (this will be first input when you did constructor)
27 // -- see standard Maker names note below!
28 // TopDirTree - top level directory tree in your input hist file
29 // (this is 3rd argument of constructor for StTreeMaker that
30 // you probably used to write the *.hist.root file)
31 // NOTE: if you ran bfc, then the TopDirTree = bfcTree !!
32 // OutFile - file where histograms will be written. Default is
33 // same as MainFile with last part of MakerHistDir in the name.
34 // PrintList - name of subset histogram list that you want extracted
35 // - these are defined in StHistUtil, method SetDefaultPrintList
36 // - default = 0, extracts all histograms in directory MakerHistDir
37 //
38 // standard Maker names in bfc
39 // (but if you run your own Maker here, then use whatever name you give it)
40 // are listed at
41 // http://www.star.bnl.gov/STAR/html/comp_l/train/tut/bfc_maker_names.html
42 //
43 //
44 // Documentation on StHistUtil class is at:
45 // http://duvall.star.bnl.gov/STARAFS/comp/pkg/dev/StRoot/StAnalysisUtilities/doc/
46 //
47 // Note: most of this code is copied from bfcread_hist_list.C
48 //======================================================================
49 
50 
51 class StChain;
52 StChain *chain;
53 
54 class StIOMaker;
55 StIOMaker *IOMk=0;
56 
57 //------------------------------------------------------------------------
58 
59 void bfcread_hist_extract(
60  const Char_t *MainFile=
61  "/afs/rhic.bnl.gov/star/data/samples/gstar.hist.root",
62  const Char_t *MakerHistDir="EventQA",
63  const Char_t *TopDirTree="bfcTree",
64  Char_t *OutFile=0,
65  const Char_t *PrintList="")
66 {
67 
68  cout << "bfcread_hist_extract.C, input hist file = "
69  << MainFile << endl;
70  cout << "bfcread_hist_extract.C, directory name for hist = "
71  << MakerHistDir << endl;
72  cout << "bfcread_hist_extract.C, top level directory in hist file = "
73  << TopDirTree << endl;
74 
75 //
76  gSystem->Load("St_base");
77  gSystem->Load("StChain");
78  gSystem->Load("StIOMaker");
79  gSystem->Load("StarClassLibrary");
80  gSystem->Load("StUtilities");
81  gSystem->Load("StAnalysisUtilities");
82  gSystem->Load("libglobal_Tables");
83 
84 // setup chain with IOMaker - can read in .dst.root, .dst.xdf files
85  StIOMaker *IOMk = new StIOMaker("IO","r",MainFile,TopDirTree);
86  IOMk->SetDebug();
87  IOMk->SetIOMode("r");
88  IOMk->SetBranch("*",0,"0"); //deactivate all branches
89  IOMk->SetBranch("histBranch",0,"r"); //activate dst Branch
90 
91 
92 // constructor for other maker (not used in chain)
93  StHistUtil *HU = new StHistUtil;
94 
95 // now must set pointer to StMaker so HistUtil can find histograms
96 // with StHistUtil methods
97 // -- input any maker pointer but must cast as type StMaker
98  HU->SetPntrToMaker((StMaker *)IOMk);
99 
100 // ONLY use StIOMaker in chain
101 // --- now execute chain member functions - 1 event (histograms) only
102  IOMk->Init();
103  IOMk->Clear();
104  IOMk->Make();
105 
106 // method to print out list of histograms
107 // - can do this anytime after they're booked
108 // - default is to print out QA hist branch
109  Int_t NoHist=0;
110  //NoHist = HU->ListHists(MakerHistDir);
111  TList* dList = HU->FindHists(MakerHistDir);
112  if (PrintList) HU->SetDefaultPrintList(MakerHistDir,PrintList);
113  NoHist = HU->CopyHists(dList);
114  TH1** nh = HU->getNewHist();
115 
116  TString name = MainFile;
117  if (!OutFile) {
118  name.Remove(0,name.Last('/')+1);
119  TString name2 = MakerHistDir;
120  name2.Remove(0,name2.Last('/')+1);
121  name.Insert(name.First('.'),"_");
122  name.Insert(name.First('.'),name2);
123  OutFile = name.Data();
124  }
125  cout << "Output hist file: " << OutFile << endl;
126  TFile* ofile = new TFile(OutFile,"RECREATE");
127  for (int i=0; i<NoHist; i++) {
128  printf("Extracting: %d. %s : %s\n",
129  i+1,nh[i]->GetName(),nh[i]->GetTitle());
130  nh[i]->Write();
131  }
132  ofile->Close();
133 
134 }
135 
136 
137 
138 
139 
140 
141 
virtual void Clear(Option_t *opt)
User defined functions.
Definition: StIOMaker.cxx:252
virtual void SetIOMode(Option_t *iomode="w")
number of transactions
Definition: StIOInterFace.h:35
virtual Int_t Make()
Definition: StIOMaker.cxx:183
virtual const char * GetName() const
special overload
Definition: StMaker.cxx:237