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.getParameter<
edm::
ParameterSet>(
"userIsolation"), consumesCollector(),
false),
145 useUserData_(iConfig.exists(
"userData")),
146 posAtECalEntranceComputer_(consumesCollector()) {
181 iConfig.
getParameter<std::vector<edm::InputTag>>(
"tauJetCorrFactorsSource"),
182 [
this](
edm::InputTag const&
tag) { return mayConsume<edm::ValueMap<TauJetCorrFactors>>(tag); });
189 std::map<std::string, IDContainerData> idContainerMap;
195 if (prov_cfg_label.empty()) {
198 if (prov_cfg_label !=
"rawValues" && prov_cfg_label !=
"workingPoints" && prov_cfg_label !=
"IDdefinitions" &&
199 prov_cfg_label !=
"IDWPdefinitions" && prov_cfg_label !=
"direct_rawValues" &&
200 prov_cfg_label !=
"direct_workingPoints")
202 <<
"PATTauProducer: Parameter 'provenanceConfigLabel' does only accept 'rawValues', 'workingPoints', " 203 "'IDdefinitions', 'IDWPdefinitions', 'direct_rawValues', 'direct_workingPoints'\n";
204 std::map<std::string, IDContainerData>::iterator it;
205 it = idContainerMap.insert({
tag.label() +
tag.instance(), {
tag, std::vector<NameWPIdx>()}}).
first;
210 if (
tauIDSrcs_.empty() && idContainerMap.empty())
211 throw cms::Exception(
"Configuration") <<
"PATTauProducer: id addTauID is true, you must specify either:\n" 212 <<
"\tPSet tauIDSources = { \n" 213 <<
"\t\tInputTag <someName> = <someTag> // as many as you want \n " 216 for (
auto const& mapEntry : idContainerMap) {
225 if (iConfig.
exists(
"isoDeposits")) {
227 if (depconf.
exists(
"tracker"))
229 if (depconf.
exists(
"ecal"))
231 if (depconf.
exists(
"hcal"))
233 if (depconf.
exists(
"pfAllParticles"))
236 if (depconf.
exists(
"pfChargedHadron"))
239 if (depconf.
exists(
"pfNeutralHadron"))
242 if (depconf.
exists(
"pfGamma"))
245 if (depconf.
exists(
"user")) {
246 std::vector<edm::InputTag> userdeps = depconf.
getParameter<std::vector<edm::InputTag>>(
"user");
247 std::vector<edm::InputTag>::const_iterator it = userdeps.begin(), ed = userdeps.end();
249 for (; it != ed; ++it, ++
key) {
256 return consumes<edm::ValueMap<IsoDeposit>>(
label.second);
275 produces<std::vector<Tau>>();
282 if (
iEvent.isRealData()) {
293 edm::LogWarning(
"DataSource") <<
"WARNING! No Tau collection found. This missing input will not block the job. " 294 "Instead, an empty tau collection is being be produced.";
295 auto patTaus = std::make_unique<std::vector<Tau>>();
311 for (
size_t j = 0, nd =
deposits.size();
j < nd; ++
j) {
316 std::vector<edm::Handle<edm::Association<reco::GenParticleCollection>>> genMatches(
genMatchTokens_.size());
328 std::vector<edm::ValueMap<TauJetCorrFactors>> tauJetCorrs;
333 tauJetCorrs.push_back(*tauJetCorr);
337 auto patTaus = std::make_unique<std::vector<Tau>>();
355 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made " 356 "from a reco::PFTau is impossible.\n";
362 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made " 363 "from a reco::PFTau is impossible.\n";
369 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made " 370 "from a reco::PFTau is impossible.\n";
376 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made " 377 "from a reco::PFTau is impossible.\n";
383 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made " 384 "from a reco::PFTau is impossible.\n";
390 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made " 391 "from a reco::PFTau is impossible.\n";
397 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made " 398 "from a reco::PFTau is impossible.\n";
404 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made " 405 "from a reco::PFTau is impossible.\n";
411 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made " 412 "from a reco::PFTau is impossible.\n";
418 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made " 419 "from a reco::PFTau is impossible.\n";
425 edm::LogWarning(
"Type Error") <<
"Embedding a PFTau-specific information into a pat::Tau which wasn't made " 426 "from a reco::PFTau is impossible.\n";
431 for (
unsigned int i = 0;
i < tauJetCorrs.size(); ++
i) {
437 std::vector<std::string>
levels = tauJetCorrs[0][tausRef].correctionLabels();
439 aTau.
initializeJEC(tauJetCorrs[0][tausRef].jecLevel(
"L2L3Residual"));
441 aTau.
initializeJEC(tauJetCorrs[0][tausRef].jecLevel(
"L3Absolute"));
443 aTau.
initializeJEC(tauJetCorrs[0][tausRef].jecLevel(
"Uncorrected"));
446 <<
"L2L3Residual and L3Absolute are not part of the correction applied jetCorrFactors \n" 447 <<
"of module " << tauJetCorrs[0][tausRef].jecSet() <<
" jets will remain" 456 for (
size_t i = 0,
n = genMatches.size();
i <
n; ++
i) {
475 size_t numberTauIds = numberPlainTauIds;
477 numberTauIds += it.size();
481 if (numberPlainTauIds != numberTauIds &&
phID_ !=
iEvent.processHistoryID()) {
485 if (!pfTauIdDiscr.isValid())
489 std::string prov_cfg_label = idcfg.second.first.first;
490 std::string prov_ID_label = idcfg.second.first.second;
492 if (prov_cfg_label ==
"rawValues" || prov_cfg_label ==
"workingPoints") {
493 const std::vector<std::string> psetsFromProvenance =
495 .getParameter<std::vector<std::string>>(prov_cfg_label);
496 for (
size_t i = 0;
i < psetsFromProvenance.size(); ++
i) {
497 if (psetsFromProvenance[
i] == prov_ID_label) {
499 if (prov_cfg_label ==
"rawValues")
500 idcfg.second.second = -1 -
i;
502 idcfg.second.second =
i;
506 }
else if (prov_cfg_label ==
"IDdefinitions" || prov_cfg_label ==
"IDWPdefinitions") {
507 const std::vector<edm::ParameterSet> psetsFromProvenance =
509 .getParameter<std::vector<edm::ParameterSet>>(prov_cfg_label);
510 for (
size_t i = 0;
i < psetsFromProvenance.size(); ++
i) {
511 if (psetsFromProvenance[
i].getParameter<std::string>(
"IDname") == prov_ID_label) {
513 if (prov_cfg_label ==
"IDdefinitions")
514 idcfg.second.second = -1 -
i;
516 idcfg.second.second =
i;
523 int i = std::stoi(prov_ID_label);
524 if (prov_cfg_label ==
"direct_rawValues")
525 idcfg.second.second = -1 -
i;
527 idcfg.second.second =
i;
529 }
catch (std::invalid_argument
const&
e) {
530 throw cms::Exception(
"Configuration") <<
"PATTauProducer: Direct access to ID container requested, so " 531 "argument of 'idLabel' must be convertable to int!\n";
535 throw cms::Exception(
"Configuration") <<
"PATTauProducer: Requested working point '" << prov_ID_label
536 <<
"' for ID '" << idcfg.first <<
"' not found!\n";
542 std::vector<pat::Tau::IdPair> ids(numberTauIds);
543 auto const& tausDeref = *tausRef;
547 for (
size_t i = 0;
i < numberPlainTauIds; ++
i) {
553 if (!missingDiscriminators.empty()) {
554 missingDiscriminators +=
", ";
566 if (!missingDiscriminators.empty()) {
567 missingDiscriminators +=
", ";
569 missingDiscriminators += it.first;
582 <<
"PATTauProducer: unsupported datatype '" <<
typeid(tausDeref).
name() <<
"' for tauSource\n";
585 edm::LogWarning(
"DataSource") <<
"The following tau discriminators have not been found in the event:\n" 586 << missingDiscriminators <<
"\n" 587 <<
"They will not be embedded into the pat::Tau object.\n" 588 <<
"Note: this message will be printed only at first occurence.";
611 float hcalEnergy = 0;
612 float sumPhiTimesEnergy = 0.;
613 float sumEtaTimesEnergy = 0.;
614 float sumEnergy = 0.;
615 float leadChargedCandPt = -99;
616 float leadChargedCandEtaAtEcalEntrance = -99;
617 const std::vector<reco::CandidatePtr>& signalCands = pfTauRef->signalCands();
618 for (
const auto& it : signalCands) {
620 if (ipfcand !=
nullptr) {
625 sumEnergy += ipfcand->
energy();
638 if (
track->pt() > leadChargedCandPt) {
640 leadChargedCandPt =
track->pt();
647 if (ipatcand !=
nullptr) {
650 double posAtECal_phi = ipatcand->
phi();
651 double posAtECal_eta = ipatcand->
eta();
655 posAtECal_phi = posAtECalEntrance.phi();
656 posAtECal_eta = posAtECalEntrance.eta();
658 sumPhiTimesEnergy += posAtECal_phi * ipatcand->
energy();
659 sumEtaTimesEnergy += posAtECal_eta * ipatcand->
energy();
660 sumEnergy += ipatcand->
energy();
662 if (
track !=
nullptr) {
663 if (
track->pt() > leadChargedCandPt) {
664 leadChargedCandEtaAtEcalEntrance = posAtECal_eta;
665 leadChargedCandPt =
track->pt();
675 if (sumEnergy != 0.) {
682 float leadingTrackNormChi2 = 0;
683 float ecalEnergyLeadChargedHadrCand = -99.;
684 float hcalEnergyLeadChargedHadrCand = -99.;
685 float emFraction = -1.;
686 float myHCALenergy = 0.;
687 float myECALenergy = 0.;
691 if (pfCandPtr !=
nullptr) {
692 ecalEnergyLeadChargedHadrCand = pfCandPtr->
ecalEnergy();
693 hcalEnergyLeadChargedHadrCand = pfCandPtr->
hcalEnergy();
696 leadingTrackNormChi2 = trackRef->normalizedChi2();
697 for (
const auto& isoPFCand : pfTauRef->isolationPFCands()) {
698 myHCALenergy += isoPFCand->hcalEnergy();
699 myECALenergy += isoPFCand->ecalEnergy();
701 for (
const auto& signalPFCand : pfTauRef->signalPFCands()) {
702 myHCALenergy += signalPFCand->hcalEnergy();
703 myECALenergy += signalPFCand->ecalEnergy();
705 if (myHCALenergy + myECALenergy != 0.) {
706 emFraction = myECALenergy / (myHCALenergy + myECALenergy);
711 if (packedCandPtr !=
nullptr) {
714 ecalEnergyLeadChargedHadrCand =
716 hcalEnergyLeadChargedHadrCand =
719 if (
track !=
nullptr) {
720 leadingTrackNormChi2 =
track->normalizedChi2();
721 for (
const auto& isoCand : pfTauRef->isolationCands()) {
729 for (
const auto& signalCand : pfTauRef->signalCands()) {
737 if (myHCALenergy + myECALenergy != 0.) {
738 emFraction = myECALenergy / (myHCALenergy + myECALenergy);
756 aTauPFEssential.
dxy_ = tauLifetimeInfo.
dxy();
761 aTauPFEssential.
ip3d_ = tauLifetimeInfo.
ip3d();
779 for (
size_t j = 0, nd =
deposits.size();
j < nd; ++
j) {
809 template <
typename TauCollectionType,
typename TauDiscrType>
814 return (*tauIdDiscr)[tauRef];
823 if ((*tauIdDiscr)[tauRef].
rawValues.size() == 1)
824 return (*tauIdDiscr)[tauRef].rawValues.at(0);
826 return (*tauIdDiscr)[tauRef].rawValues.at(-1 - wpIdx);
831 return (*tauIdDiscr)[tauRef].workingPoints.at(wpIdx);
844 iDesc.
add<
bool>(
"embedIsolationTracks",
false)->setComment(
"embed external isolation tracks");
845 iDesc.
add<
bool>(
"embedLeadTrack",
false)->setComment(
"embed external leading track");
846 iDesc.
add<
bool>(
"embedLeadTracks",
false)->setComment(
"embed external signal tracks");
849 iDesc.
add<
bool>(
"addGenMatch",
true)->setComment(
"add MC matching");
850 iDesc.
add<
bool>(
"embedGenMatch",
false)->setComment(
"embed MC matched MC information");
851 std::vector<edm::InputTag> emptySourceVector;
855 ->
setComment(
"input with MC match information");
858 iDesc.
add<
bool>(
"addGenJetMatch",
true)->setComment(
"add MC jet matching");
859 iDesc.
add<
bool>(
"embedGenJetMatch",
false)->setComment(
"embed MC jet matched jet information");
865 iDesc.
add<
bool>(
"addTauID",
true)->setComment(
"add tau ID variables");
873 iDesc.
add<
bool>(
"skipMissingTauID",
false)
874 ->setComment(
"allow to skip a tau ID variable when not present in the event");
885 isoDepositsPSet.
addOptional<std::vector<edm::InputTag>>(
"user");
891 iDesc.
add(
"efficiencies", efficienciesPSet);
892 iDesc.
add<
bool>(
"addEfficiencies",
false);
901 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
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.
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_
#define DEFINE_FWK_MODULE(type)
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