StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
bfcread_hist_integrated_to_ps.C
1 // $Id: bfcread_hist_integrated_to_ps.C,v 3.5 2018/03/21 02:53:12 genevb Exp $
2 // $Log: bfcread_hist_integrated_to_ps.C,v $
3 // Revision 3.5 2018/03/21 02:53:12 genevb
4 // Improper use of endl corrected
5 //
6 // Revision 3.4 2017/02/27 21:41:36 genevb
7 // StEvent.so now depends on StBichsel.so
8 //
9 // Revision 3.3 2013/03/14 17:28:31 genevb
10 // StTpcDb.so now depends on StEvent.so
11 //
12 // Revision 3.2 2010/03/16 16:23:08 fisyak
13 // StTpcDb requires StDetectorDbMaker
14 //
15 // Revision 3.1 2008/05/30 17:49:12 genevb
16 // Macro to sum over multiple files and prefixes to create output plots
17 //
18 //
19 //
20 //======================================================================
21 // author: G. Van Buren (BNL)
22 // what it does: see below
23 //=======================================================================
24 // bfcread_hist_integrated_to_ps.C
25 //
26 // what it does: reads multiple *.hist.root files produced from a chain
27 // (such as bfc) and
28 // adds histograms with the same name, but different prefix,
29 // from all the files
30 // then draws & sends to ps file the
31 // histograms from given input Maker
32 //
33 // (based on a combination of bfcread_hist_prefixes_add_to_ps.C and
34 // bfcread_hist_files_add.C)
35 //
36 // inputs: nfiles - number of files to process (set large to do all files)
37 // fileName - text file with list of hist.root files from bfc output
38 // MakerHistDir - directory name of Maker that you want histograms
39 // from (this will be first input when you did constructor)
40 // -- see standard Maker names note below!
41 // TopDirTree - top level directory tree in your input hist file
42 // (this is 3rd argument of constructor for StTreeMaker that
43 // you probably used to write the *.hist.root file)
44 // NOTE: if you ran bfc, then the TopDirTree = bfcTree !!
45 // psFile - output postscript file name
46 // PageTitle - title at top of each page - if it's "", then it's
47 // set to MainFile by default
48 // PrintList - name of subset histogram list that you want printed
49 // - these are defined in StHistUtil, method SetDefaultPrintList
50 // - default = "", prints all histograms in directory MakerHistDir
51 //
52 //
53 //
54 //======================================================================
55 
56 class StChain;
57 StChain *chain;
58 
59 class StIOMaker;
60 StIOMaker *IOMk=0;
61 
62 //------------------------------------------------------------------------
63 
64 void bfcread_hist_integrated_to_ps(
65  int nfiles=3,
66  const Char_t *fileName="filelist",
67  const Char_t *MakerHistDir="EventQA",
68  const Char_t *TopDirTree="bfcTree",
69  const Char_t *psFile="QA_hist.ps",
70  const Char_t *PageTitle="",
71  const Char_t *PrintList="",
72  const Int_t ZoneH=2,
73  const Int_t ZoneV=3
74 )
75 {
76 
77  cout << "bfcread_hist_integrated_to_ps.C, input file list = "
78  << fileName << endl;
79  cout << "bfcread_hist_integrated_to_ps.C, directory name for hist = "
80  << MakerHistDir << endl;
81  cout << "bfcread_hist_integrated_to_ps.C, top level directory in hist file = "
82  << TopDirTree << endl;
83  cout << "bfcread_hist_integrated_to_ps.C, output ps file = "
84  << psFile << endl;
85  cout << "bfcread_hist_integrated_to_ps.C, page title for histograms = "
86  << PageTitle << endl;
87  cout << "bfcread_hist_integrated_to_ps.C, subset list name of which histograms to draw,print = "
88  << PrintList << endl;
89  cout << "bfcread_hist_integrated_to_ps.C, # histograms on page horizontally = "
90  << ZoneH << endl;
91  cout << "bfcread_hist_integrated_to_ps.C, # histograms on page vertically = "
92  << ZoneV << endl;
93 
94 //
95  gSystem->Load("St_base");
96  gSystem->Load("StChain");
97  gSystem->Load("StIOMaker");
98  gSystem->Load("StUtilities");
99  gSystem->Load("StAnalysisUtilities");
100  gSystem->Load("libglobal_Tables");
101  gSystem->Load("libtpc_Tables");
102  gSystem->Load("libStDb_Tables.so");
103  gSystem->Load("StDetectorDbMaker");
104  gSystem->Load("StBichsel");
105  gSystem->Load("StEvent");
106  gSystem->Load("StTpcDb");
107  gSystem->Load("StPmdUtil");
108  gSystem->Load("St_QA_Maker");
109 
110 // read file list from text file (maximum of 8192 files)
111  char **fList = new char[8192][256];
112  ifstream fin(fileName);
113  if (fin) {
114  int j=0;
115  cout << "Input file " << fileName << " found." << endl;
116  for (Int_t i=0;i<nfiles;i++){
117  char *line = new char[256];
118  fin >> line;
119  if (fin.eof()) break;
120  fList[j] = line;
121  cout << " Added file : " << fList[j] << endl;
122  j++;
123  }
124  }
125  fin.close();
126 
127 // setup chain with IOMaker - can read in .dst.root, .dst.xdf files
128  StFile* fff = new StFile(fList);
129  StIOMaker *IOMk = new StIOMaker("IO","r",fff,TopDirTree);
130  IOMk->SetDebug();
131  IOMk->SetIOMode("r");
132  IOMk->SetBranch("*",0,"0"); //deactivate all branches
133  IOMk->SetBranch("histBranch",0,"r"); //activate dst Branch
134 
135 // temporary storage of summed histograms
136  TString HMname = MakerHistDir;
137  HMname.Prepend("Summed");
138  const char* MakerHistDirS = HMname.Data();
139  StHistMaker *HM = new StHistMaker(MakerHistDirS);
140 
141  StHistUtil *SHU[2];
142  StHistUtil *HU;
143  SHU[0] = new StHistUtil;
144  SHU[1] = new StHistUtil;
145  Bool_t firstSet[2];
146  Int_t SHUidx, prefixNum, nPrefixes = SHU[0]->GetNumOfPosPrefixes();
147 
148 // now must set pointer to StMaker so HistUtil can find histograms
149 // with StHistUtil methods
150  for (SHUidx=0;SHUidx<2;SHUidx++) {
151  HU = SHU[SHUidx];
152  HU->SetPntrToMaker(IOMk);
153  HU->IgnorePrefixes();
154  HU->SetDefaultPrintList(MakerHistDir,PrintList);
155  firstSet[SHUidx] = kTRUE;
156  }
157 
158 // ONLY use StIOMaker in chain
159 // --- now execute chain member functions - 1 event (histograms) only
160  IOMk->Init();
161  HM->Init();
162 
163  Int_t istat=0;
164  Int_t ifl=0;
165 
166  while (ifl<nfiles && istat==0) {
167 
168  cout << "\nNow processing file : " << ifl+1 << "\n" << endl;
169 
170 // --- each file contains only histograms (1 "event" == 1 Make call)
171 
172  IOMk->Clear();
173  istat = IOMk->Open();
174  istat = IOMk->Make();
175 
176  // from list_all macro
177  if (!(IOMk->GetDataSet("hist"))) {
178  cout << " No histogram branch found in file!" << endl;
179  } else {
180 
181  Int_t hCCount = 0;
182 
183 
184  for (prefixNum=0; prefixNum < nPrefixes; prefixNum++) {
185  SHUidx = (prefixNum>0 ? 1 : 0);
186  HU = SHU[SHUidx];
187 // get the TList pointer to the histograms for this branch:
188  TList* dirList = HU->FindHists(MakerHistDir,HU->GetPrefix(prefixNum));
189  if (dirList && (dirList->GetSize())) {
190 
191  if (firstSet[SHUidx]) {
192  firstSet[SHUidx] = kFALSE;
193 
194 // now make a copy of all histograms into the new histograms!
195  hCCount = HU->CopyHists(dirList);
196  cout << "bfcread_hist_integrated_to_ps.C, # histograms copied with prefix " <<
197  HU->GetPrefix(prefixNum) << " = " << hCCount << endl;
198 
199  HM->SetHArraySize(HU->getNewHistSize());
200  HM->SetHArray(HU->getNewHist());
201  HM->Make();
202  } else { // first set or not
203  hCCount = HU->AddHists(dirList);
204  cout << "bfcread_hist_integrated_to_ps.C, # histograms added with prefix " <<
205  HU->GetPrefix(prefixNum) << " = " << hCCount << endl;
206  } // first set or not
207  HU->Clear();
208  } // found hists
209 
210  } // loop over prefixes
211 
212  } // histogram branch found
213 
214  ifl++;
215  istat = IOMk->Close();
216  } // loop over files
217 
218 
219 
220 // method to print out list of histograms
221 // - can do this anytime after they're booked
222 // - default is to print out QA hist branch
223  Int_t NoHist=0;
224  NoHist = HU->ListHists(MakerHistDirS);
225  cout << " in bfcread_hist_list: Num of Hist = " << NoHist << endl;
226 
227 // Set the default canvas style to plain (so it won't print out grey!)
228  gROOT->SetStyle("Plain");
229 // gStyle->SetOptStat(111111);
230 
231  HU->SetHistsNamesDraw("*","*");
232  HU->GetRunYear(fList[0]);
233  HU->SetOutFile(psFile);
234  HU->SetZones(ZoneH,ZoneV);
235  HU->SetPaperSize();
236  HU->SetDefaultLogXList(MakerHistDirS);
237  HU->SetDefaultLogYList(MakerHistDirS);
238  if (PageTitle=="") PageTitle=fileName;
239  HU->SetGlobalTitle(PageTitle);
240 
241 
242  Int_t numLog = 0;
243  numLog = HU->ExamineLogYList();
244  cout <<" bfcread_hist_integrated_to_ps.C, Number hist to plot with log scale = " << numLog << endl;
245 
246  Int_t numPrint = 0;
247  numPrint = HU->ExaminePrintList();
248  cout << " bfcread_hist_integrated_to_ps.C, Number hist to print = " << numPrint << endl;
249 
250 // Now draw the actual histograms to canvas and to ps file
251  HU->DrawHists(MakerHistDirS);
252 
253  cout <<" bfcread_hist_integrated_to_ps.C, end of macro" << endl;
254 
255 }
256 
257 
258 
259 
260 
261 
262 
263 
264 
265 
266 
267 
Definition: StTree.h:125
virtual Int_t Make()
Definition: StHistMaker.cxx:34
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