Skip to content

Commit 13ac581

Browse files
authored
MCH: fix histogram reset at each cycle (#1357)
* [MCH] fixes to the histograms reset - added method to properly reset the numerator and denominator in the mergeable histogram ratios - added option "ICES" to the histogram reset to avoid removing the associated functions - added reset of orbit counters in digits task * [MCH] removed debugging output * [MCH] clang formatting * [MCH] added override keyword to Reset() functions Also bumped ClassDef version * [MCH] reverted ClassDef version bumps * [MCH] added protection for null internal histograms
1 parent 6d90d90 commit 13ac581

12 files changed

Lines changed: 84 additions & 31 deletions

Modules/MUON/Common/include/MUONCommon/MergeableTH1Ratio.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class MergeableTH1Ratio : public TH1F, public o2::mergers::MergeInterface
6060

6161
void update();
6262

63+
void Reset(Option_t* option = "") override;
64+
6365
private:
6466
TH1D* mHistoNum{ nullptr };
6567
TH1D* mHistoDen{ nullptr };

Modules/MUON/Common/include/MUONCommon/MergeableTH2Ratio.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ class MergeableTH2Ratio : public TH2F, public o2::mergers::MergeInterface
6262

6363
void beautify();
6464

65+
void Reset(Option_t* option = "") override;
66+
6567
private:
6668
TH2F* mHistoNum{ nullptr };
6769
TH2F* mHistoDen{ nullptr };

Modules/MUON/Common/src/MergeableTH1Ratio.cxx

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ MergeableTH1Ratio::MergeableTH1Ratio(MergeableTH1Ratio const& copymerge)
3232
mHistoDen = (TH1D*)copymerge.getDen()->Clone();
3333
TH1::AddDirectory(bStatus);
3434

35+
if (!mHistoNum || !mHistoDen) {
36+
return;
37+
}
38+
3539
mHistoNum->Sumw2();
3640
mHistoDen->Sumw2();
3741
}
@@ -47,6 +51,10 @@ MergeableTH1Ratio::MergeableTH1Ratio(const char* name, const char* title, int nb
4751
mHistoDen = new TH1D("den", "den", nbinsx, xmin, xmax);
4852
TH1::AddDirectory(bStatus);
4953

54+
if (!mHistoNum || !mHistoDen) {
55+
return;
56+
}
57+
5058
mHistoNum->Sumw2();
5159
mHistoDen->Sumw2();
5260

@@ -64,6 +72,10 @@ MergeableTH1Ratio::MergeableTH1Ratio(const char* name, const char* title, double
6472
mHistoDen = new TH1D("den", "den", 10, 0, 10);
6573
TH1::AddDirectory(bStatus);
6674

75+
if (!mHistoNum || !mHistoDen) {
76+
return;
77+
}
78+
6779
mHistoNum->Sumw2();
6880
mHistoDen->Sumw2();
6981

@@ -83,17 +95,25 @@ MergeableTH1Ratio::~MergeableTH1Ratio()
8395

8496
void MergeableTH1Ratio::merge(MergeInterface* const other)
8597
{
98+
if (!mHistoNum || !mHistoDen) {
99+
return;
100+
}
101+
86102
mHistoNum->Add(dynamic_cast<const MergeableTH1Ratio* const>(other)->getNum());
87103
mHistoDen->Add(dynamic_cast<const MergeableTH1Ratio* const>(other)->getDen());
88104
update();
89105
}
90106

91107
void MergeableTH1Ratio::update()
92108
{
109+
if (!mHistoNum || !mHistoDen) {
110+
return;
111+
}
112+
93113
const char* name = this->GetName();
94114
const char* title = this->GetTitle();
95115

96-
Reset();
116+
TH1F::Reset();
97117
GetXaxis()->Set(mHistoNum->GetXaxis()->GetNbins(), mHistoNum->GetXaxis()->GetXmin(), mHistoNum->GetXaxis()->GetXmax());
98118
SetBinsLength();
99119

@@ -115,4 +135,17 @@ void MergeableTH1Ratio::update()
115135
}
116136
}
117137

138+
void MergeableTH1Ratio::Reset(Option_t* option)
139+
{
140+
if (mHistoNum) {
141+
mHistoNum->Reset(option);
142+
}
143+
144+
if (mHistoDen) {
145+
mHistoDen->Reset(option);
146+
}
147+
148+
TH1F::Reset(option);
149+
}
150+
118151
} // namespace o2::quality_control_modules::muon

Modules/MUON/Common/src/MergeableTH2Ratio.cxx

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,25 +73,33 @@ MergeableTH2Ratio::~MergeableTH2Ratio()
7373

