90 std::vector<edm::EDGetTokenT<edm::Association<reco::GenParticleCollection>>>
genMatchTokens_;
100 typedef std::pair<std::string, edm::InputTag>
NameTag;
101 typedef std::pair<std::string, std::string>
WPCfg;
102 typedef std::pair<WPCfg, int>
WPIdx;
104 typedef std::pair<edm::InputTag, std::vector<NameWPIdx>>
129 template <
typename TauCollectionType,
typename TauDiscrType>
144 : isolator_(iConfig.exists(
"userIsolation") ? iConfig.getParameter<
edm::
ParameterSet>(
"userIsolation")
148 useUserData_(iConfig.exists(
"userData")),
149 posAtECalEntranceComputer_(consumesCollector()) {
178 iConfig.
getParameter<std::vector<edm::InputTag>>(
"genParticleMatch"),
179 [
this](
edm::InputTag const&
tag) { return consumes<edm::Association<reco::GenParticleCollection>>(tag); });
190 iConfig.
getParameter<std::vector<edm::InputTag>>(
"tauJetCorrFactorsSource"),
191 [
this](
edm::InputTag const&
tag) { return mayConsume<edm::ValueMap<TauJetCorrFactors>>(tag); });
198 std::map<std::string, IDContainerData> idContainerMap;
204 if (prov_cfg_label.empty()) {
207 if (prov_cfg_label !=
"rawValues" && prov_cfg_label !=
"workingPoints" && prov_cfg_label !=
"IDdefinitions" &&
208 prov_cfg_label !=
"IDWPdefinitions" && prov_cfg_label !=
"direct_rawValues" &&
209 prov_cfg_label !=
"direct_workingPoints")
211 <<
"PATTauProducer: Parameter 'provenanceConfigLabel' does only accept 'rawValues', 'workingPoints', "
212 "'IDdefinitions', 'IDWPdefinitions', 'direct_rawValues', 'direct_workingPoints'\n";
213 std::map<std::string, IDContainerData>::iterator it;
214 it = idContainerMap.insert({
tag.label() +
tag.instance(), {
tag, std::vector<NameWPIdx>()}}).
first;
219 if (
tauIDSrcs_.empty() && idContainerMap.empty())
220 throw cms::Exception(
"Configuration") <<
"PATTauProducer: id addTauID is true, you must specify either:\n"
221 <<
"\tPSet tauIDSources = { \n"
222 <<
"\t\tInputTag <someName> = <someTag> // as many as you want \n "
225 for (
auto const& mapEntry : idContainerMap) {
234 if (iConfig.
exists(
"isoDeposits")) {
236 if (depconf.
exists(
"tracker"))
238 if (depconf.
exists(
"ecal"))
240 if (depconf.
exists(
"hcal"))
242 if (depconf.
exists(
"pfAllParticles"))
245 if (depconf.
exists(
"pfChargedHadron"))
248 if (depconf.
exists(
"pfNeutralHadron"))
251 if (depconf.
exists(
"pfGamma"))
254 if (depconf.
exists(
"user")) {
255 std::vector<edm::InputTag> userdeps = depconf.
getParameter<std::vector<edm::InputTag>>(
"user");
256 std::vector<edm::InputTag>::const_iterator it = userdeps.begin(), ed = userdeps.end();
258 for (; it != ed; ++it, ++
key) {
265 return consumes<edm::ValueMap<IsoDeposit>>(
label.second);
283 produces<std::vector<Tau>>();
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>>();
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";
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";
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";
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";
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";
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";
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";
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";
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";
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";
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) {
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) {
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.";
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();
787 for (
size_t j = 0, nd =
deposits.size();
j < nd; ++
j) {
817 template <
typename TauCollectionType,
typename TauDiscrType>
822 return (*tauIdDiscr)[tauRef];
831 if ((*tauIdDiscr)[tauRef].
rawValues.size() == 1)
832 return (*tauIdDiscr)[tauRef].rawValues.at(0);
834 return (*tauIdDiscr)[tauRef].rawValues.at(-1 - wpIdx);
839 return (*tauIdDiscr)[tauRef].workingPoints.at(wpIdx);
852 iDesc.
add<
bool>(
"embedIsolationTracks",
false)->setComment(
"embed external isolation tracks");
853 iDesc.
add<
bool>(
"embedLeadTrack",
false)->setComment(
"embed external leading track");
854 iDesc.
add<
bool>(
"embedLeadTracks",
false)->setComment(
"embed external signal tracks");
857 iDesc.
add<
bool>(
"addGenMatch",
true)->setComment(
"add MC matching");
858 iDesc.
add<
bool>(
"embedGenMatch",
false)->setComment(
"embed MC matched MC information");
859 std::vector<edm::InputTag> emptySourceVector;
863 ->
setComment(
"input with MC match information");
866 iDesc.
add<
bool>(
"addGenJetMatch",
true)->setComment(
"add MC jet matching");
867 iDesc.
add<
bool>(
"embedGenJetMatch",
false)->setComment(
"embed MC jet matched jet information");
873 iDesc.
add<
bool>(
"addTauID",
true)->setComment(
"add tau ID variables");
881 iDesc.
add<
bool>(
"skipMissingTauID",
false)
882 ->setComment(
"allow to skip a tau ID variable when not present in the event");
893 isoDepositsPSet.
addOptional<std::vector<edm::InputTag>>(
"user");
899 iDesc.
add(
"efficiencies", efficienciesPSet);
900 iDesc.
add<
bool>(
"addEfficiencies",
false);
909 iDesc.
add(
"userIsolation", isolationPSet);