def makeTreeFromPAT(
        process,
        outFileName,
        useCHSJets=True,
        invertLeptonVeto=False,
        NJetsMin=2,
        HTMin=500.,
        MHTMin=200.,
        reportEveryEvt=10,
        Global_Tag="",
        MC=False,
        RecoLeptonStudyBool=False,
        DebugBool=False,
        testFileName=[
            "/store/user/kheine/HT/RA2PreSelectionOnData_Run2012A_HT_PromptReco-v1_v5/71cce229addb17644d40a607fa20b5d7/RA2SkimsOnData_99_3_TPC.root"
        ],
        numProcessedEvt=1000):

    process.load(
        "Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
    process.GlobalTag.globaltag = Global_Tag

    ## --- Log output ------------------------------------------------------
    process.load("FWCore.MessageService.MessageLogger_cfi")
    process.MessageLogger.cerr = cms.untracked.PSet(
        placeholder=cms.untracked.bool(True))
    process.MessageLogger.statistics.append('cout')
    process.MessageLogger.cout = cms.untracked.PSet(INFO=cms.untracked.PSet(
        reportEvery=cms.untracked.int32(reportEveryEvt)))

    ## --- Files to process ------------------------------------------------
    process.maxEvents = cms.untracked.PSet(
        input=cms.untracked.int32(numProcessedEvt))
    process.source = cms.Source("PoolSource",
                                fileNames=cms.untracked.vstring(testFileName))

    hltPath = ['HLT_PFHT350_PFMET100_v*', 'HLT_PFNoPUHT350_PFMET100_v*']
    process.load('HLTrigger.HLTfilters.hltHighLevel_cfi')
    process.hltHighLevel.HLTPaths = cms.vstring(hltPath)
    process.hltHighLevel.andOr = cms.bool(True)
    process.hltHighLevel.throw = cms.bool(False)

    process.HLTSelection = cms.Sequence(process.hltHighLevel)
    if MC:
        print "Running over MC: removing HLT selection"
        process.HLTSelection.remove(process.hltHighLevel)
    elif not hltPath:
        print "Empty list of HLT paths: removing HLT selection"
        process.HLTSelection.remove(process.hltHighLevel)
    ## --- Output file -----------------------------------------------------
    process.TFileService = cms.Service("TFileService",
                                       fileName=cms.string(outFileName +
                                                           ".root"))

    ## --- Selection sequences ---------------------------------------------

    # Filter-related selection
    process.load('RA2Classic.TreeMaker.filterSelection_cff')
    process.load('SandBox.Skims.RA2Leptons_cff')

    process.CleaningSelection = cms.Sequence(process.filterSelection)

    # Filter-related selection
    #    process.load('RA2Classic.TreeMaker.filterSelection_cff')
    #    from RecoMET.METFilters.jetIDFailureFilter_cfi import jetIDFailure
    #    process.PBNRFilter = jetIDFailure.clone(
    #        JetSource = cms.InputTag('MHTJets'),
    #        MinJetPt      = cms.double(30.0),
    #        taggingMode   = cms.bool(False)
    #        )
    #    process.filterSelection += process.PBNRFilter
    #    from RecoMET.METFilters.multiEventFilter_cfi import multiEventFilter
    #    process.HCALLaserEvtFilterList2012 = multiEventFilter.clone(
    #        file        = cms.FileInPath('EventFilter/HcalRawToDigi/data/AllBadHCALLaser.txt'),
    #        taggingMode = cms.bool(False)
    #        )
    #   process.filterSelection += process.HCALLaserEvtFilterList2012

    # Produce RA2 jets
    if useCHSJets:
        process.load('RA2Classic.Utils.produceRA2JetsPFCHS_cff')
        process.ProduceRA2Jets = cms.Sequence(process.produceRA2JetsPFCHS)
    else:
        process.load('RA2Classic.Utils.produceRA2JetsAK5PF_cff')
        process.ProduceRA2Jets = cms.Sequence(process.produceRA2JetsAK5PF)

    # Select events with at least 'NJetsMin' of the above jets
    from PhysicsTools.PatAlgos.selectionLayer1.jetCountFilter_cfi import countPatJets
    process.NumJetSelection = countPatJets.clone(
        src=cms.InputTag('HTJets'), minNumber=cms.uint32(NJetsMin))

    # HT selection
    htInputCol = 'htPF'
    if useCHSJets:
        htInputCol = 'htPFchs'

    from SandBox.Skims.RA2HT_cff import htPFFilter
    process.HTSelection = htPFFilter.clone(HTSource=cms.InputTag(htInputCol),
                                           MinHT=cms.double(HTMin))

    # MHT selection
    mhtMin = 0.
    mhtInputCol = 'mhtPF'
    if useCHSJets:
        mhtInputCol = 'mhtPFchs'

    from SandBox.Skims.RA2MHT_cff import mhtPFFilter
    process.MHTSelection = mhtPFFilter.clone(
        MHTSource=cms.InputTag(mhtInputCol), MinMHT=cms.double(MHTMin))

    ## --- Additional Filters (not tagging mode) ------------------------------
    from RecoMET.METFilters.jetIDFailureFilter_cfi import jetIDFailure
    process.PBNRFilter = jetIDFailure.clone(
        JetSource=cms.InputTag('patJetsPF'),
        MinJetPt=cms.double(30.0),
        taggingMode=cms.bool(False))

    from SandBox.Skims.hoNoiseFilter_cfi import hoNoiseFilter
    process.RA2HoNoiseFitler = hoNoiseFilter.clone(
        patJetsInputTag=cms.InputTag('patJetsPF'))
    from RecoMET.METFilters.multiEventFilter_cfi import multiEventFilter
    process.HCALLaserEvtFilterList2012 = multiEventFilter.clone(
        file=cms.FileInPath(
            'RA2Classic/LostLeptonBkg/data/HCALLaserEventList_20Nov2012-v2_HT-HTMHT.txt'
        ),
        taggingMode=cms.bool(False))

    process.AdditionalFiltersInTagMode = cms.Sequence(process.PBNRFilter)

    FilterNames = cms.VInputTag()
    FilterNames.append(
        cms.InputTag("HBHENoiseFilterRA2", "HBHENoiseFilterResult", "PAT"))
    FilterNames.append(cms.InputTag("beamHaloFilter"))
    FilterNames.append(cms.InputTag("trackingFailureFilter"))
    FilterNames.append(cms.InputTag("inconsistentMuons"))
    FilterNames.append(cms.InputTag("greedyMuons"))
    FilterNames.append(cms.InputTag("ra2EcalTPFilter"))
    FilterNames.append(cms.InputTag("ra2EcalBEFilter"))
    FilterNames.append(cms.InputTag("hcalLaserEventFilter"))
    FilterNames.append(cms.InputTag("ecalLaserCorrFilter"))
    FilterNames.append(cms.InputTag("eeBadScFilter"))
    FilterNames.append(cms.InputTag("PBNRFilter"))
    FilterNames.append(cms.InputTag("HCALLaserEvtFilterList2012"))
    FilterNames.append(cms.InputTag("manystripclus53X"))
    FilterNames.append(cms.InputTag("toomanystripclus53X"))
    FilterNames.append(cms.InputTag("logErrorTooManyClusters"))
    #   FilterNames.append(cms.InputTag("RA2CaloVsPFMHTFilter"))
    FilterNames.append(cms.InputTag("RA2HONoiseFilter"))

    ## --- Setup WeightProducer -------------------------------------------
    from RA2Classic.WeightProducer.getWeightProducer_cff import getWeightProducer
    process.WeightProducer = getWeightProducer(process.source.fileNames[0])

    ## --- Setup of TreeMaker ----------------------------------------------
    FilterNames = cms.VInputTag()  # All filters in AdditionalFiltersInTagMode
    for f in process.AdditionalFiltersInTagMode.moduleNames():
        FilterNames.append(cms.InputTag(f))

##     FilterNames.append(cms.InputTag("HBHENoiseFilterRA2","HBHENoiseFilterResult","PAT"))
##     FilterNames.append(cms.InputTag("beamHaloFilter"))
##     FilterNames.append(cms.InputTag("eeNoiseFilter"))
##     FilterNames.append(cms.InputTag("trackingFailureFilter"))
##     FilterNames.append(cms.InputTag("inconsistentMuons"))
##     FilterNames.append(cms.InputTag("greedyMuons"))
##     FilterNames.append(cms.InputTag("ra2EcalTPFilter"))
##     FilterNames.append(cms.InputTag("ra2EcalBEFilter"))
##     FilterNames.append(cms.InputTag("hcalLaserEventFilter"))
##     FilterNames.append(cms.InputTag("eeBadScFilter"))

    from RA2Classic.TreeMaker.treemaker_cfi import TreeMaker
    process.RA2TreeMaker = TreeMaker.clone(
        TreeName=cms.string("RA2PreSelection"),
        VertexCollection=cms.InputTag('goodVertices'),
        HT=cms.InputTag(htInputCol),
        HTJets=cms.InputTag('HTJets'),
        MHT=cms.InputTag(mhtInputCol),
        MHTJets=cms.InputTag('MHTJets'),
        VarsDouble=cms.VInputTag(
            cms.InputTag('WeightProducer:weight'),
            cms.InputTag('LostLeptonBkgProducer:LostLeptonWeight'),
            cms.InputTag('LostLeptonBkgProducer:Met'),
            cms.InputTag('LostLeptonBkgProducer:nMu'),
            cms.InputTag('LostLeptonBkgProducer:MuPt'),
            cms.InputTag('LostLeptonBkgProducer:MuEta'),
            cms.InputTag('LostLeptonBkgProducer:MuPhi'),
            cms.InputTag('LostLeptonBkgProducer:deltaRMuJet'),
            cms.InputTag('LostLeptonBkgProducer:deltaRMuMHT'),
            cms.InputTag('LostLeptonBkgProducer:deltaPtMuJet')),
        VarsDoubleNamesInTree=cms.vstring('Weight', 'LostLeptonWeight', 'Met',
                                          'numberOfMuons', 'MuPT', 'MuEta',
                                          'MuPhi', 'DeltaRMuJet',
                                          'DeltaRMuMHT', 'DeltaPtMuJet'),
        Filters=FilterNames)

    # filter used to slecte the RA2 baseline important for efficiency caluclaiton
    from RA2Classic.Utils.RA2Selection_cfi import RA2Selection
    process.RA2Selector = RA2Selection.clone(
        nJets=cms.uint32(3),
        HTMin=cms.double(500),
        MHTMin=cms.double(200),
    )

    ## ---- Load lost lepton moduels
    # special calo jets for delta R in efficiencies
    process.load('JetMETCorrections.Configuration.DefaultJEC_cff')

    #   from RA2Classic.LostLeptonBkg.llPrediction_cff import llPrediction
    #  process.lostLeptonPrediction = llPrediction()
    from RA2Classic.LostLeptonBkg.MCEffCalculator_cfi import MCEffCalculator
    process.LostLeptonBkgMCEffCalculator = MCEffCalculator.clone(
        MuonIDTag=cms.InputTag("patMuonsPFID"),
        MuonIDISOTag=cms.InputTag("patMuonsPFIDIso"),
        ElecIDTag=cms.InputTag("ra2ElectronsID"),
        ElecIDISOTag=cms.InputTag("ra2ElectronsIDIso"),
        #        ElecIDTag = cms.InputTag("patElectronsIDIso"),
        #	ElecIDISOTag = cms.InputTag("patElectronsIDIso"),
        HTTag=cms.InputTag(htInputCol),
        MHTTag=cms.InputTag(mhtInputCol),
        CaloJetTag=cms.InputTag('ak5CaloJetsL2L3'),
        #	CaloJetTag	= cms.InputTag('cleanPatJetsAK5Calo'),
        UseZResonanze=cms.bool(False),
        debug=DebugBool,
    )

    from RA2Classic.LostLeptonBkg.promtisomu_cfi import promtIsoMu
    process.promtLeptons = promtIsoMu.clone(
        MuonIDISOTag=cms.InputTag("patMuonsPFIDIso"),
        CaloJetTag=cms.InputTag("ak5CaloJetsL2L3"),
        #	CaloJetTag	= cms.InputTag('cleanPatJetsAK5Calo'),
    )

    #  process.lostLeptonPrediction = llPrediction()
    from RA2Classic.LostLeptonBkg.bkglostlepton_cfi import bkglostlepton
    process.LostLeptonBkgProducer = bkglostlepton.clone(
        HTJets=cms.InputTag('HTJets'),
        MetTag=cms.InputTag('patMETsPF'),
        CaloJetTag=cms.InputTag('ak5CaloJetsL2L3'),
        #	CaloJetTag	= cms.InputTag('cleanPatJetsAK5Calo'),
        #	MuonTag		= cms.InputTag('promtLeptons:PromtMuon'),
        MuonTag=cms.InputTag('patMuonsPFIDIso'),
        ElecTag=cms.InputTag("ra2ElectronsIDIso"),
        #	ElecTag         = cms.InputTag("patElectronsIDIso"),
        MTWCut=cms.bool(True),
        EfficiencyFileName=cms.string('MCEff.root'),
        HTTag=cms.InputTag(htInputCol),
        MHTTag=cms.InputTag(mhtInputCol),
        MetJetTagUp=cms.InputTag('jesUp:METs'),
        MetJetTagDown=cms.InputTag('jesDown:METs'),
        IsoPlots=cms.bool(True),
        TAPUncertaintiesHTNJET=cms.bool(False),
        statErrorEffmaps=cms.bool(True),
        debug=DebugBool,
    )

    from RA2Classic.LostLeptonBkg.RecoLeptonStudy_cfi import RecoLeptonStudy
    process.RecoLeptonStudyProducer = RecoLeptonStudy.clone(
        MuonIDTag=cms.InputTag("patMuonsPFID"),
        MuonIDISOTag=cms.InputTag("patMuonsPFIDIso"),
        ElecIDTag=cms.InputTag("ra2ElectronsID"),
        ElecIDISOTag=cms.InputTag("ra2ElectronsIDIso"),
        #        ElecIDTag = cms.InputTag("patElectronsIDIso"),
        #	ElecIDISOTag = cms.InputTag("patElectronsIDIso"),
        HTTag=cms.InputTag(htInputCol),
        MHTTag=cms.InputTag(mhtInputCol),
        CaloJetTag=cms.InputTag('ak5CaloJetsL2L3'),
        #	CaloJetTag	= cms.InputTag('cleanPatJetsAK5Calo'),
        UseZResonanze=cms.bool(False),
        debug=DebugBool,
    )

    #electrons selectors for ID electrons
    from SandBox.Skims.RA2Leptons_cff import patElectronsID
    from SandBox.Skims.RA2Leptons_cff import patElectronsIDIso
    process.ra2ElectronsID = patElectronsID.clone()
    process.ra2ElectronsIDIso = patElectronsIDIso.clone()

    # JES variation for MET
    from RA2Classic.Utils.jesUncertaintyVariation_cfi import jesUncertaintyVariation
    process.jesUp = jesUncertaintyVariation.clone(
        Jets=cms.InputTag('MHTJets'),  # The input jet collection
        JetTypeId=cms.string(
            'AK5PFchs'
        ),  # Type of the input jets (to obtain the uncertainty from the data base). 
        Variation=cms.string(
            'Up'
        )  # Either 'Up' or 'Dn' to produce jets with JES +/- 1 sigma, respectively
    )
    process.jesDown = jesUncertaintyVariation.clone(
        Jets=cms.InputTag('MHTJets'),  # The input jet collection
        JetTypeId=cms.string(
            'AK5PFchs'
        ),  # Type of the input jets (to obtain the uncertainty from the data base). 
        Variation=cms.string(
            'Down'
        )  # Either 'Up' or 'Dn' to produce jets with JES +/- 1 sigma, respectively
    )

    from RA2Classic.LostLeptonBkg.ra2Filters_cfi import ra2FilterSelection
    process.RA2Filters = ra2FilterSelection.clone(Filters=FilterNames)

    process.LostLepton = cms.Sequence()
    if MC:
        process.LostLepton += process.LostLeptonBkgMCEffCalculator
    process.LostLepton += process.LostLeptonBkgProducer
    if RecoLeptonStudyBool:
        process.LostLepton += process.RecoLeptonStudyProducer

    ## --- Final paths ----------------------------------------------------

    process.dump = cms.EDAnalyzer("EventContentAnalyzer")

    process.WriteTree = cms.Path(
        process.HLTSelection * process.CleaningSelection *
        process.HCALLaserEvtFilterList2012 * process.ProduceRA2Jets *
        process.NumJetSelection * process.HTSelection * process.MHTSelection *
        process.AdditionalFiltersInTagMode * process.WeightProducer *
        process.ra2ElectronsID * process.ra2ElectronsIDIso *
        #	process.jesUp *
        #	process.jesDown *
        #	process.promtLeptons *
        process.RA2Selector * process.RA2Filters * process.RA2HoNoiseFitler *
        process.ak5CaloJetsL2L3 *
        #       process.dump *
        #	process.LostLeptonBkgMCEffCalculator *
        process.LostLepton
        #	process.RA2TreeMaker
    )
Beispiel #2
0
def makeTreeFromPAT(process,
                    outFileName,
                    useCHSJets=True,
		    invertLeptonVeto=False,
                    NJetsMin=2,
                    HTMin=500.,
                    MHTMin=200.,
                    reportEveryEvt=10,
		    Global_Tag="",
                    testFileName=["/store/user/kheine/HT/RA2PreSelectionOnData_Run2012A_HT_PromptReco-v1_v5/71cce229addb17644d40a607fa20b5d7/RA2SkimsOnData_99_3_TPC.root"],
                    numProcessedEvt=1000):
    
    
    process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
    process.GlobalTag.globaltag = Global_Tag
    
    ## --- Log output ------------------------------------------------------
    process.load("FWCore.MessageService.MessageLogger_cfi")
    process.MessageLogger.cerr = cms.untracked.PSet(
        placeholder = cms.untracked.bool(True)
        )
    process.MessageLogger.statistics.append('cout')
    process.MessageLogger.cout = cms.untracked.PSet(
        INFO = cms.untracked.PSet(reportEvery = cms.untracked.int32(reportEveryEvt))
        )


    ## --- Files to process ------------------------------------------------
    process.maxEvents = cms.untracked.PSet(
        input = cms.untracked.int32(numProcessedEvt)
        )
    process.source = cms.Source(
        "PoolSource",
        fileNames = cms.untracked.vstring(testFileName)
        )
        
        
    ## --- Output file -----------------------------------------------------
    process.TFileService = cms.Service(
        "TFileService",
        fileName = cms.string(outFileName+".root")
        )
    

    ## --- Selection sequences ---------------------------------------------

    # Filter-related selection
    process.load('RA2Classic.TreeMaker.filterSelection_cff')
    process.load('SandBox.Skims.RA2Leptons_cff')

    process.CleaningSelection = cms.Sequence(
        process.filterSelection
        )
    # Produce RA2 jets
    if useCHSJets:
        process.load('RA2Classic.Utils.produceRA2JetsPFCHS_cff')
        process.ProduceRA2Jets = cms.Sequence(
            process.produceRA2JetsPFCHS
            )
    else:
        process.load('RA2Classic.Utils.produceRA2JetsAK5PF_cff')
        process.ProduceRA2Jets = cms.Sequence(
            process.produceRA2JetsAK5PF
            )
    # Select events with at least 'NJetsMin' of the above jets
    from PhysicsTools.PatAlgos.selectionLayer1.jetCountFilter_cfi import countPatJets
    process.NumJetSelection = countPatJets.clone(
        src       = cms.InputTag('HTJets'),
        minNumber = cms.uint32(NJetsMin)
        )

    # HT selection
    htInputCol = 'htPF'
    if useCHSJets:
        htInputCol = 'htPFchs'

    from SandBox.Skims.RA2HT_cff import htPFFilter
    process.HTSelection = htPFFilter.clone(
        HTSource = cms.InputTag(htInputCol),
        MinHT = cms.double(HTMin)
        )

    # MHT selection
    mhtMin = 0.
    mhtInputCol = 'mhtPF'
    if useCHSJets:
        mhtInputCol = 'mhtPFchs'

    from SandBox.Skims.RA2MHT_cff import mhtPFFilter
    process.MHTSelection = mhtPFFilter.clone(
        MHTSource = cms.InputTag(mhtInputCol),
        MinMHT = cms.double(MHTMin)
        )


    ## --- Additional Filters (not tagging mode) ------------------------------
    from RecoMET.METFilters.jetIDFailureFilter_cfi import jetIDFailure
    process.PBNRFilter = jetIDFailure.clone(
        JetSource = cms.InputTag('MHTJets'),
        MinJetPt      = cms.double(30.0),
        taggingMode   = cms.bool(False)
        )
	
	
    from RecoMET.METFilters.multiEventFilter_cfi import multiEventFilter
    process.HCALLaserEvtFilterList2012 = multiEventFilter.clone(
        file        =
        cms.FileInPath('RA2Classic/LostLeptonBkg/data/HCALLaserEventList_20Nov2012-v2_HT-HTMHT.txt'),
        taggingMode = cms.bool(False)
        )
	
	
	
	

    process.AdditionalFiltersInTagMode = cms.Sequence(
        process.PBNRFilter
        )

    FilterNames = cms.VInputTag()
    FilterNames.append(cms.InputTag("HBHENoiseFilterRA2","HBHENoiseFilterResult","PAT"))
    FilterNames.append(cms.InputTag("beamHaloFilter"))
    FilterNames.append(cms.InputTag("trackingFailureFilter"))
    FilterNames.append(cms.InputTag("inconsistentMuons"))
    FilterNames.append(cms.InputTag("greedyMuons"))
    FilterNames.append(cms.InputTag("ra2EcalTPFilter"))
    FilterNames.append(cms.InputTag("ra2EcalBEFilter"))
    FilterNames.append(cms.InputTag("hcalLaserEventFilter"))
    FilterNames.append(cms.InputTag("ecalLaserCorrFilter"))
    FilterNames.append(cms.InputTag("eeBadScFilter"))
    FilterNames.append(cms.InputTag("PBNRFilter"))
    FilterNames.append(cms.InputTag("HCALLaserEvtFilterList2012"))
    FilterNames.append(cms.InputTag("manystripclus53X"))
    FilterNames.append(cms.InputTag("toomanystripclus53X"))
    FilterNames.append(cms.InputTag("logErrorTooManyClusters"))
 #   FilterNames.append(cms.InputTag("RA2CaloVsPFMHTFilter"))
    FilterNames.append(cms.InputTag("RA2HONoiseFilter"))






    ## --- Setup WeightProducer -------------------------------------------
    from RA2Classic.WeightProducer.getWeightProducer_cff import getWeightProducer
    process.WeightProducer = getWeightProducer(process.source.fileNames[0])
        


    FilterNames = cms.VInputTag()  # All filters in AdditionalFiltersInTagMode
    for f in process.AdditionalFiltersInTagMode.moduleNames():
        FilterNames.append(cms.InputTag(f))
	
	
	# filter used to slecte the RA2 baseline important for efficiency caluclaiton
    from RA2Classic.Utils.RA2Selection_cfi import RA2Selection
    process.RA2Selector = RA2Selection.clone(
    	nJets		= cms.uint32 (3),
	HTMin		= cms.double(500),
	MHTMin		= cms.double(100),
	
	)

   ## ---- Load lost lepton moduels
   # special calo jets for delta R in efficiencies
    process.load('JetMETCorrections.Configuration.DefaultJEC_cff')




 #  process.lostLeptonPrediction = llPrediction()
    from RA2Classic.LostLeptonBkg.RecoMuon_cfi import RecoMuon
    process.RA2RecoMuon = RecoMuon.clone(
    	HTJets		= cms.InputTag('HTJets'),
	MetTag		= cms.InputTag('patMETsPF'),
	CaloJetTag	= cms.InputTag('ak5CaloJetsL2L3'),
	MuonIsoTag		= cms.InputTag('patMuonsPFIDIso'),
	ElecIsoTag         = cms.InputTag("ra2ElectronsIDIso"),
	MTWCut		= cms.bool(True),
	HTTag	   = cms.InputTag(htInputCol),
 	MHTTag	   = cms.InputTag(mhtInputCol),
    )



 #electrons selectors for ID electrons
    from SandBox.Skims.RA2Leptons_cff import patElectronsIDIso
    process.ra2ElectronsID = patElectronsIDIso.clone()
    process.ra2ElectronsID.DoElectronIsolation = False
    process.ra2ElectronsIDIso = patElectronsIDIso.clone()
 
    from RA2Classic.LostLeptonBkg.ra2Filters_cfi import ra2FilterSelection
    process.RA2Filters = ra2FilterSelection.clone(
    Filters           = FilterNames
    )

    ## --- Final paths ----------------------------------------------------

    process.dump = cms.EDAnalyzer("EventContentAnalyzer")
    
    process.WriteTree = cms.Path(
        process.CleaningSelection *
	process.HCALLaserEvtFilterList2012 *
	process.ProduceRA2Jets *
        process.NumJetSelection *
        process.HTSelection *
        process.MHTSelection *
        process.AdditionalFiltersInTagMode *
        process.WeightProducer *
	process.ra2ElectronsID *
	process.ra2ElectronsIDIso *
#	process.jesUp *
#	process.jesDown *
#	process.promtLeptons *
	process.RA2Selector *
	process.RA2Filters *
	process.ak5CaloJetsL2L3 *
 #       process.dump *
#	process.LostLeptonBkgMCEffCalculator *
	process.RA2RecoMuon
#	process.RA2TreeMaker 

        )
Beispiel #3
0
def makeTreeFromPAT(process,
                    outFileName,
                    useCHSJets=True,
		    invertLeptonVeto=False,
                    NJetsMin=2,
                    HTMin=500.,
                    MHTMin=200.,
                    reportEveryEvt=10,
		    Global_Tag="",
		    MCTAP=True,
		    Muon=False,
		    muonTrigger="",
                    testFileName=["/store/user/kheine/HT/RA2PreSelectionOnData_Run2012A_HT_PromptReco-v1_v5/71cce229addb17644d40a607fa20b5d7/RA2SkimsOnData_99_3_TPC.root"],
                    numProcessedEvt=1000):
    
    
    process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
    process.GlobalTag.globaltag = Global_Tag
    
    ## --- Log output ------------------------------------------------------
    process.load("FWCore.MessageService.MessageLogger_cfi")
    process.MessageLogger.cerr = cms.untracked.PSet(
        placeholder = cms.untracked.bool(True)
        )
    process.MessageLogger.statistics.append('cout')
    process.MessageLogger.cout = cms.untracked.PSet(
        INFO = cms.untracked.PSet(reportEvery = cms.untracked.int32(reportEveryEvt))
        )


    ## --- Files to process ------------------------------------------------
    process.maxEvents = cms.untracked.PSet(
        input = cms.untracked.int32(numProcessedEvt)
        )
    process.source = cms.Source(
        "PoolSource",
        fileNames = cms.untracked.vstring(testFileName)
        )
        
        
    ## --- Output file -----------------------------------------------------
    process.TFileService = cms.Service(
        "TFileService",
        fileName = cms.string(outFileName+".root")
        )
    

    ## --- Selection sequences ---------------------------------------------

    # Filter-related selection
    process.load('RA2Classic.TreeMaker.filterSelection_cff')
    process.load('SandBox.Skims.RA2Leptons_cff')

    process.CleaningSelection = cms.Sequence(
        process.filterSelection
        )

    # Filter-related selection
#    process.load('RA2Classic.TreeMaker.filterSelection_cff')
#    from RecoMET.METFilters.jetIDFailureFilter_cfi import jetIDFailure
#    process.PBNRFilter = jetIDFailure.clone(
#        JetSource = cms.InputTag('MHTJets'),
#        MinJetPt      = cms.double(30.0),
#        taggingMode   = cms.bool(False)
#        )
#    process.filterSelection += process.PBNRFilter
#    from RecoMET.METFilters.multiEventFilter_cfi import multiEventFilter
#    process.HCALLaserEvtFilterList2012 = multiEventFilter.clone(
#        file        = cms.FileInPath('EventFilter/HcalRawToDigi/data/AllBadHCALLaser.txt'),
#        taggingMode = cms.bool(False)
#        )
 #   process.filterSelection += process.HCALLaserEvtFilterList2012




    # Produce RA2 jets
    if useCHSJets:
        process.load('RA2Classic.Utils.produceRA2JetsPFCHS_cff')
        process.ProduceRA2Jets = cms.Sequence(
            process.produceRA2JetsPFCHS
            )
    else:
        process.load('RA2Classic.Utils.produceRA2JetsAK5PF_cff')
        process.ProduceRA2Jets = cms.Sequence(
            process.produceRA2JetsAK5PF
            )
	    
	    


    # Select events with at least 'NJetsMin' of the above jets
    from PhysicsTools.PatAlgos.selectionLayer1.jetCountFilter_cfi import countPatJets
    process.NumJetSelection = countPatJets.clone(
        src       = cms.InputTag('HTJets'),
        minNumber = cms.uint32(NJetsMin)
        )

    # HT selection
    htInputCol = 'htPF'
    if useCHSJets:
        htInputCol = 'htPFchs'

    from SandBox.Skims.RA2HT_cff import htPFFilter
    process.HTSelection = htPFFilter.clone(
        HTSource = cms.InputTag(htInputCol),
        MinHT = cms.double(HTMin)
        )

    # MHT selection
    mhtMin = 0.
    mhtInputCol = 'mhtPF'
    if useCHSJets:
        mhtInputCol = 'mhtPFchs'

    from SandBox.Skims.RA2MHT_cff import mhtPFFilter
    process.MHTSelection = mhtPFFilter.clone(
        MHTSource = cms.InputTag(mhtInputCol),
        MinMHT = cms.double(MHTMin)
        )


    ## --- Additional Filters (not tagging mode) ------------------------------
    from RecoMET.METFilters.jetIDFailureFilter_cfi import jetIDFailure
    process.PBNRFilter = jetIDFailure.clone(
        JetSource = cms.InputTag('MHTJets'),
        MinJetPt      = cms.double(30.0),
        taggingMode   = cms.bool(False)
        )
	
	
    from RecoMET.METFilters.multiEventFilter_cfi import multiEventFilter
    process.HCALLaserEvtFilterList2012 = multiEventFilter.clone(
        file        =
        cms.FileInPath('RA2Classic/LostLeptonBkg/data/HCALLaserEventList_20Nov2012-v2_HT-HTMHT.txt'),
        taggingMode = cms.bool(False)
        )
	
	
	
	

    process.AdditionalFiltersInTagMode = cms.Sequence(
        process.PBNRFilter
        )


    ## --- Setup WeightProducer -------------------------------------------
    from RA2Classic.WeightProducer.getWeightProducer_cff import getWeightProducer
    process.WeightProducer = getWeightProducer(process.source.fileNames[0])
        

    ## --- Setup of TreeMaker ----------------------------------------------
    FilterNames = cms.VInputTag()  # All filters in AdditionalFiltersInTagMode
    for f in process.AdditionalFiltersInTagMode.moduleNames():
        FilterNames.append(cms.InputTag(f))

##     FilterNames.append(cms.InputTag("HBHENoiseFilterRA2","HBHENoiseFilterResult","PAT"))
##     FilterNames.append(cms.InputTag("beamHaloFilter"))
##     FilterNames.append(cms.InputTag("eeNoiseFilter"))
##     FilterNames.append(cms.InputTag("trackingFailureFilter"))
##     FilterNames.append(cms.InputTag("inconsistentMuons"))
##     FilterNames.append(cms.InputTag("greedyMuons"))
##     FilterNames.append(cms.InputTag("ra2EcalTPFilter"))
##     FilterNames.append(cms.InputTag("ra2EcalBEFilter"))
##     FilterNames.append(cms.InputTag("hcalLaserEventFilter"))
##     FilterNames.append(cms.InputTag("eeBadScFilter"))

    process.load('Configuration.EventContent.EventContent_cff')
    process.load('Configuration.StandardSequences.MagneticField_38T_cff')
    process.load('Configuration.StandardSequences.Reconstruction_cff')
    process.load('Configuration.StandardSequences.EndOfProcess_cff')
    process.load('Configuration.StandardSequences.GeometryDB_cff')
    process.load('Configuration.StandardSequences.Services_cff')

    process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")





    process.load("MuonAnalysis.MuonAssociators.patMuonsWithTrigger_cff")
    from MuonAnalysis.MuonAssociators.patMuonsWithTrigger_cff import useExistingPATMuons
    useExistingPATMuons(process, "patMuons")

#    process.load("MuonAnalysis.MuonAssociators.patMuonsWithTrigger_cff")

    triggerProcessName = "HLT"
    triggerPathSelector = "HLT_Ele27_WP80_v*"
    matchedCutsString=' path( "'+triggerPathSelector+'",1,0 )'


	
	
	
	# filter used to slecte the RA2 baseline important for efficiency caluclaiton
    from RA2Classic.Utils.RA2Selection_cfi import RA2Selection
    process.RA2Selector = RA2Selection.clone(
    	nJets		= cms.uint32 (1),
	HTMin		= cms.double(50),
	MHTMin		= cms.double(0),
	
	)

   ## ---- Load lost lepton moduels
   # special calo jets for delta R in efficiencies
    process.load('JetMETCorrections.Configuration.DefaultJEC_cff')

   

    from RA2Classic.LostLeptonBkg.promtisomu_cfi import promtIsoMu
    process.promtLeptons = promtIsoMu.clone(
	MuonIDISOTag = cms.InputTag("patMuonsPFIDIso"),
	CaloJetTag = cms.InputTag("ak5CaloJetsL2L3"),
#	CaloJetTag	= cms.InputTag('cleanPatJetsAK5Calo'),
    )
    from RA2Classic.LostLeptonBkg.tapTreeProducer_cfi import tapTreeProducer
    process.tapTreeMuId = tapTreeProducer.clone(
	HTTag	   = cms.InputTag(htInputCol),
 	MHTTag	   = cms.InputTag(mhtInputCol),
	MC	   = cms.bool(MCTAP),
	Muon	   = True,
	MuonTrigger     =cms.string(muonTrigger),
	
    )
    process.tapTreeMuIso = process.tapTreeMuId.clone(
       MuElecIdIso    = cms.uint32(1),
       Muon	      = True
    )
    process.tapTreeElecId = process.tapTreeMuId.clone(
       MuElecIdIso    = cms.uint32(2),
       Muon	      = False
    )
    process.tapTreeElecIso = process.tapTreeMuId.clone(
       MuElecIdIso    = cms.uint32(3),
       Muon	      = False
    )
    process.tapTreeElecIdGsf = process.tapTreeMuId.clone(
       MuElecIdIso    = cms.uint32(4),
       Muon	      = False
    )
    


 #electrons selectors for ID electrons
    from SandBox.Skims.RA2Leptons_cff import patElectronsID
    from SandBox.Skims.RA2Leptons_cff import patElectronsIDIso
    process.ra2ElectronsID = patElectronsID.clone()
    process.ra2ElectronsIDIso = patElectronsIDIso.clone()
 
 
 # JES variation for MET 
    from RA2Classic.Utils.jesUncertaintyVariation_cfi import jesUncertaintyVariation
    process.jesUp = jesUncertaintyVariation.clone(
        Jets       = cms.InputTag('MHTJets'), # The input jet collection
        JetTypeId  = cms.string('AK5PFchs'),  # Type of the input jets (to obtain the uncertainty from the data base). 
        Variation  = cms.string('Up')         # Either 'Up' or 'Dn' to produce jets with JES +/- 1 sigma, respectively
    )
    process.jesDown = jesUncertaintyVariation.clone(
        Jets       = cms.InputTag('MHTJets'), # The input jet collection
        JetTypeId  = cms.string('AK5PFchs'),  # Type of the input jets (to obtain the uncertainty from the data base). 
        Variation  = cms.string('Down')         # Either 'Up' or 'Dn' to produce jets with JES +/- 1 sigma, respectively
    )



    process.tapProducer = cms.Sequence ()
    if Muon :
	    process.tapProducer+=process.patMuonsWithTriggerSequence
	    process.tapProducer+=process.tapTreeMuId
	    process.tapProducer+=process.tapTreeMuIso
    else :
	    process.tapProducer+=process.patMuonsWithTriggerSequence
	    process.tapProducer+=process.tapTreeElecIdGsf
	    process.tapProducer+=process.tapTreeElecIso
    if MCTAP  :
	    process.tapProducer+=process.tapTreeMuId
	    process.tapProducer+=process.tapTreeMuIso
	    process.tapProducer+=process.tapTreeElecIdGsf
	    process.tapProducer+=process.tapTreeElecIso


    ## --- Final paths ----------------------------------------------------

    process.dump = cms.EDAnalyzer("EventContentAnalyzer")
    
    process.WriteTree = cms.Path(
        process.CleaningSelection *
	process.HCALLaserEvtFilterList2012 *
	process.ProduceRA2Jets *
        process.NumJetSelection *
        process.HTSelection *
        process.MHTSelection *
        process.AdditionalFiltersInTagMode *
        process.WeightProducer *
	process.ra2ElectronsID *
	process.ra2ElectronsIDIso *
#	process.jesUp *
#	process.jesDown *
#	process.promtLeptons *
	process.RA2Selector *
#	process.ak5CaloJetsL2L3 *
    	process.tapProducer 
#	process.dump *
#	process.patMuonsWithTriggerSequence *
#	process.LostLeptonBkgMCEffCalculator *
#	process.LostLeptonBkgProducer
#	process.RA2TreeMaker 

        )
Beispiel #4
0
def makeTreeFromPAT(process,
                    outFileName,
                    useCHSJets=True,
		    invertLeptonVeto=False,
                    NJetsMin=2,
                    HTMin=500.,
                    MHTMin=200.,
                    reportEveryEvt=10,
		    Global_Tag="",
                    testFileName=["/store/user/kheine/HT/RA2PreSelectionOnData_Run2012A_HT_PromptReco-v1_v5/71cce229addb17644d40a607fa20b5d7/RA2SkimsOnData_99_3_TPC.root"],
                    numProcessedEvt=1000):
    
    
    process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
    process.GlobalTag.globaltag = Global_Tag
    
    ## --- Log output ------------------------------------------------------
    process.load("FWCore.MessageService.MessageLogger_cfi")
    process.MessageLogger.cerr = cms.untracked.PSet(
        placeholder = cms.untracked.bool(True)
        )
    process.MessageLogger.statistics.append('cout')
    process.MessageLogger.cout = cms.untracked.PSet(
        INFO = cms.untracked.PSet(reportEvery = cms.untracked.int32(reportEveryEvt))
        )


    ## --- Files to process ------------------------------------------------
    process.maxEvents = cms.untracked.PSet(
        input = cms.untracked.int32(numProcessedEvt)
        )
    process.source = cms.Source(
        "PoolSource",
        fileNames = cms.untracked.vstring(testFileName)
        )
        
        
    ## --- Output file -----------------------------------------------------
    process.TFileService = cms.Service(
        "TFileService",
        fileName = cms.string(outFileName+".root")
        )
    

    ## --- Selection sequences ---------------------------------------------

    # Filter-related selection
    process.load('RA2Classic.TreeMaker.filterSelection_cff')
    process.load('SandBox.Skims.RA2Leptons_cff')

    process.CleaningSelection = cms.Sequence(
        process.filterSelection
        )

    # Filter-related selection
#    process.load('RA2Classic.TreeMaker.filterSelection_cff')
#    from RecoMET.METFilters.jetIDFailureFilter_cfi import jetIDFailure
#    process.PBNRFilter = jetIDFailure.clone(
#        JetSource = cms.InputTag('MHTJets'),
#        MinJetPt      = cms.double(30.0),
#        taggingMode   = cms.bool(False)
#        )
#    process.filterSelection += process.PBNRFilter
#    from RecoMET.METFilters.multiEventFilter_cfi import multiEventFilter
#    process.HCALLaserEvtFilterList2012 = multiEventFilter.clone(
#        file        = cms.FileInPath('EventFilter/HcalRawToDigi/data/AllBadHCALLaser.txt'),
#        taggingMode = cms.bool(False)
#        )
 #   process.filterSelection += process.HCALLaserEvtFilterList2012




    # Produce RA2 jets
    if useCHSJets:
        process.load('RA2Classic.Utils.produceRA2JetsPFCHS_cff')
        process.ProduceRA2Jets = cms.Sequence(
            process.produceRA2JetsPFCHS
            )
    else:
        process.load('RA2Classic.Utils.produceRA2JetsAK5PF_cff')
        process.ProduceRA2Jets = cms.Sequence(
            process.produceRA2JetsAK5PF
            )
	    
	    


    # Select events with at least 'NJetsMin' of the above jets
    from PhysicsTools.PatAlgos.selectionLayer1.jetCountFilter_cfi import countPatJets
    process.NumJetSelection = countPatJets.clone(
        src       = cms.InputTag('HTJets'),
        minNumber = cms.uint32(NJetsMin)
        )

    # HT selection
    htInputCol = 'htPF'
    if useCHSJets:
        htInputCol = 'htPFchs'

    from SandBox.Skims.RA2HT_cff import htPFFilter
    process.HTSelection = htPFFilter.clone(
        HTSource = cms.InputTag(htInputCol),
        MinHT = cms.double(HTMin)
        )

    # MHT selection
    mhtMin = 0.
    mhtInputCol = 'mhtPF'
    if useCHSJets:
        mhtInputCol = 'mhtPFchs'

    from SandBox.Skims.RA2MHT_cff import mhtPFFilter
    process.MHTSelection = mhtPFFilter.clone(
        MHTSource = cms.InputTag(mhtInputCol),
        MinMHT = cms.double(MHTMin)
        )


    ## --- Additional Filters (not tagging mode) ------------------------------
    from RecoMET.METFilters.jetIDFailureFilter_cfi import jetIDFailure
    process.PBNRFilter = jetIDFailure.clone(
        JetSource = cms.InputTag('MHTJets'),
        MinJetPt      = cms.double(30.0),
        taggingMode   = cms.bool(False)
        )
	
	
    from RecoMET.METFilters.multiEventFilter_cfi import multiEventFilter
    process.HCALLaserEvtFilterList2012 = multiEventFilter.clone(
        file        =
        cms.FileInPath('RA2Classic/LostLeptonBkg/data/HCALLaserEventList_20Nov2012-v2_HT-HTMHT.txt'),
        taggingMode = cms.bool(False)
        )
	
	
	
	

    process.AdditionalFiltersInTagMode = cms.Sequence(
        process.PBNRFilter
        )

    FilterNames = cms.VInputTag()
    FilterNames.append(cms.InputTag("HBHENoiseFilterRA2","HBHENoiseFilterResult","PAT"))
    FilterNames.append(cms.InputTag("beamHaloFilter"))
    FilterNames.append(cms.InputTag("trackingFailureFilter"))
    FilterNames.append(cms.InputTag("inconsistentMuons"))
    FilterNames.append(cms.InputTag("greedyMuons"))
    FilterNames.append(cms.InputTag("ra2EcalTPFilter"))
    FilterNames.append(cms.InputTag("ra2EcalBEFilter"))
    FilterNames.append(cms.InputTag("hcalLaserEventFilter"))
    FilterNames.append(cms.InputTag("ecalLaserCorrFilter"))
    FilterNames.append(cms.InputTag("eeBadScFilter"))
    FilterNames.append(cms.InputTag("PBNRFilter"))
    FilterNames.append(cms.InputTag("HCALLaserEvtFilterList2012"))
    FilterNames.append(cms.InputTag("manystripclus53X"))
    FilterNames.append(cms.InputTag("toomanystripclus53X"))
    FilterNames.append(cms.InputTag("logErrorTooManyClusters"))
 #   FilterNames.append(cms.InputTag("RA2CaloVsPFMHTFilter"))
    FilterNames.append(cms.InputTag("RA2HONoiseFilter"))






    ## --- Setup WeightProducer -------------------------------------------
    from RA2Classic.WeightProducer.getWeightProducer_cff import getWeightProducer
    process.WeightProducer = getWeightProducer(process.source.fileNames[0])
        

    ## --- Setup of TreeMaker ----------------------------------------------
    FilterNames = cms.VInputTag()  # All filters in AdditionalFiltersInTagMode
    for f in process.AdditionalFiltersInTagMode.moduleNames():
        FilterNames.append(cms.InputTag(f))

##     FilterNames.append(cms.InputTag("HBHENoiseFilterRA2","HBHENoiseFilterResult","PAT"))
##     FilterNames.append(cms.InputTag("beamHaloFilter"))
##     FilterNames.append(cms.InputTag("eeNoiseFilter"))
##     FilterNames.append(cms.InputTag("trackingFailureFilter"))
##     FilterNames.append(cms.InputTag("inconsistentMuons"))
##     FilterNames.append(cms.InputTag("greedyMuons"))
##     FilterNames.append(cms.InputTag("ra2EcalTPFilter"))
##     FilterNames.append(cms.InputTag("ra2EcalBEFilter"))
##     FilterNames.append(cms.InputTag("hcalLaserEventFilter"))
##     FilterNames.append(cms.InputTag("eeBadScFilter"))



    from RA2Classic.TreeMaker.treemaker_cfi import TreeMaker
    process.RA2TreeMaker = TreeMaker.clone(
        TreeName          = cms.string("RA2PreSelection"),
        VertexCollection  = cms.InputTag('goodVertices'),
        HT                = cms.InputTag(htInputCol),
        HTJets            = cms.InputTag('HTJets'),
        MHT               = cms.InputTag(mhtInputCol),
        MHTJets           = cms.InputTag('MHTJets'),
        VarsDouble        = cms.VInputTag(cms.InputTag('WeightProducer:weight'),cms.InputTag('LostLeptonBkgProducer:LostLeptonWeight'),cms.InputTag('LostLeptonBkgProducer:Met'),cms.InputTag('LostLeptonBkgProducer:nMu'),cms.InputTag('LostLeptonBkgProducer:MuPt'),cms.InputTag('LostLeptonBkgProducer:MuEta'),cms.InputTag('LostLeptonBkgProducer:MuPhi' ),cms.InputTag('LostLeptonBkgProducer:deltaRMuJet'),cms.InputTag('LostLeptonBkgProducer:deltaRMuMHT' ),cms.InputTag('LostLeptonBkgProducer:deltaPtMuJet') ),
        VarsDoubleNamesInTree = cms.vstring('Weight','LostLeptonWeight','Met','numberOfMuons','MuPT','MuEta','MuPhi','DeltaRMuJet','DeltaRMuMHT','DeltaPtMuJet'), 
        Filters           = FilterNames
        )
	
	
	
	# filter used to slecte the RA2 baseline important for efficiency caluclaiton
    from RA2Classic.Utils.RA2Selection_cfi import RA2Selection
    process.RA2Selector = RA2Selection.clone(
    	nJets		= cms.uint32 (3),
	HTMin		= cms.double(500),
	MHTMin		= cms.double(100),
	
	)

   ## ---- Load lost lepton moduels
   # special calo jets for delta R in efficiencies
    process.load('JetMETCorrections.Configuration.DefaultJEC_cff')

   
#   from RA2Classic.LostLeptonBkg.llPrediction_cff import llPrediction
 #  process.lostLeptonPrediction = llPrediction()
    from RA2Classic.LostLeptonBkg.MCEffCalculator_cfi import MCEffCalculator
    process.LostLeptonBkgMCEffCalculator = MCEffCalculator.clone(
        MuonIDTag = cms.InputTag("patMuonsPFID"),
	MuonIDISOTag = cms.InputTag("patMuonsPFIDIso"),
        ElecIDTag = cms.InputTag("ra2ElectronsID"), 
	ElecIDISOTag = cms.InputTag("ra2ElectronsIDIso"),
#        ElecIDTag = cms.InputTag("patElectronsIDIso"), 
#	ElecIDISOTag = cms.InputTag("patElectronsIDIso"),
	HTTag	   = cms.InputTag(htInputCol),
 	MHTTag	   = cms.InputTag(mhtInputCol),
	CaloJetTag	= cms.InputTag('ak5CaloJetsL2L3'),
#	CaloJetTag	= cms.InputTag('cleanPatJetsAK5Calo'),
    )


    from RA2Classic.LostLeptonBkg.promtisomu_cfi import promtIsoMu
    process.promtLeptons = promtIsoMu.clone(
	MuonIDISOTag = cms.InputTag("patMuonsPFIDIso"),
	CaloJetTag = cms.InputTag("ak5CaloJetsL2L3"),
#	CaloJetTag	= cms.InputTag('cleanPatJetsAK5Calo'),
    )

 #  process.lostLeptonPrediction = llPrediction()
    from RA2Classic.LostLeptonBkg.bkglostlepton_cfi import bkglostlepton
    process.LostLeptonBkgProducer = bkglostlepton.clone(
    	HTJets		= cms.InputTag('HTJets'),
	MetTag		= cms.InputTag('patMETsPF'),
	CaloJetTag	= cms.InputTag('ak5CaloJetsL2L3'),
#	CaloJetTag	= cms.InputTag('cleanPatJetsAK5Calo'),
#	MuonTag		= cms.InputTag('promtLeptons:PromtMuon'),
	MuonTag		= cms.InputTag('patMuonsPFIDIso'),
	ElecTag         = cms.InputTag("ra2ElectronsIDIso"),
#	ElecTag         = cms.InputTag("patElectronsIDIso"),
	MTWCut		= cms.bool(True),
	EfficiencyFileName = cms.string('MCEff.root'),
	HTTag	   = cms.InputTag(htInputCol),
 	MHTTag	   = cms.InputTag(mhtInputCol),
	MetJetTagUp = cms.InputTag('jesUp:METs'),
	MetJetTagDown = cms.InputTag('jesDown:METs'),
	IsoPlots = cms.bool(True),
	TAPUncertaintiesHTNJET = cms.bool(True),
	statErrorEffmaps = cms.bool(True),
    )



 #electrons selectors for ID electrons
    from SandBox.Skims.RA2Leptons_cff import patElectronsID
    from SandBox.Skims.RA2Leptons_cff import patElectronsIDIso
    process.ra2ElectronsID = patElectronsID.clone()
    process.ra2ElectronsIDIso = patElectronsIDIso.clone()
 
 
 # JES variation for MET 
    from RA2Classic.Utils.jesUncertaintyVariation_cfi import jesUncertaintyVariation
    process.jesUp = jesUncertaintyVariation.clone(
        Jets       = cms.InputTag('MHTJets'), # The input jet collection
        JetTypeId  = cms.string('AK5PFchs'),  # Type of the input jets (to obtain the uncertainty from the data base). 
        Variation  = cms.string('Up')         # Either 'Up' or 'Dn' to produce jets with JES +/- 1 sigma, respectively
    )
    process.jesDown = jesUncertaintyVariation.clone(
        Jets       = cms.InputTag('MHTJets'), # The input jet collection
        JetTypeId  = cms.string('AK5PFchs'),  # Type of the input jets (to obtain the uncertainty from the data base). 
        Variation  = cms.string('Down')         # Either 'Up' or 'Dn' to produce jets with JES +/- 1 sigma, respectively
    )

    from RA2Classic.LostLeptonBkg.ra2Filters_cfi import ra2FilterSelection
    process.RA2Filters = ra2FilterSelection.clone(
    Filters           = FilterNames
    )




    ## --- Final paths ----------------------------------------------------

    process.dump = cms.EDAnalyzer("EventContentAnalyzer")
    
    process.WriteTree = cms.Path(
        process.CleaningSelection *
	process.HCALLaserEvtFilterList2012 *
	process.ProduceRA2Jets *
        process.NumJetSelection *
        process.HTSelection *
        process.MHTSelection *
        process.AdditionalFiltersInTagMode *
        process.WeightProducer *
	process.ra2ElectronsID *
	process.ra2ElectronsIDIso *
#	process.jesUp *
#	process.jesDown *
#	process.promtLeptons *
	process.RA2Selector *
	process.RA2Filters *
	process.ak5CaloJetsL2L3 *
 #       process.dump *
	process.LostLeptonBkgMCEffCalculator *
	process.LostLeptonBkgProducer
#	process.RA2TreeMaker 

        )
Beispiel #5
0
def makeTreeFromPAT(
        process,
        outFileName,
        useCHSJets=True,
        invertLeptonVeto=False,
        NJetsMin=2,
        HTMin=500.,
        MHTMin=200.,
        reportEveryEvt=10,
        Global_Tag="",
        MCTAP=True,
        Muon=False,
        muonTrigger="",
        testFileName=[
            "/store/user/kheine/HT/RA2PreSelectionOnData_Run2012A_HT_PromptReco-v1_v5/71cce229addb17644d40a607fa20b5d7/RA2SkimsOnData_99_3_TPC.root"
        ],
        numProcessedEvt=1000):

    process.load(
        "Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
    process.GlobalTag.globaltag = Global_Tag

    ## --- Log output ------------------------------------------------------
    process.load("FWCore.MessageService.MessageLogger_cfi")
    process.MessageLogger.cerr = cms.untracked.PSet(
        placeholder=cms.untracked.bool(True))
    process.MessageLogger.statistics.append('cout')
    process.MessageLogger.cout = cms.untracked.PSet(INFO=cms.untracked.PSet(
        reportEvery=cms.untracked.int32(reportEveryEvt)))

    ## --- Files to process ------------------------------------------------
    process.maxEvents = cms.untracked.PSet(
        input=cms.untracked.int32(numProcessedEvt))
    process.source = cms.Source("PoolSource",
                                fileNames=cms.untracked.vstring(testFileName))

    ## --- Output file -----------------------------------------------------
    process.TFileService = cms.Service("TFileService",
                                       fileName=cms.string(outFileName +
                                                           ".root"))

    ## --- Selection sequences ---------------------------------------------

    # Filter-related selection
    process.load('RA2Classic.TreeMaker.filterSelection_cff')
    process.load('SandBox.Skims.RA2Leptons_cff')

    process.CleaningSelection = cms.Sequence(process.filterSelection)

    # Filter-related selection
    #    process.load('RA2Classic.TreeMaker.filterSelection_cff')
    #    from RecoMET.METFilters.jetIDFailureFilter_cfi import jetIDFailure
    #    process.PBNRFilter = jetIDFailure.clone(
    #        JetSource = cms.InputTag('MHTJets'),
    #        MinJetPt      = cms.double(30.0),
    #        taggingMode   = cms.bool(False)
    #        )
    #    process.filterSelection += process.PBNRFilter
    #    from RecoMET.METFilters.multiEventFilter_cfi import multiEventFilter
    #    process.HCALLaserEvtFilterList2012 = multiEventFilter.clone(
    #        file        = cms.FileInPath('EventFilter/HcalRawToDigi/data/AllBadHCALLaser.txt'),
    #        taggingMode = cms.bool(False)
    #        )
    #   process.filterSelection += process.HCALLaserEvtFilterList2012

    # Produce RA2 jets
    if useCHSJets:
        process.load('RA2Classic.Utils.produceRA2JetsPFCHS_cff')
        process.ProduceRA2Jets = cms.Sequence(process.produceRA2JetsPFCHS)
    else:
        process.load('RA2Classic.Utils.produceRA2JetsAK5PF_cff')
        process.ProduceRA2Jets = cms.Sequence(process.produceRA2JetsAK5PF)

    # Select events with at least 'NJetsMin' of the above jets
    from PhysicsTools.PatAlgos.selectionLayer1.jetCountFilter_cfi import countPatJets
    process.NumJetSelection = countPatJets.clone(
        src=cms.InputTag('HTJets'), minNumber=cms.uint32(NJetsMin))

    # HT selection
    htInputCol = 'htPF'
    if useCHSJets:
        htInputCol = 'htPFchs'

    from SandBox.Skims.RA2HT_cff import htPFFilter
    process.HTSelection = htPFFilter.clone(HTSource=cms.InputTag(htInputCol),
                                           MinHT=cms.double(HTMin))

    # MHT selection
    mhtMin = 0.
    mhtInputCol = 'mhtPF'
    if useCHSJets:
        mhtInputCol = 'mhtPFchs'

    from SandBox.Skims.RA2MHT_cff import mhtPFFilter
    process.MHTSelection = mhtPFFilter.clone(
        MHTSource=cms.InputTag(mhtInputCol), MinMHT=cms.double(MHTMin))

    ## --- Additional Filters (not tagging mode) ------------------------------
    from RecoMET.METFilters.jetIDFailureFilter_cfi import jetIDFailure
    process.PBNRFilter = jetIDFailure.clone(JetSource=cms.InputTag('MHTJets'),
                                            MinJetPt=cms.double(30.0),
                                            taggingMode=cms.bool(False))

    from RecoMET.METFilters.multiEventFilter_cfi import multiEventFilter
    process.HCALLaserEvtFilterList2012 = multiEventFilter.clone(
        file=cms.FileInPath(
            'RA2Classic/LostLeptonBkg/data/HCALLaserEventList_20Nov2012-v2_HT-HTMHT.txt'
        ),
        taggingMode=cms.bool(False))

    process.AdditionalFiltersInTagMode = cms.Sequence(process.PBNRFilter)

    ## --- Setup WeightProducer -------------------------------------------
    from RA2Classic.WeightProducer.getWeightProducer_cff import getWeightProducer
    process.WeightProducer = getWeightProducer(process.source.fileNames[0])

    ## --- Setup of TreeMaker ----------------------------------------------
    FilterNames = cms.VInputTag()  # All filters in AdditionalFiltersInTagMode
    for f in process.AdditionalFiltersInTagMode.moduleNames():
        FilterNames.append(cms.InputTag(f))

##     FilterNames.append(cms.InputTag("HBHENoiseFilterRA2","HBHENoiseFilterResult","PAT"))
##     FilterNames.append(cms.InputTag("beamHaloFilter"))
##     FilterNames.append(cms.InputTag("eeNoiseFilter"))
##     FilterNames.append(cms.InputTag("trackingFailureFilter"))
##     FilterNames.append(cms.InputTag("inconsistentMuons"))
##     FilterNames.append(cms.InputTag("greedyMuons"))
##     FilterNames.append(cms.InputTag("ra2EcalTPFilter"))
##     FilterNames.append(cms.InputTag("ra2EcalBEFilter"))
##     FilterNames.append(cms.InputTag("hcalLaserEventFilter"))
##     FilterNames.append(cms.InputTag("eeBadScFilter"))

    process.load('Configuration.EventContent.EventContent_cff')
    process.load('Configuration.StandardSequences.MagneticField_38T_cff')
    process.load('Configuration.StandardSequences.Reconstruction_cff')
    process.load('Configuration.StandardSequences.EndOfProcess_cff')
    process.load('Configuration.StandardSequences.GeometryDB_cff')
    process.load('Configuration.StandardSequences.Services_cff')

    process.load(
        "Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")

    process.load("MuonAnalysis.MuonAssociators.patMuonsWithTrigger_cff")
    from MuonAnalysis.MuonAssociators.patMuonsWithTrigger_cff import useExistingPATMuons
    useExistingPATMuons(process, "patMuons")

    #    process.load("MuonAnalysis.MuonAssociators.patMuonsWithTrigger_cff")

    triggerProcessName = "HLT"
    triggerPathSelector = "HLT_Ele27_WP80_v*"
    matchedCutsString = ' path( "' + triggerPathSelector + '",1,0 )'

    # filter used to slecte the RA2 baseline important for efficiency caluclaiton
    from RA2Classic.Utils.RA2Selection_cfi import RA2Selection
    process.RA2Selector = RA2Selection.clone(
        nJets=cms.uint32(1),
        HTMin=cms.double(50),
        MHTMin=cms.double(0),
    )

    ## ---- Load lost lepton moduels
    # special calo jets for delta R in efficiencies
    process.load('JetMETCorrections.Configuration.DefaultJEC_cff')

    from RA2Classic.LostLeptonBkg.promtisomu_cfi import promtIsoMu
    process.promtLeptons = promtIsoMu.clone(
        MuonIDISOTag=cms.InputTag("patMuonsPFIDIso"),
        CaloJetTag=cms.InputTag("ak5CaloJetsL2L3"),
        #	CaloJetTag	= cms.InputTag('cleanPatJetsAK5Calo'),
    )
    from RA2Classic.LostLeptonBkg.tapTreeProducer_cfi import tapTreeProducer
    process.tapTreeMuId = tapTreeProducer.clone(
        HTTag=cms.InputTag(htInputCol),
        MHTTag=cms.InputTag(mhtInputCol),
        MC=cms.bool(MCTAP),
        Muon=True,
        MuonTrigger=cms.string(muonTrigger),
    )
    process.tapTreeMuIso = process.tapTreeMuId.clone(MuElecIdIso=cms.uint32(1),
                                                     Muon=True)
    process.tapTreeElecId = process.tapTreeMuId.clone(
        MuElecIdIso=cms.uint32(2), Muon=False)
    process.tapTreeElecIso = process.tapTreeMuId.clone(
        MuElecIdIso=cms.uint32(3), Muon=False)
    process.tapTreeElecIdGsf = process.tapTreeMuId.clone(
        MuElecIdIso=cms.uint32(4), Muon=False)

    #electrons selectors for ID electrons
    from SandBox.Skims.RA2Leptons_cff import patElectronsID
    from SandBox.Skims.RA2Leptons_cff import patElectronsIDIso
    process.ra2ElectronsID = patElectronsID.clone()
    process.ra2ElectronsIDIso = patElectronsIDIso.clone()

    # JES variation for MET
    from RA2Classic.Utils.jesUncertaintyVariation_cfi import jesUncertaintyVariation
    process.jesUp = jesUncertaintyVariation.clone(
        Jets=cms.InputTag('MHTJets'),  # The input jet collection
        JetTypeId=cms.string(
            'AK5PFchs'
        ),  # Type of the input jets (to obtain the uncertainty from the data base). 
        Variation=cms.string(
            'Up'
        )  # Either 'Up' or 'Dn' to produce jets with JES +/- 1 sigma, respectively
    )
    process.jesDown = jesUncertaintyVariation.clone(
        Jets=cms.InputTag('MHTJets'),  # The input jet collection
        JetTypeId=cms.string(
            'AK5PFchs'
        ),  # Type of the input jets (to obtain the uncertainty from the data base). 
        Variation=cms.string(
            'Down'
        )  # Either 'Up' or 'Dn' to produce jets with JES +/- 1 sigma, respectively
    )

    process.tapProducer = cms.Sequence()
    if Muon:
        process.tapProducer += process.patMuonsWithTriggerSequence
        process.tapProducer += process.tapTreeMuId
        process.tapProducer += process.tapTreeMuIso
    else:
        process.tapProducer += process.patMuonsWithTriggerSequence
        process.tapProducer += process.tapTreeElecIdGsf
        process.tapProducer += process.tapTreeElecIso
    if MCTAP:
        process.tapProducer += process.tapTreeMuId
        process.tapProducer += process.tapTreeMuIso
        process.tapProducer += process.tapTreeElecIdGsf
        process.tapProducer += process.tapTreeElecIso

    ## --- Final paths ----------------------------------------------------

    process.dump = cms.EDAnalyzer("EventContentAnalyzer")

    process.WriteTree = cms.Path(
        process.CleaningSelection * process.HCALLaserEvtFilterList2012 *
        process.ProduceRA2Jets * process.NumJetSelection *
        process.HTSelection * process.MHTSelection *
        process.AdditionalFiltersInTagMode * process.WeightProducer *
        process.ra2ElectronsID * process.ra2ElectronsIDIso *
        #	process.jesUp *
        #	process.jesDown *
        #	process.promtLeptons *
        process.RA2Selector *
        #	process.ak5CaloJetsL2L3 *
        process.tapProducer
        #	process.dump *
        #	process.patMuonsWithTriggerSequence *
        #	process.LostLeptonBkgMCEffCalculator *
        #	process.LostLeptonBkgProducer
        #	process.RA2TreeMaker
    )
Beispiel #6
0
def makeTreeFromPAT(
        process,
        outFileName,
        useCHSJets=True,
        invertLeptonVeto=False,
        NJetsMin=2,
        HTMin=500.,
        MHTMin=200.,
        reportEveryEvt=10,
        testFileName=[
            "/store/user/kheine/HT/RA2PreSelectionOnData_Run2012A_HT_PromptReco-v1_v5/71cce229addb17644d40a607fa20b5d7/RA2SkimsOnData_99_3_TPC.root"
        ],
        numProcessedEvt=1000):

    ## --- Log output ------------------------------------------------------
    process.load("FWCore.MessageService.MessageLogger_cfi")
    process.MessageLogger.cerr = cms.untracked.PSet(
        placeholder=cms.untracked.bool(True))
    process.MessageLogger.statistics.append('cout')
    process.MessageLogger.cout = cms.untracked.PSet(INFO=cms.untracked.PSet(
        reportEvery=cms.untracked.int32(reportEveryEvt)))

    ## --- Files to process ------------------------------------------------
    process.maxEvents = cms.untracked.PSet(
        input=cms.untracked.int32(numProcessedEvt))
    process.source = cms.Source("PoolSource",
                                fileNames=cms.untracked.vstring(testFileName))

    ## --- Output file -----------------------------------------------------
    process.TFileService = cms.Service("TFileService",
                                       fileName=cms.string(outFileName +
                                                           ".root"))

    ## --- Selection sequences ---------------------------------------------

    # Filter-related selection
    process.load('RA2Classic.TreeMaker.filterSelection_cff')
    process.load('SandBox.Skims.RA2Leptons_cff')

    process.CleaningSelection = cms.Sequence(process.filterSelection)
    # Select muon comtrol sample

    if invertLeptonVeto:
        from SandBox.Skims.RA2Leptons_cff import countPatMuons
        process.CSMuon = countPatMuons.clone()
        process.CSMuon.src = cms.InputTag('promtLeptons:PromtMuon')
        process.CSMuon.minNumber = cms.uint32(1)
        process.CSMuon.maxNumber = cms.uint32(1)
        process.LeptonVeto = cms.Sequence(process.CSMuon *
                                          process.ra2ElectronVeto)

    else:
        # Veto muons and electrons
        process.LeptonVeto = cms.Sequence(process.ra2PFMuonVeto *
                                          process.ra2ElectronVeto)

    # Produce RA2 jets
    if useCHSJets:
        process.load('RA2Classic.Utils.produceRA2JetsPFCHS_cff')
        process.ProduceRA2Jets = cms.Sequence(process.produceRA2JetsPFCHS)
    else:
        process.load('RA2Classic.Utils.produceRA2JetsAK5PF_cff')
        process.ProduceRA2Jets = cms.Sequence(process.produceRA2JetsAK5PF)

    # Include Muon information

##     from SandBox.Skims.RA2Jets_cff import patJetsAK5PFPt30, patJetsAK5PFPt50Eta25
##     if useCHSJets:
##         process.HTJets = patJetsAK5PFPt50Eta25.clone(
##             src = cms.InputTag('patJetsPF')
##             )
##         process.MHTJets = patJetsAK5PFPt30.clone(
##             src = cms.InputTag('patJetsPF')
##             )
##     else:
##         process.HTJets = patJetsAK5PFPt50Eta25.clone(
##             src = cms.InputTag('patJetsAK5PF')
##             )
##         process.MHTJets = patJetsAK5PFPt30.clone(
##             src = cms.InputTag('patJetsAK5PF')
##             )
##     process.ProduceRA2Jets = cms.Sequence(
##         process.MHTJets *
##         process.HTJets
##         )

# Select events with at least 'NJetsMin' of the above jets
    from PhysicsTools.PatAlgos.selectionLayer1.jetCountFilter_cfi import countPatJets
    process.NumJetSelection = countPatJets.clone(
        src=cms.InputTag('HTJets'), minNumber=cms.uint32(NJetsMin))

    # HT selection
    htInputCol = 'htPF'
    if useCHSJets:
        htInputCol = 'htPFchs'

    from SandBox.Skims.RA2HT_cff import htPFFilter
    process.HTSelection = htPFFilter.clone(HTSource=cms.InputTag(htInputCol),
                                           MinHT=cms.double(HTMin))

    # MHT selection

    mhtInputCol = 'mhtPF'
    if useCHSJets:
        mhtInputCol = 'mhtPFchs'

    from SandBox.Skims.RA2MHT_cff import mhtPFFilter
    process.MHTSelection = mhtPFFilter.clone(
        MHTSource=cms.InputTag(mhtInputCol), MinMHT=cms.double(MHTMin))

    ## --- Additional Filters (tagging mode) ------------------------------
    from RecoMET.METFilters.jetIDFailureFilter_cfi import jetIDFailure
    process.PBNRFilter = jetIDFailure.clone(JetSource=cms.InputTag('MHTJets'),
                                            MinJetPt=cms.double(30.0),
                                            taggingMode=cms.bool(True))

    process.AdditionalFiltersInTagMode = cms.Sequence(process.PBNRFilter)

    ## --- Setup WeightProducer -------------------------------------------
    from RA2Classic.WeightProducer.getWeightProducer_cff import getWeightProducer
    process.WeightProducer = getWeightProducer(process.source.fileNames[0])

    ## --- Setup of TreeMaker ----------------------------------------------
    FilterNames = cms.VInputTag()  # All filters in AdditionalFiltersInTagMode
    for f in process.AdditionalFiltersInTagMode.moduleNames():
        FilterNames.append(cms.InputTag(f))

##     FilterNames.append(cms.InputTag("HBHENoiseFilterRA2","HBHENoiseFilterResult","PAT"))
##     FilterNames.append(cms.InputTag("beamHaloFilter"))
##     FilterNames.append(cms.InputTag("eeNoiseFilter"))
##     FilterNames.append(cms.InputTag("trackingFailureFilter"))
##     FilterNames.append(cms.InputTag("inconsistentMuons"))
##     FilterNames.append(cms.InputTag("greedyMuons"))
##     FilterNames.append(cms.InputTag("ra2EcalTPFilter"))
##     FilterNames.append(cms.InputTag("ra2EcalBEFilter"))
##     FilterNames.append(cms.InputTag("hcalLaserEventFilter"))
##     FilterNames.append(cms.InputTag("eeBadScFilter"))

    from RA2Classic.TreeMaker.treemaker_cfi import TreeMaker
    process.RA2TreeMaker = TreeMaker.clone(
        TreeName=cms.string("RA2PreSelection"),
        VertexCollection=cms.InputTag('goodVertices'),
        HT=cms.InputTag(htInputCol),
        HTJets=cms.InputTag('HTJets'),
        MHT=cms.InputTag(mhtInputCol),
        MHTJets=cms.InputTag('MHTJets'),
        VarsDouble=cms.VInputTag(
            cms.InputTag('WeightProducer:weight'),
            cms.InputTag('LostLeptonBkgProducer:LostLeptonWeight'),
            cms.InputTag('LostLeptonBkgProducer:Met'),
            cms.InputTag('LostLeptonBkgProducer:nMu'),
            cms.InputTag('LostLeptonBkgProducer:MuPt'),
            cms.InputTag('LostLeptonBkgProducer:MuEta'),
            cms.InputTag('LostLeptonBkgProducer:MuPhi'),
            cms.InputTag('LostLeptonBkgProducer:deltaRMuJet'),
            cms.InputTag('LostLeptonBkgProducer:deltaRMuMHT'),
            cms.InputTag('LostLeptonBkgProducer:deltaPtMuJet'),
            cms.InputTag('LostLeptonBkgProducer:muonTotalWeight'),
            cms.InputTag('LostLeptonBkgProducer:elecTotalWeight'),
            cms.InputTag('LostLeptonBkgProducer:muonIsoWeight'),
            cms.InputTag('LostLeptonBkgProducer:muonRecoWeight'),
            cms.InputTag('LostLeptonBkgProducer:muonAccWeight'),
            cms.InputTag('LostLeptonBkgProducer:elecIsoWeight'),
            cms.InputTag('LostLeptonBkgProducer:elecRecoWeight'),
            cms.InputTag('LostLeptonBkgProducer:elecAccWeight'),
            cms.InputTag('LostLeptonBkgProducer:muonAccEff'),
            cms.InputTag('LostLeptonBkgProducer:elecAccEff'),
            cms.InputTag('LostLeptonBkgProducer:muonRecoEff'),
            cms.InputTag('LostLeptonBkgProducer:elecRecoEff'),
            cms.InputTag('LostLeptonBkgProducer:muonIsoEff'),
            cms.InputTag('LostLeptonBkgProducer:elecIsoEff'),
            cms.InputTag('LostLeptonBkgProducer:MTW'),
            cms.InputTag('LostLeptonBkgProducer:mtwCorrectionWeight'),
            cms.InputTag('LostLeptonBkgProducer:nLeptons')),
        VarsDoubleNamesInTree=cms.vstring(
            'Weight', 'LostLeptonWeight', 'Met', 'numberOfMuons', 'MuPT',
            'MuEta', 'MuPhi', 'DeltaRMuJet', 'DeltaRMuMHT', 'DeltaPtMuJet',
            'muonTotalWeight', 'elecTotalWeight', 'muonIsoWeight',
            'muonRecoWeight', 'muonAccWeight', 'elecIsoWeight',
            'elecRecoWeight', 'elecAccWeight', 'muonAccEff', 'elecAccEff',
            'muonRecoEff', 'elecRecoEff', 'muonIsoEff', 'elecIsoEff', 'MTW',
            'mtwCorrectionWeight', 'nLeptons'),
        Filters=FilterNames)

    # filter used to slecte the RA2 baseline important for efficiency caluclaiton
    from RA2Classic.Utils.RA2Selection_cfi import RA2Selection
    process.RA2Selector = RA2Selection.clone()

    ## ---- Load lost lepton moduels

    #   from RA2Classic.LostLeptonBkg.llPrediction_cff import llPrediction
    #  process.lostLeptonPrediction = llPrediction()
    from RA2Classic.LostLeptonBkg.bkglostlepton_cfi import bkglostlepton
    process.LostLeptonBkgProducer = bkglostlepton.clone(
        HTJets=cms.InputTag('HTJets'),
        MetTag=cms.InputTag('pfMet'),
        CaloJetTag=cms.InputTag('cleanPatJetsAK5Calo'),
        MuonTag=cms.InputTag('promtLeptons:PromtMuon'),
        MTWCut=cms.bool(True),
        EfficiencyFileName=cms.string('MCEffOnlyW.root'),
    )

    from RA2Classic.LostLeptonBkg.promtisomu_cfi import promtIsoMu
    process.promtLeptons = promtIsoMu.clone(
        MuonIDISOTag=cms.InputTag("patMuonsPFIDIso")
        #	CaloJetTag = cms.InputTag("ak5CaloJetsL2L3")
    )

    ## --- Final paths ----------------------------------------------------

    process.dump = cms.EDAnalyzer("EventContentAnalyzer")

    process.WriteTree = cms.Path(
        process.CleaningSelection * process.promtLeptons *
        #       process.LeptonVeto *
        process.ProduceRA2Jets * process.NumJetSelection *
        process.HTSelection * process.MHTSelection *
        process.AdditionalFiltersInTagMode * process.WeightProducer *
        process.RA2Selector * process.LostLeptonBkgProducer
        #        process.dump *
        #        process.RA2TreeMaker
    )
def makeTreeFromPAT(process,
                    outFileName,
                    useCHSJets=True,
		    invertLeptonVeto=False,
                    NJetsMin=2,
                    HTMin=500.,
                    MHTMin=200.,
                    reportEveryEvt=10,
                    testFileName=["/store/user/kheine/HT/RA2PreSelectionOnData_Run2012A_HT_PromptReco-v1_v5/71cce229addb17644d40a607fa20b5d7/RA2SkimsOnData_99_3_TPC.root"],
                    numProcessedEvt=1000):
    
    ## --- Log output ------------------------------------------------------
    process.load("FWCore.MessageService.MessageLogger_cfi")
    process.MessageLogger.cerr = cms.untracked.PSet(
        placeholder = cms.untracked.bool(True)
        )
    process.MessageLogger.statistics.append('cout')
    process.MessageLogger.cout = cms.untracked.PSet(
        INFO = cms.untracked.PSet(reportEvery = cms.untracked.int32(reportEveryEvt))
        )


    ## --- Files to process ------------------------------------------------
    process.maxEvents = cms.untracked.PSet(
        input = cms.untracked.int32(numProcessedEvt)
        )
    process.source = cms.Source(
        "PoolSource",
        fileNames = cms.untracked.vstring(testFileName)
        )
        
        
    ## --- Output file -----------------------------------------------------
    process.TFileService = cms.Service(
        "TFileService",
        fileName = cms.string(outFileName+".root")
        )
    

    ## --- Selection sequences ---------------------------------------------

    # Filter-related selection
    process.load('RA2Classic.TreeMaker.filterSelection_cff')
    process.load('SandBox.Skims.RA2Leptons_cff')

    process.CleaningSelection = cms.Sequence(
        process.filterSelection
        )
    # Select muon comtrol sample

    if invertLeptonVeto:
	from SandBox.Skims.RA2Leptons_cff import countPatMuons
	process.CSMuon = countPatMuons.clone()
	process.CSMuon.src = cms.InputTag('promtLeptons:PromtMuon')
	process.CSMuon.minNumber = cms.uint32(1)
	process.CSMuon.maxNumber = cms.uint32(1)
    	process.LeptonVeto = cms.Sequence(
        process.CSMuon *
	process.ra2ElectronVeto
	)	   

    else:
      # Veto muons and electrons
	process.LeptonVeto = cms.Sequence(
       	process.ra2PFMuonVeto *
       	process.ra2ElectronVeto
       	)

    # Produce RA2 jets
    if useCHSJets:
        process.load('RA2Classic.Utils.produceRA2JetsPFCHS_cff')
        process.ProduceRA2Jets = cms.Sequence(
            process.produceRA2JetsPFCHS
            )
    else:
        process.load('RA2Classic.Utils.produceRA2JetsAK5PF_cff')
        process.ProduceRA2Jets = cms.Sequence(
            process.produceRA2JetsAK5PF
            )
	    
	    
     # Include Muon information
     

##     from SandBox.Skims.RA2Jets_cff import patJetsAK5PFPt30, patJetsAK5PFPt50Eta25
##     if useCHSJets:
##         process.HTJets = patJetsAK5PFPt50Eta25.clone(
##             src = cms.InputTag('patJetsPF')
##             )
##         process.MHTJets = patJetsAK5PFPt30.clone(
##             src = cms.InputTag('patJetsPF')
##             )
##     else:
##         process.HTJets = patJetsAK5PFPt50Eta25.clone(
##             src = cms.InputTag('patJetsAK5PF')
##             )
##         process.MHTJets = patJetsAK5PFPt30.clone(
##             src = cms.InputTag('patJetsAK5PF')
##             )
##     process.ProduceRA2Jets = cms.Sequence(
##         process.MHTJets *
##         process.HTJets
##         )


    # Select events with at least 'NJetsMin' of the above jets
    from PhysicsTools.PatAlgos.selectionLayer1.jetCountFilter_cfi import countPatJets
    process.NumJetSelection = countPatJets.clone(
        src       = cms.InputTag('HTJets'),
        minNumber = cms.uint32(NJetsMin)
        )

    # HT selection
    htInputCol = 'htPF'
    if useCHSJets:
        htInputCol = 'htPFchs'

    from SandBox.Skims.RA2HT_cff import htPFFilter
    process.HTSelection = htPFFilter.clone(
        HTSource = cms.InputTag(htInputCol),
        MinHT = cms.double(HTMin)
        )

    # MHT selection

    mhtInputCol = 'mhtPF'
    if useCHSJets:
        mhtInputCol = 'mhtPFchs'

    from SandBox.Skims.RA2MHT_cff import mhtPFFilter
    process.MHTSelection = mhtPFFilter.clone(
        MHTSource = cms.InputTag(mhtInputCol),
        MinMHT = cms.double(MHTMin)
        )


    ## --- Additional Filters (tagging mode) ------------------------------
    from RecoMET.METFilters.jetIDFailureFilter_cfi import jetIDFailure
    process.PBNRFilter = jetIDFailure.clone(
        JetSource = cms.InputTag('MHTJets'),
        MinJetPt      = cms.double(30.0),
        taggingMode   = cms.bool(True)
        )

    process.AdditionalFiltersInTagMode = cms.Sequence(
        process.PBNRFilter
        )


    ## --- Setup WeightProducer -------------------------------------------
    from RA2Classic.WeightProducer.getWeightProducer_cff import getWeightProducer
    process.WeightProducer = getWeightProducer(process.source.fileNames[0])
        

    ## --- Setup of TreeMaker ----------------------------------------------
    FilterNames = cms.VInputTag()  # All filters in AdditionalFiltersInTagMode
    for f in process.AdditionalFiltersInTagMode.moduleNames():
        FilterNames.append(cms.InputTag(f))

##     FilterNames.append(cms.InputTag("HBHENoiseFilterRA2","HBHENoiseFilterResult","PAT"))
##     FilterNames.append(cms.InputTag("beamHaloFilter"))
##     FilterNames.append(cms.InputTag("eeNoiseFilter"))
##     FilterNames.append(cms.InputTag("trackingFailureFilter"))
##     FilterNames.append(cms.InputTag("inconsistentMuons"))
##     FilterNames.append(cms.InputTag("greedyMuons"))
##     FilterNames.append(cms.InputTag("ra2EcalTPFilter"))
##     FilterNames.append(cms.InputTag("ra2EcalBEFilter"))
##     FilterNames.append(cms.InputTag("hcalLaserEventFilter"))
##     FilterNames.append(cms.InputTag("eeBadScFilter"))



    from RA2Classic.TreeMaker.treemaker_cfi import TreeMaker
    process.RA2TreeMaker = TreeMaker.clone(
        TreeName          = cms.string("RA2PreSelection"),
        VertexCollection  = cms.InputTag('goodVertices'),
        HT                = cms.InputTag(htInputCol),
        HTJets            = cms.InputTag('HTJets'),
        MHT               = cms.InputTag(mhtInputCol),
        MHTJets           = cms.InputTag('MHTJets'),
        VarsDouble        = cms.VInputTag(cms.InputTag('WeightProducer:weight'),cms.InputTag('LostLeptonBkgProducer:LostLeptonWeight'),cms.InputTag('LostLeptonBkgProducer:Met'),cms.InputTag('LostLeptonBkgProducer:nMu'),cms.InputTag('LostLeptonBkgProducer:MuPt'),cms.InputTag('LostLeptonBkgProducer:MuEta'),cms.InputTag('LostLeptonBkgProducer:MuPhi' ),cms.InputTag('LostLeptonBkgProducer:deltaRMuJet'),cms.InputTag('LostLeptonBkgProducer:deltaRMuMHT' ),cms.InputTag('LostLeptonBkgProducer:deltaPtMuJet'),cms.InputTag('LostLeptonBkgProducer:muonTotalWeight'),cms.InputTag('LostLeptonBkgProducer:elecTotalWeight'),cms.InputTag('LostLeptonBkgProducer:muonIsoWeight'),cms.InputTag('LostLeptonBkgProducer:muonRecoWeight') ,cms.InputTag('LostLeptonBkgProducer:muonAccWeight'),cms.InputTag('LostLeptonBkgProducer:elecIsoWeight'),cms.InputTag('LostLeptonBkgProducer:elecRecoWeight'),cms.InputTag('LostLeptonBkgProducer:elecAccWeight'),cms.InputTag('LostLeptonBkgProducer:muonAccEff'),cms.InputTag('LostLeptonBkgProducer:elecAccEff'),cms.InputTag('LostLeptonBkgProducer:muonRecoEff'),cms.InputTag('LostLeptonBkgProducer:elecRecoEff'),cms.InputTag('LostLeptonBkgProducer:muonIsoEff'),cms.InputTag('LostLeptonBkgProducer:elecIsoEff'),cms.InputTag('LostLeptonBkgProducer:MTW'),cms.InputTag('LostLeptonBkgProducer:mtwCorrectionWeight'),cms.InputTag('LostLeptonBkgProducer:nLeptons')
	),
        VarsDoubleNamesInTree = cms.vstring('Weight','LostLeptonWeight','Met','numberOfMuons','MuPT','MuEta','MuPhi','DeltaRMuJet','DeltaRMuMHT','DeltaPtMuJet','muonTotalWeight','elecTotalWeight','muonIsoWeight','muonRecoWeight','muonAccWeight','elecIsoWeight','elecRecoWeight','elecAccWeight','muonAccEff','elecAccEff','muonRecoEff','elecRecoEff','muonIsoEff','elecIsoEff','MTW','mtwCorrectionWeight','nLeptons'), 
        Filters           = FilterNames
        )
	
	
	# filter used to slecte the RA2 baseline important for efficiency caluclaiton
    from RA2Classic.Utils.RA2Selection_cfi import RA2Selection
    process.RA2Selector = RA2Selection.clone(
	
	)
	

   ## ---- Load lost lepton moduels
   
#   from RA2Classic.LostLeptonBkg.llPrediction_cff import llPrediction
 #  process.lostLeptonPrediction = llPrediction()
    from RA2Classic.LostLeptonBkg.bkglostlepton_cfi import bkglostlepton
    process.LostLeptonBkgProducer = bkglostlepton.clone(
    	HTJets		= cms.InputTag('HTJets'),
	MetTag		= cms.InputTag('pfMet'),
	CaloJetTag	= cms.InputTag('cleanPatJetsAK5Calo'),
	MuonTag		= cms.InputTag('promtLeptons:PromtMuon'),
	MTWCut		= cms.bool(True),
	EfficiencyFileName = cms.string('MCEffOnlyW.root'),
    )

    from RA2Classic.LostLeptonBkg.promtisomu_cfi import promtIsoMu
    process.promtLeptons = promtIsoMu.clone(
	MuonIDISOTag = cms.InputTag("patMuonsPFIDIso")
 #	CaloJetTag = cms.InputTag("ak5CaloJetsL2L3")
    )




    ## --- Final paths ----------------------------------------------------

    process.dump = cms.EDAnalyzer("EventContentAnalyzer")
    
    process.WriteTree = cms.Path(
        process.CleaningSelection *
	process.promtLeptons *
 #       process.LeptonVeto *
	process.ProduceRA2Jets *
        process.NumJetSelection *
        process.HTSelection *
        process.MHTSelection *
        process.AdditionalFiltersInTagMode *
        process.WeightProducer *
	process.RA2Selector *
	process.LostLeptonBkgProducer 
#        process.dump *
#        process.RA2TreeMaker
        )