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);
284 produces<std::vector<Tau>>();
291 if (
iEvent.isRealData()) {
302 edm::LogWarning(
"DataSource") <<
"WARNING! No Tau collection found. This missing input will not block the job. " 303 "Instead, an empty tau collection is being be produced.";
304 auto patTaus = std::make_unique<std::vector<Tau>>();
320 for (
size_t j = 0, nd =
deposits.size();
j < nd; ++
j) {
325 std::vector<edm::Handle<edm::Association<reco::GenParticleCollection>>> genMatches(
genMatchTokens_.size());
337 std::vector<edm::ValueMap<TauJetCorrFactors>> tauJetCorrs;
342 tauJetCorrs.push_back(*tauJetCorr);
346 auto patTaus = std::make_unique<std::vector<Tau>>();
364 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made " 365 "from a reco::PFTau is impossible.\n";
371 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made " 372 "from a reco::PFTau is impossible.\n";
378 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made " 379 "from a reco::PFTau is impossible.\n";
385 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made " 386 "from a reco::PFTau is impossible.\n";
392 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made " 393 "from a reco::PFTau is impossible.\n";
399 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made " 400 "from a reco::PFTau is impossible.\n";
406 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made " 407 "from a reco::PFTau is impossible.\n";
413 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made " 414 "from a reco::PFTau is impossible.\n";
420 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made " 421 "from a reco::PFTau is impossible.\n";
427 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made " 428 "from a reco::PFTau is impossible.\n";
434 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made " 435 "from a reco::PFTau is impossible.\n";
440 for (
unsigned int i = 0;
i < tauJetCorrs.size(); ++
i) {
446 std::vector<std::string>
levels = tauJetCorrs[0][tausRef].correctionLabels();
448 aTau.
initializeJEC(tauJetCorrs[0][tausRef].jecLevel(
"L2L3Residual"));
450 aTau.
initializeJEC(tauJetCorrs[0][tausRef].jecLevel(
"L3Absolute"));
452 aTau.
initializeJEC(tauJetCorrs[0][tausRef].jecLevel(
"Uncorrected"));
455 <<
"L2L3Residual and L3Absolute are not part of the correction applied jetCorrFactors \n" 456 <<
"of module " << tauJetCorrs[0][tausRef].jecSet() <<
" jets will remain" 465 for (
size_t i = 0,
n = genMatches.size();
i <
n; ++
i) {
484 size_t numberTauIds = numberPlainTauIds;
486 numberTauIds += it.size();
490 if (numberPlainTauIds != numberTauIds &&
phID_ !=
iEvent.processHistoryID()) {
494 if (!pfTauIdDiscr.isValid())
498 std::string prov_cfg_label = idcfg.second.first.first;
499 std::string prov_ID_label = idcfg.second.first.second;
501 if (prov_cfg_label ==
"rawValues" || prov_cfg_label ==
"workingPoints") {
502 const std::vector<std::string> psetsFromProvenance =
504 .getParameter<std::vector<std::string>>(prov_cfg_label);
505 for (
size_t i = 0;
i < psetsFromProvenance.size(); ++
i) {
506 if (psetsFromProvenance[
i] == prov_ID_label) {
508 if (prov_cfg_label ==
"rawValues")
509 idcfg.second.second = -1 -
i;
511 idcfg.second.second =
i;
515 }
else if (prov_cfg_label ==
"IDdefinitions" || prov_cfg_label ==
"IDWPdefinitions") {
516 const std::vector<edm::ParameterSet> psetsFromProvenance =
518 .getParameter<std::vector<edm::ParameterSet>>(prov_cfg_label);
519 for (
size_t i = 0;
i < psetsFromProvenance.size(); ++
i) {
520 if (psetsFromProvenance[
i].getParameter<std::string>(
"IDname") == prov_ID_label) {
522 if (prov_cfg_label ==
"IDdefinitions")
523 idcfg.second.second = -1 -
i;
525 idcfg.second.second =
i;
532 int i = std::stoi(prov_ID_label);
533 if (prov_cfg_label ==
"direct_rawValues")
534 idcfg.second.second = -1 -
i;
536 idcfg.second.second =
i;
538 }
catch (std::invalid_argument
const&
e) {
539 throw cms::Exception(
"Configuration") <<
"PATTauProducer: Direct access to ID container requested, so " 540 "argument of 'idLabel' must be convertable to int!\n";
544 throw cms::Exception(
"Configuration") <<
"PATTauProducer: Requested working point '" << prov_ID_label
545 <<
"' for ID '" << idcfg.first <<
"' not found!\n";
551 std::vector<pat::Tau::IdPair> ids(numberTauIds);
552 auto const& tausDeref = *tausRef;
556 for (
size_t i = 0;
i < numberPlainTauIds; ++
i) {
562 if (!missingDiscriminators.empty()) {
563 missingDiscriminators +=
", ";
575 if (!missingDiscriminators.empty()) {
576 missingDiscriminators +=
", ";
578 missingDiscriminators += it.first;
591 <<
"PATTauProducer: unsupported datatype '" <<
typeid(tausDeref).
name() <<
"' for tauSource\n";
594 edm::LogWarning(
"DataSource") <<
"The following tau discriminators have not been found in the event:\n" 595 << missingDiscriminators <<
"\n" 596 <<
"They will not be embedded into the pat::Tau object.\n" 597 <<
"Note: this message will be printed only at first occurence.";
619 float ecalEnergy = 0;
620 float hcalEnergy = 0;
621 float sumPhiTimesEnergy = 0.;
622 float sumEtaTimesEnergy = 0.;
623 float sumEnergy = 0.;
624 float leadChargedCandPt = -99;
625 float leadChargedCandEtaAtEcalEntrance = -99;
626 const std::vector<reco::CandidatePtr>& signalCands = pfTauRef->signalCands();
627 for (
const auto& it : signalCands) {
629 if (ipfcand !=
nullptr) {
634 sumEnergy += ipfcand->
energy();
647 if (
track->pt() > leadChargedCandPt) {
649 leadChargedCandPt =
track->pt();
656 if (ipatcand !=
nullptr) {
659 double posAtECal_phi = ipatcand->
phi();
660 double posAtECal_eta = ipatcand->
eta();
664 posAtECal_phi = posAtECalEntrance.phi();
665 posAtECal_eta = posAtECalEntrance.eta();
667 sumPhiTimesEnergy += posAtECal_phi * ipatcand->
energy();
668 sumEtaTimesEnergy += posAtECal_eta * ipatcand->
energy();
669 sumEnergy += ipatcand->
energy();
671 if (
track !=
nullptr) {
672 if (
track->pt() > leadChargedCandPt) {
673 leadChargedCandEtaAtEcalEntrance = posAtECal_eta;
674 leadChargedCandPt =
track->pt();
684 if (sumEnergy != 0.) {
691 float leadingTrackNormChi2 = 0;
692 float ecalEnergyLeadChargedHadrCand = -99.;
693 float hcalEnergyLeadChargedHadrCand = -99.;
694 float emFraction = -1.;
695 float myHCALenergy = 0.;
696 float myECALenergy = 0.;
700 if (pfCandPtr !=
nullptr) {
701 ecalEnergyLeadChargedHadrCand = pfCandPtr->
ecalEnergy();
702 hcalEnergyLeadChargedHadrCand = pfCandPtr->
hcalEnergy();
705 leadingTrackNormChi2 = trackRef->normalizedChi2();
706 for (
const auto& isoPFCand : pfTauRef->isolationPFCands()) {
707 myHCALenergy += isoPFCand->hcalEnergy();
708 myECALenergy += isoPFCand->ecalEnergy();
710 for (
const auto& signalPFCand : pfTauRef->signalPFCands()) {
711 myHCALenergy += signalPFCand->hcalEnergy();
712 myECALenergy += signalPFCand->ecalEnergy();
714 if (myHCALenergy + myECALenergy != 0.) {
715 emFraction = myECALenergy / (myHCALenergy + myECALenergy);
720 if (packedCandPtr !=
nullptr) {
723 ecalEnergyLeadChargedHadrCand =
725 hcalEnergyLeadChargedHadrCand =
728 if (
track !=
nullptr) {
729 leadingTrackNormChi2 =
track->normalizedChi2();
730 for (
const auto& isoCand : pfTauRef->isolationCands()) {
738 for (
const auto& signalCand : pfTauRef->signalCands()) {
746 if (myHCALenergy + myECALenergy != 0.) {
747 emFraction = myECALenergy / (myHCALenergy + myECALenergy);
765 aTauPFEssential.
dxy_ = tauLifetimeInfo.
dxy();
770 aTauPFEssential.
ip3d_ = tauLifetimeInfo.
ip3d();
788 for (
size_t j = 0, nd =
deposits.size();
j < nd; ++
j) {
818 template <
typename TauCollectionType,
typename TauDiscrType>
823 return (*tauIdDiscr)[tauRef];
832 if ((*tauIdDiscr)[tauRef].
rawValues.size() == 1)
833 return (*tauIdDiscr)[tauRef].rawValues.at(0);
835 return (*tauIdDiscr)[tauRef].rawValues.at(-1 - wpIdx);
840 return (*tauIdDiscr)[tauRef].workingPoints.at(wpIdx);
853 iDesc.
add<
bool>(
"embedIsolationTracks",
false)->setComment(
"embed external isolation tracks");
854 iDesc.
add<
bool>(
"embedLeadTrack",
false)->setComment(
"embed external leading track");
855 iDesc.
add<
bool>(
"embedLeadTracks",
false)->setComment(
"embed external signal tracks");
858 iDesc.
add<
bool>(
"addGenMatch",
true)->setComment(
"add MC matching");
859 iDesc.
add<
bool>(
"embedGenMatch",
false)->setComment(
"embed MC matched MC information");
860 std::vector<edm::InputTag> emptySourceVector;
864 ->
setComment(
"input with MC match information");
867 iDesc.
add<
bool>(
"addGenJetMatch",
true)->setComment(
"add MC jet matching");
868 iDesc.
add<
bool>(
"embedGenJetMatch",
false)->setComment(
"embed MC jet matched jet information");
874 iDesc.
add<
bool>(
"addTauID",
true)->setComment(
"add tau ID variables");
882 iDesc.
add<
bool>(
"skipMissingTauID",
false)
883 ->setComment(
"allow to skip a tau ID variable when not present in the event");
894 isoDepositsPSet.
addOptional<std::vector<edm::InputTag>>(
"user");
900 iDesc.
add(
"efficiencies", efficienciesPSet);
901 iDesc.
add<
bool>(
"addEfficiencies",
false);
910 iDesc.
add(
"userIsolation", isolationPSet);
~PATTauProducer() override
bool enabled() const
'true' if this there is at least one efficiency configured
void setComment(std::string const &value)
reco::GsfTrackRef gsfTrackRef() const
void newEvent(const edm::Event &event)
To be called for each new event, reads in the ValueMaps for efficiencies.
T getParameter(std::string const &) const
std::pair< std::string, edm::InputTag > NameTag
float etaAtEcalEntranceLeadChargedCand_
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
void setIsolation(IsolationKeys key, float value)
std::vector< edm::EDGetTokenT< edm::ValueMap< IsoDeposit > > > isoDepositTokens_
std::pair< edm::InputTag, std::vector< NameWPIdx > > IDContainerData
bool enabled() const
True if it has a non null configuration.
void embedIsolationPFCands()
method to store the isolation candidates internally
void beginEvent(const edm::EventSetup &)
pat::helper::MultiIsolator::IsolationValuePairs isolatorTmpStorage_
void embedIsolationPFGammaCands()
method to store the isolation gamma candidates internally
const Vector & flightLength() const
bool addTauJetCorrFactors_
void setEfficiencies(pat::PATObject< T > &obj, const R &originalRef) const
Sets the efficiencies for this object, using the reference to the original objects.
void setAllowAnything()
allow any parameter label/value pairs
bool hasSecondaryVertex() const
#define DEFINE_FWK_MODULE(type)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
pat::helper::EfficiencyLoader efficiencyLoader_
void embedLeadTrack()
method to store the leading track internally
void embedSignalPFChargedHadrCands()
method to store the signal charged hadrons candidates internally
pat::helper::KinResolutionsLoader resolutionLoader_
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
bool isNonnull() const
Checks for non-null.
const math::XYZPointF & positionAtECALEntrance() const
float getTauIdDiscriminator(const edm::Handle< TauCollectionType > &, size_t, const edm::Handle< TauDiscrType > &)
void setDecayMode(int)
set decay mode
double flightLengthSig() const
void setTauIDs(const std::vector< IdPair > &ids)
void setResolutions(pat::PATObject< T > &obj) const
Sets the efficiencies for this object, using the reference to the original objects.
IsolationKeys
Enum defining isolation keys.
bool existsAs(std::string const ¶meterName, bool trackiness=true) const
checks if a parameter exists as a given type
float caloFraction() const
Set the fraction of ECAL+HCAL energy over candidate energy.
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
ParameterSet const & parameterSet(StableProvenance const &provenance, ProcessHistory const &history)
const std::string names[nVars_]
std::vector< edm::EDGetTokenT< reco::TauDiscriminatorContainer > > pfTauIDContainerTokens_
void fill(const edm::View< T > &coll, int idx, IsolationValuePairs &isolations) const
void setIsoDeposit(IsolationKeys key, const IsoDeposit &dep)
Sets the IsoDeposit associated with some key; if it is already existent, it is overwritten.
bool embedIsolationPFChargedHadrCands_
static void fillDescription(edm::ParameterSetDescription &iDesc)
U second(std::pair< T, U > const &p)
double ip3d_error() const
void setComment(std::string const &value)
void embedSignalPFCands()
method to store the signal candidates internally
void beginEvent(const edm::Event &event, const edm::EventSetup &eventSetup)
edm::EDGetTokenT< PFTauTIPAssociationByRef > tauTransverseImpactParameterToken_
double eta() const override
momentum pseudorapidity
pat::helper::MultiIsolator isolator_
edm::AssociationVector< reco::PFTauRefProd, std::vector< reco::PFTauTransverseImpactParameterRef > > PFTauTIPAssociationByRef
double hcalEnergy() const
return corrected Hcal energy
edm::EDGetTokenT< edm::View< reco::BaseTau > > baseTauToken_
void newEvent(const edm::Event &event, const edm::EventSetup &setup)
To be called for each new event, reads in the EventSetup object.
bool embedIsolationPFNeutralHadrCands_
bool isNonnull() const
Checks for non-null.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool enabled() const
'true' if this there is at least one efficiency configured
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
float getTauIdDiscriminatorFromContainer(const edm::Handle< reco::PFTauCollection > &, size_t, const edm::Handle< reco::TauDiscriminatorContainer > &, int)
pat::PATUserDataHelper< pat::Tau > userDataHelper_
genJetMatch
switch on/off embedding of matched genJet's
bool embedSignalPFNeutralHadrCands_
std::vector< pat::tau::TauPFEssential > pfEssential_
void embedIsolationPFNeutralHadrCands()
method to store the isolation neutral hadrons candidates internally
bool embedIsolationPFCands_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void embedLeadPFChargedHadrCand()
method to store the leading charged hadron candidate internally
double ecalEnergy() const
return corrected Ecal energy
reco::MuonRef muonRef() const
T const * get() const
Returns C++ pointer to the item.
void add(ObjectType &patObject, edm::Event const &iEvent, edm::EventSetup const &iSetup)
void embedIsolationPFChargedHadrCands()
method to store the isolation charged hadrons candidates internally
void setGenJet(const reco::GenJetRef &ref)
set the matched GenJet
const reco::Track * bestTrack() const override
return a pointer to the track if present. otherwise, return a null pointer
void embedLeadPFNeutralCand()
method to store the leading neutral candidate internally
std::vector< std::pair< pat::IsolationKeys, float > > IsolationValuePairs
void addGenParticleRef(const reco::GenParticleRef &ref)
std::vector< edm::EDGetTokenT< edm::ValueMap< TauJetCorrFactors > > > tauJetCorrFactorsTokens_
static void fillDescription(edm::ParameterSetDescription &iDesc)
Method for documentation and validation of PSet.
edm::InputTag tauTransverseImpactParameterSrc_
bool embedIsolationTracks_
bool embedLeadPFChargedHadrCand_
const Point & dxy_PCA() const
std::vector< edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > > genMatchTokens_
std::pair< std::string, WPIdx > NameWPIdx
bool embedIsolationPFGammaCands_
std::pair< std::string, std::string > WPCfg
std::vector< std::vector< NameWPIdx > > tauIDSrcContainers_
edm::EDGetTokenT< edm::Association< reco::GenJetCollection > > genJetMatchToken_
std::pair< WPCfg, int > WPIdx
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
void initializeJEC(unsigned int level, const unsigned int set=0)
initialize the jet to a given JEC level during creation starting from Uncorrected ...
void embedSignalPFNeutralHadrCands()
method to store the signal neutral hadrons candidates internally
bool embedSignalPFGammaCands_
std::vector< std::pair< pat::IsolationKeys, edm::InputTag > > isoDepositLabels_
float hcalFraction() const
Particle reconstructed by the particle flow algorithm.
void addJECFactors(const TauJetCorrFactors &jec)
add more sets of energy correction factors
PATTauProducer(const edm::ParameterSet &iConfig)
bool embedLeadPFNeutralCand_
float leadingTrackNormChi2_
double energy() const override
energy
T const * get() const
Returns C++ pointer to the item.
void embedSignalTracks()
method to store the signal tracks internally
reco::TrackRef trackRef() const
math::XYZPoint Point
point in the space
void embedSignalPFGammaCands()
method to store the signal gamma candidates internally
Log< level::Warning, false > LogWarning
edm::ProcessHistoryID phID_
float ecalEnergyLeadChargedHadrCand_
bool embedSignalPFChargedHadrCands_
std::vector< edm::EDGetTokenT< reco::PFTauDiscriminator > > pfTauIDTokens_
void embedIsolationTracks()
method to store the isolation tracks internally
StableProvenance const & stable() const
std::vector< NameTag > tauIDSrcs_
edm::EDGetTokenT< reco::PFTauCollection > pfTauToken_
float hcalEnergyLeadChargedHadrCand_
bool isPFTau() const
Returns true if this pat::Tau was made from a reco::PFTau.
double phi() const override
momentum azimuthal angle
GreaterByPt< Tau > pTTauComparator_
PositionAtECalEntranceComputer posAtECalEntranceComputer_
double energy() const final
energy