예제 #1
0
class applyJSON(Module):
    def __init__(self, json_file):
        if json_file:
            self.lumiList = LumiList(os.path.expandvars(json_file))
        else:
            self.lumiList = None

    def beginJob(self):
        pass

    def endJob(self):
        pass

    def beginFile(self, inputFile, outputFile, inputTree, wrappedOutputTree):
        self.out = wrappedOutputTree
        self.out.branch("jsonPassed", "I")

    def endFile(self, inputFile, outputFile, inputTree, wrappedOutputTree):
        pass

    def analyze(self, event):
        """process event, return True (go to next module) or False (fail, go to next event)"""

        if self.lumiList:
            jsonPassed = self.lumiList.contains(event.run,
                                                event.luminosityBlock)
        else:
            jsonPassed = 1

        self.out.fillBranch("jsonPassed", jsonPassed)
        return True
예제 #2
0
def files_for_events(run_events, dataset, instance='global'):
    wanted_run_lumis = []
    for x in run_events: # list of runs, or list of (run, event), or list of (run, lumi, event)
        if type(x) == int:
            wanted_run_lumis.append((x, None))
        elif len(x) == 2:
            wanted_run_lumis.append((x[0], None))
        else:
            wanted_run_lumis.append(x[:2])

    files = set()
    for file, run_lumis in file_details_run_lumis(dataset, instance).iteritems():
        ll = LumiList(runsAndLumis=run_lumis)
        for x in wanted_run_lumis:
            if ll.contains(*x):
                files.add(file)
    return sorted(files)
예제 #3
0
def files_for_events(run_events, dataset, instance='global'):
    wanted_run_lumis = []
    for x in run_events:  # list of runs, or list of (run, event), or list of (run, lumi, event)
        if type(x) == int:
            wanted_run_lumis.append((x, None))
        elif len(x) == 2:
            wanted_run_lumis.append((x[0], None))
        else:
            wanted_run_lumis.append(x[:2])

    files = set()
    for file, run_lumis in file_details_run_lumis(dataset,
                                                  instance).iteritems():
        ll = LumiList(runsAndLumis=run_lumis)
        for x in wanted_run_lumis:
            if ll.contains(*x):
                files.add(file)
    return sorted(files)
예제 #4
0
for aline in files:
    fullpath_file = options.prefix+aline
    if options.debug:
        print options.prefix+aline

    try:
        lumis = Lumis(fullpath_file)
    except:
        print "File "+fullpath_file+" NOT FOUND!"
        continue;

    for i,lumi in enumerate(lumis):
        lumi.getByLabel(labelPhiSymInfo,handlePhiSymInfo)
        phiSymInfo = handlePhiSymInfo.product()
        # skipping BAD lumiSections
        if options.jsonFile != "" and not lumiList.contains(phiSymInfo.back().getStartLumi().run(),phiSymInfo.back().getStartLumi().luminosityBlock()):
            continue

        beginTime=lumi.luminosityBlockAuxiliary().beginTime().unixTime()
        timeMap[beginTime]={"run":phiSymInfo.back().getStartLumi().run(),"lumi":phiSymInfo.back().getStartLumi().luminosityBlock(),"totHitsEB":phiSymInfo.back().GetTotHitsEB()}

        if options.debug:
            print "====>"
            print "Run "+str(phiSymInfo.back().getStartLumi().run())+" Lumi "+str(phiSymInfo.back().getStartLumi().luminosityBlock())+" beginTime "+str(beginTime)
            print "NEvents in this LS "+str(phiSymInfo.back().GetNEvents())
            print "TotHits EB "+str(phiSymInfo.back().GetTotHitsEB())+" Avg occ EB "+str(float(phiSymInfo.back().GetTotHitsEB())/phiSymInfo.back().GetNEvents()) 
            print "TotHits EE "+str(phiSymInfo.back().GetTotHitsEE())+" Avg occ EE "+str(float(phiSymInfo.back().GetTotHitsEE())/phiSymInfo.back().GetNEvents()) 
    
    # close current file
    lumis._tfile.Close()
예제 #5
0
    return (p.pfIsolationR03().sumChargedHadronPt + max(p.pfIsolationR03().sumNeutralHadronEt + p.pfIsolationR03().sumPhotonEt - p.pfIsolationR03().sumPUPt/2,0.0))/p.pt()

