23 HnSparse::HnSparse(
const char * name,
const char * title, Int_t dim,
const Int_t * nbins,
const Double_t * xmin,
24 const Double_t * xmax, Int_t chunksize)
25 : THnSparse(name, title, dim, nbins, xmin, xmax, chunksize)
32 Bool_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());
59 TObjArray * newAxis = (TObjArray *)s->GetListOfAxes()->Clone();
60 for (Int_t iDim = 0; iDim < newAxis->GetEntries(); iDim++) {
61 a = (TAxis *)newAxis->At(iDim);
64 if (std::find(r.begin(), r.end(), iDim) != r.end()) {
70 a->Set(1, a->GetXmin(), a->GetXmax());
74 Init(TString::Format(
"NDMSPC_%s", s->GetName()).Data(),
"", newAxis, kTRUE);
76 Int_t dims[fNdimensions];
77 Int_t c[fNdimensions];
78 for (Int_t iDim = 0; iDim < newAxis->GetEntries(); iDim++) {
85 fTree =
new TTree(
"ndh",
"Ndh tree");
86 fTree->Branch(
"h", &s);
91 for (Int_t iDim = 0; iDim < GetNdimensions(); iDim++) {
92 GetAxis(iDim)->SetRange();
95 fTree->GetUserInfo()->Add(Clone());
111 if (level >= (Int_t)r.size())
return true;
115 for (Int_t iBin = 1; iBin <= GetAxis(r[level])->GetNbins(); iBin++) {
117 coord[r[level]] = iBin;
118 s->GetAxis(r[level])->SetRange(iBin, iBin);
119 Bool_t finished =
RecursiveLoop(s, level + 1, coord, dims, r);
121 THnSparse * ss = (THnSparse *)s->ProjectionND(s->GetNdimensions(), dims,
"O");
123 ss->SetName(GetName());
126 if (ss->GetNbins() > 0) {
127 SetBinContent(coord, ss->GetNbins());
128 Printf(
"level=%d axis_id=%d iBin=%d binsFilled=%lld", level, r[level], iBin, ss->GetNbins());
129 fTree->SetBranchAddress(
"h", &ss);
133 Printf(
"[NotFilled] level=%d axis_id=%d iBin=%d binsFilled=%lld", level, r[level], iBin, ss->GetNbins());
138 Printf(
"level=%d axis_id=%d iBin=%d", level, r[level], iBin);
150 Printf(
"Reserving %e bins ...", (Double_t)nBins);
152 Printf(
"%e bins reserved.", (Double_t)nBins);
void ReserveBins(Long64_t nBins)
Bool_t Import(std::vector< Int_t > r, TString filename, TString objname, TString cacheDir=gSystem->HomeDirectory())
bool RecursiveLoop(THnSparse *s, Int_t level, Int_t *coord, Int_t *dims, std::vector< Int_t > &r)
TString fOutputFileName
Output filename.