CMS 3D CMS Logo

photons_cff.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
3 from math import ceil,log
4 
5 from PhysicsTools.SelectorUtils.tools.vid_id_tools import setupVIDSelection
11 egmPhotonIDSequence = cms.Sequence(cms.Task(egmPhotonIsolationMiniAODTask,photonIDValueMapProducer,photonMVAValueMapProducer,egmPhotonIDs,photonRegressionValueMapProducer))
12 egmPhotonIDs.physicsObjectIDs = cms.VPSet()
13 egmPhotonIDs.physicsObjectSrc = cms.InputTag('slimmedPhotons')
14 _photon_id_vid_modules=[
15 'RecoEgamma.PhotonIdentification.Identification.cutBasedPhotonID_Spring16_V2p2_cff',
16 'RecoEgamma.PhotonIdentification.Identification.mvaPhotonID_Spring16_nonTrig_V1_cff',
17 ]
18 _bitmapVIDForPho_WorkingPoints = cms.vstring(
19  "egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-loose",
20  "egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-medium",
21  "egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-tight",
22 )
23 _bitmapVIDForPho_docstring = ''
24 for modname in _photon_id_vid_modules:
25  ids= __import__(modname, globals(), locals(), ['idName','cutFlow'])
26  for name in dir(ids):
27  _id = getattr(ids,name)
28  if hasattr(_id,'idName') and hasattr(_id,'cutFlow'):
29  setupVIDSelection(egmPhotonIDs,_id)
30  if (len(_bitmapVIDForPho_WorkingPoints)>0 and _id.idName==_bitmapVIDForPho_WorkingPoints[0].split(':')[-1]):
31  _bitmapVIDForPho_docstring = 'VID compressed bitmap (%s), %d bits per cut'%(','.join([cut.cutName.value() for cut in _id.cutFlow]),int(ceil(log(len(_bitmapVIDForPho_WorkingPoints)+1,2))))
32 
33 bitmapVIDForPho = cms.EDProducer("PhoVIDNestedWPBitmapProducer",
34  src = cms.InputTag("slimmedPhotons"),
35  WorkingPoints = _bitmapVIDForPho_WorkingPoints,
36 )
37 
38 isoForPho = cms.EDProducer("PhoIsoValueMapProducer",
39  src = cms.InputTag("slimmedPhotons"),
40  relative = cms.bool(False),
41  rho_PFIso = cms.InputTag("fixedGridRhoFastjetAll"),
42  mapIsoChg = cms.InputTag("photonIDValueMapProducer:phoChargedIsolation"),
43  mapIsoNeu = cms.InputTag("photonIDValueMapProducer:phoNeutralHadronIsolation"),
44  mapIsoPho = cms.InputTag("photonIDValueMapProducer:phoPhotonIsolation"),
45  EAFile_PFIso_Chg = cms.FileInPath("RecoEgamma/PhotonIdentification/data/Spring16/effAreaPhotons_cone03_pfChargedHadrons_90percentBased.txt"),
46  EAFile_PFIso_Neu = cms.FileInPath("RecoEgamma/PhotonIdentification/data/Spring16/effAreaPhotons_cone03_pfNeutralHadrons_90percentBased.txt"),
47  EAFile_PFIso_Pho = cms.FileInPath("RecoEgamma/PhotonIdentification/data/Spring16/effAreaPhotons_cone03_pfPhotons_90percentBased.txt"),
48 )
49 
50 from EgammaAnalysis.ElectronTools.calibratedPhotonsRun2_cfi import calibratedPatPhotons
51 calibratedPatPhotons.correctionFile = cms.string("PhysicsTools/NanoAOD/data/80X_ichepV2_2016_pho") # hack, should go somewhere in EgammaAnalysis
52 calibratedPatPhotons.semiDeterministic = cms.bool(True)
53 
54 energyCorrForPhoton = cms.EDProducer("PhotonEnergyVarProducer",
55  srcRaw = cms.InputTag("slimmedPhotons"),
56  srcCorr = cms.InputTag("calibratedPatPhotons"),
57 )
58 
59 slimmedPhotonsWithUserData = cms.EDProducer("PATPhotonUserDataEmbedder",
60  src = cms.InputTag("slimmedPhotons"),
61  userFloats = cms.PSet(
62  mvaID = cms.InputTag("photonMVAValueMapProducer:PhotonMVAEstimatorRun2Spring16NonTrigV1Values"),
63  PFIsoChg = cms.InputTag("isoForPho:PFIsoChg"),
64  PFIsoAll = cms.InputTag("isoForPho:PFIsoAll"),
65  eCorr = cms.InputTag("energyCorrForPhoton:eCorr"),
66  ),
67  userIntFromBools = cms.PSet(
68  cutbasedID_loose = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-loose"),
69  cutbasedID_medium = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-medium"),
70  cutbasedID_tight = cms.InputTag("egmPhotonIDs:cutBasedPhotonID-Spring16-V2p2-tight"),
71  mvaID_WP90 = cms.InputTag("egmPhotonIDs:mvaPhoID-Spring16-nonTrig-V1-wp90"),
72  mvaID_WP80 = cms.InputTag("egmPhotonIDs:mvaPhoID-Spring16-nonTrig-V1-wp80"),
73  ),
74  userInts = cms.PSet(
75  VIDNestedWPBitmap = cms.InputTag("bitmapVIDForPho"),
76  ),
77 )
78 
79 finalPhotons = cms.EDFilter("PATPhotonRefSelector",
80  src = cms.InputTag("slimmedPhotonsWithUserData"),
81  cut = cms.string("pt > 5 ")
82 )
83 
84 photonTable = cms.EDProducer("SimpleCandidateFlatTableProducer",
85  src = cms.InputTag("linkedObjects","photons"),
86  cut = cms.string(""), #we should not filter on cross linked collections
87  name= cms.string("Photon"),
88  doc = cms.string("slimmedPhotons after basic selection (" + finalPhotons.cut.value()+")"),
89  singleton = cms.bool(False), # the number of entries is variable
90  extension = cms.bool(False), # this is the main table for the photons
91  variables = cms.PSet(CandVars,
92  jetIdx = Var("?hasUserCand('jet')?userCand('jet').key():-1", int, doc="index of the associated jet (-1 if none)"),
93  electronIdx = Var("?hasUserCand('electron')?userCand('electron').key():-1", int, doc="index of the associated electron (-1 if none)"),
94  energyErr = Var("getCorrectedEnergyError('regression2')*userFloat('eCorr')",float,doc="energy error of the cluster from regression",precision=6),
95  eCorr = Var("userFloat('eCorr')",float,doc="ratio of the calibrated energy/miniaod energy"),
96  r9 = Var("full5x5_r9()",float,doc="R9 of the supercluster, calculated with full 5x5 region",precision=10),
97  sieie = Var("full5x5_sigmaIetaIeta()",float,doc="sigma_IetaIeta of the supercluster, calculated with full 5x5 region",precision=10),
98  cutBased = Var("userInt('cutbasedID_loose')+userInt('cutbasedID_medium')+userInt('cutbasedID_tight')",int,doc="cut-based ID (0:fail, 1::loose, 2:medium, 3:tight)"),
99  vidNestedWPBitmap = Var("userInt('VIDNestedWPBitmap')",int,doc=_bitmapVIDForPho_docstring),
100  electronVeto = Var("passElectronVeto()",bool,doc="pass electron veto"),
101  pixelSeed = Var("hasPixelSeed()",bool,doc="has pixel seed"),
102  mvaID = Var("userFloat('mvaID')",float,doc="MVA ID score",precision=10),
103  mvaID_WP90 = Var("userInt('mvaID_WP90')",bool,doc="MVA ID WP90"),
104  mvaID_WP80 = Var("userInt('mvaID_WP90')",bool,doc="MVA ID WP80"),
105  pfRelIso03_chg = Var("userFloat('PFIsoChg')/pt",float,doc="PF relative isolation dR=0.3, charged component (with rho*EA PU corrections)"),
106  pfRelIso03_all = Var("userFloat('PFIsoAll')/pt",float,doc="PF relative isolation dR=0.3, total (with rho*EA PU corrections)"),
107  hoe = Var("hadronicOverEm()",float,doc="H over E",precision=8),
108  isScEtaEB = Var("abs(superCluster().eta()) < 1.4442",bool,doc="is supercluster eta within barrel acceptance"),
109  isScEtaEE = Var("abs(superCluster().eta()) > 1.566 && abs(superCluster().eta()) < 2.5",bool,doc="is supercluster eta within endcap acceptance"),
110  )
111 )
112 photonTable.variables.pt = Var("pt*userFloat('eCorr')", float, precision=-1)
113 
114 photonsMCMatchForTable = cms.EDProducer("MCMatcher", # cut on deltaR, deltaPt/Pt; pick best by deltaR
115  src = photonTable.src, # final reco collection
116  matched = cms.InputTag("finalGenParticles"), # final mc-truth particle collection
117  mcPdgId = cms.vint32(11,22), # one or more PDG ID (11 = el, 22 = pho); absolute values (see below)
118  checkCharge = cms.bool(False), # True = require RECO and MC objects to have the same charge
119  mcStatus = cms.vint32(1), # PYTHIA status code (1 = stable, 2 = shower, 3 = hard scattering)
120  maxDeltaR = cms.double(0.3), # Minimum deltaR for the match
121  maxDPtRel = cms.double(0.5), # Minimum deltaPt/Pt for the match
122  resolveAmbiguities = cms.bool(True), # Forbid two RECO objects to match to the same GEN object
123  resolveByMatchQuality = cms.bool(True), # False = just match input in order; True = pick lowest deltaR pair first
124 )
125 
126 photonMCTable = cms.EDProducer("CandMCMatchTableProducer",
127  src = photonTable.src,
128  mcMap = cms.InputTag("photonsMCMatchForTable"),
129  objName = photonTable.name,
130  objType = photonTable.name, #cms.string("Photon"),
131  branchName = cms.string("genPart"),
132  docString = cms.string("MC matching to status==1 photons or electrons"),
133 )
134 
135 photonSequence = cms.Sequence(egmPhotonIDSequence + bitmapVIDForPho + isoForPho + calibratedPatPhotons + energyCorrForPhoton + slimmedPhotonsWithUserData + finalPhotons)
136 photonTables = cms.Sequence ( photonTable)
137 photonMC = cms.Sequence(photonsMCMatchForTable + photonMCTable)
def Var(expr, valtype, compression=None, doc=None, mcOnly=False, precision=-1)
Definition: common_cff.py:20
def setupVIDSelection(vidproducer, cutflow)
Definition: vid_id_tools.py:11
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
dbl *** dir
Definition: mlp_gen.cc:35
double split
Definition: MVATrainer.cc:139