290 if (
iEvent.isRealData()) {
301 edm::LogWarning(
"DataSource") <<
"WARNING! No Tau collection found. This missing input will not block the job. "
302 "Instead, an empty tau collection is being be produced.";
303 auto patTaus = std::make_unique<std::vector<Tau>>();
319 for (
size_t j = 0, nd =
deposits.size();
j < nd; ++
j) {
324 std::vector<edm::Handle<edm::Association<reco::GenParticleCollection>>> genMatches(
genMatchTokens_.size());
336 std::vector<edm::ValueMap<TauJetCorrFactors>> tauJetCorrs;
341 tauJetCorrs.push_back(*tauJetCorr);
345 auto patTaus = std::make_unique<std::vector<Tau>>();
354 aTau.embedLeadTrack();
356 aTau.embedSignalTracks();
358 aTau.embedIsolationTracks();
361 aTau.embedLeadPFCand();
363 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made "
364 "from a reco::PFTau is impossible.\n";
368 aTau.embedLeadPFChargedHadrCand();
370 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made "
371 "from a reco::PFTau is impossible.\n";
375 aTau.embedLeadPFNeutralCand();
377 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made "
378 "from a reco::PFTau is impossible.\n";
382 aTau.embedSignalPFCands();
384 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made "
385 "from a reco::PFTau is impossible.\n";
389 aTau.embedSignalPFChargedHadrCands();
391 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made "
392 "from a reco::PFTau is impossible.\n";
396 aTau.embedSignalPFNeutralHadrCands();
398 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made "
399 "from a reco::PFTau is impossible.\n";
403 aTau.embedSignalPFGammaCands();
405 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made "
406 "from a reco::PFTau is impossible.\n";
410 aTau.embedIsolationPFCands();
412 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made "
413 "from a reco::PFTau is impossible.\n";
417 aTau.embedIsolationPFChargedHadrCands();
419 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made "
420 "from a reco::PFTau is impossible.\n";
424 aTau.embedIsolationPFNeutralHadrCands();
426 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made "
427 "from a reco::PFTau is impossible.\n";
431 aTau.embedIsolationPFGammaCands();
433 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made "
434 "from a reco::PFTau is impossible.\n";
439 for (
unsigned int i = 0;
i < tauJetCorrs.size(); ++
i) {
443 aTau.addJECFactors(tauJetCorr);
445 std::vector<std::string>
levels = tauJetCorrs[0][tausRef].correctionLabels();
447 aTau.initializeJEC(tauJetCorrs[0][tausRef].jecLevel(
"L2L3Residual"));
449 aTau.initializeJEC(tauJetCorrs[0][tausRef].jecLevel(
"L3Absolute"));
451 aTau.initializeJEC(tauJetCorrs[0][tausRef].jecLevel(
"Uncorrected"));
454 <<
"L2L3Residual and L3Absolute are not part of the correction applied jetCorrFactors \n"
455 <<
"of module " << tauJetCorrs[0][tausRef].jecSet() <<
" jets will remain"
464 for (
size_t i = 0,
n = genMatches.size();
i <
n; ++
i) {
466 aTau.addGenParticleRef(genTau);
469 aTau.embedGenParticle();
476 aTau.setGenJet(genJetTau);
483 size_t numberTauIds = numberPlainTauIds;
485 numberTauIds += it.size();
489 if (numberPlainTauIds != numberTauIds &&
phID_ !=
iEvent.processHistoryID()) {
493 if (!pfTauIdDiscr.isValid())
497 std::string prov_cfg_label = idcfg.second.first.first;
498 std::string prov_ID_label = idcfg.second.first.second;
500 if (prov_cfg_label ==
"rawValues" || prov_cfg_label ==
"workingPoints") {
501 const std::vector<std::string> psetsFromProvenance =
503 .getParameter<std::vector<std::string>>(prov_cfg_label);
504 for (
size_t i = 0;
i < psetsFromProvenance.size(); ++
i) {
505 if (psetsFromProvenance[
i] == prov_ID_label) {
507 if (prov_cfg_label ==
"rawValues")
508 idcfg.second.second = -1 -
i;
510 idcfg.second.second =
i;
514 }
else if (prov_cfg_label ==
"IDdefinitions" || prov_cfg_label ==
"IDWPdefinitions") {
515 const std::vector<edm::ParameterSet> psetsFromProvenance =
517 .getParameter<std::vector<edm::ParameterSet>>(prov_cfg_label);
518 for (
size_t i = 0;
i < psetsFromProvenance.size(); ++
i) {
519 if (psetsFromProvenance[
i].getParameter<std::string>(
"IDname") == prov_ID_label) {
521 if (prov_cfg_label ==
"IDdefinitions")
522 idcfg.second.second = -1 -
i;
524 idcfg.second.second =
i;
531 int i = std::stoi(prov_ID_label);
532 if (prov_cfg_label ==
"direct_rawValues")
533 idcfg.second.second = -1 -
i;
535 idcfg.second.second =
i;
537 }
catch (std::invalid_argument
const&
e) {
538 throw cms::Exception(
"Configuration") <<
"PATTauProducer: Direct access to ID container requested, so "
539 "argument of 'idLabel' must be convertable to int!\n";
543 throw cms::Exception(
"Configuration") <<
"PATTauProducer: Requested working point '" << prov_ID_label
544 <<
"' for ID '" << idcfg.first <<
"' not found!\n";
550 std::vector<pat::Tau::IdPair> ids(numberTauIds);
551 auto const& tausDeref = *tausRef;
555 for (
size_t i = 0;
i < numberPlainTauIds; ++
i) {
561 if (!missingDiscriminators.empty()) {
562 missingDiscriminators +=
", ";
574 if (!missingDiscriminators.empty()) {
575 missingDiscriminators +=
", ";
577 missingDiscriminators += it.first;
590 <<
"PATTauProducer: unsupported datatype '" <<
typeid(tausDeref).
name() <<
"' for tauSource\n";
593 edm::LogWarning(
"DataSource") <<
"The following tau discriminators have not been found in the event:\n"
594 << missingDiscriminators <<
"\n"
595 <<
"They will not be embedded into the pat::Tau object.\n"
596 <<
"Note: this message will be printed only at first occurence.";
604 if (aTau.isPFTau()) {
609 aTau.setDecayMode(pfTauRef->decayMode());
613 if (!aTau.pfEssential_.empty()) {
618 float ecalEnergy = 0;
619 float hcalEnergy = 0;
620 float sumPhiTimesEnergy = 0.;
621 float sumEtaTimesEnergy = 0.;
622 float sumEnergy = 0.;
623 float leadChargedCandPt = -99;
624 float leadChargedCandEtaAtEcalEntrance = -99;
625 const std::vector<reco::CandidatePtr>& signalCands = pfTauRef->signalCands();
626 for (
const auto& it : signalCands) {
627 const reco::PFCandidate* ipfcand = dynamic_cast<const reco::PFCandidate*>(it.get());
628 if (ipfcand !=
nullptr) {
633 sumEnergy += ipfcand->
energy();
646 if (
track->pt() > leadChargedCandPt) {
648 leadChargedCandPt =
track->pt();
655 if (ipatcand !=
nullptr) {
658 double posAtECal_phi = ipatcand->
phi();
659 double posAtECal_eta = ipatcand->
eta();
663 posAtECal_phi = posAtECalEntrance.phi();
664 posAtECal_eta = posAtECalEntrance.eta();
666 sumPhiTimesEnergy += posAtECal_phi * ipatcand->
energy();
667 sumEtaTimesEnergy += posAtECal_eta * ipatcand->
energy();
668 sumEnergy += ipatcand->
energy();
670 if (
track !=
nullptr) {
671 if (
track->pt() > leadChargedCandPt) {
672 leadChargedCandEtaAtEcalEntrance = posAtECal_eta;
673 leadChargedCandPt =
track->pt();
683 if (sumEnergy != 0.) {
690 float leadingTrackNormChi2 = 0;
691 float ecalEnergyLeadChargedHadrCand = -99.;
692 float hcalEnergyLeadChargedHadrCand = -99.;
693 float emFraction = -1.;
694 float myHCALenergy = 0.;
695 float myECALenergy = 0.;
698 const reco::PFCandidate* pfCandPtr = dynamic_cast<const reco::PFCandidate*>(leadingPFCharged.
get());
699 if (pfCandPtr !=
nullptr) {
700 ecalEnergyLeadChargedHadrCand = pfCandPtr->
ecalEnergy();
701 hcalEnergyLeadChargedHadrCand = pfCandPtr->
hcalEnergy();
704 leadingTrackNormChi2 = trackRef->normalizedChi2();
705 for (
const auto& isoPFCand : pfTauRef->isolationPFCands()) {
706 myHCALenergy += isoPFCand->hcalEnergy();
707 myECALenergy += isoPFCand->ecalEnergy();
709 for (
const auto& signalPFCand : pfTauRef->signalPFCands()) {
710 myHCALenergy += signalPFCand->hcalEnergy();
711 myECALenergy += signalPFCand->ecalEnergy();
713 if (myHCALenergy + myECALenergy != 0.) {
714 emFraction = myECALenergy / (myHCALenergy + myECALenergy);
719 if (packedCandPtr !=
nullptr) {
722 ecalEnergyLeadChargedHadrCand =
724 hcalEnergyLeadChargedHadrCand =
727 if (
track !=
nullptr) {
728 leadingTrackNormChi2 =
track->normalizedChi2();
729 for (
const auto& isoCand : pfTauRef->isolationCands()) {
732 const pat::PackedCandidate* isoPackedCand = static_cast<const pat::PackedCandidate*>(isoCand.get());
737 for (
const auto& signalCand : pfTauRef->signalCands()) {
740 const pat::PackedCandidate* sigPackedCand = static_cast<const pat::PackedCandidate*>(signalCand.get());
745 if (myHCALenergy + myECALenergy != 0.) {
746 emFraction = myECALenergy / (myHCALenergy + myECALenergy);
764 aTauPFEssential.
dxy_ = tauLifetimeInfo.
dxy();
769 aTauPFEssential.
ip3d_ = tauLifetimeInfo.
ip3d();
783 aTau.setIsolation(it->first, it->second);
787 for (
size_t j = 0, nd =
deposits.size();
j < nd; ++
j) {