TFile

Hi I am trying to write a bunch of histograms to a file with the following code:
{

char *m_output_ntuple;

TFile *m_f;
TH2D *jdist0_vs_sin2thlp;
TH2D *jdist0_vs_costhet;
TH2D *jdist0_vs_cospsi;
TH2D *jdist0_vs_coschi;
TH2D *jdist0_vs_phi;
TH2D *jdist0_vs_phik;

TH2D *jdist1_vs_sin2thet;
m_f = new TFile(m_output_ntuple,“RECREATE”);
m_f->Open();

jdist0_vs_sin2thlp= new TH2D(“jdist0_vs_sin2thlp”,“jdist0_vs_sin2thlp”,1000,0,1,1000,0,1);
jdist0_vs_costhet= new TH2D(“jdist0_vs_costhet”,“jdist0_vs_costhet”,1000,0,1,1000,-1,1);
jdist0_vs_cospsi= new TH2D(“jdist0_vs_cospsi”,“jdist0_vs_cospsi”,1000,0,1,1000,-1,1);
jdist0_vs_coschi= new TH2D(“jdist0_vs_coschi”,“jdist0_vs_coschi”,1000,0,1,1000,-1,1);
jdist0_vs_phi= new TH2D(“jdist0_vs_phi”,“jdist0_vs_phi”,1000,0,1,1000,0,6.5);
jdist0_vs_phik= new TH2D(“jdist0_vs_phik”,“jdist0_vs_phik”,1000,0,1,1000,0,6.5);

Long64_t nentries = fChain->GetEntriesFast();

Long64_t nbytes = 0, nb = 0;
for (Long64_t jentry=0; jentry<nentries;jentry++) {
Long64_t ientry = LoadTree(jentry);
if (ientry < 0) break;
nb = fChain->GetEntry(jentry); nbytes += nb;
// if (Cut(ientry) < 0) continue;

  for(Int_t i=0; i<=kMaxevt; i++){
  
  jdist0_vs_sin2thlp->Fill(evt_dist[i][0],evt_SIN2THLP[i]);
  jdist0_vs_costhet->Fill(evt_dist[i][0],evt_COSTHET[i]);
  jdist0_vs_cospsi->Fill(evt_dist[i][0],evt_COSPSI[i]);
  jdist0_vs_coschi->Fill(evt_dist[i][0],evt_COSCHI[i]);
  jdist0_vs_phi->Fill(evt_dist[i][0],evt_PHI[i]);
  jdist0_vs_phik->Fill(evt_dist[i][0],evt_PHIK[i]);
  
  }

}
m_f->Write();

m_f->Close();

}

but it doesnt work could you please point me into the right direction

thanks maki

Remove the line m_f->Open(); The file has already been opened by the TFile constructor (and actually TFile::Open is a static function that happens to open yet another file (unrelated to the one created/open by the TFile constructor).

Cheers,
Philippe.