I’m new to C++ and root and have what is probably an easy problem. I have an existing file with many histograms named blank_2, blank_3, blank_4, etc.
I’d like to access the histograms one at a time and use GetBinContent() to grab a quantity and then do a calculation. My problem is that I get errors when trying to create a pointer to a histogram. I used a loop and sprintf() more or less like this:
TFile f(“result.root”,“UPDATE”);
char finalname[8];
Int_t bin = 179;
for (Int_t i = 2; i < 11; i++) {
sprintf(finalname, “blank_%d”,i);
TH1D final = (TH1D)f.Get(finalname);
Float_t finalpeak = final->GetBinContent(bin);
…
I get an “illegal pointer to class object final” error at the last line. I’ve tried many variants on the last two lines and am stuck. Am I using the Get() command incorrectly? What is the proper way to do this? Any thoughts would be appreciated.
subtractMo95.C (660 Bytes)