reader.start()
maker.start()

counter_read = -1 
counter_write = -1 

while reader.run():
    counter_read += 1
    if counter_read%100==0: logger.info("Reading event %i.", counter_read)

    maker.event.run, maker.event.lumi, maker.event.evt = reader.evt

    # json
    if lumiList is not None and not lumiList.contains(maker.event.run, maker.event.lumi): continue

    # muons in acceptance
    accepted_muons = filter(  lambda p:p.pt()>15 and abs(p.eta())<2.4,  reader.products['muon'] )

    # good and veto muons (CutBasedIdMediumPrompt = CutBasedIdMedium +  and dz<0.1 and dxy< 0.02 )
    good_muons = filter( lambda p: p.CutBasedIdMediumPrompt and relIso03(p)<0.12 and abs(p.dB(ROOT.pat.Muon.PV3D)/p.edB(ROOT.pat.Muon.PV3D))<4, accepted_muons )
    #good_muons = filter( lambda p: p.CutBasedIdMediumPrompt and relIso03(p)<0.2, accepted_muons )
    veto_muons = filter( lambda p: relIso03(p)<0.4 and p not in good_muons, accepted_muons )

    # require Z from first two good muons. Always veto Medium muons.
    if len(good_muons)<2: continue

    mll = ( good_muons[0].p4() + good_muons[1].p4() ).M()
    #if abs( ( good_muons[0].p4() + good_muons[1].p4() ).M() - 91.2 ) > 10. : continue
    if mll  < 20. : continue
예제 #6
0
class JSONAnalyzer( Analyzer ):
    '''Apply a json filter, and creates an RLTInfo TTree.
    See PhysicsTools.HeppyCore.utils.RLTInfo for more information

    example:
    
    jsonFilter = cfg.Analyzer(
      "JSONAnalyzer",
      )

    The path of the json file to be used is set as a component attribute.

    The process function returns:
      - True if
         - the component is MC or
         - if the run/lumi pair is in the JSON file
         - if the json file was not set for this component
      - False if the component is MC or embed (for H->tau tau),
          and if the run/lumi pair is not in the JSON file.
    '''

    def __init__(self, cfg_ana, cfg_comp, looperName):
        super(JSONAnalyzer, self).__init__(cfg_ana, cfg_comp, looperName)
        if not cfg_comp.isMC:
            if self.cfg_comp.json is None:
                raise ValueError('component {cname} is not MC, and contains no JSON file. Either remove the JSONAnalyzer for your path or set the "json" attribute of this component'.format(cname=cfg_comp.name))
            self.lumiList = LumiList(os.path.expandvars(self.cfg_comp.json))
        else:
            self.lumiList = None
        

        self.rltInfo = RLTInfo()

    def beginLoop(self, setup):
        super(JSONAnalyzer,self).beginLoop(setup)
        self.counters.addCounter('JSON')
        self.count = self.counters.counter('JSON')
        self.count.register('All Lumis')
        self.count.register('Passed Lumis')

    def process(self, event):
        self.readCollections( event.input )
        evid = event.input.eventAuxiliary().id()
        run = evid.run()
        lumi = evid.luminosityBlock()
        eventId = evid.event()

        event.run = run
        event.lumi = lumi
        event.eventId = eventId

        if self.cfg_comp.isMC:
            return True

        if self.lumiList is None:
            return True

        self.count.inc('All Lumis')
        if self.lumiList.contains(run,lumi):
            self.count.inc('Passed Lumis')
            self.rltInfo.add('dummy', run, lumi)
            return True
        else:
            return False
        

    def write(self, setup):
        super(JSONAnalyzer, self).write(setup)
        self.rltInfo.write( self.dirName )
