17 looseJetIdAlgo_(nullptr),
18 pfMEtSignInterface_(nullptr) {
23 if (jetIdSelection_string ==
"loose")
25 else if (jetIdSelection_string ==
"medium")
27 else if (jetIdSelection_string ==
"tight")
31 <<
"Invalid Configuration Parameter 'jetIdSelection' = " << jetIdSelection_string <<
" !!\n";
45 cfgPFJetIdAlgo.addParameter<
std::string>(
"quality",
"LOOSE");
55 produces<reco::PUSubMETCandInfoCollection>(
"jetInfos");
56 produces<reco::PUSubMETCandInfoCollection>(
"pfCandInfos");
67 std::vector<int>& flags,
71 std::vector<const reco::PFJet*>* pfCandidateToJetAssociations =
nullptr) {
73 if (!pfCandidateCollection.
empty()) {
74 viewProductID = pfCandidateCollection.
ptrAt(0).
id();
78 for (std::vector<reco::PFCandidatePtr>::const_iterator pfJetConstituent = pfConsts.begin();
79 pfJetConstituent != pfConsts.end();
81 std::vector<int> idxs;
82 if (!pfCandidateCollection.
empty() && pfJetConstituent->id() == viewProductID) {
83 idxs.push_back(pfJetConstituent->key());
85 bool isMatched_fast =
false;
86 if (pfJetConstituent->key() < pfCandidateCollection.
size()) {
88 double dR2 =
deltaR2((*pfJetConstituent)->p4(), pfCandidatePtr->p4());
90 idxs.push_back(pfCandidatePtr.
key());
91 isMatched_fast =
true;
95 if (!isMatched_fast) {
96 size_t numPFCandidates = pfCandidateCollection.
size();
97 for (
size_t iPFCandidate = 0; iPFCandidate < numPFCandidates; ++iPFCandidate) {
99 double dR2 =
deltaR2((*pfJetConstituent)->p4(), pfCandidatePtr->p4());
101 idxs.push_back(pfCandidatePtr.
key());
104 if (numWarnings < maxWarnings) {
106 <<
" The productIDs of PFJetConstituent and PFCandidateCollection passed as function arguments don't "
108 <<
"NOTE: The return value will be unaffected, but the code will run MUCH slower !!";
114 for (std::vector<int>::const_iterator idx = idxs.begin(); idx != idxs.end(); ++idx) {
115 if ((*idx) >= (int)flags.size())
116 flags.resize(2 * flags.size());
117 flags[*idx] |=
value;
118 if (pfCandidateToJetAssociations !=
nullptr)
119 (*pfCandidateToJetAssociations)[*idx] = &pfJet;
123 <<
" Failed to associated PFJetConstituent with index = " << pfJetConstituent->key()
124 <<
" to any PFCandidate !!";
131 LogDebug(
"produce") <<
"<NoPileUpPFMEtDataProducer::produce>:\n"
151 std::vector<int> pfCandidateFlags(pfCandidates->size());
152 std::vector<const reco::PFJet*> pfCandidateToJetAssociations(pfCandidates->size());
167 auto jetInfos = std::make_unique<reco::PUSubMETCandInfoCollection>();
168 auto pfCandInfos = std::make_unique<reco::PUSubMETCandInfoCollection>();
173 if (!jetEnOffsetCorrector)
178 size_t numJets = jets->size();
179 for (
size_t iJet = 0; iJet < numJets; ++iJet) {
184 bool passesLooseJetId = (*looseJetIdAlgo_)(*jet);
185 if (!passesLooseJetId) {
191 jetInfo.
setP4(jet->p4());
192 int jetId = (*jetIds)[
jet];
196 double jetEnergy_uncorrected = jet->chargedHadronEnergy() + jet->neutralHadronEnergy() + jet->photonEnergy() +
197 jet->electronEnergy() + jet->muonEnergy() + jet->HFHadronEnergy() +
199 double jetPx_uncorrected =
cos(jet->phi()) *
sin(jet->theta()) * jetEnergy_uncorrected;
200 double jetPy_uncorrected =
sin(jet->phi()) *
sin(jet->theta()) * jetEnergy_uncorrected;
201 double jetPz_uncorrected =
cos(jet->theta()) * jetEnergy_uncorrected;
203 jetPx_uncorrected, jetPy_uncorrected, jetPz_uncorrected, jetEnergy_uncorrected);
205 rawJet.
setP4(rawJetP4);
206 double jetNeutralEnFrac = (jetEnergy_uncorrected > 0.)
207 ? (jet->neutralEmEnergy() + jet->neutralHadronEnergy()) / jetEnergy_uncorrected
211 (jetEnOffsetCorrector) ? rawJet.
energy() * (1. - jetEnOffsetCorrector->correction(rawJet, evt, es)) : 0.);
214 jetInfos->push_back(jetInfo);
216 LogDebug(
"produce") <<
"#jetInfos = " << jetInfos->size() << std::endl;
218 for (reco::PFJetCollection::const_iterator
jet = jets->begin();
jet != jets->end(); ++
jet) {
220 setPFCandidateFlag(*
jet,
226 &pfCandidateToJetAssociations);
230 size_t numPFCandidates = pfCandidates->size();
231 for (
size_t iPFCandidate = 0; iPFCandidate < numPFCandidates; ++iPFCandidate) {
234 int idx = pfCandidatePtr.
key();
236 pfCandInfo.
setP4(pfCandidatePtr->p4());
237 pfCandInfo.
setCharge(pfCandidatePtr->charge());
246 if (pfCandidatePtr->charge() == 0)
248 else if (isHardScatterVertex_associated)
261 const reco::PFJet* jet_matched = pfCandidateToJetAssociations[idx];
270 jetResolution.
get_sigma_e() * (pfCandidatePtr->energy() / jet_matched->
energy()),
277 pfCandInfos->push_back(pfCandInfo);
280 LogDebug(
"produce") <<
"#pfCandInfos = " << pfCandInfos->size() << std::endl;
edm::EDGetTokenT< PFCandToVertexAssMap > srcPFCandToVertexAssociations_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
const int flag_isWithinSelectedJet
void produce(edm::Event &, const edm::EventSetup &) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Ptr< value_type > ptrAt(size_type i) const
#define DEFINE_FWK_MODULE(type)
T const * get() const
Returns C++ pointer to the item.
Sin< T >::type sin(const T &t)
constexpr bool isUninitialized() const noexcept
void setP4(const reco::Candidate::LorentzVector p4)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
edm::EDGetTokenT< reco::PFJetCollection > srcJetsForMEtCov_
const int flag_isWithinFakeJet
noPuUtils::reversedPFCandToVertexAssMap reversePFCandToVertexAssociation(const PFCandToVertexAssMap &)
edm::EDGetTokenT< reco::VertexCollection > srcHardScatterVertex_
Log< level::Error, false > LogError
~NoPileUpPFMEtDataProducer() override
Jets made from PFObjects.
edm::EDGetTokenT< edm::View< reco::PFCandidate > > srcPFCandidatesView_
tuple pfCandidateCollection
static bool passJetId(int flag, Id level)
const int flag_isWithinJetForMEtCov
edm::EDGetTokenT< reco::PFCandidateCollection > srcPFCandidates_
void addParameter(std::string const &name, T const &value)
Cos< T >::type cos(const T &t)
void setIsWithinJet(bool isWJ)
edm::EDGetTokenT< reco::PFJetCollection > srcJets_
double minJetPtForMEtCov_
NoPileUpPFMEtDataProducer(const edm::ParameterSet &)
PFJetIDSelectionFunctor * looseJetIdAlgo_
PFMEtSignInterfaceBase * pfMEtSignInterface_
PF Jet selector for pat::Jets.
void setPassesLooseJetId(float jetId)
void setCharge(int charge)
edm::EDGetTokenT< edm::ValueMap< int > > srcJetIds_
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
void setChargedEnFrac(float chEnF)
std::string jetEnOffsetCorrLabel_
static const JetCorrector * getJetCorrector(const std::string &fName, const edm::EventSetup &fSetup)
retrieve corrector from the event setup. troughs exception if something is missing ...
T getParameter(std::string const &) const
ProductID id() const
Accessor for product ID.
math::XYZTLorentzVector LorentzVector
Lorentz vector.
int isVertexAssociated_fast(const reco::PFCandidateRef &, const noPuUtils::reversedPFCandToVertexAssMap &, const reco::VertexCollection &, double, int &, int)
virtual std::vector< reco::PFCandidatePtr > getPFConstituents() const
get all constituents
PileupJetIdentifier::Id jetIdSelection_
Log< level::Warning, false > LogWarning
metsig::SigInputObj compResolution(const T *particle) const
void setMEtSignObj(metsig::SigInputObj msig)
void setOffsetEnCorr(float offset)
void setP4(const LorentzVector &p4) final
set 4-momentum
double energy() const final
energy