Assume I have a root file that contains Tree-> Iris and under this tree, I have branch ->det and then I have many leaves, like TSd1rEnergy, TSd1rTheta, and so on. Now I want to save the plot generated using Iris-> Draw(“TSd1rEnergy:TSd1Theta”) as a root file. How can I do that?
Another Question is that if I have another root file having the same tree, branch, and leaves and I want to superimpose Iris-> Draw(TSd1rEnergy:TSd1Theta) from both root files and save this plot as the root file, how to do that
_ROOT Version: 6.24/06
Platform: Not Provided
Compiler: Not Provided
using namespace std;
TFile *f= new TFile(“tree06855u.root”);
TTree* Iris = (TTree*)f->Get(“Iris”);
//TH2F *h = new TH2F(“h”,“plot;TSd1rEnergy;TSd1Theta”,180,2000,4000,180,100,1500);
//TH2F *h = new TH2F(“h”,“plot;TSd1rEnergy;TSd1Theta”,100,2000.,4000.,100,100.,1500.);
This is what I am trying to do, please give me suggestions to make some changes inside script for desired results that I want in main forum
TFile *f= new TFile("tree06855u.root");
TTree* Iris = (TTree*)f->Get("Iris");
TFile f2("output.root","recreate"); // create the output file before creating the histogram/s that will be saved in this file
TH2F *h = new TH2F("h","plot;TSd1rEnergy;TSd1Theta",180,2000,4000,180,100,1500);
f2.cd(); // a precaution to make sure we write to f2
For 2 input files just open the second file and get the second tree and plot in the same way, using e.g. f2, tree2, h2 (again, create h2 after the output file); then write h1 and h2 to the output file (they will be two separate histograms).
To plot h1 and h2 together you can do
if this doesn’t work, try with “goff” (so it is not drawn) instead of “same” and then draw h2 on top of h1:
but if the scales are different it will not look good, so you may want to add h1 and h2 to a THStack instead.