示例#1
0
    def SetGlobalPar(self, key, value):
        physicsBase.setRegistryKey(self._reg, key, value)

        if self._alg:
            self._alg.SetGlobalPar(key, value)
        else:
            self._gpar[key] = value
示例#2
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 = getLog('ReadNtuple')
        self._hist = physicsBase.getRegistry()
        self._hist.AllowNonUniqueKeys()
        self._gpar = {}

        self.SetPar('AlgName', alg_name)
        self.SetPar('AlgType', 'ReadNtuple')
示例#3
0
def loadPhysicsTausLib(ROOT, options):

    clog.info('loadPhysicsTausLib - load shared libraries')

    physicsBase.loadPhysicsBase()
    setPlotDefaults(ROOT)

    if (hasattr(options, 'draw')
            and options.draw) or (hasattr(options, 'wait') and options.wait):
        clog.info(
            'loadPhysicsTausLib - draw options enabled... set plotting style')
    else:
        ROOT.gROOT.SetBatch(True)
        clog.info('loadPhysicsTausLib - set ROOT batch mode')

    ROOT.gSystem.Load('libPhysicsData')
    ROOT.gSystem.Load('libPhysicsDataDict')
    ROOT.gSystem.Load('libPhysicsTaus')
    ROOT.gSystem.Load('libPhysicsTausDict')
示例#4
0
    def AddTopAlg(self, alg_name, alg_list, Print="yes"):
        if self._alg != None:
            self._log.warning('AddTopAlg - Top algorithm is already configured')
            return
        
        self._alg = physicsBase.AlgConfig(alg_name, 'RunAlgs')
        self._alg.SetKey('Print', Print)
        self._alg.AddAlg(alg_list)

        for key, value in self._gpar.iteritems():
            self._alg.SetGlobalPar(key, value)
        self._gpar = {}
示例#5
0
def addCutsToRegistry(reg, key, cuts):

    if reg == None:
        raise Exception('addCutsToRegistry - invalid reg')

    if type(cuts) != type([]):
        raise Exception('addCutsToRegistry - invalid inputs: %s, %s, %s' %
                        (key, cuts, dir(cuts)))

    keys = []

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

        keys += [cut.GetCutName()]
        physicsBase.setRegistryKey(reg, '%s%s' % (key, cut.GetCutName()),
                                   cut.GetRegistry())

    physicsBase.setRegistryKey(reg, key, ','.join(keys))

    return cuts
示例#6
0
    def __init__(self,
                 name,
                 conf='',
                 weight=None,
                 abs=False,
                 hash=None,
                 dummy=False):

        self.cut_name = name
        self.cut_conf = ''
        self.raw_conf = conf
        self.cut_wkey = weight
        self.cut_reg = physicsBase.getRegistry()
        self.list_and = []
        self.list_or = []
        self.sub_cuts = {}
        self.hash = hash
        self.abs = abs
        self.weight = None

        if name.count(' '):
            raise Exception(
                'CutItem - name must not include space character: %s' % name)

        if conf.count('(') == 0 and conf.count(')') == 0:
            self.cut_conf = conf
        elif conf.count('(') != conf.count(')'):
            raise Exception('CutItem - bad conf string: %s' % conf)
        else:
            self.AddSubCuts(name, conf)

        self.cut_reg.SetVal('CutName', self.cut_name)
        self.cut_reg.SetVal('CutConf', self.cut_conf)

        self.SetHash(self.hash)

        if abs:
            self.cut_reg.SetVal('CutUseAbs', 'yes')
        else:
            self.cut_reg.SetVal('CutUseAbs', 'no')

        if type(self.cut_wkey) == type(''):
            self.cut_reg.SetVal('CutWeights', self.cut_wkey)
        elif type(self.cut_wkey) == type([]):
            self.cut_reg.SetVal('CutWeights', ','.join(self.cut_wkey))

        if dummy:
            self.cut_reg.SetVal('CutDummy', 'yes')
示例#7
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
示例#8
0
def getPrepReco(name, options):

    var_weights = ['MCWeightOrg']
    
    clog.info('getPrepReco - list of weights: %s' %var_weights)

    alg = physicsBase.AlgConfig(name, 'PrepReco')
    alg.SetKey('Debug',         options.debug)
    alg.SetKey('Print',         'yes')
    alg.SetKey('DoLepIdFilter', 'yes')
    alg.SetKey('AddLeptonMass', 'yes')
    alg.SetKey('Weights',       ','.join(var_weights))
    alg.SetKey('CopyName',      'loose/Count')
    alg.SetKey('DoCopy',        'yes')
        
    if options.no_weight:
        alg.SetKey('NoWeight', 'yes')

    return alg
