NAGASH 0.9.8
Next Generation Analysis System
Loading...
Searching...
No Matches
ROOTToNAGASH.cxx
Go to the documentation of this file.
1#include "NAGASH/NAGASH.h"
2#include "NAGASH/NGCount.h"
3#include "NAGASH/NNGHist.h"
4#include "NAGASH/NAGASHFile.h"
5
6using namespace NAGASH;
7
8bool isFixedBinSize(TAxis *axis)
9{
10 return axis->GetXbins()->GetSize() == 0 ? true : false;
11}
12
13int main(int argc, char **argv)
14{
15 if (argc != 3)
16 {
17 std::cout << "Usage: " << argv[0] << " (input ROOT file) (output NAGASH file)" << std::endl;
18 return 0;
19 }
20
21 TFile *f = new TFile(argv[1], "READ");
22 if (f->IsZombie())
23 {
24 std::cout << "Input Root file is broken!" << std::endl;
25 return 0;
26 }
27
28 TIter next(f->GetListOfKeys());
29 TKey *key;
30 int nhist = 0;
31
32 NAGASHFile outfile(std::make_shared<MSGTool>(), argv[2], NAGASHFile::Mode::WRITE);
33
34 while ((key = (TKey *)next()))
35 {
36 nhist++;
37 if (TString(key->GetClassName()) == TString("TH1D"))
38 {
39 TH1D *h = (TH1D *)(key->ReadObj());
40 if (isFixedBinSize(h->GetXaxis()))
41 {
42 NNGHist<Axis::Regular> nnghist(h);
43 outfile.SaveHist(h->GetName(), nnghist);
44 }
45 else
46 {
47 NNGHist<Axis::Variable> nnghist(h);
48 outfile.SaveHist(h->GetName(), nnghist);
49 }
50 }
51
52 if (TString(key->GetClassName()) == TString("TH2D"))
53 {
54 TH2D *h = (TH2D *)(key->ReadObj());
55 if (isFixedBinSize(h->GetXaxis()) && isFixedBinSize(h->GetYaxis()))
56 {
57 NNGHist<Axis::Regular, Axis::Regular> nnghist(h);
58 outfile.SaveHist(h->GetName(), nnghist);
59 }
60 else if (isFixedBinSize(h->GetXaxis()) && !isFixedBinSize(h->GetYaxis()))
61 {
62 NNGHist<Axis::Regular, Axis::Variable> nnghist(h);
63 outfile.SaveHist(h->GetName(), nnghist);
64 }
65 else if (!isFixedBinSize(h->GetXaxis()) && isFixedBinSize(h->GetYaxis()))
66 {
67 NNGHist<Axis::Variable, Axis::Regular> nnghist(h);
68 outfile.SaveHist(h->GetName(), nnghist);
69 }
70 else
71 {
72 NNGHist<Axis::Variable, Axis::Variable> nnghist(h);
73 outfile.SaveHist(h->GetName(), nnghist);
74 }
75 }
76
77 if (TString(key->GetClassName()) == TString("TH3D"))
78 {
79 TH3D *h = (TH3D *)(key->ReadObj());
80 if (isFixedBinSize(h->GetXaxis()))
81 {
82 NNGHist<Axis::Regular, Axis::Regular, Axis::Regular> nnghist(h);
83 outfile.SaveHist(h->GetName(), nnghist);
84 }
85 else
86 {
87 NNGHist<Axis::Variable, Axis::Variable, Axis::Variable> nnghist(h);
88 outfile.SaveHist(h->GetName(), nnghist);
89 }
90 }
91
92 // if (nhist % 100 == 0)
93 // std::cout << nhist << std::endl;
94 }
95
96 outfile.Close();
97
98 return 0;
99}
int main(int argc, char **argv)
bool isFixedBinSize(TAxis *axis)