I am doing neutrino research that requires me to do data analysis by overlaying histograms. We are using ROOT. I am currently trying to convert the following code from C++ to pyroot:
#include "TFile.h" #include "TH1F.h" #include "TCanvas.h" #include "TString.h" void myscript() { //get a histogram named vtx_0 from the file 5A_data TFile* file = TFile::Open("5A_data"); TH1F* hist = file->Get("vtx_0"); TCanvas* canvas = new TCanvas("c1", "Dynamic Filling Example", 200, 10, 700,500); hist->Draw(); }
This is the code I have so far, re-written in python:
from ROOT import TFile, TH1F, TCanvas, TString def myscript(): #get vtx_0 from 5A_data TFile file1 = open("5A_data") TH1F hist =
I have had limited exposure to Python. The Python code above was created mostly from looking at various online examples, and so I am not even sure if what I have written up to this point is correct.
What I am most in need of, and what I have been unable to find online, is how to covert the following line in C++ to its equivalent in Python.
TH1F* hist = file->Get("vtx_0");
How does one do this?
- In addition, if you see anything amiss with the Python code I have written so far, please tell me what I did wrong and how I might fix it. Thank you.