def doit2(skip_understood_events=False, max_mass_diff=0.1, use_jsons=True):
    old = doit('data/Run2011MuonsOnly/ana_datamc_data.root', 'dil_mass', 'SimpleNtupler', 't', 'OurSelNewNoSign && SameSign')
    new = doit('m10t/ntuple_SingleMuRun2011.root',           'mass',     'SameSign',       't', '')
    #old = doit('mc/ana_datamc_ttbar.root',  'dil_mass', 'SimpleNtupler', 't', 'OurSelNewNoSign && SameSign')
    #new = doit('m10t/ntuple_MC_ttbar.root', 'mass',     'SameSign',       't', '')
    #use_jsons = False

    if use_jsons:
        old_json = LumiList('data/Run2011MuonsOnly/ana_datamc_data.forlumi.json')
        new_json = LumiList('m10t/ntuple_SingleMuRun2011.report.json')
    else:
        class dummy:
            def contains(*args):
                return 'N/A'
        old_json = new_json = dummy()

    oldk = set(old.keys())
    newk = set(new.keys())
    max_mass_diff_seen = 0
    
    print 'counts:\told\tnew'
    print 'events:\t%i\t%i' % (len(oldk), len(newk))
    print
    print 'diffs in dimu counts?'
    print '%6s%6s%14s%14s%14s%25s%25s' % ('ojs','njs','run','lumi','event','old','new')
    for rle in sorted(oldk & newk):
        if len(old[rle]) != len(new[rle]):
            r,l,e = rle
            print '%6s%6s%14s%14s%14s%25s%25s' % (old_json.contains((r,l)), new_json.contains((r,l)), r,l,e, m2s(old[rle]), m2s(new[rle]))
    print
    print 'mass comparison:'
    print '%6s%6s%14s%14s%14s%25s%25s%10s' % ('ojs','njs','run','lumi','event','old','new','maxd')
    to_print = []
    for rle in sorted(oldk & newk):
        if len(old[rle]) == len(new[rle]):
            if len(old[rle]) > 1:
                print '***\nwarning: more than one dilepton in mass comparison, just dumbly sorting\n***'
            oldm = sorted(old[rle])
            newm = sorted(new[rle])
            masses_diff = [abs(o-n) for o,n in zip(oldm,newm)]
            mmd = max(masses_diff)
            if mmd > max_mass_diff_seen:
                max_mass_diff_seen = mmd
            if mmd > max_mass_diff:
                r,l,e = rle
                to_print.append((mmd, '%6s%6s%14s%14s%14s%25s%25s%10s' % (old_json.contains((r,l)), new_json.contains((r,l)), r,l,e, m2s(old[rle]), m2s(new[rle]), m2s(mmd))))
    to_print.sort(key=lambda x: x[0], reverse=True)
    for p in to_print:
        print p[1]
    print 'max mass diff seen: %.5f' % max_mass_diff_seen
    print
    print 'symmetric difference:'
    print '%6s%6s%14s%14s%14s%25s%25s' % ('ojs','njs','run','lumi','event','old','new')
    for rle in sorted(oldk.symmetric_difference(newk)):
        r,l,e = rle
        mold = max(old[rle] + [0])
        mnew = max(new[rle] + [0])
        #if not (mold > 300 or mnew > 300):
        #    continue
        if skip_understood_events and not old_json.contains((r,l)) and new_json.contains((r,l)):
            continue # skip events where it's just because we didn't run on it before
        print '%6s%6s%14s%14s%14s%25s%25s' % (old_json.contains((r,l)), new_json.contains((r,l)), r,l,e, m2s(old[rle]), m2s(new[rle]))
예제 #8
0
    runs = hlt_data.keys()
    runs.sort()

    hlt_menu_runs = {}

    hlt_paths = {}

    lowest_l1_prescales = {}
    print "loaded all data, starting processing runs"
    start_time = timer()
    nr_runs = len(runs)
    for run_indx,run in enumerate(runs):
        print "processing run {} {} / {} time: {:.1f}s".format(run,run_indx,nr_runs,timer()-start_time)
        if int(run) < args.min_runnr or int(run) > args.max_runnr: continue
            
        if not good_lumis.contains(int(run)): continue
        run_hlt_data = hlt_data[run]
        hlt_menu = run_hlt_data["hlt_menu"]
        trig_mode = run_hlt_data["trig_mode"]

        l1_ps_tbl = l1_ps_data[trig_mode]
        hlt_ps_tbl = hlt_ps_data[hlt_menu]
        hlt_ps_dict = make_hlt_ps_dict(hlt_ps_tbl)
        
        if trig_mode not in lowest_l1_prescales:
            lowest_l1_prescales[trig_mode] = L1PreScaleCache(get_nr_ps_col(l1_ps_tbl))
        runs_lowest_l1_ps = lowest_l1_prescales[trig_mode]
        

        good_lumis_compact = good_lumis.getCompactList()[run]
        good_lumis_unpacked = uncompact_list(good_lumis_compact)
