Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:32:31

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                 #read product of preprocessor-cmsRun
0030                 "jetsAK5"       : ( AutoHandle( ("ak5PFJetsCHS",), "std::vector<reco::PFJet>" ),
0031                                   NTupleCollection("JetAk5",     particleType, 8, help="AK5 jets")),
0032 
0033         #standard dumping of objects
0034             "selectedLeptons" : NTupleCollection("leptons", leptonType, 8, help="Leptons after the preselection"),
0035                 "selectedTaus"    : NTupleCollection("TauGood", tauType, 3, help="Taus after the preselection"),
0036             "cleanJets"       : NTupleCollection("Jet",     jetType, 8, help="Cental jets after full selection and cleaning, sorted by b-tag"),
0037         #dump of gen objects
0038                 "gentopquarks"    : NTupleCollection("GenTop",     genParticleType, 2, help="Generated top quarks from hard scattering"),
0039                 "genbquarks"      : NTupleCollection("GenBQuark",  genParticleType, 2, help="Generated bottom quarks from top quark decays"),
0040                 "genwzquarks"     : NTupleCollection("GenQuark",   genParticleType, 6, help="Generated quarks from W/Z decays"),
0041                 "genleps"         : NTupleCollection("GenLep",     genParticleType, 6, help="Generated leptons from W/Z decays"),
0042                 "gentauleps"      : NTupleCollection("GenLepFromTau", genParticleType, 6, help="Generated leptons from decays of taus from W/Z/h decays"),
0043 
0044     }
0045     )
0046 
0047 # Import standard analyzers and take their default config
0048 from PhysicsTools.Heppy.analyzers.objects.LeptonAnalyzer import LeptonAnalyzer
0049 LepAna = LeptonAnalyzer.defaultConfig
0050 from PhysicsTools.Heppy.analyzers.objects.VertexAnalyzer import VertexAnalyzer
0051 VertexAna = VertexAnalyzer.defaultConfig
0052 from PhysicsTools.Heppy.analyzers.objects.PhotonAnalyzer import PhotonAnalyzer
0053 PhoAna = PhotonAnalyzer.defaultConfig
0054 from PhysicsTools.Heppy.analyzers.objects.TauAnalyzer import TauAnalyzer
0055 TauAna = TauAnalyzer.defaultConfig
0056 from PhysicsTools.Heppy.analyzers.objects.JetAnalyzer import JetAnalyzer
0057 JetAna = JetAnalyzer.defaultConfig
0058 from PhysicsTools.Heppy.analyzers.gen.LHEAnalyzer import LHEAnalyzer 
0059 LHEAna = LHEAnalyzer.defaultConfig
0060 from PhysicsTools.Heppy.analyzers.gen.GeneratorAnalyzer import GeneratorAnalyzer 
0061 GenAna = GeneratorAnalyzer.defaultConfig
0062 from PhysicsTools.Heppy.analyzers.objects.METAnalyzer import METAnalyzer
0063 METAna = METAnalyzer.defaultConfig
0064 from PhysicsTools.Heppy.analyzers.core.PileUpAnalyzer import PileUpAnalyzer
0065 PUAna = PileUpAnalyzer.defaultConfig
0066 from PhysicsTools.Heppy.analyzers.core.TriggerBitAnalyzer import TriggerBitAnalyzer
0067 FlagsAna = TriggerBitAnalyzer.defaultEventFlagsConfig
0068 
0069 # Configure trigger bit analyzer
0070 from PhysicsTools.Heppy.analyzers.core.TriggerBitAnalyzer import TriggerBitAnalyzer
0071 TrigAna= cfg.Analyzer(
0072     verbose=False,
0073     class_object=TriggerBitAnalyzer,
0074     #grouping several paths into a single flag
0075     # v* can be used to ignore the version of a path
0076     triggerBits={
0077     'ELE':["HLT_Ele23_Ele12_CaloId_TrackId_Iso_v*","HLT_Ele32_eta2p1_WP85_Gsf_v*","HLT_Ele32_eta2p1_WP85_Gsf_v*"],
0078     'MU': ["HLT_Mu17_TrkIsoVVL_TkMu8_TrkIsoVVL_v*","HLT_Mu17_TrkIsoVVL_Mu8_TrkIsoVVL_v*","HLT_IsoTkMu24_eta2p1_IterTrk02_v*","HLT_IsoTkMu24_IterTrk02_v*"],
0079     },
0080 #   processName='HLT',
0081 #   outprefix='HLT'
0082     #setting 'unrollbits' to true will not only store the OR for each set of trigger bits but also the individual bits
0083     #caveat: this does not unroll the version numbers
0084     unrollbits=True 
0085     )
0086 
0087 
0088 
0089 #replace some parameters
0090 LepAna.loose_muon_pt = 10
0091 
0092 sequence = [LHEAna,FlagsAna, GenAna, PUAna,TrigAna,VertexAna,LepAna,TauAna,PhoAna,JetAna,METAna,treeProducer]
0093 
0094 #use tfile service to provide a single TFile to all modules where they
0095 #can write any root object. If the name is 'outputfile' or the one specified in treeProducer
0096 #also the treeProducer uses this file
0097 from PhysicsTools.HeppyCore.framework.services.tfile import TFileService 
0098 output_service = cfg.Service(
0099       TFileService,
0100       'outputfile',
0101       name="outputfile",
0102       fname='tree.root',
0103       option='recreate'
0104     )
0105 
0106 # the following two lines are just for automatic testing
0107 # they are not needed for running on your own samples
0108 from PhysicsTools.Heppy.utils.miniAodFiles import miniAodFiles
0109 testfiles=miniAodFiles()
0110 
0111 sample = cfg.Component(
0112 #specify the file you want to run on
0113 #    files = ["/scratch/arizzi/Hbb/CMSSW_7_2_2_patch2/src/VHbbAnalysis/Heppy/test/ZLL-8A345C56-6665-E411-9C25-1CC1DE04DF20.root"],
0114     files = testfiles,
0115     name="SingleSample", isMC=False,isEmbed=False
0116     )
0117 
0118 from PhysicsTools.Heppy.utils.cmsswPreprocessor import CmsswPreprocessor
0119 preprocessor = CmsswPreprocessor("makeAK5Jets.py")
0120 
0121 # the following is declared in case this cfg is used in input to the heppy.py script
0122 from PhysicsTools.HeppyCore.framework.eventsfwlite import Events
0123 selectedComponents = [sample]
0124 config = cfg.Config( components = selectedComponents,
0125                      sequence = sequence,
0126                      services = [output_service],  
0127                      preprocessor=preprocessor, #this would run cmsRun makeAK5Jets.py before running Heppy
0128                      events_class = Events)
0129 
0130 # and the following runs the process directly if running as with python filename.py  
0131 if __name__ == '__main__':
0132     from PhysicsTools.HeppyCore.framework.looper import Looper 
0133     looper = Looper( 'Loop', config, nPrint = 5,nEvents=300) 
0134     looper.loop()
0135     looper.write()