StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
bfcread_tagsBranch.C
1 // $Id: bfcread_tagsBranch.C,v 1.16 2006/08/15 21:43:14 jeromel Exp $
2 // $Log: bfcread_tagsBranch.C,v $
3 // Revision 1.16 2006/08/15 21:43:14 jeromel
4 // Fix rhic -> rhic.bnl.gov
5 //
6 // Revision 1.15 2000/06/15 21:32:56 kathy
7 // copied all integers to floats before writing out to file using fout --- otherwise CINT doesn't like it on Solaris
8 //
9 // Revision 1.14 2000/06/07 18:21:21 kathy
10 // finalized printouts
11 //
12 // Revision 1.13 2000/06/06 22:04:31 kathy
13 // updated to print out more info about tags
14 //
15 // Revision 1.12 2000/06/06 21:14:42 kathy
16 // updated to print out more info about tags
17 //
18 //
19 //======================================================================
20 // code written by: Sasha Vanyashin
21 // macro owner: Kathy
22 //
23 // what it does: reads .tags.root file produced from bfc & prints out info
24 // - a file name is given as input to the macro
25 // - this is a flat file (a TTree file)
26 // - prints out the branch name, leaf name & # tags
27 // - for given event#, prints out values of all tags
28 //
29 // branches -> TTree tables --- get a branch (table) from each TagsMaker
30 // (table names are encoded in branch.leaf names)
31 // leaves -> many leaves can be in each branch
32 // tags -> many tags (dimensions) can be in each leaf
33 //
34 // loop over leaves, then #events, then tags
35 //
36 // Inputs to macro:
37 // MainFile - input *.tags.root file
38 // printEvent - event # to print out details for (1 by default)
39 // fname - output file name to write QAInfo
40 // fullPrint - prints out lots more info if set to 1 (0 by default)
41 //
42 //=======================================================================
43 
44 void bfcread_tagsBranch(
45  const char *MainFile="/afs/rhic.bnl.gov/star/data/samples/gstar.tags.root",
46  Int_t printEvent=1,
47  const char *fname="qa_tags.out",
48  Int_t fullPrint=0)
49 {
50  // start timer
51  TStopwatch timer;
52  timer.Start();
53 
54  cout << endl << endl;
55  cout << " bfcread_tagsBranch.C: input file = " << MainFile << endl;
56  cout << " bfcread_tagsBranch.C: print event # " << printEvent << endl;
57  cout << " bfcread_tagsBranch.C: output file = " << fname << endl;
58  cout << " bfcread_tagsBranch.C: full printout = " << fullPrint << endl;
59  cout << endl;
60 
61  ofstream fout(fname);
62 
63  fout << endl << endl;
64  fout << " bfcread_tagsBranch.C: input file = " << MainFile << endl;
65  fout << " bfcread_tagsBranch.C: print evt# = " << printEvent << endl;
66  fout << " bfcread_tagsBranch.C: output file = " << fname << endl;
67  fout << " bfcread_tagsBranch.C: full printout = " << fullPrint << endl;
68  fout << endl;
69 
70  TFile *file = TFile::Open(MainFile);
71  TTree *tree = (TTree*)file->Get("Tag");
72 
73  cout <<" read file: " << file->GetName() << endl << endl;
74 
75  Int_t nEntries = tree->GetEntries();
76  cout << " Total # events = " << nEntries << endl;
77 
78  TObjArray *leaves = tree->GetListOfLeaves();
79  Int_t nLeaves = leaves->GetEntriesFast();
80 
81  cout << " Total # leaves = " << nLeaves << endl;
82 
83  TString *tName = new TString(" ");
84  TNamed *tableName=0;
85  TObjArray *tagTable = new TObjArray;
86  Int_t tableCount = 0;
87  Int_t *tableIndex = new Int_t[nLeaves];
88  Int_t tagCount = 0;
89 
90  TBranch *branch=0;
91  TLeaf *leaf=0;
92  Int_t ndim =0;
93 
94 //count number of tag tables encoded in the TTree branch names
95  for (Int_t l=0;l<nLeaves;l++) {
96  leaf = (TLeaf*)leaves->UncheckedAt(l);
97  tagCount+=leaf->GetNdata();
98  branch = leaf->GetBranch();
99  cout << "leaf # " << l << " br name = " <<
100  branch->GetName() << endl;
101  //new tag table name
102  if ( strstr(branch->GetName(), tName->Data()) == 0 ) {
103  tName = new TString(branch->GetName());
104  tName->Resize(tName->Index("."));
105  //the tableName is encoded in the branch Name before the "."
106  tableName = new TNamed(tName->Data(),"Tag");
107  tagTable->AddLast(tableName);
108  tableCount++;
109  }
110  tableIndex[l]=tableCount-1;
111  }
112 
113  cout << endl << " Total num tables(branches),tags = "
114  << tableCount << " " << tagCount << endl << endl;
115 
116  Int_t *countTagsTable = new Int_t[tableCount];
117  Int_t *countLeavesTable = new Int_t[tableCount];
118  Float_t *sumTagsLeaf = new Float_t[nLeaves];
119  Int_t *countTagsLeaf = new Int_t[nLeaves];
120 
121 // Now loop over leaves (to get values of tags)
122 
123  Int_t setBranch = -1;
124  Int_t nowBranch = -1;
125 
126  for (Int_t l=0;l<nLeaves;l++) {
127 
128  leaf = (TLeaf*)leaves->UncheckedAt(l);
129  branch = leaf->GetBranch();
130  ndim = leaf->GetNdata();
131 
132  nowBranch = tableIndex[l];
133 
134  //cout << " nowbranch, setBranch = " <<
135  // nowBranch << ", "<< setBranch << endl;
136 
137  Float_t RtableIndex=tableIndex[l];
138 
139  if (nowBranch != setBranch){
140  setBranch=nowBranch;
141  cout << " QAInfo: branch ";
142  cout.width(2);
143  cout << tableIndex[l] << " = ";
144  cout.width(10);
145  cout << ((TNamed*)tagTable->UncheckedAt(tableIndex[l]))->GetName();
146  cout << endl;
147  fout << " QAInfo: branch ";
148  fout.width(2);
149  fout << RtableIndex << " = ";
150  fout.width(10);
151  fout << ((TNamed*)tagTable->UncheckedAt(tableIndex[l]))->GetName();
152  fout << endl;
153  }
154 
155  countTagsTable[tableIndex[l]]+=leaf->GetNdata();
156  countLeavesTable[tableIndex[l]]++;
157  countTagsLeaf[l]+=ndim;
158 
159  Float_t Rl=l;
160  Float_t Rndim=ndim;
161  cout << " QAInfo: leaf ";
162  cout.width(3);
163  cout << l << " has ";
164  cout.width(1);
165  cout << ndim << " tags:";
166  cout << endl;
167  fout << " QAInfo: leaf ";
168  fout.width(3);
169  fout << Rl << " has ";
170  fout.width(1);
171  fout << Rndim << " tags:";
172  fout << endl;
173 
174 // loop over all events in each leaf
175 
176  for (Int_t nev=0; nev<nEntries; nev++) {
177  branch->GetEntry(nev);
178 
179 // loop over all tags in each leaf for each event
180 
181  for (Int_t itag=0;itag<ndim;itag++) {
182 
183  Int_t ik = nev+1;
184  if (ik==printEvent) {
185 
186  cout << " QAInfo: " << leaf->GetName();
187  if (ndim>1) cout << '['<<itag<<']';
188  cout << " = " << leaf->GetValue(itag) << endl;
189 
190  fout << " QAInfo: " << leaf->GetName();
191  if (ndim>1) fout << '['<<itag<<']';
192  fout << " = " << leaf->GetValue(itag) << endl;
193  }
194 
195  sumTagsLeaf[l]+=leaf->GetValue(itag);
196 
197  }
198  }
199  }
200  cout << endl << endl;
201  fout << endl << endl;
202 
203 
204  if (fullPrint == 1){
205 // loop over leaves again for printout at end
206  for (Int_t m=0; m<nLeaves; m++){
207 
208  leaf = (TLeaf*)leaves->UncheckedAt(m);
209  branch = leaf->GetBranch();
210  ndim = leaf->GetNdata();
211 
212  cout << " QAInfo: branch ";
213  cout.width(2);
214  cout << tableIndex[m] << " = ";
215  cout.width(10);
216  cout << ((TNamed*)tagTable->UncheckedAt(tableIndex[m]))->GetName();
217  cout << ", leaf ";
218  cout.width(3);
219  cout << m << " = ";
220  cout.width(24);
221  cout << leaf->GetName();
222  cout << ", #tags = ";
223  cout.width(1);
224  cout << ndim;
225  cout << endl;
226 
227  Float_t RtableIndex=tableIndex[m];
228  Float_t Rm=m;
229  Float_t Rndim=ndim;
230  fout << " QAInfo: branch ";
231  fout.width(2);
232  fout << RtableIndex << " = ";
233  fout.width(10);
234  fout << ((TNamed*)tagTable->UncheckedAt(tableIndex[m]))->GetName();
235  fout << ", leaf ";
236  fout.width(3);
237  fout << Rm << " = ";
238  fout.width(24);
239  fout << leaf->GetName();
240  fout << ", #tags = ";
241  fout.width(1);
242  fout << Rndim;
243  fout << endl;
244 
245  }
246  }
247  cout << endl << endl;
248  fout << endl << endl;
249 
250 
251 
252 // loop over leaves again for printout at end of averages
253  cout << " QAInfo: each leaf's avg over all tags,evts: " << endl;
254  fout << " QAInfo: each leaf's avg over all tags,evts: " << endl;
255 
256  for (Int_t m=0; m<nLeaves; m++){
257 
258  leaf = (TLeaf*)leaves->UncheckedAt(m);
259 
260  sumTagsLeaf[m]/=countTagsLeaf[m]*nEntries;
261 
262  cout << " QAInfo: avg leaf #";
263  cout.width(2);
264  cout << m << ", ";
265  cout.width(23);
266  cout << leaf->GetName() << " = ";
267  cout.width(12);
268  cout << sumTagsLeaf[m];
269  cout << endl;
270 
271  Float_t Rm=m;
272  fout << " QAInfo: avg leaf #";
273  fout.width(2);
274  fout << Rm << ", ";
275  fout.width(23);
276  fout << leaf->GetName() << " = ";
277  fout.width(12);
278  fout << sumTagsLeaf[m];
279  fout << endl;
280 
281  }
282  cout << endl << endl;
283  fout << endl << endl;
284 
285 
286 
287 // loop over all tables
288  for (Int_t m=0; m<tableCount; m++){
289 
290  cout << " QAInfo: branch(table) ";
291  cout.width(10);
292  cout << ((TNamed*)tagTable->UncheckedAt(m))->GetName() << " has ";
293  cout.width(4);
294  cout << countLeavesTable[m] << " leaves,";
295  cout.width(4);
296  cout << countTagsTable[m] << " tags" << endl;
297 
298  Float_t RcountLeavesTable=countLeavesTable[m];
299  Float_t RcountTagsTable=countTagsTable[m];
300  fout << " QAInfo: branch(table) ";
301  fout.width(10);
302  fout << ((TNamed*)tagTable->UncheckedAt(m))->GetName() << " has ";
303  fout.width(4);
304  fout << RcountLeavesTable << " leaves,";
305  fout.width(4);
306  fout << RcountTagsTable << " tags" << endl;
307 
308  }
309  cout << endl << endl;
310  fout << endl << endl;
311 
312 
313  Float_t RnEntries=nEntries;
314  Float_t RtableCount=tableCount;
315  Float_t RnLeaves=nLeaves;
316  Float_t RtagCount=tagCount;
317 
318  cout << " QAInfo: tot num events = " << nEntries << endl;
319  fout << " QAInfo: tot num events = " << RnEntries << endl;
320 
321  cout << " QAInfo: tot num branches = " << tableCount << endl;
322  fout << " QAInfo: tot num branches = " << RtableCount << endl;
323 
324  cout << " QAInfo: tot num leaves = " << nLeaves << endl;
325  fout << " QAInfo: tot num leaves = " << RnLeaves << endl;
326 
327  cout << " QAInfo: tot num tags = " << tagCount << endl;
328  fout << " QAInfo: tot num tags = " << RtagCount << endl;
329 
330 
331  // stop timer and print results
332  timer.Stop();
333  cout<< endl << endl <<"RealTime="<<timer.RealTime()<<
334  " seconds, CpuTime="<<timer.CpuTime()<<" seconds"<<endl;
335 
336  //cleanup
337  file->Close();
338  fout.close();
339 }
340 
341 
342 
343 
344 
virtual const char * GetName() const
special overload
Definition: StMaker.cxx:237