예제 #9
0
        'electrons':                 {'type':'vector<pat::Electron>', 'label':("slimmedElectrons")},
        'photons':                   {'type':'vector<pat::Photon>', 'label':("slimmedPhotons")},
    #    'electronsBeforeGSFix':      {'type':'vector<pat::Electron>', 'label':("slimmedElectronsBeforeGSFix")},
    #    'photonsBeforeGSFix':        {'type':'vector<pat::Photon>', 'label':("slimmedPhotonsBeforeGSFix")},
        }

    r = sample.fwliteReader( products = products )

    r.start()
    runs = set()
    position_r = {}
    count=0

    while r.run( ):
        if max_events is not None and max_events>0 and count>=max_events:break
        if sample.isData and ( not lumiList.contains(r.evt[0], r.evt[1])) : continue
            
        electrons = [ e for e in r.products['electrons'] if e.energy()>50 ]
        photons   = [ p for p in r.products['photons'] if p.energy()>100 ]
        for e in electrons:

            if abs(e.eta())<1.3 : continue
            if not e.electronID("cutBasedElectronID-Spring15-25ns-V1-standalone-tight"): continue 

            e_sc = {'eta':e.superCluster().eta(), 'phi':e.superCluster().phi()}

            for p in photons:
                p_sc = {'eta':p.superCluster().eta(), 'phi':p.superCluster().phi()}
                if helpers.deltaR2(e_sc, p_sc) == 0.:
                    gOverE[sample.name].Fill( p.pt(), p.pt()/e.pt() )
                    gOverE_2D[sample.name].Fill( p.pt(), p.pt()/e.pt() )
예제 #10
0
class JSONAnalyzer(Analyzer):
    '''Apply a json filter, and creates an RLTInfo TTree.
    See PhysicsTools.HeppyCore.utils.RLTInfo for more information

    example:
    
    jsonFilter = cfg.Analyzer(
      "JSONAnalyzer",
      )

    The path of the json file to be used is set as a component attribute.

    The process function returns:
      - True if
         - the component is MC or
         - if the run/lumi pair is in the JSON file
         - if the json file was not set for this component
      - False if the component is MC or embed (for H->tau tau),
          and if the run/lumi pair is not in the JSON file.

    If the option "passAll" is specified and set to True, all events will be selected and a flag event.json is set with the value of the filter
    '''
    def __init__(self, cfg_ana, cfg_comp, looperName):
        super(JSONAnalyzer, self).__init__(cfg_ana, cfg_comp, looperName)
        if not cfg_comp.isMC:
            if self.cfg_comp.json is None and hasattr(self.cfg_ana,
                                                      "json") == False:
                raise ValueError(
                    'component {cname} is not MC, and contains no JSON file. Either remove the JSONAnalyzer for your path or set the "json" attribute of this component'
                    .format(cname=cfg_comp.name))