7474
void MergeableTH2Ratio::merge(MergeInterface* const other)
7575
{
76+
if (!mHistoNum || !mHistoDen) {
77+
return;
78+
}
79+
7680
mHistoNum->Add(dynamic_cast<const MergeableTH2Ratio* const>(other)->getNum());
7781
mHistoDen->Add(dynamic_cast<const MergeableTH2Ratio* const>(other)->getDen());
7882
update();
7983
}
8084

8185
void MergeableTH2Ratio::update()
8286
{
87+
if (!mHistoNum || !mHistoDen) {
88+
return;
89+
}
90+
8391
const char* name = this->GetName();
8492
const char* title = this->GetTitle();
8593

86-
Reset();
87-
beautify();
94+
TH2F::Reset();
8895

96+
SetNameTitle(name, title);
8997
GetXaxis()->Set(mHistoNum->GetXaxis()->GetNbins(), mHistoNum->GetXaxis()->GetXmin(), mHistoNum->GetXaxis()->GetXmax());
9098
GetYaxis()->Set(mHistoNum->GetYaxis()->GetNbins(), mHistoNum->GetYaxis()->GetXmin(), mHistoNum->GetYaxis()->GetXmax());
9199
SetBinsLength();
100+
beautify();
92101

93102
Divide(mHistoNum, mHistoDen);
94-
SetNameTitle(name, title);
95103

96104
if (mShowZeroBins) {
97105
// bins which have zero numerators are plotted in white when using the "col" and "colz" options, regardless of
@@ -113,7 +121,10 @@ void MergeableTH2Ratio::update()
113121

114122
void MergeableTH2Ratio::beautify()
115123
{
116-
SetOption("colz");
124+
if (!mHistoNum) {
125+
return;
126+
}
127+
117128
GetListOfFunctions()->RemoveAll();
118129

119130
TList* functions = (TList*)mHistoNum->GetListOfFunctions()->Clone();
@@ -123,4 +134,17 @@ void MergeableTH2Ratio::beautify()
123134
}
124135
}
125136

137+
void MergeableTH2Ratio::Reset(Option_t* option)
138+
{
139+
if (mHistoNum) {
140+
mHistoNum->Reset(option);
141+
}
142+
143+
if (mHistoDen) {
144+
mHistoDen->Reset(option);
145+
}
146+
147+
TH2F::Reset(option);
148+
}
149+
126150
} // namespace o2::quality_control_modules::muon

Modules/MUON/MCH/include/MCH/PhysicsTaskDigits.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class PhysicsTaskDigits /*final*/ : public TaskInterface // todo add back the "f
6767
void addDefaultOrbitsInTF();
6868
void plotDigit(const o2::mch::Digit& digit);
6969
void updateOrbits();
70+
void resetOrbits();
7071

7172
template <typename T>
7273
void publishObject(std::shared_ptr<T> histo, std::string drawOption, bool statBox, bool isExpert)

Modules/MUON/MCH/src/DecodingErrorsTask.cxx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,10 @@ void DecodingErrorsTask::endOfActivity(Activity& /*activity*/)
315315
void DecodingErrorsTask::reset()
316316
{
317317
// clean all the monitor objects here
318-
319318
ILOG(Info, Support) << "Resetting the histograms" << ENDM;
320319

321320
for (auto h : mAllHistograms) {
322-
h->Reset();
321+
h->Reset("ICES");
323322
}
324323
}
325324

