Exemplo n.º 1
0
    def test_number_parsing_w_space(self):
        samples = TQSampleFolder("samples")
        parser = TQXSecParser(samples)
        parser.readCSVfile(os.path.join(self.tempdir, "testXS.csv"))
        parser.readMappingFromColumn("*path*")
        unit = TQXSecParser.unitName(TQXSecParser.unit("pb"))
        parser.setTagString("xSectionUnit", unit)
        parser.addPathVariant("channel", "em")
        parser.addAllSamples(False)

        vbf = samples.getSampleFolder("sig/em/vbf/341080")
        self.assertTrue(vbf, msg="Failed to get vbf sample folder")

        xsVBF = vbf.getTagDoubleDefault(".xsp.xSection", -999.)
        self.assertAlmostEqual(xsVBF, 0.8579E-4, delta=1e-10)
Exemplo n.º 2
0
    def test_simple_mapping(self):
        histogram = os.path.join(self.tempdir, "testHistogram.root:mapping")

        samples = TQSampleFolder("samples")
        testSample = samples.getSampleFolder("test+").getSample("testSample+")

        testSample.setTreeLocation(
            os.path.join(self.tempdir, "test.root:testTree"))
        testSample.setTagBool("usemcweights", True)
        #print "Creating test cuts"
        baseCutFolder = TQFolder("cuts")
        cutText = '+baseCut{<.cutExpression="1.",.weightExpression="1.",title="dummy base cut">\n+weightedCut{<.cutExpression="1.",.weightExpression="TH1Map:' + histogram + '([testVal])">}\n}'
        #print "Creating cuts from expression:"
        #print cutText
        baseCutFolder.importFromText(cutText)
        baseCut = TQCut.importFromFolder(baseCutFolder.getFolder("?"))
        #print "creating sample visitor"
        visitor = TQAnalysisSampleVisitor()
        visitor.setBaseCut(baseCut)
        #visitor.setVerbose(True)

        #print "creating histomaker analysis job"
        histoJob = TQHistoMakerAnalysisJob()
        if not histoJob.bookHistogram(
                'TH1F("histo","",20,-2.,2.) << (testVal:"original distribution")'
        ):
            print("Failed to book histogram")

        baseCut.addAnalysisJob(histoJob, "*")
        samples.visitMe(visitor)
        #samples.writeToFile("testSampleFolder.root")
        original = samples.getHistogram("test", "baseCut/histo")
        scaled = samples.getHistogram("test", "weightedCut/histo")
        ok = True
        for b in range(0, original.GetNbinsX()):
            exponent = -1 if original.GetBinCenter(b) < 0 else 1
            #check if removing the scaling yield the same bin value
            ok = ok and (abs(
                original.GetBinContent(b) -
                scaled.GetBinContent(b) / pow(2, exponent)) < 1e-10)
            self.assertTrue(
                ok
            )  #don't check for exact match, we might have some numerical discrepancies