Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:29

0001 #! /usr/bin/env python
0002 import ROOT
0003 import PhysicsTools.HeppyCore.framework.config as cfg
0004 
0005 # The content of the output tree is defined here
0006 # the definitions of the NtupleObjects are located under PhysicsTools/Heppy/pythonanalyzers/objects/autophobj.py
0007  
0008 from PhysicsTools.Heppy.analyzers.core.AutoFillTreeProducer  import * 
0009 treeProducer= cfg.Analyzer(
0010     class_object=AutoFillTreeProducer, 
0011     verbose=False, 
0012     vectorTree = True,
0013         #here the list of simple event variables (floats, int) can be specified
0014         globalVariables = [
0015              NTupleVariable("rho",  lambda ev: ev.rho, float, help="jets rho"),
0016         ],
0017         #here one can specify compound objects 
0018         globalObjects = {
0019           "met"    : NTupleObject("met",     metType, help="PF E_{T}^{miss}, after default type 1 corrections"),
0020         },
0021     collections = {
0022         #The following would just store the electrons and muons from miniaod without any selection or cleaning
0023                 # only the basice particle information is saved
0024         #"slimmedMuons" : ( AutoHandle( ("slimmedMuons",), "std::vector<pat::Muon>" ),
0025                 #           NTupleCollection("mu", particleType, 4, help="patMuons, directly from MINIAOD") ),
0026                 #"slimmedElectron" : ( AutoHandle( ("slimmedElectrons",), "std::vector<pat::Electron>" ),
0027                 #           NTupleCollection("ele", particleType, 4, help="patElectron, directly from MINIAOD") ),
0028 
0029         #standard dumping of objects
0030             "selectedLeptons" : NTupleCollection("leptons", leptonType, 8, help="Leptons after the preselection"),
0031                 "selectedTaus"    : NTupleCollection("TauGood", tauType, 3, help="Taus after the preselection"),
0032             "cleanJets"       : NTupleCollection("Jet",     jetType, 8, help="Cental jets after full selection and cleaning, sorted by b-tag"),
0033         #dump of gen objects
0034                 "gentopquarks"    : NTupleCollection("GenTop",     genParticleType, 2, help="Generated top quarks from hard scattering"),
0035                 "genbquarks"      : NTupleCollection("GenBQuark",  genParticleType, 2, help="Generated bottom quarks from top quark decays"),
0036                 "genwzquarks"     : NTupleCollection("GenQuark",   genParticleType, 6, help="Generated quarks from W/Z decays"),
0037                 "genleps"         : NTupleCollection("GenLep",     genParticleType, 6, help="Generated leptons from W/Z decays"),
0038                 "gentauleps"      : NTupleCollection("GenLepFromTau", genParticleType, 6, help="Generated leptons from decays of taus from W/Z/h decays"),
0039 
0040     }
0041     )
0042 
0043 # Import standard analyzers and take their default config
0044 from PhysicsTools.Heppy.analyzers.objects.LeptonAnalyzer import LeptonAnalyzer
0045 LepAna = LeptonAnalyzer.defaultConfig
0046 from PhysicsTools.Heppy.analyzers.objects.VertexAnalyzer import VertexAnalyzer
0047 VertexAna = VertexAnalyzer.defaultConfig
0048 from PhysicsTools.Heppy.analyzers.objects.PhotonAnalyzer import PhotonAnalyzer
0049 PhoAna = PhotonAnalyzer.defaultConfig
0050 from PhysicsTools.Heppy.analyzers.objects.TauAnalyzer import TauAnalyzer
0051 TauAna = TauAnalyzer.defaultConfig
0052 from PhysicsTools.Heppy.analyzers.objects.JetAnalyzer import JetAnalyzer
0053 JetAna = JetAnalyzer.defaultConfig
0054 from PhysicsTools.Heppy.analyzers.gen.LHEAnalyzer import LHEAnalyzer 
0055 LHEAna = LHEAnalyzer.defaultConfig
0056 from PhysicsTools.Heppy.analyzers.gen.GeneratorAnalyzer import GeneratorAnalyzer 
0057 GenAna = GeneratorAnalyzer.defaultConfig
0058 from PhysicsTools.Heppy.analyzers.objects.METAnalyzer import METAnalyzer
0059 METAna = METAnalyzer.defaultConfig
0060 from PhysicsTools.Heppy.analyzers.core.PileUpAnalyzer import PileUpAnalyzer
0061 PUAna = PileUpAnalyzer.defaultConfig
0062 from PhysicsTools.Heppy.analyzers.core.TriggerBitAnalyzer import TriggerBitAnalyzer
0063 FlagsAna = TriggerBitAnalyzer.defaultEventFlagsConfig
0064 
0065 # Configure trigger bit analyzer
0066 from PhysicsTools.Heppy.analyzers.core.TriggerBitAnalyzer import TriggerBitAnalyzer
0067 TrigAna= cfg.Analyzer(
0068     verbose=False,
0069     class_object=TriggerBitAnalyzer,
0070     #grouping several paths into a single flag
0071     # v* can be used to ignore the version of a path
0072     triggerBits={
0073     'ELE':["HLT_Ele23_Ele12_CaloId_TrackId_Iso_v*","HLT_Ele32_eta2p1_WP85_Gsf_v*","HLT_Ele32_eta2p1_WP85_Gsf_v*"],
0074     'MU': ["HLT_Mu17_TrkIsoVVL_TkMu8_TrkIsoVVL_v*","HLT_Mu17_TrkIsoVVL_Mu8_TrkIsoVVL_v*","HLT_IsoTkMu24_eta2p1_IterTrk02_v*","HLT_IsoTkMu24_IterTrk02_v*"],
0075     },
0076 #   processName='HLT',
0077 #   outprefix='HLT'
0078     #setting 'unrollbits' to true will not only store the OR for each set of trigger bits but also the individual bits
0079     #caveat: this does not unroll the version numbers
0080     unrollbits=True 
0081     )
0082 
0083 
0084 
0085 #replace some parameters
0086 LepAna.loose_muon_pt = 10
0087 
0088 sequence = [LHEAna,FlagsAna, GenAna, PUAna,TrigAna,VertexAna,LepAna,TauAna,PhoAna,JetAna,METAna,treeProducer]
0089 
0090 #use tfile service to provide a single TFile to all modules where they
0091 #can write any root object. If the name is 'outputfile' or the one specified in treeProducer
0092 #also the treeProducer uses this file
0093 from PhysicsTools.HeppyCore.framework.services.tfile import TFileService 
0094 output_service = cfg.Service(
0095       TFileService,
0096       'outputfile',
0097       name="outputfile",
0098       fname='tree.root',
0099       option='recreate'
0100     )
0101 
0102 # the following two lines are just for automatic testing
0103 # they are not needed for running on your own samples
0104 from PhysicsTools.Heppy.utils.miniAodFiles import miniAodFiles
0105 testfiles=miniAodFiles()
0106 
0107 sample = cfg.Component(
0108 #specify the file you want to run on
0109     # files = ["/scratch/arizzi/Hbb/CMSSW_7_2_2_patch2/src/VHbbAnalysis/Heppy/test/ZLL-8A345C56-6665-E411-9C25-1CC1DE04DF20.root"],
0110     files = testfiles,
0111     name="SingleSample", isMC=False,isEmbed=False
0112     )
0113 
0114 # the following is declared in case this cfg is used in input to the heppy.py script
0115 from PhysicsTools.HeppyCore.framework.eventsfwlite import Events
0116 selectedComponents = [sample]
0117 config = cfg.Config( components = selectedComponents,
0118                      sequence = sequence,
0119                      services = [output_service],  
0120                      events_class = Events)
0121 
0122 # and the following runs the process directly if running as with python filename.py  
0123 if __name__ == '__main__':
0124     from PhysicsTools.HeppyCore.framework.looper import Looper 
0125     looper = Looper( 'Loop', config, nPrint = 5,nEvents=300) 
0126     looper.loop()
0127     looper.write()