Modules/MUON/MCH/src/PhysicsCheck.cxx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,6 @@ Quality PhysicsCheck::processFecOccupancy(MergeableTH2Ratio* hr, std::vector<dou
181181
// integrated occupancies
182182
if (deOccupancyDen[de] > 0) {
183183
deOccupancy[de] = deOccupancyNum[de] / deOccupancyDen[de];
184-
if (de == 10) {
185-
std::cout << fmt::format("xxxx occupancy: {} = {} / {}", deOccupancy[de], deOccupancyNum[de], deOccupancyDen[de]) << std::endl;
186-
}
187184
} else {
188185
deOccupancy[de] = 0;
189186
}
@@ -211,15 +208,11 @@ Quality PhysicsCheck::check(std::map<std::string, std::shared_ptr<MonitorObject>
211208
mHistogramOccupancyFecPrevCycle = std::make_shared<MergeableTH2Ratio>(*hr);
212209
mHistogramOccupancyFecPrevCycle->SetName("mHistogramOccupancyFecPrevCycle");
213210
mHistogramOccupancyFecPrevCycle->Reset();
214-
mHistogramOccupancyFecPrevCycle->getNum()->Reset();
215-
mHistogramOccupancyFecPrevCycle->getDen()->Reset();
216211
}
217212

218213
MergeableTH2Ratio hdiff(*hr);
219214
hdiff.SetName("mHistogramOccupancyFecOnCycle");
220215
hdiff.Reset();
221-
hdiff.getNum()->Reset();
222-
hdiff.getDen()->Reset();
223216

224217
hdiff.getNum()->Add(hr->getNum());
225218
hdiff.getNum()->Add(mHistogramOccupancyFecPrevCycle->getNum(), -1);
@@ -231,8 +224,6 @@ Quality PhysicsCheck::check(std::map<std::string, std::shared_ptr<MonitorObject>
231224

232225
// update previous cycle plot
233226
mHistogramOccupancyFecPrevCycle->Reset();
234-
mHistogramOccupancyFecPrevCycle->getNum()->Reset();
235-
mHistogramOccupancyFecPrevCycle->getDen()->Reset();
236227
mHistogramOccupancyFecPrevCycle->getNum()->Add(hr->getNum());
237228
mHistogramOccupancyFecPrevCycle->getDen()->Add(hr->getDen());
238229
}

Modules/MUON/MCH/src/PhysicsPreclustersCheck.cxx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ Quality PhysicsPreclustersCheck::check(std::map<std::string, std::shared_ptr<Mon
198198
// into the histogram bins in the beutify() method
199199
for (int i = 0; i < 2; i++) {
200200
for (size_t de = 0; de < dePseudoeffDen[i].size(); de++) {
201-
std::cout << fmt::format("xxxx DE{} num {} den {}", de, dePseudoeffNum[i][de], dePseudoeffDen[i][de]) << std::endl;
202201
if (dePseudoeffDen[i][de] > 0) {
203202
mDePseudoeff[i][de] = dePseudoeffNum[i][de] / dePseudoeffDen[i][de];
204203
} else {

Modules/MUON/MCH/src/PhysicsTaskDigits.cxx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,7 @@ void PhysicsTaskDigits::initialize(o2::framework::InitContext& /*ctx*/)
106106

107107
const uint32_t nElecXbins = PhysicsTaskDigits::sMaxFeeId * PhysicsTaskDigits::sMaxLinkId * PhysicsTaskDigits::sMaxDsId;
108108

109-
for (int fee = 0; fee < PhysicsTaskDigits::sMaxFeeId; fee++) {
110-
for (int link = 0; link < PhysicsTaskDigits::sMaxLinkId; link++) {
111-
mNOrbits[fee][link] = mLastOrbitSeen[fee][link] = 0;
112-
}
113-
}
109+
resetOrbits();
114110

115111
// Histograms in electronics coordinates
116112
mHistogramOccupancyElec = std::make_shared<MergeableTH2Ratio>("Occupancy_Elec", "Occupancy", nElecXbins, 0, nElecXbins, 64, 0, 64);
@@ -401,6 +397,15 @@ void PhysicsTaskDigits::updateOrbits()
401397
}
402398
}
403399

400+
void PhysicsTaskDigits::resetOrbits()
401+
{
402+
for (int fee = 0; fee < PhysicsTaskDigits::sMaxFeeId; fee++) {
403+
for (int link = 0; link < PhysicsTaskDigits::sMaxLinkId; link++) {
404+
mNOrbits[fee][link] = mLastOrbitSeen[fee][link] = 0;
405+
}
406+
}
407+
}
408+
404409
void PhysicsTaskDigits::endOfCycle()
405410
{
406411
// copy bin contents from src to dst
@@ -486,10 +491,12 @@ void PhysicsTaskDigits::endOfActivity(Activity& /*activity*/)
486491
void PhysicsTaskDigits::reset()
487492
{
488493
// clean all the monitor objects here
489-
ILOG(Info, Support) << "Reseting the histogram" << AliceO2::InfoLogger::InfoLogger::endm;
494+
ILOG(Info, Support) << "Resetting the histograms" << AliceO2::InfoLogger::InfoLogger::endm;
495+
496+
resetOrbits();
490497

491498
for (auto h : mAllHistograms) {
492-
h->Reset();
499+
h->Reset("ICES");
493500
}
494501
}
495502

Modules/MUON/MCH/src/PhysicsTaskPreclusters.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ void PhysicsTaskPreclusters::reset()
578578
ILOG(Info, Support) << "Reseting the histogram" << AliceO2::InfoLogger::InfoLogger::endm;
579579

580580
for (auto h : mAllHistograms) {
581-
h->Reset();
581+
h->Reset("ICES");
582582
}
583583
}
584584

0 commit comments

Comments
 (0)