Problem when creating array of histograms

Try: [code]#include “TFile.h”
#include “TH1.h”
#include “TString.h”
#include “TDirectory.h”
#include “TROOT.h”

#include

std::vector<TH1D*> *myhists(int runfirst, int runlast,
int first_segment, int last_segment,
int detn)
{
TDirectory cwd = gDirectory;
std::vector<TH1D
> hists = new std::vector<TH1D>; // Raw signals

// Load File
TString f_name = TString::Format(“HPGe_%d_%d_%d.root”,runfirst, runlast, last_segment);
TFile *f = TFile::Open(f_name);
if ((!f) || (f->IsZombie())) {
std::cout << “File " << f_name << " could not be opened.” << std::endl;
delete f;
if (cwd) cwd->cd();
return hists;
}

for (int run = runfirst; run <= runlast; run++) {
for (int seg = first_segment; seg <= last_segment; seg++) {
std::cout << "Run : " << run << std::endl;
std::cout << "Segment : " << seg << std::endl;
std::cout << “-----------------” << std::endl;
TH1D *hSignal;
f->GetObject(TString::Format(“h_HPGe_%d_%d_%d”, detn, run, seg), hSignal);
if(!hSignal) { std::cout << “***Segment not found. Moving on.” << std::endl; continue; }
hSignal->SetDirectory(cwd); // (cwd) … or … (0) … or … (gROOT)
hists->push_back(hSignal);
} // End of loop over segments
} // End of Loop over runs

delete f;
if (cwd) cwd->cd();
return hists;
}[/code]