示例#9
0
def getRunNexus(name, options, algs=None, do_nexus_file=False):

    chain = physicsCuts.getRunChain(name, algs=algs, cuts=None)
    chain.SetKey('DirName',     '')
    chain.SetKey('Debug',       options.debug)
    chain.SetKey('Print',       options.debug)
    chain.SetKey('DoTimer',     options.do_timer)

    alg = physicsBase.AlgConfig(name, 'RunNexus')    
    alg.SetKey('Print',    options.debug)
    alg.SetKey('Debug',    options.debug)
    alg.SetKey('DirName',  '')    
    alg.SetKey('DirName0', 'data')
    alg.SetKey('VarName',  'MCChannel')
    alg.SetKey('AlgName',   chain.GetAlgName())
    
    alg.AddAlg(chain)

    if do_nexus_file and options.output and options.output.count('.root'):
        alg.SetKey('FileKey', '%s-' %options.output.partition('.root')[0])
        alg.SetKey('DoFile',  'yes')

    return alg
示例#10
0
def getPlotEventAlgs(name, options, runNumber, isData):

    print_event  = physicsBase.AlgConfig('printEvent', 'PrintEvent')

    plot_event  = physicsBase.AlgConfig('plotEvent', 'PlotEvent')
    plot_event.SetKey('DirName',     'taus')
    plot_event.SetKey('Debug',       options.debug)
    plot_event.SetKey('KeyHist',     'PlotEventHistKey')

    plot_SigSS  = physicsBase.AlgConfig('plotSigSS', 'PlotEvent')
    plot_SigSS.SetKey('DirName', 'SigSS')
    plot_SigSS.SetKey('Debug',       options.debug)
    plot_SigSS.SetKey('KeyHist',     'PlotEventHistKey')

    plot_SigOS  = physicsBase.AlgConfig('plotSigOS', 'PlotEvent')
    plot_SigOS.SetKey('DirName', 'SigOS')
    plot_SigOS.SetKey('Debug',       options.debug)
    plot_SigOS.SetKey('KeyHist',     'PlotEventHistKey')

    plot_BkgOS  = physicsBase.AlgConfig('plotBkgOS', 'PlotEvent')
    plot_BkgOS.SetKey('DirName', 'BkgOS')
    plot_BkgOS.SetKey('Debug',       options.debug)
    plot_BkgOS.SetKey('KeyHist',     'PlotEventHistKey')

    plot_BkgSS  = physicsBase.AlgConfig('plotBkgSS', 'PlotEvent')
    plot_BkgSS.SetKey('DirName', 'BkgSS')
    plot_BkgSS.SetKey('Debug',       options.debug)
    plot_BkgSS.SetKey('KeyHist',     'PlotEventHistKey')

    event_cuts = getEventCuts(runNumber, isData)
    event_cuts_OS = getEventCutsOS(runNumber, isData)
    event_cuts_SS = getEventCutsSS(runNumber, isData)
    object_tau_cuts = getTauCuts()
    object_truth_cuts = getTruthCuts()
    object_muon_cuts = getMuonCuts()
    invert_muon_cuts = getInvertMuonCuts()
    object_elec_cuts = getElecCuts()
    object_jet_cuts = getJetCuts()
    object_truth_tau_cuts = getTruthCuts();
    object_truth_tau_cuts = getTruthTauCuts()
    object_truth_elec_cuts = getTruthElecCuts()
    object_truth_muon_cuts = getTruthMuonCuts()
    object_elec_trig_cuts = getNewElecTriggers()
    object_muon_trig_cuts = getNewMuonTriggers()

    physicsCuts.addCuts(plot_event, 'CutEvent', event_cuts)
    physicsCuts.addCuts(plot_event, 'CutElec', object_elec_cuts)
    physicsCuts.addCuts(plot_event, 'CutMuon', object_muon_cuts)
    physicsCuts.addCuts(plot_event, 'CutTau', object_tau_cuts)

    physicsCuts.addCuts(plot_SigOS, 'CutEvent', event_cuts_OS )
    physicsCuts.addCuts(plot_SigOS, 'CutMuon', object_muon_cuts)
    physicsCuts.addCuts(plot_SigOS, 'CutElec', object_elec_cuts)
    physicsCuts.addCuts(plot_SigOS, 'CutTau', object_tau_cuts)

    physicsCuts.addCuts(plot_SigSS, 'CutEvent', event_cuts_SS )
    physicsCuts.addCuts(plot_SigSS, 'CutMuon', object_muon_cuts)
    physicsCuts.addCuts(plot_SigSS, 'CutElec', object_elec_cuts)
    physicsCuts.addCuts(plot_SigSS, 'CutTau', object_tau_cuts)

    physicsCuts.addCuts(plot_BkgOS, 'CutEvent', event_cuts_OS )
    physicsCuts.addCuts(plot_BkgOS, 'CutMuon', invert_muon_cuts)
    physicsCuts.addCuts(plot_BkgOS, 'CutElec', object_elec_cuts)
    physicsCuts.addCuts(plot_BkgOS, 'CutTau', object_tau_cuts)

    physicsCuts.addCuts(plot_BkgSS, 'CutEvent', event_cuts_SS )
    physicsCuts.addCuts(plot_BkgSS, 'CutMuon', invert_muon_cuts)
    physicsCuts.addCuts(plot_BkgSS, 'CutElec', object_elec_cuts)
    physicsCuts.addCuts(plot_BkgSS, 'CutTau', object_tau_cuts)

    write_ntuple = physicsBase.AlgConfig('WriteNtuple', 'WriteNtuple')

    physicsCuts.addCuts(write_ntuple, 'CutEvent', event_cuts)
    physicsCuts.addCuts(write_ntuple, 'CutElec', object_elec_cuts)

    algs = [plot_SigOS]#, plot_SigSS]#, plot_BkgOS, plot_BkgSS ]
    
    chain = physicsCuts.getRunChain(name, algs=algs)
    chain.SetKey('DirName',     name)
    chain.SetKey('Debug',       options.debug)
    chain.SetKey('Print',       'no')
    chain.SetKey('DoTimer',     options.do_timer)

    return chain
