36 #include "TCollection.h"
40 #include "THnSparse.h"
45 template <class TemplateArray, typename TemplateType>
61 template <
class TemplateArray,
typename TemplateType>
63 AliTHnBase(name, title, nSelStep, nVarIn, nBinIn),
83 template <
class TemplateArray,
typename TemplateType>
88 fValues =
new TemplateArray*[fNSteps];
89 fSumw2 =
new TemplateArray*[fNSteps];
91 for (
Int_t i=0; i<fNSteps; i++)
98 template <
class TemplateArray,
typename TemplateType>
104 fValues(new TemplateArray*[c.fNSteps]),
105 fSumw2(new TemplateArray*[c.fNSteps]),
125 template <
class TemplateArray,
typename TemplateType>
135 delete[] fNbinsCache;
140 template <
class TemplateArray,
typename TemplateType>
145 for (
Int_t i=0; i<fNSteps; i++)
147 if (fValues && fValues[i])
153 if (fSumw2 && fSumw2[i])
162 template <
class TemplateArray,
typename TemplateType>
168 AliCFContainer::operator=(c);
172 for(
Int_t i=0; i< fNSteps; ++i) {
181 fValues=
new TemplateArray*[fNSteps];
182 fSumw2=
new TemplateArray*[fNSteps];
183 memset(fValues,0,fNSteps*
sizeof(TemplateArray*));
184 memset(fSumw2,0,fNSteps*
sizeof(TemplateArray*));
186 for (
Int_t i=0; i<fNSteps; i++) {
187 if (c.
fValues[i]) fValues[i] =
new TemplateArray(*(c.
fValues[i]));
188 if (c.
fSumw2[i]) fSumw2[i] =
new TemplateArray(*(c.
fSumw2[i]));
195 axisCache =
new TAxis*[fNVars];
202 template <
class TemplateArray,
typename TemplateType>
209 AliCFContainer::Copy(target);
217 for (
Int_t i=0; i<fNSteps; i++)
220 target.
fValues[i] =
new TemplateArray(*(fValues[i]));
225 target.
fSumw2[i] =
new TemplateArray(*(fSumw2[i]));
232 template <
class TemplateArray,
typename TemplateType>
247 TIterator* iter = list->MakeIterator();
251 while ((obj = iter->Next())) {
257 for (
Int_t i=0; i<fNSteps; i++)
262 fValues[i] =
new TemplateArray(fNBins);
265 fValues[i]->GetArray()[l] += entry->
fValues[i]->GetArray()[l];
271 fSumw2[i] =
new TemplateArray(fNBins);
274 fSumw2[i]->GetArray()[l] += entry->
fSumw2[i]->GetArray()[l];
284 template <
class TemplateArray,
typename TemplateType>
292 axisCache =
new TAxis*[fNVars];
293 fNbinsCache =
new Int_t[fNVars];
294 for (
Int_t i=0; i<fNVars; i++)
297 fNbinsCache[i] = axisCache[i]->GetNbins();
301 fLastBins =
new Int_t[fNVars];
304 for (
Int_t i=0; i<fNVars; i++)
306 fLastBins[i] = axisCache[i]->FindBin(var[i]);
307 fLastVars[i] = var[i];
313 for (
Int_t i=0; i<fNVars; i++)
315 bin *= fNbinsCache[i];
318 if (fLastVars[i] == var[i])
319 tmpBin = fLastBins[i];
322 tmpBin = axisCache[i]->FindBin(var[i]);
323 fLastBins[i] = tmpBin;
324 fLastVars[i] = var[i];
329 if (tmpBin < 1 || tmpBin > fNbinsCache[i])
339 fValues[istep] =
new TemplateArray(fNBins);
340 AliInfo(Form(
"Created values container for step %d", istep));
348 fSumw2[istep] =
new TemplateArray(*fValues[istep]);
349 AliInfo(Form(
"Created sumw2 container for step %d", istep));
353 fValues[istep]->GetArray()[bin] += weight;
355 fSumw2[istep]->GetArray()[bin] += weight * weight;
363 template <
class TemplateArray,
typename TemplateType>
371 for (
Int_t i=0; i<fNVars; i++)
373 bin *=
GetAxis(i, 0)->GetNbins();
374 bin += binIdx[i] - 1;
380 template <
class TemplateArray,
typename TemplateType>
385 for (
Int_t i=0; i<fNSteps; i++)
390 TemplateType* source = fValues[i]->GetArray();
392 TemplateType* sourceSumw2 = source;
394 sourceSumw2 = fSumw2[i]->GetArray();
396 THnSparse* target = cont->GetGrid(i)->GetGrid();
400 for (
Int_t j=0; j<fNVars; j++)
403 nBins[j] = target->GetAxis(j)->GetNbins();
413 Long64_t globalBin = GetGlobalBinIndex(binIdx);
416 if (source[globalBin] != 0)
418 target->SetBinContent(binIdx, source[globalBin]);
419 target->SetBinError(binIdx, TMath::Sqrt(sourceSumw2[globalBin]));
426 for (
Int_t j=fNVars-1; j>0; j--)
428 if (binIdx[j] > nBins[j])
435 if (binIdx[0] > nBins[0])
439 AliInfo(Form(
"Step %d: copied %lld entries out of %lld bins", i, count, GetGlobalBinIndex(binIdx)));
446 template <
class TemplateArray,
typename TemplateType>
454 template <
class TemplateArray,
typename TemplateType>
460 Int_t axis = fNVars-1;
462 for (
Int_t i=0; i<fNSteps; i++)
467 TemplateType* source = fValues[i]->GetArray();
468 TemplateType* sourceSumw2 = 0;
470 sourceSumw2 = fSumw2[i]->GetArray();
472 THnSparse* target = GetGrid(i)->GetGrid();
476 for (
Int_t j=0; j<fNVars; j++)
479 nBins[j] = target->GetAxis(j)->GetNbins();
487 TemplateType sumValues = 0;
488 TemplateType sumSumw2 = 0;
489 for (
Int_t j=1; j<=nBins[axis]; j++)
492 Long64_t globalBin = GetGlobalBinIndex(binIdx);
493 sumValues += source[globalBin];
494 source[globalBin] = 0;
498 sumSumw2 += sourceSumw2[globalBin];
499 sourceSumw2[globalBin] = 0;
504 Long64_t globalBin = GetGlobalBinIndex(binIdx);
505 source[globalBin] = sumValues;
507 sourceSumw2[globalBin] = sumSumw2;
514 for (
Int_t j=fNVars-2; j>0; j--)
516 if (binIdx[j] > nBins[j])
523 if (binIdx[0] > nBins[0])
527 AliInfo(Form(
"Step %d: reduced %lld bins to %lld entries", i, GetGlobalBinIndex(binIdx), count));
templateClassImp(AliTHnT) template< class TemplateArray
virtual void FillParent()
virtual Long64_t Merge(TCollection *list)
virtual void DeleteContainers()
TList * list
TDirectory file where lists per trigger are stored in train ouput.
TAxis * GetAxis(TDirectory *dir, const char *name, Bool_t verbose=true)
virtual void Copy(TObject &c) const
Long64_t GetGlobalBinIndex(const Int_t *binIdx)
virtual void FillContainer(AliCFContainer *cont)
virtual void Fill(const Double_t *var, Int_t istep, Double_t weight=1.)
AliTHnT & operator=(const AliTHnT &corr)
TH1 * Merge(const TH1 *cen, const TH1 *fwd, Double_t &xlow, Double_t &xhigh)
virtual void ReduceAxis()