Skip to content

Commit d3f1e31

Browse files
committed
Removed call to TH1::SetDefaultSumw2 in TnPEfficiencyClient
- This call was interfering with fits in other modules - Fixed memory leak - Avoid unnecessary extra cloning
1 parent e00eab5 commit d3f1e31

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

DQMOffline/MuonDPG/plugins/TnPEfficiencyClient.cc

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,7 @@ void TnPEfficiencyClient::dqmEndJob(DQMStore::IBooker& ibooker, DQMStore::IGette
6666
ibooker.setCurrentFolder(topFolder() + outFolder + "/");
6767
std::string baseFolder = topFolder() + outFolder + "/";
6868

69-
TH1::SetDefaultSumw2(kTRUE);
70-
7169
for (const auto& s : passNfailHistoNames) {
72-
TH1::SetDefaultSumw2(kTRUE);
73-
7470
std::string passHistoName = s.substr(0, s.find(':'));
7571
std::string failHistoName = s.substr(s.find(':') + 1, s.length());
7672

@@ -110,16 +106,20 @@ void TnPEfficiencyClient::dqmEndJob(DQMStore::IBooker& ibooker, DQMStore::IGette
110106
return;
111107
}
112108

113-
TH1F* h1_den = (TH1F*)h1_pass->Clone();
114-
TH1F* h1_num = (TH1F*)h1_pass->Clone();
115-
h1_den->Sumw2();
116-
h1_num->Sumw2();
109+
std::unique_ptr<TH1F> h1_den{(TH1F*)h1_pass->Clone()};
110+
std::unique_ptr<TH1F> h1_num{(TH1F*)h1_pass->Clone()};
111+
//If we call Sumw2 on a histogram which already has it set, we get an exception
112+
if (h1_den->GetSumw2N() == 0) {
113+
h1_den->Sumw2();
114+
}
115+
if (h1_num->GetSumw2N() == 0) {
116+
h1_num->Sumw2();
117+
}
117118
h1_den->Add(h1_fail);
118119

119-
h1_num->Divide(h1_den);
120-
TH1F* h1_ratio = (TH1F*)h1_num->Clone();
120+
h1_num->Divide(h1_den.get());
121121

122-
effHistos[effHistoName] = ibooker.book1D(effHistoName, h1_ratio);
122+
effHistos[effHistoName] = ibooker.book1D(effHistoName, h1_num.get());
123123
effHistos[effHistoName]->setTitle(effHistoName);
124124
effHistos[effHistoName]->setAxisTitle("Efficiency", 2);
125125
}
@@ -146,16 +146,19 @@ void TnPEfficiencyClient::dqmEndJob(DQMStore::IBooker& ibooker, DQMStore::IGette
146146
return;
147147
}
148148

149-
TH2F* h2_den = (TH2F*)h2_pass->Clone();
150-
TH2F* h2_num = (TH2F*)h2_pass->Clone();
151-
h2_den->Sumw2();
152-
h2_num->Sumw2();
149+
std::unique_ptr<TH2F> h2_den{(TH2F*)h2_pass->Clone()};
150+
std::unique_ptr<TH2F> h2_num{(TH2F*)h2_pass->Clone()};
151+
if (h2_den->GetSumw2N() == 0) {
152+
h2_den->Sumw2();
153+
}
154+
if (h2_num->GetSumw2N() == 0) {
155+
h2_num->Sumw2();
156+
}
153157
h2_den->Add(h2_fail);
154158

155-
h2_num->Divide(h2_den);
156-
TH2F* h2_ratio = (TH2F*)h2_num->Clone();
159+
h2_num->Divide(h2_den.get());
157160

158-
effHistos[effHistoName] = ibooker.book2D(effHistoName, h2_ratio);
161+
effHistos[effHistoName] = ibooker.book2D(effHistoName, h2_num.get());
159162
effHistos[effHistoName]->setTitle(effHistoName);
160163
effHistos[effHistoName]->setAxisTitle("Efficiency", 3);
161164
}

0 commit comments

Comments
 (0)