Hello co-rooters!
I am facing the following issue :
In my code I have to define a lot of histograms, that share almost the same name (i.e. ha1, ha2, ha3, …)
This is the case for many other histograms wihtin my code (hb1, hb2, hb3, …, hc1, hc2, hc3, …)
I thought about making a function that will construct those histograms. Although I tried to do it, I am not sure if it’s possible and if I am on the right track.
My code so far is
TH1F test_root(int number, char *name, double nbins, double bin_low, double bin_high){
TString hname(name);
TH1F *myhist[number];
char *histname = new char[10];
for (int i=1; i<=number; i++){
sprintf(histname,"h%s%d",hname,i);
//myhist[i] = new TH1F(TString::Format("%s%d",hname.Data(),i),TString::Format("%s%d",hname.Data(),i),nbins,bin_low,bin_high);
myhist[i] = new TH1F (histname,"",nbins,bin_low,bin_high);
return myhist[i];
}
}
When I run the code using .x test_root.c(2,“amp”,100,0,100) I get the error
[quote]Error: Non-static-const variable in array dimension test_root.c:3:
(cint allows this only in interactive command and special form macro which
is special extension. It is not allowed in source code. Please ignore
subsequent errors.)
*** Interpreter error recovered ***
[/quote]
I am sure that my code is not correct, but at least I have a starting point… Any help would be more than welcome!