I’m trying to merge some histograms into one (I have to fit a background distribution compounded by several channels). For each bin, I take the max value among the various histos. I’m accustomed to use STL so I would like to use vectors.
typedef vector<TH1F> HistVector_t;
typedef vector<TH1F>::const_iterator HistVectorItr;
HistVector_t bkg_vec;
bkg_vec.push_back(&h_j1);
.
.
.
bkg_vec.push_back(&h_j8);
TH1F* h_bkg = MergeHistograms(bkg_vec, hmodel, sout);
Here it is MergeHistogram:
TH1F* MergeHistograms(HistVector_t &hvec, TH1F* hmodel, ostream& sout) {
TH1F* h_bkg = (TH1F*)hmodel->Clone("h_bkg");
sout << endl << "Merging "<< hvec.size() << " background histograms." << endl;
for(Int_t binc = 1; binc <h_bkg>GetNbinsX(); binc++) { //for each bin
vector<Float_t> values;
sout << "Bin " << binc <<endl>GetBinContent(binc); // fill values vector
//sout << "value = " << vtemp << endl;
values.push_back(vtemp);
}
//find max element
sout << "Finding max el.." << endl;
vector<Float_t>::iterator melement = max_element( values.begin(), values.end() );
//sout << "Bin: " << binc << ", value= " << melement <<endl>SetBinContent(binc, (*melement) );
}
return h_bkg;
}
When I launch the macro, ROOT says:
*** Break *** bus error
Debugging the code, the error is here:
I’ve got another error if I remove brackets, or if I use double deference **.
Thank you in advance