ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided
Hi
I am reading a set of TGraphAsymmErrors and save them to a map, but when I am trying to pass and read the TGraph from the map, I get like that the TGraph is empy.
import ROOT as root
import sys,math
eff_dataH = root.std.map("string", root.TGraphAsymmErrors)()
def ScaleFactor(inputRootFile="Muon_IsoMu27.root") :
global etaBinsH
global get_EfficiencyData
global get_EfficiencyMC
EtaBins=["Lt0p9", "0p9to1p2","1p2to2p1","Gt2p1"]
print inputRootFile
fileIn = root.TFile(inputRootFile,"read")
fileIn.ls()
HistoBaseName = "ZMassEta"
etaBinsH = fileIn.Get("etaBinsH")
#etaLabel, GraphName
nEtaBins = int(etaBinsH.GetNbinsX())
eff_data= []
eff_mc= []
#eff_mcH =root.TGraphAsymmErrors()
print "EtaBins...........",nEtaBins, len(EtaBins)
for iBin in range (0, nEtaBins) :
etaLabel = EtaBins[iBin]
GraphName = HistoBaseName+etaLabel+"_Data"
eff_data.append(fileIn.Get(str(GraphName)))
eff_dataH[etaLabel]=fileIn.Get(str(GraphName))
sff = get_EfficiencyData(46.8,2.0)
print "ScaleFactor ",sff
def get_EfficiencyData(pt, eta) :
label = FindEtaLabel(eta,"data")
binNumber = etaBinsH.GetXaxis().FindFixBin(eta)
label = etaBinsH.GetXaxis().GetBinLabel(binNumber)
print eff_dataH
ptbin = FindPtBin(eff_dataH, label, pt)
Eta = math.fabs(eta)
if ptbin == -99 : eff =1
else : eff= eff_dataH[label].GetY()[ptbin-1]
print "inside eff_data",eff
if eff > 1. : eff = -1
if eff < 0 : eff = 0.
return eff
def FindPtBin( eff_map, EtaLabel, Pt) :
Npoints = eff_map[EtaLabel].GetN()
print Npoints, "for ===============>",eff_map[EtaLabel],eff_map[EtaLabel].GetN(),EtaLabel
ptMAX = (eff_map[EtaLabel].GetX()[Npoints-1])+(eff_map[EtaLabel].GetErrorXhigh(Npoints-1))
ptMIN = (eff_map[EtaLabel].GetX()[0])-(eff_map[EtaLabel].GetErrorXlow(0))
if Pt >= ptMAX : return Npoints
elif Pt < ptMIN :
return -99
else : return eff_map[EtaLabel].GetXaxis().FindFixBin(Pt)
The problem seems to appear when I call the FindPtBin to which I pass the map<string,TGraph> as shown above where the GetN() returns always 0. Any ideas what am I doing wrong ?
Thanks