Beispiel #1
0
    def customInit(self, initVars):
        self.n_excluded = 0
        self.n_kept = 0
        self.n_skipped = 0
        self.sample = initVars['sample']
        self.config = initVars['config']

        if self.sample.identifier in self.applyToSamples:
            self.excludedEvents = {}
            excludedSampleTree = SampleTree([self.excludeTreeFileName],
                                            config=self.config)
            excludedSampleTree.enableBranches(['run', 'event'])
            print "INFO: loading list of events to filter"
            n_events = 0
            for ev in excludedSampleTree:
                if ev.run not in self.excludedEvents:
                    self.excludedEvents[ev.run] = {}
                if ev.event not in self.excludedEvents[ev.run]:
                    self.excludedEvents[ev.run][ev.event] = 0
                self.excludedEvents[ev.run][ev.event] += 1
                if self.excludedEvents[ev.run][ev.event] == 1:
                    n_events += 1

            intrinsicDuplicates = sum(
                [[[event, run, count]
                  for event, count in self.excludedEvents[run].items()
                  if count > 1] for run in self.excludedEvents.keys()], [])
            print "INFO: done => ", n_events, "distinct events will be filtered out of", self.applyToSamples
            if len(intrinsicDuplicates) > 0:
                print "INFO: the event list provided contains", len(
                    intrinsicDuplicates), "duplicates itself!"
        else:
            print "INFO: event number filter disdable for this sample"
    def customInit(self, initVars):
        self.n_excluded = 0
        self.n_kept = 0
        self.n_skipped = 0
        self.sample = initVars['sample']
        self.config = initVars['config']

        if self.sample.identifier in self.applyToSamples:
            self.excludedEvents = {}
            excludedSampleTree = SampleTree([self.excludeTreeFileName], config=self.config)
            excludedSampleTree.enableBranches(['run','event'])
            print "INFO: loading list of events to filter"
            n_events = 0
            for ev in excludedSampleTree:
                if ev.run not in self.excludedEvents:
                    self.excludedEvents[ev.run] = {}
                if ev.event not in self.excludedEvents[ev.run]:
                    self.excludedEvents[ev.run][ev.event] = 0
                self.excludedEvents[ev.run][ev.event] += 1
                if self.excludedEvents[ev.run][ev.event]==1:
                    n_events += 1

            intrinsicDuplicates = sum([[[event,run,count] for event,count in self.excludedEvents[run].items() if count > 1] for run in self.excludedEvents.keys()], [])
            print "INFO: done => ", n_events, "distinct events will be filtered out of", self.applyToSamples
            if len(intrinsicDuplicates) > 0:
                print "INFO: the event list provided contains",len(intrinsicDuplicates),"duplicates itself!"
        else:
            print "INFO: event number filter disdable for this sample"
Beispiel #3
0
        dataSamples = eval(config.get('dc:' + region, 'data'))
        for dataSample in dataSamples:
            sampleTree = SampleTree({
                'name': dataSample,
                'folder': inputFolder
            },
                                    config=config)

            outputFileName = logFolder + '/' + region + '_' + dataSample + '_' + opts.run + '_' + opts.event + '.txt'
            print("save event list to:", outputFileName)
            treePlayer = sampleTree.tree.GetPlayer()
            treePlayer.SetScanRedirect(True)
            treePlayer.SetScanFileName(outputFileName)

            branchList = BranchList(["run", "event"])
            regionCut = config.get(
                'Cuts',
                config.get('dc:' + region, 'cut') if config.has_option(
                    'dc:' + region, 'cut') else region)
            branchList.addCut(regionCut)

            expressions = ":".join(branchList.getListOfBranches()) if len(
                opts.expressions) < 1 else opts.expressions
            branchList.addCut(expressions)
            sampleTree.enableBranches(branchList.getListOfBranches())

            sampleTree.tree.Scan(expressions,
                                 "run==" + opts.run + "&&event==" + opts.event,
                                 "colsize=16")
Beispiel #4
0
    sampleTree = SampleTree({
        'sample': sample,
        'folder': directory
    },
                            config=config)
    #raw_input()

    # since we load all trees, we can compute the factor to scale cross section to luminosity directly (otherwise write it to ntuples
    # first and then use it as branch, or compute it with full set of trees before)
    scaleXStoLumi = sampleTree.getScale(sample)

    # enable only used branches!
    # this will speed up processing a lot
    sampleTree.enableBranches(
        BranchList([
            signalRegionSelection, weightExpression_DeepCSV,
            weightExpression_DeepJet, taggerExpression_DeepCSV,
            taggerExpression_DeepJet
        ]).getListOfBranches() + ['Jet*'])

    # this will create the TTreeformula objects
    sampleTree.addFormula(signalRegionSelection)
    sampleTree.addFormula(signalRegionSelection_roc)
    sampleTree.addFormula(weightExpression_DeepCSV)
    sampleTree.addFormula(weightExpression_DeepJet)
    sampleTree.addFormula(weightExpression_DeepCSV_nosf)
    sampleTree.addFormula(weightExpression_DeepJet_nosf)
    sampleTree.addFormula(taggerExpression_DeepCSV)
    sampleTree.addFormula(taggerExpression_DeepJet)

    isSignal = 1 if sample.name in signalNames else 0
Beispiel #5
0
from __future__ import print_function
import ROOT
ROOT.gROOT.SetBatch(True)
from myutils.XbbConfig import XbbConfigReader, XbbConfigTools
from myutils.sampleTree import SampleTree as SampleTree
from myutils.BranchList import BranchList

config = XbbConfigTools(XbbConfigReader.read("Zvv2017"))
sampleTree = SampleTree(
    {
        'name': 'MET',
        'folder': config.get('Directories', 'dcSamples')
    },
    config=config)
variables = ["H_pt", "MET_Pt", "H_pt/MET_Pt"]

# enable only explicitly used branches
sampleTree.enableBranches(BranchList(variables).getListOfBranches())

# create TTReeFormula's
for variable in variables:
    sampleTree.addFormula(variable)

# loop over events
for event in sampleTree:
    print(
        sampleTree.tree.GetReadEntry(),
        ", ".join([x + "=%1.4f" % sampleTree.evaluate(x) for x in variables]))
    if sampleTree.tree.GetReadEntry() > 98:
        break