@@ -216,15 +216,17 @@ class TH1 : public TNamed, public TAttLine, public TAttFill, public TAttMarker {
216
216
TH1* Slice (Args... args){
217
217
constexpr size_t ndim = sizeof ...(args) / 2 ;
218
218
if (ndim != fDimension ) {
219
- Error ( " TH1::Slice " , " Number of dimensions in slice does not match histogram dimension." );
219
+ throw std::invalid_argument ( " Number of dimensions in slice does not match histogram dimension." );
220
220
}
221
221
222
222
std::array<Int_t, sizeof ...(args)> binsArray{args...};
223
223
std::vector<Int_t> nBins (ndim);
224
224
std::vector<Double_t> binLowEdge (ndim), binUpEdge (ndim);
225
225
std::vector<Int_t> shiftedBins (ndim*2 );
226
-
227
- auto configureAxis = [&](size_t i, const auto &axis) {
226
+
227
+ // Configure all axes
228
+ for (size_t i = 0 ; i < ndim; ++i) {
229
+ const auto &axis = (i == 0 ) ? fXaxis : (i == 1 ) ? fYaxis : fZaxis ;
228
230
Int_t binLow = std::max (1 , binsArray[i * 2 ]);
229
231
Int_t binUp = std::min (axis.GetNbins () + 1 , binsArray[i * 2 + 1 ]);
230
232
binsArray[i * 2 ] = binLow;
@@ -234,37 +236,28 @@ class TH1 : public TNamed, public TAttLine, public TAttFill, public TAttMarker {
234
236
binUpEdge[i] = axis.GetBinLowEdge (binUp);
235
237
shiftedBins[i * 2 ] = 1 ;
236
238
shiftedBins[i * 2 + 1 ] = nBins[i] + 1 ;
237
- };
238
-
239
- // Configure all axes
240
- for (size_t i = 0 ; i < ndim; ++i) {
241
- const auto &axis = (i == 0 ) ? fXaxis : (i == 1 ) ? fYaxis : fZaxis ;
242
- configureAxis (i, axis);
243
239
}
244
240
245
241
// Create a new histogram of the same type as this
246
242
std::unique_ptr<TH1> hSlice (static_cast <TH1*>(IsA ()->GetNew ()(nullptr )));
247
243
248
244
if (!hSlice) {
249
- Error ( " TH1::Slice " , " Failed to create a new histogram instance." );
245
+ throw std::runtime_error ( " Failed to create a new histogram instance." );
250
246
}
251
247
252
248
// Configure name, title and bins
253
249
hSlice->SetNameTitle (Form (" %s_slice" , GetName ()), GetTitle ());
254
250
255
- auto configureBins = [&](auto &hist) {
256
- if constexpr (ndim == 1 ) {
257
- hist.SetBins (nBins[0 ], binLowEdge[0 ], binUpEdge[0 ]);
258
- } else if constexpr (ndim == 2 ) {
259
- hist.SetBins (nBins[0 ], binLowEdge[0 ], binUpEdge[0 ],
260
- nBins[1 ], binLowEdge[1 ], binUpEdge[1 ]);
261
- } else if constexpr (ndim == 3 ) {
262
- hist.SetBins (nBins[0 ], binLowEdge[0 ], binUpEdge[0 ],
263
- nBins[1 ], binLowEdge[1 ], binUpEdge[1 ],
264
- nBins[2 ], binLowEdge[2 ], binUpEdge[2 ]);
265
- }
266
- };
267
- configureBins (*hSlice);
251
+ if constexpr (ndim == 1 ) {
252
+ hSlice->SetBins (nBins[0 ], binLowEdge[0 ], binUpEdge[0 ]);
253
+ } else if constexpr (ndim == 2 ) {
254
+ hSlice->SetBins (nBins[0 ], binLowEdge[0 ], binUpEdge[0 ],
255
+ nBins[1 ], binLowEdge[1 ], binUpEdge[1 ]);
256
+ } else if constexpr (ndim == 3 ) {
257
+ hSlice->SetBins (nBins[0 ], binLowEdge[0 ], binUpEdge[0 ],
258
+ nBins[1 ], binLowEdge[1 ], binUpEdge[1 ],
259
+ nBins[2 ], binLowEdge[2 ], binUpEdge[2 ]);
260
+ }
268
261
269
262
std::vector<Double_t> sliceContents;
270
263
std::unordered_set<Int_t> processedBins;
@@ -317,7 +310,7 @@ class TH1 : public TNamed, public TAttLine, public TAttFill, public TAttMarker {
317
310
void SetSliceContent (const std::variant<std::vector<Double_t>, Double_t> &input, Args... args) {
318
311
constexpr auto ndim = sizeof ...(args) / 2 ;
319
312
if (ndim != fDimension ) {
320
- Error ( " TH1::SetSliceContent " , " Number of edges in the specified slice does not match histogram dimension." );
313
+ throw std::invalid_argument ( " Number of edges in the specified slice does not match histogram dimension." );
321
314
}
322
315
323
316
// Extract low/up edges in pairs
@@ -343,8 +336,7 @@ class TH1 : public TNamed, public TAttLine, public TAttFill, public TAttMarker {
343
336
}, input);
344
337
345
338
if (values.size () != sliceIndices.size ()) {
346
- Error (" TH1::SetSliceContent" , " Number of provided values does not match number of bins to set. " );
347
- return ;
339
+ throw std::invalid_argument (" Number of provided values does not match number of bins to set." );
348
340
}
349
341
350
342
unpack_caller<ndim> caller;
0 commit comments