def __init__(self, infilenames, categories, histSuffix="mDiMu"):
        self.infilenames = infilenames
        self.categories = categories
        self.histSuffix = histSuffix
        self.files = []
        self.masses = []
        for i in infilenames:
            self.files.append(root.TFile(i))
            mass = -1.
            match = re.match(r".*Hmumu([\d.]+)_.*", i)
            if match:
                mass = float(match.group(1))
            self.masses.append(mass)
        self.hists = {}
        for c in categories:
            tmpList = []
            for i in self.files:
                tmpList.append(i.Get(os.path.normpath(c + "/" + histSuffix)))
            self.hists[c] = tmpList

        self.workspace = root.RooWorkspace("w")
        wImport = getattr(self.workspace, "import")
        self.wImport = wImport

        self.params = {}
        for c in categories:
            tmpList = []
            for inHist, mass in zip(self.hists[c], self.masses):
                inHist.Rebin(1)
                mMuMu = root.RooRealVar("mMuMu", "mMuMu", mass - 20.0,
                                        mass + 20.0)
                mMuMu.setRange("signalfit", mass - 15.0, mass + 15.0)
                #makePDFSig = makeCards.makePDFSigGaus
                #makePDFSig = makeCards.makePDFSigCBConvGaus
                params, debug = makePDFSig(c + str(mass), inHist, mMuMu,
                                           SIGNALFIT[0], SIGNALFIT[1], wImport,
                                           c + str(mass))
                tmpList.append(params)
            self.params[c] = tmpList

        self.eff = {}
        tEff = root.TEfficiency()
        for c in categories:
            tmpList = []
            tmpListErrUp = []
            tmpListErrDown = []
            for inHist, mass, inFn in zip(self.hists[c], self.masses,
                                          self.infilenames):
                tmpSampleName = os.path.splitext(os.path.split(inFn)[1])[0]
                print tmpSampleName
                tmpEff = inHist.Integral() / nEventsMap[tmpSampleName]
                cLevel = 0.683
                tmpList.append((tEff.ClopperPearson(nEventsMap[tmpSampleName],
                                                    int(inHist.Integral()),
                                                    cLevel, False), tmpEff,
                                tEff.ClopperPearson(nEventsMap[tmpSampleName],
                                                    int(inHist.Integral()),
                                                    cLevel, True)))
            self.eff[c] = tmpList
  def __init__(self,infilenames,categories,histSuffix="mDiMu"):
    self.infilenames = infilenames
    self.categories = categories
    self.histSuffix = histSuffix
    self.files = []
    self.masses = []
    for i in infilenames:
      self.files.append(root.TFile(i))
      mass = -1.
      match = re.match(r".*Hmumu([\d.]+)_.*",i)
      if match:
        mass = float(match.group(1))
      self.masses.append(mass)
    self.hists = {}
    for c in categories:
      tmpList = []
      for i in self.files:
        tmpList.append(i.Get(os.path.normpath(c+"/"+histSuffix)))
      self.hists[c] = tmpList

    self.workspace = root.RooWorkspace("w")
    wImport = getattr(self.workspace,"import")
    self.wImport = wImport

    self.params = {}
    for c in categories:
      tmpList = []
      for inHist,mass in zip(self.hists[c],self.masses):
        inHist.Rebin(1)
        mMuMu = root.RooRealVar("mMuMu","mMuMu",mass-20.0,mass+20.0)
        mMuMu.setRange("signalfit",mass-15.0,mass+15.0)
        #makePDFSig = makeCards.makePDFSigGaus
        #makePDFSig = makeCards.makePDFSigCBConvGaus
        params,debug = makePDFSig(c+str(mass),inHist,mMuMu,
                            SIGNALFIT[0],SIGNALFIT[1],
                            wImport,c+str(mass)
                            )
        tmpList.append(params)
      self.params[c] = tmpList

    self.eff = {}
    tEff = root.TEfficiency()
    for c in categories:
      tmpList = []
      tmpListErrUp = []
      tmpListErrDown = []
      for inHist,mass,inFn in zip(self.hists[c],self.masses,self.infilenames):
        tmpSampleName = os.path.splitext(os.path.split(inFn)[1])[0]
        print tmpSampleName
        tmpEff = inHist.Integral()/nEventsMap[tmpSampleName]
        cLevel = 0.683
        tmpList.append((
            tEff.ClopperPearson(nEventsMap[tmpSampleName],int(inHist.Integral()),cLevel,False),
            tmpEff,
            tEff.ClopperPearson(nEventsMap[tmpSampleName],int(inHist.Integral()),cLevel,True)
            )
            )
      self.eff[c] = tmpList
