37 const static int qualityMap[8] = {1, 0, 1, 1, 4, 4, 5, 6};
71 std::vector<size_t>
idx(v.size());
72 for (
size_t i = 0;
i !=
idx.size(); ++
i)
74 std::sort(
idx.begin(),
idx.end(), [&
v](
size_t i1,
size_t i2) {
97 std::vector<edm::EDGetTokenT<edm::View<reco::Candidate>>>
SVWhiteLists_;
117 return p.Z() - v.Z() -
118 ((p.X() - v.X()) * c.
px() + (p.Y() - v.Y()) * c.
py()) * c.
pz() /
127 !iConfig.getParameter<
edm::InputTag>(
"PuppiSrc").
encode().
empty() ||
128 !iConfig.getParameter<
edm::InputTag>(
"PuppiNoLepSrc")
132 iConfig.getParameter<
edm::InputTag>(
"inputCollection"))),
134 iConfig.getParameter<
edm::InputTag>(
"inputVertices"))),
136 iConfig.getParameter<
edm::InputTag>(
"vertexAssociator"))),
138 iConfig.getParameter<
edm::InputTag>(
"vertexAssociator"))),
140 iConfig.getParameter<
edm::InputTag>(
"originalVertices"))),
142 iConfig.getParameter<
edm::InputTag>(
"originalTracks"))),
145 iConfig.getParameter<
edm::InputTag>(
"PuppiSrc"))
149 iConfig.getParameter<
edm::InputTag>(
"PuppiNoLepSrc"))
153 iConfig.getParameter<
edm::InputTag>(
"PuppiSrc"))
157 iConfig.getParameter<
edm::InputTag>(
"PuppiSrc"))
161 iConfig.getParameter<
edm::InputTag>(
"PuppiNoLepSrc"))
164 !iConfig.getParameter<
edm::InputTag>(
"chargedHadronIsolation")
168 iConfig.getParameter<
edm::InputTag>(
"chargedHadronIsolation"))),
170 iConfig.getParameter<double>(
"minPtForChargedHadronProperties")),
172 iConfig.getParameter<double>(
"minPtForTrackProperties")),
175 iConfig.getParameter<
std::vector<
int>>(
"covariancePackingSchemas")),
177 "pfCandidateTypesForHcalDepth")),
179 iConfig.getParameter<
bool>(
"storeHcalDepthEndcapOnly")),
181 std::vector<edm::InputTag> sv_tags =
183 "secondaryVerticesForWhiteList");
184 for (
auto itag : sv_tags) {
188 produces<std::vector<pat::PackedCandidate>>();
189 produces<edm::Association<pat::PackedCandidateCollection>>();
190 produces<edm::Association<reco::PFCandidateCollection>>();
194 "hcalDepthEnergyFractions");
209 std::vector<reco::CandidatePtr> puppiCandsNoLepPtrs;
216 for (
auto pup : *puppiCandsNoLep) {
217 puppiCandsNoLepPtrs.push_back(pup.sourceCandidatePtr(0));
220 std::vector<int> mappingPuppi(
usePuppi_ ? puppiCands->size() : 0);
237 std::set<unsigned int> whiteList;
238 std::set<reco::TrackRef> whiteListTk;
243 *(svWhiteListHandle.
product());
244 for (
unsigned int i = 0;
i < svWhiteList.
size();
i++) {
246 for (
unsigned int j = 0; j < svWhiteList[
i].numberOfSourceCandidatePtrs();
249 svWhiteList[
i].sourceCandidatePtr(j);
250 if (c.
id() == cands.
id())
251 whiteList.insert(c.
key());
254 for (
auto dau = svWhiteList[
i].
begin(); dau != svWhiteList[
i].
end();
258 if (chCand !=
nullptr) {
259 whiteListTk.insert(chCand->
track());
271 std::vector<pat::HcalDepthEnergyFractions> hcalDepthEnergyFractions;
272 hcalDepthEnergyFractions.reserve(cands->size());
273 std::vector<pat::HcalDepthEnergyFractions> hcalDepthEnergyFractions_Ordered;
274 hcalDepthEnergyFractions_Ordered.reserve(cands->size());
278 auto outPtrP = std::make_unique<std::vector<pat::PackedCandidate>>();
279 std::vector<int>
mapping(cands->size());
280 std::vector<int> mappingReverse(cands->size());
281 std::vector<int> mappingTk(TKOrigs->size(), -1);
283 for (
unsigned int ic = 0, nc = cands->size(); ic < nc; ++ic) {
295 for (
size_t ii = 0;
ii < PVs->size();
ii++) {
322 float ptTrk = ctrack->
pt();
323 float etaAtVtx = ctrack->
eta();
324 float phiAtVtx = ctrack->
phi();
339 etaAtVtx, phiAtVtx, cand.
pdgId(),
340 PVRefProd,
PV.key()));
341 outPtrP->back().setAssociationQuality(
345 PVOrig->trackWeight(cand.
trackRef()) > 0.5 && quality == 7) {
346 outPtrP->back().setAssociationQuality(
350 outPtrP->back().setLostInnerHits(lostHits);
353 whiteList.find(ic) != whiteList.end() ||
355 whiteListTk.find(cand.
trackRef()) != whiteListTk.end())) {
358 if (
abs(outPtrP->back().pdgId()) == 22) {
359 outPtrP->back().setTrackProperties(
363 outPtrP->back().setTrackProperties(
367 outPtrP->back().setTrackProperties(
373 if (outPtrP->back().pt() > 0.5) {
375 outPtrP->back().setTrackProperties(
379 outPtrP->back().setTrackProperties(
386 outPtrP->back().setTrackHighPurity(
390 outPtrP->back().setMuonID(cand.
muonRef()->isStandAloneMuon(),
391 cand.
muonRef()->isGlobalMuon());
396 PVpos =
PV->position();
401 cand.
phi(), cand.
pdgId(), PVRefProd,
PV.key()));
402 outPtrP->back().setAssociationQuality(
409 bool isIsolatedChargedHadron =
false;
412 *(chargedHadronIsolationHandle.
product());
413 isIsolatedChargedHadron =
416 outPtrP->back().setIsIsolatedChargedHadron(isIsolatedChargedHadron);
420 outPtrP->back().setHcalFraction(cand.
hcalEnergy() /
422 }
else if (cand.
charge() && cand.
pt() > 0.5) {
423 outPtrP->back().setHcalFraction(cand.
hcalEnergy() /
428 outPtrP->back().setHcalFraction(0);
429 outPtrP->back().setCaloFraction(0);
432 if (isIsolatedChargedHadron) {
433 outPtrP->back().setRawCaloFraction(
435 outPtrP->back().setRawHcalFraction(
438 outPtrP->back().setRawCaloFraction(0);
439 outPtrP->back().setRawHcalFraction(0);
442 std::vector<float> dummyVector;
451 fabs(outPtrP->back().eta()) >
455 std::vector<float> hcalDepthEnergyFractionTmp(
458 hcalDepthEFrac.
reset(hcalDepthEnergyFractionTmp);
461 hcalDepthEnergyFractions.push_back(hcalDepthEFrac);
468 outPtrP->back().setGoodEgamma();
475 float puppiWeightVal = (*puppiWeight)[pkref];
476 float puppiWeightNoLepVal = 0.0;
480 if (puppiWeightNoLep.
isValid()) {
482 auto pkrefPtr = pkref->sourceCandidatePtr(0);
484 bool foundNoLep =
false;
485 for (
size_t ipcnl = 0; ipcnl < puppiCandsNoLepPtrs.size(); ipcnl++) {
486 if (puppiCandsNoLepPtrs[ipcnl] == pkrefPtr) {
488 puppiWeightNoLepVal =
489 puppiCandsNoLep->at(ipcnl).pt() /
494 if (!foundNoLep || puppiWeightNoLepVal > 1) {
495 puppiWeightNoLepVal = 1.0;
498 outPtrP->back().setPuppiWeight(puppiWeightVal, puppiWeightNoLepVal);
500 mappingPuppi[((*puppiCandsMap)[pkref]).
key()] = ic;
513 auto outPtrPSorted = std::make_unique<std::vector<pat::PackedCandidate>>();
515 std::vector<size_t> reverseOrder(order.size());
516 for (
size_t i = 0, nc = cands->size();
i < nc;
i++) {
517 outPtrPSorted->push_back((*outPtrP)[order[
i]]);
518 reverseOrder[order[
i]] =
i;
519 mappingReverse[order[
i]] =
i;
520 hcalDepthEnergyFractions_Ordered.push_back(
521 hcalDepthEnergyFractions[order[i]]);
525 for (
size_t i = 0, ntk = mappingTk.size();
i < ntk;
i++) {
526 if (mappingTk[
i] >= 0)
527 mappingTk[
i] = reverseOrder[mappingTk[
i]];
530 for (
size_t i = 0, ntk = mappingPuppi.size();
i < ntk;
i++) {
531 mappingPuppi[
i] = reverseOrder[mappingPuppi[
i]];
539 std::make_unique<edm::Association<pat::PackedCandidateCollection>>(oh);
541 std::make_unique<edm::Association<reco::PFCandidateCollection>>(
cands);
544 pf2pcFiller.insert(cands, mappingReverse.begin(), mappingReverse.end());
545 pc2pfFiller.
insert(oh, order.begin(), order.end());
547 pf2pcFiller.insert(TKOrigs, mappingTk.begin(), mappingTk.end());
549 pf2pcFiller.insert(puppiCands, mappingPuppi.begin(), mappingPuppi.end());
557 auto hcalDepthEnergyFractionsV =
558 std::make_unique<edm::ValueMap<HcalDepthEnergyFractions>>();
560 fillerHcalDepthEnergyFractions(*hcalDepthEnergyFractionsV);
561 fillerHcalDepthEnergyFractions.insert(
562 cands, hcalDepthEnergyFractions_Ordered.begin(),
563 hcalDepthEnergyFractions_Ordered.end());
564 fillerHcalDepthEnergyFractions.fill();
568 "hcalDepthEnergyFractions");
BranchAliasSetterT< ProductType > produces()
declare what type of product will make and with which optional label
T getParameter(std::string const &) const
double ecalEnergy() const
return corrected Ecal energy
int pdgId() const final
PDG identifier.
const Point & referencePoint() const
Reference point on the track.
virtual double pz() const =0
z coordinate of momentum vector
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
bool isNonnull() const
Checks for non-null.
double eta() const final
momentum pseudorapidity
const PolarLorentzVector & polarP4() const final
four-momentum Lorentz vector
double rawEcalEnergy() const
return corrected Ecal energy
int covarianceSchema() const
bool hasValidHitInPixelLayer(enum PixelSubdetector::SubDetector, uint16_t layer) const
~PATPackedCandidateProducer() override
const edm::EDGetTokenT< std::vector< reco::PFCandidate > > PuppiCandsNoLep_
float mva_nothing_gamma() const
mva for gamma detection
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Sin< T >::type sin(const T &t)
void insert(const H &h, I begin, I end)
const std::array< float, 7 > & hcalDepthEnergyFractions() const
fraction of hcal energy at a given depth (index 0..6 for depth 1..7)
std::vector< Track > TrackCollection
collection of Tracks
double phi() const
azimuthal angle of momentum vector
double pt() const final
transverse momentum
std::vector< Vertex > VertexCollection
collection of Vertex objects
int charge() const final
electric charge
static const int qualityMap[8]
conversion map from quality flags used in PV association and miniAOD one
const edm::EDGetTokenT< reco::PFCandidateCollection > Cands_
key_type key() const
Accessor for product key.
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
const reco::VertexRef vertexRef() const
ProductID id() const
Accessor for product ID.
const edm::EDGetTokenT< edm::ValueMap< int > > PVAssoQuality_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
const edm::EDGetTokenT< edm::ValueMap< float > > PuppiWeightNoLep_
reco::TrackRef trackRef() const
const double minPtForTrackProperties_
const Point & vertex() const override
vertex position (overwritten by PF...)
bool isTimeValid() const
do we have a valid time information
virtual double py() const =0
y coordinate of momentum vector
int charge() const override
electric charge
PATPackedCandidateProducer(const edm::ParameterSet &)
#define DEFINE_FWK_MODULE(type)
double eta() const
pseudorapidity of momentum vector
void reset(std::vector< float > v)
double pt() const
track transverse momentum
Cos< T >::type cos(const T &t)
double energy() const final
energy
float calcDxy(float dx, float dy, float phi) const
Abs< T >::type abs(const T &t)
const bool storeChargedHadronIsolation_
const edm::EDGetTokenT< std::vector< reco::PFCandidate > > PuppiCands_
reco::TrackRef track() const override
reference to a track
static std::vector< size_t > sort_indexes(const std::vector< T > &v)
const edm::EDGetTokenT< reco::TrackCollection > TKOrigs_
const bool storeHcalDepthEndcapOnly_
const edm::EDGetTokenT< edm::ValueMap< reco::CandidatePtr > > PuppiCandsMap_
edm::Ref< VertexCollection > VertexRef
persistent reference to a Vertex
const int covarianceVersion_
reco::MuonRef muonRef() const
bool hasTrackDetails() const
Return true if a bestTrack can be extracted from this Candidate.
double dz() const
dz parameter (= dsz/cos(lambda)). This is the track z0 w.r.t (0,0,0) only if the refPoint is close to...
LostInnerHits
Enumerator specifying the.
double eta() const override
momentum pseudorapidity
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
const edm::EDGetTokenT< edm::ValueMap< bool > > ChargedHadronIsolation_
float calcDz(reco::Candidate::Point p, reco::Candidate::Point v, const reco::Candidate &c) const
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
T const * product() const
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
const std::vector< int > covariancePackingSchemas_
virtual double pt() const =0
transverse momentum
XYZPointD XYZPoint
point in space with cartesian internal representation
ProductID id() const
Accessor for product ID.
const edm::EDGetTokenT< edm::ValueMap< float > > PuppiWeight_
const edm::EDGetTokenT< reco::VertexCollection > PVOrigs_
int numberOfLostHits(HitCategory category) const
Particle reconstructed by the particle flow algorithm.
std::vector< edm::EDGetTokenT< edm::View< reco::Candidate > > > SVWhiteLists_
reco::GsfTrackRef gsfTrackRef() const
const std::vector< int > pfCandidateTypesForHcalDepth_
double hcalEnergy() const
return corrected Hcal energy
int numberOfValidPixelHits() const
math::XYZPoint Point
point in the space
const_iterator end() const
const edm::EDGetTokenT< edm::Association< reco::VertexCollection > > PVAsso_
const edm::EDGetTokenT< reco::VertexCollection > PVs_
virtual double px() const =0
x coordinate of momentum vector
virtual ParticleType particleId() const
uint16_t getHitPattern(HitCategory category, int position) const
static bool candsOrdering(pat::PackedCandidate const &i, pat::PackedCandidate const &j)
double phi() const final
momentum azimuthal angle
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
const double minPtForChargedHadronProperties_
double rawHcalEnergy() const
return raw Hcal energy