Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-01-15 23:45:37

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 # File with the ID variables to include in the Ntuplizer
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          #'/store/mc/Run3Winter22MiniAOD/DYJetsToLL_M-50_TuneCP5_13p6TeV-madgraphMLM-pythia8/MINIAODSIM/122X_mcRun3_2021_realistic_v9_ext1-v1/2830000/009dec29-88c9-4721-bb6f-135a7005e281.root',
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 # turn on VID producer, indicate data format  to be
0031 # DataFormat.AOD or DataFormat.MiniAOD, as appropriate
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 # define which IDs we want to produce
0049 my_id_modules = [
0050         #'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring16_GeneralPurpose_V1_cff',
0051         #'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Spring16_HZZ_V1_cff',
0052         #'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_noIso_V1_cff',
0053         #'RecoEgamma.ElectronIdentification.Identification.mvaElectronID_Fall17_iso_V1_cff',
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 #add them to the VID producer
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                                           #"egmGsfElectronIDs:mvaEleID-Spring16-GeneralPurpose-V1-wp80",
0067                                           #"egmGsfElectronIDs:mvaEleID-Spring16-GeneralPurpose-V1-wp90",
0068                                           #"egmGsfElectronIDs:mvaEleID-Spring16-HZZ-V1-wpLoose",
0069                                           #"egmGsfElectronIDs:mvaEleID-Fall17-noIso-V2-wp80",
0070                                           #"egmGsfElectronIDs:mvaEleID-Fall17-noIso-V2-wpLoose",
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                                           #"egmGsfElectronIDs:mvaEleID-Fall17-noIso-V2-wp90",
0077                                           #"egmGsfElectronIDs:mvaEleID-Fall17-iso-V2-wpHZZ",
0078                                           # "egmGsfElectronIDs:mvaEleID-Fall17-iso-V2-wp80",
0079                                           #"egmGsfElectronIDs:mvaEleID-Fall17-iso-V2-wp80",
0080                                           #"egmGsfElectronIDs:mvaEleID-Fall17-iso-V2-wpLoose",
0081                                           #"egmGsfElectronIDs:mvaEleID-Fall17-iso-V2-wp90",
0082                                           #"egmGsfElectronIDs:mvaEleID-Fall17-noIso-V1-wp90",
0083                                           #"egmGsfElectronIDs:mvaEleID-Fall17-noIso-V1-wp80",
0084                                           #"egmGsfElectronIDs:mvaEleID-Fall17-noIso-V1-wpLoose",
0085                                           #"egmGsfElectronIDs:mvaEleID-Fall17-iso-V1-wp90",
0086                                           #"egmGsfElectronIDs:mvaEleID-Fall17-iso-V1-wp80",
0087                                           #"egmGsfElectronIDs:mvaEleID-Fall17-iso-V1-wpLoose",
0088                                           ),
0089         eleMVALabels        = cms.vstring(
0090                                           #"Spring16GPV1wp80",
0091                                           #"Spring16GPV1wp90",
0092                                           #"Spring16HZZV1wpLoose",
0093                                           #"Fall17noIsoV2wp80",
0094                                           #"Fall17noIsoV2wpLoose",
0095                                           #"Fall17noIsoV2wp90",
0096                                           #"Fall17isoV2wpHZZ",
0097                                           #"Fall17isoV2wp80",
0098                                           #"Fall17isoV2wpLoose",
0099                                           #"Fall17isoV2wp90",
0100                                           #"Fall17noIsoV1wp90",
0101                                           #"Fall17noIsoV1wp80",
0102                                           #"Fall17noIsoV1wpLoose",
0103                                           #"Fall17isoV1wp90",
0104                                           #"Fall17isoV1wp80",
0105                                           #"Fall17isoV1wpLoose",
0106                                            "RunIIIWinter22isoV1wp80",
0107                                            "RunIIIWinter22isoV1wp90", 
0108                                            "RunIIIWinter22noIsoV1wp80",
0109                                            "RunIIIWinter22noIsoV1wp90",
0110                                            "Winter22isoV1wpHZZ", 
0111                                           ),
0112         eleMVAValMaps        = cms.vstring(
0113                                            #"electronMVAValueMapProducer:ElectronMVAEstimatorRun2Spring16GeneralPurposeV1Values",
0114                                            #"electronMVAValueMapProducer:ElectronMVAEstimatorRun2Spring16GeneralPurposeV1RawValues",
0115                                            #"electronMVAValueMapProducer:ElectronMVAEstimatorRun2Spring16HZZV1Values",
0116                                            #"electronMVAValueMapProducer:ElectronMVAEstimatorRun2Spring16HZZV1RawValues",
0117                                            #"electronMVAValueMapProducer:ElectronMVAEstimatorRun2Fall17NoIsoV2Values",
0118                                            #"electronMVAValueMapProducer:ElectronMVAEstimatorRun2Fall17NoIsoV2RawValues",
0119                                            #"electronMVAValueMapProducer:ElectronMVAEstimatorRun2Fall17IsoV2Values",
0120                                            #"electronMVAValueMapProducer:ElectronMVAEstimatorRun2Fall17IsoV2RawValues",
0121                                            #"electronMVAValueMapProducer:ElectronMVAEstimatorRun2Fall17IsoV1Values",
0122                                            #"electronMVAValueMapProducer:ElectronMVAEstimatorRun2Fall17NoIsoV1Values",
0123                                            "electronMVAValueMapProducer:ElectronMVAEstimatorRun2RunIIIWinter22IsoV1Values",
0124                                            "electronMVAValueMapProducer:ElectronMVAEstimatorRun2RunIIIWinter22IsoV1RawValues",
0125                                            "electronMVAValueMapProducer:ElectronMVAEstimatorRun2RunIIIWinter22NoIsoV1Values",
0126                                            "electronMVAValueMapProducer:ElectronMVAEstimatorRun2RunIIIWinter22NoIsoV1RawValues",
0127                                            "electronMVAValueMapProducer:ElectronMVAEstimatorRun2Winter22HZZV1Values",
0128                                            "electronMVAValueMapProducer:ElectronMVAEstimatorRun2Winter22HZZV1RawValues",
0129                                            ),
0130         eleMVAValMapLabels   = cms.vstring(
0131                                            #"Spring16GPV1Vals",
0132                                            #"Spring16GPV1RawVals",
0133                                            #"Spring16HZZV1Vals",
0134                                            #"Spring16HZZV1RawVals",
0135                                            #"Fall17NoIsoV2Vals",
0136                                            #"Fall17NoIsoV2RawVals",
0137                                            #"Fall17IsoV2Vals",
0138                                            #"Fall17IsoV2RawVals",
0139                                            #"Fall17IsoV1Vals",
0140                                            "RunIIIWinter22NoIsoV1Vals",
0141                                            "RunIIIWinter22NoIsoV1RawVals",
0142                                            "RunIIIWinter22IsoV1Vals",
0143                                            "RunIIIWinter22IsoV1RawVals",
0144                                            "Winter22HZZV1Vals",
0145                                            "Winter22HZZV1RawVals",
0146                                            ),
0147         eleMVACats           = cms.vstring(
0148                                            #"electronMVAValueMapProducer:ElectronMVAEstimatorRun2Fall17NoIsoV1Categories",
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), # disabled by default due to large size
0159         energyMatrixSize = cms.int32(2), # corresponding to 5x5
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)