40 enum class tauId_pnet_idx : size_t {
dm = 0,
vsjet,
vse,
vsmu,
ptcorr,
qconf,
pdm0,
pdm1,
pdm2,
pdm10,
pdm11,
last };
47 addGenJetMatch_(
cfg.getParameter<
bool>(
"addGenJetMatch")),
48 dR2Max_(
std::
pow(
cfg.getParameter<double>(
"dRMax"), 2)),
49 jetPtMin_(
cfg.getParameter<double>(
"jetPtMin")),
50 jetEtaMax_(
cfg.getParameter<double>(
"jetEtaMax")),
52 pnetPtCorrName_(
cfg.getParameter<
std::
string>(
"pnetPtCorrName")),
53 tauScoreMin_(
cfg.getParameter<double>(
"tauScoreMin")),
54 vsJetMin_(
cfg.getParameter<double>(
"vsJetMin")),
55 chargeAssignmentProbMin_(
cfg.getParameter<double>(
"chargeAssignmentProbMin")),
56 checkTauScoreIsBest_(
cfg.getParameter<
bool>(
"checkTauScoreIsBest")),
57 usePFLeptonsAsChargedHadrons_(
cfg.getParameter<
bool>(
"usePFLeptonsAsChargedHadrons")),
58 tagToDM_({{
"1h0p", 0}, {
"1h1or2p", 1}, {
"1h1p", 1}, {
"1h2p", 2}, {
"3h0p", 10}, {
"3h1p", 11}}) {
60 std::vector<std::string> pnetScoreNames =
cfg.getParameter<std::vector<std::string>>(
"pnetScoreNames");
61 for (
const auto& scoreName : pnetScoreNames) {
62 size_t labelLenght = scoreName.find(
':') == std::string::npos ? 0 : scoreName.find(
':') + 1;
64 if (
name.find(
"prob") == std::string::npos)
66 if (
name.find(
"tau") != std::string::npos)
67 pnetTauScoreNames_.push_back(
name);
68 else if (
name.find(
"ele") != std::string::npos ||
name.find(
"mu") != std::string::npos)
69 pnetLepScoreNames_.push_back(
name);
71 pnetJetScoreNames_.push_back(
name);
72 if (pnetPtCorrName_.find(
':') != std::string::npos)
73 pnetPtCorrName_ = pnetPtCorrName_.substr(pnetPtCorrName_.find(
':') + 1);
75 if (addGenJetMatch_) {
77 consumes<edm::Association<reco::GenJetCollection>>(
cfg.getParameter<
edm::InputTag>(
"genJetMatch"));
81 produces<std::vector<pat::Tau>>();
90 auto outputTaus = std::make_unique<std::vector<pat::Tau>>();
91 outputTaus->reserve(inputTaus->size());
123 std::set<unsigned int> matched_taus;
125 for (
const auto&
jet : *
jets) {
135 std::pair<std::string, float> bestPnetTauScore(
"probtauundef", -1);
136 float sumOfPnetTauScores = 0;
137 std::vector<float> tauPerDMScores(5);
138 float plusChargeProb = 0;
141 sumOfPnetTauScores +=
score;
142 if (scoreName.find(
"taup") != std::string::npos)
143 plusChargeProb +=
score;
144 if (
score > bestPnetTauScore.second) {
145 bestPnetTauScore.second =
score;
146 bestPnetTauScore.first = scoreName;
148 if (scoreName.find(
"1h0p") != std::string::npos)
149 tauPerDMScores[0] +=
score;
150 else if (scoreName.find(
"1h1") !=
153 tauPerDMScores[1] +=
score;
154 else if (scoreName.find(
"1h2p") != std::string::npos)
155 tauPerDMScores[2] +=
score;
156 else if (scoreName.find(
"3h0p") != std::string::npos)
157 tauPerDMScores[3] +=
score;
158 else if (scoreName.find(
"3h1p") != std::string::npos)
159 tauPerDMScores[4] +=
score;
161 if (sumOfPnetTauScores > 0)
162 plusChargeProb /= sumOfPnetTauScores;
164 float sumOfPnetEleScores = 0, sumOfPnetMuScores = 0;
165 bool isTauScoreBest = (sumOfPnetTauScores > 0);
168 if (scoreName.find(
"ele") != std::string::npos)
169 sumOfPnetEleScores +=
score;
170 else if (scoreName.find(
"mu") != std::string::npos)
171 sumOfPnetMuScores +=
score;
172 if (
score > bestPnetTauScore.second)
173 isTauScoreBest =
false;
177 if (
jet.bDiscriminator(
pnetLabel_ +
":" + scoreName) > bestPnetTauScore.second)
178 isTauScoreBest =
false;
184 (1. - sumOfPnetEleScores -
188 (sumOfPnetTauScores + sumOfPnetEleScores);
190 sumOfPnetTauScores / (sumOfPnetTauScores + sumOfPnetMuScores);
195 bestPnetTauScore.first.find(
"tau") + 3;
196 const char q = (
pos < bestPnetTauScore.first.size()) ? bestPnetTauScore.first[
pos] :
'u';
200 }
else if (
q ==
'p') {
204 auto pNetDM =
tagToDM_.find(bestPnetTauScore.first.substr(
pos));
224 for (
const auto& inputTau : *inputTaus) {
226 if (matched_taus.count(tau_idx - 1) > 0)
231 matched_taus.insert(tau_idx - 1);
233 const size_t nTauIds = inputTau.tauIDs().size();
234 std::vector<pat::Tau::IdPair> tauIds(nTauIds + tauIds_pnet.size());
235 for (
size_t i = 0;
i < nTauIds; ++
i)
236 tauIds[
i] = inputTau.tauIDs()[
i];
237 for (
size_t i = 0;
i < tauIds_pnet.size(); ++
i)
238 tauIds[nTauIds +
i] = tauIds_pnet[
i];
241 outputTaus->push_back(outputTau);
257 reco::PFTau pfTauFromJet(bestCharge,
jet.correctedP4(
"Uncorrected"));
259 pfTauFromJet.
setPdgId(bestCharge < 0 ? 15 : -15);
261 pfTauFromJet.setDecayMode(
266 pfTauFromJet.setSignalConeSize(
267 std::clamp(3.6 /
jet.correctedP4(
"Uncorrected").pt(), 0.08, 0.12));
272 pat::Tau outputTauFromJet(pfTauFromJet);
274 std::vector<pat::Tau::IdPair> newtauIds(tauIds_minimal.size() + tauIds_pnet.size());
275 for (
size_t i = 0;
i < tauIds_minimal.size(); ++
i)
276 newtauIds[
i] = tauIds_minimal[
i];
277 for (
size_t i = 0;
i < tauIds_pnet.size(); ++
i)
278 newtauIds[tauIds_minimal.size() +
i] = tauIds_pnet[
i];
287 outputTaus->push_back(outputTauFromJet);
292 if (matched_taus.size() < inputTaus->size()) {
293 for (
size_t iTau = 0; iTau < inputTaus->size(); ++iTau) {
294 if (matched_taus.count(iTau) > 0)
296 const pat::Tau& inputTau = inputTaus->at(iTau);
298 const size_t nTauIds = inputTau.
tauIDs().size();
299 std::vector<pat::Tau::IdPair> tauIds(nTauIds + tauIds_pnet.size());
300 for (
size_t i = 0;
i < nTauIds; ++
i)
302 for (
size_t i = 0;
i < tauIds_pnet.size(); ++
i) {
303 tauIds[nTauIds +
i] = tauIds_pnet[
i];
304 tauIds[nTauIds +
i].second =
308 outputTaus->push_back(outputTau);
317 typedef std::vector<reco::CandidatePtr>
CandPtrs;
330 if (pfTau.
charge() == 0 || pfChs.size() == 1) {
333 pfChsSig.push_back(pfChs[0]);
334 pfChs.erase(pfChs.begin());
336 for (CandPtrs::iterator
it = pfChs.begin();
it != pfChs.end();) {
337 if ((*it)->charge() == pfTau.
charge()) {
340 pfChsSig.push_back(*
it);
341 it = pfChs.erase(
it);
351 pfChsSig.push_back(pfChs[0]);
352 pfChs.erase(pfChs.begin());
359 for (CandPtrs::iterator
it = pfChs.begin();
it != pfChs.end();) {
361 pfChsSig.push_back(*
it);
362 it = pfChs.erase(
it);
369 pfChs.erase(std::remove_if(pfChs.begin(),
395 std::clamp(0.2 *
std::pow((*it)->pt(), -0.66), 0.05, 0.15) &&
397 std::clamp(0.35 *
std::pow((*it)->pt(), -0.71), 0.05, 0.3)) {
398 pfGammasSig.push_back(*
it);
416 desc.add<
double>(
"dRMax", 0.4);
417 desc.add<
double>(
"jetPtMin", 20.0);
418 desc.add<
double>(
"jetEtaMax", 2.5);
420 desc.add<std::vector<std::string>>(
422 {
"probmu",
"probele",
"probtaup1h0p",
"probtaup1h1p",
"probtaup1h2p",
"probtaup3h0p",
"probtaup3h1p",
423 "probtaum1h0p",
"probtaum1h1p",
"probtaum1h2p",
"probtaum3h0p",
"probtaum3h1p",
"probb",
"probc",
424 "probuds",
"probg",
"ptcorr",
"ptreshigh",
"ptreslow",
"ptnu"});
426 desc.add<
double>(
"tauScoreMin", -1)->setComment(
"Minimal value of the best tau score to built recovery tau");
427 desc.add<
double>(
"vsJetMin", -1)->setComment(
"Minimal value of PNet tau-vs-jet discriminant to built recovery tau");
428 desc.add<
bool>(
"checkTauScoreIsBest",
false)
429 ->setComment(
"If true, recovery tau is built only if one of tau scores is the highest");
430 desc.add<
double>(
"chargeAssignmentProbMin", 0.2)
431 ->setComment(
"Minimal value of charge assignment probability to built recovery tau (0,0.5)");
432 desc.add<
bool>(
"addGenJetMatch",
true)->setComment(
"add MC genTauJet matching");
434 desc.add<
bool>(
"usePFLeptonsAsChargedHadrons",
true)
435 ->setComment(
"If true, all charged particles are used as charged hadron candidates");
std::vector< CandidatePtr > pfCandidatesByPdgId(const Jet &jet, int pdgId, bool sort=true)
void setsignalChargedHadrCands(const std::vector< reco::CandidatePtr > &)
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
std::string pnetPtCorrName_
double signalConeSize() const
Size of signal cone.
const bool checkTauScoreIsBest_
std::vector< Jet > JetCollection
std::vector< std::string > pnetTauScoreNames_
const CandidatePtr & leadChargedHadrCand() const
edm::EDGetTokenT< pat::JetCollection > jetsToken_
bool isNonnull() const
Checks for non-null.
std::vector< Tau > TauCollection
bool getByToken(EDGetToken token, Handle< PROD > &result) const
void setTauIDs(const std::vector< IdPair > &ids)
void setleadCand(const CandidatePtr &)
std::vector< CandidatePtr > pfChargedCands(const Jet &jet, bool sort=true)
Extract all non-neutral candidates from a PFJet.
void setisolationChargedHadrCands(const std::vector< reco::CandidatePtr > &)
PATTauHybridProducer(const edm::ParameterSet &)
const std::vector< IdPair > & tauIDs() const
void setleadChargedHadrCand(const CandidatePtr &)
U second(std::pair< T, U > const &p)
bool isNull() const
Checks for null.
ALPAKA_FN_ACC static ALPAKA_FN_INLINE float dR2(Position4 pos1, Position4 pos2)
std::vector< reco::CandidatePtr > CandPtrs
std::vector< std::string > pnetJetScoreNames_
const float chargeAssignmentProbMin_
bool isNonnull() const
Checks for non-null.
Abs< T >::type abs(const T &t)
const std::map< std::string, int > tagToDM_
#define DEFINE_FWK_MODULE(type)
genJetMatch
switch on/off embedding of matched genJet's
Analysis-level tau class.
edm::EDGetTokenT< edm::Association< reco::GenJetCollection > > genJetMatchToken_
void produce(edm::Event &, const edm::EventSetup &) override
void fillTauFromJet(reco::PFTau &pfTau, const reco::JetBaseRef &jet)
void setGenJet(const reco::GenJetRef &ref)
set the matched GenJet
edm::EDGetTokenT< pat::TauCollection > tausToken_
const bool usePFLeptonsAsChargedHadrons_
hadronicDecayMode decayMode() const
void setisolationGammaCands(const std::vector< reco::CandidatePtr > &)
void setsignalGammaCands(const std::vector< reco::CandidatePtr > &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
~PATTauHybridProducer() override
std::vector< std::string > pnetLepScoreNames_
const std::string pnetLabel_
if(threadIdxLocalY==0 &&threadIdxLocalX==0)
void setPdgId(int pdgId) final
Power< A, B >::type pow(const A &a, const B &b)
int charge() const final
electric charge
std::vector< CandidatePtr > pfGammas(const Jet &jet, bool sort=true)
Extract all pfGammas from a PFJet.