Hi, I am pasting part of my code that I am using:
{
gROOT->Reset();
TH1F *after_accep_corr[3];
char *histname_accep_corr = new char[30];
for (Int_t k=0; k<3; k++) {
sprintf(histname_accep_corr, “after_accep_corr_%d”,k+1);
after_accep_corr[k] = new TH1F(histname_accep_corr,"",20,x_nu);
}
TFile *f_flux = new TFile(“nu_flux_output.root”,“READ”);
cout<<final_flux_1_1->GetBinContent(2)<<endl;
f_flux->Close();
The first output statement prints w/o any problem. But in the second output statement I get the following message:
Error: Symbol after_accep_corr_1 is not defined in current scope
This means that somehow the code is looking for after_accep_corr_1 in the root file nu_flux_output.root instead of in the main body of the code. How can I get around this problem ?
I am using a slightly old version of root : root_4.04_02b
[quote]This means that somehow the code is looking for after_accep_corr_1 in the root file nu_flux_output.root instead of in the main body of the code. How can I get around this problem ?
[/quote]What about using the variable you have declared an use after_accep_corr[0] instead?
HI Philippe,
thanks for your answer. Actually the place where I have my second cout statement, I will replace that with a function . I was planning to pass the after_accep_corr_1 (filled in the main program) histogram and the final_flux_1_1 histogram (from the nu_flux_output.root) file.
But since this is creating problems, what I can do is right at the beginnig of my code (before I declare any histogram) I can open the nu_flux_output.root file , then copy all the histogram contents in array and pass them onto the function later on. But I was hoping there would be a way out , b/c doing this would make my code a little clumsy.
[quote]But since this is creating problems, [/quote]I don’t understand why you still have a problem if you use “after_accep_corr[0]”. What is the issue then?
HI Philippe,
sorry for confusing you. What I am trying to do is pass two histograms to a function. One histogram is declared in the code, the other is inside a root file. But if I open this root file to access the histogram then my code can’t identify the first histogram anymore.
[quote]But if I open this root file to access the histogram then my code can’t identify the first histogram anymore.[/quote]This is what I understood and since in your case you already have a C++ variable pointing to the histogram object ( after_accep_corr[0] ), you do NOT need to refer to the histogram using its histogram name (after_accep_corr_1) ).
Could you please send me the code snippets where you attempts to apply my recommendation and tell me explicity how it is failing.
Yes. The variable follow the C++ syntax and grammar (and can be used in compiled code) while the ‘name’ is a CINT addon which result depend on the current ROOT file directory (and can not be used in every circunstances).