示例#11
0
def getLog(name, level='INFO', debug=True, print_time=False):
    return physicsBase.getLog(name=name,
                              level=level,
                              debug=debug,
                              print_time=print_time)
示例#12
0
def prepareRunModule(ROOT, options, hist_config=None):
    loadPhysicsTausLib(ROOT, options)

    run = physicsBase.RunModule()

    run.SetKey('TreeName', 'sum config event')
    run.SetKey('TreeThread', 'event')
    run.SetKey('PrintFiles', 'no')
    run.SetKey('NPrint', options.nprint)
    run.SetKey('NEvent', options.nevent)
    run.SetKey('FileKeys', '.root')
    run.SetKey('CloseFile', '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)

        if os.path.isdir(histPath):
            for file in os.listdir(histPath):
                if file.count('.xml'):
                    histman.ReadFile(histPath + file)

    top_algs = []

    #=========================================================================
    # Configure object algs
    #
    prep_jet = physicsBase.AlgConfig('prepJet', 'PrepJet')
    prep_met = physicsBase.AlgConfig('prepMet', 'PrepMet')
    prep_elec = physicsBase.AlgConfig('prepElec', 'PrepElec')
    prep_muon = physicsBase.AlgConfig('prepMuon', 'PrepMuon')
    prep_track = physicsBase.AlgConfig('prepTrack', 'PrepTrack')
    prep_vtx = physicsBase.AlgConfig('prepVtx', 'PrepVtx')
    prep_truth = physicsBase.AlgConfig('prepTruth', 'PrepTruth')

    top_algs += [
        prep_jet, prep_met, prep_elec, prep_muon, prep_track, prep_vtx,
        prep_truth
    ]

    trig_muon = ['EF_mu18_MG', 'EF_mu18_MG_medium']
    trig_elec = ['EF_e20_medium', 'EF_e22_medium', 'EF_e22vh_medium1']

    #    for trig in trig_muon:
    #        physicsTrig.addTrigCuts(prep_muon, trig)

    #    for trig in trig_elec:
    #        physicsTrig.addTrigCuts(prep_elec, trig)

    prep_muon.SetKey('TrigMuon', ','.join(trig_muon))
    prep_elec.SetKey('TrigElec', ','.join(trig_elec))

    if options.smear_sigma > 0.0:
        prep_track.SetKey('SmearSigma', options.smear_sigma)

    return (run, top_algs)
示例#13
0
    def GetRegistryConfig(self):
        if type(self._alg) == None:
            self._log.warning('Missing top algorithm')
            return None

        reg = physicsBase.getRegistry()

        reg.Merge(self._reg)

        if self._alg != None:
            physicsBase.setRegistryKey(reg, 'ReadNtuple::SubAlgType',
                                       self._alg.GetAlgType())
            physicsBase.setRegistryKey(reg, 'ReadNtuple::SubAlgName',
                                       self._alg.GetAlgName())
            physicsBase.setRegistryKey(reg, self._alg.GetAlgName(),
                                       self._alg.GetConfigRegistry())

        physicsBase.setRegistryKey(reg, 'ReadNtuple::HistMan', self._hist)

        input_reg = physicsBase.getRegistry()
        input_reg.AllowNonUniqueKeys()

        for file in self._files:
            physicsBase.setRegistryKey(input_reg, 'File', file)

        physicsBase.setRegistryKey(reg, 'ReadNtuple::InputFiles', input_reg)
        return reg
示例#14
0
 def SetPar(self, key, value):
     physicsBase.setRegistryKey(self._reg, key, value)
示例#15
0
 def SetKey(self, key, value):
     physicsBase.setRegistryKey(self._reg, 'ReadNtuple::' + key, value)