37 const static int qualityMap[8] = {1, 0, 1, 1, 4, 4, 5, 6};
69 std::vector<size_t> idx(v.size());
70 for (
size_t i = 0;
i != idx.size(); ++
i)
72 std::sort(idx.begin(), idx.end(), [&
v](
size_t i1,
size_t i2) {
return candsOrdering(v[i1], v[i2]); });
90 std::vector<edm::EDGetTokenT<edm::View<reco::Candidate>>>
SVWhiteLists_;
111 return p.Z() - v.Z() - ((p.X() - v.X()) * c.
px() + (p.Y() - v.Y()) * c.
py()) * c.
pz() / (c.
pt() * c.
pt());
123 PVAssoQuality_(consumes<edm::ValueMap<int>>(iConfig.getParameter<edm::
InputTag>(
"vertexAssociator"))),
126 PuppiWeight_(usePuppi_ ? consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::
InputTag>(
"PuppiSrc"))
127 : edm::EDGetTokenT<edm::ValueMap<float>>()),
128 PuppiWeightNoLep_(usePuppi_ ? consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::
InputTag>(
"PuppiNoLepSrc"))
129 : edm::EDGetTokenT<edm::ValueMap<float>>()),
130 storeChargedHadronIsolation_(!iConfig.getParameter<edm::
InputTag>(
"chargedHadronIsolation").
encode().
empty()),
131 ChargedHadronIsolation_(
132 consumes<edm::ValueMap<bool>>(iConfig.getParameter<edm::
InputTag>(
"chargedHadronIsolation"))),
133 minPtForChargedHadronProperties_(iConfig.getParameter<double>(
"minPtForChargedHadronProperties")),
134 minPtForTrackProperties_(iConfig.getParameter<double>(
"minPtForTrackProperties")),
135 minPtForLowQualityTrackProperties_(iConfig.getParameter<double>(
"minPtForLowQualityTrackProperties")),
136 covarianceVersion_(iConfig.getParameter<int>(
"covarianceVersion")),
137 covariancePackingSchemas_(iConfig.getParameter<std::
vector<int>>(
"covariancePackingSchemas")),
138 pfCandidateTypesForHcalDepth_(iConfig.getParameter<std::
vector<int>>(
"pfCandidateTypesForHcalDepth")),
139 storeHcalDepthEndcapOnly_(iConfig.getParameter<bool>(
"storeHcalDepthEndcapOnly")),
140 storeTiming_(iConfig.getParameter<bool>(
"storeTiming")),
143 t0Map_(timeFromValueMap_ ? consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::
InputTag>(
"timeMap"))
144 : edm::EDGetTokenT<edm::ValueMap<float>>()),
145 t0ErrMap_(timeFromValueMap_ ? consumes<edm::ValueMap<float>>(iConfig.getParameter<edm::
InputTag>(
"timeMapErr"))
146 : edm::EDGetTokenT<edm::ValueMap<float>>()) {
147 std::vector<edm::InputTag> sv_tags =
148 iConfig.
getParameter<std::vector<edm::InputTag>>(
"secondaryVerticesForWhiteList");
149 for (
const auto &itag : sv_tags) {
153 produces<std::vector<pat::PackedCandidate>>();
154 produces<edm::Association<pat::PackedCandidateCollection>>();
155 produces<edm::Association<reco::PFCandidateCollection>>();
171 iEvent.
getByToken(PuppiWeightNoLep_, puppiWeightNoLep);
180 iEvent.
getByToken(PVAssoQuality_, assoQualityHandle);
185 if (storeChargedHadronIsolation_)
186 iEvent.
getByToken(ChargedHadronIsolation_, chargedHadronIsolationHandle);
188 std::set<unsigned int> whiteList;
189 std::set<reco::TrackRef> whiteListTk;
190 for (
auto itoken : SVWhiteLists_) {
194 for (
unsigned int i = 0;
i < svWhiteList.
size();
i++) {
196 for (
unsigned int j = 0;
j < svWhiteList[
i].numberOfSourceCandidatePtrs();
j++) {
198 if (c.
id() == cands.
id())
199 whiteList.insert(c.
key());
202 for (
auto dau = svWhiteList[
i].
begin(); dau != svWhiteList[
i].
end(); dau++) {
204 if (chCand !=
nullptr) {
205 whiteListTk.insert(chCand->
track());
213 if (timeFromValueMap_) {
224 std::vector<pat::HcalDepthEnergyFractions> hcalDepthEnergyFractions;
225 hcalDepthEnergyFractions.reserve(cands->size());
226 std::vector<pat::HcalDepthEnergyFractions> hcalDepthEnergyFractions_Ordered;
227 hcalDepthEnergyFractions_Ordered.reserve(cands->size());
231 auto outPtrP = std::make_unique<std::vector<pat::PackedCandidate>>();
232 std::vector<int> mapping(cands->size());
233 std::vector<int> mappingReverse(cands->size());
234 std::vector<int> mappingTk(TKOrigs->size(), -1);
236 for (
unsigned int ic = 0, nc = cands->size(); ic < nc; ++ic) {
247 for (
size_t ii = 0;
ii < PVs->size();
ii++) {
270 float ptTrk = ctrack->
pt();
271 float etaAtVtx = ctrack->
eta();
272 float phiAtVtx = ctrack->
phi();
286 outPtrP->back().setCovarianceVersion(covarianceVersion_);
292 outPtrP->back().setLostInnerHits(lostHits);
293 if (outPtrP->back().pt() > minPtForTrackProperties_ || outPtrP->back().ptTrk() > minPtForTrackProperties_ ||
294 whiteList.find(ic) != whiteList.end() ||
297 if (
abs(outPtrP->back().pdgId()) == 22) {
298 outPtrP->back().setTrackProperties(*ctrack, covariancePackingSchemas_[4], covarianceVersion_);
301 outPtrP->back().setTrackProperties(*ctrack,
302 covariancePackingSchemas_[0],
305 outPtrP->back().setTrackProperties(*ctrack, covariancePackingSchemas_[1], covarianceVersion_);
310 if (outPtrP->back().pt() > minPtForLowQualityTrackProperties_) {
312 outPtrP->back().setTrackProperties(*ctrack,
313 covariancePackingSchemas_[2],
316 outPtrP->back().setTrackProperties(*ctrack,
317 covariancePackingSchemas_[3],
326 outPtrP->back().setMuonID(cand.
muonRef()->isStandAloneMuon(), cand.
muonRef()->isGlobalMuon());
331 PVpos = PV->position();
336 outPtrP->back().setAssociationQuality(
342 bool isIsolatedChargedHadron =
false;
343 if (storeChargedHadronIsolation_) {
345 isIsolatedChargedHadron =
346 ((cand.
pt() > minPtForChargedHadronProperties_) && (chargedHadronIsolation[
reco::PFCandidateRef(cands, ic)]));
347 outPtrP->back().setIsIsolatedChargedHadron(isIsolatedChargedHadron);
356 outPtrP->back().setHcalFraction(0);
357 outPtrP->back().setCaloFraction(0);
360 if (isIsolatedChargedHadron) {
364 outPtrP->back().setRawCaloFraction(0);
365 outPtrP->back().setRawHcalFraction(0);
368 std::vector<float> dummyVector;
373 if (
std::find(pfCandidateTypesForHcalDepth_.begin(), pfCandidateTypesForHcalDepth_.end(),
abs(cand.
pdgId())) !=
374 pfCandidateTypesForHcalDepth_.end()) {
375 if (!storeHcalDepthEndcapOnly_ ||
376 fabs(outPtrP->back().eta()) > 1.3) {
381 hcalDepthEFrac.
reset(hcalDepthEnergyFractionTmp);
384 hcalDepthEnergyFractions.push_back(hcalDepthEFrac);
390 outPtrP->back().setGoodEgamma();
396 float puppiWeightVal = (*puppiWeight)[pkref];
397 float puppiWeightNoLepVal = (*puppiWeightNoLep)[pkref];
398 outPtrP->back().setPuppiWeight(puppiWeightVal, puppiWeightNoLepVal);
402 if (timeFromValueMap_) {
405 auto t0Err = (*t0ErrMap)[cand.
trackRef()];
406 outPtrP->back().setTime(
t0, t0Err);
421 auto outPtrPSorted = std::make_unique<std::vector<pat::PackedCandidate>>();
422 std::vector<size_t> order = sort_indexes(*outPtrP);
423 std::vector<size_t> reverseOrder(order.size());
424 for (
size_t i = 0, nc = cands->size();
i < nc;
i++) {
425 outPtrPSorted->push_back((*outPtrP)[order[
i]]);
426 reverseOrder[order[
i]] =
i;
427 mappingReverse[order[
i]] =
i;
428 hcalDepthEnergyFractions_Ordered.push_back(hcalDepthEnergyFractions[order[i]]);
432 for (
size_t i = 0, ntk = mappingTk.size();
i < ntk;
i++) {
433 if (mappingTk[
i] >= 0)
434 mappingTk[
i] = reverseOrder[mappingTk[
i]];
440 auto pf2pc = std::make_unique<edm::Association<pat::PackedCandidateCollection>>(oh);
441 auto pc2pf = std::make_unique<edm::Association<reco::PFCandidateCollection>>(
cands);
444 pf2pcFiller.insert(cands, mappingReverse.begin(), mappingReverse.end());
445 pc2pfFiller.
insert(oh, order.begin(), order.end());
447 pf2pcFiller.insert(TKOrigs, mappingTk.begin(), mappingTk.end());
455 auto hcalDepthEnergyFractionsV = std::make_unique<edm::ValueMap<HcalDepthEnergyFractions>>();
457 fillerHcalDepthEnergyFractions.insert(
458 cands, hcalDepthEnergyFractions_Ordered.begin(), hcalDepthEnergyFractions_Ordered.end());
459 fillerHcalDepthEnergyFractions.fill();
461 if (not pfCandidateTypesForHcalDepth_.empty())
462 iEvent.
put(
std::move(hcalDepthEnergyFractionsV),
"hcalDepthEnergyFractions");
double ecalEnergy() const
return corrected Ecal energy
const Point & referencePoint() const
Reference point on the track.
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
const edm::EventSetup & c
bool isNonnull() const
Checks for non-null.
double rawEcalEnergy() const
return corrected Ecal energy
double pt() const final
transverse momentum
int covarianceSchema() const
int charge() const override
electric charge
bool hasValidHitInPixelLayer(enum PixelSubdetector::SubDetector, uint16_t layer) const
~PATPackedCandidateProducer() override
float mva_nothing_gamma() const
mva for gamma detection
bool getByToken(EDGetToken token, Handle< PROD > &result) const
virtual double pt() const =0
transverse momentum
#define DEFINE_FWK_MODULE(type)
uint32_t const *__restrict__ Quality * quality
std::vector< l1t::PFCandidate > PFCandidateCollection
Sin< T >::type sin(const T &t)
virtual double pz() const =0
z coordinate of momentum vector
void insert(const H &h, I begin, I end)
std::vector< Track > TrackCollection
collection of Tracks
double phi() const
azimuthal angle of momentum vector
static const int qualityMap[8]
conversion map from quality flags used in PV association and miniAOD one
const edm::EDGetTokenT< reco::PFCandidateCollection > Cands_
string chargedHadronIsolation
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)
std::vector< Vertex > VertexCollection
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
int pdgId() const final
PDG identifier.
const double minPtForTrackProperties_
bool isTimeValid() const
do we have a valid time information
PATPackedCandidateProducer(const edm::ParameterSet &)
double eta() const
pseudorapidity of momentum vector
void reset(std::vector< float > v)
double eta() const override
momentum pseudorapidity
const edm::EDGetTokenT< edm::ValueMap< float > > t0ErrMap_
reco::TrackRef track() const override
reference to a track
double pt() const
track transverse momentum
const PolarLorentzVector & polarP4() const final
four-momentum Lorentz vector
Cos< T >::type cos(const T &t)
float calcDxy(float dx, float dy, float phi) const
Abs< T >::type abs(const T &t)
const bool storeChargedHadronIsolation_
const bool timeFromValueMap_
static std::vector< size_t > sort_indexes(const std::vector< T > &v)
const edm::EDGetTokenT< reco::TrackCollection > TKOrigs_
virtual double py() const =0
y coordinate of momentum vector
const bool storeHcalDepthEndcapOnly_
edm::Ref< VertexCollection > VertexRef
persistent reference to a Vertex
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
const int covarianceVersion_
reco::MuonRef muonRef() const
bool hasTrackDetails() const
Return true if a bestTrack can be extracted from this Candidate.
virtual double px() const =0
x coordinate of momentum vector
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.
const std::array< float, 7 > & hcalDepthEnergyFractions() const
fraction of hcal energy at a given depth (index 0..6 for depth 1..7)
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_
XYZPointD XYZPoint
point in space with cartesian internal representation
T getParameter(std::string const &) const
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
const Point & vertex() const override
vertex position (overwritten by PF...)
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_
const double minPtForLowQualityTrackProperties_
const edm::EDGetTokenT< edm::ValueMap< float > > t0Map_
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
const double minPtForChargedHadronProperties_
int charge() const final
electric charge
double rawHcalEnergy() const
return raw Hcal energy
double energy() const final
energy
double eta() const final
momentum pseudorapidity