Пример #3
0
  def __init__(self,fileName,title):
    f = root.TFile(fileName)
    self.f = f
    self.colors = [1,root.kRed+1,root.kBlue+1,root.kGreen+1,root.kCyan,root.kPink]
    self.title = title
    self.saveTitle = re.sub(r"rightarrow","",title)
    self.saveTitle = re.sub(r"#","",self.saveTitle)
    self.saveTitle = re.sub(r"{\W}+","",self.saveTitle)
    self.saveTitle = re.sub(r" +","",self.saveTitle)
    print self.title
    print self.saveTitle
    # Old Code
    getData = getattr(self,"getData")
    countsList = []
    resList = []
    quantList = []
    categoriesList = []
    prefix = "IncPresel"
    categories = ["BB","BO","BE","OO","OE","EE"]
    if re.search(r"VBF",fileName) or re.search(r"vbf",fileName) :
      prefix = "VBFPresel"
      categories = [""]
    self.categories = categories
    if True:
      tmpCounts, tmpRes, tmpQuants, hists = getData(f,categories,prefix)
      countsList.append(tmpCounts)
      resList.append(tmpRes)
      quantList.append(tmpQuants)
      categoriesList.append(categories)
      self.histsCatDict = hists
    self.titles = [title]
    self.countsList = countsList
    self.resList = resList
    self.quantList = quantList
    self.categoriesList = categoriesList
    self.prefix = prefix

    # New Code
    self.workspace = root.RooWorkspace("w")
    wImport = getattr(self.workspace,"import")
    mMuMu = root.RooRealVar("mMuMu","m_{#mu#mu} [GeV]",vminMass,vmaxMass)
    mMuMu.setRange("signal",signalRange[0],signalRange[1])
    mMuMu.setRange("signalfit",SIGNALFIT[0],SIGNALFIT[1])
    mMuMu.setRange("all",minMass,maxMass)
    mMuMu.setRange("vall",vminMass,vmaxMass)
    mMuMu.setRange("draw",plotRange[0],plotRange[1])
    wImport(mMuMu)
    self.mMuMu = mMuMu
    for i in categories:
       tmpParamList, tmpDebug = makePDFSig(i,self.histsCatDict[i],mMuMu,minMass,maxMass,wImport,i)
       #print tmpDebug

    #self.workspace.Print()

    self.canvas = root.TCanvas("canvas")
Пример #4
0
    def __init__(self, fileNames, titles, categories):
        assert (len(fileNames) == len(titles))
        self.files = []
        self.histsCatDict = {}
        self.titles = titles
        self.nFiles = len(fileNames)
        self.categories = categories

        self.colors = [
            1, root.kRed + 1, root.kBlue + 1, root.kGreen + 1, root.kCyan,
            root.kPink
        ]

        for i in categories:
            self.histsCatDict[i] = []

        for f in fileNames:
            tmpFile = root.TFile(f)
            self.files.append(tmpFile)
            for i in categories:
                strToGet = i + '/mDiMu'
                strToGet = os.path.normpath(strToGet)
                if strToGet[0] == '/':
                    strToGet = strToGet[1:]
                tmpHist = tmpFile.Get(strToGet)
                self.histsCatDict[i].append(tmpHist)

        self.workspace = root.RooWorkspace("w")
        wImport = getattr(self.workspace, "import")
        mMuMu = root.RooRealVar("mMuMu", "m_{#mu#mu} [GeV]", vminMass,
                                vmaxMass)
        mMuMu.setRange("signal", signalRange[0], signalRange[1])
        mMuMu.setRange("signalfit", SIGNALFIT[0], SIGNALFIT[1])
        mMuMu.setRange("all", minMass, maxMass)
        mMuMu.setRange("vall", vminMass, vmaxMass)
        mMuMu.setRange("draw", plotRange[0], plotRange[1])
        wImport(mMuMu)
        self.mMuMu = mMuMu
        for i in categories:
            for j in range(self.nFiles):
                tmpParamList, tmpDebug, tmpSigInjectDS = makePDFSig(
                    i + str(j), self.histsCatDict[i][j], mMuMu, minMass,
                    maxMass, wImport, i)
                #print tmpDebug

        #self.workspace.Print()

        self.canvas = root.TCanvas("canvas")
