CMS 3D CMS Logo

LeptonInJetProducer.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 
4 // user include files
7 
10 
13 
16 
21 
23 #include "fastjet/PseudoJet.hh"
24 #include <fastjet/JetDefinition.hh>
25 #include <TLorentzVector.h>
26 #include <TMath.h>
27 
29 
30 template <typename T>
32 public:
33  explicit LeptonInJetProducer(const edm::ParameterSet &iConfig)
34  : srcJet_(consumes<edm::View<pat::Jet>>(iConfig.getParameter<edm::InputTag>("src"))),
35  srcEle_(consumes<edm::View<pat::Electron>>(iConfig.getParameter<edm::InputTag>("srcEle"))),
36  srcMu_(consumes<edm::View<pat::Muon>>(iConfig.getParameter<edm::InputTag>("srcMu"))) {
37  produces<edm::ValueMap<float>>("lsf3");
38  produces<edm::ValueMap<int>>("muIdx3SJ");
39  produces<edm::ValueMap<int>>("eleIdx3SJ");
40  }
41  ~LeptonInJetProducer() override{};
42 
43  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
44 
45 private:
46  void produce(edm::StreamID, edm::Event &, edm::EventSetup const &) const override;
47 
48  static bool orderPseudoJet(fastjet::PseudoJet j1, fastjet::PseudoJet j2);
49  std::tuple<float, float> calculateLSF(std::vector<fastjet::PseudoJet> iCParticles,
50  std::vector<fastjet::PseudoJet> &ljets,
51  float ilPt,
52  float ilEta,
53  float ilPhi,
54  int ilId,
55  double dr,
56  int nsj) const;
57 
61 };
62 
63 // ------------ method called to produce the data ------------
64 template <typename T>
66  // needs jet collection (srcJet), leptons collection
68  iEvent.getByToken(srcJet_, srcJet);
70  iEvent.getByToken(srcEle_, srcEle);
72  iEvent.getByToken(srcMu_, srcMu);
73 
74  unsigned int nJet = srcJet->size();
75  unsigned int nEle = srcEle->size();
76  unsigned int nMu = srcMu->size();
77 
78  std::vector<float> vlsf3;
79  std::vector<int> vmuIdx3SJ;
80  std::vector<int> veleIdx3SJ;
81 
82  int ele_pfmatch_index = -1;
83  int mu_pfmatch_index = -1;
84 
85  // Find leptons in jets
86  for (unsigned int ij = 0; ij < nJet; ij++) {
87  const pat::Jet &itJet = (*srcJet)[ij];
88  if (itJet.pt() <= 10)
89  continue;
90  std::vector<fastjet::PseudoJet> lClusterParticles;
91  float lepPt(-1), lepEta(-1), lepPhi(-1);
92  int lepId(-1);
93  for (auto const &d : itJet.daughterPtrVector()) {
94  fastjet::PseudoJet p(d->px(), d->py(), d->pz(), d->energy());
95  lClusterParticles.emplace_back(p);
96  }
97 
98  // match to leading and closest electron or muon
99  double dRmin(0.8), dRele(999), dRmu(999), dRtmp(999);
100  for (unsigned int il(0); il < nEle; il++) {
101  auto itLep = srcEle->ptrAt(il);
102  if (matchByCommonSourceCandidatePtr(*itLep, itJet)) {
103  dRtmp = reco::deltaR(itJet.eta(), itJet.phi(), itLep->eta(), itLep->phi());
104  if (dRtmp < dRmin && dRtmp < dRele && itLep->pt() > lepPt) {
105  lepPt = itLep->pt();
106  lepEta = itLep->eta();
107  lepPhi = itLep->phi();
108  lepId = 11;
109  ele_pfmatch_index = il;
110  dRele = dRtmp;
111  break;
112  }
113  }
114  }
115  for (unsigned int il(0); il < nMu; il++) {
116  auto itLep = srcMu->ptrAt(il);
117  if (matchByCommonSourceCandidatePtr(*itLep, itJet)) {
118  dRtmp = reco::deltaR(itJet.eta(), itJet.phi(), itLep->eta(), itLep->phi());
119  if (dRtmp < dRmin && dRtmp < dRele && dRtmp < dRmu && itLep->pt() > lepPt) {
120  lepPt = itLep->pt();
121  lepEta = itLep->eta();
122  lepPhi = itLep->phi();
123  lepId = 13;
124  ele_pfmatch_index = -1;
125  mu_pfmatch_index = il;
126  dRmu = dRtmp;
127  break;
128  }
129  }
130  }
131 
132  std::vector<fastjet::PseudoJet> psub_3;
133  std::sort(lClusterParticles.begin(), lClusterParticles.end(), orderPseudoJet);
134  auto lsf_3 = calculateLSF(lClusterParticles, psub_3, lepPt, lepEta, lepPhi, lepId, 2.0, 3);
135  vlsf3.push_back(std::get<0>(lsf_3));
136  veleIdx3SJ.push_back(ele_pfmatch_index);
137  vmuIdx3SJ.push_back(mu_pfmatch_index);
138  }
139 
140  // Filling table
141  std::unique_ptr<edm::ValueMap<float>> lsf3V(new edm::ValueMap<float>());
142  edm::ValueMap<float>::Filler fillerlsf3(*lsf3V);
143  fillerlsf3.insert(srcJet, vlsf3.begin(), vlsf3.end());
144  fillerlsf3.fill();
145  iEvent.put(std::move(lsf3V), "lsf3");
146 
147  std::unique_ptr<edm::ValueMap<int>> muIdx3SJV(new edm::ValueMap<int>());
148  edm::ValueMap<int>::Filler fillermuIdx3SJ(*muIdx3SJV);
149  fillermuIdx3SJ.insert(srcJet, vmuIdx3SJ.begin(), vmuIdx3SJ.end());
150  fillermuIdx3SJ.fill();
151  iEvent.put(std::move(muIdx3SJV), "muIdx3SJ");
152 
153  std::unique_ptr<edm::ValueMap<int>> eleIdx3SJV(new edm::ValueMap<int>());
154  edm::ValueMap<int>::Filler fillereleIdx3SJ(*eleIdx3SJV);
155  fillereleIdx3SJ.insert(srcJet, veleIdx3SJ.begin(), veleIdx3SJ.end());
156  fillereleIdx3SJ.fill();
157  iEvent.put(std::move(eleIdx3SJV), "eleIdx3SJ");
158 }
159 
160 template <typename T>
161 bool LeptonInJetProducer<T>::orderPseudoJet(fastjet::PseudoJet j1, fastjet::PseudoJet j2) {
162  return j1.perp2() > j2.perp2();
163 }
164 
165 template <typename T>
166 std::tuple<float, float> LeptonInJetProducer<T>::calculateLSF(std::vector<fastjet::PseudoJet> iCParticles,
167  std::vector<fastjet::PseudoJet> &lsubjets,
168  float ilPt,
169  float ilEta,
170  float ilPhi,
171  int ilId,
172  double dr,
173  int nsj) const {
174  float lsf(-1), lmd(-1);
175  if (ilPt > 0 && (ilId == 11 || ilId == 13)) {
176  TLorentzVector ilep;
177  if (ilId == 11)
178  ilep.SetPtEtaPhiM(ilPt, ilEta, ilPhi, 0.000511);
179  if (ilId == 13)
180  ilep.SetPtEtaPhiM(ilPt, ilEta, ilPhi, 0.105658);
181  fastjet::JetDefinition lCJet_def(fastjet::kt_algorithm, dr);
182  fastjet::ClusterSequence lCClust_seq(iCParticles, lCJet_def);
183  if (dr > 0.5) {
184  lsubjets = sorted_by_pt(lCClust_seq.exclusive_jets_up_to(nsj));
185  } else {
186  lsubjets = sorted_by_pt(lCClust_seq.inclusive_jets());
187  }
188  int lId(-1);
189  double dRmin = 999.;
190  for (unsigned int i0 = 0; i0 < lsubjets.size(); i0++) {
191  double dR = reco::deltaR(lsubjets[i0].eta(), lsubjets[i0].phi(), ilep.Eta(), ilep.Phi());
192  if (dR < dRmin) {
193  dRmin = dR;
194  lId = i0;
195  }
196  }
197  if (lId != -1) {
198  TLorentzVector pVec;
199  pVec.SetPtEtaPhiM(lsubjets[lId].pt(), lsubjets[lId].eta(), lsubjets[lId].phi(), lsubjets[lId].m());
200  lsf = ilep.Pt() / pVec.Pt();
201  lmd = (ilep - pVec).M() / pVec.M();
202  }
203  }
204  return std::tuple<float, float>(lsf, lmd);
205 }
206 
207 template <typename T>
210  desc.add<edm::InputTag>("src")->setComment("jet input collection");
211  desc.add<edm::InputTag>("srcEle")->setComment("electron input collection");
212  desc.add<edm::InputTag>("srcMu")->setComment("muon input collection");
214  modname += "LepIn";
215  if (typeid(T) == typeid(pat::Jet))
216  modname += "Jet";
217  modname += "Producer";
218  descriptions.add(modname, desc);
219 }
220 
222 
223 //define this as a plug-in
ConfigurationDescriptions.h
edm::StreamID
Definition: StreamID.h:30
edm::helper::Filler::insert
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
sistrip::View
View
Definition: ConstantsForView.h:26
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
edm::EDGetTokenT
Definition: EDGetToken.h:33
Electron
Definition: Electron.py:1
edm
HLT enums.
Definition: AlignableModifier.h:19
Muon.h
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
LeptonInJetProducer::produce
void produce(edm::StreamID, edm::Event &, edm::EventSetup const &) const override
Definition: LeptonInJetProducer.cc:65
matchByCommonSourceCandidatePtr
bool matchByCommonSourceCandidatePtr(const C1 &c1, const C2 &c2)
Definition: MatchingUtils.h:9
LeptonInJetProducer::LeptonInJetProducer
LeptonInJetProducer(const edm::ParameterSet &iConfig)
Definition: LeptonInJetProducer.cc:33
jets_cff.srcMu
srcMu
Definition: jets_cff.py:197
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89281
edm::helper::Filler::fill
void fill()
Definition: ValueMap.h:65
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
reco::LeafCandidate::pt
double pt() const final
transverse momentum
Definition: LeafCandidate.h:146
LeptonInJetProducer::orderPseudoJet
static bool orderPseudoJet(fastjet::PseudoJet j1, fastjet::PseudoJet j2)
Definition: LeptonInJetProducer.cc:161
edm::Handle
Definition: AssociativeIterator.h:50
Muon
Definition: Muon.py:1
LeptonInJetProducer::~LeptonInJetProducer
~LeptonInJetProducer() override
Definition: LeptonInJetProducer.cc:41
MakerMacros.h
pat::Jet
Analysis-level calorimeter jet class.
Definition: Jet.h:77
LeptonInJetProducer::srcEle_
edm::EDGetTokenT< edm::View< pat::Electron > > srcEle_
Definition: LeptonInJetProducer.cc:59
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
PVValHelper::eta
Definition: PVValidationHelpers.h:70
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
ParameterSetDescription.h
edm::global::EDProducer
Definition: EDProducer.h:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
reco::LeafCandidate::eta
double eta() const final
momentum pseudorapidity
Definition: LeafCandidate.h:152
PVValHelper::phi
Definition: PVValidationHelpers.h:69
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
PackedCandidate.h
LeptonInJetProducer
Definition: LeptonInJetProducer.cc:31
LeptonInJetProducer::srcMu_
edm::EDGetTokenT< edm::View< pat::Muon > > srcMu_
Definition: LeptonInJetProducer.cc:60
iEvent
int iEvent
Definition: GenABIO.cc:224
MatchingUtils.h
LeptonInJetProducer::calculateLSF
std::tuple< float, float > calculateLSF(std::vector< fastjet::PseudoJet > iCParticles, std::vector< fastjet::PseudoJet > &ljets, float ilPt, float ilEta, float ilPhi, int ilId, double dr, int nsj) const
Definition: LeptonInJetProducer.cc:166
edm::EventSetup
Definition: EventSetup.h:58
pat
Definition: HeavyIon.h:7
Jet.h
FlatTable.h
jets_cff.srcEle
srcEle
Definition: jets_cff.py:196
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
reco::LeafCandidate::phi
double phi() const final
momentum azimuthal angle
Definition: LeafCandidate.h:148
LepInJetProducer
LeptonInJetProducer< pat::Jet > LepInJetProducer
Definition: LeptonInJetProducer.cc:221
Frameworkfwd.h
T
long double T
Definition: Basic3DVectorLD.h:48
pat::Jet::daughterPtrVector
const reco::CompositePtrCandidate::daughters & daughterPtrVector() const override
references to daughtes
edm::ValueMap< float >
flavorHistoryFilter_cfi.dr
dr
Definition: flavorHistoryFilter_cfi.py:37
electrons_cff.srcJet
srcJet
Definition: electrons_cff.py:144
reco::deltaR
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
Electron.h
LeptonInJetProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: LeptonInJetProducer.cc:208
ztail.d
d
Definition: ztail.py:151
edm::helper::Filler
Definition: ValueMap.h:22
HGC3DClusterGenMatchSelector_cfi.dR
dR
Definition: HGC3DClusterGenMatchSelector_cfi.py:7
ParameterSet.h
edm::EDConsumerBase::consumes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: EDConsumerBase.h:155
EDProducer.h
edm::Event
Definition: Event.h:73
StreamID.h
LeptonInJetProducer::srcJet_
edm::EDGetTokenT< edm::View< pat::Jet > > srcJet_
Definition: LeptonInJetProducer.cc:58
timingPdfMaker.modname
modname
Definition: timingPdfMaker.py:218
edm::InputTag
Definition: InputTag.h:15