File indexing completed on 2024-11-25 02:29:50
0001 import os
0002 import PhysicsTools.HeppyCore.framework.config as cfg
0003 from PhysicsTools.Heppy.utils.miniAodFiles import miniAodFiles
0004
0005
0006 multi_thread = False
0007
0008
0009
0010
0011 inputSample = cfg.MCComponent(
0012 'test_component',
0013 files = miniAodFiles(),
0014
0015 )
0016
0017 if 'RelValZMM' not in inputSample.files[0]:
0018 print('''WARNING: this tutorial is supposed to run on Z->mumu events.
0019 Do not expect meaningful results for this sample:''')
0020 print(inputSample)
0021
0022 if multi_thread:
0023 inputSample.splitFactor = len(inputSample.files)
0024
0025 selectedComponents = [inputSample]
0026
0027
0028
0029 from PhysicsTools.Heppy.analyzers.examples.SimpleMuonAnalyzer import SimpleMuonAnalyzer
0030 muons = cfg.Analyzer(
0031 SimpleMuonAnalyzer,
0032 'muons',
0033 )
0034
0035 from PhysicsTools.Heppy.analyzers.examples.ResonanceBuilder import ResonanceBuilder
0036 dimuons = cfg.Analyzer(
0037 ResonanceBuilder,
0038 'dimuons',
0039 leg_collection = 'muons',
0040 filter_func = lambda x : True,
0041 pdgid = 23
0042 )
0043
0044
0045
0046
0047 from PhysicsTools.Heppy.analyzers.examples.SimpleJetAnalyzer import SimpleJetAnalyzer
0048 all_jets = cfg.Analyzer(
0049 SimpleJetAnalyzer,
0050 'all_jets',
0051 njets = 4,
0052 filter_func = lambda x : True
0053 )
0054
0055
0056
0057 from PhysicsTools.HeppyCore.analyzers.Filter import Filter
0058 sel_jets = cfg.Analyzer(
0059 Filter,
0060 'jets',
0061 input_objects = 'all_jets',
0062 filter_func = lambda x : x.pt()>30
0063 )
0064
0065
0066
0067 from PhysicsTools.Heppy.analyzers.examples.ZJetsTreeAnalyzer import ZJetsTreeAnalyzer
0068 tree = cfg.Analyzer(
0069 ZJetsTreeAnalyzer
0070 )
0071
0072
0073
0074
0075 sequence = cfg.Sequence( [
0076 muons,
0077 dimuons,
0078 all_jets,
0079 sel_jets,
0080 tree
0081 ] )
0082
0083
0084 from PhysicsTools.HeppyCore.framework.eventsfwlite import Events
0085 config = cfg.Config( components = selectedComponents,
0086 sequence = sequence,
0087 services = [],
0088 events_class = Events)
0089
0090 print(config)
0091
0092 if __name__ == '__main__':
0093
0094
0095
0096
0097
0098
0099 from PhysicsTools.Heppy.physicsutils.LorentzVectors import LorentzVector
0100
0101 from PhysicsTools.HeppyCore.framework.looper import Looper
0102 looper = Looper( 'Loop', config, nPrint = 5, nEvents=100)
0103 looper.loop()
0104 looper.write()
0105
0106
0107 print(looper.event)
0108 pz = LorentzVector()
0109 for imu, mu in enumerate(looper.event.muons):
0110 print('muon1', mu, 'abs iso=', mu.relIso()*mu.pt())
0111 pz += mu.p4()
0112 print('z candidate mass = ', pz.M())
0113
0114
0115
0116
0117
0118
0119 def next():
0120 looper.process(looper.event.iEv+1)