177 if (
iEvent.isRealData()) {
188 edm::LogWarning(
"DataSource") <<
"WARNING! No Tau collection found. This missing input will not block the job. "
189 "Instead, an empty tau collection is being be produced.";
190 auto patTaus = std::make_unique<std::vector<Tau>>();
206 for (
size_t j = 0, nd =
deposits.size();
j < nd; ++
j) {
211 std::vector<edm::Handle<edm::Association<reco::GenParticleCollection>>> genMatches(
genMatchTokens_.size());
223 std::vector<edm::ValueMap<TauJetCorrFactors>> tauJetCorrs;
228 tauJetCorrs.push_back(*tauJetCorr);
232 auto patTaus = std::make_unique<std::vector<Tau>>();
241 aTau.embedLeadTrack();
243 aTau.embedSignalTracks();
245 aTau.embedIsolationTracks();
248 aTau.embedLeadPFCand();
250 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made "
251 "from a reco::PFTau is impossible.\n";
255 aTau.embedLeadPFChargedHadrCand();
257 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made "
258 "from a reco::PFTau is impossible.\n";
262 aTau.embedLeadPFNeutralCand();
264 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made "
265 "from a reco::PFTau is impossible.\n";
269 aTau.embedSignalPFCands();
271 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made "
272 "from a reco::PFTau is impossible.\n";
276 aTau.embedSignalPFChargedHadrCands();
278 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made "
279 "from a reco::PFTau is impossible.\n";
283 aTau.embedSignalPFNeutralHadrCands();
285 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made "
286 "from a reco::PFTau is impossible.\n";
290 aTau.embedSignalPFGammaCands();
292 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made "
293 "from a reco::PFTau is impossible.\n";
297 aTau.embedIsolationPFCands();
299 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made "
300 "from a reco::PFTau is impossible.\n";
304 aTau.embedIsolationPFChargedHadrCands();
306 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made "
307 "from a reco::PFTau is impossible.\n";
311 aTau.embedIsolationPFNeutralHadrCands();
313 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made "
314 "from a reco::PFTau is impossible.\n";
318 aTau.embedIsolationPFGammaCands();
320 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made "
321 "from a reco::PFTau is impossible.\n";
326 for (
unsigned int i = 0;
i < tauJetCorrs.size(); ++
i) {
330 aTau.addJECFactors(tauJetCorr);
332 std::vector<std::string>
levels = tauJetCorrs[0][tausRef].correctionLabels();
334 aTau.initializeJEC(tauJetCorrs[0][tausRef].jecLevel(
"L2L3Residual"));
336 aTau.initializeJEC(tauJetCorrs[0][tausRef].jecLevel(
"L3Absolute"));
338 aTau.initializeJEC(tauJetCorrs[0][tausRef].jecLevel(
"Uncorrected"));
341 <<
"L2L3Residual and L3Absolute are not part of the correction applied jetCorrFactors \n"
342 <<
"of module " << tauJetCorrs[0][tausRef].jecSet() <<
" jets will remain"
351 for (
size_t i = 0,
n = genMatches.size();
i <
n; ++
i) {
353 aTau.addGenParticleRef(genTau);
356 aTau.embedGenParticle();
363 aTau.setGenJet(genJetTau);
370 size_t numberTauIds = numberPlainTauIds;
372 numberTauIds += it.size();
376 if (numberPlainTauIds != numberTauIds &&
phID_ !=
iEvent.processHistoryID()) {
380 if (!pfTauIdDiscr.isValid())
384 std::string prov_cfg_label = idcfg.second.first.first;
385 std::string prov_ID_label = idcfg.second.first.second;
387 if (prov_cfg_label ==
"rawValues" || prov_cfg_label ==
"workingPoints") {
388 const std::vector<std::string> psetsFromProvenance =
390 .getParameter<std::vector<std::string>>(prov_cfg_label);
391 for (
size_t i = 0;
i < psetsFromProvenance.size(); ++
i) {
392 if (psetsFromProvenance[
i] == prov_ID_label) {
394 if (prov_cfg_label ==
"rawValues")
395 idcfg.second.second = -1 -
i;
397 idcfg.second.second =
i;
401 }
else if (prov_cfg_label ==
"IDdefinitions" || prov_cfg_label ==
"IDWPdefinitions") {
402 const std::vector<edm::ParameterSet> psetsFromProvenance =
404 .getParameter<std::vector<edm::ParameterSet>>(prov_cfg_label);
405 for (
size_t i = 0;
i < psetsFromProvenance.size(); ++
i) {
406 if (psetsFromProvenance[
i].getParameter<std::string>(
"IDname") == prov_ID_label) {
408 if (prov_cfg_label ==
"IDdefinitions")
409 idcfg.second.second = -1 -
i;
411 idcfg.second.second =
i;
418 int i = std::stoi(prov_ID_label);
419 if (prov_cfg_label ==
"direct_rawValues")
420 idcfg.second.second = -1 -
i;
422 idcfg.second.second =
i;
424 }
catch (std::invalid_argument
const&
e) {
425 throw cms::Exception(
"Configuration") <<
"PATTauProducer: Direct access to ID container requested, so "
426 "argument of 'idLabel' must be convertable to int!\n";
430 throw cms::Exception(
"Configuration") <<
"PATTauProducer: Requested working point '" << prov_ID_label
431 <<
"' for ID '" << idcfg.first <<
"' not found!\n";
437 std::vector<pat::Tau::IdPair> ids(numberTauIds);
438 auto const& tausDeref = *tausRef;
442 for (
size_t i = 0;
i < numberPlainTauIds; ++
i) {
448 if (!missingDiscriminators.empty()) {
449 missingDiscriminators +=
", ";
461 if (!missingDiscriminators.empty()) {
462 missingDiscriminators +=
", ";
464 missingDiscriminators += it.first;
477 <<
"PATTauProducer: unsupported datatype '" <<
typeid(tausDeref).
name() <<
"' for tauSource\n";
480 edm::LogWarning(
"DataSource") <<
"The following tau discriminators have not been found in the event:\n"
481 << missingDiscriminators <<
"\n"
482 <<
"They will not be embedded into the pat::Tau object.\n"
483 <<
"Note: this message will be printed only at first occurence.";
491 if (aTau.isPFTau()) {
496 aTau.setDecayMode(pfTauRef->decayMode());
500 if (!aTau.pfEssential_.empty()) {
505 float ecalEnergy = 0;
506 float hcalEnergy = 0;
507 float sumPhiTimesEnergy = 0.;
508 float sumEtaTimesEnergy = 0.;
509 float sumEnergy = 0.;
510 float leadChargedCandPt = -99;
511 float leadChargedCandEtaAtEcalEntrance = -99;
512 const std::vector<reco::CandidatePtr>& signalCands = pfTauRef->signalCands();
513 for (
const auto& it : signalCands) {
514 const reco::PFCandidate* ipfcand = dynamic_cast<const reco::PFCandidate*>(it.get());
515 if (ipfcand !=
nullptr) {
520 sumEnergy += ipfcand->
energy();
533 if (
track->pt() > leadChargedCandPt) {
535 leadChargedCandPt =
track->pt();
542 if (ipatcand !=
nullptr) {
545 double posAtECal_phi = ipatcand->
phi();
546 double posAtECal_eta = ipatcand->
eta();
550 posAtECal_phi = posAtECalEntrance.phi();
551 posAtECal_eta = posAtECalEntrance.eta();
553 sumPhiTimesEnergy += posAtECal_phi * ipatcand->
energy();
554 sumEtaTimesEnergy += posAtECal_eta * ipatcand->
energy();
555 sumEnergy += ipatcand->
energy();
557 if (
track !=
nullptr) {
558 if (
track->pt() > leadChargedCandPt) {
559 leadChargedCandEtaAtEcalEntrance = posAtECal_eta;
560 leadChargedCandPt =
track->pt();
570 if (sumEnergy != 0.) {
577 float leadingTrackNormChi2 = 0;
578 float ecalEnergyLeadChargedHadrCand = -99.;
579 float hcalEnergyLeadChargedHadrCand = -99.;
580 float emFraction = -1.;
581 float myHCALenergy = 0.;
582 float myECALenergy = 0.;
585 const reco::PFCandidate* pfCandPtr = dynamic_cast<const reco::PFCandidate*>(leadingPFCharged.
get());
586 if (pfCandPtr !=
nullptr) {
587 ecalEnergyLeadChargedHadrCand = pfCandPtr->
ecalEnergy();
588 hcalEnergyLeadChargedHadrCand = pfCandPtr->
hcalEnergy();
591 leadingTrackNormChi2 = trackRef->normalizedChi2();
592 for (
const auto& isoPFCand : pfTauRef->isolationPFCands()) {
593 myHCALenergy += isoPFCand->hcalEnergy();
594 myECALenergy += isoPFCand->ecalEnergy();
596 for (
const auto& signalPFCand : pfTauRef->signalPFCands()) {
597 myHCALenergy += signalPFCand->hcalEnergy();
598 myECALenergy += signalPFCand->ecalEnergy();
600 if (myHCALenergy + myECALenergy != 0.) {
601 emFraction = myECALenergy / (myHCALenergy + myECALenergy);
606 if (packedCandPtr !=
nullptr) {
609 ecalEnergyLeadChargedHadrCand =
611 hcalEnergyLeadChargedHadrCand =
614 if (
track !=
nullptr) {
615 leadingTrackNormChi2 =
track->normalizedChi2();
616 for (
const auto& isoCand : pfTauRef->isolationCands()) {
619 const pat::PackedCandidate* isoPackedCand = static_cast<const pat::PackedCandidate*>(isoCand.get());
624 for (
const auto& signalCand : pfTauRef->signalCands()) {
627 const pat::PackedCandidate* sigPackedCand = static_cast<const pat::PackedCandidate*>(signalCand.get());
632 if (myHCALenergy + myECALenergy != 0.) {
633 emFraction = myECALenergy / (myHCALenergy + myECALenergy);
651 aTauPFEssential.
dxy_ = tauLifetimeInfo.
dxy();
656 aTauPFEssential.
ip3d_ = tauLifetimeInfo.
ip3d();
670 aTau.setIsolation(it->first, it->second);
674 for (
size_t j = 0, nd =
deposits.size();
j < nd; ++
j) {