37 const static int qualityMap[8] = {1, 0, 1, 1, 4, 4, 5, 6};
49 if (
i.charge() != 0) {
50 if (
i.hasTrackDetails() and !
j.hasTrackDetails())
52 if (!
i.hasTrackDetails() and
j.hasTrackDetails())
54 if (
i.covarianceSchema() >
j.covarianceSchema())
56 if (
i.covarianceSchema() <
j.covarianceSchema())
59 if (
i.vertexRef() ==
j.vertexRef())
60 return i.eta() >
j.eta();
62 return i.vertexRef().key() <
j.vertexRef().key();
69 std::vector<size_t>
idx(
v.size());
70 for (
size_t i = 0;
i !=
idx.size(); ++
i)
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"))
128 PuppiWeightNoLep_(usePuppi_ ? consumes<
edm::ValueMap<
float>>(iConfig.getParameter<
edm::
InputTag>(
"PuppiNoLepSrc"))
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"))
145 t0ErrMap_(timeFromValueMap_ ? consumes<
edm::ValueMap<
float>>(iConfig.getParameter<
edm::
InputTag>(
"timeMapErr"))
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>>();
170 iEvent.getByToken(PuppiWeight_, puppiWeight);
171 iEvent.getByToken(PuppiWeightNoLep_, puppiWeightNoLep);
175 iEvent.getByToken(PVOrigs_, PVOrigs);
178 iEvent.getByToken(PVAsso_, assoHandle);
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_) {
192 iEvent.getByToken(itoken, svWhiteListHandle);
194 for (
unsigned int i = 0;
i < svWhiteList.
size();
i++) {
196 for (
unsigned int j = 0;
j < svWhiteList[
i].numberOfSourceCandidatePtrs();
j++) {
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_) {
214 iEvent.getByToken(t0Map_, t0Map);
215 iEvent.getByToken(t0ErrMap_, t0ErrMap);
219 iEvent.getByToken(PVs_, PVs);
224 std::vector<pat::HcalDepthEnergyFractions> hcalDepthEnergyFractions;
225 hcalDepthEnergyFractions.reserve(
cands->size());
226 std::vector<pat::HcalDepthEnergyFractions> hcalDepthEnergyFractions_Ordered;
227 hcalDepthEnergyFractions_Ordered.reserve(
cands->size());
230 iEvent.getByToken(TKOrigs_, TKOrigs);
231 auto outPtrP = std::make_unique<std::vector<pat::PackedCandidate>>();
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) {
239 if ((
abs(
cand.pdgId()) == 11 ||
cand.pdgId() == 22) &&
cand.gsfTrackRef().isNonnull()) {
240 ctrack = &*
cand.gsfTrackRef();
241 }
else if (
cand.trackRef().isNonnull()) {
242 ctrack = &*
cand.trackRef();
247 for (
size_t ii = 0;
ii < PVs->size();
ii++) {
270 float ptTrk = ctrack->
pt();
286 outPtrP->back().setCovarianceVersion(covarianceVersion_);
287 if (
cand.trackRef().isNonnull() && PVOrig.
isNonnull() && PVOrig->trackWeight(
cand.trackRef()) > 0.5 &&
292 outPtrP->back().setLostInnerHits(
lostHits);
293 if (outPtrP->back().pt() > minPtForTrackProperties_ || outPtrP->back().ptTrk() > minPtForTrackProperties_ ||
294 whiteList.find(ic) != whiteList.end() ||
295 (
cand.trackRef().isNonnull() && whiteListTk.find(
cand.trackRef()) != whiteListTk.end())) {
296 outPtrP->back().setTrkAlgo(static_cast<uint8_t>(ctrack->
algo()), static_cast<uint8_t>(ctrack->
originalAlgo()));
298 if (
abs(outPtrP->back().pdgId()) == 22) {
299 outPtrP->back().setTrackProperties(*ctrack, covariancePackingSchemas_[4], covarianceVersion_);
302 outPtrP->back().setTrackProperties(*ctrack,
303 covariancePackingSchemas_[0],
306 outPtrP->back().setTrackProperties(*ctrack, covariancePackingSchemas_[1], covarianceVersion_);
311 if (outPtrP->back().pt() > minPtForLowQualityTrackProperties_) {
313 outPtrP->back().setTrackProperties(*ctrack,
314 covariancePackingSchemas_[2],
317 outPtrP->back().setTrackProperties(*ctrack,
318 covariancePackingSchemas_[3],
324 outPtrP->back().setTrackHighPurity(
cand.trackRef().isNonnull() &&
329 PVpos =
PV->position();
334 outPtrP->back().setAssociationQuality(
340 if (
cand.muonRef().isNonnull()) {
341 outPtrP->back().setMuonID(
cand.muonRef()->isStandAloneMuon(),
cand.muonRef()->isGlobalMuon());
346 bool isIsolatedChargedHadron =
false;
347 if (storeChargedHadronIsolation_) {
349 isIsolatedChargedHadron =
351 outPtrP->back().setIsIsolatedChargedHadron(isIsolatedChargedHadron);
355 outPtrP->back().setHcalFraction(
cand.hcalEnergy() / (
cand.ecalEnergy() +
cand.hcalEnergy()));
356 }
else if ((
cand.charge() ||
abs(
cand.pdgId()) == 22) &&
cand.pt() > 0.5) {
357 outPtrP->back().setHcalFraction(
cand.hcalEnergy() / (
cand.ecalEnergy() +
cand.hcalEnergy()));
358 outPtrP->back().setCaloFraction((
cand.hcalEnergy() +
cand.ecalEnergy()) /
cand.energy());
360 outPtrP->back().setHcalFraction(0);
361 outPtrP->back().setCaloFraction(0);
364 if (isIsolatedChargedHadron) {
365 outPtrP->back().setRawCaloFraction((
cand.rawEcalEnergy() +
cand.rawHcalEnergy()) /
cand.energy());
366 outPtrP->back().setRawHcalFraction(
cand.rawHcalEnergy() / (
cand.rawEcalEnergy() +
cand.rawHcalEnergy()));
368 outPtrP->back().setRawCaloFraction(0);
369 outPtrP->back().setRawHcalFraction(0);
372 std::vector<float> dummyVector;
377 if (
std::find(pfCandidateTypesForHcalDepth_.begin(), pfCandidateTypesForHcalDepth_.end(),
abs(
cand.pdgId())) !=
378 pfCandidateTypesForHcalDepth_.end()) {
379 if (!storeHcalDepthEndcapOnly_ ||
380 fabs(outPtrP->back().eta()) > 1.3) {
383 std::vector<float> hcalDepthEnergyFractionTmp(
cand.hcalDepthEnergyFractions().begin(),
384 cand.hcalDepthEnergyFractions().end());
385 hcalDepthEFrac.
reset(hcalDepthEnergyFractionTmp);
388 hcalDepthEnergyFractions.push_back(hcalDepthEFrac);
394 outPtrP->back().setGoodEgamma();
400 float puppiWeightVal = (*puppiWeight)[pkref];
401 float puppiWeightNoLepVal = (*puppiWeightNoLep)[pkref];
402 outPtrP->back().setPuppiWeight(puppiWeightVal, puppiWeightNoLepVal);
406 if (timeFromValueMap_) {
407 if (
cand.trackRef().isNonnull()) {
408 auto t0 = (*t0Map)[
cand.trackRef()];
409 auto t0Err = (*t0ErrMap)[
cand.trackRef()];
410 outPtrP->back().setTime(
t0, t0Err);
413 if (
cand.isTimeValid()) {
414 outPtrP->back().setTime(
cand.time(),
cand.timeError());
420 if (
cand.trackRef().isNonnull() &&
cand.trackRef().id() == TKOrigs.
id()) {
421 mappingTk[
cand.trackRef().key()] = ic;
425 auto outPtrPSorted = std::make_unique<std::vector<pat::PackedCandidate>>();
426 std::vector<size_t>
order = sort_indexes(*outPtrP);
427 std::vector<size_t> reverseOrder(
order.size());
428 for (
size_t i = 0, nc =
cands->size();
i < nc;
i++) {
429 outPtrPSorted->push_back((*outPtrP)[
order[
i]]);
432 hcalDepthEnergyFractions_Ordered.push_back(hcalDepthEnergyFractions[
order[
i]]);
436 for (
size_t i = 0, ntk = mappingTk.size();
i < ntk;
i++) {
437 if (mappingTk[
i] >= 0)
438 mappingTk[
i] = reverseOrder[mappingTk[
i]];
444 auto pf2pc = std::make_unique<edm::Association<pat::PackedCandidateCollection>>(oh);
445 auto pc2pf = std::make_unique<edm::Association<reco::PFCandidateCollection>>(
cands);
448 pf2pcFiller.insert(
cands, mappingReverse.begin(), mappingReverse.end());
451 pf2pcFiller.insert(TKOrigs, mappingTk.begin(), mappingTk.end());
459 auto hcalDepthEnergyFractionsV = std::make_unique<edm::ValueMap<HcalDepthEnergyFractions>>();
461 fillerHcalDepthEnergyFractions.insert(
462 cands, hcalDepthEnergyFractions_Ordered.begin(), hcalDepthEnergyFractions_Ordered.end());
463 fillerHcalDepthEnergyFractions.fill();
465 if (not pfCandidateTypesForHcalDepth_.empty())
466 iEvent.put(
std::move(hcalDepthEnergyFractionsV),
"hcalDepthEnergyFractions");
int numberOfValidPixelHits() const
T getParameter(std::string const &) const
int numberOfLostHits(HitCategory category) const
~PATPackedCandidateProducer() override
std::vector< l1t::PFCandidate > PFCandidateCollection
Sin< T >::type sin(const T &t)
T const * product() const
void insert(const H &h, I begin, I end)
std::vector< Track > TrackCollection
collection of Tracks
bool isNonnull() const
Checks for non-null.
static const int qualityMap[8]
conversion map from quality flags used in PV association and miniAOD one
const Point & referencePoint() const
Reference point on the track.
const edm::EDGetTokenT< reco::PFCandidateCollection > Cands_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
std::vector< Vertex > VertexCollection
key_type key() const
Accessor for product key.
const edm::EDGetTokenT< edm::ValueMap< int > > PVAssoQuality_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
const edm::EDGetTokenT< edm::ValueMap< float > > PuppiWeightNoLep_
const double minPtForTrackProperties_
double pt() const
track transverse momentum
TrackAlgorithm originalAlgo() const
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...
PATPackedCandidateProducer(const edm::ParameterSet &)
void reset(std::vector< float > v)
const edm::EDGetTokenT< edm::ValueMap< float > > t0ErrMap_
reco::TrackRef track() const override
reference to a track
Cos< T >::type cos(const T &t)
Abs< T >::type abs(const T &t)
const bool storeChargedHadronIsolation_
double phi() const
azimuthal angle of momentum vector
const bool timeFromValueMap_
#define DEFINE_FWK_MODULE(type)
static std::vector< size_t > sort_indexes(const std::vector< T > &v)
const edm::EDGetTokenT< reco::TrackCollection > TKOrigs_
float calcDz(reco::Candidate::Point p, reco::Candidate::Point v, const reco::Candidate &c) const
const bool storeHcalDepthEndcapOnly_
edm::Ref< VertexCollection > VertexRef
persistent reference to a Vertex
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
uint16_t getHitPattern(HitCategory category, int position) const
const int covarianceVersion_
LostInnerHits
Enumerator specifying the.
double eta() const
pseudorapidity of momentum vector
const edm::EDGetTokenT< edm::ValueMap< bool > > ChargedHadronIsolation_
TrackAlgorithm algo() const
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
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
const edm::EDGetTokenT< edm::ValueMap< float > > PuppiWeight_
const edm::EDGetTokenT< reco::VertexCollection > PVOrigs_
float calcDxy(float dx, float dy, float phi) const
Particle reconstructed by the particle flow algorithm.
std::vector< edm::EDGetTokenT< edm::View< reco::Candidate > > > SVWhiteLists_
const std::vector< int > pfCandidateTypesForHcalDepth_
math::XYZPoint Point
point in the space
const edm::EDGetTokenT< edm::Association< reco::VertexCollection > > PVAsso_
const edm::EDGetTokenT< reco::VertexCollection > PVs_
const double minPtForLowQualityTrackProperties_
const edm::EDGetTokenT< edm::ValueMap< float > > t0Map_
static bool candsOrdering(pat::PackedCandidate const &i, pat::PackedCandidate const &j)
const_iterator end() const
bool hasValidHitInPixelLayer(enum PixelSubdetector::SubDetector, uint16_t layer) const
const double minPtForChargedHadronProperties_