CMS 3D CMS Logo

Functions
custom_muon_cff Namespace Reference

Functions

def AddPFTracks (proc)
 
def AddVariablesForMuon (proc)
 
def Custom_Muon_Task (process)
 
def PrepMuonCustomNanoAOD (process)
 

Function Documentation

◆ AddPFTracks()

def custom_muon_cff.AddPFTracks (   proc)

Definition at line 31 of file custom_muon_cff.py.

References common_cff.Var().

Referenced by PrepMuonCustomNanoAOD().

31 def AddPFTracks(proc):
32  pfTracks = "pfTracks"
33  setattr(proc, pfTracks, cms.EDProducer("pfTracksProducer",
34  PFCands=cms.InputTag("packedPFCandidates"),
35  lostTracks=cms.InputTag("lostTracks"),
36  TrkHPurity = cms.bool(False),
37  trkSelection = cms.string("bestTrack.pt()>5 && abs(bestTrack.eta())<2.4 "),
38  )
39  )
40 
41  pfTracksTable = "pfTracksTable"
42  setattr(proc, pfTracksTable, cms.EDProducer("SimpleTrackFlatTableProducer",
43  src = cms.InputTag("pfTracks"),
44  cut = cms.string("pt > 15"), # filtered already above
45  name = cms.string("Track"),
46  doc = cms.string("General tracks with pt > 15 GeV"),
47  singleton = cms.bool(False), # the number of entries is variable
48  extension = cms.bool(False), # this is the main table for the muons
49  variables = cms.PSet(P3Vars,
50  dz = Var("dz",float,doc="dz (with sign) wrt first PV, in cm",precision=10),
51  dxy = Var("dxy",float,doc="dxy (with sign) wrt first PV, in cm",precision=10),
52  charge = Var("charge", int, doc="electric charge"),
53  normChiSq = Var("normalizedChi2", float, precision=14, doc="Chi^2/ndof"),
54  numberOfValidHits = Var('numberOfValidHits()', 'int', precision=-1, doc='Number of valid hits in track'),
55  numberOfLostHits = Var('numberOfLostHits()', 'int', precision=-1, doc='Number of lost hits in track'),
56  trackAlgo = Var('algo()', 'int', precision=-1, doc='Track algo enum, check DataFormats/TrackReco/interface/TrackBase.h for details.'),
57  trackOriginalAlgo = Var('originalAlgo()', 'int', precision=-1, doc='Track original algo enum'),
58  qualityMask = Var('qualityMask()', 'int', precision=-1, doc='Quality mask of the track.'),
59  extraIdx = Var('extra().key()', 'int', precision=-1, doc='Index of the TrackExtra in the original collection'),
60  vx = Var('vx', 'float', precision=-1, doc='Track X position'),
61  vy = Var('vy', 'float', precision=-1, doc='Track Y position'),
62  vz = Var('vz', 'float', precision=-1, doc='Track Z position'),
63  ),
64  )
65  )
66 
67  pfTracksTask = "pfTracksTask"
68  setattr(proc,pfTracksTask, cms.Task(
69  getattr(proc,pfTracks)
70  )
71  )
72 
73  pfTracksTableTask = "pfTracksTableTask"
74  setattr(proc,pfTracksTableTask, cms.Task(
75  getattr(proc,pfTracksTable)
76  )
77  )
78  proc.nanoTableTaskCommon.add(getattr(proc,pfTracksTask))
79  proc.nanoTableTaskCommon.add(getattr(proc,pfTracksTableTask))
80 
81  return proc
82 
83 
84 
def Var(expr, valtype, doc=None, precision=-1)
Definition: common_cff.py:16
def AddPFTracks(proc)

◆ AddVariablesForMuon()

def custom_muon_cff.AddVariablesForMuon (   proc)

Definition at line 85 of file custom_muon_cff.py.

References PVValHelper.add(), and common_cff.Var().

Referenced by PrepMuonCustomNanoAOD().

