Hi,
I know there are similar threads to this but I can’t find any that actually address my problem and so far none of the fixes have worked. I might have missed one that does apply so please feel free to redirect me if that is the case.
I am writing a macro to pull in two files that share the same Tree name and structure but have different data parameters. I want to plot a histogram from each file (EDecayG1) and save the histograms to a separate file (cf.root) to access later. When I execute the macro it works fine and the histogram of sim1240.EDecayG1 appears. However, if I try “simpeak630->Draw()” I get
Error: Symbol simpeak630 is not defined in current scope (tmpfile):1:
Error: Failed to evaluate simpeak630->Draw()
*** Interpreter error recovered ***
“simpeak1240->Draw()” doesn’t complain until I close the canvas that was automatically produced from executing the macro. Then I get the same error.
This is the code for my macro:
[code]{
//Open initial simulation file for the first peak
TFile * sim630 = TFile::Open(“26F-1p1n-geant-anal_E630_W50_100k.root”);
//Add the second simulation file to the tree
at->AddFriend(“sim1240 = at”,“26F-1p1n-geant-anal_E1240_W30_100k.root”);
//Draw EDecayG1 histogram for simulations
at->Draw(“EDecayG1>>simpeak630(25,0,5)”);
simpeak630->SetLineColor(2);
simpeak630->Draw();
at->Draw(“sim1240.EDecayG1>>simpeak1240(25,0,5)”);
simpeak1240->SetLineColor(2);
simpeak1240->Draw();
//Add histograms to the list
TList * list = new TList();
list->Add(simpeak630);
list->Add(simpeak1240);
//Change the ownership of the histograms so they aren’t deleted when the file is closed at the end of this macro
simpeak630->SetDirectory(0);
simpeak1240->SetDirectory(0);
//Save the list of histograms to a file
TFile * cf = new TFile(“cf.root”,“recreate”);
list->Write();
cf->Close();
}
[/code]
Sidenote:
Before I simplified down to this I had a section of code at the beginning that pulled in a data file, created a histogram from that file and added it to the list of histograms to be written to cf.root. That section worked perfectly fine and I could reproduce the “datahst” histogram without any problems, but I had the same issues with the simulation files as described above. I took out that portion of the code to try to isolate the problem. If you would like to see the code including the data portion please let me know and I can attach it.