@@ -1336,77 +1336,89 @@ void TAxis::UnZoom()
1336
1336
1337
1337
void TAxis::AutoZoom ()
1338
1338
{
1339
- if (!gPad ) {
1340
- Warning (" TAxis::AutoZoom" ," Cannot AutoZoom if gPad does not exist. Did you mean to draw the TAxis first?" );
1341
- return ;
1342
- }
1343
- gPad ->SetView ();
1344
1339
if (!GetParent ()) {
1345
1340
Warning (" TAxis::AutoZoom" ," Cannot AutoZoom if parent does not exist. Did you mean to draw the TAxis first?" );
1346
1341
return ;
1347
1342
}
1348
1343
auto dim = strstr (GetName (), " xaxis" ) ? 0 : strstr (GetName (), " yaxis" ) ? 1 : strstr (GetName (), " zaxis" ) ? 2 : -1 ;
1349
1344
TH1 *hobj1 = static_cast <TH1 *>(GetParent ());
1350
1345
Int_t first = -1 , last = -1 ;
1351
- if (hobj1 && !strstr (hobj1->GetName (), " hframe" )) {
1352
- auto ndims = hobj1->GetDimension ();
1353
- // Sanity checks
1354
- if (dim == 0 ) {
1355
- if (ndims != 1 && ndims != 2 && ndims != 3 ) {
1356
- Warning (" TAxis::AutoZoom" ," Cannot AutoZoom xaxis if TH has %d dimension(s)" , ndims);
1357
- return ;
1358
- }
1359
- } else if (dim == 1 ) {
1360
- if (ndims == 1 ) {
1361
- UnZoom (); // For a TH1, it acts as an AutoZoom of the yaxis (bin content axis)
1362
- return ;
1363
- }
1364
- if (ndims != 2 && ndims != 3 ) {
1365
- Warning (" TAxis::AutoZoom" ," Cannot AutoZoom yaxis if TH has %d dimension(s)" , ndims);
1366
- return ;
1367
- }
1368
- } else if (dim == 2 ) {
1369
- if (ndims == 2 ) {
1370
- UnZoom (); // For a TH2, it acts as an AutoZoom of the zaxis (bin content axis)
1371
- return ;
1372
- }
1373
- if (ndims != 3 ) {
1374
- Warning (" TAxis::AutoZoom" ," Cannot AutoZoom zaxis if TH has %d dimension(s)" , ndims);
1375
- return ;
1376
- }
1346
+
1347
+ auto ndims = hobj1->GetDimension ();
1348
+ // Sanity checks
1349
+ if (dim == 0 ) {
1350
+ if (ndims != 1 && ndims != 2 && ndims != 3 ) {
1351
+ Warning (" TAxis::AutoZoom" ," Cannot AutoZoom xaxis if TH has %d dimension(s)" , ndims);
1352
+ return ;
1353
+ }
1354
+ } else if (dim == 1 ) {
1355
+ if (ndims == 1 ) {
1356
+ UnZoom (); // For a TH1, it acts as an AutoZoom of the yaxis (bin content axis)
1357
+ return ;
1358
+ }
1359
+ if (ndims != 2 && ndims != 3 ) {
1360
+ Warning (" TAxis::AutoZoom" ," Cannot AutoZoom yaxis if TH has %d dimension(s)" , ndims);
1361
+ return ;
1362
+ }
1363
+ } else if (dim == 2 ) {
1364
+ if (ndims == 2 ) {
1365
+ UnZoom (); // For a TH2, it acts as an AutoZoom of the zaxis (bin content axis)
1366
+ return ;
1367
+ }
1368
+ if (ndims != 3 ) {
1369
+ Warning (" TAxis::AutoZoom" ," Cannot AutoZoom zaxis if TH has %d dimension(s)" , ndims);
1370
+ return ;
1377
1371
}
1372
+ }
1373
+
1374
+ hobj1->GetRangeOfFilledWeights (dim, first, last, false );
1375
+ SetRange (first, last);
1376
+
1377
+ if (gPad )
1378
+ gPad ->AutoZoomed ();
1379
+ }
1378
1380
1379
- hobj1->GetRangeOfFilledWeights (dim, first, last, false );
1380
- SetRange (first, last);
1381
+ // //////////////////////////////////////////////////////////////////////////////
1382
+ // / Automatically zoom the current axis to the range of all histograms overlaid
1383
+ // / in this pad and detect shared range filled with non-zero contents (weights or errors)
1384
+ // / \note For the bin content axis (yaxis) of a TH1 or (zaxis) of a TH2,
1385
+ // / UnZoom is called instead. TH3, the PaletteAxis does not implement AutoZoom nor UnZoom
1386
+
1387
+ void TAxis::AutoZoomAll ()
1388
+ {
1389
+ if (!gPad ) {
1390
+ Warning (" TAxis::AutoZoom" ," Cannot AutoZoom if gPad does not exist. Did you mean to draw the TAxis first?" );
1391
+ return ;
1381
1392
}
1382
- if (first == -1 && last == -1 ) { // This only happens if parent histogram was missing, or if it was called "hframe"
1383
- // Must autozoom all histograms in the pad
1384
- Double_t globalMin = DBL_MAX;
1385
- Double_t globalMax = DBL_MIN;
1386
- TIter next (gPad ->GetListOfPrimitives ());
1387
- while (TObject *obj= next ()) {
1388
- if (!obj || !obj->InheritsFrom (TH1::Class ()))
1389
- continue ;
1390
- TH1 *hobj = static_cast <TH1*>(obj);
1391
- if (!obj || !obj->InheritsFrom (TH1::Class ()))
1392
- continue ;
1393
- if (!strstr (hobj->GetName (), " hframe" )) {
1394
- hobj->GetRangeOfFilledWeights (dim, first, last, false );
1395
- TAxis *ax = (dim == 0 ) ? hobj->GetXaxis () : (dim == 1 ) ? hobj->GetYaxis () : (dim == 2 ) ? hobj->GetZaxis () : nullptr ;
1396
- if (ax) {
1397
- globalMin = std::min (globalMin, ax->GetBinLowEdge (first));
1398
- globalMax = std::max (globalMax, ax->GetBinUpEdge (last));
1399
- }
1400
- }
1393
+ gPad ->SetView ();
1394
+ auto dim = strstr (GetName (), " xaxis" ) ? 0 : strstr (GetName (), " yaxis" ) ? 1 : strstr (GetName (), " zaxis" ) ? 2 : -1 ;
1395
+ Int_t first = -1 , last = -1 ;
1396
+
1397
+ Double_t globalMin = DBL_MAX;
1398
+ Double_t globalMax = DBL_MIN;
1399
+ TIter next (gPad ->GetListOfPrimitives ());
1400
+ while (TObject *obj= next ()) {
1401
+ if (!obj || !obj->InheritsFrom (TH1::Class ()))
1402
+ continue ;
1403
+ TH1 *hobj = static_cast <TH1*>(obj);
1404
+ if (dim > hobj->GetDimension ())
1405
+ continue ;
1406
+ hobj->GetRangeOfFilledWeights (dim, first, last, false );
1407
+ TAxis *ax = (dim == 0 ) ? hobj->GetXaxis () : (dim == 1 ) ? hobj->GetYaxis () : (dim == 2 ) ? hobj->GetZaxis () : nullptr ;
1408
+ if (ax) {
1409
+ globalMin = std::min (globalMin, ax->GetBinLowEdge (first));
1410
+ globalMax = std::max (globalMax, ax->GetBinUpEdge (last));
1401
1411
}
1402
- while (TObject *obj = next ()) {
1403
- if (!obj || !obj->InheritsFrom (TH1::Class ()))
1404
- continue ;
1405
- TH1 *hobj = static_cast <TH1 *>(obj);
1406
- TAxis *ax = (dim == 0 ) ? hobj->GetXaxis () : (dim == 1 ) ? hobj->GetYaxis () : (dim == 2 ) ? hobj->GetZaxis () : nullptr ;
1407
- if (ax) {
1408
- ax->SetRangeUser (globalMin, globalMax);
1409
- }
1412
+ }
1413
+ while (TObject *obj = next ()) {
1414
+ if (!obj || !obj->InheritsFrom (TH1::Class ()))
1415
+ continue ;
1416
+ TH1 *hobj = static_cast <TH1 *>(obj);
1417
+ if (dim > hobj->GetDimension ())
1418
+ continue ;
1419
+ TAxis *ax = (dim == 0 ) ? hobj->GetXaxis () : (dim == 1 ) ? hobj->GetYaxis () : (dim == 2 ) ? hobj->GetZaxis () : nullptr ;
1420
+ if (ax) {
1421
+ ax->SetRangeUser (globalMin, globalMax);
1410
1422
}
1411
1423
}
1412
1424
0 commit comments