#use json from this analyzer if given, otherwise use the component json
            self.lumiList = LumiList(
                os.path.expandvars(
                    getattr(self.cfg_ana, "json", self.cfg_comp.json)))
        else:
            self.lumiList = None
        self.passAll = getattr(self.cfg_ana, 'passAll', False)
        self.useLumiBlocks = self.cfg_ana.useLumiBlocks if (hasattr(
            self.cfg_ana, 'useLumiBlocks')) else False

        self.rltInfo = RLTInfo()

    def beginLoop(self, setup):
        super(JSONAnalyzer, self).beginLoop(setup)
        self.counters.addCounter('JSON')
        self.count = self.counters.counter('JSON')
        self.count.register('All Events')
        self.count.register('Passed Events')

        if self.useLumiBlocks and not self.cfg_comp.isMC and not self.lumiList is None:
            lumis = Lumis(self.cfg_comp.files)
            for lumi in lumis:
                lumiid = lumi.luminosityBlockAuxiliary().id()
                run, lumi = lumiid.run(), lumiid.luminosityBlock()
                if self.lumiList.contains(run, lumi):
                    self.rltInfo.add('dummy', run, lumi)

    def process(self, event):
        self.readCollections(event.input)
        evid = event.input.eventAuxiliary().id()
        run = evid.run()
        lumi = evid.luminosityBlock()
        eventId = evid.event()

        event.run = run
        event.lumi = lumi
        event.eventId = eventId

        if self.cfg_comp.isMC:
            return True

        if self.lumiList is None:
            return True

        self.count.inc('All Events')
        sel = self.lumiList.contains(run, lumi)
        setattr(event, "json" + getattr(self.cfg_ana, "suffix", ""), sel)
        if sel:
            self.count.inc('Passed Events')
            if not self.useLumiBlocks:
                self.rltInfo.add('dummy', run, lumi)
            return True
        else:
            return self.passAll

    def write(self, setup):
        super(JSONAnalyzer, self).write(setup)
        self.rltInfo.write(self.dirName)
예제 #11
0
def doit2(skip_understood_events=False, max_mass_diff=0.1, use_jsons=True):
    old = doit('data/Run2011MuonsOnly/ana_datamc_data.root', 'dil_mass',
               'SimpleNtupler', 't', 'OurSelNewNoSign && SameSign')
    new = doit('m10t/ntuple_SingleMuRun2011.root', 'mass', 'SameSign', 't', '')
    #old = doit('mc/ana_datamc_ttbar.root',  'dil_mass', 'SimpleNtupler', 't', 'OurSelNewNoSign && SameSign')
    #new = doit('m10t/ntuple_MC_ttbar.root', 'mass',     'SameSign',       't', '')
    #use_jsons = False

    if use_jsons:
        old_json = LumiList(
            'data/Run2011MuonsOnly/ana_datamc_data.forlumi.json')
        new_json = LumiList('m10t/ntuple_SingleMuRun2011.report.json')
    else:

        class dummy:
            def contains(*args):
                return 'N/A'

        old_json = new_json = dummy()

    oldk = set(old.keys())
    newk = set(new.keys())
    max_mass_diff_seen = 0

    print 'counts:\told\tnew'
    print 'events:\t%i\t%i' % (len(oldk), len(newk))
    print
    print 'diffs in dimu counts?'
    print '%6s%6s%14s%14s%14s%25s%25s' % ('ojs', 'njs', 'run', 'lumi', 'event',
                                          'old', 'new')
    for rle in sorted(oldk & newk):
        if len(old[rle]) != len(new[rle]):
            r, l, e = rle
            print '%6s%6s%14s%14s%14s%25s%25s' % (old_json.contains(
                (r, l)), new_json.contains(
                    (r, l)), r, l, e, m2s(old[rle]), m2s(new[rle]))
    print
    print 'mass comparison:'
    print '%6s%6s%14s%14s%14s%25s%25s%10s' % ('ojs', 'njs', 'run', 'lumi',
                                              'event', 'old', 'new', 'maxd')
    to_print = []
    for rle in sorted(oldk & newk):
        if len(old[rle]) == len(new[rle]):
            if len(old[rle]) > 1:
                print '***\nwarning: more than one dilepton in mass comparison, just dumbly sorting\n***'
            oldm = sorted(old[rle])
            newm = sorted(new[rle])
            masses_diff = [abs(o - n) for o, n in zip(oldm, newm)]
            mmd = max(masses_diff)
            if mmd > max_mass_diff_seen:
                max_mass_diff_seen = mmd
            if mmd > max_mass_diff:
                r, l, e = rle
                to_print.append(
                    (mmd,
                     '%6s%6s%14s%14s%14s%25s%25s%10s' % (old_json.contains(
                         (r, l)), new_json.contains(
                             (r, l)), r, l, e, m2s(old[rle]), m2s(
                                 new[rle]), m2s(mmd))))
    to_print.sort(key=lambda x: x[0], reverse=True)
    for p in to_print:
        print p[1]
    print 'max mass diff seen: %.5f' % max_mass_diff_seen
    print
    print 'symmetric difference:'
    print '%6s%6s%14s%14s%14s%25s%25s' % ('ojs', 'njs', 'run', 'lumi', 'event',
                                          'old', 'new')
    for rle in sorted(oldk.symmetric_difference(newk)):
        r, l, e = rle
        mold = max(old[rle] + [0])
        mnew = max(new[rle] + [0])
        #if not (mold > 300 or mnew > 300):
        #    continue
        if skip_understood_events and not old_json.contains(
            (r, l)) and new_json.contains((r, l)):
            continue  # skip events where it's just because we didn't run on it before
        print '%6s%6s%14s%14s%14s%25s%25s' % (old_json.contains(
            (r, l)), new_json.contains(
                (r, l)), r, l, e, m2s(old[rle]), m2s(new[rle]))
