Exemplo n.º 1
0
    def test_max_overflow_bin(self):
        obj = RoundLog(0.1, 100, max = 1000, overflow_bin = 1000)
        self.assertEqual(  100, obj(  100))
        self.assertEqual( 1000, obj( 1000))
        self.assertEqual( 1000, obj( 5000))

        self.assertEqual( 1000, obj.next(1000)) # the next to the overflow bin
Exemplo n.º 2
0
    def test_min_underflow_bin(self):
        obj = RoundLog(0.1, 100, min = 10, underflow_bin = 0)
        self.assertEqual(  100, obj( 100))
        self.assertAlmostEqual(   10, obj(  10))
        self.assertEqual( 0, obj(   9))

        self.assertEqual( obj(10), obj.next( 0)) # the next to the underflow
Exemplo n.º 3
0
    def test_call(self):
        low = Round(20.0, 100)
        high = RoundLog(0.1, 100)
        binning = Combine(low=low, high=high, at=100)
        self.assertEqual(0, binning(10))
        self.assertEqual(80, binning(90))
        self.assertEqual(100, binning(100))

        low = Round(10.0, 50)
        high = RoundLog(0.1, 50)
        binning = Combine(low=low, high=high, at=50)
        self.assertEqual(10, binning(11))
        self.assertEqual(40, binning(40))
        self.assertAlmostEqual(50, binning(50))
Exemplo n.º 4
0
    def test_next(self):
        low = Round(20.0, 100)
        high = RoundLog(0.1, 100)
        binning = Combine(low=low, high=high, at=100)
        self.assertEqual(20, binning.next(10))
        self.assertEqual(100, binning.next(90))
        self.assertEqual(125.89254117941675, binning.next(100))

        low = Round(10.0, 50)
        high = RoundLog(0.1, 50)
        binning = Combine(low=low, high=high, at=50)
        self.assertEqual(20, binning.next(10))
        self.assertAlmostEqual(50, binning.next(45))
        self.assertEqual(62.94627058970836, binning.next(50))
Exemplo n.º 5
0
 def test_min(self):
     obj = RoundLog(0.1, 100, min = 10)
     self.assertEqual(  100, obj( 100))
     self.assertAlmostEqual(   10, obj(  10))
     self.assertEqual( None, obj(   9))
Exemplo n.º 6
0
 def test_onBoundary(self):
     obj = RoundLog(0.1, 100)
     self.assertEqual( 100, obj( 100))
Exemplo n.º 7
0
 def test_valid(self):
     obj = RoundLog(valid = lambda x: x >= 10)
     self.assertAlmostEqual( 12.589254117941675, obj(13))
     self.assertAlmostEqual( 10.0, obj(10))
     self.assertIsNone(obj(7))
Exemplo n.º 8
0
 def test_call_negative(self):
     obj = RoundLog()
     self.assertIsNone(obj(-1))
Exemplo n.º 9
0
 def test_call_center(self):
     obj = RoundLog(retvalue = 'center')
     self.assertAlmostEqual( 2.23872113856834, obj(   2))
     self.assertAlmostEqual( 22.3872113856834, obj(  20))
     self.assertAlmostEqual( 223.872113856834, obj( 200))
Exemplo n.º 10
0
 def test_call(self):
     obj = RoundLog()
     self.assertAlmostEqual( 1.9952623149688, obj(   2))
     self.assertAlmostEqual( 19.952623149688, obj(  20))
     self.assertAlmostEqual( 199.52623149688, obj( 200))
Exemplo n.º 11
0
    help="Heppy results dir")
parser.add_argument('-o', '--outdir', default='tmp')
parser.add_argument(
    "-n",
    "--nevents",
    default=-1,
    type=int,
    help="maximum number of events to process for each component")
args = parser.parse_args()

analyzerName = 'treeProducerSusyAlphaT'
fileName = 'tree.root'
treeName = 'tree'

outPath1 = os.path.join(args.outdir, 'tbl_met.txt')
binning1 = RoundLog(0.1, 1)
keyComposer1 = GenericKeyComposer(('met_pt', ), (binning1, ))
nextKeyComposer1 = NextKeyComposer((binning1, ))
resultsCombinationMethod1 = CombineIntoList(('met', ))
deliveryMethod1 = WriteListToFile(outPath1)
collector1 = Collector(resultsCombinationMethod1, deliveryMethod1)

outPath2 = os.path.join(args.outdir, 'tbl_jetpt.txt')
binning2 = RoundLog(0.1, 1)
keyComposer2 = GenericKeyComposer(('jet_pt', ), (binning2, ), (0, ))
nextKeyComposer2 = NextKeyComposer((binning2, ))
resultsCombinationMethod2 = CombineIntoList(('jet_pt', ))
deliveryMethod2 = WriteListToFile(outPath2)
collector2 = Collector(resultsCombinationMethod2, deliveryMethod2)

