00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 void bfcread_tagsBranch(
00045 const char *MainFile="/afs/rhic.bnl.gov/star/data/samples/gstar.tags.root",
00046 Int_t printEvent=1,
00047 const char *fname="qa_tags.out",
00048 Int_t fullPrint=0)
00049 {
00050
00051 TStopwatch timer;
00052 timer.Start();
00053
00054 cout << endl << endl;
00055 cout << " bfcread_tagsBranch.C: input file = " << MainFile << endl;
00056 cout << " bfcread_tagsBranch.C: print event # " << printEvent << endl;
00057 cout << " bfcread_tagsBranch.C: output file = " << fname << endl;
00058 cout << " bfcread_tagsBranch.C: full printout = " << fullPrint << endl;
00059 cout << endl;
00060
00061 ofstream fout(fname);
00062
00063 fout << endl << endl;
00064 fout << " bfcread_tagsBranch.C: input file = " << MainFile << endl;
00065 fout << " bfcread_tagsBranch.C: print evt# = " << printEvent << endl;
00066 fout << " bfcread_tagsBranch.C: output file = " << fname << endl;
00067 fout << " bfcread_tagsBranch.C: full printout = " << fullPrint << endl;
00068 fout << endl;
00069
00070 TFile *file = TFile::Open(MainFile);
00071 TTree *tree = (TTree*)file->Get("Tag");
00072
00073 cout <<" read file: " << file->GetName() << endl << endl;
00074
00075 Int_t nEntries = tree->GetEntries();
00076 cout << " Total # events = " << nEntries << endl;
00077
00078 TObjArray *leaves = tree->GetListOfLeaves();
00079 Int_t nLeaves = leaves->GetEntriesFast();
00080
00081 cout << " Total # leaves = " << nLeaves << endl;
00082
00083 TString *tName = new TString(" ");
00084 TNamed *tableName=0;
00085 TObjArray *tagTable = new TObjArray;
00086 Int_t tableCount = 0;
00087 Int_t *tableIndex = new Int_t[nLeaves];
00088 Int_t tagCount = 0;
00089
00090 TBranch *branch=0;
00091 TLeaf *leaf=0;
00092 Int_t ndim =0;
00093
00094
00095 for (Int_t l=0;l<nLeaves;l++) {
00096 leaf = (TLeaf*)leaves->UncheckedAt(l);
00097 tagCount+=leaf->GetNdata();
00098 branch = leaf->GetBranch();
00099 cout << "leaf # " << l << " br name = " <<
00100 branch->GetName() << endl;
00101
00102 if ( strstr(branch->GetName(), tName->Data()) == 0 ) {
00103 tName = new TString(branch->GetName());
00104 tName->Resize(tName->Index("."));
00105
00106 tableName = new TNamed(tName->Data(),"Tag");
00107 tagTable->AddLast(tableName);
00108 tableCount++;
00109 }
00110 tableIndex[l]=tableCount-1;
00111 }
00112
00113 cout << endl << " Total num tables(branches),tags = "
00114 << tableCount << " " << tagCount << endl << endl;
00115
00116 Int_t *countTagsTable = new Int_t[tableCount];
00117 Int_t *countLeavesTable = new Int_t[tableCount];
00118 Float_t *sumTagsLeaf = new Float_t[nLeaves];
00119 Int_t *countTagsLeaf = new Int_t[nLeaves];
00120
00121
00122
00123 Int_t setBranch = -1;
00124 Int_t nowBranch = -1;
00125
00126 for (Int_t l=0;l<nLeaves;l++) {
00127
00128 leaf = (TLeaf*)leaves->UncheckedAt(l);
00129 branch = leaf->GetBranch();
00130 ndim = leaf->GetNdata();
00131
00132 nowBranch = tableIndex[l];
00133
00134
00135
00136
00137 Float_t RtableIndex=tableIndex[l];
00138
00139 if (nowBranch != setBranch){
00140 setBranch=nowBranch;
00141 cout << " QAInfo: branch ";
00142 cout.width(2);
00143 cout << tableIndex[l] << " = ";
00144 cout.width(10);
00145 cout << ((TNamed*)tagTable->UncheckedAt(tableIndex[l]))->GetName();
00146 cout << endl;
00147 fout << " QAInfo: branch ";
00148 fout.width(2);
00149 fout << RtableIndex << " = ";
00150 fout.width(10);
00151 fout << ((TNamed*)tagTable->UncheckedAt(tableIndex[l]))->GetName();
00152 fout << endl;
00153 }
00154
00155 countTagsTable[tableIndex[l]]+=leaf->GetNdata();
00156 countLeavesTable[tableIndex[l]]++;
00157 countTagsLeaf[l]+=ndim;
00158
00159 Float_t Rl=l;
00160 Float_t Rndim=ndim;
00161 cout << " QAInfo: leaf ";
00162 cout.width(3);
00163 cout << l << " has ";
00164 cout.width(1);
00165 cout << ndim << " tags:";
00166 cout << endl;
00167 fout << " QAInfo: leaf ";
00168 fout.width(3);
00169 fout << Rl << " has ";
00170 fout.width(1);
00171 fout << Rndim << " tags:";
00172 fout << endl;
00173
00174
00175
00176 for (Int_t nev=0; nev<nEntries; nev++) {
00177 branch->GetEntry(nev);
00178
00179
00180
00181 for (Int_t itag=0;itag<ndim;itag++) {
00182
00183 Int_t ik = nev+1;
00184 if (ik==printEvent) {
00185
00186 cout << " QAInfo: " << leaf->GetName();
00187 if (ndim>1) cout << '['<<itag<<']';
00188 cout << " = " << leaf->GetValue(itag) << endl;
00189
00190 fout << " QAInfo: " << leaf->GetName();
00191 if (ndim>1) fout << '['<<itag<<']';
00192 fout << " = " << leaf->GetValue(itag) << endl;
00193 }
00194
00195 sumTagsLeaf[l]+=leaf->GetValue(itag);
00196
00197 }
00198 }
00199 }
00200 cout << endl << endl;
00201 fout << endl << endl;
00202
00203
00204 if (fullPrint == 1){
00205
00206 for (Int_t m=0; m<nLeaves; m++){
00207
00208 leaf = (TLeaf*)leaves->UncheckedAt(m);
00209 branch = leaf->GetBranch();
00210 ndim = leaf->GetNdata();
00211
00212 cout << " QAInfo: branch ";
00213 cout.width(2);
00214 cout << tableIndex[m] << " = ";
00215 cout.width(10);
00216 cout << ((TNamed*)tagTable->UncheckedAt(tableIndex[m]))->GetName();
00217 cout << ", leaf ";
00218 cout.width(3);
00219 cout << m << " = ";
00220 cout.width(24);
00221 cout << leaf->GetName();
00222 cout << ", #tags = ";
00223 cout.width(1);
00224 cout << ndim;
00225 cout << endl;
00226
00227 Float_t RtableIndex=tableIndex[m];
00228 Float_t Rm=m;
00229 Float_t Rndim=ndim;
00230 fout << " QAInfo: branch ";
00231 fout.width(2);
00232 fout << RtableIndex << " = ";
00233 fout.width(10);
00234 fout << ((TNamed*)tagTable->UncheckedAt(tableIndex[m]))->GetName();
00235 fout << ", leaf ";
00236 fout.width(3);
00237 fout << Rm << " = ";
00238 fout.width(24);
00239 fout << leaf->GetName();
00240 fout << ", #tags = ";
00241 fout.width(1);
00242 fout << Rndim;
00243 fout << endl;
00244
00245 }
00246 }
00247 cout << endl << endl;
00248 fout << endl << endl;
00249
00250
00251
00252
00253 cout << " QAInfo: each leaf's avg over all tags,evts: " << endl;
00254 fout << " QAInfo: each leaf's avg over all tags,evts: " << endl;
00255
00256 for (Int_t m=0; m<nLeaves; m++){
00257
00258 leaf = (TLeaf*)leaves->UncheckedAt(m);
00259
00260 sumTagsLeaf[m]/=countTagsLeaf[m]*nEntries;
00261
00262 cout << " QAInfo: avg leaf #";
00263 cout.width(2);
00264 cout << m << ", ";
00265 cout.width(23);
00266 cout << leaf->GetName() << " = ";
00267 cout.width(12);
00268 cout << sumTagsLeaf[m];
00269 cout << endl;
00270
00271 Float_t Rm=m;
00272 fout << " QAInfo: avg leaf #";
00273 fout.width(2);
00274 fout << Rm << ", ";
00275 fout.width(23);
00276 fout << leaf->GetName() << " = ";
00277 fout.width(12);
00278 fout << sumTagsLeaf[m];
00279 fout << endl;
00280
00281 }
00282 cout << endl << endl;
00283 fout << endl << endl;
00284
00285
00286
00287
00288 for (Int_t m=0; m<tableCount; m++){
00289
00290 cout << " QAInfo: branch(table) ";
00291 cout.width(10);
00292 cout << ((TNamed*)tagTable->UncheckedAt(m))->GetName() << " has ";
00293 cout.width(4);
00294 cout << countLeavesTable[m] << " leaves,";
00295 cout.width(4);
00296 cout << countTagsTable[m] << " tags" << endl;
00297
00298 Float_t RcountLeavesTable=countLeavesTable[m];
00299 Float_t RcountTagsTable=countTagsTable[m];
00300 fout << " QAInfo: branch(table) ";
00301 fout.width(10);
00302 fout << ((TNamed*)tagTable->UncheckedAt(m))->GetName() << " has ";
00303 fout.width(4);
00304 fout << RcountLeavesTable << " leaves,";
00305 fout.width(4);
00306 fout << RcountTagsTable << " tags" << endl;
00307
00308 }
00309 cout << endl << endl;
00310 fout << endl << endl;
00311
00312
00313 Float_t RnEntries=nEntries;
00314 Float_t RtableCount=tableCount;
00315 Float_t RnLeaves=nLeaves;
00316 Float_t RtagCount=tagCount;
00317
00318 cout << " QAInfo: tot num events = " << nEntries << endl;
00319 fout << " QAInfo: tot num events = " << RnEntries << endl;
00320
00321 cout << " QAInfo: tot num branches = " << tableCount << endl;
00322 fout << " QAInfo: tot num branches = " << RtableCount << endl;
00323
00324 cout << " QAInfo: tot num leaves = " << nLeaves << endl;
00325 fout << " QAInfo: tot num leaves = " << RnLeaves << endl;
00326
00327 cout << " QAInfo: tot num tags = " << tagCount << endl;
00328 fout << " QAInfo: tot num tags = " << RtagCount << endl;
00329
00330
00331
00332 timer.Stop();
00333 cout<< endl << endl <<"RealTime="<<timer.RealTime()<<
00334 " seconds, CpuTime="<<timer.CpuTime()<<" seconds"<<endl;
00335
00336
00337 file->Close();
00338 fout.close();
00339 }
00340
00341
00342
00343
00344