ROOT Version: 6.16
Platform: Fedora
Compiler: Emacs
I need to create one final histogram as a sum of many histograms. Any ideas about why I have errors in this code?
void scsum()
{
TCanvas *time = new TCanvas("c1", "overlap", 0, 0, 800, 600);
//TH1F sum("sum","Sum",21620,0,21619);
auto sum = new TH1F("sum","Sum",21620,0,2162);
const int firstNumber = 10153;
const int NFiles = 3;
for (int fileNumber = firstNumber; fileNumber < firstNumber+NFiles; fileNumber++)
{
const char* filename = Form("hists%i_blinded.root", fileNumber);
TFile* myFile = TFile::Open(filename);
if (!myFile)
{
printf("Can not find a file named \"%s\"!\n", filename);
continue;
}
const char* histoname = Form("sc%i", fileNumber);
TH1* h1 = (TH1*)myFile->Get(histoname);
{
Int_t bin[21621];
for (int bin=1; bin <= "sc%i"->GetNbinsX(); bin++)
{sum->SetBinContent(bin, sum->GetXaxis()->GetBinContent(bin) + " sc%i" ->GetXaxis()->GetBinContent(bin));
}
if (!h1)
{
printf("Can not find a histogram named \"%s\" in the file named \"%s\"!\n", histoname, filename);
continue;
}
sum->SetBinContent(bin);
}
}
h1->SetDirectory(gROOT);
h1->Draw("sum");
myFile->Close();
}
}