85 def AddVariablesForMuon(proc):
86 
87  muonWithVariables = "muonWithVariables"
88  setattr(proc, muonWithVariables, cms.EDProducer("MuonSpecialVariables",
89  muonSrc=cms.InputTag("slimmedMuons"),
90  vertexSrc=cms.InputTag("offlineSlimmedPrimaryVertices"),
91  trkSrc=cms.InputTag("pfTracks"),
92  )
93  )
94  getattr(proc,"muonTask").add(getattr(proc,muonWithVariables))
95 
96  proc.slimmedMuonsUpdated.src = cms.InputTag("muonWithVariables")
97  #proc.muonMVATTH.src = cms.InputTag("muonWithVariables")
98  #proc.muonMVALowPt.src = cms.InputTag("muonWithVariables")
99  #proc.muonTable.src = cms.InputTag("muonWithVariables")
100  #proc.muonMCTable.src = cms.InputTag("muonWithVariables")
101  #proc.muonsMCMatchForTable.src = cms.InputTag("muonWithVariables")
102 
103 
104  #SandAlone Variables
105  proc.muonTable.variables.standalonePt = Var("? standAloneMuon().isNonnull() ? standAloneMuon().pt() : -1", float, doc = "pt of the standalone muon", precision=14)
106  proc.muonTable.variables.standaloneEta = Var("? standAloneMuon().isNonnull() ? standAloneMuon().eta() : -99", float, doc = "eta of the standalone muon", precision=14)
107  proc.muonTable.variables.standalonePhi = Var("? standAloneMuon().isNonnull() ? standAloneMuon().phi() : -99", float, doc = "phi of the standalone muon", precision=14)
108  proc.muonTable.variables.standaloneCharge = Var("? standAloneMuon().isNonnull() ? standAloneMuon().charge() : -99", float, doc = "phi of the standalone muon", precision=14)
109 
110  # Inner Track Algo variables
111  proc.muonTable.variables.innerTrackAlgo = Var('? innerTrack().isNonnull() ? innerTrack().algo() : -99', 'int', precision=-1, doc='Track algo enum, check DataFormats/TrackReco/interface/TrackBase.h for details.')
112  proc.muonTable.variables.innerTrackOriginalAlgo = Var('? innerTrack().isNonnull() ? innerTrack().originalAlgo() : -99', 'int', precision=-1, doc='Track original algo enum')
113 
114  #Spark Tool Iso 03 variables
115  proc.muonTable.variables.pfAbsIso03_neu = Var("pfIsolationR03().sumNeutralHadronEt",float,doc="PF absolute isolation dR=0.3, neutral component")
116  proc.muonTable.variables.pfAbsIso03_pho = Var("pfIsolationR03().sumPhotonEt",float,doc="PF absolute isolation dR=0.3, photon component")
117  proc.muonTable.variables.pfAbsIso03_sumPU = Var("pfIsolationR03().sumPUPt",float,doc="PF absolute isolation dR=0.3, pu component (no deltaBeta corrections)")
118 
119  # Spark Tool Iso 04 variables
120  proc.muonTable.variables.pfAbsIso04_chg = Var("pfIsolationR04().sumChargedHadronPt",float,doc="PF absolute isolation dR=0.4, charged component")
121  proc.muonTable.variables.pfAbsIso04_neu = Var("pfIsolationR04().sumNeutralHadronEt",float,doc="PF absolute isolation dR=0.4, neutral component")
122  proc.muonTable.variables.pfAbsIso04_pho = Var("pfIsolationR04().sumPhotonEt",float,doc="PF absolute isolation dR=0.4, photon component")
123  proc.muonTable.variables.pfAbsIso04_sumPU = Var("pfIsolationR04().sumPUPt",float,doc="PF absolute isolation dR=0.4, pu component (no deltaBeta corrections)")
124 
125  #Mini PF Isolation
126  proc.muonTable.variables.miniPFAbsIso_chg = Var("userFloat('miniIsoChg')",float,doc="mini PF absolute isolation, charged component")
127  proc.muonTable.variables.miniPFAbsIso_all = Var("userFloat('miniIsoAll')",float,doc="mini PF absolute isolation, total (with scaled rho*EA PU corrections)")
128  proc.muonTable.variables.miniPFAbsIso_neu = Var("miniPFIsolation().neutralHadronIso()",float,doc="mini PF absolute isolation, neutral component")
129  proc.muonTable.variables.miniPFAbsIso_pho = Var("miniPFIsolation().photonIso()", float, doc="mini PF absolute isolation, photon component")
130 
131  # Absolute Isolations for variables already present in Standard NanoAOD as Relative Isolation
132  proc.muonTable.variables.tkAbsIso = Var("isolationR03().sumPt",float,doc="Tracker-based absolute isolation dR=0.3 for highPt, trkIso",precision=6)
133  proc.muonTable.variables.pfAbsIso03_chg = Var("pfIsolationR03().sumChargedHadronPt",float,doc="PF absolute isolation dR=0.3, charged component")
134  proc.muonTable.variables.pfAbsIso03_all = Var("(pfIsolationR03().sumChargedHadronPt + max(pfIsolationR03().sumNeutralHadronEt + pfIsolationR03().sumPhotonEt - pfIsolationR03().sumPUPt/2,0.0))",float,doc="PF absolute isolation dR=0.3, total (deltaBeta corrections)")
135  proc.muonTable.variables.pfAbsIso04_all = Var("(pfIsolationR04().sumChargedHadronPt + max(pfIsolationR04().sumNeutralHadronEt + pfIsolationR04().sumPhotonEt - pfIsolationR04().sumPUPt/2,0.0))",float,doc="PF absolute isolation dR=0.4, total (deltaBeta corrections)")
136  proc.muonTable.variables.jetAbsIso = Var("?userCand('jetForLepJetVar').isNonnull()?(1./userFloat('ptRatio'))-1.:(pfIsolationR04().sumChargedHadronPt + max(pfIsolationR04().sumNeutralHadronEt + pfIsolationR04().sumPhotonEt - pfIsolationR04().sumPUPt/2,0.0))",float,doc="Absolute isolation in matched jet (1/ptRatio-1, pfRelIso04_all if no matched jet)",precision=8)
137  proc.muonTable.variables.relTrkiso4 = Var("userFloat('relTrkiso4')",float,doc="Realtive Tracker Iso with cone size 0.4")
138 
139  # Muon Quality Variables
140  proc.muonTable.variables.expectedMatchedStations = Var("expectedNnumberOfMatchedStations()",int,doc="Expected Number of Matched stations")
141  proc.muonTable.variables.RPCLayers = Var("numberOfMatchedRPCLayers()",int,doc="Number of RPC Layers")
142  proc.muonTable.variables.stationMask = Var("stationMask()","uint8",doc="Number of masked station")
143  proc.muonTable.variables.nShowers = Var("numberOfShowers()",int,doc="Number of Showers")
144  proc.muonTable.variables.muonHits = Var("? globalTrack().isNonnull() ? globalTrack().hitPattern().numberOfValidMuonHits() : ? innerTrack().isNonnull() && innerTrack().isAvailable() ? innerTrack().hitPattern().numberOfValidMuonHits() :-99",float,doc="Number of valid Muon Hits from either globalTrack or innerTrack")
145 
146  proc.muonTable.variables.outerTrackMuonHits = Var("? outerTrack().isNonnull() ? outerTrack().hitPattern().numberOfValidMuonHits() : -99", float, doc = "Number of valid Muon Hits from OuterTrack")
147 
148  proc.muonTable.variables.pixelLayers = Var("? innerTrack().isNonnull() && innerTrack().isAvailable() ? innerTrack().hitPattern().pixelLayersWithMeasurement() : -99", float,doc="Number of Pixel Layers") # No of tracker layers are already saved in the standard NanoAODs
149  proc.muonTable.variables.validFraction = Var("? innerTrack().isNonnull() && innerTrack().isAvailable() ? innerTrack().validFraction() : -99", float, doc="Inner Track Valid Fraction")
150  proc.muonTable.variables.pixelHits = Var("? innerTrack().isNonnull() && innerTrack().isAvailable() ? innerTrack().hitPattern().numberOfValidPixelHits() : -99", float, doc="Numbr of valid pixel hits")
151  proc.muonTable.variables.muonStations = Var("? outerTrack().isNonnull() && outerTrack().isAvailable() ? outerTrack().hitPattern().muonStationsWithValidHits() : -99", float, doc="No of valid hits in muon stations")
152  proc.muonTable.variables.DTHits = Var("? outerTrack().isNonnull() && outerTrack().isAvailable() ? outerTrack().hitPattern().numberOfValidMuonDTHits() : -99", float, doc="No of valid hits in DT")
153  proc.muonTable.variables.CSCHits = Var("? outerTrack().isNonnull() && outerTrack().isAvailable() ? outerTrack().hitPattern().numberOfValidMuonCSCHits() : -99", float, doc="No of valid hits in CSC")
154  proc.muonTable.variables.RPCHits = Var("? outerTrack().isNonnull() && outerTrack().isAvailable() ? outerTrack().hitPattern().numberOfValidMuonRPCHits() : -99", float, doc="No of valid hits in RPC")
155 
156 
157 
158  # Chi2 related to different tracks
159  proc.muonTable.variables.trkChi2 = Var("? globalTrack().isNonnull() ? globalTrack().normalizedChi2() : ? innerTrack().isNonnull() && innerTrack().isAvailable() ? innerTrack().normalizedChi2() : -99",float,doc="Normalized Chi Square from either globalTrack or innerTrack ")
160  proc.muonTable.variables.trkChi2_outerTrack = Var("? outerTrack().isNonnull() && outerTrack().isAvailable() ? outerTrack().normalizedChi2() : -99",float,doc="Normalized Chi Square from outerTrack ")
161  proc.muonTable.variables.trkChi2_innerTrack = Var("? innerTrack().isNonnull() && innerTrack().isAvailable() ? innerTrack().normalizedChi2() : -99",float,doc="Normalized Chi Square from outerTrack ")
162 
163 
164  #pt, ptErr, eta, phi, charge for different tracks
165 
168  proc.muonTable.variables.innerTrack_ptErr = Var("? innerTrack().isNonnull() && innerTrack().isAvailable() ? innerTrack().ptError()/innerTrack().pt() : -99", float, doc="InnerTrack Pt Error")
169  proc.muonTable.variables.outerTrack_ptErr = Var("? outerTrack().isNonnull() && outerTrack().isAvailable() ? outerTrack().ptError()/outerTrack().pt() : -99", float, doc="OuterTrack Pt Error")
170  proc.muonTable.variables.outerTrack_pt = Var("? outerTrack().isNonnull() && outerTrack().isAvailable() ? outerTrack().pt(): -99", float, doc="OuterTrack Pt")
171  proc.muonTable.variables.outerTrack_eta = Var("? outerTrack().isNonnull() && outerTrack().isAvailable() ? outerTrack().eta(): -99", float, doc="OuterTrack Eta")
172  proc.muonTable.variables.outerTrack_phi = Var("? outerTrack().isNonnull() && outerTrack().isAvailable() ? outerTrack().phi(): -99", float, doc="OuterTrack Phi")
173  proc.muonTable.variables.outerTrack_charge = Var("? outerTrack().isNonnull() && outerTrack().isAvailable() ? outerTrack().charge(): -99", float, doc="OuterTrack charge")
174  proc.muonTable.variables.innerTrack_charge = Var("? innerTrack().isNonnull() && innerTrack().isAvailable() ? innerTrack().charge(): -99", float, doc="OuterTrack charge")
175 
176 
177  # TuneP related variables
178  proc.muonTable.variables.tuneP_pt = Var("? tunePMuonBestTrack().isNonnull() ? tunePMuonBestTrack().pt() : -99", float, doc = "pT from tunePMuonBestTrack")
179  proc.muonTable.variables.tuneP_pterr = Var("? tunePMuonBestTrack().isNonnull() ? tunePMuonBestTrack().ptError() : -99", float, doc = "pTerr from tunePMuonBestTrack")
180  proc.muonTable.variables.tuneP_muonHits = Var("? tunePMuonBestTrack().isNonnull() ? tunePMuonBestTrack().hitPattern().numberOfValidMuonHits() : -99", int, doc="No of valid muon hists from tunePMuonBestTrack")
181 
182 
183  #CombinedQuality Variables
184  proc.muonTable.variables.positionChi2 = Var("combinedQuality().chi2LocalPosition", float, doc="chi2 Local Position")
185  proc.muonTable.variables.momentumChi2 = Var("combinedQuality().chi2LocalMomentum", float, doc="chi2 Local Momentum")
186  proc.muonTable.variables.trkKink = Var("combinedQuality().trkKink", float, doc="Track Kink")
187  proc.muonTable.variables.glbKink = Var("combinedQuality().glbKink", float, doc="Glb Kink")
188  proc.muonTable.variables.glbTrackProbability = Var("combinedQuality().glbTrackProbability", float, doc="Glb Track Probability")
189  proc.muonTable.variables.trkRelChi2 = Var("combinedQuality().trkRelChi2",float,doc="Track Rel Chi2")
190 
191  #timAtIpInOutErr
192  proc.muonTable.variables.timAtIpInOutErr = Var("time().timeAtIpInOutErr",float,doc="timAtIpInOutErr")
193 
194  #isArbitratedTracker
195  proc.muonTable.variables.isArbitratedTracker = Var("userInt('isArbitratedTracker')", bool, doc = "s Arbitrated Tracker")
196 
197  #ExtraidX
198  proc.muonTable.variables.standaloneExtraIdx = Var('? standAloneMuon().isNonnull() ? standAloneMuon().extra().key() : -99', 'int', precision=-1, doc='Index of the StandAloneTrack TrackExtra in the original collection')
199  proc.muonTable.variables.innerTrackExtraIdx = Var('? innerTrack().isNonnull() ? innerTrack().extra().key() : -99', 'int', precision=-1, doc='Index of the innerTrack TrackExtra in the original collection')
200 
201  #Jet Related Variables
202  proc.muonTable.variables.jetPtRatio = Var("?userCand('jetForLepJetVar').isNonnull()?min(userFloat('ptRatio'),1.5):1.0/(1.0+(pfIsolationR04().sumChargedHadronPt + max(pfIsolationR04().sumNeutralHadronEt + pfIsolationR04().sumPhotonEt - pfIsolationR04().sumPUPt/2,0.0))/pt)", float, doc="ptRatio using the LepAware JEC approach, for muon MVA")
203  proc.muonTable.variables.jetDF = Var("?userCand('jetForLepJetVar').isNonnull()?max(userCand('jetForLepJetVar').bDiscriminator('pfDeepFlavourJetTags:probbb')+userCand('jetForLepJetVar').bDiscriminator('pfDeepFlavourJetTags:probb')+userCand('jetForLepJetVar').bDiscriminator('pfDeepFlavourJetTags:problepb'),0.0):0.0",float,doc="b-tagging discriminator of the jet matched to the lepton, for muon MVA")
204  proc.muonTable.variables.jetCSVv2 = Var("?userCand('jetForLepJetVar').isNonnull()?max(userCand('jetForLepJetVar').bDiscriminator('pfCombinedSecondaryVertexV2BJetTags'),0.0):0.0",float,doc="CSVv2 b-tagging discriminator of the jet matched to the lepton, for muon MVA")
205 
206  #Dxy Dz variables as of Spark tool
207  proc.muonTable.variables.innerTrackDxy = Var("? userInt('isGoodVertex') ? userFloat('innerTrackDxy') : -99.9",float,doc = "dxy from Primary Vertex calculated with Inner Track")
208  proc.muonTable.variables.innerTrackDz = Var("? userInt('isGoodVertex') ? userFloat('innerTrackDz') : -99.9",float,doc= "dz from Primary Vertex calculated with Inner Track")
209 
210  #nSegments
211  proc.muonTable.variables.nsegments = Var("userInt('nsegments')", int, doc = "nsegments as of Spark-tool")
212 
213  #Sim Variables
214  proc.muonTable.variables.simType = Var("? simType() ? simType() : -99",int,doc="simType")
215  proc.muonTable.variables.simExtType = Var("? simExtType() ? simExtType() : -99",int,doc="simExtType")
216  proc.muonTable.variables.simFlavour = Var("? simFlavour() ? simFlavour() : -99",int,doc="simFlavour")
217  proc.muonTable.variables.simHeaviestMotherFlavour = Var(" ? simHeaviestMotherFlavour() ? simHeaviestMotherFlavour() : -99",int,doc="simHeaviestMotherFlavour")
218  proc.muonTable.variables.simPdgId = Var("? simPdgId() ? simPdgId() : -99",int,doc="simPdgId")
219  proc.muonTable.variables.simMotherPdgId = Var("? simMotherPdgId() ? simMotherPdgId() : -99",int,doc="simMotherPdgId")
220  proc.muonTable.variables.simBX = Var("? simBX() ? simBX() : -99",int,doc="simBX")
221  proc.muonTable.variables.simProdRho = Var("? simProdRho() ? simProdRho(): -99",float,doc="simProdRho")
222  proc.muonTable.variables.simProdZ = Var("? simProdZ() ? simProdZ(): -99",float,doc="simProdZ")
223  proc.muonTable.variables.simPt = Var("? simPt() ? simPt(): -99",float,doc="simPt")
224  proc.muonTable.variables.simEta = Var("? simEta() ? simEta(): -99",float,doc="simEta")
225  proc.muonTable.variables.simPhi = Var("? simPhi() ? simPhi(): -99",float,doc='simPhi')
226 
227 
228  return proc
229 
230 
def Var(expr, valtype, doc=None, precision=-1)
Definition: common_cff.py:16
def AddVariablesForMuon(proc)
void add(std::map< std::string, TH1 *> &h, TH1 *hist)

