Hi,
I am new in pyROOT. I am converting a ROOT code to pyRoot to have better integration with my python codes, but I am having some errors.
I am using Root 5.34.34 without possibility to upgrade and the correspont pyROOT version with python 2.7
My root code is like that for now:
#include<iostream>
#include <fstream>
#include "TROOT.h"
#include "TStyle.h"
#include "TCanvas.h"
#include "TH2D.h"
#include "TFile.h"
#include "TTree.h"
using namespace std;
void root(int dataset, int t, bool isCalib=false)
{
gROOT->SetBatch(true);
gStyle->SetOptStat(0);
const char* dataType;
if( isCalib )
{
dataType = "calibration";
}
else
{
dataType = "background";
}
TFile* dataFile = new TFile(Form("data/%s_%d_%03d.root",dataType,dataset,t));
TTree* chi2tree = (TTree*) dataFile->Get("chi2tree");
Int_t chan = 0;
Float_t energy = 0;
chi2tree->SetBranchAddress("chan", &chan);
chi2tree->SetBranchAddress("energy", &energy);
When I do the same in pyROOT, everything goes fine until the SetBranchAddress where I get the following error:
TypeError: none of the 3 overloaded methods succeeded. Full details:
Int_t TTree::SetBranchAddress(const char* bname, void** add, TBranch** ptr = 0) =>
could not convert argument 2
Int_t TTree::SetBranchAddress(const char* bname, void* add, TClass* realClass, EDataType datatype, Bool_t isptr) =>
takes at least 5 arguments (2 given)
Int_t TTree::SetBranchAddress(const char* bname, void* add, TBranch** ptr, TClass* realClass, EDataType datatype, Bool_t isptr) =>
takes at least 6 arguments (2 given)
My pyROOT code is the following:
import ROOT
import sys
print(" This is my script ")
def main(args):
tamanho = len(args)
if tamanho==4:
root(args[1],args[2],args[3])
else:
root(args[1],args[2])
def root(dataset,t,isCalib=False):
ROOT.gROOT.SetBatch(True)
ROOT.gStyle.SetOptStat(0)
if isCalib:
print("\nLoading calibration data\n")
dataType = "calibration"
else:
print("\nLoading background data\n")
dataType = "background"
dataFile = ROOT.TFile("data/{0}_{1}_{2:03}.root".format(dataType,dataset,int(t)))
chi2tree = dataFile.Get("chi2tree")
chan = 0
energy = 0.
chi2tree.SetBranchAddress("chan", chan)
chi2tree.SetBranchAddress("energy", energy)
Thanks in advance,
Pedro