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