1 #include "writeTextFile.h"
3 const char* inrootfile=
"HIST/finish_central_cut1.hist.root";
4 const char* outdir=
"REAL";
6 int main(
int argc,
char** argv)
8 char* argvZ[] = {
"-b"};
10 TApplication r00t(
"r00t", &argcZ, argvZ);
13 const char* options =
"i:o:m:";
15 char inRootFile[300],outDir[300];
17 while ((chr = getopt(argc, argv, options)) >= 0){
19 case 'i': strcpy(inRootFile,optarg); i=1;
break;
20 case 'o': strcpy(outDir,optarg); o=1;
break;
21 case 'm': match=optarg;
break;
25 cout <<
"-i infile -o outdir [-m <match>]" << endl;
30 cout <<
"in root=" << inRootFile << endl
31 <<
"out dir=" << outDir << endl;
32 if(match!=
"") cout <<
"match=" << match << endl;
35 TFile inRoot(inRootFile);
37 cout <<
"Cannot open " << inRootFile << endl;
40 TIterator* iterator = inRoot.GetListOfKeys()->MakeIterator();
43 TString outText = inRootFile;
44 outText.Replace(0,outText.Last(
'/')+1,
"");
45 outText.ReplaceAll(
".root",
".txt");
46 outText.Prepend(
"/"); outText.Prepend(outDir);
48 cout <<
"out txt file=" << outText.Data() << endl;
50 ofstream os(outText.Data());
51 if(!os){cout <<
"huh?" << endl;
return -1; }
54 int count(0),nLimit(99999999);
55 while( (key=dynamic_cast<TKey*>(iterator->Next())) != 0){
57 TObject* t = inRoot.Get(key->GetName());
59 if(!(t->IsA()->InheritsFrom(
"TH1")))
continue;
63 TString name=h->GetName();
64 if(match!=
"" && !strstr(name,match.Data()))
continue;
66 if(++count>nLimit)
break;
68 if(h->GetXaxis()->GetXbins()->GetSize())
continue;
70 os <<
"name: " << h->GetName() << endl
71 <<
"title: " << h->GetTitle() << endl
72 <<
"dim: " << h->GetDimension() << endl
73 <<
"ary: " << (h->GetXaxis()->GetXbins()->GetSize()!=0) << endl;
74 for(
int iDim=1; iDim<=h->GetDimension(); iDim++){
77 case 1: axis = h->GetXaxis();
break;
78 case 2: axis = h->GetYaxis();
break;
79 case 3: axis = h->GetZaxis();
break;
80 default: cout <<
"wrong dimension" << endl;exit(0);
83 int nBin = axis->GetNbins();
85 os <<
"bins: " << nBin << endl;
88 if(axis->GetXbins()->GetSize()){
90 for(
int i=0; i<ary->GetSize();i++){
91 os << ary->At(i) <<
" ";
96 os <<
"min: " << axis->GetBinLowEdge(1) << endl
97 <<
"max: " << axis->GetBinUpEdge(nBin) << endl;
101 for(
int ix=0; ix<h->GetNbinsX()+2; ix++){
102 for(
int iy=0; iy<h->GetNbinsY()+2; iy++){
103 for(
int iz=0; iz<h->GetNbinsZ()+2; iz++){
105 int bin = h->GetBin(ix,iy,iz);
106 os <<
"bin=" << bin <<
" " << h->GetBinContent(bin) <<
" "
107 << h->GetBinError(bin) << endl;
114 cout <<
"done" << endl;