CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
autophobj.py
Go to the documentation of this file.
1 #!/bin/env python
2 from math import *
3 import ROOT
4 #from CMGTools.TTHAnalysis.signedSip import *
7 
8 objectFloat = NTupleObjectType("builtInType", variables = [
9  NTupleVariable("", lambda x : x),
10 ])
11 objectInt = NTupleObjectType("builtInType", variables = [
12  NTupleVariable("", lambda x : x,int),
13 ])
14 
15 twoVectorType = NTupleObjectType("twoVector", variables = [
16  NTupleVariable("pt", lambda x : x.pt()),
17  NTupleVariable("phi", lambda x : x.phi()),
18 ])
19 
20 fourVectorType = NTupleObjectType("fourVector", variables = [
21  NTupleVariable("pt", lambda x : x.pt()),
22  NTupleVariable("eta", lambda x : x.eta()),
23  NTupleVariable("phi", lambda x : x.phi()),
24  NTupleVariable("mass", lambda x : x.mass()),
25  NTupleVariable("p4", lambda x : x, "TLorentzVector", default=ROOT.reco.Particle.LorentzVector(0.,0.,0.,0.), filler = lambda vector, obj: vector.SetPtEtaPhiM(obj.pt(), obj.eta(), obj.phi(), obj.mass())),
26  # ^^^^------- Note: p4 normally is not saved unless 'saveTLorentzVectors' is enabled in the tree producer
27 ])
28 particleType = NTupleObjectType("particle", baseObjectTypes = [ fourVectorType ], variables = [
29  NTupleVariable("pdgId", lambda x : x.pdgId(), int),
30 ])
31 
32 weightsInfoType = NTupleObjectType("WeightsInfo", variables = [
33  NTupleVariable("id", lambda x : x.id, int),
34  NTupleVariable("wgt", lambda x : x.wgt),
35 ])
36 
37 ##------------------------------------------
38 ## LEPTON
39 ##------------------------------------------
40 
41 ### BASIC VERSION WITH ONLY MAIN LEPTON ID CRITERIA
42 leptonType = NTupleObjectType("lepton", baseObjectTypes = [ particleType ], variables = [
43  NTupleVariable("charge", lambda x : x.charge(), int),
44  # Identification
45  NTupleVariable("tightId", lambda x : x.tightId(), int, help="POG Tight ID (for electrons it's configured in the analyzer)"),
46  NTupleVariable("eleCutIdCSA14_25ns_v1", lambda x : (1*x.electronID("POG_Cuts_ID_CSA14_25ns_v1_Veto") + 1*x.electronID("POG_Cuts_ID_CSA14_25ns_v1_Loose") + 1*x.electronID("POG_Cuts_ID_CSA14_25ns_v1_Medium") + 1*x.electronID("POG_Cuts_ID_CSA14_25ns_v1_Tight")) if abs(x.pdgId()) == 11 else -1, int, help="Electron cut-based id (POG CSA14_25ns_v1): 0=none, 1=veto, 2=loose, 3=medium, 4=tight"),
47  NTupleVariable("eleCutIdCSA14_50ns_v1", lambda x : (1*x.electronID("POG_Cuts_ID_CSA14_50ns_v1_Veto") + 1*x.electronID("POG_Cuts_ID_CSA14_50ns_v1_Loose") + 1*x.electronID("POG_Cuts_ID_CSA14_50ns_v1_Medium") + 1*x.electronID("POG_Cuts_ID_CSA14_50ns_v1_Tight")) if abs(x.pdgId()) == 11 else -1, int, help="Electron cut-based id (POG CSA14_50ns_v1): 0=none, 1=veto, 2=loose, 3=medium, 4=tight"),
48  # Impact parameter
49  NTupleVariable("dxy", lambda x : x.dxy(), help="d_{xy} with respect to PV, in cm (with sign)"),
50  NTupleVariable("dz", lambda x : x.dz() , help="d_{z} with respect to PV, in cm (with sign)"),
51  NTupleVariable("edxy", lambda x : x.edB(), help="#sigma(d_{xy}) with respect to PV, in cm"),
52  NTupleVariable("edz", lambda x : x.edz(), help="#sigma(d_{z}) with respect to PV, in cm"),
53  NTupleVariable("ip3d", lambda x : x.ip3D() , help="d_{3d} with respect to PV, in cm (absolute value)"),
54  NTupleVariable("sip3d", lambda x : x.sip3D(), help="S_{ip3d} with respect to PV (significance)"),
55  # Conversion rejection
56  NTupleVariable("convVeto", lambda x : x.passConversionVeto() if abs(x.pdgId())==11 else 1, int, help="Conversion veto (always true for muons)"),
57  NTupleVariable("lostHits", lambda x : (x.gsfTrack() if abs(x.pdgId())==11 else x.innerTrack()).hitPattern().numberOfLostHits(ROOT.reco.HitPattern.MISSING_INNER_HITS), int, help="Number of lost hits on inner track"),
58  # Isolations with the two radia
59  NTupleVariable("relIso03", lambda x : x.relIso03, help="PF Rel Iso, R=0.3, pile-up corrected"),
60  NTupleVariable("relIso04", lambda x : x.relIso04, help="PF Rel Iso, R=0.4, pile-up corrected"),
61  NTupleVariable("miniRelIso", lambda x : x.miniRelIso if hasattr(x,'miniRelIso') else -999, help="PF Rel miniRel, pile-up corrected"),
62  # Charge flip rejection criteria
63  NTupleVariable("tightCharge", lambda lepton : ( lepton.isGsfCtfScPixChargeConsistent() + lepton.isGsfScPixChargeConsistent() ) if abs(lepton.pdgId()) == 11 else 2*(lepton.innerTrack().ptError()/lepton.innerTrack().pt() < 0.2), int, help="Tight charge criteria: for electrons, 2 if isGsfCtfScPixChargeConsistent, 1 if only isGsfScPixChargeConsistent, 0 otherwise; for muons, 2 if ptError/pt < 0.20, 0 otherwise "),
64  # MC-match info
65  NTupleVariable("mcMatchId", lambda x : getattr(x, 'mcMatchId', -99), int, mcOnly=True, help="Match to source from hard scatter (pdgId of heaviest particle in chain, 25 for H, 6 for t, 23/24 for W/Z), zero if non-prompt or fake"),
66  NTupleVariable("mcMatchAny", lambda x : x.mcMatchAny, int, mcOnly=True, help="Match to any final state leptons: 0 if unmatched, 1 if light flavour (including prompt), 4 if charm, 5 if bottom"),
67  NTupleVariable("mcMatchTau", lambda x : x.mcMatchTau, int, mcOnly=True, help="True if the leptons comes from a tau"),
68  NTupleVariable("mcPt", lambda x : x.mcLep.pt() if getattr(x,"mcLep",None) else 0., mcOnly=True, help="p_{T} of associated gen lepton"),
69  NTupleVariable("mediumMuonId", lambda x : x.muonID("POG_ID_Medium") if abs(x.pdgId())==13 else 1, int, help="Muon POG Medium id"),
70 ])
71 
72 ### EXTENDED VERSION WITH INDIVIUAL DISCRIMINATING VARIABLES
73 leptonTypeExtra = NTupleObjectType("leptonExtra", baseObjectTypes = [ leptonType ], variables = [
74  # Extra isolation variables
75  NTupleVariable("chargedHadRelIso03", lambda x : x.chargedHadronIsoR(0.3)/x.pt(), help="PF Rel Iso, R=0.3, charged hadrons only"),
76  NTupleVariable("chargedHadRelIso04", lambda x : x.chargedHadronIsoR(0.4)/x.pt(), help="PF Rel Iso, R=0.4, charged hadrons only"),
77  # Extra muon ID working points
78  NTupleVariable("softMuonId", lambda x : x.muonID("POG_ID_Soft") if abs(x.pdgId())==13 else 1, int, help="Muon POG Soft id"),
79  NTupleVariable("pfMuonId", lambda x : x.muonID("POG_ID_Loose") if abs(x.pdgId())==13 else 1, int, help="Muon POG Loose id"),
80  # Extra electron ID working points
81  NTupleVariable("eleCutId2012_full5x5", lambda x : (1*x.electronID("POG_Cuts_ID_2012_full5x5_Veto") + 1*x.electronID("POG_Cuts_ID_2012_full5x5_Loose") + 1*x.electronID("POG_Cuts_ID_2012_full5x5_Medium") + 1*x.electronID("POG_Cuts_ID_2012_full5x5_Tight")) if abs(x.pdgId()) == 11 else -1, int, help="Electron cut-based id (POG 2012, full5x5 shapes): 0=none, 1=veto, 2=loose, 3=medium, 4=tight"),
82  # Extra tracker-related variables
83  NTupleVariable("trackerLayers", lambda x : (x.track() if abs(x.pdgId())==13 else x.gsfTrack()).hitPattern().trackerLayersWithMeasurement(), int, help="Tracker Layers"),
84  NTupleVariable("pixelLayers", lambda x : (x.track() if abs(x.pdgId())==13 else x.gsfTrack()).hitPattern().pixelLayersWithMeasurement(), int, help="Pixel Layers"),
85  NTupleVariable("trackerHits", lambda x : (x.track() if abs(x.pdgId())==13 else x.gsfTrack()).hitPattern().numberOfValidTrackerHits(), int, help="Tracker hits"),
86  NTupleVariable("lostOuterHits", lambda x : (x.gsfTrack() if abs(x.pdgId())==11 else x.innerTrack()).hitPattern().numberOfLostHits(ROOT.reco.HitPattern.MISSING_OUTER_HITS), int, help="Number of lost hits on inner track"),
87  NTupleVariable("innerTrackValidHitFraction", lambda x : (x.gsfTrack() if abs(x.pdgId())==11 else x.innerTrack()).validFraction(), help="fraction of valid hits on inner track"),
88  NTupleVariable("innerTrackChi2", lambda x : (x.gsfTrack() if abs(x.pdgId())==11 else x.innerTrack()).normalizedChi2(), help="Inner track normalized chi2"),
89  # Extra muon ID variables
90  NTupleVariable("nStations", lambda lepton : lepton.numberOfMatchedStations() if abs(lepton.pdgId()) == 13 else 4, help="Number of matched muons stations (4 for electrons)"),
91  NTupleVariable("caloCompatibility", lambda lepton : lepton.caloCompatibility() if abs(lepton.pdgId()) == 13 else 0, help="Calorimetric compatibility"),
92  NTupleVariable("globalTrackChi2", lambda lepton : lepton.globalTrack().normalizedChi2() if abs(lepton.pdgId()) == 13 and lepton.globalTrack().isNonnull() else 0, help="Global track normalized chi2"),
93  NTupleVariable("trkKink", lambda lepton : lepton.combinedQuality().trkKink if abs(lepton.pdgId()) == 13 else 0, help="Tracker kink-finder"),
94  NTupleVariable("segmentCompatibility", lambda lepton : lepton.segmentCompatibility() if abs(lepton.pdgId()) == 13 else 0, help="Segment-based compatibility"),
95  NTupleVariable("chi2LocalPosition", lambda lepton : lepton.combinedQuality().chi2LocalPosition if abs(lepton.pdgId()) == 13 else 0, help="Tracker-Muon matching in position"),
96  NTupleVariable("chi2LocalMomentum", lambda lepton : lepton.combinedQuality().chi2LocalMomentum if abs(lepton.pdgId()) == 13 else 0, help="Tracker-Muon matching in momentum"),
97  NTupleVariable("glbTrackProbability", lambda lepton : lepton.combinedQuality().glbTrackProbability if abs(lepton.pdgId()) == 13 else 0, help="Global track pseudo-probability"),
98  # Extra electron ID variables
99  NTupleVariable("sigmaIEtaIEta", lambda x : x.full5x5_sigmaIetaIeta() if abs(x.pdgId())==11 else 0, help="Electron sigma(ieta ieta), with full5x5 cluster shapes"),
100  NTupleVariable("dEtaScTrkIn", lambda x : x.deltaEtaSuperClusterTrackAtVtx() if abs(x.pdgId())==11 else 0, help="Electron deltaEtaSuperClusterTrackAtVtx (without absolute value!)"),
101  NTupleVariable("dPhiScTrkIn", lambda x : x.deltaPhiSuperClusterTrackAtVtx() if abs(x.pdgId())==11 else 0, help="Electron deltaPhiSuperClusterTrackAtVtx (without absolute value!)"),
102  NTupleVariable("hadronicOverEm", lambda x : x.hadronicOverEm() if abs(x.pdgId())==11 else 0, help="Electron hadronicOverEm"),
103  NTupleVariable("eInvMinusPInv", lambda x : ((1.0/x.ecalEnergy() - x.eSuperClusterOverP()/x.ecalEnergy()) if x.ecalEnergy()>0. else 9e9) if abs(x.pdgId())==11 else 0, help="Electron 1/E - 1/p (without absolute value!)"),
104  NTupleVariable("etaSc", lambda x : x.superCluster().eta() if abs(x.pdgId())==11 else -100, help="Electron supercluster pseudorapidity"),
105 ])
106 
107 
108 ##------------------------------------------
109 ## TAU
110 ##------------------------------------------
111 
112 tauType = NTupleObjectType("tau", baseObjectTypes = [ particleType ], variables = [
113  NTupleVariable("charge", lambda x : x.charge(), int),
114  NTupleVariable("decayMode", lambda x : x.decayMode(), int),
115  NTupleVariable("idDecayMode", lambda x : x.idDecayMode, int),
116  NTupleVariable("idDecayModeNewDMs", lambda x : x.idDecayModeNewDMs, int),
117  NTupleVariable("dxy", lambda x : x.dxy(), help="d_{xy} of lead track with respect to PV, in cm (with sign)"),
118  NTupleVariable("dz", lambda x : x.dz() , help="d_{z} of lead track with respect to PV, in cm (with sign)"),
119  NTupleVariable("idMVA", lambda x : x.idMVA, int, help="1,2,3,4,5,6 if the tau passes the very loose to very very tight WP of the MVA3oldDMwLT discriminator"),
120  NTupleVariable("idMVANewDM", lambda x : x.idMVANewDM, int, help="1,2,3,4,5,6 if the tau passes the very loose to very very tight WP of the MVA3newDMwLT discriminator"),
121  NTupleVariable("idCI3hit", lambda x : x.idCI3hit, int, help="1,2,3 if the tau passes the loose, medium, tight WP of the By<X>CombinedIsolationDBSumPtCorr3Hits discriminator"),
122  NTupleVariable("idAntiMu", lambda x : x.idAntiMu, int, help="1,2 if the tau passes the loose/tight WP of the againstMuon<X>3 discriminator"),
123  NTupleVariable("idAntiE", lambda x : x.idAntiE, int, help="1,2,3,4,5 if the tau passes the v loose, loose, medium, tight, v tight WP of the againstElectron<X>MVA5 discriminator"),
124  NTupleVariable("isoCI3hit", lambda x : x.tauID("byCombinedIsolationDeltaBetaCorrRaw3Hits"), help="byCombinedIsolationDeltaBetaCorrRaw3Hits raw output discriminator"),
125  # MC-match info
126  NTupleVariable("mcMatchId", lambda x : getattr(x, 'mcMatchId', -99), int, mcOnly=True, help="Match to source from hard scatter (pdgId of heaviest particle in chain, 25 for H, 6 for t, 23/24 for W/Z), zero if non-prompt or fake"),
127 ])
128 
129 ##------------------------------------------
130 ## ISOTRACK
131 ##------------------------------------------
132 
133 isoTrackType = NTupleObjectType("isoTrack", baseObjectTypes = [ particleType ], variables = [
134  NTupleVariable("charge", lambda x : x.charge(), int),
135  NTupleVariable("dz", lambda x : x.dz() , help="d_{z} of lead track with respect to PV, in cm (with sign)"),
136  NTupleVariable("absIso", lambda x : x.absIso, float, mcOnly=False, help="abs charged iso with condition for isolation such that Min(0.2*pt, 8 GeV)"),
137  NTupleVariable("mcMatchId", lambda x : getattr(x, 'mcMatchId', -99), int, mcOnly=True, help="Match to source from hard scatter (pdgId of heaviest particle in chain, 25 for H, 6 for t, 23/24 for W/Z), zero if non-prompt or fake"),
138 ])
139 
140 
141 ##------------------------------------------
142 ## PHOTON
143 ##------------------------------------------
144 
145 photonType = NTupleObjectType("gamma", baseObjectTypes = [ particleType ], variables = [
146  NTupleVariable("idCutBased", lambda x : x.idCutBased, int, help="1,2,3 if the gamma passes the loose, medium, tight WP of PhotonCutBasedID"),
147  NTupleVariable("hOverE", lambda x : x.hOVERe(), float, help="hoverE for photons"),
148  NTupleVariable("r9", lambda x : x.r9(), float, help="r9 for photons"),
149  NTupleVariable("sigmaIetaIeta", lambda x : x.sigmaIetaIeta(), float, help="sigmaIetaIeta for photons"),
150  #NTupleVariable("chHadIso", lambda x : x.chargedHadronIso(), float, help="chargedHadronIsolation for photons"),
151  #NTupleVariable("neuHadIso", lambda x : x.neutralHadronIso(), float, help="neutralHadronIsolation for photons"),
152  #NTupleVariable("phIso", lambda x : x.photonIso(), float, help="gammaIsolation for photons"),
153  NTupleVariable("chHadIso", lambda x : x.recoChargedHadronIso(), float, help="chargedHadronIsolation for photons (reco::Photon method, deltaR = 0.3)"),
154  NTupleVariable("chHadIso04", lambda x : x.chargedHadronIso(), float, help="chargedHadronIsolation for photons (PAT method, deltaR = 0.4)"),
155  NTupleVariable("neuHadIso", lambda x : x.recoNeutralHadronIso(), float, help="neutralHadronIsolation for photons"),
156  NTupleVariable("phIso", lambda x : x.recoPhotonIso(), float, help="gammaIsolation for photons"),
157  NTupleVariable("mcMatchId", lambda x : getattr(x, 'mcMatchId', -99), int, mcOnly=True, help="Match to source from hard scatter (pdgId of heaviest particle in chain, 25 for H, 6 for t, 23/24 for W/Z), zero if non-prompt or fake"),
158  NTupleVariable("mcPt", lambda x : x.mcGamma.pt() if getattr(x,"mcGamma",None) else 0., mcOnly=True, help="p_{T} of associated gen photon"),
159 ])
160 
161 ##------------------------------------------
162 ## JET
163 ##------------------------------------------
164 
165 jetType = NTupleObjectType("jet", baseObjectTypes = [ fourVectorType ], variables = [
166  NTupleVariable("id", lambda x : x.jetID("POG_PFID") , int, mcOnly=False,help="POG Loose jet ID"),
167  NTupleVariable("puId", lambda x : getattr(x, 'puJetIdPassed', -99), int, mcOnly=False, help="puId (full MVA, loose WP, 5.3.X training on AK5PFchs: the only thing that is available now)"),
168  NTupleVariable("btagCSV", lambda x : x.btag('pfCombinedInclusiveSecondaryVertexV2BJetTags'), help="CSV-IVF v2 discriminator"),
169  NTupleVariable("btagCMVA", lambda x : x.btag('pfCombinedMVABJetTags'), help="CMVA discriminator"),
170  NTupleVariable("rawPt", lambda x : x.pt() * x.rawFactor(), help="p_{T} before JEC"),
171  NTupleVariable("mcPt", lambda x : x.mcJet.pt() if getattr(x,"mcJet",None) else 0., mcOnly=True, help="p_{T} of associated gen jet"),
172  NTupleVariable("mcFlavour", lambda x : x.partonFlavour(), int, mcOnly=True, help="parton flavour (physics definition, i.e. including b's from shower)"),
173  NTupleVariable("mcMatchId", lambda x : getattr(x, 'mcMatchId', -99), int, mcOnly=True, help="Match to source from hard scatter (pdgId of heaviest particle in chain, 25 for H, 6 for t, 23/24 for W/Z), zero if non-prompt or fake"),
174 ])
175 jetTypeExtra = NTupleObjectType("jetExtra", baseObjectTypes = [ jetType ], variables = [
176  NTupleVariable("area", lambda x : x.jetArea(), help="Catchment area of jet"),
177  # QG variables:
178  NTupleVariable("qgl", lambda x : getattr(x,'qgl', 0) , float, mcOnly=False,help="QG Likelihood"),
179  NTupleVariable("ptd", lambda x : getattr(x,'ptd', 0), float, mcOnly=False,help="QG input variable: ptD"),
180  NTupleVariable("axis2", lambda x : getattr(x,'axis2', 0) , float, mcOnly=False,help="QG input variable: axis2"),
181  NTupleVariable("mult", lambda x : getattr(x,'mult', 0) , int, mcOnly=False,help="QG input variable: total multiplicity"),
182  NTupleVariable("partonId", lambda x : getattr(x,'partonId', 0), int, mcOnly=True, help="parton flavour (manually matching to status 23 particles)"),
183  NTupleVariable("partonMotherId", lambda x : getattr(x,'partonMotherId', 0), int, mcOnly=True, help="parton flavour (manually matching to status 23 particles)"),
184  NTupleVariable("nLeptons", lambda x : len(x.leptons) if hasattr(x,'leptons') else 0 , float, mcOnly=False,help="Number of associated leptons"),
185 ])
186 
187 
188 ##------------------------------------------
189 ## MET
190 ##------------------------------------------
191 
192 metType = NTupleObjectType("met", baseObjectTypes = [ fourVectorType ], variables = [
193  NTupleVariable("sumEt", lambda x : x.sumEt() ),
194  NTupleVariable("genPt", lambda x : x.genMET().pt() , mcOnly=True ),
195  NTupleVariable("genPhi", lambda x : x.genMET().phi(), mcOnly=True ),
196  NTupleVariable("genEta", lambda x : x.genMET().eta(), mcOnly=True ),
197 ])
198 
199 ##------------------------------------------
200 ## GENPARTICLE
201 ##------------------------------------------
202 
203 genParticleType = NTupleObjectType("genParticle", baseObjectTypes = [ particleType ], mcOnly=True, variables = [
204  NTupleVariable("charge", lambda x : x.threeCharge()/3.0, float),
205  NTupleVariable("status", lambda x : x.status(),int),
206 ])
207 genParticleWithMotherId = NTupleObjectType("genParticleWithMotherId", baseObjectTypes = [ genParticleType ], mcOnly=True, variables = [
208  NTupleVariable("motherId", lambda x : x.mother(0).pdgId() if x.mother(0) else 0, int, help="pdgId of the mother of the particle"),
209  NTupleVariable("grandmotherId", lambda x : x.mother(0).mother(0).pdgId() if x.mother(0) and x.mother(0).mother(0) else 0, int, help="pdgId of the grandmother of the particle")
210 ])
211 genParticleWithAncestryType = NTupleObjectType("genParticleWithAncestry", baseObjectTypes = [ genParticleType ], mcOnly=True, variables = [
212  NTupleVariable("motherId", lambda x : x.motherId, int, help="pdgId of the mother of the particle"),
213  NTupleVariable("grandmotherId", lambda x : x.grandmotherId, int, help="pdgId of the grandmother of the particle"),
214  NTupleVariable("sourceId", lambda x : x.sourceId, int, help="origin of the particle (heaviest ancestor): 6=t, 25=h, 23/24=W/Z"),
215 ])
216 genParticleWithLinksType = NTupleObjectType("genParticleWithLinks", baseObjectTypes = [ genParticleWithAncestryType ], mcOnly=True, variables = [
217  NTupleVariable("motherIndex", lambda x : x.motherIndex, int, help="index of the mother in the generatorSummary")
218 ])
219 
T eta() const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Definition: DDAxes.h:10