32Bool_t
HnSparse::Import(std::vector<Int_t> r, TString filename, TString objname, TString cacheDir)
38 if (!cacheDir.IsNull()) TFile::SetCacheFileDir(cacheDir.Data(), 1, 1);
40 if (filename.IsNull()) {
41 Printf(
"Error: filename is empty !!!");
44 if (objname.IsNull()) {
45 Printf(
"Error: objname is empty !!!");
49 Printf(
"Opening file='%s' obj='%s' ...", filename.Data(), objname.Data());
50 TFile * f = TFile::Open(filename.Data());
51 if (f ==
nullptr)
return kFALSE;
53 THnSparse * s = (THnSparse *)f->Get(objname.Data());
57 TObjArray * newAxis = (TObjArray *)s->GetListOfAxes()->Clone();
58 for (Int_t iDim = 0; iDim < newAxis->GetEntries(); iDim++) {
59 TAxis * a = (TAxis *)newAxis->At(iDim);
62 if (std::find(r.begin(), r.end(), iDim) != r.end()) {
68 a->Set(1, a->GetXmin(), a->GetXmax());
72 Init(TString::Format(
"ndh_%s", s->GetName()).Data(),
"", newAxis, kTRUE);
74 Int_t dims[fNdimensions];
75 Int_t c[fNdimensions];
76 for (Int_t iDim = 0; iDim < newAxis->GetEntries(); iDim++) {
77 TAxis * a = s->GetAxis(iDim);
83 fTree =
new TTree(
"ndh",
"NDH tree");
84 fTree->Branch(
"h", &s);
89 for (Int_t iDim = 0; iDim < GetNdimensions(); iDim++) {
90 GetAxis(iDim)->SetRange();
93 fTree->GetUserInfo()->Add(Clone());
109 if (level >= r.size())
return true;
113 for (Int_t iBin = 1; iBin <= GetAxis(r[level])->GetNbins(); iBin++) {
115 coord[r[level]] = iBin;
116 s->GetAxis(r[level])->SetRange(iBin, iBin);
117 Bool_t finished =
RecursiveLoop(s, level + 1, coord, dims, r);
119 THnSparse * ss = (THnSparse *)s->ProjectionND(s->GetNdimensions(), dims,
"O");
121 ss->SetName(GetName());
124 if (ss->GetNbins() > 0) {
125 SetBinContent(coord, ss->GetNbins());
126 Printf(
"level=%d axis_id=%d iBin=%d binsFilled=%d", level, r[level], iBin, ss->GetNbins());
127 fTree->SetBranchAddress(
"h", &ss);
131 Printf(
"[NotFilled] level=%d axis_id=%d iBin=%d binsFilled=%d", level, r[level], iBin, ss->GetNbins());
136 Printf(
"level=%d axis_id=%d iBin=%d", level, r[level], iBin);