@@ -216,15 +216,17 @@ class TH1 : public TNamed, public TAttLine, public TAttFill, public TAttMarker {
216216 TH1* Slice (Args... args){
217217 constexpr size_t ndim = sizeof ...(args) / 2 ;
218218 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." );
220220 }
221221
222222 std::array<Int_t, sizeof ...(args)> binsArray{args...};
223223 std::vector<Int_t> nBins (ndim);
224224 std::vector<Double_t> binLowEdge (ndim), binUpEdge (ndim);
225225 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 ;
228230 Int_t binLow = std::max (1 , binsArray[i * 2 ]);
229231 Int_t binUp = std::min (axis.GetNbins () + 1 , binsArray[i * 2 + 1 ]);
230232 binsArray[i * 2 ] = binLow;
@@ -234,37 +236,28 @@ class TH1 : public TNamed, public TAttLine, public TAttFill, public TAttMarker {
234236 binUpEdge[i] = axis.GetBinLowEdge (binUp);
235237 shiftedBins[i * 2 ] = 1 ;
236238 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);
243239 }
244240
245241 // Create a new histogram of the same type as this
246242 std::unique_ptr<TH1> hSlice (static_cast <TH1*>(IsA ()->GetNew ()(nullptr )));
247243
248244 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." );
250246 }
251247
252248 // Configure name, title and bins
253249 hSlice->SetNameTitle (Form (" %s_slice" , GetName ()), GetTitle ());
254250
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+ }
268261
269262 std::vector<Double_t> sliceContents;
270263 std::unordered_set<Int_t> processedBins;
@@ -317,7 +310,7 @@ class TH1 : public TNamed, public TAttLine, public TAttFill, public TAttMarker {
317310 void SetSliceContent (const std::variant<std::vector<Double_t>, Double_t> &input, Args... args) {
318311 constexpr auto ndim = sizeof ...(args) / 2 ;
319312 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." );
321314 }
322315
323316 // Extract low/up edges in pairs
@@ -343,8 +336,7 @@ class TH1 : public TNamed, public TAttLine, public TAttFill, public TAttMarker {
343336 }, input);
344337
345338 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." );
348340 }
349341
350342 unpack_caller<ndim> caller;
0 commit comments