コード例 #1
0
def addCuts(alg, key, cuts, save=False):

    if alg == None:
        raise Exception('addCuts - invalid alg')

    if type(cuts) != type([]):
        raise Exception('addCuts - invalid inputs for %s: %s, %s, %s' %
                        (alg.GetAlgName(), key, cuts, dir(cuts)))

    keys = []

    for cut in cuts:
        print cut
        if cut.GetCutName() in keys:
            raise Exception('addCuts - %s::%s - duplicate cut %s in %s' %
                            (alg.GetAlgName(), key, cut.GetCutName(), keys))

        keys += [cut.GetCutName()]
        alg.SetPar('%s%s' % (key, cut.GetCutName()), cut.GetRegistry())

    alg.SetPar(key, ','.join(keys))

    if save:
        clog.info('Print cuts: %s' % key)
        print physicsLight.getCutsAsLatex(
            cuts, 'cuts_%s_%s.tex' % (alg.GetAlgName(), key))

    return cuts
コード例 #2
0
def prepareReadNtuple(ROOT, options, tree='event', hist_config=None, load_libs=True):

    if load_libs:
        physicsConfig.loadPhysicsTausLib(ROOT, options)
    
    run = ReadNtuple('readNtuple')
    run.SetKey('TreeName',       tree)
    run.SetKey('PrintFiles',     'no')
    run.SetKey('NPrint',         options.nprint)
    run.SetKey('NEvent',         options.nevent)
    run.SetKey('FileKeys',       '.root')
    run.SetKey('CloseFile',      'yes')
    run.SetKey('Print',          'yes')
    run.SetPar('HistMan::Debug', 'no')
    run.SetPar('HistMan::Sumw2', 'yes')
    
    if options.output:
        run.SetKey('OutputFile', options.output)
        
    testArea = os.environ.get('TestArea')

    #
    # Set recursively global parameters
    #
    if options.debug:        
        run.SetGlobalPar('Debug', options.debug)
        run.SetKey('Debug', 'yes')
    else:
        run.SetKey('Debug', 'no')
        
    #
    # Read histogram definitions
    #
    histman = ROOT.Anp.HistMan.Instance()
    
    testArea = os.environ.get('TestArea')

    if hist_config == None:
        hist_config = ['config']

    for hconfig in hist_config:
        histPath = '%s/PhysicsNtuple/PhysicsTaus/%s/' %(testArea, hconfig.rstrip('/'))
        
        if os.path.isdir(histPath):
            clog.info('prepareReadNtuple - read xml files from: %s' %histPath)
                    
            for file in os.listdir(histPath):
                if file.count('.xml'):
                    histman.ReadFile(histPath+file)
        else:
            clog.warning('prepareReadNtuple - invalid path: %s' %histPath)
            
    return run
コード例 #3
0
def getRunChain(name, algs=None, cuts=None, options=None):

    alg = physicsBase.AlgConfig(name, 'RunChain')

    if type(cuts) == type([]):
        addCuts(alg, 'CutCand', cuts)

    if type(algs) == type([]) and len(algs):
        alg.AddAlg(algs)

    if options != None and cuts != None and options.print_cuts:
        clog.info('----------------------------------------')
        clog.info('Print candidate cuts for %s:' % name)
        print physicsLight.getCutsAsLatex(cuts,
                                          'RunChain_%s_CutCand.tex' % name)

    return alg
コード例 #4
0
    def __init__(self, alg_name):
        import ROOT
        
        self._alg   = None
        self._reg   = physicsBase.getRegistry()
        self._run   = ROOT.Anp.ReadNtuple()
        self._files = []
        self._dirs  = []        
        self._log   = physicsConfig.getLog('ReadNtuple')
        self._hist  = physicsBase.getRegistry()
        self._hist.AllowNonUniqueKeys()
        self._gpar  = {}

        self.SetPar('AlgName', alg_name)
        self.SetPar('AlgType', 'ReadNtuple')
コード例 #5
0
def main():

    #
    # Check inputs
    #
    if len(args) != 1: 
        log.info('Need exactly one argument: %s' %(args))
        sys.exit(1)

    if len(args) == 1 and not os.path.isfile(args[0]):
        log.error('Invalid input file: %s' %args[0])
        sys.exit(1)

    tausConfig.setPlotDefaults(ROOT)

    rfile = ROOT.TFile(args[0], 'READ')

    #
    # Check which dataset ids (MC channel ids) are active for the input file
    #
    dsids = readDSIDs(rfile)

    #
    # Read x-section data
    #
    xsecs = readXSecs(dsids)

    #
    # Read sum of MC event weights computed before selections, using all events
    #
    readNorms(rfile, xsecs)

    #
    # Plot TH1 histograms at requested path
    #
    plotHists(rfile, xsecs, options.dir_path)
コード例 #6
0
import os
import sys
import re

import PhysicsBase.PhysicsBaseConfig as physicsBase
import PhysicsTaus.PhysicsTausConfig as physicsConfig
import PhysicsTaus.PhysicsTausCuts   as physicsCuts
import PhysicsTaus.PhysicsTausBase   as physicsTauBase

from PhysicsTaus.PhysicsTausConfig  import CutItem
from PhysicsTaus.PhysicsTausConfig  import getCandName