예제 #12
0
파일: makeMap.py 프로젝트: zwimpee/EFlow
        print options.prefix+aline

lumis = Lumis(fullpath_files)

handlePhiSymInfo  = Handle ("std::vector<PhiSymInfo>")
labelPhiSymInfo = ("PhiSymProducer")

timeMap={}

lumiList = LumiList(os.path.expandvars(options.jsonFile))

for i,lumi in enumerate(lumis):
    lumi.getByLabel (labelPhiSymInfo,handlePhiSymInfo)
    phiSymInfo = handlePhiSymInfo.product()
    #skipping BAD lumiSections
    if not lumiList.contains(phiSymInfo.back().getStartLumi().run(),phiSymInfo.back().getStartLumi().luminosityBlock()):
        continue

    beginTime=lumi.luminosityBlockAuxiliary().beginTime().unixTime()
    timeMap[beginTime]={"run":phiSymInfo.back().getStartLumi().run(),"lumi":phiSymInfo.back().getStartLumi().luminosityBlock(),"totHitsEB":phiSymInfo.back().GetTotHitsEB()}

    if options.debug:
        print "====>"
        print "Run "+str(phiSymInfo.back().getStartLumi().run())+" Lumi "+str(phiSymInfo.back().getStartLumi().luminosityBlock())+" beginTime "+str(beginTime)
        print "NEvents in this LS "+str(phiSymInfo.back().GetNEvents())
        print "TotHits EB "+str(phiSymInfo.back().GetTotHitsEB())+" Avg occ EB "+str(float(phiSymInfo.back().GetTotHitsEB())/phiSymInfo.back().GetNEvents()) 
        print "TotHits EE "+str(phiSymInfo.back().GetTotHitsEE())+" Avg occ EE "+str(float(phiSymInfo.back().GetTotHitsEE())/phiSymInfo.back().GetNEvents()) 


nMaxHits=options.maxHit
maxStopTime=options.maxTime
예제 #13
0
        print options.prefix+aline

lumis = Lumis(fullpath_files)

handlePhiSymInfo  = Handle ("std::vector<PhiSymInfo>")
labelPhiSymInfo = ("PhiSymProducer")

timeMap={}

lumiList = LumiList(os.path.expandvars(options.jsonFile))

for i,lumi in enumerate(lumis):
    lumi.getByLabel (labelPhiSymInfo,handlePhiSymInfo)
    phiSymInfo = handlePhiSymInfo.product()
    #skipping BAD lumiSections
    if not lumiList.contains(phiSymInfo.back().getStartLumi().run(),phiSymInfo.back().getStartLumi().luminosityBlock()):
        continue

    beginTime=lumi.luminosityBlockAuxiliary().beginTime().unixTime()
    timeMap[beginTime]={"run":phiSymInfo.back().getStartLumi().run(),"lumi":phiSymInfo.back().getStartLumi().luminosityBlock(),"totHitsEB":phiSymInfo.back().GetTotHitsEB()}

    if options.debug:
        print "====>"
        print "Run "+str(phiSymInfo.back().getStartLumi().run())+" Lumi "+str(phiSymInfo.back().getStartLumi().luminosityBlock())+" beginTime "+str(beginTime)
        print "NEvents in this LS "+str(phiSymInfo.back().GetNEvents())
        print "TotHits EB "+str(phiSymInfo.back().GetTotHitsEB())+" Avg occ EB "+str(float(phiSymInfo.back().GetTotHitsEB())/phiSymInfo.back().GetNEvents()) 
        print "TotHits EE "+str(phiSymInfo.back().GetTotHitsEE())+" Avg occ EE "+str(float(phiSymInfo.back().GetTotHitsEE())/phiSymInfo.back().GetNEvents()) 