outPath3 = os.path.join(args.outdir, 'tbl_njets_nbjets.txt')
Exemplo n.º 12
0
#!/usr/bin/env python
# Tai Sakuma <*****@*****.**>
from AlphaTwirl.Counter import Counts
from AlphaTwirl.Binning import RoundLog, Echo
import AlphaTwirl

##__________________________________________________________________||
alphaTwirl = AlphaTwirl.AlphaTwirl()

tblcfg = [
    dict(outFileName = 'tbl_met.txt',
         branchNames = ('met_pt', ),
         outColumnNames = ('met', ),
         binnings = (RoundLog(0.1, 1), ),
         countsClass = Counts),
    dict(outFileName = 'tbl_jetpt.txt',
         branchNames = ('jet_pt', ),
         binnings = (RoundLog(0.1, 1), ),
         indices = (0, ),
         countsClass = Counts),
    dict(outFileName = 'tbl_njets_nbjets.txt',
         branchNames = ('nJet40', 'nBJet40'),
         outColumnNames = ('njets', 'nbjets'),
         binnings = (Echo(), Echo()),
         countsClass = Counts),
]

alphaTwirl.addTreeReader(
    analyzerName = 'treeProducerSusyAlphaT',
    fileName = 'tree.root',
    treeName = 'tree',
Exemplo n.º 13
0
    help="Heppy results dir")
parser.add_argument('-o', '--outdir', default='tmp')
parser.add_argument(
    "-n",
    "--nevents",
    default=-1,
    type=int,
    help="maximum number of events to process for each component")
args = parser.parse_args()

analyzerName = 'treeProducerSusyAlphaT'
fileName = 'tree.root'
treeName = 'tree'
outPath = os.path.join(args.outdir, 'tbl_met.txt')

binning = RoundLog(0.1, 1)
keyComposer = GenericKeyComposer(('met_pt', ), (binning, ))

eventBuilder = EventBuilder(analyzerName, fileName, treeName, args.nevents)

outFile = open(outPath, 'w')
columnnames = ("component", "met", "n", "nvar")
print >> outFile, "{:>22s} {:>12s} {:>6s} {:>6s}".format(*columnnames)

heppyResult = HeppyResult(args.heppydir)
for component in heppyResult.components():

    counts = Counts()

    events = eventBuilder.build(component)
    for event in events:
Exemplo n.º 14
0
 def test_max(self):
     obj = RoundLog(0.1, 100, max = 1000)
     self.assertEqual(  100, obj(  100))
     self.assertEqual( None, obj( 1000))
     self.assertEqual( None, obj( 5000))
Exemplo n.º 15
0
 def test_next(self):
     obj = RoundLog(retvalue = 'center')
     self.assertAlmostEqual( 2.818382931264, obj.next(2.23872113856834))
     self.assertAlmostEqual( 28.18382931264, obj.next(22.3872113856834))
     self.assertAlmostEqual( 281.8382931264, obj.next(223.872113856834))
Exemplo n.º 16
0
 def test_init(self):
     RoundLog(retvalue = 'center')
     RoundLog(retvalue = 'lowedge')
     self.assertRaises(ValueError, RoundLog, retvalue = 'yyy')
Exemplo n.º 17
0
    def test_call_zero(self):
        obj = RoundLog()
        self.assertEqual(0, obj(0))

        self.assertEqual(0, obj.next(0)) # next to 0 is 0 unless 0 is the
Exemplo n.º 18
0
 def test_inf(self):
     obj = RoundLog(0.1, 100)
     self.assertIsNone(obj(float('inf')))
     self.assertIsNone(obj(float('-inf')))
     self.assertIsNone(obj.next(float('inf')))
     self.assertIsNone(obj.next(float('-inf')))
Exemplo n.º 19
0
alphaTwirl.addComponentReader(tblXsec)

tbl_nevt_path = os.path.join(args.outDir, 'tbl_nevt.txt')
tblNevt = HeppyResult.TblCounter(outPath=tbl_nevt_path,
                                 columnNames=('nevt', 'nevt_sumw'),
                                 analyzerName='skimAnalyzerCount',
                                 fileName='SkimReport.txt',
                                 levels=('All Events', 'Sum Weights'))
alphaTwirl.addComponentReader(tblNevt)

##__________________________________________________________________||
from AlphaTwirl.Binning import RoundLog
tblcfg = [
    dict(
        keyAttrNames=('met_pt', ),
        binnings=(RoundLog(0.1, 10), ),
        keyOutColumnNames=('met', ),
    )
]

tableConfigCompleter = AlphaTwirl.Configure.TableConfigCompleter(
    defaultSummaryClass=AlphaTwirl.Summary.Count,
    defaultOutDir=args.outDir,
    createOutFileName=AlphaTwirl.Configure.TableFileNameComposer2())
tblcfg = [tableConfigCompleter.complete(c) for c in tblcfg]

reader_collector_pair = [
    AlphaTwirl.Configure.build_counter_collector_pair(c) for c in tblcfg
]
reader = AlphaTwirl.Loop.ReaderComposite()
collector = AlphaTwirl.Loop.CollectorComposite(