Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:25:11

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("PhotonMVANtuplizer")
0006 
0007 #process.load('Configuration.StandardSequences.GeometryRecoDB_cff')
0008 #process.load("Configuration.StandardSequences.GeometryDB_cff")
0009 process.load("Configuration.StandardSequences.MagneticField_cff")
0010 process.load("Configuration.StandardSequences.FrontierConditions_GlobalTag_cff")
0011 
0012 
0013 #process.GlobalTag = GlobalTag(process.GlobalTag, '122X_mcRun3_2021_realistic_v9', '')
0014 process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:phase1_2022_realistic', '')
0015 
0016 # File with the ID variables form the text file to include in the Ntuplizer0
0017 mvaVariablesFile = "RecoEgamma/PhotonIdentification/data/PhotonMVAEstimatorRun3VariablesWinter22V1.txt"
0018 
0019 
0020 process.maxEvents = cms.untracked.PSet( input = cms.untracked.int32(-1) )
0021 
0022 
0023 inputFilesAOD = cms.untracked.vstring(
0024         #'/store/mc/Run3Winter22DR/GJet_Pt-10to40_DoubleEMEnriched_TuneCP5_13p6TeV_pythia8/AODSIM/FlatPU0to70_122X_mcRun3_2021_realistic_v9-v2/2430000/00acca83-e889-4d35-8339-0a0ba956e74e.root',
0025         '/store/mc/Run3Winter22DR/GJet_Pt-10to40_DoubleEMEnriched_TuneCP5_13p6TeV_pythia8/AODSIM/FlatPU0to70_122X_mcRun3_2021_realistic_v9-v2/2430000/023a9365-aa97-4a10-8a5a-178eaedd94d4.root',
0026         '/store/mc/Run3Winter22DR/GJet_Pt-10to40_DoubleEMEnriched_TuneCP5_13p6TeV_pythia8/AODSIM/FlatPU0to70_122X_mcRun3_2021_realistic_v9-v2/2430000/0725adeb-68f1-4023-a2e8-373c52e85ff4.root',
0027         '/store/mc/Run3Winter22DR/GJet_Pt-10to40_DoubleEMEnriched_TuneCP5_13p6TeV_pythia8/AODSIM/FlatPU0to70_122X_mcRun3_2021_realistic_v9-v2/2430000/0817e2b0-81e3-49f4-90c1-19cfa46ab46a.root')
0028 
0029 inputFilesMiniAOD = cms.untracked.vstring(
0030         'file:/eos/cms/store/group/phys_egamma/ec/prrout/Run3IDchecks/MiniAOD_Hgg.root'
0031         #'/store/mc/Run3Winter22MiniAOD/GJet_Pt-10to40_DoubleEMEnriched_TuneCP5_13p6TeV_pythia8/MINIAODSIM/FlatPU0to70_122X_mcRun3_2021_realistic_v9-v2/2430000/019c9ef2-86db-4258-a076-bdb5169dc3d0.root',
0032         #'/store/mc/Run3Winter22MiniAOD/GJet_Pt-10to40_DoubleEMEnriched_TuneCP5_13p6TeV_pythia8/MINIAODSIM/FlatPU0to70_122X_mcRun3_2021_realistic_v9-v2/2430000/0a80915b-ce51-4d0e-ae0d-a170a6736a19.root',
0033        #'/store/mc/Run3Winter22MiniAOD/GJet_Pt-10to40_DoubleEMEnriched_TuneCP5_13p6TeV_pythia8/MINIAODSIM/FlatPU0to70_122X_mcRun3_2021_realistic_v9-v2/2430000/1020066d-ab70-4718-8535-efbdfd3356cd.root',
0034        #'/store/mc/Run3Winter22MiniAOD/GJet_Pt-10to40_DoubleEMEnriched_TuneCP5_13p6TeV_pythia8/MINIAODSIM/FlatPU0to70_122X_mcRun3_2021_realistic_v9-v2/2430000/11fa80b0-204f-49ad-8682-5bf232b9f927.root'
0035 )
0036 
0037 useAOD = False
0038 
0039 if useAOD == True :
0040     inputFiles = inputFilesAOD
0041     outputFile = "photon_ntuple_Run3_Winter22_IDtest_Hgg_xmlweights_AOD.root"
0042     print("AOD input files are used")
0043 else :
0044     inputFiles = inputFilesMiniAOD
0045     outputFile = "photon_ntuple_Run3_Winter22_IDtest_Hgg_xmlweights_MiniAOD.root"
0046     print("MiniAOD input files are used")
0047 process.source = cms.Source ("PoolSource", fileNames = inputFiles )
0048 
0049 from PhysicsTools.SelectorUtils.tools.vid_id_tools import *
0050 # turn on VID producer, indicate data format  to be
0051 # DataFormat.AOD or DataFormat.MiniAOD, as appropriate
0052 if useAOD == True :
0053     dataFormat = DataFormat.AOD
0054     input_tags = dict(
0055         src = cms.InputTag("gedPhotons"),
0056         vertices = cms.InputTag("offlinePrimaryVertices"),
0057         pileup = cms.InputTag("addPileupInfo"),
0058         genParticles = cms.InputTag("genParticles"),
0059         ebReducedRecHitCollection = cms.InputTag("reducedEcalRecHitsEB"),
0060         eeReducedRecHitCollection = cms.InputTag("reducedEcalRecHitsEE"),
0061     )
0062 else :
0063     dataFormat = DataFormat.MiniAOD
0064     input_tags = dict()
0065 
0066 switchOnVIDPhotonIdProducer(process, dataFormat)
0067 
0068 # define which IDs we want to produce
0069 my_id_modules = [
0070         'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Winter22_122X_V1_cff',
0071                  ]
0072 
0073 #add them to the VID producer
0074 for idmod in my_id_modules:
0075     setupAllVIDIdsInModule(process,idmod,setupVIDPhotonSelection)
0076 
0077 process.ntuplizer = cms.EDAnalyzer('PhotonMVANtuplizer',
0078         phoMVAs              = cms.vstring(
0079                                           ),
0080         phoMVALabels         = cms.vstring(
0081                                           ),
0082         phoMVAValMaps        = cms.vstring(
0083                                            #"photonMVAValueMapProducer:PhotonMVAEstimatorRunIIFall17v1p1Values",
0084                                            #"photonMVAValueMapProducer:PhotonMVAEstimatorRunIIFall17v2Values",
0085                                            "photonMVAValueMapProducer:PhotonMVAEstimatorRunIIIWinter22v1Values",
0086                                            ),
0087         phoMVAValMapLabels   = cms.vstring(
0088                                            #"Fall17v1p1",
0089                                            #"Fall17v2",
0090                                            "Winter22v1",
0091                                            ),
0092         phoMVACats           = cms.vstring(
0093                                            #"photonMVAValueMapProducer:PhotonMVAEstimatorRunIIFall17v1Categories",
0094                                            "photonMVAValueMapProducer:PhotonMVAEstimatorRunIIIWinter22v1Categories",
0095                                            ),
0096         phoMVACatLabels      = cms.vstring(
0097                                            "PhoMVACats",
0098                                            ),
0099         variableDefinition = cms.string(mvaVariablesFile),
0100         #
0101         doEnergyMatrix = cms.bool(False), # disabled by default due to large size
0102         energyMatrixSize = cms.int32(2), # corresponding to 5x5
0103         #
0104         **input_tags
0105         )
0106 """
0107 The energy matrix is the n x n of raw rec-hit energies around the seed
0108 crystal.
0109 
0110 The size of the energy matrix is controlled with the parameter
0111 "energyMatrixSize", which controlls the extension of crystals in each
0112 direction away from the seed, in other words n = 2 * energyMatrixSize + 1.
0113 
0114 The energy matrix gets saved as a vector but you can easily unroll it
0115 to a two dimensional numpy array later, for example like that:
0116 
0117 >>> import uproot
0118 >>> import numpy as np
0119 >>> import matplotlib.pyplot as plt
0120 
0121 >>> tree = uproot.open("photon_ntuple.root")["ntuplizer/tree"]
0122 >>> n = 5
0123 
0124 >>> for a in tree.array("ele_energyMatrix"):
0125 >>>     a = a.reshape((n,n))
0126 >>>     plt.imshow(np.log10(a))
0127 >>>     plt.colorbar()
0128 >>>     plt.show()
0129 """
0130 
0131 process.TFileService = cms.Service("TFileService", fileName = cms.string(outputFile))
0132 
0133 process.p = cms.Path(process.egmPhotonIDSequence * process.ntuplizer)