@@ -1336,21 +1336,24 @@ void TGraphPainter::PaintGraph(TGraph *theGraph, Int_t npoints, const Double_t *
13361336
13371337 // Draw the Axis.
13381338 Double_t rwxmin,rwxmax, rwymin, rwymax, maximum, minimum, dx, dy;
1339+
1340+ TH1F *histogram = nullptr ;
13391341 if (optionAxis) {
1340- if (theGraph->GetHistogram ()) {
1342+ histogram = theGraph->GetHistogram ();
1343+ if (histogram) {
13411344 rwxmin = gPad ->GetUxmin ();
13421345 rwxmax = gPad ->GetUxmax ();
13431346 rwymin = gPad ->GetUymin ();
13441347 rwymax = gPad ->GetUymax ();
1345- minimum = theGraph-> GetHistogram () ->GetMinimumStored ();
1346- maximum = theGraph-> GetHistogram () ->GetMaximumStored ();
1348+ minimum = histogram ->GetMinimumStored ();
1349+ maximum = histogram ->GetMaximumStored ();
13471350 if (minimum == -1111 ) { // this can happen after unzooming
1348- minimum = theGraph-> GetHistogram () ->GetYaxis ()->GetXmin ();
1349- theGraph-> GetHistogram () ->SetMinimum (minimum);
1351+ minimum = histogram ->GetYaxis ()->GetXmin ();
1352+ histogram ->SetMinimum (minimum);
13501353 }
13511354 if (maximum == -1111 ) {
1352- maximum = theGraph-> GetHistogram () ->GetYaxis ()->GetXmax ();
1353- theGraph-> GetHistogram () ->SetMaximum (maximum);
1355+ maximum = histogram ->GetYaxis ()->GetXmax ();
1356+ histogram ->SetMaximum (maximum);
13541357 }
13551358 uxmin = gPad ->PadtoX (rwxmin);
13561359 uxmax = gPad ->PadtoX (rwxmax);
@@ -1367,9 +1370,12 @@ void TGraphPainter::PaintGraph(TGraph *theGraph, Int_t npoints, const Double_t *
13671370 minimum = rwymin - dy;
13681371 maximum = rwymax + dy;
13691372 }
1370- if (theGraph->GetMinimum () != -1111 ) rwymin = minimum = theGraph->GetMinimum ();
1371- if (theGraph->GetMaximum () != -1111 ) rwymax = maximum = theGraph->GetMaximum ();
1372- if (uxmin < 0 && rwxmin >= 0 ) uxmin = 0.9 *rwxmin;
1373+ if (theGraph->GetMinimum () != -1111 )
1374+ rwymin = minimum = theGraph->GetMinimum ();
1375+ if (theGraph->GetMaximum () != -1111 )
1376+ rwymax = maximum = theGraph->GetMaximum ();
1377+ if (uxmin < 0 && rwxmin >= 0 )
1378+ uxmin = 0.9 *rwxmin;
13731379 if (uxmax > 0 && rwxmax <= 0 ) {
13741380 if (gPad ->GetLogx ()) uxmax = 1.1 *rwxmax;
13751381 else uxmax = 0 ;
@@ -1393,31 +1399,32 @@ void TGraphPainter::PaintGraph(TGraph *theGraph, Int_t npoints, const Double_t *
13931399 if (strstr (chopt," x+" )) strncat (chopth, " x+" ,3 );
13941400 if (strstr (chopt," y+" )) strncat (chopth, " y+" ,3 );
13951401 if (optionIAxis) strncat (chopth, " A" ,2 );
1396- if (!theGraph-> GetHistogram () ) {
1402+ if (!histogram ) {
13971403 // the graph is created with at least as many bins as there are
13981404 // points to permit zooming on the full range.
13991405 rwxmin = uxmin;
14001406 rwxmax = uxmax;
14011407 npt = 100 ;
14021408 if (theNpoints > npt) npt = theNpoints;
1403- TH1F *h = new TH1F (TString::Format (" %s_h" ,GetName ()),GetTitle (),npt,rwxmin,rwxmax);
1404- theGraph->SetHistogram (h);
1405- if (!theGraph->GetHistogram ()) return ;
1406- theGraph->GetHistogram ()->SetMinimum (rwymin);
1407- theGraph->GetHistogram ()->SetMaximum (rwymax);
1408- theGraph->GetHistogram ()->GetYaxis ()->SetLimits (rwymin,rwymax);
1409- theGraph->GetHistogram ()->SetBit (TH1::kNoStats );
1410- theGraph->GetHistogram ()->SetDirectory (nullptr );
1411- theGraph->GetHistogram ()->Sumw2 (kFALSE );
1412- theGraph->GetHistogram ()->Paint (chopth); // Draw histogram axis, title and grid
1409+ histogram = new TH1F (TString::Format (" %s_h" ,GetName ()),GetTitle (),npt,rwxmin,rwxmax);
1410+ theGraph->SetHistogram (histogram);
1411+ histogram = theGraph->GetHistogram ();
1412+ if (!histogram) return ;
1413+ histogram->SetMinimum (rwymin);
1414+ histogram->SetMaximum (rwymax);
1415+ histogram->GetYaxis ()->SetLimits (rwymin,rwymax);
1416+ histogram->SetBit (TH1::kNoStats );
1417+ histogram->SetDirectory (nullptr );
1418+ histogram->Sumw2 (kFALSE );
1419+ histogram->Paint (chopth); // Draw histogram axis, title and grid
14131420 } else {
14141421 if (gPad ->GetLogy ()) {
1415- theGraph-> GetHistogram () ->SetMinimum (rwymin);
1416- theGraph-> GetHistogram () ->SetMaximum (rwymax);
1417- theGraph-> GetHistogram () ->GetYaxis ()->SetLimits (rwymin,rwymax);
1422+ histogram ->SetMinimum (rwymin);
1423+ histogram ->SetMaximum (rwymax);
1424+ histogram ->GetYaxis ()->SetLimits (rwymin,rwymax);
14181425 }
1419- theGraph-> GetHistogram () ->Sumw2 (kFALSE );
1420- theGraph-> GetHistogram () ->Paint (chopth); // Draw histogram axis, title and grid
1426+ histogram ->Sumw2 (kFALSE );
1427+ histogram ->Paint (chopth); // Draw histogram axis, title and grid
14211428 }
14221429 }
14231430
@@ -1430,9 +1437,10 @@ void TGraphPainter::PaintGraph(TGraph *theGraph, Int_t npoints, const Double_t *
14301437 rwymax = gPad ->GetUymax ();
14311438 uxmin = gPad ->PadtoX (rwxmin);
14321439 uxmax = gPad ->PadtoX (rwxmax);
1433- if (theGraph->GetHistogram () && !theGraph->InheritsFrom (" TGraphPolar" )) {
1434- maximum = theGraph->GetHistogram ()->GetMaximum ();
1435- minimum = theGraph->GetHistogram ()->GetMinimum ();
1440+
1441+ if (histogram && !theGraph->InheritsFrom (" TGraphPolar" )) {
1442+ maximum = histogram->GetMaximum ();
1443+ minimum = histogram->GetMinimum ();
14361444 } else {
14371445 maximum = gPad ->PadtoY (rwymax);
14381446 minimum = gPad ->PadtoY (rwymin);
0 commit comments