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, '122X_mcRun3_2021_realistic_v9', '')
0012
0013
0014 mvaVariablesFile = "RecoEgamma/ElectronIdentification/data/ElectronIDVariablesRun3.txt"
0015
0016 outputFile = "electron_ntuple.root"
0017
0018 process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(10000) )
0019
0020 process.source = cms.Source("PoolSource",
0021 fileNames = cms.untracked.vstring(
0022
0023 '/store/mc/Run3Winter22MiniAOD/DYJetsToLL_M-50_TuneCP5_13p6TeV-madgraphMLM-pythia8/MINIAODSIM/122X_mcRun3_2021_realistic_v9_ext2-v2/40000/004dd361-f49c-43fe-8344-f18aa036e286.root'
0024 )
0025 )
0026
0027 useAOD = False
0028
0029 from PhysicsTools.SelectorUtils.tools.vid_id_tools import *
0030
0031
0032 if useAOD == True :
0033 dataFormat = DataFormat.AOD
0034 input_tags = dict(
0035 src = cms.InputTag("gedGsfElectrons"),
0036 vertices = cms.InputTag("offlinePrimaryVertices"),
0037 pileup = cms.InputTag("addPileupInfo"),
0038 genParticles = cms.InputTag("genParticles"),
0039 ebReducedRecHitCollection = cms.InputTag("reducedEcalRecHitsEB"),
0040 eeReducedRecHitCollection = cms.InputTag("reducedEcalRecHitsEE"),
0041 )
0042 else :
0043 dataFormat = DataFormat.MiniAOD
0044 input_tags = dict()
0045
0046 switchOnVIDElectronIdProducer(process, dataFormat)
0047
0048
0049 my_id_modules = [
0050
0051
0052
0053
0054 'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_RunIIIWinter22_iso_V1_cff',
0055 'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_RunIIIWinter22_noIso_V1_cff',
0056 'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Winter22_HZZ_V1_cff',
0057 ]
0058
0059
0060 for idmod in my_id_modules:
0061 setupAllVIDIdsInModule(process,idmod,setupVIDElectronSelection)
0062
0063 process.ntuplizer = cms.EDAnalyzer('ElectronMVANtuplizer',
0064
0065 eleMVAs = cms.vstring(
0066
0067
0068
0069
0070
0071 "egmGsfElectronIDs:mvaEleID-RunIIIWinter22-iso-V1-wp80",
0072 "egmGsfElectronIDs:mvaEleID-RunIIIWinter22-iso-V1-wp90",
0073 "egmGsfElectronIDs:mvaEleID-RunIIIWinter22-noIso-V1-wp80",
0074 "egmGsfElectronIDs:mvaEleID-RunIIIWinter22-noIso-V1-wp90",
0075 "egmGsfElectronIDs:mvaEleID-Winter22-HZZ-V1",
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088 ),
0089 eleMVALabels = cms.vstring(
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106 "RunIIIWinter22isoV1wp80",
0107 "RunIIIWinter22isoV1wp90",
0108 "RunIIIWinter22noIsoV1wp80",
0109 "RunIIIWinter22noIsoV1wp90",
0110 "Winter22isoV1wpHZZ",
0111 ),
0112 eleMVAValMaps = cms.vstring(
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123 "electronMVAValueMapProducer:ElectronMVAEstimatorRun2RunIIIWinter22IsoV1Values",
0124 "electronMVAValueMapProducer:ElectronMVAEstimatorRun2RunIIIWinter22IsoV1RawValues",
0125 "electronMVAValueMapProducer:ElectronMVAEstimatorRun2RunIIIWinter22NoIsoV1Values",
0126 "electronMVAValueMapProducer:ElectronMVAEstimatorRun2RunIIIWinter22NoIsoV1RawValues",
0127 "electronMVAValueMapProducer:ElectronMVAEstimatorRun2Winter22HZZV1Values",
0128 "electronMVAValueMapProducer:ElectronMVAEstimatorRun2Winter22HZZV1RawValues",
0129 ),
0130 eleMVAValMapLabels = cms.vstring(
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140 "RunIIIWinter22NoIsoV1Vals",
0141 "RunIIIWinter22NoIsoV1RawVals",
0142 "RunIIIWinter22IsoV1Vals",
0143 "RunIIIWinter22IsoV1RawVals",
0144 "Winter22HZZV1Vals",
0145 "Winter22HZZV1RawVals",
0146 ),
0147 eleMVACats = cms.vstring(
0148
0149 "electronMVAValueMapProducer:ElectronMVAEstimatorRun2RunIIIWinter22NoIsoV1Categories",
0150 ),
0151 eleMVACatLabels = cms.vstring(
0152 "EleMVACats",
0153 ),
0154
0155 variableDefinition = cms.string(mvaVariablesFile),
0156 ptThreshold = cms.double(5.0),
0157
0158 doEnergyMatrix = cms.bool(False),
0159 energyMatrixSize = cms.int32(2),
0160
0161 **input_tags
0162 )
0163 """
0164 The energy matrix is for ecal driven electrons the n x n of raw
0165 rec-hit energies around the seed crystal.
0166
0167 The size of the energy matrix is controlled with the parameter
0168 "energyMatrixSize", which controlls the extension of crystals in each
0169 direction away from the seed, in other words n = 2 * energyMatrixSize + 1.
0170
0171 The energy matrix gets saved as a vector but you can easily unroll it
0172 to a two dimensional numpy array later, for example like that:
0173
0174 >>> import uproot
0175 >>> import numpy as np
0176 >>> import matplotlib.pyplot as plt
0177
0178 >>> tree = uproot.open("electron_ntuple.root")["ntuplizer/tree"]
0179 >>> n = 5
0180
0181 >>> for a in tree.array("ele_energyMatrix"):
0182 >>> a = a.reshape((n,n))
0183 >>> plt.imshow(np.log10(a))
0184 >>> plt.colorbar()
0185 >>> plt.show()
0186 """
0187
0188 process.TFileService = cms.Service("TFileService", fileName = cms.string(outputFile))
0189
0190 process.p = cms.Path(process.egmGsfElectronIDSequence * process.ntuplizer)