AliRoot Core  edcc906 (edcc906)
MakeTreeStat.C
Go to the documentation of this file.
1 
38 
39 
40 
41 
42 
43 
44 #include "TFile.h"
45 #include "TTree.h"
46 #include "TBranch.h"
47 #include "TMath.h"
48 #include "TArrayF.h"
49 #include "TObjArray.h"
50 #include "TObjString.h"
51 
52 
53 
54 
55 TTree *fTree; // tree of interest
56 TObjArray aReport; // array with branch statistic
57 TArrayF totSize; // total size for branch
58 TArrayF zipSize; // zip Size for branch
59 TArrayF zipRatio; // zip Ratio for branch
60 
61 void MakeStat(TTree *tree, Bool_t zipSort);
62 
63 
64 
65 void PrintSorted(Bool_t zipSort){
67 
68  Int_t entries = aReport.GetEntries();
69  Int_t* indexes = new Int_t[entries];
70  if (zipSort) TMath::Sort(entries,zipSize.GetArray(),indexes,kTRUE);
71  else{
72  TMath::Sort(entries,totSize.GetArray(),indexes,kTRUE);
73  }
74  Float_t zipBytes = zipSize[indexes[0]];
75  Float_t totBytes = totSize[indexes[0]];
76  Float_t ratioT = 100.*zipBytes/totBytes;
77  for (Int_t i=entries-1; i>=0; i--){
78  Int_t ib = indexes[i];
79  Float_t ratio0= 100.*totSize[ib]/totBytes;
80  Float_t ratio1= 100.*zipSize[ib]/zipBytes;
81  if (i==0) {
82  printf("\n------------------------------------------------------------\n");
83  printf("%d \t\t%5.f(%.2f\%) \t\t%5.f(%.2f\%) \t%.2f \t%s\n",i,
84  totSize[ib],100., zipSize[ib],100., 100.*zipRatio[ib], aReport.At(ib)->GetName());
85  }else{
86  printf("%d \t\t%5.f(%.2f\%) \t\t%5.f(%.2f\%) \t%.2f \t%s\n",i,
87  totSize[ib],ratio0, zipSize[ib],ratio1, 100.*zipRatio[ib], aReport.At(ib)->GetName());
88  }
89  }
90 
91 
92 }
93 
94 
95 void AddToReport(const char *prefix,const char * name, Float_t size[2], Float_t ratio){
97 
98  char fullname[10000];
99  sprintf(fullname,"%s.%s",prefix,name);
100  aReport.AddLast(new TObjString(fullname));
101  Int_t entry = aReport.GetEntries();
102  if (totSize.GetSize()<entry){
103  totSize.Set(entry*2);
104  zipSize.Set(entry*2);
105  zipRatio.Set(entry*2);
106  }
107  totSize[entry-1]=Float_t(size[0]);
108  zipSize[entry-1]=Float_t(size[1]);
109  zipRatio[entry-1]=Float_t(ratio);
110 }
111 
112 
113 
114 
115 
116 void MakeStat(const char *prefix, TBranch * branch, Float_t* size, Float_t mratio);
117 
118 
119 
120 void MakeStat(TTree *tree, Bool_t zipSort){
122 
123  fTree= tree;
124  aReport.Clear();
125  TObjArray * array = tree->GetListOfBranches();
126  Float_t size[2]={0,0};
127  char * prefix ="";
128  Float_t mratio=tree->GetZipBytes()/float(tree->GetTotBytes());
129  for (Int_t i=0; i<array->GetEntries(); i++){
130  MakeStat(prefix,(TBranch*)array->At(i),size, mratio);
131  }
132  Float_t ratio= (size[0]>0) ? size[1]/Float_t(size[0]): 0;
133  // printf("Sum :\t%f\t%f\t%f\t%s.%s\t\n", float(size[0]), float(size[1]),ratio, prefix,tree->GetName());
134 
135  AddToReport(prefix, tree->GetName(),size,ratio);
136  PrintSorted(zipSort);
137 }
138 
139 
140 void MakeStat(const char *prefix, TBranch * branch, Float_t *size, Float_t mratio){
143 
144  TObjArray * array = branch->GetListOfBranches();
145  Float_t bsizeSum[2]={0,0};
146 
147  if (!array || array->GetEntries()==0){
148  Float_t bsize[2] = {0,0};
149  bsize[0]=branch->GetTotalSize();
150  bsize[1]=branch->GetZipBytes();
151  if (bsize[1]>0){
152  Float_t ratio= (bsize[0]>0) ? bsize[1]/Float_t(bsize[0]): 0;
153  // printf("Term:\t%f\t%f\t%f\t%s.%s\t\n",float(bsize[0]), float(bsize[1]),ratio, prefix,branch->GetName());
154  AddToReport(prefix, branch->GetName(),bsize,ratio);
155  //branch->Print();
156  size[0]+=bsize[0];
157  size[1]+=bsize[1];
158  }else{
159  Float_t ratio= mratio;
160  //printf("Ter?:\t%f\t%f\t%f\t%s.%s\t\n",float(bsize[0]), float(-1),ratio, prefix,branch->GetName());
161  AddToReport(prefix, branch->GetName(),bsize,ratio);
162  //branch->Print();
163  size[0]+=bsize[0];
164  size[1]+=TMath::Nint(bsize[0]*mratio);
165  }
166 
167  return;
168  }
169  for (Int_t i=0; i<array->GetEntries(); i++){
170  Float_t bsize[2] = {0,0};
171  TString str=prefix;
172  str+= branch->GetName();
173  MakeStat(str.Data(),(TBranch*)array->At(i), bsize, mratio);
174  bsizeSum[0]+=bsize[0];
175  bsizeSum[1]+=bsize[1];
176  size[0]+=bsize[0];
177  size[1]+=bsize[1];
178  }
179  Float_t ratio= (size[0]>0) ? size[1]/Float_t(size[0]): 0;
180  //printf("Sum :\t%f\t%f\t%f\t%s.%s\t\n", float(bsizeSum[0]), float(bsizeSum[1]),ratio, prefix,branch->GetName());
181  AddToReport(prefix,branch->GetName(),bsizeSum,ratio);
182 }
printf("Chi2/npoints = %f\n", TMath::Sqrt(chi2/npoints))
TTree * fTree
Definition: MakeTreeStat.C:55
TArrayF totSize
Definition: MakeTreeStat.C:57
#define TObjArray
TArrayF zipRatio
Definition: MakeTreeStat.C:59
TObjArray aReport
Definition: MakeTreeStat.C:56
void AddToReport(const char *prefix, const char *name, Float_t size[2], Float_t ratio)
Definition: MakeTreeStat.C:95
TTree * tree
TObjArray * array
Definition: AnalyzeLaser.C:12
TArrayF zipSize
Definition: MakeTreeStat.C:58
char * prefix
void PrintSorted(Bool_t zipSort)
Definition: MakeTreeStat.C:65
void MakeStat(TTree *tree, Bool_t zipSort)
Definition: MakeTreeStat.C:120