本文整理汇总了Python中FWCore.PythonUtilities.LumiList.LumiList.contains方法的典型用法代码示例。如果您正苦于以下问题:Python LumiList.contains方法的具体用法?Python LumiList.contains怎么用?Python LumiList.contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FWCore.PythonUtilities.LumiList.LumiList
的用法示例。
在下文中一共展示了LumiList.contains方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: files_for_events
# 需要导入模块: from FWCore.PythonUtilities.LumiList import LumiList [as 别名]
# 或者: from FWCore.PythonUtilities.LumiList.LumiList import contains [as 别名]
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)
示例2: JSONAnalyzer
# 需要导入模块: from FWCore.PythonUtilities.LumiList import LumiList [as 别名]
# 或者: from FWCore.PythonUtilities.LumiList.LumiList import contains [as 别名]
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 )
示例3: return
# 需要导入模块: from FWCore.PythonUtilities.LumiList import LumiList [as 别名]
# 或者: from FWCore.PythonUtilities.LumiList.LumiList import contains [as 别名]
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
示例4: doit2
# 需要导入模块: from FWCore.PythonUtilities.LumiList import LumiList [as 别名]
# 或者: from FWCore.PythonUtilities.LumiList.LumiList import contains [as 别名]
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]))
示例5: Lumis
# 需要导入模块: from FWCore.PythonUtilities.LumiList import LumiList [as 别名]
# 或者: from FWCore.PythonUtilities.LumiList.LumiList import contains [as 别名]
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
示例6: set
# 需要导入模块: from FWCore.PythonUtilities.LumiList import LumiList [as 别名]
# 或者: from FWCore.PythonUtilities.LumiList.LumiList import contains [as 别名]
'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() )
示例7: JSONAnalyzer
# 需要导入模块: from FWCore.PythonUtilities.LumiList import LumiList [as 别名]
# 或者: from FWCore.PythonUtilities.LumiList.LumiList import contains [as 别名]
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 )
示例8: JSONAnalyzer
# 需要导入模块: from FWCore.PythonUtilities.LumiList import LumiList [as 别名]
# 或者: from FWCore.PythonUtilities.LumiList.LumiList import contains [as 别名]
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 )
示例9: Lumis
# 需要导入模块: from FWCore.PythonUtilities.LumiList import LumiList [as 别名]
# 或者: from FWCore.PythonUtilities.LumiList.LumiList import contains [as 别名]
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()