-2

我正在尝试从函数内部调用函数,而前者调用更多函数等。

import ROOT as root
import sys, math

class SFs():
    def __init__(self):
        self.get_EfficiencyData = None
        self.get_EfficiencyMC = None
        self.get_ScaleFactor = None
        self.eff_dataH = None
        self.eff_mcH = None
        self.get_ScaleFactor = None
        self.get_EfficiencyMC = None

    def ScaleFactor(self,inputRootFile):
        self.eff_dataH = root.std.map("string", root.TGraphAsymmErrors)()
        self.eff_mcH = root.std.map("string", root.TGraphAsymmErrors)()
        EtaBins=["Lt0p9", "0p9to1p2","1p2to2p1","Gt2p1"]

        fileIn = root.TFile(inputRootFile,"read")
        HistoBaseName = "Label"
        etaBinsH = fileIn.Get("Bins")
        # etaLabel, GraphName
        nEtaBins = int(etaBinsH.GetNbinsX())
        for iBin in range (0, nEtaBins):
            etaLabel = EtaBins[iBin]
            GraphName = HistoBaseName+etaLabel+"_Data"
        print GraphName,etaLabel

        self.eff_dataH[etaLabel]=fileIn.Get(str(GraphName))
        self.eff_mcH[etaLabel]=fileIn.Get("histo")

        print self.eff_mcH[etaLabel].GetXaxis().GetNbins()
        print self.eff_mcH[etaLabel].GetX()[5]
        self.get_ScaleFactor(46.8,2.0)


    def get_ScaleFactor(self,pt, eta):

        efficiency_mc = get_EfficiencyMC(pt, eta)
        if  efficiency_mc != 0.:
            SF = 1/float(efficiency_mc)
        else:
            SF=1.

        return SF


    def get_EfficiencyMC(self,pt, eta):

        label = FindEtaLabel(eta,"mc")
        # label= "Lt0p9"
        binNumber = etaBinsH.GetXaxis().FindFixBin(eta)
        label = etaBinsH.GetXaxis().GetBinLabel(binNumber)
        ptbin = FindPtBin(eff_mcH, label, pt)
        Eta = math.fabs(eta)
        print "eff_mcH ==================",eff_mcH,binNumber,label,ptbin
        # ptbin=10
        if ptbin == -99: eff =1
        else: eff= eff_mcH[label].GetY()[ptbin-1]

        if eff > 1.: eff = -1
        if eff < 0: eff = 0.
        print "inside eff_mc",eff
        return eff

    sf = SFs()
    sf.ScaleFactor("Muon_IsoMu27.root")

我想调用 get_ScaleFactor() 依次调用 get_EfficiencyMC() 等,但我曾经尝试调用前者,我得到 TypeError: 'NoneType' object is not callable

4

1 回答 1

0

在您的类初始化中,您定义:

self.get_EfficiencyMC = 无

然后定义一个函数(即类方法)def get_EfficiencyMC(self,pt, eta):

当您创建类的实例时,init 部分会在类方法的阴影下执行。只需将其从 init 中删除,或更改方法名称即可。

于 2019-05-26T19:50:38.423 回答