◆ Custom_Muon_Task()

def custom_muon_cff.Custom_Muon_Task (   process)

Definition at line 9 of file custom_muon_cff.py.

Referenced by PrepMuonCustomNanoAOD().

9 def Custom_Muon_Task(process):
10  process.nanoTableTaskCommon.remove(process.electronTablesTask)
11  process.nanoTableTaskCommon.remove(process.lowPtElectronTablesTask)
12  process.nanoTableTaskCommon.remove(process.photonTablesTask)
13  process.nanoTableTaskCommon.remove(process.metTablesTask)
14  process.nanoTableTaskCommon.remove(process.tauTablesTask)
15  process.nanoTableTaskCommon.remove(process.boostedTauTablesTask)
16  process.nanoTableTaskCommon.remove(process.jetPuppiTablesTask)
17  process.nanoTableTaskCommon.remove(process.jetAK8TablesTask)
18 
19  process.nanoTableTaskFS.remove(process.electronMCTask)
20  process.nanoTableTaskFS.remove(process.lowPtElectronMCTask)
21  process.nanoTableTaskFS.remove(process.photonMCTask)
22  process.nanoTableTaskFS.remove(process.jetMCTask)
23  process.nanoTableTaskFS.remove(process.tauMCTask)
24  process.nanoTableTaskFS.remove(process.boostedTauMCTask)
25  process.nanoTableTaskFS.remove(process.metMCTable)
26  process.nanoTableTaskFS.remove(process.ttbarCatMCProducersTask)
27  process.nanoTableTaskFS.remove(process.ttbarCategoryTableTask)
28 
29  return process
30 
def Custom_Muon_Task(process)

◆ PrepMuonCustomNanoAOD()

def custom_muon_cff.PrepMuonCustomNanoAOD (   process)

Definition at line 231 of file custom_muon_cff.py.

References AddPFTracks(), AddVariablesForMuon(), and Custom_Muon_Task().

231 def PrepMuonCustomNanoAOD(process):
232 
233  process = Custom_Muon_Task(process)
234  process = AddPFTracks(process)
235  process = AddVariablesForMuon(process)
236 
237 
238  return process
239 
def Custom_Muon_Task(process)
def AddVariablesForMuon(proc)
def PrepMuonCustomNanoAOD(process)
def AddPFTracks(proc)