nMaxHits=options.maxHit
maxStopTime=options.maxTime
예제 #14
0
        'electrons':                 {'type':'vector<pat::Electron>', 'label':("slimmedElectrons")},
        'photons':                   {'type':'vector<pat::Photon>', 'label':("slimmedPhotons")},
    #    'electronsBeforeGSFix':      {'type':'vector<pat::Electron>', 'label':("slimmedElectronsBeforeGSFix")},
    #    'photonsBeforeGSFix':        {'type':'vector<pat::Photon>', 'label':("slimmedPhotonsBeforeGSFix")},
        }

    r = sample.fwliteReader( products = products )

    r.start()
    runs = set()
    position_r = {}
    count=0

    while r.run( ):
        if max_events is not None and max_events>0 and count>=max_events:break
        if sample.isData and ( not lumiList.contains(r.evt[0], r.evt[1])) : continue
            
        electrons = [ e for e in r.products['electrons'] if e.energy()>50 ]
        photons   = [ p for p in r.products['photons'] if p.energy()>100 ]
        for e in electrons:

            if abs(e.eta())<1.3 : continue
            if not e.electronID("cutBasedElectronID-Spring15-25ns-V1-standalone-tight"): continue 

            e_sc = {'eta':e.superCluster().eta(), 'phi':e.superCluster().phi()}

            for p in photons:
                p_sc = {'eta':p.superCluster().eta(), 'phi':p.superCluster().phi()}
                if helpers.deltaR2(e_sc, p_sc) == 0.:
                    gOverE[sample.name].Fill( p.pt(), p.pt()/e.pt() )
                    gOverE_2D[sample.name].Fill( p.pt(), p.pt()/e.pt() )
예제 #15
0
class JSONAnalyzer( Analyzer ):
    '''Apply a json filter, and creates an RLTInfo TTree.
    See PhysicsTools.HeppyCore.utils.RLTInfo for more information

    example:
    
    jsonFilter = cfg.Analyzer(
      "JSONAnalyzer",
      )

    The path of the json file to be used is set as a component attribute.

    The process function returns:
      - True if
         - the component is MC or
         - if the run/lumi pair is in the JSON file
         - if the json file was not set for this component
      - False if the component is MC or embed (for H->tau tau),
          and if the run/lumi pair is not in the JSON file.

    If the option "passAll" is specified and set to True, all events will be selected and a flag event.json is set with the value of the filter
    '''

    def __init__(self, cfg_ana, cfg_comp, looperName):
        super(JSONAnalyzer, self).__init__(cfg_ana, cfg_comp, looperName)
        if not cfg_comp.isMC:
            if self.cfg_comp.json is None and hasattr(self.cfg_ana,"json") == False :
                raise ValueError('component {cname} is not MC, and contains no JSON file. Either remove the JSONAnalyzer for your path or set the "json" attribute of this component'.format(cname=cfg_comp.name))
	    #use json from this analyzer if given, otherwise use the component json 
            self.lumiList = LumiList(os.path.expandvars(getattr(self.cfg_ana,"json",self.cfg_comp.json)))
        else:
            self.lumiList = None
        self.passAll = getattr(self.cfg_ana,'passAll',False)
        self.useLumiBlocks = self.cfg_ana.useLumiBlocks if (hasattr(self.cfg_ana,'useLumiBlocks')) else False

        self.rltInfo = RLTInfo()

    def beginLoop(self, setup):
        super(JSONAnalyzer,self).beginLoop(setup)
        self.counters.addCounter('JSON')
        self.count = self.counters.counter('JSON')
        self.count.register('All Events')
        self.count.register('Passed Events')

        if self.useLumiBlocks and not self.cfg_comp.isMC and not self.lumiList is None:
            lumis = Lumis(self.cfg_comp.files)
            for lumi in lumis:
                lumiid = lumi.luminosityBlockAuxiliary().id()
                run, lumi = lumiid.run(), lumiid.luminosityBlock()
                if self.lumiList.contains(run,lumi):
                    self.rltInfo.add('dummy', run, lumi)
            

    def process(self, event):
        self.readCollections( event.input )
        evid = event.input.eventAuxiliary().id()
        run = evid.run()
        lumi = evid.luminosityBlock()
        eventId = evid.event()

        event.run = run
        event.lumi = lumi
        event.eventId = eventId

        if self.cfg_comp.isMC:
            return True

        if self.lumiList is None:
            return True

        self.count.inc('All Events')
        sel = self.lumiList.contains(run,lumi)
        setattr(event,"json"+getattr(self.cfg_ana,"suffix",""), sel)
        if sel :
            self.count.inc('Passed Events')
            if not self.useLumiBlocks:
                self.rltInfo.add('dummy', run, lumi)
            return True
        else:
            return self.passAll
        

    def write(self, setup):
        super(JSONAnalyzer, self).write(setup)
        self.rltInfo.write( self.dirName )
