CMS 3D CMS Logo

LeptonJetVarProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: PhysicsTools/NanoAOD
4 // Class: LeptonJetVarProducer
5 //
13 //
14 // Original Author: Marco Peruzzi
15 // Created: Tue, 05 Sep 2017 12:24:38 GMT
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
25 
28 
31 
36 
39 
41 
42 //
43 // class declaration
44 //
45 
46 template <typename T>
48 public:
49  explicit LeptonJetVarProducer(const edm::ParameterSet& iConfig)
50  : srcJet_(consumes<edm::View<pat::Jet>>(iConfig.getParameter<edm::InputTag>("srcJet"))),
51  srcLep_(consumes<edm::View<T>>(iConfig.getParameter<edm::InputTag>("srcLep"))),
52  srcVtx_(consumes<std::vector<reco::Vertex>>(iConfig.getParameter<edm::InputTag>("srcVtx"))) {
53  produces<edm::ValueMap<float>>("ptRatio");
54  produces<edm::ValueMap<float>>("ptRel");
55  produces<edm::ValueMap<float>>("jetNDauChargedMVASel");
56  produces<edm::ValueMap<reco::CandidatePtr>>("jetForLepJetVar");
57  }
58  ~LeptonJetVarProducer() override{};
59 
60  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
61 
62 private:
63  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
64 
65  std::tuple<float, float, float> calculatePtRatioRel(edm::Ptr<reco::Candidate> lep,
67  const reco::Vertex& vtx) const;
68 
69  // ----------member data ---------------------------
70 
74 };
75 
76 //
77 // constants, enums and typedefs
78 //
79 
80 //
81 // static data member definitions
82 //
83 
84 //
85 // member functions
86 //
87 
88 // ------------ method called to produce the data ------------
89 template <typename T>
92  iEvent.getByToken(srcJet_, srcJet);
94  iEvent.getByToken(srcLep_, srcLep);
96  iEvent.getByToken(srcVtx_, srcVtx);
97 
98  unsigned int nJet = srcJet->size();
99  unsigned int nLep = srcLep->size();
100 
101  std::vector<float> ptRatio(nLep, -1);
102  std::vector<float> ptRel(nLep, -1);
103  std::vector<float> jetNDauChargedMVASel(nLep, 0);
104  std::vector<reco::CandidatePtr> jetForLepJetVar(nLep, reco::CandidatePtr());
105 
106  const auto& pv = (*srcVtx)[0];
107 
108  for (unsigned int il = 0; il < nLep; il++) {
109  for (unsigned int ij = 0; ij < nJet; ij++) {
110  auto lep = srcLep->ptrAt(il);
111  auto jet = srcJet->ptrAt(ij);
112  if (matchByCommonSourceCandidatePtr(*lep, *jet)) {
113  auto res = calculatePtRatioRel(lep, jet, pv);
114  ptRatio[il] = std::get<0>(res);
115  ptRel[il] = std::get<1>(res);
116  jetNDauChargedMVASel[il] = std::get<2>(res);
117  jetForLepJetVar[il] = jet;
118  break; // take leading jet with shared source candidates
119  }
120  }
121  }
122 
123  std::unique_ptr<edm::ValueMap<float>> ptRatioV(new edm::ValueMap<float>());
124  edm::ValueMap<float>::Filler fillerRatio(*ptRatioV);
125  fillerRatio.insert(srcLep, ptRatio.begin(), ptRatio.end());
126  fillerRatio.fill();
127  iEvent.put(std::move(ptRatioV), "ptRatio");
128 
129  std::unique_ptr<edm::ValueMap<float>> ptRelV(new edm::ValueMap<float>());
130  edm::ValueMap<float>::Filler fillerRel(*ptRelV);
131  fillerRel.insert(srcLep, ptRel.begin(), ptRel.end());
132  fillerRel.fill();
133  iEvent.put(std::move(ptRelV), "ptRel");
134 
135  std::unique_ptr<edm::ValueMap<float>> jetNDauChargedMVASelV(new edm::ValueMap<float>());
136  edm::ValueMap<float>::Filler fillerNDau(*jetNDauChargedMVASelV);
137  fillerNDau.insert(srcLep, jetNDauChargedMVASel.begin(), jetNDauChargedMVASel.end());
138  fillerNDau.fill();
139  iEvent.put(std::move(jetNDauChargedMVASelV), "jetNDauChargedMVASel");
140 
141  std::unique_ptr<edm::ValueMap<reco::CandidatePtr>> jetForLepJetVarV(new edm::ValueMap<reco::CandidatePtr>());
142  edm::ValueMap<reco::CandidatePtr>::Filler fillerjetForLepJetVar(*jetForLepJetVarV);
143  fillerjetForLepJetVar.insert(srcLep, jetForLepJetVar.begin(), jetForLepJetVar.end());
144  fillerjetForLepJetVar.fill();
145  iEvent.put(std::move(jetForLepJetVarV), "jetForLepJetVar");
146 }
147 
148 template <typename T>
151  const reco::Vertex& vtx) const {
152  auto rawp4 = jet->correctedP4("Uncorrected");
153  auto lepp4 = lep->p4();
154 
155  if ((rawp4 - lepp4).R() < 1e-4)
156  return std::tuple<float, float, float>(1.0, 0.0, 0.0);
157 
158  auto l1corrFactor = jet->jecFactor("L1FastJet") / jet->jecFactor("Uncorrected");
159 
160  auto jetp4 = (rawp4 - lepp4 * (1.0 / l1corrFactor)) * (jet->pt() / rawp4.pt()) + lepp4;
161  auto ptratio = lepp4.pt() / jetp4.pt();
162  auto ptrel = lepp4.Vect().Cross((jetp4 - lepp4).Vect().Unit()).R();
163 
164  unsigned int jndau = 0;
165  for (const auto& _d : jet->daughterPtrVector()) {
166  const auto d = dynamic_cast<const pat::PackedCandidate*>(_d.get());
167  if (d->charge() == 0)
168  continue;
169  if (d->fromPV() <= 1)
170  continue;
171  if (deltaR(*d, *lep) > 0.4)
172  continue;
173  if (!(d->hasTrackDetails()))
174  continue;
175  auto tk = d->pseudoTrack();
176  if (tk.pt() > 1 && tk.hitPattern().numberOfValidHits() >= 8 && tk.hitPattern().numberOfValidPixelHits() >= 2 &&
177  tk.normalizedChi2() < 5 && fabs(tk.dxy(vtx.position())) < 0.2 && fabs(tk.dz(vtx.position())) < 17)
178  jndau++;
179  }
180 
181  return std::tuple<float, float, float>(ptratio, ptrel, float(jndau));
182 }
183 
184 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
185 template <typename T>
187  //The following says we do not know what parameters are allowed so do no validation
188  // Please change this to state exactly what you do use, even if it is no parameters
190  desc.add<edm::InputTag>("srcJet")->setComment("jet input collection");
191  desc.add<edm::InputTag>("srcLep")->setComment("lepton input collection");
192  desc.add<edm::InputTag>("srcVtx")->setComment("primary vertex input collection");
194  if (typeid(T) == typeid(pat::Muon))
195  modname += "Muon";
196  else if (typeid(T) == typeid(pat::Electron))
197  modname += "Electron";
198  modname += "JetVarProducer";
199  descriptions.add(modname, desc);
200 }
201 
204 
205 //define this as a plug-in
edm::StreamID
Definition: StreamID.h:30
edm::helper::Filler::insert
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
sistrip::View
View
Definition: ConstantsForView.h:26
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
jetAnalyzer_cff.srcVtx
srcVtx
Definition: jetAnalyzer_cff.py:41
Muon.h
electrons_cff.ptRatio
ptRatio
Definition: electrons_cff.py:203
matchByCommonSourceCandidatePtr
bool matchByCommonSourceCandidatePtr(const C1 &c1, const C2 &c2)
Definition: MatchingUtils.h:9
edm::helper::Filler::fill
void fill()
Definition: ValueMap.h:65
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
pat::Muon
Analysis-level muon class.
Definition: Muon.h:51
edm::Handle
Definition: AssociativeIterator.h:50
electrons_cff.ptRel
ptRel
Definition: electrons_cff.py:204
electrons_cff.jetForLepJetVar
jetForLepJetVar
Definition: electrons_cff.py:239
MakerMacros.h
LeptonJetVarProducer
Definition: LeptonJetVarProducer.cc:47
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Jet
Definition: Jet.py:1
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
LeptonJetVarProducer::LeptonJetVarProducer
LeptonJetVarProducer(const edm::ParameterSet &iConfig)
Definition: LeptonJetVarProducer.cc:49
VertexCompositePtrCandidate.h
ElectronJetVarProducer
LeptonJetVarProducer< pat::Electron > ElectronJetVarProducer
Definition: LeptonJetVarProducer.cc:203
LeptonJetVarProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: LeptonJetVarProducer.cc:186
electrons_cff.jetNDauChargedMVASel
jetNDauChargedMVASel
Definition: electrons_cff.py:205
PbPb_ZMuSkimMuonDPG_cff.deltaR
deltaR
Definition: PbPb_ZMuSkimMuonDPG_cff.py:63
edm::global::EDProducer
Definition: EDProducer.h:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
badGlobalMuonTaggersAOD_cff.vtx
vtx
Definition: badGlobalMuonTaggersAOD_cff.py:5
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
Vertex.h
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
LeptonJetVarProducer::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition: LeptonJetVarProducer.cc:90
Event.h
MuonJetVarProducer
LeptonJetVarProducer< pat::Muon > MuonJetVarProducer
Definition: LeptonJetVarProducer.cc:202
MetAnalyzer.pv
def pv(vc)
Definition: MetAnalyzer.py:7
iEvent
int iEvent
Definition: GenABIO.cc:224
MatchingUtils.h
edm::EventSetup
Definition: EventSetup.h:57
pat
Definition: HeavyIon.h:7
electrons_cff.srcLep
srcLep
Definition: electrons_cff.py:158
LeptonJetVarProducer::~LeptonJetVarProducer
~LeptonJetVarProducer() override
Definition: LeptonJetVarProducer.cc:58
Jet.h
res
Definition: Electron.h:6
edm::Ptr< reco::Candidate >
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
HltBtagValidation_cff.Vertex
Vertex
Definition: HltBtagValidation_cff.py:32
Frameworkfwd.h
T
long double T
Definition: Basic3DVectorLD.h:48
metsig::jet
Definition: SignAlgoResolutions.h:47
edm::ValueMap< float >
LeptonJetVarProducer::srcJet_
edm::EDGetTokenT< edm::View< pat::Jet > > srcJet_
Definition: LeptonJetVarProducer.cc:71
electrons_cff.srcJet
srcJet
Definition: electrons_cff.py:157
LeptonJetVarProducer::srcVtx_
edm::EDGetTokenT< std::vector< reco::Vertex > > srcVtx_
Definition: LeptonJetVarProducer.cc:73
reco::Candidate::p4
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector
Electron.h
ztail.d
d
Definition: ztail.py:151
edm::helper::Filler
Definition: ValueMap.h:22
pat::Electron
Analysis-level electron class.
Definition: Electron.h:51
LeptonJetVarProducer::calculatePtRatioRel
std::tuple< float, float, float > calculatePtRatioRel(edm::Ptr< reco::Candidate > lep, edm::Ptr< pat::Jet > jet, const reco::Vertex &vtx) const
Definition: LeptonJetVarProducer.cc:149
View.h
ParameterSet.h
edm::EDConsumerBase::consumes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: EDConsumerBase.h:126
EDProducer.h
edm::Event
Definition: Event.h:73
LeptonJetVarProducer::srcLep_
edm::EDGetTokenT< edm::View< T > > srcLep_
Definition: LeptonJetVarProducer.cc:72
StreamID.h
dttmaxenums::R
Definition: DTTMax.h:29
timingPdfMaker.modname
modname
Definition: timingPdfMaker.py:218
edm::InputTag
Definition: InputTag.h:15
reco::Vertex
Definition: Vertex.h:35
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37