|
3 | 3 | #include "DataFormats/Common/interface/Handle.h" |
4 | 4 | #include "FWCore/Framework/interface/Event.h" |
5 | 5 | #include "FWCore/ParameterSet/interface/ParameterSet.h" |
| 6 | +#include "FWCore/MessageLogger/interface/MessageLogger.h" |
6 | 7 | #include "FWCore/Utilities/interface/InputTag.h" |
7 | 8 |
|
8 | 9 | #include "DQMServices/Core/interface/DQMStore.h" |
@@ -125,43 +126,47 @@ void PFClient::createResolutionPlots(DQMStore::IBooker &ibooker, |
125 | 126 | float ymax = th->GetYaxis()->GetXmax(); |
126 | 127 | std::string xtit = th->GetXaxis()->GetTitle(); |
127 | 128 | std::string ytit = th->GetYaxis()->GetTitle(); |
128 | | - float *xbins = new float[nbinx + 1]; |
| 129 | + std::unique_ptr<float[]> xbins{new float[nbinx + 1]}; |
129 | 130 | for (size_t ix = 1; ix < nbinx + 1; ++ix) { |
130 | 131 | xbins[ix - 1] = th->GetXaxis()->GetBinLowEdge(ix); |
131 | 132 | if (ix == nbinx) |
132 | 133 | xbins[ix] = th->GetXaxis()->GetBinUpEdge(ix); |
133 | 134 | } |
134 | 135 | std::string tit_new = ";" + xtit + ";" + ytit; |
135 | 136 | ibooker.setCurrentFolder(folder); |
136 | | - MonitorElement *me_slice = ibooker.book1D("PFlowSlice", "PFlowSlice", nbiny, ymin, ymax); |
| 137 | + TH1F th_slice("PFlowSlice", "PFlowSlice", nbiny, ymin, ymax); |
137 | 138 |
|
138 | 139 | tit_new = ";" + xtit + ";Average_" + ytit; |
139 | | - me_average = ibooker.book1D("average_" + name, tit_new, nbinx, xbins); |
| 140 | + me_average = ibooker.book1D("average_" + name, tit_new, nbinx, xbins.get()); |
140 | 141 | me_average->setEfficiencyFlag(); |
141 | 142 | tit_new = ";" + xtit + ";RMS_" + ytit; |
142 | | - me_rms = ibooker.book1D("rms_" + name, tit_new, nbinx, xbins); |
| 143 | + me_rms = ibooker.book1D("rms_" + name, tit_new, nbinx, xbins.get()); |
143 | 144 | me_rms->setEfficiencyFlag(); |
144 | 145 | tit_new = ";" + xtit + ";Mean_" + ytit; |
145 | | - me_mean = ibooker.book1D("mean_" + name, tit_new, nbinx, xbins); |
| 146 | + me_mean = ibooker.book1D("mean_" + name, tit_new, nbinx, xbins.get()); |
146 | 147 | me_mean->setEfficiencyFlag(); |
147 | 148 | tit_new = ";" + xtit + ";Sigma_" + ytit; |
148 | | - me_sigma = ibooker.book1D("sigma_" + name, tit_new, nbinx, xbins); |
| 149 | + me_sigma = ibooker.book1D("sigma_" + name, tit_new, nbinx, xbins.get()); |
149 | 150 | me_sigma->setEfficiencyFlag(); |
150 | 151 |
|
151 | 152 | double average, rms, mean, sigma; |
152 | 153 |
|
153 | 154 | for (size_t ix = 1; ix < nbinx + 1; ++ix) { |
154 | | - me_slice->Reset(); |
| 155 | + th_slice.Reset(); |
| 156 | + unsigned int nNonZeroBins = 0; |
155 | 157 | for (size_t iy = 1; iy < nbiny + 1; ++iy) { |
156 | | - me_slice->setBinContent(iy, th->GetBinContent(ix, iy)); |
| 158 | + auto value = th->GetBinContent(ix, iy); |
| 159 | + th_slice.SetBinContent(iy, value); |
| 160 | + if (value != 0) { |
| 161 | + ++nNonZeroBins; |
| 162 | + } |
157 | 163 | } |
158 | | - getHistogramParameters(me_slice, average, rms, mean, sigma); |
| 164 | + getHistogramParameters(th_slice, nNonZeroBins, average, rms, mean, sigma); |
159 | 165 | me_average->setBinContent(ix, average); |
160 | 166 | me_rms->setBinContent(ix, rms); |
161 | 167 | me_mean->setBinContent(ix, mean); |
162 | 168 | me_sigma->setBinContent(ix, sigma); |
163 | 169 | } |
164 | | - delete[] xbins; |
165 | 170 | } |
166 | 171 | } |
167 | 172 |
|
@@ -257,7 +262,7 @@ void PFClient::createProfilePlots(DQMStore::IBooker &ibooker, |
257 | 262 | // size_t nbiny = me->getNbinsY(); |
258 | 263 | // TProfile* profileX = th->ProfileX("",0,nbiny+1); add underflow and |
259 | 264 | // overflow |
260 | | - static const Int_t NUM_STAT = 7; |
| 265 | + static constexpr Int_t NUM_STAT = 7; |
261 | 266 | Double_t stats[NUM_STAT] = {0}; |
262 | 267 | th->GetStats(stats); |
263 | 268 |
|
@@ -285,24 +290,24 @@ void PFClient::createProfilePlots(DQMStore::IBooker &ibooker, |
285 | 290 | // -- Get Histogram Parameters |
286 | 291 | // |
287 | 292 | void PFClient::getHistogramParameters( |
288 | | - MonitorElement *me_slice, double &average, double &rms, double &mean, double &sigma) { |
| 293 | + TH1F &th_slice, unsigned int nNonZeroBins, double &average, double &rms, double &mean, double &sigma) { |
289 | 294 | average = 0.0; |
290 | 295 | rms = 0.0; |
291 | 296 | mean = 0.0; |
292 | 297 | sigma = 0.0; |
293 | 298 |
|
294 | | - if (!me_slice) |
295 | | - return; |
296 | | - if (me_slice->kind() == MonitorElement::Kind::TH1F) { |
297 | | - average = me_slice->getMean(); |
298 | | - rms = me_slice->getRMS(); |
299 | | - TH1F *th_slice = me_slice->getTH1F(); |
300 | | - if (th_slice && th_slice->GetEntries() > 0) { |
301 | | - // need our own copy for thread safety |
302 | | - TF1 gaus("mygaus", "gaus"); |
303 | | - th_slice->Fit(&gaus, "Q0 SERIAL"); |
| 299 | + average = th_slice.GetMean(); |
| 300 | + rms = th_slice.GetRMS(); |
| 301 | + //Need a minimum of 3 points to fit a gaussian |
| 302 | + if (nNonZeroBins > 2) { |
| 303 | + // need our own copy for thread safety |
| 304 | + TF1 gaus("mygaus", "gaus", 0, 1, TF1::EAddToList::kNo); |
| 305 | + auto fit = th_slice.Fit(&gaus, "Q0 SERIAL"); |
| 306 | + if (int(fit) == 0) { |
304 | 307 | sigma = gaus.GetParameter(2); |
305 | 308 | mean = gaus.GetParameter(1); |
| 309 | + } else { |
| 310 | + edm::LogWarning("FitFailed") << "Failed to fit gaussian"; |
306 | 311 | } |
307 | 312 | } |
308 | 313 | } |
|
0 commit comments