Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion 12 Utilities/Mergers/src/MergerAlgorithm.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,17 @@ void merge(TObject* const target, TObject* const other)

if (target->InheritsFrom(TH1::Class())) {
// this includes TH1, TH2, TH3
errorCode = reinterpret_cast<TH1*>(target)->Merge(&otherCollection);
auto targetTH1 = reinterpret_cast<TH1*>(target);
if (targetTH1->TestBit(TH1::kIsAverage)) {
// Merge() does not support averages, we have to use Add()
// this will break if collection.size != 1
if (auto otherTH1 = dynamic_cast<TH1*>(otherCollection.First())) {
errorCode = targetTH1->Add(otherTH1);
}
} else {
// Add() does not support histograms with labels, thus we resort to Merge() by default
errorCode = targetTH1->Merge(&otherCollection);
}
} else if (target->InheritsFrom(THnBase::Class())) {
// this includes THn and THnSparse
errorCode = reinterpret_cast<THnBase*>(target)->Merge(&otherCollection);
Expand Down
14 changes: 14 additions & 0 deletions 14 Utilities/Mergers/test/test_Algorithm.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,17 @@ BOOST_AUTO_TEST_CASE(Deleting)
// I am afraid we can't check more than that.
BOOST_CHECK_NO_THROW(algorithm::deleteTCollections(main));
}

BOOST_AUTO_TEST_CASE(AverageHisto)
{
TH1F* target = new TH1F("histo 1", "histo 1", bins, min, max);
target->SetBit(TH1::kIsAverage);
target->Fill(5);

TH1F* other = new TH1F("histo 2", "histo 2", bins, min, max);
other->SetBit(TH1::kIsAverage);
other->Fill(5);

BOOST_CHECK_NO_THROW(algorithm::merge(target, other));
BOOST_CHECK_CLOSE(target->GetBinContent(other->FindBin(5)), 1.0, 0.001);
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.