I am 100% sure I am making an extremely stupid mistake here. I have a macro that is supposed to get one histogram from each file and plot them on the same canvas. what it actually does is plot them separately:
void compare(){
TFile *f1 = TFile::Open("hfile.root");
TFile *f2 = TFile::Open("PythiaWithTrackSystematicsCombined.root");
TFile *output = new TFile("output.root","Recreate");
gROOT -> cd();
output->cd();
TCanvas *c = new TCanvas("c");
c->cd();
TH1F *pTNominal = new TH1F("pTNominal","pT Nominal",100,50,7000);
if(f1){pTNominal = (TH1F*)f1->Get("h");
}
TH1F *pTSystematics1 = new TH1F("pTSystematics1","pT Systematics Variation 1",100,50,7000);
pTSystematics1 = (TH1F*)f2->Get("h1_central_rjet_pt_TRACKING1");
if(pTNominal){pTNominal->Draw();
std::cout<<"histogram exists"<<endl;}
pTNominal->SetLineColor(kBlue);
std::cout<<"in the loop"<<endl;
pTNominal->Write();
pTSystematics1->Draw("Same");
pTSystematics1->SetLineColor(kRed);
pTSystematics1->Write();
std::cout<<"in second loop"<<endl;
c->Update();
output->Write();
output->Close();
The output is two empty histograms with the name pTSystematics1 and pTNominal, and two filled histograms with the names they had in the original file, i.e. h and h1_central_rjet_pt_TRACKING1. What am I missing? Thanks for any help!
If you want to have two superimposed histograms stored in the file you need a different approach. Sorry, I thought you wanted to have these superimposed histograms plotted on screen and to write two separate histograms in the file. You probably want to take a look at the THStack class in this case.