File indexing completed on 2024-04-06 12:25:08
0001 import FWCore.ParameterSet.Config as cms
0002 from PhysicsTools.SelectorUtils.tools.vid_id_tools import *
0003 from Configuration.AlCa.GlobalTag import GlobalTag
0004
0005 process = cms.Process("ElectronMVANtuplizer")
0006
0007 process.load("Configuration.StandardSequences.GeometryDB_cff")
0008 process.load("FWCore.MessageService.MessageLogger_cfi")
0009 process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
0010
0011 process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:run2_mc', '')
0012
0013
0014 mvaVariablesFile = "RecoEgamma/ElectronIdentification/data/ElectronIDVariables.txt"
0015
0016 outputFile = "electron_ntuple.root"
0017
0018 process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(-1) )
0019
0020 process.source = cms.Source("PoolSource",
0021 fileNames = cms.untracked.vstring(
0022 '/store/mc/RunIIFall17MiniAOD/DYJetsToLL_M-50_TuneCP5_13TeV-madgraphMLM-pythia8/MINIAODSIM/RECOSIMstep_94X_mc2017_realistic_v10-v1/00000/0293A280-B5F3-E711-8303-3417EBE33927.root'
0023 )
0024 )
0025
0026 useAOD = False
0027
0028 from PhysicsTools.SelectorUtils.tools.vid_id_tools import *
0029
0030
0031 if useAOD == True :
0032 dataFormat = DataFormat.AOD
0033 input_tags = dict(
0034 src = cms.InputTag("gedGsfElectrons"),
0035 vertices = cms.InputTag("offlinePrimaryVertices"),
0036 pileup = cms.InputTag("addPileupInfo"),
0037 genParticles = cms.InputTag("genParticles"),
0038 ebReducedRecHitCollection = cms.InputTag("reducedEcalRecHitsEB"),
0039 eeReducedRecHitCollection = cms.InputTag("reducedEcalRecHitsEE"),
0040 )
0041 else :
0042 dataFormat = DataFormat.MiniAOD
0043 input_tags = dict()
0044
0045 switchOnVIDElectronIdProducer(process, dataFormat)
0046
0047
0048 my_id_modules = [
0049 'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring16_GeneralPurpose_V1_cff',
0050 'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring16_HZZ_V1_cff',
0051 'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_noIso_V1_cff',
0052 'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_iso_V1_cff',
0053 'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_noIso_V2_cff',
0054 'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_iso_V2_cff',
0055 ]
0056
0057
0058 for idmod in my_id_modules:
0059 setupAllVIDIdsInModule(process,idmod,setupVIDElectronSelection)
0060
0061 process.ntuplizer = cms.EDAnalyzer('ElectronMVANtuplizer',
0062
0063 eleMVAs = cms.vstring(
0064 "egmGsfElectronIDs:mvaEleID-Spring16-GeneralPurpose-V1-wp80",
0065 "egmGsfElectronIDs:mvaEleID-Spring16-GeneralPurpose-V1-wp90",
0066 "egmGsfElectronIDs:mvaEleID-Spring16-HZZ-V1-wpLoose",
0067 "egmGsfElectronIDs:mvaEleID-Fall17-noIso-V2-wp80",
0068 "egmGsfElectronIDs:mvaEleID-Fall17-noIso-V2-wpLoose",
0069 "egmGsfElectronIDs:mvaEleID-Fall17-noIso-V2-wp90",
0070 "egmGsfElectronIDs:mvaEleID-Fall17-iso-V2-wpHZZ",
0071 "egmGsfElectronIDs:mvaEleID-Fall17-iso-V2-wp80",
0072 "egmGsfElectronIDs:mvaEleID-Fall17-iso-V2-wpLoose",
0073 "egmGsfElectronIDs:mvaEleID-Fall17-iso-V2-wp90",
0074 "egmGsfElectronIDs:mvaEleID-Fall17-noIso-V1-wp90",
0075 "egmGsfElectronIDs:mvaEleID-Fall17-noIso-V1-wp80",
0076 "egmGsfElectronIDs:mvaEleID-Fall17-noIso-V1-wpLoose",
0077 "egmGsfElectronIDs:mvaEleID-Fall17-iso-V1-wp90",
0078 "egmGsfElectronIDs:mvaEleID-Fall17-iso-V1-wp80",
0079 "egmGsfElectronIDs:mvaEleID-Fall17-iso-V1-wpLoose",
0080 ),
0081 eleMVALabels = cms.vstring(
0082 "Spring16GPV1wp80",
0083 "Spring16GPV1wp90",
0084 "Spring16HZZV1wpLoose",
0085 "Fall17noIsoV2wp80",
0086 "Fall17noIsoV2wpLoose",
0087 "Fall17noIsoV2wp90",
0088 "Fall17isoV2wpHZZ",
0089 "Fall17isoV2wp80",
0090 "Fall17isoV2wpLoose",
0091 "Fall17isoV2wp90",
0092 "Fall17noIsoV1wp90",
0093 "Fall17noIsoV1wp80",
0094 "Fall17noIsoV1wpLoose",
0095 "Fall17isoV1wp90",
0096 "Fall17isoV1wp80",
0097 "Fall17isoV1wpLoose",
0098 ),
0099 eleMVAValMaps = cms.vstring(
0100 "electronMVAValueMapProducer:ElectronMVAEstimatorRun2Spring16GeneralPurposeV1Values",
0101 "electronMVAValueMapProducer:ElectronMVAEstimatorRun2Spring16GeneralPurposeV1RawValues",
0102 "electronMVAValueMapProducer:ElectronMVAEstimatorRun2Spring16HZZV1Values",
0103 "electronMVAValueMapProducer:ElectronMVAEstimatorRun2Spring16HZZV1RawValues",
0104 "electronMVAValueMapProducer:ElectronMVAEstimatorRun2Fall17NoIsoV2Values",
0105 "electronMVAValueMapProducer:ElectronMVAEstimatorRun2Fall17NoIsoV2RawValues",
0106 "electronMVAValueMapProducer:ElectronMVAEstimatorRun2Fall17IsoV2Values",
0107 "electronMVAValueMapProducer:ElectronMVAEstimatorRun2Fall17IsoV2RawValues",
0108 "electronMVAValueMapProducer:ElectronMVAEstimatorRun2Fall17IsoV1Values",
0109 "electronMVAValueMapProducer:ElectronMVAEstimatorRun2Fall17NoIsoV1Values",
0110 ),
0111 eleMVAValMapLabels = cms.vstring(
0112 "Spring16GPV1Vals",
0113 "Spring16GPV1RawVals",
0114 "Spring16HZZV1Vals",
0115 "Spring16HZZV1RawVals",
0116 "Fall17NoIsoV2Vals",
0117 "Fall17NoIsoV2RawVals",
0118 "Fall17IsoV2Vals",
0119 "Fall17IsoV2RawVals",
0120 "Fall17IsoV1Vals",
0121 "Fall17NoIsoV1Vals",
0122 ),
0123 eleMVACats = cms.vstring(
0124 "electronMVAValueMapProducer:ElectronMVAEstimatorRun2Fall17NoIsoV1Categories",
0125 ),
0126 eleMVACatLabels = cms.vstring(
0127 "EleMVACats",
0128 ),
0129
0130 variableDefinition = cms.string(mvaVariablesFile),
0131 ptThreshold = cms.double(5.0),
0132
0133 doEnergyMatrix = cms.bool(False),
0134 energyMatrixSize = cms.int32(2),
0135
0136 **input_tags
0137 )
0138 """
0139 The energy matrix is for ecal driven electrons the n x n of raw
0140 rec-hit energies around the seed crystal.
0141
0142 The size of the energy matrix is controlled with the parameter
0143 "energyMatrixSize", which controlls the extension of crystals in each
0144 direction away from the seed, in other words n = 2 * energyMatrixSize + 1.
0145
0146 The energy matrix gets saved as a vector but you can easily unroll it
0147 to a two dimensional numpy array later, for example like that:
0148
0149 >>> import uproot
0150 >>> import numpy as np
0151 >>> import matplotlib.pyplot as plt
0152
0153 >>> tree = uproot.open("electron_ntuple.root")["ntuplizer/tree"]
0154 >>> n = 5
0155
0156 >>> for a in tree.array("ele_energyMatrix"):
0157 >>> a = a.reshape((n,n))
0158 >>> plt.imshow(np.log10(a))
0159 >>> plt.colorbar()
0160 >>> plt.show()
0161 """
0162
0163 process.TFileService = cms.Service("TFileService", fileName = cms.string(outputFile))
0164
0165 process.p = cms.Path(process.egmGsfElectronIDSequence * process.ntuplizer)