ROOT changing histograms

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

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.

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

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

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