|
|
Go to the documentation of this file.
31 : isolator_(iConfig.exists(
"userIsolation") ? iConfig.getParameter<
edm::
ParameterSet>(
"userIsolation")
35 useUserData_(iConfig.exists(
"userData")),
36 posAtECalEntranceComputer_(consumesCollector()) {
65 iConfig.
getParameter<std::vector<edm::InputTag>>(
"genParticleMatch"),
66 [
this](
edm::InputTag const&
tag) { return consumes<edm::Association<reco::GenParticleCollection>>(tag); });
77 iConfig.
getParameter<std::vector<edm::InputTag>>(
"tauJetCorrFactorsSource"),
78 [
this](
edm::InputTag const&
tag) { return mayConsume<edm::ValueMap<TauJetCorrFactors>>(tag); });
85 std::map<std::string, IDContainerData> idContainerMap;
91 if (prov_cfg_label.empty()) {
94 if (prov_cfg_label !=
"rawValues" && prov_cfg_label !=
"workingPoints" && prov_cfg_label !=
"IDdefinitions" &&
95 prov_cfg_label !=
"IDWPdefinitions" && prov_cfg_label !=
"direct_rawValues" &&
96 prov_cfg_label !=
"direct_workingPoints")
98 <<
"PATTauProducer: Parameter 'provenanceConfigLabel' does only accept 'rawValues', 'workingPoints', "
99 "'IDdefinitions', 'IDWPdefinitions', 'direct_rawValues', 'direct_workingPoints'\n";
100 std::map<std::string, IDContainerData>::iterator it;
101 it = idContainerMap.insert({
tag.label() +
tag.instance(), {
tag, std::vector<NameWPIdx>()}}).
first;
106 if (
tauIDSrcs_.empty() && idContainerMap.empty())
107 throw cms::Exception(
"Configuration") <<
"PATTauProducer: id addTauID is true, you must specify either:\n"
108 <<
"\tPSet tauIDSources = { \n"
109 <<
"\t\tInputTag <someName> = <someTag> // as many as you want \n "
112 for (
auto const& mapEntry : idContainerMap) {
121 if (iConfig.
exists(
"isoDeposits")) {
123 if (depconf.
exists(
"tracker"))
125 if (depconf.
exists(
"ecal"))
127 if (depconf.
exists(
"hcal"))
129 if (depconf.
exists(
"pfAllParticles"))
132 if (depconf.
exists(
"pfChargedHadron"))
135 if (depconf.
exists(
"pfNeutralHadron"))
138 if (depconf.
exists(
"pfGamma"))
141 if (depconf.
exists(
"user")) {
142 std::vector<edm::InputTag> userdeps = depconf.
getParameter<std::vector<edm::InputTag>>(
"user");
143 std::vector<edm::InputTag>::const_iterator it = userdeps.begin(), ed = userdeps.end();
145 for (; it != ed; ++it, ++
key) {
152 return consumes<edm::ValueMap<IsoDeposit>>(
label.second);
170 produces<std::vector<Tau>>();
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>>();
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";
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";
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";
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";
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";
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";
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";
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";
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";
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";
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) {
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) {
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.";
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();
674 for (
size_t j = 0, nd =
deposits.size();
j < nd; ++
j) {
704 template <
typename TauCollectionType,
typename TauDiscrType>
709 return (*tauIdDiscr)[tauRef];
718 if ((*tauIdDiscr)[tauRef].
rawValues.size() == 1)
719 return (*tauIdDiscr)[tauRef].rawValues.at(0);
721 return (*tauIdDiscr)[tauRef].rawValues.at(-1 - wpIdx);
726 return (*tauIdDiscr)[tauRef].workingPoints.at(wpIdx);
739 iDesc.
add<
bool>(
"embedIsolationTracks",
false)->setComment(
"embed external isolation tracks");
740 iDesc.
add<
bool>(
"embedLeadTrack",
false)->setComment(
"embed external leading track");
741 iDesc.
add<
bool>(
"embedLeadTracks",
false)->setComment(
"embed external signal tracks");
744 iDesc.
add<
bool>(
"addGenMatch",
true)->setComment(
"add MC matching");
745 iDesc.
add<
bool>(
"embedGenMatch",
false)->setComment(
"embed MC matched MC information");
746 std::vector<edm::InputTag> emptySourceVector;
750 ->
setComment(
"input with MC match information");
753 iDesc.
add<
bool>(
"addGenJetMatch",
true)->setComment(
"add MC jet matching");
754 iDesc.
add<
bool>(
"embedGenJetMatch",
false)->setComment(
"embed MC jet matched jet information");
760 iDesc.
add<
bool>(
"addTauID",
true)->setComment(
"add tau ID variables");
768 iDesc.
add<
bool>(
"skipMissingTauID",
false)
769 ->setComment(
"allow to skip a tau ID variable when not present in the event");
780 isoDepositsPSet.
addOptional<std::vector<edm::InputTag>>(
"user");
786 iDesc.
add(
"efficiencies", efficienciesPSet);
787 iDesc.
add<
bool>(
"addEfficiencies",
false);
796 iDesc.
add(
"userIsolation", isolationPSet);
reco::TrackRef trackRef() const
edm::EDGetTokenT< reco::PFTauCollection > pfTauToken_
void embedSignalPFCands()
method to store the signal candidates internally
Assists in assimilating all pat::UserData into pat objects.
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void setGenJet(const reco::GenJetRef &ref)
set the matched GenJet
PATTauProducer(const edm::ParameterSet &iConfig)
std::vector< std::vector< NameWPIdx > > tauIDSrcContainers_
float etaAtEcalEntranceLeadChargedCand_
void embedLeadPFChargedHadrCand()
method to store the leading charged hadron candidate internally
std::pair< WPCfg, int > WPIdx
void fill(const edm::View< T > &coll, int idx, IsolationValuePairs &isolations) const
void embedSignalPFNeutralHadrCands()
method to store the signal neutral hadrons candidates internally
bool embedIsolationPFNeutralHadrCands_
static void fillDescription(edm::ParameterSetDescription &iDesc)
float caloFraction() const
Set the fraction of ECAL+HCAL energy over candidate energy.
bool embedIsolationTracks_
const math::XYZPointF & positionAtECALEntrance() const
void embedLeadPFNeutralCand()
method to store the leading neutral candidate internally
void setIsolation(IsolationKeys key, float value)
bool enabled() const
'true' if this there is at least one efficiency configured
T const * get() const
Returns C++ pointer to the item.
std::vector< pat::tau::TauPFEssential > pfEssential_
U second(std::pair< T, U > const &p)
void addGenParticleRef(const reco::GenParticleRef &ref)
bool embedIsolationPFGammaCands_
T const * get() const
Returns C++ pointer to the item.
bool embedLeadPFChargedHadrCand_
pat::helper::MultiIsolator isolator_
bool existsAs(std::string const ¶meterName, bool trackiness=true) const
checks if a parameter exists as a given type
void addJECFactors(const TauJetCorrFactors &jec)
add more sets of energy correction factors
std::vector< edm::EDGetTokenT< reco::TauDiscriminatorContainer > > pfTauIDContainerTokens_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
Log< level::Warning, false > LogWarning
std::vector< std::pair< pat::IsolationKeys, float > > IsolationValuePairs
bool enabled() const
'true' if this there is at least one efficiency configured
edm::ProcessHistoryID phID_
bool enabled() const
True if it has a non null configuration.
bool embedSignalPFGammaCands_
void beginEvent(const edm::EventSetup &)
ParameterSet const & parameterSet(StableProvenance const &provenance, ProcessHistory const &history)
PositionAtECalEntranceComputer posAtECalEntranceComputer_
std::vector< edm::EDGetTokenT< edm::Association< reco::GenParticleCollection > > > genMatchTokens_
reco::MuonRef muonRef() const
double energy() const override
energy
std::pair< std::string, edm::InputTag > NameTag
#define DEFINE_FWK_MODULE(type)
const reco::Track * bestTrack() const override
return a pointer to the track if present. otherwise, return a null pointer
std::vector< std::pair< pat::IsolationKeys, edm::InputTag > > isoDepositLabels_
double flightLengthSig() const
const std::string names[nVars_]
bool isPFTau() const
Returns true if this pat::Tau was made from a reco::PFTau.
void add(ObjectType &patObject, edm::Event const &iEvent, edm::EventSetup const &iSetup)
pat::helper::MultiIsolator::IsolationValuePairs isolatorTmpStorage_
void embedSignalTracks()
method to store the signal tracks internally
void newEvent(const edm::Event &event)
To be called for each new event, reads in the ValueMaps for efficiencies.
std::pair< std::string, WPIdx > NameWPIdx
void initializeJEC(unsigned int level, const unsigned int set=0)
initialize the jet to a given JEC level during creation starting from Uncorrected
void setIsoDeposit(IsolationKeys key, const IsoDeposit &dep)
Sets the IsoDeposit associated with some key; if it is already existent, it is overwritten.
~PATTauProducer() override
void embedSignalPFGammaCands()
method to store the signal gamma candidates internally
std::vector< NameTag > tauIDSrcs_
edm::EDGetTokenT< edm::Association< reco::GenJetCollection > > genJetMatchToken_
bool addTauJetCorrFactors_
void embedIsolationTracks()
method to store the isolation tracks internally
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 >
bool hasSecondaryVertex() const
void setResolutions(pat::PATObject< T > &obj) const
Sets the efficiencies for this object, using the reference to the original objects.
bool exists(std::string const ¶meterName) const
checks if a parameter exists
std::pair< std::string, std::string > WPCfg
void embedIsolationPFCands()
method to store the isolation candidates internally
void setComment(std::string const &value)
reco::GsfTrackRef gsfTrackRef() const
bool embedSignalPFChargedHadrCands_
genJetMatch
switch on/off embedding of matched genJet's
pat::helper::EfficiencyLoader efficiencyLoader_
static void fillDescription(edm::ParameterSetDescription &iDesc)
Method for documentation and validation of PSet.
std::vector< edm::EDGetTokenT< reco::PFTauDiscriminator > > pfTauIDTokens_
bool isNonnull() const
Checks for non-null.
edm::EDGetTokenT< edm::View< reco::BaseTau > > baseTauToken_
double phi() const override
momentum azimuthal angle
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
std::vector< edm::EDGetTokenT< edm::ValueMap< IsoDeposit > > > isoDepositTokens_
bool embedSignalPFNeutralHadrCands_
bool embedIsolationPFCands_
double ip3d_error() const
void embedLeadTrack()
method to store the leading track internally
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
float leadingTrackNormChi2_
const Point & dxy_PCA() const
void embedSignalPFChargedHadrCands()
method to store the signal charged hadrons candidates internally
void setAllowAnything()
allow any parameter label/value pairs
void embedIsolationPFGammaCands()
method to store the isolation gamma candidates internally
void newEvent(const edm::Event &event, const edm::EventSetup &setup)
To be called for each new event, reads in the EventSetup object.
void setDecayMode(int)
set decay mode
double ecalEnergy() const
return corrected Ecal energy
GreaterByPt< Tau > pTTauComparator_
float ecalEnergyLeadChargedHadrCand_
float hcalFraction() const
IsolationKeys
Enum defining isolation keys.
void beginEvent(const edm::Event &event, const edm::EventSetup &eventSetup)
void setEfficiencies(pat::PATObject< T > &obj, const R &originalRef) const
Sets the efficiencies for this object, using the reference to the original objects.
double hcalEnergy() const
return corrected Hcal energy
pat::PATUserDataHelper< pat::Tau > userDataHelper_
bool embedIsolationPFChargedHadrCands_
StableProvenance const & stable() const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool embedLeadPFNeutralCand_
float getTauIdDiscriminator(const edm::Handle< TauCollectionType > &, size_t, const edm::Handle< TauDiscrType > &)
float getTauIdDiscriminatorFromContainer(const edm::Handle< reco::PFTauCollection > &, size_t, const edm::Handle< reco::TauDiscriminatorContainer > &, int)
bool isNonnull() const
Checks for non-null.
T getParameter(std::string const &) const
double energy() const final
energy
Particle reconstructed by the particle flow algorithm.
std::vector< edm::EDGetTokenT< edm::ValueMap< TauJetCorrFactors > > > tauJetCorrFactorsTokens_
pat::helper::KinResolutionsLoader resolutionLoader_
edm::EDGetTokenT< PFTauTIPAssociationByRef > tauTransverseImpactParameterToken_
edm::InputTag tauTransverseImpactParameterSrc_
void setComment(std::string const &value)
void setTauIDs(const std::vector< IdPair > &ids)
math::XYZPoint Point
point in the space
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
void embedIsolationPFNeutralHadrCands()
method to store the isolation neutral hadrons candidates internally
void embedIsolationPFChargedHadrCands()
method to store the isolation charged hadrons candidates internally
double eta() const override
momentum pseudorapidity
const Vector & flightLength() const
float hcalEnergyLeadChargedHadrCand_