Пример #5
0
  def __init__(self,fileNames,titles,categories):
    assert(len(fileNames) == len(titles))
    self.files = []
    self.histsCatDict = {}
    self.titles = titles
    self.nFiles = len(fileNames)
    self.categories = categories

    self.colors = [1,root.kRed+1,root.kBlue+1,root.kGreen+1,root.kCyan,root.kPink]

    for i in categories:
      self.histsCatDict[i] = []

    for f in fileNames:
      tmpFile = root.TFile(f)
      self.files.append(tmpFile)
      for i in categories:
        strToGet = i + '/mDiMu'
        strToGet = os.path.normpath(strToGet)
        if strToGet[0] == '/':
            strToGet = strToGet[1:]
        tmpHist = tmpFile.Get(strToGet)
        self.histsCatDict[i].append(tmpHist)
    
    self.workspace = root.RooWorkspace("w")
    wImport = getattr(self.workspace,"import")
    mMuMu = root.RooRealVar("mMuMu","m_{#mu#mu} [GeV]",vminMass,vmaxMass)
    mMuMu.setRange("signal",signalRange[0],signalRange[1])
    mMuMu.setRange("signalfit",SIGNALFIT[0],SIGNALFIT[1])
    mMuMu.setRange("all",minMass,maxMass)
    mMuMu.setRange("vall",vminMass,vmaxMass)
    mMuMu.setRange("draw",plotRange[0],plotRange[1])
    wImport(mMuMu)
    self.mMuMu = mMuMu
    for i in categories:
     for j in range(self.nFiles):
       tmpParamList, tmpDebug, tmpSigInjectDS = makePDFSig(
                        i+str(j),self.histsCatDict[i][j],mMuMu,minMass,maxMass,wImport,i)
       #print tmpDebug

    #self.workspace.Print()

    self.canvas = root.TCanvas("canvas")
Пример #6
0
    def __init__(self, fileName, title):
        f = root.TFile(fileName)
        self.f = f
        self.colors = [
            1, root.kRed + 1, root.kBlue + 1, root.kGreen + 1, root.kCyan,
            root.kPink
        ]
        self.title = title
        self.saveTitle = re.sub(r"rightarrow", "", title)
        self.saveTitle = re.sub(r"#", "", self.saveTitle)
        self.saveTitle = re.sub(r"{\W}+", "", self.saveTitle)
        self.saveTitle = re.sub(r" +", "", self.saveTitle)
        print self.title
        print self.saveTitle
        # Old Code
        getData = getattr(self, "getData")
        countsList = []
        resList = []
        quantList = []
        categoriesList = []
        prefix = "IncPresel"
        categories = ["BB", "BO", "BE", "OO", "OE", "EE"]
        if re.search(r"VBF", fileName) or re.search(r"vbf", fileName):
            prefix = "VBFPresel"
            categories = [""]
        self.categories = categories
        if True:
            tmpCounts, tmpRes, tmpQuants, hists = getData(
                f, categories, prefix)
            countsList.append(tmpCounts)
            resList.append(tmpRes)
            quantList.append(tmpQuants)
            categoriesList.append(categories)
            self.histsCatDict = hists
        self.titles = [title]
        self.countsList = countsList
        self.resList = resList
        self.quantList = quantList
        self.categoriesList = categoriesList
        self.prefix = prefix

        # New Code
        self.workspace = root.RooWorkspace("w")
        wImport = getattr(self.workspace, "import")
        mMuMu = root.RooRealVar("mMuMu", "m_{#mu#mu} [GeV]", vminMass,
                                vmaxMass)
        mMuMu.setRange("signal", signalRange[0], signalRange[1])
        mMuMu.setRange("signalfit", SIGNALFIT[0], SIGNALFIT[1])
        mMuMu.setRange("all", minMass, maxMass)
        mMuMu.setRange("vall", vminMass, vmaxMass)
        mMuMu.setRange("draw", plotRange[0], plotRange[1])
        wImport(mMuMu)
        self.mMuMu = mMuMu
        for i in categories:
            tmpParamList, tmpDebug = makePDFSig(i, self.histsCatDict[i], mMuMu,
                                                minMass, maxMass, wImport, i)
            #print tmpDebug

        #self.workspace.Print()

        self.canvas = root.TCanvas("canvas")