Skip to content

Commit eaf1d69

Browse files
committed
StepTHn: speedup filling
Replaces 4 virtual calls to GetAt / SetAt / AddAt with just one to updateBin.
1 parent 531ea81 commit eaf1d69

2 files changed

Lines changed: 26 additions & 20 deletions

File tree

Framework/Core/include/Framework/StepTHn.h

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class StepTHn : public TNamed
5858
virtual Long64_t Merge(TCollection* list) = 0;
5959

6060
TAxis* GetAxis(int i) { return mPrototype->GetAxis(i); }
61-
void Sumw2(){}; // TODO: added for compatibiltiy with registry, but maybe it would be useful also in StepTHn as toggle for error weights
61+
void Sumw2() {}; // TODO: added for compatibiltiy with registry, but maybe it would be useful also in StepTHn as toggle for error weights
6262

6363
protected:
6464
void init();
@@ -67,6 +67,7 @@ class StepTHn : public TNamed
6767
void deleteContainers();
6868

6969
Long64_t getGlobalBinIndex(const Int_t* binIdx);
70+
virtual void updateBin(int iStep, Long64_t bin, double weight) = 0;
7071

7172
Long64_t mNBins; // number of total bins
7273
Int_t mNVars; // number of variables
@@ -107,6 +108,28 @@ class StepTHnT : public StepTHn
107108
}
108109
}
109110

111+
void updateBin(int iStep, Long64_t bin, double weight) override
112+
{
113+
if (!mValues[iStep]) {
114+
mValues[iStep] = createArray();
115+
LOGF(info, "Created values container for step %d", iStep);
116+
}
117+
118+
if (weight != 1.) {
119+
if (!mSumw2[iStep]) {
120+
mSumw2[iStep] = createArray(mValues[iStep]);
121+
LOGF(info, "Created sumw2 container for step %d", iStep);
122+
}
123+
}
124+
125+
auto* arr = static_cast<TemplateArray*>(mValues[iStep])->GetArray();
126+
arr[bin] += weight;
127+
if (mSumw2[iStep]) {
128+
auto* sw2 = static_cast<TemplateArray*>(mSumw2[iStep])->GetArray();
129+
sw2[bin] += weight * weight;
130+
}
131+
}
132+
110133
ClassDef(StepTHnT, 1) // THn like container
111134
};
112135

Framework/Core/src/StepTHn.cxx

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ void StepTHn::Fill(int iStep, int nParams, double positionAndWeight[])
424424
mLastBins[i] = tmpBin;
425425
mLastVars[i] = positionAndWeight[i];
426426
}
427-
//Printf("%d", tmpBin);
427+
// Printf("%d", tmpBin);
428428

429429
// under/overflow not supported
430430
if (tmpBin < 1 || tmpBin > mNbinsCache[i]) {
@@ -436,24 +436,7 @@ void StepTHn::Fill(int iStep, int nParams, double positionAndWeight[])
436436
// Printf("%lld", bin);
437437
}
438438

439-
if (!mValues[iStep]) {
440-
mValues[iStep] = createArray();
441-
LOGF(info, "Created values container for step %d", iStep);
442-
}
443-
444-
if (weight != 1.) {
445-
// initialize with already filled entries (which have been filled with weight == 1), in this case mSumw2 := mValues
446-
if (!mSumw2[iStep]) {
447-
mSumw2[iStep] = createArray(mValues[iStep]);
448-
LOGF(info, "Created sumw2 container for step %d", iStep);
449-
}
450-
}
451-
452-
// TODO probably slow; add StepTHnT::add ?
453-
mValues[iStep]->SetAt(mValues[iStep]->GetAt(bin) + weight, bin);
454-
if (mSumw2[iStep]) {
455-
mSumw2[iStep]->SetAt(mSumw2[iStep]->GetAt(bin) + weight * weight, bin);
456-
}
439+
updateBin(iStep, bin, weight);
457440
}
458441

459442
template class StepTHnT<TArrayF>;

0 commit comments

Comments
 (0)