# ROOT changing histograms

**URL:** <https://root-forum.cern.ch/t/root-changing-histograms/63606>\
**Category:** Newbie\
**Created:** [May 26, 2025, 3:09am UTC](https://root-forum.cern.ch/t/root-changing-histograms/63606 "2025-05-26T03:09:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![spencer](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/spencer/32/39846_2.png) [@spencer](https://root-forum.cern.ch/u/spencer)\
**Post date:** [May 26, 2025, 3:09am UTC](https://root-forum.cern.ch/t/root-changing-histograms/63606/1 "2025-05-26T03:09:57Z")

</div>

Hi,

I am not a newbie, but this is probably a newbie question. I am trying to plot two histograms, using the following code, but the second histogram overwrites the first, even if I don’t actually plot the second histogram. I get what I expect (the first histogram) as long as the line

```auto
Oalphatuple->Draw("fspt*fspt>>htOalpha");

```

is commented out, but if I uncomment that line, then the second histogram somehow overwrites the first, even though they have different names, etc. I added htOO-\>SetDirectory(0); to try to protect the first histogram, but that didn’t help. This happens even when the line to plot the second histogram is commented out, as it is below.

```auto
void oxygen(void)
{
using namespace std;
//gROOT->SetStyle("MyStyle");

// gStyle->SetOptFit();

// open files OO, then Oalpha
 
TFile *NTfile1 = new TFile("OO.root");
TNtuple* OOtuple = (TNtuple*)NTfile1->Get("esNT");
 cout<<"OO NTuple retrieved with "<<OOtuple->GetEntries()<< " entries."<<endl;

TFile *NTfile12 = new TFile("Oalpha.root");
TNtuple* Oalphatuple = (TNtuple*)NTfile12->Get("esNT");
cout<<"Oalpha NTuple retrieved with "<<Oalphatuple->GetEntries()<< " entries."<<endl;

// Now plot t for both

TCanvas *c1 = new TCanvas("Fig 1","t-spectrum for OO and O-alpha",600,600);

 TH1F *htOO = new TH1F("htOO","",50,0.,0.04); 
 OOtuple->Draw("fspt*fspt>>htOO");
 htOO->Draw();
 htOO->SetDirectory(0);

TH1F *htOalpha = new TH1F("htOalpha","",50,0.,0.04); 
Oalphatuple->Draw("fspt*fspt>>htOalpha");
 // htOalpha->Draw("same");  
}

```

_ROOT Version:_ 6.34.08  
_Platform:_ Mac Sequioia 15.5  
_Compiler:_ clang-1600.0.26.6

* * *

Spencer Klein

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [May 26, 2025, 4:54am UTC](https://root-forum.cern.ch/t/root-changing-histograms/63606/2 "2025-05-26T04:54:29Z")

</div>

Add the option “goff” so that it is not drawn:

```auto
Oalphatuple->Draw("fspt*fspt>>htOalpha","","goff");

```

> **[ROOT: TTree Class Reference](https://root.cern/doc/master/classTTree.html#a73450649dc6e54b5b94516c468523e45)**
