Hello rooters,
This maybe a simple question.But I cannot resolve it.
I tried to read a existing .root file and read a histogram. Okay.It’s working
Then I wanna create a new .root file which should have a new histogram.But my new .root file is empty.
I tried to shorten my code as much as possible.
#include <algorithm>
#include <TRandom3.h>
#include <TF2.h>
#include <TH2D.h>
#include <TMath.h>
#include <TFile.h>
#include <TCanvas.h>
void Fitting(){
TFile *AnaFile = new TFile("fit.root", "RECREATE");
TFile *hFile=TFile::Open("xBQ2binning_data.root");
TH1F *h_pion_invariant_mass_Stat_Syst;
hFile->GetObject("h_pion_invariant_mass_Stat_Syst", h_pion_invariant_mass_Stat_Syst);
auto* h_QSq_xBj_log_bin_data=new TH2F("h_QSq_xBj_log_bin_data", "QSq vs xBj log binning cross section", 50,0.0,1.0,100,0.0,10.0);
h_QSq_xBj_log_bin_data->Fill(1,1);
AnaFile->Write();
AnaFile->Close();
}
I expect h_QSq_xBj_log_bin_data
histogram in the new fit.root file.But fit.root is empty.Not sure why.
Could you please help me?
Attached the .root file that reading the histogram.
xBQ2binning_data.root (1.2 MB)