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");
98 unsigned int nJet = srcJet->size();
99 unsigned int nLep = srcLep->size();
101 std::vector<float> ptRatio(nLep, -1);
102 std::vector<float> ptRel(nLep, -1);
103 std::vector<float> jetNDauChargedMVASel(nLep, 0);
106 const auto&
pv = (*srcVtx)[0];
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);
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;
125 fillerRatio.
insert(srcLep, ptRatio.begin(), ptRatio.end());
131 fillerRel.
insert(srcLep, ptRel.begin(), ptRel.end());
137 fillerNDau.
insert(srcLep, jetNDauChargedMVASel.begin(), jetNDauChargedMVASel.end());
139 iEvent.
put(
std::move(jetNDauChargedMVASelV),
"jetNDauChargedMVASel");
143 fillerjetForLepJetVar.
insert(srcLep, jetForLepJetVar.begin(), jetForLepJetVar.end());
144 fillerjetForLepJetVar.
fill();
145 iEvent.
put(
std::move(jetForLepJetVarV),
"jetForLepJetVar");
148 template <
typename T>
152 auto rawp4 = jet->correctedP4(
"Uncorrected");
153 auto lepp4 = lep->p4();
155 if ((rawp4 - lepp4).
R() < 1
e-4)
156 return std::tuple<float, float, float>(1.0, 0.0, 0.0);
158 auto l1corrFactor = jet->jecFactor(
"L1FastJet") / jet->jecFactor(
"Uncorrected");
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();
164 unsigned int jndau = 0;
165 for (
const auto& _d : jet->daughterPtrVector()) {
167 if (
d->charge() == 0)
169 if (
d->fromPV() <= 1)
173 if (!(
d->hasTrackDetails()))
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)
181 return std::tuple<float, float, float>(ptratio, ptrel, float(jndau));
185 template <
typename T>
192 desc.
add<
edm::InputTag>(
"srcVtx")->setComment(
"primary vertex input collection");
197 modname +=
"Electron";
198 modname +=
"JetVarProducer";
199 descriptions.
add(modname, desc);
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
#define DEFINE_FWK_MODULE(type)
void insert(const H &h, I begin, I end)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::tuple< float, float, float > calculatePtRatioRel(edm::Ptr< reco::Candidate > lep, edm::Ptr< pat::Jet > jet, const reco::Vertex &vtx) const
const Point & position() const
position
LeptonJetVarProducer< pat::Electron > ElectronJetVarProducer
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::EDGetTokenT< std::vector< reco::Vertex > > srcVtx_
bool matchByCommonSourceCandidatePtr(const C1 &c1, const C2 &c2)
~LeptonJetVarProducer() override
ParameterDescriptionBase * add(U const &iLabel, T const &value)
LeptonJetVarProducer(const edm::ParameterSet &iConfig)
Analysis-level electron class.
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::EDGetTokenT< edm::View< pat::Jet > > srcJet_
Analysis-level muon class.
LeptonJetVarProducer< pat::Muon > MuonJetVarProducer
edm::EDGetTokenT< edm::View< T > > srcLep_