예제 #16
0

reader.start()
maker.start()

counter_read = -1
counter_write = -1

while reader.run():
    counter_read += 1
    if counter_read % 100 == 0: logger.info("Reading event %i.", counter_read)

    maker.event.run, maker.event.lumi, maker.event.evt = reader.evt

    # json
    if lumiList is not None and not lumiList.contains(maker.event.run,
                                                      maker.event.lumi):
        continue

    # muons in acceptance
    accepted_muons = filter(lambda p: p.pt() > 15 and abs(p.eta()) < 2.4,
                            reader.products['muon'])

    # good and veto muons (CutBasedIdMediumPrompt = CutBasedIdMedium +  and dz<0.1 and dxy< 0.02 )
    good_muons = filter(
        lambda p: p.CutBasedIdMediumPrompt and relIso03(p) < 0.12 and abs(
            p.dB(ROOT.pat.Muon.PV3D) / p.edB(ROOT.pat.Muon.PV3D)) < 4,
        accepted_muons)
    #good_muons = filter( lambda p: p.CutBasedIdMediumPrompt and relIso03(p)<0.2, accepted_muons )
    veto_muons = filter(lambda p: relIso03(p) < 0.4 and p not in good_muons,
                        accepted_muons)
예제 #17
0
class JSONAnalyzer( Analyzer ):
    '''Apply a json filter, and creates an RLTInfo TTree.
    See CMGTools.RootTools.utils.RLTInfo for more information

    example:
    
    jsonFilter = cfg.Analyzer(
      "JSONAnalyzer",
      )

    The path of the json file to be used is set as a component attribute.

    The process function returns:
      - True if
         - the component is MC or
         - if the run/lumi pair is in the JSON file
         - if the json file was not set for this component
      - False if the component is MC or embed (for H->tau tau),
          and if the run/lumi pair is not in the JSON file.
    '''

    def __init__(self, cfg_ana, cfg_comp, looperName):
        super(JSONAnalyzer, self).__init__(cfg_ana, cfg_comp, looperName)
        if not cfg_comp.isMC:
            self.lumiList = LumiList(self.cfg_comp.json)
        else:
            self.lumiList = None
        

        self.rltInfo = RLTInfo()


    def beginLoop(self):
        super(JSONAnalyzer,self).beginLoop()
        self.counters.addCounter('JSON')
        self.count = self.counters.counter('JSON')
        self.count.register('All Lumis')
        self.count.register('Passed Lumis')

    def process(self, iEvent, event):
        self.readCollections( iEvent )
        run = iEvent.eventAuxiliary().id().run()
        lumi = iEvent.eventAuxiliary().id().luminosityBlock()
        eventId = iEvent.eventAuxiliary().id().event()

        event.run = run
        event.lumi = lumi
        event.eventId = eventId

        if self.cfg_comp.isMC:
            return True

        if self.lumiList is None:
            return True

        self.count.inc('All Lumis')
        if self.lumiList.contains(run,lumi):
            self.count.inc('Passed Lumis')
            self.rltInfo.add('dummy', run, lumi)
            return True
        else:
            return False
        

    def write(self):
        super(JSONAnalyzer, self).write()
        self.rltInfo.write( self.dirName )