clog = physicsConfig.getLog(os.path.basename(__file__))
#========================================================================================
# Configuration for algorithms
#========================================================================================
def prepareJobConfig(ROOT, options, runNumber, isData):

    clog.info('Prepare python configuration...')

    prep_algs = [getPrepReco('prepReco', options)]
    plot_algs = []
    
    #-------------------------------------------------------------------------
    # Configure event plotting algorithm
    #
    plot_algs += [getPlotEventAlgs('plotEventAlgs', options, runNumber, isData)]

    #-------------------------------------------------------------------------
    # Configure top level alg
    #
コード例 #7
0
import os
import sys
import re
import PhysicsBase.PhysicsBaseConfig as physicsBase
import PhysicsTaus.PhysicsTausConfig as physicsLight

from PhysicsTaus.PhysicsTausConfig import CutItem

clog = physicsLight.getLog(__name__)


#-----------------------------------------------------------------------------
def addCuts(alg, key, cuts, save=False):

    if alg == None:
        raise Exception('addCuts - invalid alg')

    if type(cuts) != type([]):
        raise Exception('addCuts - invalid inputs for %s: %s, %s, %s' %
                        (alg.GetAlgName(), key, cuts, dir(cuts)))

    keys = []

    for cut in cuts:
        print cut
        if cut.GetCutName() in keys:
            raise Exception('addCuts - %s::%s - duplicate cut %s in %s' %
                            (alg.GetAlgName(), key, cut.GetCutName(), keys))

        keys += [cut.GetCutName()]
        alg.SetPar('%s%s' % (key, cut.GetCutName()), cut.GetRegistry())
コード例 #8
0
def main():

    timeStart = time.time()
    
    #
    # Parse command line options
    #
    import PhysicsTaus.PhysicsTausConfig as config

    p = config.prepareOptionParser()
    (options, args) = p.parse_args()

    log = config.getLog(__name__, debug=options.debug)
    log.info('Start time: %s' %time.asctime())    

    #
    # Recursively search for ROOT files in input paths
    #
    root_files = sorted(config.findInputLocalFiles(args, options.filekey, options.dirskey, print_files=False))

    if options.xsec_list:
        files = config.selectInputFiles(root_files, options)
    else:
        files = root_files


    log.info('Selected %4d ROOT files' %(len(files)))

    #
    # Filter files
    #
    if options.filekey:
        store = files
        files = []
        
        for fpath in store:
            if re.search(options.filekey, os.path.basename(fpath)):
                files += [fpath]

        log.info('%4d file(s) passed filter: --file-key=\"%s\"' %(len(files), options.filekey))

    log.info('Process %d input file(s)' %len(files))
    for file in files:
        print '   %s' %file
            
    #
    # Configure python RunConfig wrapper around C++ RunModule
    #
    import ROOT
    from PhysicsTaus.PhysicsTausNtuple import prepareMakeNtupleConfig
    
    if not options.no_batch:
        ROOT.gROOT.SetBatch(True)

    isData = False
    if 'Data' in file:
        isData = True
    runNumber = file[-11:-5]
    run = prepareMakeNtupleConfig(ROOT, options)
    
    for file in files:
        run.StoreInputFile(file)

    if options.print_vars:
        ROOT.Anp.Cut.PrintCutNames()        
        
#    run.ExecuteRegistry()

    log.info('Run python post processing code...')

    log.info('Local time: %s'    %time.asctime())
    log.info('Total time: %.1fs' %(time.time()-timeStart))
コード例 #9
0
def main():

    timeStart = time.time()

    #
    # Parse command line options
    #
    import PhysicsTaus.PhysicsTausConfig as config

    p = config.prepareOptionParser()
    (options, args) = p.parse_args()

    log = config.getLog(__name__, debug=options.debug)
    log.info('Start time: %s' % time.asctime())

    #
    # Recursively search for ROOT files in input paths
    #
    root_files = sorted(
        config.findInputLocalFiles(args,
                                   '.root',
                                   options.dirskey,
                                   save_files=options.save_files,
                                   print_files=False))

    if options.xsec_list:
        files = config.selectInputFiles(root_files, options)
    else:
        files = root_files

    log.info('%4d file(s) selected from %d input ROOT files' %
             (len(files), len(root_files)))

    #
    # Filter files
    #
    if options.filekey:
        store = files
        files = []

        for fpath in store:
            if re.search(options.filekey, os.path.basename(fpath)):
                files += [fpath]

        log.info('%4d file(s) passed filter: --file-key=\"%s\"' %
                 (len(files), options.filekey))

    if options.save_files:
        log.info('Save input files to: %s' % options.save_files)

        ofile = open(options.save_files, 'w')

        for file in files:
            ofile.write('%s\n' % file)

        ofile.close()

    log.info('Process %d input file(s)' % len(files))
    for file in files:
        print '   %s' % file

    #
    # Configure python RunConfig wrapper around C++ RunModule
    #
    import ROOT
    import PhysicsTaus.PhysicsTausRun2Base as Base
    import PhysicsTaus.PhysicsTausRun2Plot as tth
    from PhysicsTaus.PhysicsTausProcReco import prepareJobConfig

    if options.batch:
        ROOT.gROOT.SetBatch(True)

    run = prepareJobConfig(ROOT, options)

    for file in files:
        run.StoreInputFile(file)

    if options.print_vars:
        ROOT.Anp.Cut.PrintCutNames()

    run.ExecuteRegistry()

    log.info('Run python post processing code...')

    if options.ntuple_file and options.do_flat_ntuple:
        Base.copySimpleCountsFromInputFiles(files, options.ntuple_file)

    log.info('Local time: %s' % time.asctime())
    log.info('Total time: %.1fs' % (time.time() - timeStart))