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_;
110 return p.Z() -
v.Z() - ((
p.X() -
v.X()) *
c.px() + (
p.Y() -
v.Y()) *
c.py()) *
c.pz() / (
c.pt() *
c.pt());
122 PVAssoQuality_(consumes<
edm::ValueMap<
int>>(iConfig.getParameter<
edm::
InputTag>(
"vertexAssociator"))),
125 PuppiWeight_(usePuppi_ ? consumes<
edm::ValueMap<
float>>(iConfig.getParameter<
edm::
InputTag>(
"PuppiSrc"))
127 PuppiWeightNoLep_(usePuppi_ ? consumes<
edm::ValueMap<
float>>(iConfig.getParameter<
edm::
InputTag>(
"PuppiNoLepSrc"))
129 storeChargedHadronIsolation_(!iConfig.getParameter<
edm::
InputTag>(
"chargedHadronIsolation").
encode().
empty()),
130 ChargedHadronIsolation_(
131 consumes<
edm::ValueMap<
bool>>(iConfig.getParameter<
edm::
InputTag>(
"chargedHadronIsolation"))),
132 minPtForChargedHadronProperties_(iConfig.getParameter<double>(
"minPtForChargedHadronProperties")),
133 minPtForTrackProperties_(iConfig.getParameter<double>(
"minPtForTrackProperties")),
134 covarianceVersion_(iConfig.getParameter<
int>(
"covarianceVersion")),
135 covariancePackingSchemas_(iConfig.getParameter<
std::
vector<
int>>(
"covariancePackingSchemas")),
136 pfCandidateTypesForHcalDepth_(iConfig.getParameter<
std::
vector<
int>>(
"pfCandidateTypesForHcalDepth")),
137 storeHcalDepthEndcapOnly_(iConfig.getParameter<
bool>(
"storeHcalDepthEndcapOnly")),
138 storeTiming_(iConfig.getParameter<
bool>(
"storeTiming")),
141 t0Map_(timeFromValueMap_ ? consumes<
edm::ValueMap<
float>>(iConfig.getParameter<
edm::
InputTag>(
"timeMap"))
143 t0ErrMap_(timeFromValueMap_ ? consumes<
edm::ValueMap<
float>>(iConfig.getParameter<
edm::
InputTag>(
"timeMapErr"))
145 std::vector<edm::InputTag> sv_tags =
146 iConfig.
getParameter<std::vector<edm::InputTag>>(
"secondaryVerticesForWhiteList");
147 for (
const auto &itag : sv_tags) {
151 produces<std::vector<pat::PackedCandidate>>();
152 produces<edm::Association<pat::PackedCandidateCollection>>();
153 produces<edm::Association<reco::PFCandidateCollection>>();
168 iEvent.getByToken(PuppiWeight_, puppiWeight);
169 iEvent.getByToken(PuppiWeightNoLep_, puppiWeightNoLep);
173 iEvent.getByToken(PVOrigs_, PVOrigs);
176 iEvent.getByToken(PVAsso_, assoHandle);
178 iEvent.getByToken(PVAssoQuality_, assoQualityHandle);
183 if (storeChargedHadronIsolation_)
184 iEvent.getByToken(ChargedHadronIsolation_, chargedHadronIsolationHandle);
186 std::set<unsigned int> whiteList;
187 std::set<reco::TrackRef> whiteListTk;
188 for (
auto itoken : SVWhiteLists_) {
190 iEvent.getByToken(itoken, svWhiteListHandle);
192 for (
unsigned int i = 0;
i < svWhiteList.
size();
i++) {
194 for (
unsigned int j = 0;
j < svWhiteList[
i].numberOfSourceCandidatePtrs();
j++) {
197 whiteList.insert(
c.key());
200 for (
auto dau = svWhiteList[
i].begin(); dau != svWhiteList[
i].
end(); dau++) {
202 if (chCand !=
nullptr) {
203 whiteListTk.insert(chCand->
track());
211 if (timeFromValueMap_) {
212 iEvent.getByToken(t0Map_, t0Map);
213 iEvent.getByToken(t0ErrMap_, t0ErrMap);
217 iEvent.getByToken(PVs_, PVs);
222 std::vector<pat::HcalDepthEnergyFractions> hcalDepthEnergyFractions;
223 hcalDepthEnergyFractions.reserve(
cands->size());
224 std::vector<pat::HcalDepthEnergyFractions> hcalDepthEnergyFractions_Ordered;
225 hcalDepthEnergyFractions_Ordered.reserve(
cands->size());
228 iEvent.getByToken(TKOrigs_, TKOrigs);
229 auto outPtrP = std::make_unique<std::vector<pat::PackedCandidate>>();
231 std::vector<int> mappingReverse(
cands->size());
232 std::vector<int> mappingTk(TKOrigs->size(), -1);
234 for (
unsigned int ic = 0, nc =
cands->size(); ic < nc; ++ic) {
237 if ((
abs(
cand.pdgId()) == 11 ||
cand.pdgId() == 22) &&
cand.gsfTrackRef().isNonnull()) {
238 ctrack = &*
cand.gsfTrackRef();
239 }
else if (
cand.trackRef().isNonnull()) {
240 ctrack = &*
cand.trackRef();
245 for (
size_t ii = 0;
ii < PVs->size();
ii++) {
268 float ptTrk = ctrack->
pt();
269 float etaAtVtx = ctrack->
eta();
270 float phiAtVtx = ctrack->
phi();
284 outPtrP->back().setCovarianceVersion(covarianceVersion_);
285 if (
cand.trackRef().isNonnull() && PVOrig.
isNonnull() && PVOrig->trackWeight(
cand.trackRef()) > 0.5 &&
290 outPtrP->back().setLostInnerHits(
lostHits);
291 if (outPtrP->back().pt() > minPtForTrackProperties_ || outPtrP->back().ptTrk() > minPtForTrackProperties_ ||
292 whiteList.find(ic) != whiteList.end() ||
293 (
cand.trackRef().isNonnull() && whiteListTk.find(
cand.trackRef()) != whiteListTk.end())) {
295 if (
abs(outPtrP->back().pdgId()) == 22) {
296 outPtrP->back().setTrackProperties(*ctrack, covariancePackingSchemas_[4], covarianceVersion_);
299 outPtrP->back().setTrackProperties(*ctrack,
300 covariancePackingSchemas_[0],
303 outPtrP->back().setTrackProperties(*ctrack, covariancePackingSchemas_[1], covarianceVersion_);
308 if (outPtrP->back().pt() > 0.5) {
310 outPtrP->back().setTrackProperties(*ctrack,
311 covariancePackingSchemas_[2],
314 outPtrP->back().setTrackProperties(*ctrack,
315 covariancePackingSchemas_[3],
321 outPtrP->back().setTrackHighPurity(
cand.trackRef().isNonnull() &&
323 if (
cand.muonRef().isNonnull()) {
324 outPtrP->back().setMuonID(
cand.muonRef()->isStandAloneMuon(),
cand.muonRef()->isGlobalMuon());
329 PVpos =
PV->position();
334 outPtrP->back().setAssociationQuality(
340 bool isIsolatedChargedHadron =
false;
341 if (storeChargedHadronIsolation_) {
343 isIsolatedChargedHadron =
345 outPtrP->back().setIsIsolatedChargedHadron(isIsolatedChargedHadron);
349 outPtrP->back().setHcalFraction(
cand.hcalEnergy() / (
cand.ecalEnergy() +
cand.hcalEnergy()));
350 }
else if ((
cand.charge() ||
abs(
cand.pdgId()) == 22) &&
cand.pt() > 0.5) {
351 outPtrP->back().setHcalFraction(
cand.hcalEnergy() / (
cand.ecalEnergy() +
cand.hcalEnergy()));
352 outPtrP->back().setCaloFraction((
cand.hcalEnergy() +
cand.ecalEnergy()) /
cand.energy());
354 outPtrP->back().setHcalFraction(0);
355 outPtrP->back().setCaloFraction(0);
358 if (isIsolatedChargedHadron) {
359 outPtrP->back().setRawCaloFraction((
cand.rawEcalEnergy() +
cand.rawHcalEnergy()) /
cand.energy());
360 outPtrP->back().setRawHcalFraction(
cand.rawHcalEnergy() / (
cand.rawEcalEnergy() +
cand.rawHcalEnergy()));
362 outPtrP->back().setRawCaloFraction(0);
363 outPtrP->back().setRawHcalFraction(0);
366 std::vector<float> dummyVector;
371 if (
std::find(pfCandidateTypesForHcalDepth_.begin(), pfCandidateTypesForHcalDepth_.end(),
abs(
cand.pdgId())) !=
372 pfCandidateTypesForHcalDepth_.end()) {
373 if (!storeHcalDepthEndcapOnly_ ||
374 fabs(outPtrP->back().eta()) > 1.3) {
377 std::vector<float> hcalDepthEnergyFractionTmp(
cand.hcalDepthEnergyFractions().begin(),
378 cand.hcalDepthEnergyFractions().end());
379 hcalDepthEFrac.
reset(hcalDepthEnergyFractionTmp);
382 hcalDepthEnergyFractions.push_back(hcalDepthEFrac);
388 outPtrP->back().setGoodEgamma();
394 float puppiWeightVal = (*puppiWeight)[pkref];
395 float puppiWeightNoLepVal = (*puppiWeightNoLep)[pkref];
396 outPtrP->back().setPuppiWeight(puppiWeightVal, puppiWeightNoLepVal);
400 if (timeFromValueMap_) {
401 if (
cand.trackRef().isNonnull()) {
402 auto t0 = (*t0Map)[
cand.trackRef()];
403 auto t0Err = (*t0ErrMap)[
cand.trackRef()];
404 outPtrP->back().setTime(
t0, t0Err);
407 if (
cand.isTimeValid()) {
408 outPtrP->back().setTime(
cand.time(),
cand.timeError());
414 if (
cand.trackRef().isNonnull() &&
cand.trackRef().id() == TKOrigs.
id()) {
415 mappingTk[
cand.trackRef().key()] = ic;
419 auto outPtrPSorted = std::make_unique<std::vector<pat::PackedCandidate>>();
420 std::vector<size_t>
order = sort_indexes(*outPtrP);
421 std::vector<size_t> reverseOrder(
order.size());
422 for (
size_t i = 0, nc =
cands->size();
i < nc;
i++) {
423 outPtrPSorted->push_back((*outPtrP)[
order[
i]]);
426 hcalDepthEnergyFractions_Ordered.push_back(hcalDepthEnergyFractions[
order[
i]]);
430 for (
size_t i = 0, ntk = mappingTk.size();
i < ntk;
i++) {
431 if (mappingTk[
i] >= 0)
432 mappingTk[
i] = reverseOrder[mappingTk[
i]];
438 auto pf2pc = std::make_unique<edm::Association<pat::PackedCandidateCollection>>(oh);
439 auto pc2pf = std::make_unique<edm::Association<reco::PFCandidateCollection>>(
cands);
442 pf2pcFiller.insert(
cands, mappingReverse.begin(), mappingReverse.end());
445 pf2pcFiller.insert(TKOrigs, mappingTk.begin(), mappingTk.end());
453 auto hcalDepthEnergyFractionsV = std::make_unique<edm::ValueMap<HcalDepthEnergyFractions>>();
455 fillerHcalDepthEnergyFractions.insert(
456 cands, hcalDepthEnergyFractions_Ordered.begin(), hcalDepthEnergyFractions_Ordered.end());
457 fillerHcalDepthEnergyFractions.fill();
459 if (not pfCandidateTypesForHcalDepth_.empty())
460 iEvent.put(
std::move(hcalDepthEnergyFractionsV),
"hcalDepthEnergyFractions");