Esempio 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
Esempio 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
Esempio 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))
Esempio 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))
Esempio 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))
Esempio n. 6
0
 def test_onBoundary(self):
     obj = RoundLog(0.1, 100)
     self.assertEqual( 100, obj( 100))
Esempio 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))
Esempio n. 8
0
 def test_call_negative(self):
     obj = RoundLog()
     self.assertIsNone(obj(-1))
Esempio 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))
Esempio 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))
Esempio 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')
Esempio 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',
Esempio 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:
Esempio 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))
Esempio 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))
Esempio n. 16
0
 def test_init(self):
     RoundLog(retvalue = 'center')
     RoundLog(retvalue = 'lowedge')
     self.assertRaises(ValueError, RoundLog, retvalue = 'yyy')
Esempio 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
Esempio 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')))
Esempio 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(